Skip to content

Commit e983d40

Browse files
committed
Fixed bug 2976 - Fix RGBA<->RGBA blit that was broken with the optimization from Bug 11
id.zeta The optimization from Bug 11 added a code branch on cases where the source RGB masks match the destination RGB masks and a optimized blit function Blit4to4MaskAlpha that always overrides the source alpha info would be chosen. Unfortunately, the branch also errorneously took over the RGBA<->RGBA blitting cases where the source alpha info should be copied, while they would instead get overriden in Blit4to4MaskAlpha. The attached patch fixes that by handling the RGBA<->RGBA cases correctly in that branch with the original BlitNtoNCopyAlpha as well as uses an optimized Blit4to4CopyAlpha along the same vein.
1 parent 289d660 commit e983d40

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/video/SDL_blit_N.c

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,6 +2114,33 @@ Blit4to4MaskAlpha(SDL_BlitInfo * info)
21142114
}
21152115
}
21162116

2117+
/* blits 32 bit RGBA<->RGBA with both surfaces having the same R,G,B,A fields */
2118+
static void
2119+
Blit4to4CopyAlpha(SDL_BlitInfo * info)
2120+
{
2121+
int width = info->dst_w;
2122+
int height = info->dst_h;
2123+
Uint32 *src = (Uint32 *) info->src;
2124+
int srcskip = info->src_skip;
2125+
Uint32 *dst = (Uint32 *) info->dst;
2126+
int dstskip = info->dst_skip;
2127+
2128+
/* RGBA->RGBA, COPY_ALPHA */
2129+
while (height--) {
2130+
/* *INDENT-OFF* */
2131+
DUFFS_LOOP(
2132+
{
2133+
*dst = *src;
2134+
++dst;
2135+
++src;
2136+
},
2137+
width);
2138+
/* *INDENT-ON* */
2139+
src = (Uint32 *) ((Uint8 *) src + srcskip);
2140+
dst = (Uint32 *) ((Uint8 *) dst + dstskip);
2141+
}
2142+
}
2143+
21172144
static void
21182145
BlitNtoN(SDL_BlitInfo * info)
21192146
{
@@ -2562,8 +2589,17 @@ SDL_CalculateBlitN(SDL_Surface * surface)
25622589
srcfmt->Rmask == dstfmt->Rmask &&
25632590
srcfmt->Gmask == dstfmt->Gmask &&
25642591
srcfmt->Bmask == dstfmt->Bmask) {
2565-
/* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */
2566-
blitfun = Blit4to4MaskAlpha;
2592+
if (a_need == COPY_ALPHA) {
2593+
if (srcfmt->Amask == dstfmt->Amask) {
2594+
/* Fastpath C fallback: 32bit RGBA<->RGBA blit with matching RGBA */
2595+
blitfun = Blit4to4CopyAlpha;
2596+
} else {
2597+
blitfun = BlitNtoNCopyAlpha;
2598+
}
2599+
} else {
2600+
/* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */
2601+
blitfun = Blit4to4MaskAlpha;
2602+
}
25672603
} else if (a_need == COPY_ALPHA) {
25682604
blitfun = BlitNtoNCopyAlpha;
25692605
}

0 commit comments

Comments
 (0)