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 - Hardcoded srcA value in SDL_Blit_RGB888_RGB888_Blend_Scale function
Summary: Hardcoded srcA value in SDL_Blit_RGB888_RGB888_Blend_Scale function
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.0
Hardware: x86 Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-06 02:47 UTC by Nitz
Modified: 2019-10-24 16:14 UTC (History)
1 user (show)

See Also:


Attachments
patch (18.62 KB, patch)
2017-10-24 20:22 UTC, Sylvain
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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 !