1 /* -*- mode: C; tab-width: 4 -*-
2 * Bumps, Copyright (c) 2002, 2006 Shane Smit <CodeWeaver@DigitalLoom.org>
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
16 * This is typical bump-mapping. The actual bump map is generated by a screen
17 * grab. The light source is represented by a spotlight of random color. This
18 * spotlight randomly traverses the bump map in a sinus pattern.
20 * Essentially, it 3D-izes your desktop, based on color intensity.
22 * Modification History:
23 * [10/01/1999] - Shane Smit: Creation
24 * [10/08/1999] - Shane Smit: Port to C. (Ick)
25 * [03/08/2002] - Shane Smit: New movement code.
26 * [09/12/2002] - Shane Smit: MIT-SHM XImages.
27 * Thanks to Kennett Galbraith <http://www.Alpha-II.com/>
28 * for code optimization.
29 * [10/09/2016] - Dave Odell: Updated for new xshm.c.
37 #include "screenhack.h"
43 #define RANDOM() ((int) (random() & 0X7FFFFFFFL))
45 typedef unsigned char BOOL;
50 static const char *bumps_defaults [] = {
60 #ifdef __sgi /* really, HAVE_READ_DISPLAY_EXTENSION */
63 #ifdef HAVE_XSHM_EXTENSION
65 #endif /* HAVE_XSHM_EXTENSION */
67 "*ignoreRotation: True",
68 "*rotateImages: True",
73 static XrmOptionDescRec bumps_options [] = {
74 { "-color", ".color", XrmoptionSepArg, 0 },
75 { "-colorcount", ".colorcount", XrmoptionSepArg, 0 },
76 { "-duration", ".duration", XrmoptionSepArg, 0 },
77 { "-delay", ".delay", XrmoptionSepArg, 0 },
78 { "-soften", ".soften", XrmoptionSepArg, 0 },
79 { "-invert", ".invert", XrmoptionNoArg, "TRUE" },
80 #ifdef HAVE_XSHM_EXTENSION
81 { "-shm", ".useSHM", XrmoptionNoArg, "True" },
82 { "-no-shm", ".useSHM", XrmoptionNoArg, "False" },
83 #endif /* HAVE_XSHM_EXTENSION */
89 /* This structure handles everything to do with the spotlight, and is designed to be
90 * a member of TBumps. */
94 uint16_t nFalloffDiameter, nFalloffRadius;
95 uint16_t nLightDiameter, nLightRadius;
96 float nAccelX, nAccelY;
98 float nVelocityX, nVelocityY;
104 /* The entire program's operation is contained within this structure. */
107 /* XWindows specific variables. */
114 unsigned long *aColors;
116 XShmSegmentInfo XShmInfo;
118 uint8_t nColorCount; /* Number of colors used. */
119 uint8_t bytesPerPixel;
120 uint16_t iWinWidth, iWinHeight;
121 uint16_t *aBumpMap; /* The actual bump map. */
122 SSpotLight SpotLight;
128 async_load_state *img_loader;
132 static void SetPalette(Display *, SBumps *, XWindowAttributes * );
133 static void InitBumpMap(Display *, SBumps *, XWindowAttributes * );
134 static void InitBumpMap_2(Display *, SBumps *);
135 static void SoftenBumpMap( SBumps * );
140 /* This function pointer will point to the appropriate PutPixel*() function below. */
141 static void (*MyPutPixel)( int8_t *, uint32_t );
143 static void PutPixel32( int8_t *pData, uint32_t pixel )
145 *(uint32_t *)pData = pixel;
148 static void PutPixel24( int8_t *pData, uint32_t pixel )
150 pData[ 2 ] = ( pixel & 0x00FF0000 ) >> 16;
151 pData[ 1 ] = ( pixel & 0x0000FF00 ) >> 8;
152 pData[ 0 ] = ( pixel & 0x000000FF );
155 static void PutPixel16( int8_t *pData, uint32_t pixel )
157 *(uint16_t *)pData = (uint16_t)pixel;
160 static void PutPixel8( int8_t *pData, uint32_t pixel )
162 *(uint8_t *)pData = (uint8_t)pixel;
165 /* Creates the light map, which is a circular image... going from black around the edges
166 * to white in the center. */
167 static void CreateSpotLight( SSpotLight *pSpotLight, uint16_t iDiameter, uint16_t nColorCount )
170 int16_t iDistX, iDistY;
173 pSpotLight->nFalloffDiameter = iDiameter;
174 pSpotLight->nFalloffRadius = pSpotLight->nFalloffDiameter / 2;
175 pSpotLight->nLightDiameter = iDiameter / 2;
176 pSpotLight->nLightRadius = pSpotLight->nLightDiameter / 2;
178 printf( "%s: Falloff Diameter: %d\n", progclass, pSpotLight->nFalloffDiameter );
179 printf( "%s: Spot Light Diameter: %d\n", progclass, pSpotLight->nLightDiameter );
182 pSpotLight->aLightMap = malloc( pSpotLight->nLightDiameter * pSpotLight->nLightDiameter * sizeof(uint8_t) );
184 pLOffset = pSpotLight->aLightMap;
185 for( iDistY=-pSpotLight->nLightRadius; iDistY<pSpotLight->nLightRadius; ++iDistY )
187 for( iDistX=-pSpotLight->nLightRadius; iDistX<pSpotLight->nLightRadius; ++iDistX )
189 nDist = sqrt( pow( iDistX+0.5F, 2 ) + pow( iDistY+0.5F, 2 ) );
190 if( nDist / pSpotLight->nLightRadius <= 1.0f )
191 *pLOffset = (uint8_t)(nColorCount - ( ( nDist / pSpotLight->nLightRadius ) * ( nColorCount - 1 ) ));
199 /* Initialize movement variables. */
200 pSpotLight->nAccelX = 0;
201 pSpotLight->nAccelY = 0;
202 pSpotLight->nVelocityX = ( RANDOM() % 2 ) ? pSpotLight->nVelocityMax : -pSpotLight->nVelocityMax;
203 pSpotLight->nVelocityY = ( RANDOM() % 2 ) ? pSpotLight->nVelocityMax : -pSpotLight->nVelocityMax;
207 /* Calculates the position of the spot light on the screen. */
208 static void CalcLightPos( SBumps *pBumps )
210 SSpotLight *pSpotLight = &pBumps->SpotLight;
214 if( pSpotLight->nXPos < pSpotLight->nFalloffRadius ) nGravity = 1.0f;
215 else if( pSpotLight->nXPos > pBumps->iWinWidth - pSpotLight->nFalloffRadius ) nGravity = -1.0f;
216 else nGravity = ( ( RANDOM() % 201 ) / 100.0f ) - 1.0f;
218 pSpotLight->nAccelX += nGravity * ( pSpotLight->nAccelMax / 5.0f );
219 if( pSpotLight->nAccelX < -pSpotLight->nAccelMax ) pSpotLight->nAccelX = -pSpotLight->nAccelMax;
220 else if( pSpotLight->nAccelX > pSpotLight->nAccelMax ) pSpotLight->nAccelX = pSpotLight->nAccelMax;
222 pSpotLight->nVelocityX += pSpotLight->nAccelX;
223 if( pSpotLight->nVelocityX < -pSpotLight->nVelocityMax ) pSpotLight->nVelocityX = -pSpotLight->nVelocityMax;
224 else if( pSpotLight->nVelocityX > pSpotLight->nVelocityMax ) pSpotLight->nVelocityX = pSpotLight->nVelocityMax;
226 pSpotLight->nXPos += pSpotLight->nVelocityX;
229 if( pSpotLight->nYPos < pSpotLight->nFalloffRadius ) nGravity = 1.0f;
230 else if( pSpotLight->nYPos > pBumps->iWinHeight - pSpotLight->nFalloffRadius ) nGravity = -1.0f;
231 else nGravity = ( ( RANDOM() % 201 ) / 100.0f ) - 1.0f;
233 pSpotLight->nAccelY += nGravity * ( pSpotLight->nAccelMax / 5.0f );
234 if( pSpotLight->nAccelY < -pSpotLight->nAccelMax ) pSpotLight->nAccelY = -pSpotLight->nAccelMax;
235 else if( pSpotLight->nAccelY > pSpotLight->nAccelMax ) pSpotLight->nAccelY = pSpotLight->nAccelMax;
237 pSpotLight->nVelocityY += pSpotLight->nAccelY;
238 if( pSpotLight->nVelocityY < -pSpotLight->nVelocityMax ) pSpotLight->nVelocityY = -pSpotLight->nVelocityMax;
239 else if( pSpotLight->nVelocityY > pSpotLight->nVelocityMax ) pSpotLight->nVelocityY = pSpotLight->nVelocityMax;
241 pSpotLight->nYPos += pSpotLight->nVelocityY;
245 /* Main initialization function. */
246 static void CreateBumps( SBumps *pBumps, Display *dpy, Window NewWin )
248 XWindowAttributes XWinAttribs;
253 /* Make size and velocity a function of window size, so it appears the same at 100x60 as it does in 3200x1200. */
254 XGetWindowAttributes( dpy, NewWin, &XWinAttribs );
255 pBumps->iWinWidth = XWinAttribs.width;
256 pBumps->iWinHeight = XWinAttribs.height;
257 pBumps->SpotLight.nXPos = XWinAttribs.width / 2.0f;
258 pBumps->SpotLight.nYPos = XWinAttribs.height / 2.0f;
259 pBumps->SpotLight.nVelocityMax = ( ( XWinAttribs.width < XWinAttribs.height ) ? XWinAttribs.width : XWinAttribs.height ) / 140.0f;
260 pBumps->SpotLight.nAccelMax = pBumps->SpotLight.nVelocityMax / 10.0f;
262 pBumps->Win = NewWin;
263 pBumps->screen = XWinAttribs.screen;
265 iDiameter = ( ( pBumps->iWinWidth < pBumps->iWinHeight ) ? pBumps->iWinWidth : pBumps->iWinHeight ) / 2;
267 /* jwz: sometimes we get tearing if this lands on the wrong bounaary;
268 constraining it to be a multiple of 8 seems to fix it. */
269 iDiameter = ((iDiameter+7)/8)*8;
271 pBumps->pXImage = create_xshm_image( pBumps->dpy, XWinAttribs.visual, XWinAttribs.depth,
272 ZPixmap, &pBumps->XShmInfo, iDiameter, iDiameter );
274 /* For speed, access the XImage data directly using my own PutPixel routine. */
275 switch( pBumps->pXImage->bits_per_pixel )
278 pBumps->bytesPerPixel = 4;
279 MyPutPixel = PutPixel32;
283 pBumps->bytesPerPixel = 3;
284 MyPutPixel = PutPixel24;
288 pBumps->bytesPerPixel = 2;
289 MyPutPixel = PutPixel16;
293 pBumps->bytesPerPixel = 1;
294 MyPutPixel = PutPixel8;
298 fprintf( stderr, "%s: Unknown XImage depth.", progname );
299 destroy_xshm_image( pBumps->dpy, pBumps->pXImage, &pBumps->XShmInfo );
303 GCValues.function = GXcopy;
304 GCValues.subwindow_mode = IncludeInferiors;
305 nGCFlags = GCFunction;
306 if( use_subwindow_mode_p( XWinAttribs.screen, pBumps->Win ) ) /* See grabscreen.c */
307 nGCFlags |= GCSubwindowMode;
308 pBumps->GraphicsContext = XCreateGC( pBumps->dpy, pBumps->Win, nGCFlags, &GCValues );
310 SetPalette(dpy, pBumps, &XWinAttribs );
311 CreateSpotLight( &pBumps->SpotLight, iDiameter, pBumps->nColorCount );
312 InitBumpMap(dpy, pBumps, &XWinAttribs );
316 /* Creates a specialized phong shade palette. */
317 static void SetPalette(Display *dpy, SBumps *pBumps, XWindowAttributes *pXWinAttribs )
321 char *sColor; /* Spotlight Color */
324 sColor = get_string_resource(dpy, "color", "Color" );
326 BaseColor.red = RANDOM() % 0xFFFF;
327 BaseColor.green = RANDOM() % 0xFFFF;
328 BaseColor.blue = RANDOM() % 0xFFFF;
330 /* Make one color full intesity to avoid dark spotlights. */
331 switch( RANDOM() % 3 )
333 case 0: BaseColor.red = 0xFFFF; break;
334 case 1: BaseColor.green = 0xFFFF; break;
335 case 2: BaseColor.blue = 0xFFFF; break;
338 if( strcasecmp( sColor, "random" ) && !XParseColor( pBumps->dpy, pXWinAttribs->colormap, sColor, &BaseColor ) )
339 fprintf( stderr, "%s: color %s not found in database. Choosing random...\n", progname, sColor );
342 printf( "%s: Spotlight color is <%d,%d,%d> RGB.\n", progclass, BaseColor.red, BaseColor.green, BaseColor.blue );
345 pBumps->nColorCount = get_integer_resource(dpy, "colorcount", "Integer" );
346 if( pBumps->nColorCount < 2 ) pBumps->nColorCount = 2;
347 if( pBumps->nColorCount > 128 ) pBumps->nColorCount = 128;
349 pBumps->aColors = malloc( pBumps->nColorCount * sizeof(unsigned long) );
351 /* Creates a phong shade: / BaseColor \ Index/ColorCount
352 * PhongShade = | ------------ | Index + ( 65535 - BaseColor )^
354 pBumps->nColorCount--;
355 for( iColor=0; iColor<=pBumps->nColorCount; iColor++ )
357 Color.red = (uint16_t)( ( ( BaseColor.red / (double)pBumps->nColorCount ) * iColor ) + pow( 0xFFFF - BaseColor.red, iColor/(double)pBumps->nColorCount ) );
358 Color.green = (uint16_t)( ( ( BaseColor.green / (double)pBumps->nColorCount ) * iColor ) + pow( 0xFFFF - BaseColor.green, iColor/(double)pBumps->nColorCount ) );
359 Color.blue = (uint16_t)( ( ( BaseColor.blue / (double)pBumps->nColorCount ) * iColor ) + pow( 0xFFFF - BaseColor.blue, iColor/(double)pBumps->nColorCount ) );
361 if( !XAllocColor( pBumps->dpy, pXWinAttribs->colormap, &Color ) )
363 XFreeColors( pBumps->dpy, pXWinAttribs->colormap, pBumps->aColors, iColor, 0 );
364 free( pBumps->aColors );
365 pBumps->aColors = malloc( pBumps->nColorCount * sizeof(unsigned long) );
366 pBumps->nColorCount--;
370 pBumps->aColors[ iColor ] = Color.pixel;
372 pBumps->nColorCount++;
375 printf( "%s: Allocated %d colors.\n", progclass, pBumps->nColorCount );
378 XSetWindowBackground( pBumps->dpy, pBumps->Win, pBumps->aColors[ 0 ] );
382 /* Grabs the current contents of the window to use an intensity-based bump map. */
383 static void InitBumpMap(Display *dpy, SBumps *pBumps, XWindowAttributes *pXWinAttribs )
385 pBumps->xColors = (XColor*)malloc( pBumps->iWinWidth * sizeof(XColor) );
387 if (pBumps->source) abort();
388 pBumps->source = XCreatePixmap(pBumps->dpy, pBumps->Win,
389 pXWinAttribs->width, pXWinAttribs->height,
390 pXWinAttribs->depth);
391 pBumps->img_loader = load_image_async_simple (0, pXWinAttribs->screen,
392 pBumps->Win, pBumps->source, 0, 0);
395 static void InitBumpMap_2(Display *dpy, SBumps *pBumps)
397 XImage *pScreenImage;
400 uint16_t iWidth, iHeight;
404 double softenMultiplier = 1.0f;
405 BOOL bInvert = (BOOL)get_boolean_resource(dpy, "invert", "Boolean" );
406 XWindowAttributes XWinAttribs;
407 XGetWindowAttributes( pBumps->dpy, pBumps->Win, &XWinAttribs );
409 pBumps->start_time = time ((time_t *) 0);
411 pScreenImage = XGetImage( pBumps->dpy, pBumps->source, 0, 0,
412 pBumps->iWinWidth, pBumps->iWinHeight,
414 /* XFreePixmap (pBumps->dpy, pBumps->source);
415 pBumps->source = 0;*/
417 XSetWindowBackground( pBumps->dpy, pBumps->Win, pBumps->aColors[ 0 ] );
418 XClearWindow (pBumps->dpy, pBumps->Win);
419 XSync (pBumps->dpy, 0);
421 pBumps->aBumpMap = malloc( pBumps->iWinWidth * pBumps->iWinHeight * sizeof(uint16_t) );
423 nSoften = get_integer_resource(dpy, "soften", "Integer" );
425 softenMultiplier *= 1.0f + ( 1.0f / 3.0f ); /* Softening takes the max height down, so scale up to compensate. */
426 maxHeight = pBumps->SpotLight.nLightRadius * softenMultiplier;
427 nAverager = maxHeight ? ( 3 * 0xFFFF ) / maxHeight : 0;
429 pBump = pBumps->aBumpMap;
430 if( bInvert ) /* Funny, it's actually the 'else' that inverts the bump map... */
432 for( iHeight=0; iHeight<pBumps->iWinHeight; iHeight++ )
434 pColor = pBumps->xColors;
435 for( iWidth=0; iWidth<pBumps->iWinWidth; iWidth++ )
436 (pColor++)->pixel = XGetPixel( pScreenImage, iWidth, iHeight );
438 XQueryColors( pBumps->dpy, XWinAttribs.colormap, pBumps->xColors, pBumps->iWinWidth );
440 pColor = pBumps->xColors;
441 for( iWidth=pBumps->iWinWidth; iWidth; --iWidth, ++pColor, ++pBump )
442 *pBump = ( nAverager ? ( pColor->red + pColor->green + pColor->blue ) / nAverager : 0 );
447 for( iHeight=0; iHeight<pBumps->iWinHeight; iHeight++ )
449 pColor = pBumps->xColors;
450 for( iWidth=0; iWidth<pBumps->iWinWidth; iWidth++ )
451 (pColor++)->pixel = XGetPixel( pScreenImage, iWidth, iHeight );
453 XQueryColors( pBumps->dpy, XWinAttribs.colormap, pBumps->xColors, pBumps->iWinWidth );
455 pColor = pBumps->xColors;
456 for( iWidth=pBumps->iWinWidth; iWidth; --iWidth, ++pColor, ++pBump )
457 *pBump = ( maxHeight - ( nAverager ? ( pColor->red + pColor->green + pColor->blue ) / nAverager : 0 ) );
461 XDestroyImage( pScreenImage );
463 nSoften = get_integer_resource(dpy, "soften", "Integer" );
465 if( nSoften ) printf( "%s: Softening Bump Map %d time(s)...\n", progclass, nSoften );
468 SoftenBumpMap( pBumps );
470 /* free( pBumps->xColors );
471 pBumps->xColors = 0;*/
474 /* Soften the bump map. This is to avoid pixelated-looking ridges.
475 * |-----|-----|-----|
476 * | 0% |12.5%| 0% | The adjacent pixels are averaged together
477 * |-----|-----|-----| first. Then than value is averaged with
478 * |12.5%| 50% |12.5%| the pixel is question. This essentially weights
479 * |-----|-----|-----| each pixel as shown on the left.
481 * |-----|-----|-----|
483 static void SoftenBumpMap( SBumps *pBumps )
485 uint16_t *pOffset, *pTOffset;
487 uint32_t iWidth, iHeight;
488 uint16_t *aTempBuffer = malloc( pBumps->iWinWidth * pBumps->iWinHeight * sizeof(uint16_t) );
490 pOffset = pBumps->aBumpMap;
491 pTOffset = aTempBuffer;
492 for( iHeight=pBumps->iWinHeight; iHeight; --iHeight )
494 for( iWidth=pBumps->iWinWidth; iWidth; --iWidth, ++pOffset, ++pTOffset )
496 if( iHeight==pBumps->iWinHeight || iHeight==1 ||
497 iWidth==pBumps->iWinWidth || iWidth==1 )
503 nHeight = pOffset[ -pBumps->iWinWidth ];
504 nHeight += pOffset[ 1 ];
505 nHeight += pOffset[ pBumps->iWinWidth ];
506 nHeight += pOffset[ -1 ];
508 nHeight += pOffset[ 0 ];
514 memcpy( pBumps->aBumpMap, aTempBuffer, pBumps->iWinWidth * pBumps->iWinHeight * sizeof(uint16_t) );
519 /* This is where we slap down some pixels... */
520 static void Execute( SBumps *pBumps )
522 int32_t nLightXPos, nLightYPos;
523 int32_t iScreenX, iScreenY;
524 int32_t iLightX, iLightY;
529 int32_t nLightOffsetFar = pBumps->SpotLight.nFalloffDiameter - pBumps->SpotLight.nLightRadius;
531 CalcLightPos( pBumps );
533 /* Offset to upper left hand corner. */
534 nLightXPos = pBumps->SpotLight.nXPos - pBumps->SpotLight.nFalloffRadius;
535 nLightYPos = pBumps->SpotLight.nYPos - pBumps->SpotLight.nFalloffRadius;
537 for( iScreenY=nLightYPos, iLightY=-pBumps->SpotLight.nLightRadius; iLightY<nLightOffsetFar; ++iScreenY, ++iLightY )
539 if( iScreenY < 0 ) continue;
540 else if( iScreenY >= pBumps->iWinHeight ) break;
542 /* warning: pointer targets in assignment differ in signedness
543 Should pDOffset be a int8? I can't tell. -jwz, 22-Jul-2003 */
544 pDOffset = (int8_t *) &pBumps->pXImage->data[ (iLightY+pBumps->SpotLight.nLightRadius) * pBumps->pXImage->bytes_per_line ];
545 pBOffset = pBumps->aBumpMap + ( iScreenY * pBumps->iWinWidth ) + nLightXPos;
546 for( iScreenX=nLightXPos, iLightX=-pBumps->SpotLight.nLightRadius; iLightX<nLightOffsetFar; ++iScreenX, ++iLightX, ++pBOffset, pDOffset+=pBumps->bytesPerPixel )
548 if( iScreenX < 0 ) continue;
549 else if( iScreenX >= pBumps->iWinWidth ) break;
550 else if( iScreenY == 0 || iScreenY >= pBumps->iWinHeight-2 ||
551 iScreenX == 0 || iScreenX >= pBumps->iWinWidth-2 )
553 MyPutPixel( pDOffset, pBumps->aColors[ 0 ] );
557 /* That's right folks, all the magic of bump mapping occurs in these two lines. (kinda disappointing, isn't it?) */
558 nX = ( pBOffset[ 1 ] - pBOffset[ 0 ] ) + iLightX;
559 nY = ( pBOffset[ pBumps->iWinWidth ] - pBOffset[ 0 ] ) + iLightY;
561 if( nX<0 || nX>=pBumps->SpotLight.nLightDiameter
562 || nY<0 || nY>=pBumps->SpotLight.nLightDiameter )
564 MyPutPixel( pDOffset, pBumps->aColors[ 0 ] );
568 nColor = pBumps->SpotLight.aLightMap[ ( nY * pBumps->SpotLight.nLightDiameter ) + nX ];
569 MyPutPixel( pDOffset, pBumps->aColors[ nColor ] );
573 /* Allow the spotlight to go *slightly* off the screen by clipping the XImage. */
574 iLightX = iLightY = 0; /* Use these for XImages X and Y now. */
575 nX = nY = pBumps->SpotLight.nFalloffDiameter; /* Use these for XImage width and height now. */
578 iLightX = -nLightXPos;
582 else if( nLightXPos + nX >= pBumps->iWinWidth )
584 nX -= ( nLightXPos + nX ) - pBumps->iWinWidth;
589 iLightY = -nLightYPos;
593 else if( nLightYPos + nY >= pBumps->iWinHeight )
595 nY -= ( nLightYPos + nY ) - pBumps->iWinHeight;
598 put_xshm_image( pBumps->dpy, pBumps->Win, pBumps->GraphicsContext, pBumps->pXImage, iLightX, iLightY, nLightXPos, nLightYPos,
599 nX, nY, &pBumps->XShmInfo);
603 static void DestroySpotLight( SSpotLight *pSpotLight ) { free( pSpotLight->aLightMap ); }
606 static void DestroyBumps( SBumps *pBumps )
608 DestroySpotLight( &pBumps->SpotLight );
609 free( pBumps->aColors );
610 free( pBumps->aBumpMap );
611 destroy_xshm_image( pBumps->dpy, pBumps->pXImage, &pBumps->XShmInfo );
615 /* All messages to the screensaver are processed here. */
617 bumps_init (Display *dpy, Window Win)
619 SBumps *Bumps = (SBumps *) calloc (1, sizeof(SBumps));
622 time_t Time = time( NULL );
626 CreateBumps( Bumps, dpy, Win );
627 Bumps->delay = get_integer_resource(dpy, "delay", "Integer" );
628 Bumps->duration = get_integer_resource (dpy, "duration", "Seconds");
629 if (Bumps->delay < 0) Bumps->delay = 0;
630 if (Bumps->duration < 1) Bumps->duration = 1;
631 Bumps->start_time = time ((time_t *) 0);
636 bumps_draw (Display *dpy, Window window, void *closure)
638 SBumps *Bumps = (SBumps *) closure;
640 if (Bumps->img_loader) /* still loading */
642 Bumps->img_loader = load_image_async_simple (Bumps->img_loader, 0, 0, 0, 0, 0);
643 if (! Bumps->img_loader) /* just finished */
644 InitBumpMap_2(dpy, Bumps);
648 if (!Bumps->img_loader &&
649 Bumps->start_time + Bumps->duration < time ((time_t *) 0)) {
650 Bumps->img_loader = load_image_async_simple (0, Bumps->screen,
651 Bumps->Win, Bumps->source,
659 if( Time - time( NULL ) )
661 printf( "FPS: %d\n", iFrame );
671 bumps_reshape (Display *dpy, Window window, void *closure,
672 unsigned int w, unsigned int h)
677 bumps_event (Display *dpy, Window window, void *closure, XEvent *event)
679 SBumps *Bumps = (SBumps *) closure;
680 if (screenhack_event_helper (dpy, window, event))
682 Bumps->start_time = 0;
690 bumps_free (Display *dpy, Window window, void *closure)
692 SBumps *Bumps = (SBumps *) closure;
693 DestroyBumps( Bumps );
697 XSCREENSAVER_MODULE ("Bumps", bumps)