Index: Source/platform/image-decoders/ImageFrame.h |
diff --git a/Source/platform/image-decoders/ImageFrame.h b/Source/platform/image-decoders/ImageFrame.h |
index fb7425755bd77887066531b171c6c8dc21c5b2d8..0a2a13162e201066bf2bb22cd146e425b8f8a5ea 100644 |
--- a/Source/platform/image-decoders/ImageFrame.h |
+++ b/Source/platform/image-decoders/ImageFrame.h |
@@ -178,6 +178,45 @@ public: |
*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); |
+ } |
+ |
// Notifies the SkBitmap if any pixels changed and resets the flag. |
inline void notifyBitmapIfPixelsChanged() |
{ |