Title: [225453] trunk/Source/WebCore
Revision
225453
Author
[email protected]
Date
2017-12-02 12:35:46 -0800 (Sat, 02 Dec 2017)

Log Message

Add an AlphaPremultiplication enum and use it consistently
https://bugs.webkit.org/show_bug.cgi?id=180316

Reviewed by Zalan Bujtas.

ImageBuffer-related code sometimes used the 'Multiply' enum, and sometimes
a bool to represent alpha premultiplication. Make an enum class and use it
everywhere. Re-order and rename some parameters to clarify the meaning of this
argument.

* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::putImageData):
* platform/graphics/GraphicsTypes.cpp:
(WebCore::operator<<):
* platform/graphics/GraphicsTypes.h:
* platform/graphics/ImageBuffer.cpp:
(WebCore::ImageBuffer::genericConvertToLuminanceMask):
* platform/graphics/ImageBuffer.h:
* platform/graphics/ShadowBlur.cpp:
(WebCore::ShadowBlur::blurShadowBuffer):
* platform/graphics/cairo/ImageBufferCairo.cpp:
(WebCore::getImageData):
(WebCore::ImageBuffer::getUnmultipliedImageData const):
(WebCore::ImageBuffer::getPremultipliedImageData const):
(WebCore::ImageBuffer::putByteArray):
* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::ImageBuffer::getUnmultipliedImageData const):
(WebCore::ImageBuffer::getPremultipliedImageData const):
(WebCore::ImageBuffer::putByteArray):
* platform/graphics/cg/ImageBufferDataCG.cpp:
(WebCore::ImageBufferData::getData const):
(WebCore::ImageBufferData::putData):
* platform/graphics/cg/ImageBufferDataCG.h:
* platform/graphics/filters/FEColorMatrix.cpp:
(WebCore::FEColorMatrix::platformApplySoftware):
* platform/graphics/filters/FEDropShadow.cpp:
(WebCore::FEDropShadow::platformApplySoftware):
* platform/graphics/filters/FilterEffect.cpp:
(WebCore::FilterEffect::imageBufferResult):
* platform/graphics/win/ImageBufferDataDirect2D.cpp:
(WebCore::ImageBufferData::getData const):
(WebCore::ImageBufferData::putData):
* platform/graphics/win/ImageBufferDataDirect2D.h:
* platform/graphics/win/ImageBufferDirect2D.cpp:
(WebCore::ImageBuffer::getUnmultipliedImageData const):
(WebCore::ImageBuffer::getPremultipliedImageData const):
(WebCore::ImageBuffer::putByteArray):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (225452 => 225453)


