Commit 602b6f28 authored by Sam Lantinga's avatar Sam Lantinga

Allow icons of any size

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40592
parent a31d3a0a
...@@ -15,7 +15,7 @@ SDL_Surface *LoadIconSurface(char *file, Uint8 **maskp) ...@@ -15,7 +15,7 @@ SDL_Surface *LoadIconSurface(char *file, Uint8 **maskp)
SDL_Surface *icon; SDL_Surface *icon;
Uint8 *pixels; Uint8 *pixels;
Uint8 *mask; Uint8 *mask;
int mlen, i; int mlen, i, j;
*maskp = NULL; *maskp = NULL;
...@@ -26,12 +26,15 @@ SDL_Surface *LoadIconSurface(char *file, Uint8 **maskp) ...@@ -26,12 +26,15 @@ SDL_Surface *LoadIconSurface(char *file, Uint8 **maskp)
return(NULL); return(NULL);
} }
/* Check width and height */ /* Check width and height
if ( (icon->w%8) != 0 ) { if ( (icon->w%8) != 0 ) {
fprintf(stderr, "Icon width must be a multiple of 8!\n"); fprintf(stderr, "Icon width must be a multiple of 8!\n");
SDL_FreeSurface(icon); SDL_FreeSurface(icon);
return(NULL); return(NULL);
} }
*/
if ( icon->format->palette == NULL ) { if ( icon->format->palette == NULL ) {
fprintf(stderr, "Icon must have a palette!\n"); fprintf(stderr, "Icon must have a palette!\n");
SDL_FreeSurface(icon); SDL_FreeSurface(icon);
...@@ -47,21 +50,21 @@ SDL_Surface *LoadIconSurface(char *file, Uint8 **maskp) ...@@ -47,21 +50,21 @@ SDL_Surface *LoadIconSurface(char *file, Uint8 **maskp)
icon->format->palette->colors[*pixels].r, icon->format->palette->colors[*pixels].r,
icon->format->palette->colors[*pixels].g, icon->format->palette->colors[*pixels].g,
icon->format->palette->colors[*pixels].b); icon->format->palette->colors[*pixels].b);
mlen = icon->w*icon->h; mlen = (icon->w*icon->h + 7) / 8;
mask = (Uint8 *)malloc(mlen/8); mask = (Uint8 *)malloc(mlen);
if ( mask == NULL ) { if ( mask == NULL ) {
fprintf(stderr, "Out of memory!\n"); fprintf(stderr, "Out of memory!\n");
SDL_FreeSurface(icon); SDL_FreeSurface(icon);
return(NULL); return(NULL);
} }
memset(mask, 0, mlen/8); memset(mask, 0, mlen);
for ( i=0; i<mlen; ) { for ( i=0; i < icon->h; i++)
if ( pixels[i] != *pixels ) for (j=0; j < icon->w; j++) {
mask[i/8] |= 0x01; int pindex = i * icon->pitch + j;
++i; int mindex = i * icon->w + j;
if ( (i%8) != 0 ) if ( pixels[pindex] != *pixels )
mask[i/8] <<= 1; mask[mindex>>3] |= 1 << (7 - (mindex & 7));
} }
*maskp = mask; *maskp = mask;
return(icon); return(icon);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment