diff options
author | Teng-Hui Zhu <ztenghui@google.com> | 2010-11-10 15:31:59 -0800 |
---|---|---|
committer | Teng-Hui Zhu <ztenghui@google.com> | 2010-11-17 13:35:59 -0800 |
commit | 28040489d744e0c5d475a88663056c9040ed5320 (patch) | |
tree | c463676791e4a63e452a95f0a12b2a8519730693 /WebCore/platform/image-decoders/cg/ImageDecoderCG.cpp | |
parent | eff9be92c41913c92fb1d3b7983c071f3e718678 (diff) | |
download | external_webkit-28040489d744e0c5d475a88663056c9040ed5320.zip external_webkit-28040489d744e0c5d475a88663056c9040ed5320.tar.gz external_webkit-28040489d744e0c5d475a88663056c9040ed5320.tar.bz2 |
Merge WebKit at r71558: Initial merge by git.
Change-Id: Ib345578fa29df7e4bc72b4f00e4a6fddcb754c4c
Diffstat (limited to 'WebCore/platform/image-decoders/cg/ImageDecoderCG.cpp')
-rw-r--r-- | WebCore/platform/image-decoders/cg/ImageDecoderCG.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/WebCore/platform/image-decoders/cg/ImageDecoderCG.cpp b/WebCore/platform/image-decoders/cg/ImageDecoderCG.cpp index 2fac7da..0f4dbc8 100644 --- a/WebCore/platform/image-decoders/cg/ImageDecoderCG.cpp +++ b/WebCore/platform/image-decoders/cg/ImageDecoderCG.cpp @@ -31,11 +31,16 @@ namespace WebCore { +static RGBA32Buffer::PixelData* getPtrAsPixelData(CFMutableDataRef data) +{ + return data ? reinterpret_cast<RGBA32Buffer::PixelData*>(CFDataGetMutableBytePtr(data)) : 0; +} + void RGBA32Buffer::copyReferenceToBitmapData(const RGBA32Buffer& other) { ASSERT(this != &other); m_backingStore = other.m_backingStore; - m_bytes = reinterpret_cast<PixelData*>(CFDataGetMutableBytePtr(m_backingStore.get())); + m_bytes = getPtrAsPixelData(m_backingStore.get()); // FIXME: The rest of this function seems redundant with RGBA32Buffer::copyBitmapData. m_size = other.m_size; setHasAlpha(other.m_hasAlpha); @@ -47,7 +52,7 @@ bool RGBA32Buffer::copyBitmapData(const RGBA32Buffer& other) return true; m_backingStore.adoptCF(CFDataCreateMutableCopy(kCFAllocatorDefault, 0, other.m_backingStore.get())); - m_bytes = reinterpret_cast<PixelData*>(CFDataGetMutableBytePtr(m_backingStore.get())); + m_bytes = getPtrAsPixelData(m_backingStore.get()); m_size = other.m_size; setHasAlpha(other.m_hasAlpha); return true; @@ -64,15 +69,30 @@ bool RGBA32Buffer::setSize(int newWidth, int newHeight) return true; } +static CGColorSpaceRef createColorSpace(const ColorProfile& colorProfile) +{ + if (colorProfile.isEmpty()) + return CGColorSpaceCreateDeviceRGB(); + + RetainPtr<CFDataRef> data(AdoptCF, CFDataCreate(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(colorProfile.data()), colorProfile.size())); +#if !defined(TARGETING_TIGER) && !defined(TARGETING_LEOPARD) + return CGColorSpaceCreateWithICCProfile(data.get()); +#else + RetainPtr<CGColorSpaceRef> deviceColorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB()); + 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(), deviceColorSpace.get()); +#endif +} + NativeImagePtr RGBA32Buffer::asNewNativeImage() const { - // FIXME: Figure out the right color space. - DEFINE_STATIC_LOCAL(RetainPtr<CGColorSpaceRef>, deviceColorSpace, (AdoptCF, CGColorSpaceCreateDeviceRGB())); + RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, createColorSpace(m_colorProfile)); RetainPtr<CGDataProviderRef> dataProvider(AdoptCF, CGDataProviderCreateWithCFData(m_backingStore.get())); CGImageAlphaInfo alphaInfo = m_premultiplyAlpha ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaFirst; - return CGImageCreate(width(), height(), 8, 32, width() * sizeof(PixelData), deviceColorSpace.get(), + return CGImageCreate(width(), height(), 8, 32, width() * sizeof(PixelData), colorSpace.get(), alphaInfo | kCGBitmapByteOrder32Host, dataProvider.get(), 0, false, kCGRenderingIntentDefault); } |