Mercurial > sdl-ios-xcode
comparison src/video/SDL_shape.c @ 4837:2e446923c9fb
Fixed lots of little bugs in Win32 shaping and in SDL_CalculateShapeTree(). Still not actually showing anything on Windows, though there's no crashes and everything compiles fine. Bugger.
author | egottlieb |
---|---|
date | Fri, 06 Aug 2010 20:22:14 -0400 |
parents | 7eb8ca721a5b |
children | 05d172e92b52 |
comparison
equal
deleted
inserted
replaced
4836:7eb8ca721a5b | 4837:2e446923c9fb |
---|---|
109 } | 109 } |
110 if(SDL_MUSTLOCK(shape)) | 110 if(SDL_MUSTLOCK(shape)) |
111 SDL_UnlockSurface(shape); | 111 SDL_UnlockSurface(shape); |
112 } | 112 } |
113 | 113 |
114 SDL_ShapeTree* RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_bool invert,SDL_Rect dimensions) { | 114 SDL_ShapeTree* RecursivelyCalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* mask,SDL_Rect dimensions) { |
115 int x = 0,y = 0; | 115 int x = 0,y = 0; |
116 Uint8* pixel = NULL; | 116 Uint8* pixel = NULL; |
117 Uint32 pixel_value = 0; | 117 Uint32 pixel_value = 0; |
118 Uint8 r = 0,g = 0,b = 0,a = 0; | 118 Uint8 r = 0,g = 0,b = 0,a = 0; |
119 SDL_bool pixel_transparent = SDL_FALSE; | 119 SDL_bool pixel_opaque = SDL_FALSE; |
120 int last_transparent = -1; | 120 int last_opaque = -1; |
121 SDL_Color key; | 121 SDL_Color key; |
122 SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree)); | 122 SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree)); |
123 SDL_Rect next = {0,0,0,0}; | 123 SDL_Rect next = {0,0,0,0}; |
124 for(y=dimensions.y;y<dimensions.h;y++) | 124 for(y=dimensions.y;y<dimensions.y + dimensions.h;y++) |
125 for(x=dimensions.x;x<dimensions.w;x++) { | 125 for(x=dimensions.x;x<dimensions.x + dimensions.w;x++) { |
126 pixel_value = 0; | 126 pixel_value = 0; |
127 pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel); | 127 pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel); |
128 switch(mask->format->BytesPerPixel) { | 128 switch(mask->format->BytesPerPixel) { |
129 case(1): | 129 case(1): |
130 pixel_value = *(Uint8*)pixel; | 130 pixel_value = *(Uint8*)pixel; |
140 break; | 140 break; |
141 } | 141 } |
142 SDL_GetRGBA(pixel_value,mask->format,&r,&g,&b,&a); | 142 SDL_GetRGBA(pixel_value,mask->format,&r,&g,&b,&a); |
143 switch(mode.mode) { | 143 switch(mode.mode) { |
144 case(ShapeModeDefault): | 144 case(ShapeModeDefault): |
145 pixel_transparent = (SDL_bool)(a >= 1 ? !invert : invert); | 145 pixel_opaque = (a >= 1 ? SDL_TRUE : SDL_FALSE); |
146 break; | 146 break; |
147 case(ShapeModeBinarizeAlpha): | 147 case(ShapeModeBinarizeAlpha): |
148 pixel_transparent = (SDL_bool)(a >= mode.parameters.binarizationCutoff ? !invert : invert); | 148 pixel_opaque = (a >= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE); |
149 break; | 149 break; |
150 case(ShapeModeReverseBinarizeAlpha): | 150 case(ShapeModeReverseBinarizeAlpha): |
151 pixel_transparent = (SDL_bool)(a <= mode.parameters.binarizationCutoff ? !invert : invert); | 151 pixel_opaque = (a <= mode.parameters.binarizationCutoff ? SDL_TRUE : SDL_FALSE); |
152 break; | 152 break; |
153 case(ShapeModeColorKey): | 153 case(ShapeModeColorKey): |
154 key = mode.parameters.colorKey; | 154 key = mode.parameters.colorKey; |
155 pixel_transparent = (SDL_bool)((key.r == r && key.g == g && key.b == b) ? !invert : invert); | 155 pixel_opaque = ((key.r == r && key.g == g && key.b == b) ? SDL_TRUE : SDL_FALSE); |
156 break; | 156 break; |
157 } | 157 } |
158 if(last_transparent == -1) { | 158 if(last_opaque == -1) |
159 last_transparent = pixel_transparent; | 159 last_opaque = pixel_opaque; |
160 break; | 160 if(last_opaque != pixel_opaque) { |
161 } | |
162 if(last_transparent != pixel_transparent) { | |
163 result->kind = QuadShape; | 161 result->kind = QuadShape; |
164 //These will stay the same. | 162 //These will stay the same. |
165 next.w = dimensions.w / 2; | 163 next.w = dimensions.w / 2; |
166 next.h = dimensions.h / 2; | 164 next.h = dimensions.h / 2; |
167 //These will change from recursion to recursion. | 165 //These will change from recursion to recursion. |
168 next.x = dimensions.x; | 166 next.x = dimensions.x; |
169 next.y = dimensions.y; | 167 next.y = dimensions.y; |
170 result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); | 168 result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next); |
171 next.x = dimensions.w / 2; | 169 next.x = dimensions.w / 2; |
172 //Unneeded: next.y = dimensions.y; | 170 //Unneeded: next.y = dimensions.y; |
173 result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); | 171 result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next); |
174 next.x = dimensions.x; | 172 next.x = dimensions.x; |
175 next.y = dimensions.h / 2; | 173 next.y = dimensions.h / 2; |
176 result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); | 174 result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next); |
177 next.x = dimensions.w / 2; | 175 next.x = dimensions.w / 2; |
178 //Unneeded: next.y = dimensions.h / 2 + 1; | 176 //Unneeded: next.y = dimensions.h / 2 + 1; |
179 result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); | 177 result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,next); |
180 return result; | 178 return result; |
181 } | 179 } |
182 } | 180 } |
183 //If we never recursed, all the pixels in this quadrant have the same "value". | 181 //If we never recursed, all the pixels in this quadrant have the same "value". |
184 result->kind = (last_transparent == SDL_FALSE ? OpaqueShape : TransparentShape); | 182 result->kind = (last_opaque == SDL_TRUE ? OpaqueShape : TransparentShape); |
185 result->data.shape = dimensions; | 183 result->data.shape = dimensions; |
186 return result; | 184 return result; |
187 } | 185 } |
188 | 186 |
189 SDL_ShapeTree* SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape,SDL_bool invert) { | 187 SDL_ShapeTree* SDL_CalculateShapeTree(SDL_WindowShapeMode mode,SDL_Surface* shape) { |
190 SDL_Rect dimensions = {0,0,shape->w,shape->h}; | 188 SDL_Rect dimensions = {0,0,shape->w,shape->h}; |
191 SDL_ShapeTree* result = NULL; | 189 SDL_ShapeTree* result = NULL; |
192 if(SDL_MUSTLOCK(shape)) | 190 if(SDL_MUSTLOCK(shape)) |
193 SDL_LockSurface(shape); | 191 SDL_LockSurface(shape); |
194 result = RecursivelyCalculateShapeTree(mode,shape,invert,dimensions); | 192 result = RecursivelyCalculateShapeTree(mode,shape,dimensions); |
195 if(SDL_MUSTLOCK(shape)) | 193 if(SDL_MUSTLOCK(shape)) |
196 SDL_UnlockSurface(shape); | 194 SDL_UnlockSurface(shape); |
197 return result; | 195 return result; |
198 } | 196 } |
199 | 197 |