Commit 1fbeb615 authored by caryclark@google.com's avatar caryclark@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.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96609 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c9258aee
2011-10-04 Cary Clark <caryclark@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 <leandro@profusion.mobi>
[CMake] Unreviewed: pass feature definitions in the right format for the CSS scripts.
......@@ -188,6 +188,9 @@ namespace WebCore {
#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;
......
......@@ -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 @@ void ImageFrame::setHasAlpha(bool alpha)
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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment