Changeset 71065 in webkit


Ignore:
Timestamp:
Nov 1, 2010 3:33:44 PM (13 years ago)
Author:
abarth@webkit.org
Message:

2010-10-31 Adam Barth <abarth@webkit.org>

Reviewed by Eric Seidel.

[Chromium] Add ICC support for PNG on Mac
https://bugs.webkit.org/show_bug.cgi?id=48170

This just pipes the ICC profile from libpng to CoreGraphics. This
patch would have been a lot prettier on Snow Leopard, but we have to
use a somewhat ugly API to get this to work on Leopard.

This is covered by about infinite tests.

  • platform/image-decoders/ImageDecoder.cpp: (WebCore::RGBA32Buffer::setColorProfile):
  • platform/image-decoders/ImageDecoder.h:
  • platform/image-decoders/cg/ImageDecoderCG.cpp: (WebCore::RGBA32Buffer::asNewNativeImage):
  • platform/image-decoders/png/PNGImageDecoder.cpp: (WebCore::PNGImageDecoder::headerAvailable): (WebCore::PNGImageDecoder::rowAvailable):
  • platform/image-decoders/qt/RGBA32BufferQt.cpp: (WebCore::RGBA32Buffer::setColorProfile):
  • platform/image-decoders/skia/ImageDecoderSkia.cpp: (WebCore::RGBA32Buffer::setColorProfile):
