# HG changeset patch # User Eli Gottlieb # Date 1279864122 14400 # Node ID 2ae79ed78a5a4dbe17232a683221a5bbb31ae4c5 # Parent c9eb95f29770d88010d3660e56f558415a2bdddc More work on color-key mode. diff -r c9eb95f29770 -r 2ae79ed78a5a src/video/SDL_shape.c --- a/src/video/SDL_shape.c Thu Jul 22 23:11:01 2010 -0400 +++ b/src/video/SDL_shape.c Fri Jul 23 01:48:42 2010 -0400 @@ -96,7 +96,7 @@ break; case(ShapeModeColorKey): key = mode.parameters.colorKey; - bitmap[bitmap_pixel / ppb] |= (key.r == r && key.g == g && key.b == b ? value : 0) << ((ppb - 1) - (bitmap_pixel % ppb)); + bitmap[bitmap_pixel / ppb] |= ((key.r == r && key.g == g && key.b == b) ? value : 0) << ((ppb - 1) - (bitmap_pixel % ppb)); break; } } diff -r c9eb95f29770 -r 2ae79ed78a5a test/testshape.c --- a/test/testshape.c Thu Jul 22 23:11:01 2010 -0400 +++ b/test/testshape.c Fri Jul 23 01:48:42 2010 -0400 @@ -14,6 +14,12 @@ #define TICK_INTERVAL 18 +typedef struct LoadedPicture { + SDL_Surface *surface; + SDL_Texture *texture; + SDL_WindowShapeMode mode; +} LoadedPicture; + void render(SDL_Window* window,SDL_Texture *texture,SDL_Rect texture_dimensions) { SDL_SelectRenderer(window); @@ -49,28 +55,39 @@ } Uint8 num_pictures = argc - 1; - SDL_Surface **pictures = malloc(sizeof(SDL_Surface*)*num_pictures); + LoadedPicture* pictures = malloc(sizeof(LoadedPicture)*num_pictures); int i = 0; for(i=0;iformat; + Uint32 format_enum = SDL_MasksToPixelFormatEnum (format->BitsPerPixel,format->Rmask,format->Gmask, format->Bmask,format->Amask); + if(SDL_ISPIXELFORMAT_ALPHA(format_enum)) { + pictures[i].mode.mode = ShapeModeBinarizeAlpha; + pictures[i].mode.parameters.binarizationCutoff = 1; + } + else { + pictures[i].mode.mode = ShapeModeColorKey; + SDL_Color black = {0,0,0,0xff}; + pictures[i].mode.parameters.colorKey = black; + } } SDL_Window *window = SDL_CreateShapedWindow("SDL_Shape test",SHAPED_WINDOW_X,SHAPED_WINDOW_Y,SHAPED_WINDOW_DIMENSION,SHAPED_WINDOW_DIMENSION,SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN); if(window == NULL) { for(i=0;i= num_pictures) current_picture = 0; - SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); + SDL_QueryTexture(pictures[current_picture].texture,&format,&access,&texture_dimensions.w,&texture_dimensions.h); SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); - SDL_SetWindowShape(window,pictures[current_picture],&mode); + SDL_SetWindowShape(window,pictures[current_picture].surface,&mode); } if(event.type == SDL_QUIT) should_exit = 1; event_pending = 0; } - render(window,textures[current_picture],texture_dimensions); + render(window,pictures[current_picture].texture,texture_dimensions); SDL_Delay(time_left()); next_time += TICK_INTERVAL; } //Free the textures. for(i=0;i