Paste number 95564: avoid function calls for pixel handling

Paste number 95564: avoid function calls for pixel handling
Pasted by: kov
When:1 year, 11 months ago
Share:Tweet this! | http://paste.lisp.org/+21QK
Channel:#webkit-gtk
Paste contents:
Raw Source | XML | Display As
diff --git a/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp b/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
index 124c7cf..8abcfb6 100644
--- a/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
+++ b/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp
@@ -180,17 +180,23 @@ PassRefPtr<ImageData> getImageData(const IntRect& rect, const ImageBufferData& d
     for (int y = 0; y < numRows; ++y) {
         unsigned* row = reinterpret_cast<unsigned*>(dataSrc + stride * (y + originy));
         for (int x = 0; x < numColumns; x++) {
-            int basex = x * 4;
+            unsigned char* destPixel = &destRows[x * 4];
             unsigned* pixel = row + x + originx;
-            Color pixelColor;
-            if (multiplied == Unmultiplied)
-                pixelColor = colorFromPremultipliedARGB(*pixel);
-            else
-                pixelColor = Color(*pixel);
-            destRows[basex]     = pixelColor.red();
-            destRows[basex + 1] = pixelColor.green();
-            destRows[basex + 2] = pixelColor.blue();
-            destRows[basex + 3] = pixelColor.alpha();
+            Color pixelColor = Color(*pixel);
+
+            if (multiplied == Unmultiplied) {
+                unsigned alpha = pixelColor.alpha();
+
+                destPixel[0] = alpha ? pixelColor.red() * 255 / alpha : 0;
+                destPixel[1] = alpha ? pixelColor.green() * 255 / alpha : 0;
+                destPixel[2] = alpha ? pixelColor.blue() * 255 / alpha : 0;
+                destPixel[3] = alpha;
+            } else {
+                destPixel[0] = pixelColor.red();
+                destPixel[1] = pixelColor.green();
+                destPixel[2] = pixelColor.blue();
+                destPixel[3] = pixelColor.alpha();
+            }
         }
         destRows += destBytesPerRow;
     }
@@ -250,20 +256,22 @@ void putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint&
         for (int x = 0; x < numColumns; x++) {
             int basex = x * 4;
             unsigned* pixel = row + x + destx;
-            Color pixelColor(srcRows[basex],
-                    srcRows[basex + 1],
-                    srcRows[basex + 2],
-                    srcRows[basex + 3]);
-            if (multiplied == Unmultiplied)
-                *pixel = premultipliedARGBFromColor(pixelColor);
-            else
-                *pixel = pixelColor.rgb();
+            if (multiplied == Unmultiplied) {
+                unsigned char alpha = srcRows[basex + 3];
+
+                pixel[basex] = (srcRows[basex] * alpha + 254) / 255;
+                pixel[basex + 1] = (srcRows[basex + 1] * alpha + 254) / 255;
+                pixel[basex + 2] = (srcRows[basex + 2] * alpha + 254) / 255;
+                pixel[basex + 3] = alpha;
+            } else {
+                *pixel = srcRows[basex];
+            }
         }
         srcRows += srcBytesPerRow;
     }
-    cairo_surface_mark_dirty_rectangle (data.m_surface,
-                                        destx, desty,
-                                        numColumns, numRows);
+    cairo_surface_mark_dirty_rectangle(data.m_surface,
+                                       destx, desty,
+                                       numColumns, numRows);
 }
 
 void ImageBuffer::putUnmultipliedImageData(ImageData* source, const IntRect& sourceRect, const IntPoint& destPoint)

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.