--- trunk/Source/WebCore/ChangeLog	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/ChangeLog	2017-12-02 20:35:46 UTC (rev 225453)
@@ -1,3 +1,53 @@
+2017-12-02  Simon Fraser  <[email protected]>
+
+        Add an AlphaPremultiplication enum and use it consistently
+        https://bugs.webkit.org/show_bug.cgi?id=180316
+
+        Reviewed by Zalan Bujtas.
+
+        ImageBuffer-related code sometimes used the 'Multiply' enum, and sometimes
+        a bool to represent alpha premultiplication. Make an enum class and use it
+        everywhere. Re-order and rename some parameters to clarify the meaning of this
+        argument.
+
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::putImageData):
+        * platform/graphics/GraphicsTypes.cpp:
+        (WebCore::operator<<):
+        * platform/graphics/GraphicsTypes.h:
+        * platform/graphics/ImageBuffer.cpp:
+        (WebCore::ImageBuffer::genericConvertToLuminanceMask):
+        * platform/graphics/ImageBuffer.h:
+        * platform/graphics/ShadowBlur.cpp:
+        (WebCore::ShadowBlur::blurShadowBuffer):
+        * platform/graphics/cairo/ImageBufferCairo.cpp:
+        (WebCore::getImageData):
+        (WebCore::ImageBuffer::getUnmultipliedImageData const):
+        (WebCore::ImageBuffer::getPremultipliedImageData const):
+        (WebCore::ImageBuffer::putByteArray):
+        * platform/graphics/cg/ImageBufferCG.cpp:
+        (WebCore::ImageBuffer::getUnmultipliedImageData const):
+        (WebCore::ImageBuffer::getPremultipliedImageData const):
+        (WebCore::ImageBuffer::putByteArray):
+        * platform/graphics/cg/ImageBufferDataCG.cpp:
+        (WebCore::ImageBufferData::getData const):
+        (WebCore::ImageBufferData::putData):
+        * platform/graphics/cg/ImageBufferDataCG.h:
+        * platform/graphics/filters/FEColorMatrix.cpp:
+        (WebCore::FEColorMatrix::platformApplySoftware):
+        * platform/graphics/filters/FEDropShadow.cpp:
+        (WebCore::FEDropShadow::platformApplySoftware):
+        * platform/graphics/filters/FilterEffect.cpp:
+        (WebCore::FilterEffect::imageBufferResult):
+        * platform/graphics/win/ImageBufferDataDirect2D.cpp:
+        (WebCore::ImageBufferData::getData const):
+        (WebCore::ImageBufferData::putData):
+        * platform/graphics/win/ImageBufferDataDirect2D.h:
+        * platform/graphics/win/ImageBufferDirect2D.cpp:
+        (WebCore::ImageBuffer::getUnmultipliedImageData const):
+        (WebCore::ImageBuffer::getPremultipliedImageData const):
+        (WebCore::ImageBuffer::putByteArray):
+
 2017-12-02  Youenn Fablet  <[email protected]>
 
         Implement https://w3c.github.io/ServiceWorker/#clients-getall

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (225452 => 225453)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2017-12-02 20:35:46 UTC (rev 225453)
@@ -2245,7 +2245,7 @@
     sourceRect.intersect(IntRect(0, 0, data.width(), data.height()));
 
     if (!sourceRect.isEmpty())
-        buffer->putByteArray(Unmultiplied, *data.data(), IntSize(data.width(), data.height()), sourceRect, IntPoint(destOffset), coordinateSystem);
+        buffer->putByteArray(*data.data(), AlphaPremultiplication::Unpremultiplied, IntSize(data.width(), data.height()), sourceRect, IntPoint(destOffset), coordinateSystem);
 
     didDraw(destRect, CanvasDidDrawApplyNone); // ignore transform, shadow and clip
 }

Modified: trunk/Source/WebCore/platform/graphics/GraphicsTypes.cpp (225452 => 225453)


--- trunk/Source/WebCore/platform/graphics/GraphicsTypes.cpp	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/platform/graphics/GraphicsTypes.cpp	2017-12-02 20:35:46 UTC (rev 225453)
@@ -181,5 +181,17 @@
     return ts;
 }
 
+TextStream& operator<<(TextStream& ts, AlphaPremultiplication premultiplication)
+{
+    switch (premultiplication) {
+    case AlphaPremultiplication::Premultiplied:
+        ts << "premultiplied";
+        break;
+    case AlphaPremultiplication::Unpremultiplied:
+        ts << "unpremultiplied";
+        break;
+    }
+    return ts;
+}
 
-}
+} // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/GraphicsTypes.h (225452 => 225453)


--- trunk/Source/WebCore/platform/graphics/GraphicsTypes.h	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/platform/graphics/GraphicsTypes.h	2017-12-02 20:35:46 UTC (rev 225453)
@@ -102,6 +102,11 @@
     Accelerated
 };
 
+enum class AlphaPremultiplication {
+    Premultiplied,
+    Unpremultiplied
+};
+
 String compositeOperatorName(CompositeOperator, BlendMode);
 bool parseBlendMode(const String&, BlendMode&);
 bool parseCompositeAndBlendOperator(const String&, CompositeOperator&, BlendMode&);
@@ -117,6 +122,7 @@
 WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, WindRule);
 WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, LineCap);
 WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, LineJoin);
+WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, AlphaPremultiplication);
 
 } // namespace WebCore
 

