Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed bug 1424 - Handling of alpha channel in Altivec accelerated bli…
Browse files Browse the repository at this point in the history
…t 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.
  • Loading branch information
slouken committed Feb 21, 2012
1 parent 5d2fff5 commit 3aead2b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/video/SDL_blit_N.c
Expand Up @@ -707,6 +707,8 @@ ConvertAltivec32to32_noprefetch(SDL_BlitInfo * info)
while ((UNALIGNED_PTR(dst)) && (width)) {
bits = *(src++);
RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
if(!srcfmt->Amask)
a = srcfmt->alpha;
*(dst++) = MAKE8888(dstfmt, r, g, b, a);
width--;
}
Expand Down Expand Up @@ -734,6 +736,8 @@ ConvertAltivec32to32_noprefetch(SDL_BlitInfo * info)
while (extrawidth) {
bits = *(src++); /* max 7 pixels, don't bother with prefetch. */
RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
if(!srcfmt->Amask)
a = srcfmt->alpha;
*(dst++) = MAKE8888(dstfmt, r, g, b, a);
extrawidth--;
}
Expand Down Expand Up @@ -790,6 +794,8 @@ ConvertAltivec32to32_prefetch(SDL_BlitInfo * info)
DST_CHAN_DEST);
bits = *(src++);
RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
if(!srcfmt->Amask)
a = srcfmt->alpha;
*(dst++) = MAKE8888(dstfmt, r, g, b, a);
width--;
}
Expand Down Expand Up @@ -821,6 +827,8 @@ ConvertAltivec32to32_prefetch(SDL_BlitInfo * info)
while (extrawidth) {
bits = *(src++); /* max 7 pixels, don't bother with prefetch. */
RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
if(!srcfmt->Amask)
a = srcfmt->alpha;
*(dst++) = MAKE8888(dstfmt, r, g, b, a);
extrawidth--;
}
Expand Down

0 comments on commit 3aead2b

Please sign in to comment.