Location:
trunk/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r71055 r71065  
     12010-10-31  Adam Barth  <abarth@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        [Chromium] Add ICC support for PNG on Mac
     6        https://bugs.webkit.org/show_bug.cgi?id=48170
     7
     8        This just pipes the ICC profile from libpng to CoreGraphics.  This
     9        patch would have been a lot prettier on Snow Leopard, but we have to
     10        use a somewhat ugly API to get this to work on Leopard.
     11
     12        This is covered by about infinite tests.
     13
     14        * platform/image-decoders/ImageDecoder.cpp:
     15        (WebCore::RGBA32Buffer::setColorProfile):
     16        * platform/image-decoders/ImageDecoder.h:
     17        * platform/image-decoders/cg/ImageDecoderCG.cpp:
     18        (WebCore::RGBA32Buffer::asNewNativeImage):
     19        * platform/image-decoders/png/PNGImageDecoder.cpp:
     20        (WebCore::PNGImageDecoder::headerAvailable):
     21        (WebCore::PNGImageDecoder::rowAvailable):
     22        * platform/image-decoders/qt/RGBA32BufferQt.cpp:
     23        (WebCore::RGBA32Buffer::setColorProfile):
     24        * platform/image-decoders/skia/ImageDecoderSkia.cpp:
     25        (WebCore::RGBA32Buffer::setColorProfile):
     26
    1272010-11-01  David Hyatt  <hyatt@apple.com>
    228
  • trunk/WebCore/platform/image-decoders/ImageDecoder.cpp

    r70846 r71065  
    188188{
    189189    m_hasAlpha = alpha;
     190}
     191
     192void RGBA32Buffer::setColorProfile(const ColorProfile& colorProfile)
     193{
     194    m_colorProfile = colorProfile;
    190195}
    191196
  • trunk/WebCore/platform/image-decoders/ImageDecoder.h

    r70846 r71065  
    4747namespace WebCore {
    4848
     49    // FIXME: Do we want better encapsulation?
     50    typedef Vector<char> ColorProfile;
     51
    4952    // The RGBA32Buffer object represents the decoded image data in RGBA32
    5053    // format.  This buffer is what all decoders write a single frame into.
     
    126129
    127130        void setHasAlpha(bool alpha);
     131        void setColorProfile(const ColorProfile&);
    128132        void setRect(const IntRect& r) { m_rect = r; }
    129133        void setStatus(FrameStatus status);
     
    193197        bool m_hasAlpha; // Whether or not any of the pixels in the buffer
    194198                         // have transparency.
     199        ColorProfile m_colorProfile;
    195200#endif
    196201        IntRect m_rect; // The rect of the original specified frame within
     
    345350        RefPtr<SharedBuffer> m_data; // The encoded data.
    346351        Vector<RGBA32Buffer> m_frameBufferCache;
     352        ColorProfile m_colorProfile;
    347353        bool m_scaled;
    348354        Vector<int> m_scaledColumns;
  • trunk/WebCore/platform/image-decoders/cg/ImageDecoderCG.cpp

    r70846 r71065  
    6565}
    6666
     67static CGColorSpaceRef createColorSpace(const ColorProfile& colorProfile)
     68{
     69    if (colorProfile.isEmpty())
     70        return CGColorSpaceCreateDeviceRGB();
     71
     72    RetainPtr<CFDataRef> data(AdoptCF, CFDataCreate(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(colorProfile.data()), colorProfile.size()));
     73#if !defined(TARGETING_TIGER) && !defined(TARGETING_LEOPARD)
     74    return CGColorSpaceCreateWithICCProfile(data.get());
     75#else
     76    RetainPtr<CGColorSpaceRef> deviceColorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB());
     77    RetainPtr<CGDataProviderRef> profileDataProvider(AdoptCF, CGDataProviderCreateWithCFData(data.get()));
     78    CGFloat ranges[] = {0.0, 255.0, 0.0, 255.0, 0.0, 255.0};
     79    return CGColorSpaceCreateICCBased(3, ranges, profileDataProvider.get(), deviceColorSpace.get());
     80#endif
     81}
     82
    6783NativeImagePtr RGBA32Buffer::asNewNativeImage() const
    6884{
    69     // FIXME: Figure out the right color space.
    70     DEFINE_STATIC_LOCAL(RetainPtr<CGColorSpaceRef>, deviceColorSpace, (AdoptCF, CGColorSpaceCreateDeviceRGB()));
     85    RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, createColorSpace(m_colorProfile));
    7186    RetainPtr<CGDataProviderRef> dataProvider(AdoptCF, CGDataProviderCreateWithCFData(m_backingStore.get()));
    7287
    7388    CGImageAlphaInfo alphaInfo = m_premultiplyAlpha ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaFirst;
    7489
    75     return CGImageCreate(width(), height(), 8, 32, width() * sizeof(PixelData), deviceColorSpace.get(),
     90    return CGImageCreate(width(), height(), 8, 32, width() * sizeof(PixelData), colorSpace.get(),
    7691        alphaInfo | kCGBitmapByteOrder32Host, dataProvider.get(), 0, false, kCGRenderingIntentDefault);
    7792}
  • trunk/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp

    r66039 r71065  
    221221}
    222222
     223static ColorProfile readColorProfile(png_structp png, png_infop info)
     224{
     225#ifdef PNG_iCCP_SUPPORTED
     226    char* profileName;
     227    int compressionType;
     228    char* profile;
     229    png_uint_32 profileLength;
     230    png_get_iCCP(png, info, &profileName, &compressionType, &profile, &profileLength);
     231    if (profile) {
     232        ColorProfile colorProfile;
     233        colorProfile.append(profile, profileLength);
     234        return colorProfile;
     235    }
     236#endif
     237    return ColorProfile();
     238}
     239
    223240void PNGImageDecoder::headerAvailable()
    224241{
     
    250267    png_get_IHDR(png, info, &width, &height, &bitDepth, &colorType, &interlaceType, &compressionType, &filterType);
    251268
     269    m_colorProfile = readColorProfile(png, info);
     270
    252271    // The options we set here match what Mozilla does.
    253272
     
    312331        buffer.setStatus(RGBA32Buffer::FramePartial);
    313332        buffer.setHasAlpha(false);
     333        buffer.setColorProfile(m_colorProfile);
    314334
    315335        // For PNGs, the frame always fills the entire image.
  • trunk/WebCore/platform/image-decoders/qt/RGBA32BufferQt.cpp

    r68446 r71065  
    2828#include "config.h"
    2929#include "ImageDecoder.h"
     30
     31#include "NotImplemented.h"
    3032
    3133#include <QPixmap>
     
    125127}
    126128
     129void RGBA32Buffer::setColorProfile(const ColorProfile& colorProfile)
     130{
     131    notImplemented();
     132}
     133
    127134void RGBA32Buffer::setStatus(FrameStatus status)
    128135{
  • trunk/WebCore/platform/image-decoders/skia/ImageDecoderSkia.cpp

    r68446 r71065  
    2727#include "config.h"
    2828#include "ImageDecoder.h"
     29
     30#include "NotImplemented.h"
    2931
    3032namespace WebCore {
     
    110112}
    111113
     114void RGBA32Buffer::setColorProfile(const ColorProfile& colorProfile)
     115{
     116    notImplemented();
     117}
     118
    112119void RGBA32Buffer::setStatus(FrameStatus status)
    113120{
Note: See TracChangeset for help on using the changeset viewer.