Mercurial > sdl-ios-xcode
comparison src/video/SDL_shape.c @ 4802:f14a8c05f5bb
Minor bugfixes. testshape now draws a shaped window with bizarre, pixellated gashes of transparency across it, and in doing so seems to hog a system resource and slow the rest of the video system down.
author | Eli Gottlieb <eligottlieb@gmail.com> |
---|---|
date | Sun, 18 Jul 2010 23:05:40 -0400 |
parents | 506a9165491b |
children | 007567dbb8c1 |
comparison
equal
deleted
inserted
replaced
4801:506a9165491b | 4802:f14a8c05f5bb |
---|---|
57 /* REQUIRES that bitmap point to a w-by-h bitmap with 1bpp. */ | 57 /* REQUIRES that bitmap point to a w-by-h bitmap with 1bpp. */ |
58 void SDL_CalculateShapeBitmap(Uint8 alphacutoff,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb,Uint8 value) { | 58 void SDL_CalculateShapeBitmap(Uint8 alphacutoff,SDL_Surface *shape,Uint8* bitmap,Uint8 ppb,Uint8 value) { |
59 int x = 0; | 59 int x = 0; |
60 int y = 0; | 60 int y = 0; |
61 Uint8 r = 0,g = 0,b = 0,alpha = 0; | 61 Uint8 r = 0,g = 0,b = 0,alpha = 0; |
62 Uint8* pixel; | 62 Uint8* pixel = NULL; |
63 Uint32 bitmap_pixel; | 63 Uint32 bitmap_pixel,pixel_value = 0; |
64 if(SDL_MUSTLOCK(shape)) | 64 if(SDL_MUSTLOCK(shape)) |
65 SDL_LockSurface(shape); | 65 SDL_LockSurface(shape); |
66 pixel = (Uint8*)shape->pixels; | 66 pixel = (Uint8*)shape->pixels; |
67 for(y = 0;y<shape->h;y++) { | 67 for(y = 0;y<shape->h;y++) { |
68 pixel = (Uint8 *)(shape->pixels) + y * shape->pitch; | |
69 for(x=0;x<shape->w;x++) { | 68 for(x=0;x<shape->w;x++) { |
70 alpha = 0; | 69 alpha = 0; |
71 SDL_GetRGBA(*(Uint32*)pixel,shape->format,&r,&g,&b,&alpha); | 70 pixel_value = 0; |
71 pixel = shape->pixels + y * shape->pitch + x * shape->format->BytesPerPixel; | |
72 switch(shape->format->BytesPerPixel) { | |
73 case(1): | |
74 pixel_value = *(Uint8*)pixel; | |
75 break; | |
76 case(2): | |
77 pixel_value = *(Uint16*)pixel; | |
78 break; | |
79 case(4): | |
80 pixel_value = *(Uint32*)pixel; | |
81 break; | |
82 } | |
83 SDL_GetRGBA(pixel_value,shape->format,&r,&g,&b,&alpha); | |
72 bitmap_pixel = y*shape->w + x; | 84 bitmap_pixel = y*shape->w + x; |
73 bitmap[bitmap_pixel / ppb] |= (alpha >= alphacutoff ? value : 0) << ((ppb - 1) - (bitmap_pixel % ppb)); | 85 bitmap[bitmap_pixel / ppb] |= (alpha >= alphacutoff ? value : 0) << ((ppb - 1) - (bitmap_pixel % ppb)); |
74 pixel += shape->format->BytesPerPixel; | |
75 } | 86 } |
76 } | 87 } |
77 if(SDL_MUSTLOCK(shape)) | 88 if(SDL_MUSTLOCK(shape)) |
78 SDL_UnlockSurface(shape); | 89 SDL_UnlockSurface(shape); |
79 } | 90 } |
97 window->shaper->alphacutoff = shapeMode->parameters.binarizationCutoff; | 108 window->shaper->alphacutoff = shapeMode->parameters.binarizationCutoff; |
98 break; | 109 break; |
99 } | 110 } |
100 } | 111 } |
101 } | 112 } |
102 //TODO: Platform-specific implementations of SetWindowShape. X11 is finished. Win32 is in progress. | 113 //TODO: Platform-specific implementations of SetWindowShape. X11 is finished. Win32 is finished. Debugging is in progress on both. |
103 result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shapeMode); | 114 result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shapeMode); |
104 window->shaper->hasshape = SDL_TRUE; | 115 window->shaper->hasshape = SDL_TRUE; |
105 if((window->shaper->usershownflag & SDL_WINDOW_SHOWN) == SDL_WINDOW_SHOWN) { | 116 if((window->shaper->usershownflag & SDL_WINDOW_SHOWN) == SDL_WINDOW_SHOWN) { |
106 SDL_ShowWindow(window); | 117 SDL_ShowWindow(window); |
107 window->shaper->usershownflag &= !SDL_WINDOW_SHOWN; | 118 window->shaper->usershownflag &= !SDL_WINDOW_SHOWN; |