We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2014

Summary: Hardcoded srcA value in SDL_Blit_RGB888_RGB888_Blend_Scale function
Product: SDL Reporter: Nitz <nitin.j4>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sylvain.becker
Version: 2.0.0   
Hardware: x86   
OS: Linux   
Attachments: patch

Description Nitz 2013-08-06 02:47:43 UTC
In Function
static void SDL_Blit_RGB888_RGB888_Blend_Scale(SDL_BlitInfo *info)
{
  // Some Code
  srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
  
  dstpixel = *dst;
  
  dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
            
  if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
  /* This goes away if we ever use premultiplied alpha */
   if (srcA < 255) {
    srcR = (srcR * srcA) / 255;
    srcG = (srcG * srcA) / 255;
    srcB = (srcB * srcA) / 255;
   }
  }

 //Some Code
}

In this code srcA and dstA value is hardcoded to 0xFF, because of which the if condition 
if (srcA < 255) {
    srcR = (srcR * srcA) / 255;
    srcG = (srcG * srcA) / 255;
    srcB = (srcB * srcA) / 255;
   }
will never get executed.
So either remove this code or change the hardcoded value of srcA and dstA.

Thanks!
Comment 1 Sylvain 2017-10-24 20:22:40 UTC
Created attachment 3041 [details]
patch

not fully tested, but here's a patch to remove hardcoded constants.
Comment 2 Sylvain 2019-10-24 16:08:02 UTC
Fixed in https://hg.libsdl.org/SDL/rev/f530cdaaab62
Comment 3 Sylvain 2019-10-24 16:14:09 UTC
Modified sdlgenblit.pl so that when:
srcA = 0xFF;
or
A = 0xFF;
It is initialised as const and/or inlined afterwards. 
Un-reacheable code is removed !