Changeset 96609 in webkit


Ignore:
Timestamp:
Oct 4, 2011 10:49:46 AM (13 years ago)
Author:
caryclark@google.com
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.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r96607 r96609  
     12011-10-04  Cary Clark  <caryclark@google.com>
     2
     3        Apply color profile found to decoded bitmap (Skia on Mac)
     4        https://bugs.webkit.org/show_bug.cgi?id=69144
     5        This fixes http://code.google.com/p/chromium/issues/detail?id=97830
     6
     7        Reviewed by Stephen White.
     8
     9        No new tests. This platform is not enabled.
     10
     11        * platform/image-decoders/ImageDecoder.h:
     12        Add color profile slot to Skia variation.
     13
     14        * platform/image-decoders/skia/ImageDecoderSkia.cpp:
     15        (WebCore::resolveColorSpace):
     16        Adjust the bitmap in place to use the supplied color space.
     17
     18        (WebCore::createColorSpace):
     19        Create a CGColorSpace from a color profile.
     20
     21        (WebCore::ImageFrame::setColorProfile):
     22        Save the image's color profile until the image is complete.
     23
     24        (WebCore::ImageFrame::setStatus):
     25        Apply the color profile, if any, to the image.
     26
    1272011-10-04  Leandro Pereira  <leandro@profusion.mobi>
    228
  • trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h

    r93792 r96609  
    189189#if USE(SKIA)
    190190        NativeImageSkia m_bitmap;
     191#if PLATFORM(CHROMIUM) && OS(DARWIN)
     192        ColorProfile m_colorProfile;
     193#endif
    191194#elif PLATFORM(QT)
    192195        mutable QPixmap m_pixmap;
  • trunk/Source/WebCore/platform/image-decoders/skia/ImageDecoderSkia.cpp

    r95901 r96609  
    2929
    3030#include "NotImplemented.h"
     31
     32#if PLATFORM(CHROMIUM) && OS(DARWIN)
     33#include "GraphicsContextCG.h"
     34#include "SkCGUtils.h"
     35#endif
    3136
    3237namespace WebCore {
     
    111116}
    112117
     118#if PLATFORM(CHROMIUM) && OS(DARWIN)
     119static void resolveColorSpace(const SkBitmap& bitmap, CGColorSpaceRef colorSpace)
     120{
     121    int width = bitmap.width();
     122    int height = bitmap.height();
     123    CGImageRef srcImage = SkCreateCGImageRefWithColorspace(bitmap, colorSpace);
     124    SkAutoLockPixels lock(bitmap);
     125    void* pixels = bitmap.getPixels();
     126    RetainPtr<CGContextRef> cgBitmap(AdoptCF, CGBitmapContextCreate(pixels, width, height, 8, width * 4, deviceRGBColorSpaceRef(), kCGBitmapByteOrder32Host | kCGImageAlphaPremultipliedFirst));
     127    if (!cgBitmap)
     128        return;
     129    CGContextSetBlendMode(cgBitmap.get(), kCGBlendModeCopy);
     130    CGRect bounds = { {0, 0}, {width, height} };
     131    CGContextDrawImage(cgBitmap.get(), bounds, srcImage);
     132}
     133
     134static CGColorSpaceRef createColorSpace(const ColorProfile& colorProfile)
     135{
     136    RetainPtr<CFDataRef> data(AdoptCF, CFDataCreate(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(colorProfile.data()), colorProfile.size()));
     137#ifndef TARGETING_LEOPARD
     138    return CGColorSpaceCreateWithICCProfile(data.get());
     139#else
     140    RetainPtr<CGDataProviderRef> profileDataProvider(AdoptCF, CGDataProviderCreateWithCFData(data.get()));
     141    CGFloat ranges[] = {0.0, 255.0, 0.0, 255.0, 0.0, 255.0};
     142    return CGColorSpaceCreateICCBased(3, ranges, profileDataProvider.get(), deviceRGBColorSpaceRef());
     143#endif
     144}
     145#endif
     146
    113147void ImageFrame::setColorProfile(const ColorProfile& colorProfile)
    114148{
     149#if PLATFORM(CHROMIUM) && OS(DARWIN)
     150    m_colorProfile = colorProfile;
     151#else
    115152    notImplemented();
     153#endif
    116154}
    117155
     
    119157{
    120158    m_status = status;
    121     if (m_status == FrameComplete)
     159    if (m_status == FrameComplete) {
    122160        m_bitmap.setDataComplete();  // Tell the bitmap it's done.
     161#if PLATFORM(CHROMIUM) && OS(DARWIN)
     162        if (m_colorProfile.isEmpty())
     163            return;
     164        RetainPtr<CGColorSpaceRef> cgColorSpace(AdoptCF, createColorSpace(m_colorProfile));
     165        resolveColorSpace(m_bitmap.bitmap(), cgColorSpace.get());
     166#endif
     167    }
    123168}
    124169
Note: See TracChangeset for help on using the changeset viewer.