Modified: trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp (225452 => 225453)


--- trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp	2017-12-02 20:35:46 UTC (rev 225453)
@@ -180,7 +180,7 @@
         double luma = (r * 0.2125 + g * 0.7154 + b * 0.0721) * ((double)a / 255.0);
         srcPixelArray->set(pixelOffset + 3, luma);
     }
-    putByteArray(Unmultiplied, *srcPixelArray, luminanceRect.size(), luminanceRect, IntPoint());
+    putByteArray(*srcPixelArray, AlphaPremultiplication::Unpremultiplied, luminanceRect.size(), luminanceRect, IntPoint());
 }
 
 void ImageBuffer::convertToLuminanceMask()

Modified: trunk/Source/WebCore/platform/graphics/ImageBuffer.h (225452 => 225453)


--- trunk/Source/WebCore/platform/graphics/ImageBuffer.h	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/platform/graphics/ImageBuffer.h	2017-12-02 20:35:46 UTC (rev 225453)
@@ -50,11 +50,6 @@
 class IntPoint;
 class IntRect;
 
-enum Multiply {
-    Premultiplied,
-    Unmultiplied
-};
-
 enum BackingStoreCopy {
     CopyBackingStore, // Guarantee subsequent draws don't affect the copy.
     DontCopyBackingStore // Subsequent draws may affect the copy.
@@ -106,7 +101,7 @@
     RefPtr<Uint8ClampedArray> getUnmultipliedImageData(const IntRect&, IntSize* pixelArrayDimensions = nullptr, CoordinateSystem = LogicalCoordinateSystem) const;
     RefPtr<Uint8ClampedArray> getPremultipliedImageData(const IntRect&, IntSize* pixelArrayDimensions = nullptr, CoordinateSystem = LogicalCoordinateSystem) const;
 
-    void putByteArray(Multiply multiplied, const Uint8ClampedArray&, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem = LogicalCoordinateSystem);
+    void putByteArray(const Uint8ClampedArray&, AlphaPremultiplication bufferFormat, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem = LogicalCoordinateSystem);
     
     void convertToLuminanceMask();
     

Modified: trunk/Source/WebCore/platform/graphics/ShadowBlur.cpp (225452 => 225453)


--- trunk/Source/WebCore/platform/graphics/ShadowBlur.cpp	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/platform/graphics/ShadowBlur.cpp	2017-12-02 20:35:46 UTC (rev 225453)
@@ -865,7 +865,7 @@
         return;
 
     blurLayerImage(layerData->data(), blurRect.size(), blurRect.width() * 4);
-    m_layerImage->putByteArray(Unmultiplied, *layerData, blurRect.size(), blurRect, IntPoint());
+    m_layerImage->putByteArray(*layerData, AlphaPremultiplication::Unpremultiplied, blurRect.size(), blurRect, { });
 }
 
 void ShadowBlur::blurAndColorShadowBuffer(const IntSize& templateSize)

Modified: trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp (225452 => 225453)


--- trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2017-12-02 20:35:46 UTC (rev 225453)
@@ -339,7 +339,7 @@
     return adoptRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, rect.width(), rect.height()));
 }
 
