Title: [96609] trunk/Source/WebCore
Revision
96609
Author
carycl...@google.com
Date
2011-10-04 10:49:46 -0700 (Tue, 04 Oct 2011)

Log Message

Apply color profile found to decoded bitmap (Skia on Mac)
https://bugs.webkit.org/show_bug.cgi?id=69144
This fixes http://code.google.com/p/chromium/issues/detail?id=97830

Reviewed by Stephen White.

No new tests. This platform is not enabled.

* platform/image-decoders/ImageDecoder.h:
Add color profile slot to Skia variation.

* platform/image-decoders/skia/ImageDecoderSkia.cpp:
(WebCore::resolveColorSpace):
Adjust the bitmap in place to use the supplied color space.

(WebCore::createColorSpace):
Create a CGColorSpace from a color profile.

(WebCore::ImageFrame::setColorProfile):
Save the image's color profile until the image is complete.

(WebCore::ImageFrame::setStatus):
Apply the color profile, if any, to the image.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (96608 => 96609)


--- trunk/Source/WebCore/ChangeLog	2011-10-04 17:47:29 UTC (rev 96608)
+++ trunk/Source/WebCore/ChangeLog	2011-10-04 17:49:46 UTC (rev 96609)
@@ -1,3 +1,29 @@
+2011-10-04  Cary Clark  <carycl...@google.com>
+
+        Apply color profile found to decoded bitmap (Skia on Mac)
+        https://bugs.webkit.org/show_bug.cgi?id=69144
+        This fixes http://code.google.com/p/chromium/issues/detail?id=97830
+
+        Reviewed by Stephen White.
+
+        No new tests. This platform is not enabled.
+
+        * platform/image-decoders/ImageDecoder.h:
+        Add color profile slot to Skia variation.
+
+        * platform/image-decoders/skia/ImageDecoderSkia.cpp:
+        (WebCore::resolveColorSpace):
+        Adjust the bitmap in place to use the supplied color space.
+
+        (WebCore::createColorSpace):
+        Create a CGColorSpace from a color profile.
+
+        (WebCore::ImageFrame::setColorProfile):
+        Save the image's color profile until the image is complete.
+
+        (WebCore::ImageFrame::setStatus):
+        Apply the color profile, if any, to the image.
+
 2011-10-04  Leandro Pereira  <lean...@profusion.mobi>
 
         [CMake] Unreviewed: pass feature definitions in the right format for the CSS scripts.

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


--- trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h	2011-10-04 17:47:29 UTC (rev 96608)
+++ trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h	2011-10-04 17:49:46 UTC (rev 96609)
@@ -188,6 +188,9 @@
 
 #if USE(SKIA)
         NativeImageSkia m_bitmap;
+#if PLATFORM(CHROMIUM) && OS(DARWIN)
+        ColorProfile m_colorProfile;
+#endif
 #elif PLATFORM(QT)
         mutable QPixmap m_pixmap;
         mutable QImage m_image;

Modified: trunk/Source/WebCore/platform/image-decoders/skia/ImageDecoderSkia.cpp (96608 => 96609)


--- trunk/Source/WebCore/platform/image-decoders/skia/ImageDecoderSkia.cpp	2011-10-04 17:47:29 UTC (rev 96608)
+++ trunk/Source/WebCore/platform/image-decoders/skia/ImageDecoderSkia.cpp	2011-10-04 17:49:46 UTC (rev 96609)
@@ -29,6 +29,11 @@
 
 #include "NotImplemented.h"
 
+#if PLATFORM(CHROMIUM) && OS(DARWIN)
+#include "GraphicsContextCG.h"
+#include "SkCGUtils.h"
+#endif
+
 namespace WebCore {
 
 ImageFrame::ImageFrame()
@@ -110,16 +115,56 @@
     m_bitmap.bitmap().setIsOpaque(!alpha);
 }
 
+#if PLATFORM(CHROMIUM) && OS(DARWIN)
+static void resolveColorSpace(const SkBitmap& bitmap, CGColorSpaceRef colorSpace)
+{
+    int width = bitmap.width();
+    int height = bitmap.height();
+    CGImageRef srcImage = SkCreateCGImageRefWithColorspace(bitmap, colorSpace);
+    SkAutoLockPixels lock(bitmap);
+    void* pixels = bitmap.getPixels();
+    RetainPtr<CGContextRef> cgBitmap(AdoptCF, CGBitmapContextCreate(pixels, width, height, 8, width * 4, deviceRGBColorSpaceRef(), kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst));
+    if (!cgBitmap)
+        return;
+    CGContextSetBlendMode(cgBitmap.get(), kCGBlendModeCopy);
+    CGRect bounds = { {0, 0}, {width, height} };
+    CGContextDrawImage(cgBitmap.get(), bounds, srcImage);
+}
+
+static CGColorSpaceRef createColorSpace(const ColorProfile& colorProfile)
+{
+    RetainPtr<CFDataRef> data(AdoptCF, CFDataCreate(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(colorProfile.data()), colorProfile.size()));
+#ifndef TARGETING_LEOPARD
+    return CGColorSpaceCreateWithICCProfile(data.get());
+#else
+    RetainPtr<CGDataProviderRef> profileDataProvider(AdoptCF, CGDataProviderCreateWithCFData(data.get()));
+    CGFloat ranges[] = {0.0, 255.0, 0.0, 255.0, 0.0, 255.0};
+    return CGColorSpaceCreateICCBased(3, ranges, profileDataProvider.get(), deviceRGBColorSpaceRef());
+#endif
+}
+#endif
+
 void ImageFrame::setColorProfile(const ColorProfile& colorProfile)
 {
+#if PLATFORM(CHROMIUM) && OS(DARWIN)
+    m_colorProfile = colorProfile;
+#else
     notImplemented();
+#endif
 }
 
 void ImageFrame::setStatus(FrameStatus status)
 {
     m_status = status;
-    if (m_status == FrameComplete)
+    if (m_status == FrameComplete) {
         m_bitmap.setDataComplete();  // Tell the bitmap it's done.
+#if PLATFORM(CHROMIUM) && OS(DARWIN)
+        if (m_colorProfile.isEmpty())
+            return;
+        RetainPtr<CGColorSpaceRef> cgColorSpace(AdoptCF, createColorSpace(m_colorProfile));
+        resolveColorSpace(m_bitmap.bitmap(), cgColorSpace.get());
+#endif
+    }
 }
 
 int ImageFrame::width() const
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to