Index: third_party/WebKit/Source/platform/image-decoders/ImageFrame.h |
diff --git a/third_party/WebKit/Source/platform/image-decoders/ImageFrame.h b/third_party/WebKit/Source/platform/image-decoders/ImageFrame.h |
index 574b66df089049e866ddfaf8c9bc811a30e10619..9ff7a3ba439efd0436aaba700ae739edbf4733f7 100644 |
--- a/third_party/WebKit/Source/platform/image-decoders/ImageFrame.h |
+++ b/third_party/WebKit/Source/platform/image-decoders/ImageFrame.h |
@@ -218,6 +218,51 @@ class PLATFORM_EXPORT ImageFrame final { |
*dest = SkPackARGB32NoCheck(a, r, g, b); |
} |
+ inline void overRGBAPremultiply(PixelData* dest, |
+ unsigned r, |
+ unsigned g, |
+ unsigned b, |
+ unsigned a) { |
+ enum FractionControl { RoundFractionControl = 257 * 128 }; |
+ |
+ if (!a) |
+ return; |
+ |
+ if (a < 255) { |
+ unsigned alpha = a * 257; |
+ r = (r * alpha + RoundFractionControl) >> 16; |
+ g = (g * alpha + RoundFractionControl) >> 16; |
+ b = (b * alpha + RoundFractionControl) >> 16; |
+ *dest = SkPMSrcOver(SkPackARGB32NoCheck(a, r, g, b), *dest); |
+ } else { |
+ *dest = SkPackARGB32NoCheck(a, r, g, b); |
+ } |
+ } |
+ |
+ inline void overRGBARaw(PixelData* dest, |
+ unsigned r, |
+ unsigned g, |
+ unsigned b, |
+ unsigned a) { |
+ if (!a) |
+ return; |
+ |
+ unsigned aDest = SkGetPackedA32(*dest); |
+ if (aDest && a < 255) { |
+ unsigned u = a * 255; |
+ unsigned v = (255 - a) * aDest; |
+ unsigned alpha = u + v; |
+ unsigned rDest = SkGetPackedR32(*dest); |
+ unsigned gDest = SkGetPackedG32(*dest); |
+ unsigned bDest = SkGetPackedB32(*dest); |
+ a = (alpha + (alpha >> 8) + 1) >> 8; |
+ r = (r * u + rDest * v) / alpha; |
+ g = (g * u + gDest * v) / alpha; |
+ b = (b * u + bDest * v) / alpha; |
+ } |
+ *dest = SkPackARGB32NoCheck(a, r, g, b); |
+ } |
+ |
// Blend the RGBA pixel provided by |r|, |g|, |b|, |a| over the pixel in |
// |dest|, without premultiplication, and overwrite |dest| with the result. |
static inline void blendRGBARaw(PixelData* dest, |