Mercurial > sdl-ios-xcode
comparison src/video/SDL_shape.c @ 4815:93402b9dd20c
Added Andreas's patch to fix my silly C++-style errors.
author | Eli Gottlieb <eligottlieb@gmail.com> |
---|---|
date | Thu, 29 Jul 2010 22:57:39 -0400 |
parents | 5b4c7d7d8953 |
children | c68e7490e4cf |
comparison
equal
deleted
inserted
replaced
4814:4f7133445367 | 4815:93402b9dd20c |
---|---|
112 Uint32 pixel_value = 0; | 112 Uint32 pixel_value = 0; |
113 Uint8 r = 0,g = 0,b = 0,a = 0; | 113 Uint8 r = 0,g = 0,b = 0,a = 0; |
114 SDL_bool pixel_transparent = SDL_FALSE; | 114 SDL_bool pixel_transparent = SDL_FALSE; |
115 int last_transparent = -1; | 115 int last_transparent = -1; |
116 SDL_Color key; | 116 SDL_Color key; |
117 SDL_ShapeTree* result = malloc(sizeof(SDL_ShapeTree)); | 117 SDL_ShapeTree* result = (SDL_ShapeTree*)SDL_malloc(sizeof(SDL_ShapeTree)); |
118 SDL_Rect next = {0,0,0,0}; | 118 SDL_Rect next = {0,0,0,0}; |
119 for(y=dimensions.y;y<dimensions.h;y++) | 119 for(y=dimensions.y;y<dimensions.h;y++) |
120 for(x=dimensions.x;x<dimensions.w;x++) { | 120 for(x=dimensions.x;x<dimensions.w;x++) { |
121 pixel_value = 0; | 121 pixel_value = 0; |
122 pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel); | 122 pixel = (Uint8 *)(mask->pixels) + (y*mask->pitch) + (x*mask->format->BytesPerPixel); |
132 break; | 132 break; |
133 } | 133 } |
134 SDL_GetRGBA(pixel_value,mask->format,&r,&g,&b,&a); | 134 SDL_GetRGBA(pixel_value,mask->format,&r,&g,&b,&a); |
135 switch(mode.mode) { | 135 switch(mode.mode) { |
136 case(ShapeModeDefault): | 136 case(ShapeModeDefault): |
137 pixel_transparent = (a >= 1 ? !invert : invert); | 137 pixel_transparent = (SDL_bool)(a >= 1 ? !invert : invert); |
138 break; | 138 break; |
139 case(ShapeModeBinarizeAlpha): | 139 case(ShapeModeBinarizeAlpha): |
140 pixel_transparent = (a >= mode.parameters.binarizationCutoff ? !invert : invert); | 140 pixel_transparent = (SDL_bool)(a >= mode.parameters.binarizationCutoff ? !invert : invert); |
141 break; | 141 break; |
142 case(ShapeModeReverseBinarizeAlpha): | 142 case(ShapeModeReverseBinarizeAlpha): |
143 pixel_transparent = (a <= mode.parameters.binarizationCutoff ? !invert : invert); | 143 pixel_transparent = (SDL_bool)(a <= mode.parameters.binarizationCutoff ? !invert : invert); |
144 break; | 144 break; |
145 case(ShapeModeColorKey): | 145 case(ShapeModeColorKey): |
146 key = mode.parameters.colorKey; | 146 key = mode.parameters.colorKey; |
147 pixel_transparent = ((key.r == r && key.g == g && key.b == b) ? !invert : invert); | 147 pixel_transparent = (SDL_bool)((key.r == r && key.g == g && key.b == b) ? !invert : invert); |
148 break; | 148 break; |
149 } | 149 } |
150 if(last_transparent == -1) { | 150 if(last_transparent == -1) { |
151 last_transparent = pixel_transparent; | 151 last_transparent = pixel_transparent; |
152 break; | 152 break; |
157 next.w = dimensions.w / 2; | 157 next.w = dimensions.w / 2; |
158 next.h = dimensions.h / 2; | 158 next.h = dimensions.h / 2; |
159 //These will change from recursion to recursion. | 159 //These will change from recursion to recursion. |
160 next.x = dimensions.x; | 160 next.x = dimensions.x; |
161 next.y = dimensions.y; | 161 next.y = dimensions.y; |
162 result->data.children.upleft = RecursivelyCalculateShapeTree(mode,mask,invert,next); | 162 result->data.children.upleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); |
163 next.x = dimensions.w / 2 + 1; | 163 next.x = dimensions.w / 2 + 1; |
164 //Unneeded: next.y = dimensions.y; | 164 //Unneeded: next.y = dimensions.y; |
165 result->data.children.upright = RecursivelyCalculateShapeTree(mode,mask,invert,next); | 165 result->data.children.upright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); |
166 next.x = dimensions.x; | 166 next.x = dimensions.x; |
167 next.y = dimensions.h / 2 + 1; | 167 next.y = dimensions.h / 2 + 1; |
168 result->data.children.downleft = RecursivelyCalculateShapeTree(mode,mask,invert,next); | 168 result->data.children.downleft = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); |
169 next.x = dimensions.w / 2 + 1; | 169 next.x = dimensions.w / 2 + 1; |
170 //Unneeded: next.y = dimensions.h / 2 + 1; | 170 //Unneeded: next.y = dimensions.h / 2 + 1; |
171 result->data.children.downright = RecursivelyCalculateShapeTree(mode,mask,invert,next); | 171 result->data.children.downright = (struct SDL_ShapeTree *)RecursivelyCalculateShapeTree(mode,mask,invert,next); |
172 return result; | 172 return result; |
173 } | 173 } |
174 } | 174 } |
175 //If we never recursed, all the pixels in this quadrant have the same "value". | 175 //If we never recursed, all the pixels in this quadrant have the same "value". |
176 result->kind = (last_transparent == SDL_FALSE ? OpaqueShape : TransparentShape); | 176 result->kind = (last_transparent == SDL_FALSE ? OpaqueShape : TransparentShape); |
189 return result; | 189 return result; |
190 } | 190 } |
191 | 191 |
192 void SDL_TraverseShapeTree(SDL_ShapeTree *tree,void(*function)(SDL_ShapeTree*,void*),void* closure) { | 192 void SDL_TraverseShapeTree(SDL_ShapeTree *tree,void(*function)(SDL_ShapeTree*,void*),void* closure) { |
193 if(tree->kind == QuadShape) { | 193 if(tree->kind == QuadShape) { |
194 SDL_TraverseShapeTree(tree->data.children.upleft,function,closure); | 194 SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upleft,function,closure); |
195 SDL_TraverseShapeTree(tree->data.children.upright,function,closure); | 195 SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.upright,function,closure); |
196 SDL_TraverseShapeTree(tree->data.children.downleft,function,closure); | 196 SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downleft,function,closure); |
197 SDL_TraverseShapeTree(tree->data.children.downright,function,closure); | 197 SDL_TraverseShapeTree((SDL_ShapeTree *)tree->data.children.downright,function,closure); |
198 } | 198 } |
199 else | 199 else |
200 function(tree,closure); | 200 function(tree,closure); |
201 } | 201 } |
202 | 202 |
203 void SDL_FreeShapeTree(SDL_ShapeTree** shapeTree) { | 203 void SDL_FreeShapeTree(SDL_ShapeTree** shapeTree) { |
204 if((*shapeTree)->kind == QuadShape) { | 204 if((*shapeTree)->kind == QuadShape) { |
205 SDL_FreeShapeTree(&(*shapeTree)->data.children.upleft); | 205 SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.upleft); |
206 SDL_FreeShapeTree(&(*shapeTree)->data.children.upright); | 206 SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.upright); |
207 SDL_FreeShapeTree(&(*shapeTree)->data.children.downleft); | 207 SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.downleft); |
208 SDL_FreeShapeTree(&(*shapeTree)->data.children.downright); | 208 SDL_FreeShapeTree((SDL_ShapeTree **)&(*shapeTree)->data.children.downright); |
209 } | 209 } |
210 free(*shapeTree); | 210 SDL_free(*shapeTree); |
211 *shapeTree = NULL; | 211 *shapeTree = NULL; |
212 } | 212 } |
213 | 213 |
214 int SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { | 214 int SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) { |
215 int result; | 215 int result; |