[CG] ImageBuffer::toDataURL: Remove alpha stuffing loop when encoding to JPEG
authornoel.gordon@gmail.com <noel.gordon@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Apr 2012 06:56:22 +0000 (06:56 +0000)
committernoel.gordon@gmail.com <noel.gordon@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Apr 2012 06:56:22 +0000 (06:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=84319

Reviewed by Eric Seidel.

No change in behavior. Covered by existing canvas 2d and 3d tests:

  canvas/philip/tests/toDataURL.jpeg.alpha.html
  fast/canvas/webgl/premultiplyalpha-test.html

* platform/graphics/cg/ImageBufferCG.cpp:
(WebCore::ImageBuffer::toDataURL): Remove the alpha stuffing loop and instead,
make JPEG encoder ignore the alpha channel (kCGImageAlphaNoneSkipLast).

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@114616 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp

index 64edb19..e8c50ec 100644 (file)
@@ -1,3 +1,19 @@
+2012-04-18  Noel Gordon  <noel.gordon@gmail.com>
+
+        [CG] ImageBuffer::toDataURL: Remove alpha stuffing loop when encoding to JPEG
+        https://bugs.webkit.org/show_bug.cgi?id=84319
+
+        Reviewed by Eric Seidel.
+
+        No change in behavior. Covered by existing canvas 2d and 3d tests:
+
+          canvas/philip/tests/toDataURL.jpeg.alpha.html
+          fast/canvas/webgl/premultiplyalpha-test.html
+
+        * platform/graphics/cg/ImageBufferCG.cpp:
+        (WebCore::ImageBuffer::toDataURL): Remove the alpha stuffing loop and instead,
+        make JPEG encoder ignore the alpha channel (kCGImageAlphaNoneSkipLast).
+
 2012-04-18  Emil A Eklund  <eae@chromium.org>
 
         Remove unnecessary rounding/conversions in RenderBoxModelObject
index 752ac4d..7e930d5 100644 (file)
@@ -449,17 +449,13 @@ String ImageBuffer::toDataURL(const String& mimeType, const double* quality, Coo
         if (!premultipliedData)
             return "data:,";
 
-        unsigned char *data = premultipliedData->data();
-        for (int i = 0; i < logicalSize().width() * logicalSize().height(); i++)
-            data[i * 4 + 3] = 255; // The data is premultiplied, we just need to make it opaque.
-
         RetainPtr<CGDataProviderRef> dataProvider;
-        dataProvider.adoptCF(CGDataProviderCreateWithData(0, data, 4 * logicalSize().width() * logicalSize().height(), 0));
+        dataProvider.adoptCF(CGDataProviderCreateWithData(0, premultipliedData->data(), 4 * logicalSize().width() * logicalSize().height(), 0));
         if (!dataProvider)
             return "data:,";
 
         image.adoptCF(CGImageCreate(logicalSize().width(), logicalSize().height(), 8, 32, 4 * logicalSize().width(),
-                                    deviceRGBColorSpaceRef(), kCGBitmapByteOrderDefault | kCGImageAlphaLast,
+                                    deviceRGBColorSpaceRef(), kCGBitmapByteOrderDefault | kCGImageAlphaNoneSkipLast,
                                     dataProvider.get(), 0, false, kCGRenderingIntentDefault));
     } else if (m_resolutionScale == 1)
         image.adoptCF(copyNativeImage(CopyBackingStore));