comparison src/video/SDL_shape.c @ 4817:c68e7490e4cf

Fixed a couple of bugs in the general and X11 shape code, and fixed a bug in testshape that was keeping it from recognizing surfaces without alpha. Thanks to Andreas's bit-bashing tip, X11 shaped windows now work entirely, AFAICT.
author Eli Gottlieb <eligottlieb@gmail.com>
date Sun, 01 Aug 2010 21:10:42 -0400
parents 93402b9dd20c
children 55f32099a4b5
comparison
equal deleted inserted replaced
4816:eb433f0d2ac5 4817:c68e7490e4cf
25 #include "SDL_video.h" 25 #include "SDL_video.h"
26 #include "SDL_sysvideo.h" 26 #include "SDL_sysvideo.h"
27 #include "SDL_pixels.h" 27 #include "SDL_pixels.h"
28 #include "SDL_surface.h" 28 #include "SDL_surface.h"
29 #include "SDL_shape.h" 29 #include "SDL_shape.h"
30 #include "SDL_shape_internals.h" 30 #include "../src/video/SDL_shape_internals.h"
31 31
32 SDL_Window* SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) { 32 SDL_Window* SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) {
33 SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,SDL_WINDOW_BORDERLESS | flags & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN); 33 SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,SDL_WINDOW_BORDERLESS | flags & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN);
34 if(result != NULL) { 34 if(result != NULL) {
35 result->shaper = result->display->device->shape_driver.CreateShaper(result); 35 result->shaper = result->display->device->shape_driver.CreateShaper(result);
55 else 55 else
56 return (SDL_bool)(window->shaper != NULL); 56 return (SDL_bool)(window->shaper != NULL);
57 } 57 }
58 58
59 /* REQUIRES that bitmap point to a w-by-h bitmap with ppb pixels-per-byte. */ 59 /* REQUIRES that bitmap point to a w-by-h bitmap with ppb pixels-per-byte. */
60 void SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb,Uint8 value) { 60 void SDL_CalculateShapeBitmap(SDL_WindowShapeMode mode,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb) {
61 int x = 0; 61 int x = 0;
62 int y = 0; 62 int y = 0;
63 Uint8 r = 0,g = 0,b = 0,alpha = 0; 63 Uint8 r = 0,g = 0,b = 0,alpha = 0;
64 Uint8* pixel = NULL; 64 Uint8* pixel = NULL;
65 Uint32 bitmap_pixel,pixel_value = 0; 65 Uint32 bitmap_pixel,pixel_value = 0,mask_value = 0;
66 SDL_Color key; 66 SDL_Color key;
67 if(SDL_MUSTLOCK(shape)) 67 if(SDL_MUSTLOCK(shape))
68 SDL_LockSurface(shape); 68 SDL_LockSurface(shape);
69 pixel = (Uint8*)shape->pixels; 69 pixel = (Uint8*)shape->pixels;
70 for(y = 0;y<shape->h;y++) { 70 for(y = 0;y<shape->h;y++) {
77 pixel_value = *(Uint8*)pixel; 77 pixel_value = *(Uint8*)pixel;
78 break; 78 break;
79 case(2): 79 case(2):
80 pixel_value = *(Uint16*)pixel; 80 pixel_value = *(Uint16*)pixel;
81 break; 81 break;
82 case(3):
83 pixel_value = *(Uint32*)pixel & (~shape->format->Amask);
84 break;
82 case(4): 85 case(4):
83 pixel_value = *(Uint32*)pixel; 86 pixel_value = *(Uint32*)pixel;
84 break; 87 break;
85 } 88 }
86 SDL_GetRGBA(pixel_value,shape->format,&r,&g,&b,&alpha); 89 SDL_GetRGBA(pixel_value,shape->format,&r,&g,&b,&alpha);
87 bitmap_pixel = y*shape->w + x; 90 bitmap_pixel = y*shape->w + x;
88 switch(mode.mode) { 91 switch(mode.mode) {
89 case(ShapeModeDefault): 92 case(ShapeModeDefault):
90 bitmap[bitmap_pixel / ppb] |= (alpha >= 1 ? value : 0) << ((ppb - 1) - (bitmap_pixel % ppb)); 93 mask_value = (alpha >= 1 ? 1 : 0);
91 break; 94 break;
92 case(ShapeModeBinarizeAlpha): 95 case(ShapeModeBinarizeAlpha):
93 bitmap[bitmap_pixel / ppb] |= (alpha >= mode.parameters.binarizationCutoff ? value : 0) << ((ppb - 1) - (bitmap_pixel % ppb)); 96 mask_value = (alpha >= mode.parameters.binarizationCutoff ? 1 : 0);
94 break; 97 break;
95 case(ShapeModeReverseBinarizeAlpha): 98 case(ShapeModeReverseBinarizeAlpha):
96 bitmap[bitmap_pixel / ppb] |= (alpha <= mode.parameters.binarizationCutoff ? value : 0) << ((ppb - 1) - (bitmap_pixel % ppb)); 99 mask_value = (alpha <= mode.parameters.binarizationCutoff ? 1 : 0);
97 break; 100 break;
98 case(ShapeModeColorKey): 101 case(ShapeModeColorKey):
99 key = mode.parameters.colorKey; 102 key = mode.parameters.colorKey;
100 bitmap[bitmap_pixel / ppb] |= ((key.r == r && key.g == g && key.b == b) ? value : 0) << ((ppb - 1) - (bitmap_pixel % ppb)); 103 mask_value = ((key.r != r && key.g != g && key.b != b) ? 1 : 0);
101 break; 104 break;
102 } 105 }
106 bitmap[bitmap_pixel / ppb] |= mask_value << (7 - ((ppb - 1) - (bitmap_pixel % ppb)));
103 } 107 }
104 } 108 }
105 if(SDL_MUSTLOCK(shape)) 109 if(SDL_MUSTLOCK(shape))
106 SDL_UnlockSurface(shape); 110 SDL_UnlockSurface(shape);
107 } 111 }