comparison src/video/SDL_surface.c @ 2785:fa1095d42a5b

Fixed bug with converting colorkey surface to texture
author Sam Lantinga <slouken@libsdl.org>
date Tue, 25 Nov 2008 02:12:19 +0000
parents 204be4fc2726
children 6bacfecbf27e
comparison
equal deleted inserted replaced
2784:9bbe3bd94be8 2785:fa1095d42a5b
267 } 267 }
268 268
269 return 0; 269 return 0;
270 } 270 }
271 271
272 /* This is a fairly slow function to switch from colorkey to alpha */
273 void
274 SDL_ConvertColorkeyToAlpha(SDL_Surface *surface)
275 {
276 int x, y;
277
278 if (!surface) {
279 return;
280 }
281
282 if (!(surface->map->info.flags & SDL_COPY_COLORKEY) ||
283 !surface->format->Amask) {
284 return;
285 }
286
287 SDL_LockSurface(surface);
288
289 switch (surface->format->BytesPerPixel) {
290 case 2:
291 {
292 Uint16 *row, *spot;
293 Uint16 ckey = (Uint16)surface->map->info.colorkey;
294 Uint16 mask = (Uint16)(~surface->format->Amask);
295
296 row = (Uint16 *)surface->pixels;
297 for (y = surface->h; y--; ) {
298 spot = row;
299 for (x = surface->w; x--; ) {
300 if (*spot == ckey) {
301 *spot &= mask;
302 }
303 ++spot;
304 }
305 row += surface->pitch / 2;
306 }
307 }
308 break;
309 case 3:
310 /* FIXME */
311 break;
312 case 4:
313 {
314 Uint32 *row, *spot;
315 Uint32 ckey = surface->map->info.colorkey;
316 Uint32 mask = ~surface->format->Amask;
317
318 row = (Uint32 *)surface->pixels;
319 for (y = surface->h; y--; ) {
320 spot = row;
321 for (x = surface->w; x--; ) {
322 if (*spot == ckey) {
323 *spot &= mask;
324 }
325 ++spot;
326 }
327 row += surface->pitch / 4;
328 }
329 }
330 break;
331 }
332
333 SDL_UnlockSurface(surface);
334
335 SDL_SetColorKey(surface, 0, 0);
336 }
337
272 int 338 int
273 SDL_SetSurfaceColorMod(SDL_Surface * surface, Uint8 r, Uint8 g, Uint8 b) 339 SDL_SetSurfaceColorMod(SDL_Surface * surface, Uint8 r, Uint8 g, Uint8 b)
274 { 340 {
275 int flags; 341 int flags;
276 342