diff options
author | Steve Block <steveblock@google.com> | 2011-05-25 19:08:45 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2011-06-08 13:51:31 +0100 |
commit | 2bde8e466a4451c7319e3a072d118917957d6554 (patch) | |
tree | 28f4a1b869a513e565c7760d0e6a06e7cf1fe95a /Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp | |
parent | 6939c99b71d9372d14a0c74a772108052e8c48c8 (diff) | |
download | external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.zip external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.tar.gz external_webkit-2bde8e466a4451c7319e3a072d118917957d6554.tar.bz2 |
Merge WebKit at r82507: Initial merge by git
Change-Id: I60ce9d780725b58b45e54165733a8ffee23b683e
Diffstat (limited to 'Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp')
-rw-r--r-- | Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp | 60 |
1 files changed, 45 insertions, 15 deletions
diff --git a/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp b/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp index 7c8e313..3c8f959 100644 --- a/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp +++ b/Source/WebCore/platform/graphics/cg/ImageBufferCG.cpp @@ -32,6 +32,7 @@ #include "BitmapImage.h" #include "GraphicsContext.h" #include "GraphicsContextCG.h" +#include "ImageData.h" #include "MIMETypeRegistry.h" #include <ApplicationServices/ApplicationServices.h> #include <wtf/Assertions.h> @@ -498,21 +499,8 @@ static RetainPtr<CFStringRef> utiFromMIMEType(const String& mimeType) #endif } -String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const +static String CGImageToDataURL(CGImageRef image, const String& mimeType, const double* quality) { - ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); - - RetainPtr<CGImageRef> image; - if (!m_accelerateRendering) - image.adoptCF(CGBitmapContextCreateImage(context()->platformContext())); -#if USE(IOSURFACE_CANVAS_BACKING_STORE) - else - image.adoptCF(wkIOSurfaceContextCreateImage(context()->platformContext())); -#endif - - if (!image) - return "data:,"; - RetainPtr<CFMutableDataRef> data(AdoptCF, CFDataCreateMutable(kCFAllocatorDefault, 0)); if (!data) return "data:,"; @@ -533,7 +521,7 @@ String ImageBuffer::toDataURL(const String& mimeType, const double* quality) con imageProperties.adoptCF(CFDictionaryCreate(0, &key, &value, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); } - CGImageDestinationAddImage(destination.get(), image.get(), imageProperties.get()); + CGImageDestinationAddImage(destination.get(), image, imageProperties.get()); CGImageDestinationFinalize(destination.get()); Vector<char> out; @@ -541,4 +529,46 @@ String ImageBuffer::toDataURL(const String& mimeType, const double* quality) con return makeString("data:", mimeType, ";base64,", out); } + +String ImageBuffer::toDataURL(const String& mimeType, const double* quality) const +{ + ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); + + RetainPtr<CGImageRef> image; + if (!m_accelerateRendering) + image.adoptCF(CGBitmapContextCreateImage(context()->platformContext())); +#if USE(IOSURFACE_CANVAS_BACKING_STORE) + else + image.adoptCF(wkIOSurfaceContextCreateImage(context()->platformContext())); +#endif + + if (!image) + return "data:,"; + + return CGImageToDataURL(image.get(), mimeType, quality); +} + +String ImageDataToDataURL(const ImageData& source, const String& mimeType, const double* quality) +{ + ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); + + RetainPtr<CGImageRef> image; + RetainPtr<CGDataProviderRef> dataProvider; + + dataProvider.adoptCF(CGDataProviderCreateWithData(0, source.data()->data()->data(), + 4 * source.width() * source.height(), 0)); + + if (!dataProvider) + return "data:,"; + + image.adoptCF(CGImageCreate(source.width(), source.height(), 8, 32, 4 * source.width(), + CGColorSpaceCreateDeviceRGB(), kCGBitmapByteOrderDefault | kCGImageAlphaLast, + dataProvider.get(), 0, false, kCGRenderingIntentDefault)); + + + if (!image) + return "data:,"; + + return CGImageToDataURL(image.get(), mimeType, quality); +} } // namespace WebCore |