Title: [137413] trunk/Source/WebCore
Revision
137413
Author
[email protected]
Date
2012-12-11 21:35:01 -0800 (Tue, 11 Dec 2012)

Log Message

Remove conversion to/from float and float division from ImageFrame::setRGBA
https://bugs.webkit.org/show_bug.cgi?id=103693

Patch by Viatcheslav Ostapenko <[email protected]> on 2012-12-11
Reviewed by Brent Fulgham.

Replace floating point operations used for alpha premultiply with fixed point arithmetic
which is basically integer operations. Allows to shave extra couple percent from decoding
images with transparency.

Covered by existing tests.

* platform/image-decoders/ImageDecoder.h:
(ImageFrame):
(WebCore::ImageFrame::fixPointUnsignedMultiply):
(WebCore::ImageFrame::setRGBA):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (137412 => 137413)


--- trunk/Source/WebCore/ChangeLog	2012-12-12 05:34:04 UTC (rev 137412)
+++ trunk/Source/WebCore/ChangeLog	2012-12-12 05:35:01 UTC (rev 137413)
@@ -1,3 +1,21 @@
+2012-12-11  Viatcheslav Ostapenko  <[email protected]>
+
+        Remove conversion to/from float and float division from ImageFrame::setRGBA
+        https://bugs.webkit.org/show_bug.cgi?id=103693
+
+        Reviewed by Brent Fulgham.
+
+        Replace floating point operations used for alpha premultiply with fixed point arithmetic
+        which is basically integer operations. Allows to shave extra couple percent from decoding
+        images with transparency.
+
+        Covered by existing tests.
+
+        * platform/image-decoders/ImageDecoder.h:
+        (ImageFrame):
+        (WebCore::ImageFrame::fixPointUnsignedMultiply):
+        (WebCore::ImageFrame::setRGBA):
+
 2012-12-11  Kihong Kwon  <[email protected]>
 
         Vibration API: IDL type doesn't match implementation type

Modified: trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h (137412 => 137413)


--- trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h	2012-12-12 05:34:04 UTC (rev 137412)
+++ trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h	2012-12-12 05:35:01 UTC (rev 137413)
@@ -159,6 +159,16 @@
         }
 #endif
 
+        // Use fix point multiplier instead of integer division or floating point math.
+        // This multipler produces exactly the same result for all values in range 0 - 255.
+        static const unsigned fixPointShift = 24;
+        static const unsigned fixPointMult = static_cast<unsigned>(1.0 / 255.0 * (1 << fixPointShift)) + 1;
+        // Multiplies unsigned value by fixpoint value and converts back to unsigned.
+        static unsigned fixPointUnsignedMultiply(unsigned fixed, unsigned v)
+        {
+            return  (fixed * v) >> fixPointShift;
+        }
+
         inline void setRGBA(PixelData* dest, unsigned r, unsigned g, unsigned b, unsigned a)
         {
             if (m_premultiplyAlpha && a < 255) {
@@ -167,10 +177,10 @@
                     return;
                 }
 
-                float alphaPercent = a / 255.0f;
-                r = static_cast<unsigned>(r * alphaPercent);
-                g = static_cast<unsigned>(g * alphaPercent);
-                b = static_cast<unsigned>(b * alphaPercent);
+                unsigned alphaMult = a * fixPointMult;
+                r = fixPointUnsignedMultiply(r, alphaMult);
+                g = fixPointUnsignedMultiply(g, alphaMult);
+                b = fixPointUnsignedMultiply(b, alphaMult);
             }
 #if USE(SKIA)
             // Call the "NoCheck" version since we may deliberately pass non-premultiplied
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to