summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp')
-rw-r--r--Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp41
1 files changed, 35 insertions, 6 deletions
diff --git a/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp b/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp
index c19bd72..187d296 100644
--- a/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp
+++ b/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp
@@ -26,7 +26,7 @@
#include "config.h"
-#if ENABLE(3D_CANVAS)
+#if ENABLE(WEBGL)
#include "GraphicsContext3D.h"
#include "GraphicsContextCG.h"
@@ -105,7 +105,7 @@ bool GraphicsContext3D::getImageData(Image* image,
decoder.setData(image->data(), true);
if (!decoder.frameCount())
return false;
- decodedImage = decoder.createFrameAtIndex(0);
+ decodedImage.adoptCF(decoder.createFrameAtIndex(0));
cgImage = decodedImage.get();
} else
cgImage = image->nativeImageForCurrentFrame();
@@ -116,6 +116,34 @@ bool GraphicsContext3D::getImageData(Image* image,
size_t height = CGImageGetHeight(cgImage);
if (!width || !height)
return false;
+
+ // See whether the image is using an indexed color space, and if
+ // so, re-render it into an RGB color space. The image re-packing
+ // code requires color data, not color table indices, for the
+ // image data.
+ CGColorSpaceRef colorSpace = CGImageGetColorSpace(cgImage);
+ CGColorSpaceModel model = CGColorSpaceGetModel(colorSpace);
+ if (model == kCGColorSpaceModelIndexed) {
+ RetainPtr<CGContextRef> bitmapContext;
+ // FIXME: we should probably manually convert the image by indexing into
+ // the color table, which would allow us to avoid premultiplying the
+ // alpha channel. Creation of a bitmap context with an alpha channel
+ // doesn't seem to work unless it's premultiplied.
+ bitmapContext.adoptCF(CGBitmapContextCreate(0, width, height, 8, width * 4,
+ deviceRGBColorSpaceRef(),
+ kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host));
+ if (!bitmapContext)
+ return false;
+
+ CGContextSetBlendMode(bitmapContext.get(), kCGBlendModeCopy);
+ CGContextSetInterpolationQuality(bitmapContext.get(), kCGInterpolationNone);
+ CGContextDrawImage(bitmapContext.get(), CGRectMake(0, 0, width, height), cgImage);
+
+ // Now discard the original CG image and replace it with a copy from the bitmap context.
+ decodedImage.adoptCF(CGBitmapContextCreateImage(bitmapContext.get()));
+ cgImage = decodedImage.get();
+ }
+
size_t bitsPerComponent = CGImageGetBitsPerComponent(cgImage);
size_t bitsPerPixel = CGImageGetBitsPerPixel(cgImage);
if (bitsPerComponent != 8 && bitsPerComponent != 16)
@@ -168,10 +196,11 @@ bool GraphicsContext3D::getImageData(Image* image,
AlphaFormat alphaFormat = AlphaFormatNone;
switch (CGImageGetAlphaInfo(cgImage)) {
case kCGImageAlphaPremultipliedFirst:
- // This path is only accessible for MacOS earlier than 10.6.4.
// This is a special case for texImage2D with HTMLCanvasElement input,
- // in which case image->data() should be null.
- ASSERT(!image->data());
+ // in which case image->data() should be null, or indexed color models,
+ // where we need premultiplied alpha to create the bitmap context
+ // successfully.
+ ASSERT(!image->data() || model == kCGColorSpaceModelIndexed);
if (!premultiplyAlpha)
neededAlphaOp = AlphaDoUnmultiply;
alphaFormat = AlphaFormatFirst;
@@ -254,4 +283,4 @@ void GraphicsContext3D::paintToCanvas(const unsigned char* imagePixels, int imag
} // namespace WebCore
-#endif // ENABLE(3D_CANVAS)
+#endif // ENABLE(WEBGL)