Skip to content

Commit

Permalink
From: "Alex Volkov"
Browse files Browse the repository at this point in the history
Date: Thu, 10 Nov 2005 21:53:40 -0500
Subject: [SDL] BUG[?]: 32bpp RGBA->RGB colorkey blit, no SDL_SRCALPHA

It seems there is either a documentation vs. reality mismatch or a real bug
in SDL_blit_N.c:BlitNtoNKey().
The exact blit in question is a 32bpp RGBA->RGB, where RGBA has SDL_COLORKEY
and *no* SDL_SRCALPHA flags. The doc in SDL_video.h states:
* RGBA->RGB:
*     SDL_SRCALPHA not set:
*       copy RGB.
*       if SDL_SRCCOLORKEY set, only copy the pixels matching the
*       RGB values of the source colour key, ignoring alpha in the
*       comparison.

BlitNtoNKey(), however, forgets to "ignore alpha in the comparison". The
documentation makes perfect sense, so I think it is the code that is faulty.

The attached patch corrects the code.
  • Loading branch information
slouken committed Mar 15, 2006
1 parent ff71047 commit 32d3c42
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/video/SDL_blit_N.c
Expand Up @@ -2194,6 +2194,10 @@ static void BlitNtoNKey(SDL_BlitInfo *info)
int srcbpp = srcfmt->BytesPerPixel;
int dstbpp = dstfmt->BytesPerPixel;
unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0;
Uint32 rgbmask = ~srcfmt->Amask;

/* Set up some basic variables */
ckey &= rgbmask;

while ( height-- ) {
DUFFS_LOOP(
Expand All @@ -2203,7 +2207,7 @@ static void BlitNtoNKey(SDL_BlitInfo *info)
unsigned sG;
unsigned sB;
RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel);
if ( Pixel != ckey ) {
if ( (Pixel & rgbmask) != ckey ) {
RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB);
ASSEMBLE_RGBA(dst, dstbpp, dstfmt,
sR, sG, sB, alpha);
Expand Down

0 comments on commit 32d3c42

Please sign in to comment.