comparison src/video/SDL_surface.c @ 2257:340942cfda48

Moved the colorkey and per-surface alpha into the blit info, in preparation for support for general color channel modulation. Removed and consolidated some data in the blit info.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 17 Aug 2007 00:54:53 +0000
parents 6d99edd791bf
children 202ddfd1cfb1
comparison
equal deleted inserted replaced
2256:e893d24ad8db 2257:340942cfda48
229 flag = 0; 229 flag = 0;
230 } 230 }
231 231
232 /* Optimize away operations that don't change anything */ 232 /* Optimize away operations that don't change anything */
233 if ((flag == (surface->flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK))) && 233 if ((flag == (surface->flags & (SDL_SRCCOLORKEY | SDL_RLEACCELOK))) &&
234 (key == surface->format->colorkey)) { 234 (key == surface->map->ckey)) {
235 return (0); 235 return (0);
236 } 236 }
237 237
238 /* UnRLE surfaces before we change the colorkey */ 238 /* UnRLE surfaces before we change the colorkey */
239 if (surface->flags & SDL_RLEACCEL) { 239 if (surface->flags & SDL_RLEACCEL) {
240 SDL_UnRLESurface(surface, 1); 240 SDL_UnRLESurface(surface, 1);
241 } 241 }
242 242
243 if (flag) { 243 if (flag) {
244 surface->flags |= SDL_SRCCOLORKEY; 244 surface->flags |= SDL_SRCCOLORKEY;
245 surface->format->colorkey = key; 245 surface->map->ckey = key;
246 if (flag & SDL_RLEACCELOK) { 246 if (flag & SDL_RLEACCELOK) {
247 surface->flags |= SDL_RLEACCELOK; 247 surface->flags |= SDL_RLEACCELOK;
248 } else { 248 } else {
249 surface->flags &= ~SDL_RLEACCELOK; 249 surface->flags &= ~SDL_RLEACCELOK;
250 } 250 }
251 } else { 251 } else {
252 surface->flags &= ~(SDL_SRCCOLORKEY | SDL_RLEACCELOK); 252 surface->flags &= ~(SDL_SRCCOLORKEY | SDL_RLEACCELOK);
253 surface->format->colorkey = 0; 253 surface->map->ckey = 0;
254 } 254 }
255 SDL_InvalidateMap(surface->map); 255 SDL_InvalidateMap(surface->map);
256 return (0); 256 return (0);
257 } 257 }
258 258
259 /* This function sets the alpha channel of a surface */ 259 /* This function sets the alpha channel of a surface */
260 int 260 int
261 SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value) 261 SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value)
262 { 262 {
263 Uint32 oldflags = surface->flags; 263 Uint32 oldflags = surface->flags;
264 Uint32 oldalpha = surface->format->alpha; 264 Uint32 oldalpha = (surface->map->cmod >> 24);
265 265
266 /* Sanity check the flag as it gets passed in */ 266 /* Sanity check the flag as it gets passed in */
267 if (flag & SDL_SRCALPHA) { 267 if (flag & SDL_SRCALPHA) {
268 if (flag & (SDL_RLEACCEL | SDL_RLEACCELOK)) { 268 if (flag & (SDL_RLEACCEL | SDL_RLEACCELOK)) {
269 flag = (SDL_SRCALPHA | SDL_RLEACCELOK); 269 flag = (SDL_SRCALPHA | SDL_RLEACCELOK);
283 if (!(flag & SDL_RLEACCELOK) && (surface->flags & SDL_RLEACCEL)) 283 if (!(flag & SDL_RLEACCELOK) && (surface->flags & SDL_RLEACCEL))
284 SDL_UnRLESurface(surface, 1); 284 SDL_UnRLESurface(surface, 1);
285 285
286 if (flag) { 286 if (flag) {
287 surface->flags |= SDL_SRCALPHA; 287 surface->flags |= SDL_SRCALPHA;
288 surface->format->alpha = value; 288 surface->map->cmod &= 0x00FFFFFF;
289 surface->map->cmod |= ((Uint32)value << 24);
289 if (flag & SDL_RLEACCELOK) { 290 if (flag & SDL_RLEACCELOK) {
290 surface->flags |= SDL_RLEACCELOK; 291 surface->flags |= SDL_RLEACCELOK;
291 } else { 292 } else {
292 surface->flags &= ~SDL_RLEACCELOK; 293 surface->flags &= ~SDL_RLEACCELOK;
293 } 294 }
294 } else { 295 } else {
295 surface->flags &= ~SDL_SRCALPHA; 296 surface->flags &= ~SDL_SRCALPHA;
296 surface->format->alpha = SDL_ALPHA_OPAQUE; 297 surface->map->cmod |= 0xFF000000;
297 } 298 }
298 /* 299 /*
299 * The representation for software surfaces is independent of 300 * The representation for software surfaces is independent of
300 * per-surface alpha, so no need to invalidate the blit mapping 301 * per-surface alpha, so no need to invalidate the blit mapping
301 * if just the alpha value was changed. (If either is 255, we still 302 * if just the alpha value was changed. (If either is 255, we still
410 (src->map->dst->format_version != src->map->format_version)) { 411 (src->map->dst->format_version != src->map->format_version)) {
411 if (SDL_MapSurface(src, dst) < 0) { 412 if (SDL_MapSurface(src, dst) < 0) {
412 return (-1); 413 return (-1);
413 } 414 }
414 } 415 }
415 return (src->map->sw_blit(src, srcrect, dst, dstrect)); 416 return (src->map->blit(src, srcrect, dst, dstrect));
416 } 417 }
417 418
418 419
419 int 420 int
420 SDL_UpperBlit(SDL_Surface * src, SDL_Rect * srcrect, 421 SDL_UpperBlit(SDL_Surface * src, SDL_Rect * srcrect,
599 if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { 600 if ((surface_flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
600 /* Convert colourkeyed surfaces to RGBA if requested */ 601 /* Convert colourkeyed surfaces to RGBA if requested */
601 if ((flags & SDL_SRCCOLORKEY) != SDL_SRCCOLORKEY && format->Amask) { 602 if ((flags & SDL_SRCCOLORKEY) != SDL_SRCCOLORKEY && format->Amask) {
602 surface_flags &= ~SDL_SRCCOLORKEY; 603 surface_flags &= ~SDL_SRCCOLORKEY;
603 } else { 604 } else {
604 colorkey = surface->format->colorkey; 605 colorkey = surface->map->ckey;
605 SDL_SetColorKey(surface, 0, 0); 606 SDL_SetColorKey(surface, 0, 0);
606 } 607 }
607 } 608 }
608 if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) { 609 if ((surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
609 /* Copy over the alpha channel to RGBA if requested */ 610 /* Copy over the alpha channel to RGBA if requested */
610 if (format->Amask) { 611 if (format->Amask) {
611 surface->flags &= ~SDL_SRCALPHA; 612 surface->flags &= ~SDL_SRCALPHA;
612 } else { 613 } else {
613 alpha = surface->format->alpha; 614 alpha = (Uint8)(surface->map->cmod >> 24);
614 SDL_SetAlpha(surface, 0, 0); 615 SDL_SetAlpha(surface, 0, 0);
615 } 616 }
616 } 617 }
617 618
618 /* Copy over the image data */ 619 /* Copy over the image data */