Skip to content

Commit

Permalink
[coreImage] Reduce rounding errors in BitBlitAlpha, take the fast lan…
Browse files Browse the repository at this point in the history
…e for the edge case of alpha = 255
  • Loading branch information
eumagga0x2a committed Aug 17, 2020
1 parent 2403e92 commit 6dac2d0
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions avidemux_core/ADM_coreImage/src/ADM_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,25 @@ bool r=false;
}

/**
* \fn BitBlitAlpha
* \brief Alpha blit from dst to src
* \fn BitBlitAlpha
* \brief Alpha blit from dst to src
*/
bool BitBlitAlpha(uint8_t *dst, uint32_t pitchDst,uint8_t *src,uint32_t pitchSrc,
uint32_t width, uint32_t height,uint32_t alpha)
uint32_t width, uint32_t height,uint32_t alpha)
{

if(alpha>255) alpha=255;
if(alpha==255) // take a shortcut
return BitBlit(dst,pitchDst,src,pitchSrc,width,height);
for(int y=0;y<height;y++)
{
for(int x=0;x<width;x++)
{
uint32_t s=src[x],d=dst[x];

d=s*alpha+(255-alpha)*d;
d>>=8;
dst[x]=d;
}
for(int x=0;x<width;x++)
{
float s=src[x],d=dst[x];
d=s*alpha+(255.-alpha)*d;
d/=255.;
d+=0.49;
dst[x]=(uint8_t)d;
}
src+=pitchSrc;
dst+=pitchDst;
}
Expand Down

0 comments on commit 6dac2d0

Please sign in to comment.