Fixed bug 1424 - Handling of alpha channel in Altivec accelerated blit functions SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Mon, 20 Feb 2012 20:55:23 -0500
branchSDL-1.2
changeset 62947a2e0f7b30cb
parent 6293 57a55e457ef6
child 6297 c787fb1b5699
Fixed bug 1424 - Handling of alpha channel in Altivec accelerated blit functions

evilbite 2012-02-19 09:38:21 PST

There is only one Altivec accelerated blit function
(ConvertAltivec32to32_prefetch() or ConvertAltivec32to32_noprefetch(),
depending on the CPU used) that is supposed to handle all alpha combinations.
This works as follows for every pixel line:
1. Blit single pixels until an aligned address is reached
2. Accelerated blit as far as possible
3. Blit single remaining pixels
Part 2. is set up correctly to handle different combinations of the alpha
channels of the participating surfaces. Parts 1. and 3. only do a simple copy
of all the pixel's components from souce to destination. But when the source
surface has no alpha channel (Amask is 0, e.g. the video surface) the surface's
alpha value must be used instead. Otherwise crap (uninitialized data) is being
copied to the destiniation's alpha channel.

The attached patch is a quick'n'dirty solution to the problem. A more
sophisticated solution might require separate functions for different
combinations of the alpha channels of the participating surfaces.
src/video/SDL_blit_N.c
     1.1 --- a/src/video/SDL_blit_N.c	Mon Feb 20 20:50:38 2012 -0500
     1.2 +++ b/src/video/SDL_blit_N.c	Mon Feb 20 20:55:23 2012 -0500
     1.3 @@ -689,6 +689,8 @@
     1.4          while ((UNALIGNED_PTR(dst)) && (width)) {
     1.5              bits = *(src++);
     1.6              RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
     1.7 +            if(!srcfmt->Amask)
     1.8 +              a = srcfmt->alpha;
     1.9              *(dst++) = MAKE8888(dstfmt, r, g, b, a);
    1.10              width--;
    1.11          }
    1.12 @@ -716,6 +718,8 @@
    1.13          while (extrawidth) {
    1.14              bits = *(src++);  /* max 7 pixels, don't bother with prefetch. */
    1.15              RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
    1.16 +            if(!srcfmt->Amask)
    1.17 +              a = srcfmt->alpha;
    1.18              *(dst++) = MAKE8888(dstfmt, r, g, b, a);
    1.19              extrawidth--;
    1.20          }
    1.21 @@ -769,6 +773,8 @@
    1.22              vec_dstst(dst+scalar_dst_lead, DST_CTRL(2,32,1024), DST_CHAN_DEST);
    1.23              bits = *(src++);
    1.24              RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
    1.25 +            if(!srcfmt->Amask)
    1.26 +              a = srcfmt->alpha;
    1.27              *(dst++) = MAKE8888(dstfmt, r, g, b, a);
    1.28              width--;
    1.29          }
    1.30 @@ -798,6 +804,8 @@
    1.31          while (extrawidth) {
    1.32              bits = *(src++);  /* max 7 pixels, don't bother with prefetch. */
    1.33              RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
    1.34 +            if(!srcfmt->Amask)
    1.35 +              a = srcfmt->alpha;
    1.36              *(dst++) = MAKE8888(dstfmt, r, g, b, a);
    1.37              extrawidth--;
    1.38          }