test/testwm.c
changeset 591 9c9598e4b904
parent 87 3ef4bc90c388
child 609 a30b17e09cc0
     1.1 --- a/test/testwm.c	Sat Feb 01 20:30:55 2003 +0000
     1.2 +++ b/test/testwm.c	Sat Feb 01 20:32:44 2003 +0000
     1.3 @@ -15,7 +15,7 @@
     1.4  	SDL_Surface *icon;
     1.5  	Uint8       *pixels;
     1.6  	Uint8       *mask;
     1.7 -	int          mlen, i;
     1.8 +	int          mlen, i, j;
     1.9  
    1.10  	*maskp = NULL;
    1.11  
    1.12 @@ -26,12 +26,15 @@
    1.13  		return(NULL);
    1.14  	}
    1.15  
    1.16 -	/* Check width and height */
    1.17 +	/* Check width and height 
    1.18  	if ( (icon->w%8) != 0 ) {
    1.19  		fprintf(stderr, "Icon width must be a multiple of 8!\n");
    1.20  		SDL_FreeSurface(icon);
    1.21  		return(NULL);
    1.22  	}
    1.23 +*/
    1.24 +    
    1.25 +    
    1.26  	if ( icon->format->palette == NULL ) {
    1.27  		fprintf(stderr, "Icon must have a palette!\n");
    1.28  		SDL_FreeSurface(icon);
    1.29 @@ -47,21 +50,21 @@
    1.30  				icon->format->palette->colors[*pixels].r,
    1.31  				icon->format->palette->colors[*pixels].g,
    1.32  				icon->format->palette->colors[*pixels].b);
    1.33 -	mlen = icon->w*icon->h;
    1.34 -	mask = (Uint8 *)malloc(mlen/8);
    1.35 +	mlen = (icon->w*icon->h + 7) / 8;
    1.36 +	mask = (Uint8 *)malloc(mlen);
    1.37  	if ( mask == NULL ) {
    1.38  		fprintf(stderr, "Out of memory!\n");
    1.39  		SDL_FreeSurface(icon);
    1.40  		return(NULL);
    1.41  	}
    1.42 -	memset(mask, 0, mlen/8);
    1.43 -	for ( i=0; i<mlen; ) {
    1.44 -		if ( pixels[i] != *pixels )
    1.45 -			mask[i/8] |= 0x01;
    1.46 -		++i;
    1.47 -		if ( (i%8) != 0 )
    1.48 -			mask[i/8] <<= 1;
    1.49 -	}
    1.50 +	memset(mask, 0, mlen);
    1.51 +	for ( i=0; i < icon->h; i++)
    1.52 +        for (j=0; j < icon->w; j++) {
    1.53 +            int pindex = i * icon->pitch + j;
    1.54 +            int mindex = i * icon->w + j;
    1.55 +            if ( pixels[pindex] != *pixels )
    1.56 +                mask[mindex>>3] |= 1 << (7 - (mindex & 7));
    1.57 +        }
    1.58  	*maskp = mask;
    1.59  	return(icon);
    1.60  }