static inline void setPixelPremultipliedRGBA(ImageFrame::PixelData* dest, png_bytep pixel, unsigned char& nonTrivialAlphaMask) { unsigned char a = pixel[3]; unsigned char r = fastDivideBy255(pixel[0] * a); unsigned char g = fastDivideBy255(pixel[1] * a); unsigned char b = fastDivideBy255(pixel[2] * a); *dest = a << 24 | r << 16 | g << 8 | b; nonTrivialAlphaMask |= (255 - a); }
RGBA32 premultipliedARGBFromColor(const Color& color) { unsigned pixelColor; unsigned alpha = color.alpha(); if (alpha < 255) { pixelColor = Color::createUnchecked( fastDivideBy255(color.red() * alpha + 254), fastDivideBy255(color.green() * alpha + 254), fastDivideBy255(color.blue() * alpha + 254), alpha).rgb(); } else pixelColor = color.rgb(); return pixelColor; }
static void platformApply(unsigned char* sourcePixelA, unsigned char* sourcePixelB, unsigned char* destinationPixel, unsigned pixelArrayLength) { unsigned len = pixelArrayLength / 4; for (unsigned pixelOffset = 0; pixelOffset < len; pixelOffset++) { unsigned char alphaA = sourcePixelA[3]; unsigned char alphaB = sourcePixelB[3]; destinationPixel[0] = BlendFunction(sourcePixelA[0], sourcePixelB[0], alphaA, alphaB); destinationPixel[1] = BlendFunction(sourcePixelA[1], sourcePixelB[1], alphaA, alphaB); destinationPixel[2] = BlendFunction(sourcePixelA[2], sourcePixelB[2], alphaA, alphaB); destinationPixel[3] = 255 - fastDivideBy255((255 - alphaA) * (255 - alphaB)); sourcePixelA += 4; sourcePixelB += 4; destinationPixel += 4; } }
inline unsigned char feBlendLighten(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char alphaB) { return fastDivideBy255(std::max((255 - alphaA) * colorB + colorA * 255, (255 - alphaB) * colorA + colorB * 255)); }
inline unsigned char feBlendScreen(unsigned char colorA, unsigned char colorB, unsigned char, unsigned char) { return fastDivideBy255((colorB + colorA) * 255 - colorA * colorB); }
inline unsigned char feBlendMultiply(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char alphaB) { return fastDivideBy255((255 - alphaA) * colorB + (255 - alphaB + colorB) * colorA); }
inline unsigned char feBlendNormal(unsigned char colorA, unsigned char colorB, unsigned char alphaA, unsigned char) { return fastDivideBy255((255 - alphaA) * colorB + colorA * 255); }