sdl2_frt/src/video
Sam Lantinga e589cdba2f Fixed bug 3023 - setting a white and then non-white texture color mod breaks the texture with software renderer
Adam M.

Okay, here is the problem, I think.

During the first blit, RLEAlphaSurface is called to do RLE conversion of the RGBA source into a format allowing it "to be quickly alpha-blittable onto dest". Since the destination is the screen, it has no alpha channel. RLEAlphaSurface calls copy_opaque(dst, src + runstart, len, sf, df) (where copy_opaque is copy_32), which has this code:

SDL_RLEaccel.c:984:
  RGBA_FROM_8888(*src, sfmt, r, g, b, a);
  PIXEL_FROM_RGBA(*d, dfmt, r, g, b, a);

On the first line, it reads the source pixel 0xFFFFFFFF. The second line drops the alpha value (because dfmt for the screen has no alpha channel) and writes 0x00FFFFFF. Later, when the RLE conversion is being undone, uncopy_32 is called, which has the following code:

SDL_RLEaccel.c:1001:
  Uint32 pixel = *s++;
  RGB_FROM_PIXEL(pixel, sfmt, r, g, b);
  a = pixel >> 24;
  PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);

However, the the alpha channel has already been dropped by copy_opaque (= copy_32), so pixel = 0x00FFFFFF and 'a' becomes 0. Thus, all opaque pixels lose their alpha channel when being unRLE'd. (I don't know what happens to pixels with alpha from 1-254, but they should be checked too.)

So, that seems to be the problem, but I'm not sure what the solution should be. Since opaque pixels have alpha == 255, I'm thinking to create another uncopy function for opaque pixels that simply uses 255 for alpha.

However, there may be other problems here. For translucent pixels, uncopy_32 assumes the alpha channel is stored in the upper 8 bits, but copy_32 doesn't store it there. Instead, it stores it in whatever location is appropriate for the destination surface. Isn't one of their behaviors incorrect, given the other? I'm not sure which to change, however.

For translucent pixels, it seems that the blit function uses do_blend, which is the BLIT_TRANSL_888 macro, which also assumes alpha is in top 8 bits. It has the comment "we have made sure the alpha is stored in the top 8 bits...", but it seems that's not true (copy_32 doesn't make sure the alpha goes there).

Perhaps the correct fix is to make copy_32 put the alpha there, but then that seems to require that RLE conversion be limited to destination surfaces that don't use the upper 8 bits. However, looking further, it seems that has already been done: if (masksum != 0x00ffffff) return -1; /* requires unused high byte */
2015-06-19 23:12:13 -07:00
..
android Android: Changed two unknown keys to be consistent with Windows and X11 mapping. 2015-05-31 19:22:42 +02:00
cocoa Backout commit 83034612a883 2015-06-04 02:12:06 -04:00
directfb Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
dummy Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
emscripten Emscripten: Fixed SDL_GetTouchDevice() returning 0 for the valid device index. 2015-06-09 21:06:29 +02:00
haiku Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
mir Fixed comments at conditional compilation macros. 2015-06-05 19:41:18 +02:00
nacl Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
pandora Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
psp Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
raspberry RPi: Patched to compile without OpenGL (thanks, Simon!), other cleanups. 2015-06-06 22:45:22 -04:00
uikit iOS: Fixed some cases where SDL_DestroyWindow or SDL_GL_DeleteContext can cause crashes. 2015-06-09 21:08:24 -03:00
vivante Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
wayland Wayland: Fixed SDL_GetTouchDevice() returning 0 for the valid device index. 2015-06-09 21:06:55 +02:00
windows Implement repositioning the OS-rendered IME with SDL_SetTextInputRect on Windows. 2015-06-15 20:24:51 -07:00
winrt Fixed comments at conditional compilation macros. 2015-06-05 19:41:18 +02:00
x11 Fixed bug 3010 - SDL_x11messagebox.c needs including X11/keysym.h 2015-06-13 13:34:30 -07:00
SDL_blit_0.c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_blit_1.c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_blit_A.c Fixed comments at conditional compilation macros. 2015-06-05 19:41:18 +02:00
SDL_blit_auto.c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_blit_auto.h Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_blit_copy.c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_blit_copy.h Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_blit_N.c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_blit_slow.c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_blit_slow.h Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_blit.c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_blit.h Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_bmp.c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_clipboard.c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_egl_c.h Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_egl.c EGL: OpenGL ES 3.0 contexts can now be created without the EGL_KHR_create_context extension. 2015-05-26 19:34:56 -03:00
SDL_fillrect.c Fixed swizzle of SDL_FillRect() on 24-bit surface (thanks, "nagydavid91"!). 2015-05-31 11:38:10 -04:00
SDL_pixels_c.h Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_pixels.c VS2005 tweaks (thanks, Ozkan!). 2015-06-07 19:58:42 -04:00
SDL_rect_c.h Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_rect.c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_RLEaccel_c.h Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_RLEaccel.c Fixed bug 3023 - setting a white and then non-white texture color mod breaks the texture with software renderer 2015-06-19 23:12:13 -07:00
SDL_shape_internals.h Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_shape.c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_stretch.c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_surface.c Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_sysvideo.h Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00
SDL_video.c Fixed bug 3015 - grab mouse inconsistent state 2015-06-15 23:44:08 -07:00
sdlgenblit.pl Updated the copyright year to 2015 2015-05-26 06:27:46 -07:00