-template <Multiply multiplied>
+template <AlphaPremultiplication premultiplied>
 RefPtr<Uint8ClampedArray> getImageData(const IntRect& rect, const IntRect& logicalRect, const ImageBufferData& data, const IntSize& size, const IntSize& logicalSize, float resolutionScale)
 {
     auto result = Uint8ClampedArray::createUninitialized(rect.width() * rect.height() * 4);
@@ -403,7 +403,7 @@
             unsigned green = (*pixel & 0x0000FF00) >> 8;
             unsigned blue = (*pixel & 0x000000FF);
 
-            if (multiplied == Unmultiplied) {
+            if (premultiplied == AlphaPremultiplication::Unpremultiplied) {
                 if (alpha && alpha != 255) {
                     red = red * 255 / alpha;
                     green = green * 255 / alpha;
@@ -448,7 +448,7 @@
     IntRect backingStoreRect = backingStoreUnit(rect, coordinateSystem, m_resolutionScale);
     if (pixelArrayDimensions)
         *pixelArrayDimensions = backingStoreRect.size();
-    return getImageData<Unmultiplied>(backingStoreRect, logicalRect, m_data, m_size, m_logicalSize, m_resolutionScale);
+    return getImageData<AlphaPremultiplication::Unpremultiplied>(backingStoreRect, logicalRect, m_data, m_size, m_logicalSize, m_resolutionScale);
 }
 
 RefPtr<Uint8ClampedArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, IntSize* pixelArrayDimensions, CoordinateSystem coordinateSystem) const
@@ -457,10 +457,10 @@
     IntRect backingStoreRect = backingStoreUnit(rect, coordinateSystem, m_resolutionScale);
     if (pixelArrayDimensions)
         *pixelArrayDimensions = backingStoreRect.size();
-    return getImageData<Premultiplied>(backingStoreRect, logicalRect, m_data, m_size, m_logicalSize, m_resolutionScale);
+    return getImageData<AlphaPremultiplication::Premultiplied>(backingStoreRect, logicalRect, m_data, m_size, m_logicalSize, m_resolutionScale);
 }
 
-void ImageBuffer::putByteArray(Multiply multiplied, const Uint8ClampedArray& source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem coordinateSystem)
+void ImageBuffer::putByteArray(const Uint8ClampedArray& source, AlphaPremultiplication sourceFormat, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem coordinateSystem)
 {
     IntRect scaledSourceRect = backingStoreUnit(sourceRect, coordinateSystem, m_resolutionScale);
     IntSize scaledSourceSize = backingStoreUnit(sourceSize, coordinateSystem, m_resolutionScale);
@@ -527,7 +527,7 @@
             unsigned blue = srcRows[basex + 2];
             unsigned alpha = srcRows[basex + 3];
 
-            if (multiplied == Unmultiplied) {
+            if (sourceFormat == AlphaPremultiplication::Unpremultiplied) {
                 if (alpha != 255) {
                     red = (red * alpha + 254) / 255;
                     green = (green * alpha + 254) / 255;

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp (225452 => 225453)


--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp	2017-12-02 20:35:46 UTC (rev 225453)
@@ -397,7 +397,7 @@
     if (pixelArrayDimensions)
         *pixelArrayDimensions = srcRect.size();
 
-    return m_data.getData(srcRect, internalSize(), context().isAcceleratedContext(), true, 1);
+    return m_data.getData(AlphaPremultiplication::Unpremultiplied, srcRect, internalSize(), context().isAcceleratedContext(), 1);
 }
 
 RefPtr<Uint8ClampedArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, IntSize* pixelArrayDimensions, CoordinateSystem coordinateSystem) const
@@ -412,10 +412,10 @@
     if (pixelArrayDimensions)
         *pixelArrayDimensions = srcRect.size();
 
-    return m_data.getData(srcRect, internalSize(), context().isAcceleratedContext(), false, 1);
+    return m_data.getData(AlphaPremultiplication::Premultiplied, srcRect, internalSize(), context().isAcceleratedContext(), 1);
 }
 
-void ImageBuffer::putByteArray(Multiply multiplied, const Uint8ClampedArray& source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem coordinateSystem)
+void ImageBuffer::putByteArray(const Uint8ClampedArray& source, AlphaPremultiplication sourceFormat, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem coordinateSystem)
 {
     if (context().isAcceleratedContext())
         flushContext();
@@ -427,7 +427,7 @@
         scaledSourceSize.scale(m_resolutionScale);
     }
 
-    m_data.putData(source, scaledSourceSize, scaledSourceRect, destPoint, internalSize(), context().isAcceleratedContext(), multiplied == Unmultiplied, 1);
+    m_data.putData(source, sourceFormat, scaledSourceSize, scaledSourceRect, destPoint, internalSize(), context().isAcceleratedContext(), 1);
     
     // Force recreating the IOSurface cached image if it is requested through CGIOSurfaceContextCreateImage().
     // See https://bugs.webkit.org/show_bug.cgi?id=157966 for explaining why this is necessary.

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferDataCG.cpp (225452 => 225453)


--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferDataCG.cpp	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferDataCG.cpp	2017-12-02 20:35:46 UTC (rev 225453)
@@ -142,7 +142,7 @@
 }
 
 
-RefPtr<Uint8ClampedArray> ImageBufferData::getData(const IntRect& rect, const IntSize& size, bool accelerateRendering, bool unmultiplied, float resolutionScale) const
+RefPtr<Uint8ClampedArray> ImageBufferData::getData(AlphaPremultiplication outputFormat, const IntRect& rect, const IntSize& size, bool accelerateRendering, float resolutionScale) const
 {
     Checked<unsigned, RecordOverflow> area = 4;
     area *= rect.width();
@@ -207,7 +207,7 @@
         srcRows = reinterpret_cast<uint8_t*>(data) + originy * srcBytesPerRow + originx * 4;
 
 #if USE(ACCELERATE)
-        if (unmultiplied) {
+        if (outputFormat == AlphaPremultiplication::Unpremultiplied) {
 
             vImage_Buffer src;
             src.width = width.unsafeGet();
@@ -242,7 +242,7 @@
             RetainPtr<CGContextRef> destinationContext = adoptCF(CGBitmapContextCreate(destRows, destw.unsafeGet(), desth.unsafeGet(), 8, destBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast));
             CGContextSetBlendMode(destinationContext.get(), kCGBlendModeCopy);
             CGContextDrawImage(destinationContext.get(), CGRectMake(0, 0, width.unsafeGet() / resolutionScale, height.unsafeGet() / resolutionScale), sourceImage.get()); // FIXME: Add subpixel translation.
-            if (!unmultiplied)
+            if (outputFormat == AlphaPremultiplication::Premultiplied)
                 return result;
 
             srcRows = destRows;
@@ -250,7 +250,7 @@
             width = destw;
             height = desth;
         }
-        if (unmultiplied) {
+        if (outputFormat == AlphaPremultiplication::Unpremultiplied) {
             if ((width * 4).hasOverflowed())
                 CRASH();
             for (int y = 0; y < height.unsafeGet(); ++y) {
@@ -329,7 +329,7 @@
             src = ""
         }
 
-        if (unmultiplied)
+        if (outputFormat == AlphaPremultiplication::Unpremultiplied)
             unpremultiplyBufferData(src, dest);
         else {
             // Swap pixel channels from BGRA to RGBA.
@@ -353,7 +353,7 @@
         if ((width * 4).hasOverflowed())
             CRASH();
 
-        if (unmultiplied) {
+        if (outputFormat == AlphaPremultiplication::Unpremultiplied) {
             for (int y = 0; y < height.unsafeGet(); ++y) {
                 for (int x = 0; x < width.unsafeGet(); x++) {
                     int basex = x * 4;
@@ -398,7 +398,7 @@
     return result;
 }
 
-void ImageBufferData::putData(const Uint8ClampedArray& source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, const IntSize& size, bool accelerateRendering, bool unmultiplied, float resolutionScale)
+void ImageBufferData::putData(const Uint8ClampedArray& source, AlphaPremultiplication sourceFormat, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, const IntSize& size, bool accelerateRendering, float resolutionScale)
 {
 #if ASSERT_DISABLED
     UNUSED_PARAM(size);
@@ -453,7 +453,7 @@
         destRows = reinterpret_cast<uint8_t*>(data) + (desty * destBytesPerRow + destx * 4).unsafeGet();
 
 #if USE(ACCELERATE)
-        if (unmultiplied) {
+        if (sourceFormat == AlphaPremultiplication::Unpremultiplied) {
 
             vImage_Buffer src;
             src.width = width.unsafeGet();
@@ -487,7 +487,7 @@
             RetainPtr<CGContextRef> destinationContext = adoptCF(CGBitmapContextCreate(destRows, destw.unsafeGet(), desth.unsafeGet(), 8, destBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast));
             CGContextSetBlendMode(destinationContext.get(), kCGBlendModeCopy);
             CGContextDrawImage(destinationContext.get(), CGRectMake(0, 0, width.unsafeGet() / resolutionScale, height.unsafeGet() / resolutionScale), sourceImage.get()); // FIXME: Add subpixel translation.
-            if (!unmultiplied)
+            if (sourceFormat == AlphaPremultiplication::Premultiplied)
                 return;
 
             // The premultiplying will be done in-place.
@@ -503,7 +503,7 @@
                 uint8_t alpha = srcRows[basex + 3];
 #if USE_ARGB32
                 // Byte order is different as we use image buffers of ARGB32
-                if (unmultiplied && alpha != 255) {
+                if (sourceFormat == AlphaPremultiplication::Unpremultiplied && alpha != 255) {
                     destRows[basex] = (srcRows[basex + 2] * alpha + 254) / 255;
                     destRows[basex + 1] = (srcRows[basex + 1] * alpha + 254) / 255;
                     destRows[basex + 2] = (srcRows[basex + 0] * alpha + 254) / 255;
@@ -515,7 +515,7 @@
                     destRows[basex + 3] = alpha;
                 }
 #else
-                if (unmultiplied && alpha != 255) {
+                if (sourceFormat == AlphaPremultiplication::Unpremultiplied && alpha != 255) {
                     destRows[basex] = (srcRows[basex] * alpha + 254) / 255;
                     destRows[basex + 1] = (srcRows[basex + 1] * alpha + 254) / 255;
                     destRows[basex + 2] = (srcRows[basex + 2] * alpha + 254) / 255;
@@ -553,7 +553,7 @@
             src = ""
         }
 
-        if (unmultiplied)
+        if (sourceFormat == AlphaPremultiplication::Unpremultiplied)
             premultiplyBufferData(src, dest);
         else {
             // Swap pixel channels from RGBA to BGRA.
@@ -579,7 +579,7 @@
                 int basex = x * 4;
                 uint8_t b = srcRows[basex];
                 uint8_t alpha = srcRows[basex + 3];
-                if (unmultiplied && alpha != 255) {
+                if (sourceFormat == AlphaPremultiplication::Unpremultiplied && alpha != 255) {
                     destRows[basex] = (srcRows[basex + 2] * alpha + 254) / 255;
                     destRows[basex + 1] = (srcRows[basex + 1] * alpha + 254) / 255;
                     destRows[basex + 2] = (b * alpha + 254) / 255;

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageBufferDataCG.h (225452 => 225453)


--- trunk/Source/WebCore/platform/graphics/cg/ImageBufferDataCG.h	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageBufferDataCG.h	2017-12-02 20:35:46 UTC (rev 225453)
@@ -62,8 +62,8 @@
 #endif
 
     Vector<uint8_t> toBGRAData(bool accelerateRendering, int width, int height) const;
-    RefPtr<Uint8ClampedArray> getData(const IntRect&, const IntSize&, bool accelerateRendering, bool unmultiplied, float resolutionScale) const;
-    void putData(const Uint8ClampedArray& source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, const IntSize&, bool accelerateRendering, bool unmultiplied, float resolutionScale);
+    RefPtr<Uint8ClampedArray> getData(AlphaPremultiplication, const IntRect&, const IntSize&, bool accelerateRendering, float resolutionScale) const;
+    void putData(const Uint8ClampedArray& source, AlphaPremultiplication sourceFormat, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, const IntSize&, bool accelerateRendering, float resolutionScale);
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/filters/FEColorMatrix.cpp (225452 => 225453)


--- trunk/Source/WebCore/platform/graphics/filters/FEColorMatrix.cpp	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/platform/graphics/filters/FEColorMatrix.cpp	2017-12-02 20:35:46 UTC (rev 225453)
@@ -310,7 +310,7 @@
         break;
     }
 
-    resultImage->putByteArray(Unmultiplied, *pixelArray, imageRect.size(), imageRect, IntPoint());
+    resultImage->putByteArray(*pixelArray, AlphaPremultiplication::Unpremultiplied, imageRect.size(), imageRect, IntPoint());
 }
 
 static TextStream& operator<<(TextStream& ts, const ColorMatrixType& type)

Modified: trunk/Source/WebCore/platform/graphics/filters/FEDropShadow.cpp (225452 => 225453)


--- trunk/Source/WebCore/platform/graphics/filters/FEDropShadow.cpp	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/platform/graphics/filters/FEDropShadow.cpp	2017-12-02 20:35:46 UTC (rev 225453)
@@ -105,7 +105,7 @@
 
     contextShadow.blurLayerImage(srcPixelArray->data(), shadowArea.size(), 4 * shadowArea.size().width());
 
-    resultImage->putByteArray(Premultiplied, *srcPixelArray, shadowArea.size(), shadowArea, IntPoint(), ImageBuffer::BackingStoreCoordinateSystem);
+    resultImage->putByteArray(*srcPixelArray, AlphaPremultiplication::Premultiplied, shadowArea.size(), shadowArea, IntPoint(), ImageBuffer::BackingStoreCoordinateSystem);
 
     resultContext.setCompositeOperation(CompositeSourceIn);
     resultContext.fillRect(FloatRect(FloatPoint(), absolutePaintRect().size()), m_shadowColor);

Modified: trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp (225452 => 225453)


--- trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/platform/graphics/filters/FilterEffect.cpp	2017-12-02 20:35:46 UTC (rev 225453)
@@ -225,9 +225,9 @@
 
     IntRect destinationRect(IntPoint(), m_absolutePaintRect.size());
     if (m_premultipliedImageResult)
-        m_imageBufferResult->putByteArray(Premultiplied, *m_premultipliedImageResult, destinationRect.size(), destinationRect, IntPoint());
+        m_imageBufferResult->putByteArray(*m_premultipliedImageResult, AlphaPremultiplication::Premultiplied, destinationRect.size(), destinationRect, IntPoint());
     else
-        m_imageBufferResult->putByteArray(Unmultiplied, *m_unmultipliedImageResult, destinationRect.size(), destinationRect, IntPoint());
+        m_imageBufferResult->putByteArray(*m_unmultipliedImageResult, AlphaPremultiplication::Unpremultiplied, destinationRect.size(), destinationRect, IntPoint());
     return m_imageBufferResult.get();
 }
 

Modified: trunk/Source/WebCore/platform/graphics/win/ImageBufferDataDirect2D.cpp (225452 => 225453)


--- trunk/Source/WebCore/platform/graphics/win/ImageBufferDataDirect2D.cpp	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/platform/graphics/win/ImageBufferDataDirect2D.cpp	2017-12-02 20:35:46 UTC (rev 225453)
@@ -41,7 +41,7 @@
 
 namespace WebCore {
 
-RefPtr<Uint8ClampedArray> ImageBufferData::getData(const IntRect& rect, const IntSize& size, bool /* accelerateRendering */, bool /* unmultiplied */, float /* resolutionScale */) const
+RefPtr<Uint8ClampedArray> ImageBufferData::getData(AlphaPremultiplication, const IntRect& rect, const IntSize& size, bool /* accelerateRendering */, float /* resolutionScale */) const
 {
     auto platformContext = context->platformContext();
 
@@ -84,7 +84,7 @@
     return result;
 }
 
-void ImageBufferData::putData(const Uint8ClampedArray& source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, const IntSize& size, bool /* accelerateRendering */, bool unmultiplied, float resolutionScale)
+void ImageBufferData::putData(const Uint8ClampedArray& source, AlphaPremultiplication sourceFormat, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, const IntSize& size, bool /* accelerateRendering */, float resolutionScale)
 {
     auto platformContext = context->platformContext();
     COMPtr<ID2D1BitmapRenderTarget> renderTarget(Query, platformContext);
@@ -140,7 +140,7 @@
         for (int x = 0; x < width.unsafeGet(); x++) {
             int basex = x * 4;
             uint8_t alpha = srcRows[basex + 3];
-            if (unmultiplied && alpha != 255) {
+            if (sourceFormat == AlphaPremultiplication::Unpremultiplied && alpha != 255) {
                 row[basex] = (srcRows[basex] * alpha + 254) / 255;
                 row[basex + 1] = (srcRows[basex + 1] * alpha + 254) / 255;
                 row[basex + 2] = (srcRows[basex + 2] * alpha + 254) / 255;

Modified: trunk/Source/WebCore/platform/graphics/win/ImageBufferDataDirect2D.h (225452 => 225453)


--- trunk/Source/WebCore/platform/graphics/win/ImageBufferDataDirect2D.h	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/platform/graphics/win/ImageBufferDataDirect2D.h	2017-12-02 20:35:46 UTC (rev 225453)
@@ -43,8 +43,8 @@
     std::unique_ptr<GraphicsContext> context;
     ID2D1RenderTarget* m_compatibleTarget { nullptr };
 
-    RefPtr<Uint8ClampedArray> getData(const IntRect&, const IntSize&, bool accelerateRendering, bool unmultiplied, float resolutionScale) const;
-    void putData(const Uint8ClampedArray& source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, const IntSize&, bool accelerateRendering, bool unmultiplied, float resolutionScale);
+    RefPtr<Uint8ClampedArray> getData(AlphaPremultiplication, const IntRect&, const IntSize&, bool accelerateRendering, float resolutionScale) const;
+    void putData(const Uint8ClampedArray& source, AlphaPremultiplication sourceFormat, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, const IntSize&, bool accelerateRendering, float resolutionScale);
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/win/ImageBufferDirect2D.cpp (225452 => 225453)


--- trunk/Source/WebCore/platform/graphics/win/ImageBufferDirect2D.cpp	2017-12-02 19:41:00 UTC (rev 225452)
+++ trunk/Source/WebCore/platform/graphics/win/ImageBufferDirect2D.cpp	2017-12-02 20:35:46 UTC (rev 225453)
@@ -225,7 +225,7 @@
     if (pixelArrayDimensions)
         *pixelArrayDimensions = srcRect.size();
 
-    return m_data.getData(srcRect, internalSize(), context().isAcceleratedContext(), true, 1);
+    return m_data.getData(AlphaPremultiplication::Unpremultiplied, srcRect, internalSize(), context().isAcceleratedContext(), 1);
 }
 
 RefPtr<Uint8ClampedArray> ImageBuffer::getPremultipliedImageData(const IntRect& rect, IntSize* pixelArrayDimensions, CoordinateSystem coordinateSystem) const
@@ -240,10 +240,10 @@
     if (pixelArrayDimensions)
         *pixelArrayDimensions = srcRect.size();
 
-    return m_data.getData(srcRect, internalSize(), context().isAcceleratedContext(), false, 1);
+    return m_data.getData(AlphaPremultiplication::Premultiplied, srcRect, internalSize(), context().isAcceleratedContext(), 1);
 }
 
-void ImageBuffer::putByteArray(Multiply multiplied, Uint8ClampedArray* source, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem coordinateSystem)
+void ImageBuffer::putByteArray(const Uint8ClampedArray& source, AlphaPremultiplication bufferFormat, const IntSize& sourceSize, const IntRect& sourceRect, const IntPoint& destPoint, CoordinateSystem coordinateSystem)
 {
     if (context().isAcceleratedContext())
         flushContext();
@@ -255,7 +255,7 @@
         scaledSourceSize.scale(m_resolutionScale);
     }
 
-    m_data.putData(source, scaledSourceSize, scaledSourceRect, destPoint, internalSize(), context().isAcceleratedContext(), multiplied == Unmultiplied, 1);
+    m_data.putData(source, bufferFormat, scaledSourceSize, scaledSourceRect, destPoint, internalSize(), context().isAcceleratedContext(), 1);
 }
 
 String ImageBuffer::toDataURL(const String&, std::optional<double>, CoordinateSystem) const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to