comparison src/video/SDL_surface.c @ 431:41cadcba32e8

Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha
author Sam Lantinga <slouken@libsdl.org>
date Thu, 01 Aug 2002 23:06:39 +0000
parents b1b9ee41be70
children 598b25b9bffe
comparison
equal deleted inserted replaced
430:60effdbf14ee 431:41cadcba32e8
209 surface->format->colorkey = 0; 209 surface->format->colorkey = 0;
210 } 210 }
211 SDL_InvalidateMap(surface->map); 211 SDL_InvalidateMap(surface->map);
212 return(0); 212 return(0);
213 } 213 }
214 /* This function sets the alpha channel of a surface */
214 int SDL_SetAlpha (SDL_Surface *surface, Uint32 flag, Uint8 value) 215 int SDL_SetAlpha (SDL_Surface *surface, Uint32 flag, Uint8 value)
215 { 216 {
216 Uint32 oldflags = surface->flags; 217 Uint32 oldflags = surface->flags;
217 Uint32 oldalpha = surface->format->alpha; 218 Uint32 oldalpha = surface->format->alpha;
218 219
266 if((surface->flags & SDL_HWACCEL) == SDL_HWACCEL 267 if((surface->flags & SDL_HWACCEL) == SDL_HWACCEL
267 || oldflags != surface->flags 268 || oldflags != surface->flags
268 || (((oldalpha + 1) ^ (value + 1)) & 0x100)) 269 || (((oldalpha + 1) ^ (value + 1)) & 0x100))
269 SDL_InvalidateMap(surface->map); 270 SDL_InvalidateMap(surface->map);
270 return(0); 271 return(0);
272 }
273 int SDL_SetAlphaChannel(SDL_Surface *surface, Uint8 value)
274 {
275 int row, col;
276 int offset;
277 Uint8 *buf;
278
279 if ( (surface->format->Amask != 0xFF000000) &&
280 (surface->format->Amask != 0x000000FF) ) {
281 SDL_SetError("Unsupported surface alpha mask format");
282 return -1;
283 }
284
285 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
286 if ( surface->format->Amask == 0xFF000000 ) {
287 offset = 3;
288 } else {
289 offset = 0;
290 }
291 #else
292 if ( surface->format->Amask == 0xFF000000 ) {
293 offset = 0;
294 } else {
295 offset = 3;
296 }
297 #endif /* Byte ordering */
298
299 /* Quickly set the alpha channel of an RGBA or ARGB surface */
300 if ( SDL_MUSTLOCK(surface) ) {
301 if ( SDL_LockSurface(surface) < 0 ) {
302 return -1;
303 }
304 }
305 row = surface->h;
306 while (row--) {
307 col = surface->w;
308 buf = (Uint8 *)surface->pixels + row * surface->pitch + offset;
309 while(col--) {
310 *buf = value;
311 buf += 4;
312 }
313 }
314 if ( SDL_MUSTLOCK(surface) ) {
315 SDL_UnlockSurface(surface);
316 }
317 return 0;
271 } 318 }
272 319
273 /* 320 /*
274 * A function to calculate the intersection of two rectangles: 321 * A function to calculate the intersection of two rectangles:
275 * return true if the rectangles intersect, false otherwise 322 * return true if the rectangles intersect, false otherwise
746 colorkey = surface->format->colorkey; 793 colorkey = surface->format->colorkey;
747 SDL_SetColorKey(surface, 0, 0); 794 SDL_SetColorKey(surface, 0, 0);
748 } 795 }
749 } 796 }
750 if ( (surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { 797 if ( (surface_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
751 alpha = surface->format->alpha; 798 /* Copy over the alpha channel to RGBA if requested */
752 SDL_SetAlpha(surface, 0, 0); 799 if ( format->Amask ) {
800 surface->flags &= ~SDL_SRCALPHA;
801 } else {
802 alpha = surface->format->alpha;
803 SDL_SetAlpha(surface, 0, 0);
804 }
753 } 805 }
754 806
755 /* Copy over the image data */ 807 /* Copy over the image data */
756 bounds.x = 0; 808 bounds.x = 0;
757 bounds.y = 0; 809 bounds.y = 0;
778 Uint32 aflags = surface_flags&(SDL_SRCALPHA|SDL_RLEACCELOK); 830 Uint32 aflags = surface_flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
779 if ( convert != NULL ) { 831 if ( convert != NULL ) {
780 SDL_SetAlpha(convert, aflags|(flags&SDL_RLEACCELOK), 832 SDL_SetAlpha(convert, aflags|(flags&SDL_RLEACCELOK),
781 alpha); 833 alpha);
782 } 834 }
783 SDL_SetAlpha(surface, aflags, alpha); 835 if ( format->Amask ) {
836 surface->flags |= SDL_SRCALPHA;
837 } else {
838 SDL_SetAlpha(surface, aflags, alpha);
839 }
784 } 840 }
785 841
786 /* We're ready to go! */ 842 /* We're ready to go! */
787 return(convert); 843 return(convert);
788 } 844 }