Skip to content
Permalink
Browse files
GIFs2PNG algorithm: treat out-of-mask area as white pixels
  • Loading branch information
Wohlstand committed Jun 13, 2020
1 parent 5243baf commit 0d940806879c876e74ecf63b1dd83f874b096a78
Showing 1 changed file with 22 additions and 5 deletions.
@@ -287,15 +287,20 @@ void GraphicsHelps::mergeWithMask(FIBITMAP *image, FIBITMAP *mask)
BYTE *FPixP = img_bits;
BYTE *SPixP = mask_bits;
RGBQUAD Npix = {0x00, 0x00, 0x00, 0xFF}; //Destination pixel color
BYTE Wpix[] = {0xFF, 0xFF, 0xFF, 0xFF}; //Dummy white pixel
unsigned short newAlpha = 0xFF; //Calculated destination alpha-value

bool endOfY = false;
unsigned int ym = mask_h - 1;
unsigned int y = img_h - 1;

while(1)
{
FPixP = img_bits + (img_w * y * 4);
SPixP = mask_bits + (mask_w * ym * 4);
for(unsigned int x = 0; (x < img_w) && (x < mask_w); x++)
if(!endOfY)
SPixP = mask_bits + (mask_w * ym * 4);

for(unsigned int x = 0; (x < img_w); x++)
{
Npix.rgbBlue = ((SPixP[FI_RGBA_BLUE] & 0x7F) | FPixP[FI_RGBA_BLUE]);
Npix.rgbGreen = ((SPixP[FI_RGBA_GREEN] & 0x7F) | FPixP[FI_RGBA_GREEN]);
@@ -320,12 +325,24 @@ void GraphicsHelps::mergeWithMask(FIBITMAP *image, FIBITMAP *mask)
FPixP[FI_RGBA_RED] = Npix.rgbRed;
FPixP[FI_RGBA_ALPHA] = static_cast<BYTE>(newAlpha);
FPixP += 4;
SPixP += 4;

if(x >= mask_w - 1)
SPixP = Wpix;
else
SPixP += 4;
}

if(ym == 0)
{
endOfY = true;
SPixP = Wpix;
}
else
ym--;

if(y == 0 || ym == 0)
if(y == 0)
break;
y--; ym--;
y--;
}
}

0 comments on commit 0d94080

Please sign in to comment.