X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fdistort.c;h=b9f6cee75ecdb9a6b3b4715a536792944627dc4b;hb=40eacb5812ef7c0e3374fb139afbb4f5bc8bbfb5;hp=97b4ffe829b1f4d76d72756a79905d4e45e36fb6;hpb=72c1f4c1dc6ab07fe121a327ff1c30bf51ef74c1;p=xscreensaver diff --git a/hacks/distort.c b/hacks/distort.c index 97b4ffe8..b9f6cee7 100644 --- a/hacks/distort.c +++ b/hacks/distort.c @@ -1,5 +1,5 @@ /* -*- mode: C; tab-width: 4 -*- - * xscreensaver, Copyright (c) 1992, 1993, 1994, 1996, 1997, 1998 + * xscreensaver, Copyright (c) 1992, 1993, 1994, 1996, 1997, 1998, 2002, 2003 * Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its @@ -113,6 +113,8 @@ static void init_distort(Display *dpy, Window window) if (get_boolean_resource("bounce", "Boolean")) effect = &move_lense; + XGetWindowAttributes (dpy, window, &xgwa); + if (effect == NULL && radius == 0 && speed == 0 && number == 0 && !blackhole && !vortex && !magnify && !reflect) { /* if no cmdline options are given, randomly choose one of: @@ -201,8 +203,23 @@ static void init_distort(Display *dpy, Window window) abort(); break; } + /* but if the window is small, reduce default radius */ + if (xgwa.width < radius * 8) + radius = xgwa.width/8; } + /* never allow the radius to be too close to the min window dimension + */ + if (radius >= xgwa.width * 0.45) radius = xgwa.width * 0.45; + if (radius >= xgwa.height * 0.45) radius = xgwa.height * 0.45; + + + /* -swamp mode consumes vast amounts of memory, proportional to radius -- + so throttle radius to a small-ish value (60 => ~30MB.) + */ + if (effect == &swamp_thing && radius > 60) + radius = 60; + if (delay < 0) delay = 0; if (radius <= 0) @@ -222,7 +239,6 @@ static void init_distort(Display *dpy, Window window) if (draw == NULL) draw = &plain_draw; - XGetWindowAttributes (dpy, window, &xgwa); black_pixel = BlackPixelOfScreen( xgwa.screen ); gcv.function = GXcopy; @@ -232,7 +248,7 @@ static void init_distort(Display *dpy, Window window) gcflags |= GCSubwindowMode; gc = XCreateGC (dpy, window, gcflags, &gcv); - grab_screen_image (xgwa.screen, window); + load_random_image (xgwa.screen, window, window); buffer_map = 0; orig_map = XGetImage(dpy, window, 0, 0, xgwa.width, xgwa.height, @@ -564,6 +580,7 @@ static void reflect_draw(int k) ly = i - cy; lysq = ly * ly; ny = xy_coo[k].y + i; + if (ny >= orig_map->height) ny = orig_map->height-1; for(j = 0 ; j < 2*radius+speed+2 ; j++) { lx = j - cx; dist = lx * lx + lysq;