Title: [121292] trunk/Source/WebCore
Revision
121292
Author
noam.rosent...@nokia.com
Date
2012-06-26 15:51:35 -0700 (Tue, 26 Jun 2012)

Log Message

[Qt] Use premultiplied alpha when extracting image data in WebGL
https://bugs.webkit.org/show_bug.cgi?id=89937

Reviewed by Jocelyn Turcotte.

Perform conversion in QImage only if the image format is not ARGB32 or
ARGB32_Premultiplied. Otherwise, allow packPixels to perform the conversion if the formats
don't match, as packPixels already performs pixel-specific operations.

Covered by tests in LayoutTests/fast/canvas/webgl, e.g. webgl-composite-modes.html.

* platform/graphics/qt/GraphicsContext3DQt.cpp:
(WebCore::GraphicsContext3D::getImageData):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (121291 => 121292)


--- trunk/Source/WebCore/ChangeLog	2012-06-26 22:04:09 UTC (rev 121291)
+++ trunk/Source/WebCore/ChangeLog	2012-06-26 22:51:35 UTC (rev 121292)
@@ -1,3 +1,19 @@
+2012-06-26  No'am Rosenthal  <noam.rosent...@nokia.com>
+
+        [Qt] Use premultiplied alpha when extracting image data in WebGL
+        https://bugs.webkit.org/show_bug.cgi?id=89937
+
+        Reviewed by Jocelyn Turcotte.
+
+        Perform conversion in QImage only if the image format is not ARGB32 or
+        ARGB32_Premultiplied. Otherwise, allow packPixels to perform the conversion if the formats
+        don't match, as packPixels already performs pixel-specific operations.
+
+        Covered by tests in LayoutTests/fast/canvas/webgl, e.g. webgl-composite-modes.html.
+
+        * platform/graphics/qt/GraphicsContext3DQt.cpp:
+        (WebCore::GraphicsContext3D::getImageData):
+
 2012-06-26  Joshua Bell  <jsb...@chromium.org>
 
         IndexedDB: Move method precondition checks to front end objects

Modified: trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp (121291 => 121292)


--- trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp	2012-06-26 22:04:09 UTC (rev 121291)
+++ trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp	2012-06-26 22:51:35 UTC (rev 121292)
@@ -414,6 +414,7 @@
     // If GraphicsContext3D init failed in constructor, m_private set to nullptr and no buffers are allocated.
     if (!m_private)
         return;
+
     makeContextCurrent();
     glDeleteTextures(1, &m_texture);
     glDeleteFramebuffers(1, &m_fbo);
@@ -486,13 +487,13 @@
     UNUSED_PARAM(ignoreGammaAndColorProfile);
     if (!image)
         return false;
-    QImage nativeImage;
+
+    QImage qtImage;
     // Is image already loaded? If not, load it.
     if (image->data())
-        nativeImage = QImage::fromData(reinterpret_cast<const uchar*>(image->data()->data()), image->data()->size()).convertToFormat(QImage::Format_ARGB32);
+        qtImage = QImage::fromData(reinterpret_cast<const uchar*>(image->data()->data()), image->data()->size());
     else {
         QPixmap* nativePixmap = image->nativeImageForCurrentFrame();
-        QImage qtImage;
 #if HAVE(QT5)
         // With QPA, we can avoid a deep copy.
         qtImage = *nativePixmap->handle()->buffer();
@@ -500,19 +501,32 @@
         // This might be a deep copy, depending on other references to the pixmap.
         qtImage = nativePixmap->toImage();
 #endif
-        nativeImage = qtImage.convertToFormat(QImage::Format_ARGB32);
     }
-    AlphaOp neededAlphaOp = AlphaDoNothing;
-    if (premultiplyAlpha)
-        neededAlphaOp = AlphaDoPremultiply;
 
+    AlphaOp alphaOp = AlphaDoNothing;
+    switch (qtImage.format()) {
+    case QImage::Format_ARGB32:
+        if (premultiplyAlpha)
+            alphaOp = AlphaDoPremultiply;
+        break;
+    case QImage::Format_ARGB32_Premultiplied:
+        if (!premultiplyAlpha)
+            alphaOp = AlphaDoUnmultiply;
+        break;
+    default:
+        // The image has a format that is not supported in packPixels. We have to convert it here.
+        qtImage = qtImage.convertToFormat(premultiplyAlpha ? QImage::Format_ARGB32_Premultiplied : QImage::Format_ARGB32);
+        break;
+    }
+
     unsigned int packedSize;
     // Output data is tightly packed (alignment == 1).
     if (computeImageSizeInBytes(format, type, image->width(), image->height(), 1, &packedSize, 0) != GraphicsContext3D::NO_ERROR)
         return false;
+
     outputVector.resize(packedSize);
 
-    return packPixels(nativeImage.bits(), SourceFormatBGRA8, image->width(), image->height(), 0, format, type, neededAlphaOp, outputVector.data());
+    return packPixels(qtImage.bits(), SourceFormatBGRA8, image->width(), image->height(), 0, format, type, alphaOp, outputVector.data());
 }
 
 void GraphicsContext3D::setContextLostCallback(PassOwnPtr<ContextLostCallback>)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to