# HG changeset patch # User Sam Lantinga # Date 1044131564 0 # Node ID 9c9598e4b904ebb2f07fa8407cd1e0d56649c055 # Parent 3f1e241519d92c54f94bfc5d5878e6b74b84d8a0 Allow icons of any size diff -r 3f1e241519d9 -r 9c9598e4b904 test/testwm.c --- a/test/testwm.c Sat Feb 01 20:30:55 2003 +0000 +++ b/test/testwm.c Sat Feb 01 20:32:44 2003 +0000 @@ -15,7 +15,7 @@ SDL_Surface *icon; Uint8 *pixels; Uint8 *mask; - int mlen, i; + int mlen, i, j; *maskp = NULL; @@ -26,12 +26,15 @@ return(NULL); } - /* Check width and height */ + /* Check width and height if ( (icon->w%8) != 0 ) { fprintf(stderr, "Icon width must be a multiple of 8!\n"); SDL_FreeSurface(icon); return(NULL); } +*/ + + if ( icon->format->palette == NULL ) { fprintf(stderr, "Icon must have a palette!\n"); SDL_FreeSurface(icon); @@ -47,21 +50,21 @@ icon->format->palette->colors[*pixels].r, icon->format->palette->colors[*pixels].g, icon->format->palette->colors[*pixels].b); - mlen = icon->w*icon->h; - mask = (Uint8 *)malloc(mlen/8); + mlen = (icon->w*icon->h + 7) / 8; + mask = (Uint8 *)malloc(mlen); if ( mask == NULL ) { fprintf(stderr, "Out of memory!\n"); SDL_FreeSurface(icon); return(NULL); } - memset(mask, 0, mlen/8); - for ( i=0; ih; i++) + for (j=0; j < icon->w; j++) { + int pindex = i * icon->pitch + j; + int mindex = i * icon->w + j; + if ( pixels[pindex] != *pixels ) + mask[mindex>>3] |= 1 << (7 - (mindex & 7)); + } *maskp = mask; return(icon); }