From http://www.jwz.org/xscreensaver/xscreensaver-5.22.tar.gz
[xscreensaver] / hacks / ripples.c
index aa286426a960537ce62e6360e1d049bde3d50001..bffd2c68014f79a0de17d903f40c9cc909388ff2 100644 (file)
@@ -62,6 +62,7 @@ struct state {
   XImage *orig_map, *buffer_map;
   int ctab[256];
   Colormap colormap;
+  Screen *screen;
   int ncolors;
   int light;
 
@@ -495,6 +496,7 @@ setup_X(struct state *st)
   XGetWindowAttributes(st->dpy, st->window, &xgwa);
   depth = xgwa.depth;
   st->colormap = xgwa.colormap;
+  st->screen = xgwa.screen;
   st->bigwidth = xgwa.width;
   st->bigheight = xgwa.height;
   st->visual = xgwa.visual;
@@ -656,7 +658,8 @@ init_oily_colors(struct state *st)
 
   if (!mono_p) {
     colors = (XColor *)malloc(sizeof(*colors) * (st->ncolors+1));
-    make_smooth_colormap(st->dpy, st->visual, st->colormap, colors, &st->ncolors,
+    make_smooth_colormap(st->screen, st->visual, st->colormap,
+                         colors, &st->ncolors,
                          True, /* allocate */
                          False, /* not writable */
                          True); /* verbose (complain about failure) */
@@ -703,6 +706,7 @@ sinc(struct state *st, double x)
   int i;
   i = (int)(x * TABLE + 0.5);
   if (i >= TABLE) i = (TABLE-1) - (i-(TABLE-1));
+  if (i < 0) return 0.;
   return st->cos_tab[i];
 #elif 0
   return cos(x * M_PI/2);
@@ -718,19 +722,21 @@ sinc(struct state *st, double x)
 static void
 add_circle_drop(struct state *st, int x, int y, int radius, int dheight)
 {
-  int i, r2, cx, cy;
+  int r, r2, cx, cy;
   short *buf = (random()&1) ? st->bufferA : st->bufferB;
 
-  i = y * st->width + x;
   r2 = radius * radius;
 
+
   for (cy = -radius; cy <= radius; cy++)
     for (cx = -radius; cx <= radius; cx++) {
-      int r = cx*cx + cy*cy;
-      if (r <= r2) {
-        buf[i + cx + cy*st->width] =
-          (short)(dheight * sinc(st, sqrt(r)/radius));
-      }
+      int xx = x+cx;
+      int yy = y+cy;
+      if (xx < 0 || yy < 0 || xx >= st->width || yy >= st->height) {break;}
+      r = cx*cx + cy*cy;
+      if (r > r2) break;
+      buf[xx + yy*st->width] =
+        (short)(dheight * sinc(st, (radius > 0) ? sqrt(r)/radius : 0));
     }
 }
 
@@ -1091,16 +1097,19 @@ static const char *ripples_defaults[] =
   "*duration:          120",
   "*rate:              5",
   "*box:               0",
-  "*water:             False",
+  "*water:             True",
   "*oily:              False",
   "*stir:              False",
   "*fluidity:          6",
-  "*light:             0",
+  "*light:             4",
   "*grayscale:                 False",
 #ifdef HAVE_XSHM_EXTENSION
   "*useSHM: True",
 #else
   "*useSHM: False",
+#endif
+#ifdef USE_IPHONE
+  "*ignoreRotation: True",
 #endif
   0
 };