comparison test/testwm.c @ 591:9c9598e4b904

Allow icons of any size
author Sam Lantinga <slouken@libsdl.org>
date Sat, 01 Feb 2003 20:32:44 +0000
parents 3ef4bc90c388
children a30b17e09cc0
comparison
equal deleted inserted replaced
590:3f1e241519d9 591:9c9598e4b904
13 SDL_Surface *LoadIconSurface(char *file, Uint8 **maskp) 13 SDL_Surface *LoadIconSurface(char *file, Uint8 **maskp)
14 { 14 {
15 SDL_Surface *icon; 15 SDL_Surface *icon;
16 Uint8 *pixels; 16 Uint8 *pixels;
17 Uint8 *mask; 17 Uint8 *mask;
18 int mlen, i; 18 int mlen, i, j;
19 19
20 *maskp = NULL; 20 *maskp = NULL;
21 21
22 /* Load the icon surface */ 22 /* Load the icon surface */
23 icon = SDL_LoadBMP(file); 23 icon = SDL_LoadBMP(file);
24 if ( icon == NULL ) { 24 if ( icon == NULL ) {
25 fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError()); 25 fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
26 return(NULL); 26 return(NULL);
27 } 27 }
28 28
29 /* Check width and height */ 29 /* Check width and height
30 if ( (icon->w%8) != 0 ) { 30 if ( (icon->w%8) != 0 ) {
31 fprintf(stderr, "Icon width must be a multiple of 8!\n"); 31 fprintf(stderr, "Icon width must be a multiple of 8!\n");
32 SDL_FreeSurface(icon); 32 SDL_FreeSurface(icon);
33 return(NULL); 33 return(NULL);
34 } 34 }
35 */
36
37
35 if ( icon->format->palette == NULL ) { 38 if ( icon->format->palette == NULL ) {
36 fprintf(stderr, "Icon must have a palette!\n"); 39 fprintf(stderr, "Icon must have a palette!\n");
37 SDL_FreeSurface(icon); 40 SDL_FreeSurface(icon);
38 return(NULL); 41 return(NULL);
39 } 42 }
45 pixels = (Uint8 *)icon->pixels; 48 pixels = (Uint8 *)icon->pixels;
46 printf("Transparent pixel: (%d,%d,%d)\n", 49 printf("Transparent pixel: (%d,%d,%d)\n",
47 icon->format->palette->colors[*pixels].r, 50 icon->format->palette->colors[*pixels].r,
48 icon->format->palette->colors[*pixels].g, 51 icon->format->palette->colors[*pixels].g,
49 icon->format->palette->colors[*pixels].b); 52 icon->format->palette->colors[*pixels].b);
50 mlen = icon->w*icon->h; 53 mlen = (icon->w*icon->h + 7) / 8;
51 mask = (Uint8 *)malloc(mlen/8); 54 mask = (Uint8 *)malloc(mlen);
52 if ( mask == NULL ) { 55 if ( mask == NULL ) {
53 fprintf(stderr, "Out of memory!\n"); 56 fprintf(stderr, "Out of memory!\n");
54 SDL_FreeSurface(icon); 57 SDL_FreeSurface(icon);
55 return(NULL); 58 return(NULL);
56 } 59 }
57 memset(mask, 0, mlen/8); 60 memset(mask, 0, mlen);
58 for ( i=0; i<mlen; ) { 61 for ( i=0; i < icon->h; i++)
59 if ( pixels[i] != *pixels ) 62 for (j=0; j < icon->w; j++) {
60 mask[i/8] |= 0x01; 63 int pindex = i * icon->pitch + j;
61 ++i; 64 int mindex = i * icon->w + j;
62 if ( (i%8) != 0 ) 65 if ( pixels[pindex] != *pixels )
63 mask[i/8] <<= 1; 66 mask[mindex>>3] |= 1 << (7 - (mindex & 7));
64 } 67 }
65 *maskp = mask; 68 *maskp = mask;
66 return(icon); 69 return(icon);
67 } 70 }
68 71
69 void HotKey_ToggleFullScreen(void) 72 void HotKey_ToggleFullScreen(void)