Index: third_party/WebKit/Source/platform/graphics/BitmapImage.cpp |
diff --git a/third_party/WebKit/Source/platform/graphics/BitmapImage.cpp b/third_party/WebKit/Source/platform/graphics/BitmapImage.cpp |
index 80d9482b1ad892bd8a88d69a286dbfa96fa314f8..d2993c22a2ecc243bdd96ea378d0b4e6d9fec773 100644 |
--- a/third_party/WebKit/Source/platform/graphics/BitmapImage.cpp |
+++ b/third_party/WebKit/Source/platform/graphics/BitmapImage.cpp |
@@ -31,12 +31,18 @@ |
#include "platform/Timer.h" |
#include "platform/TraceEvent.h" |
#include "platform/geometry/FloatRect.h" |
+#include "platform/graphics/ColorSpaceFilter.h" |
+#include "platform/graphics/ColorSpaceProfile.h" |
#include "platform/graphics/DeferredImageDecoder.h" |
+#include "platform/graphics/GraphicsScreen.h" |
+#include "platform/graphics/ImageBuffer.h" |
#include "platform/graphics/ImageObserver.h" |
#include "platform/graphics/StaticBitmapImage.h" |
#include "platform/graphics/skia/SkiaUtils.h" |
#include "third_party/skia/include/core/SkCanvas.h" |
+#include "third_party/skia/include/core/SkColorFilter.h" |
#include "wtf/PassRefPtr.h" |
+#include "wtf/RefPtr.h" |
#include "wtf/text/WTFString.h" |
namespace blink { |
@@ -69,6 +75,7 @@ BitmapImage::BitmapImage(ImageObserver* observer) |
, m_sizeAvailable(false) |
, m_hasUniformFrameSize(true) |
, m_haveFrameCount(false) |
+ , m_drawingToCanvasElement(false) |
{ |
} |
@@ -86,6 +93,7 @@ BitmapImage::BitmapImage(const SkBitmap& bitmap, ImageObserver* observer) |
, m_haveSize(true) |
, m_sizeAvailable(true) |
, m_haveFrameCount(true) |
+ , m_drawingToCanvasElement(false) |
{ |
// Since we don't have a decoder, we can't figure out the image orientation. |
// Set m_sizeRespectingOrientation to be the same as m_size so it's not 0x0. |
@@ -301,9 +309,41 @@ void BitmapImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& |
} |
} |
+ if (RefPtr<ColorSpaceProfile> source = colorProfile()) { |
+ // Tagged images (those that have a color profile) are drawn color-correct on supported platforms. |
+ RefPtr<ColorSpaceProfile> screen = screenColorProfile(currentScreenId()); |
+ if (RefPtr<SkColorFilter> colorTransform = createColorSpaceFilter(source.get(), screen.get())) { |
+ fprintf(stderr, "BitmapImage::draw color transform [%s]\n", colorSpaceFilterKey(colorTransform.get()).latin1().data()); |
+ if (currentScreenId()) { |
+ if (drawingToCanvasElement()) // FIXME: debug for the <canvas> case. |
+ exit(0); |
+ const_cast<SkPaint*>(&paint)->setColorFilter(colorTransform.get()); |
+ } else { |
+ if (!drawingToCanvasElement()) // FIXME: Only <canvas> draws outside normal paint flows. |
+ exit(0); |
+ // FIXME: normal bitmap drawing paths apply the transform filter, but the canvas drawing |
+ // path does not. Paint with the color transform, into a local Imagebuffer, then extract |
+ // the result as a SkImage, which will be used to do the final drawImageRect() pass. |
+ SkPaint transformPaint; |
+ transformPaint.setColorFilter(colorTransform.get()); |
+ OwnPtr<ImageBuffer> buffer = ImageBuffer::create(size(), currentFrameKnownToBeOpaque() ? Opaque : NonOpaque); |
+ FloatRect source = IntRect(IntPoint(), size()); |
+ SkCanvas::SrcRectConstraint skSrcRectClamp = WebCoreClampingModeToSkiaRectConstraint(Image::ClampImageToSourceRect); |
+ buffer->canvas()->drawImageRect(image.get(), source, source, &transformPaint, skSrcRectClamp); |
+ image = buffer->newSkImageSnapshot(PreferNoAcceleration); |
+ } |
+ fflush(stderr); |
+ } |
+ } else { |
+ // For sRGB assumed images: easy, just interpolate the sRGB color profile here as the src profile? |
+ // FIXME: untagged images should be drawn from sRGB color space, per CSS2.1 onwards, a change that |
+ // would also require that all CSS content, including <canvas>, be drawn from sRGB space to match, |
+ // and the same for plugins (Flash, NaCl) which don't define their color space at all, <video> and |
+ // OOPIF, and so on ... |
+ } |
+ |
SkRect skSrcRect = adjustedSrcRect; |
- canvas->drawImageRect(image.get(), skSrcRect, adjustedDstRect, &paint, |
- WebCoreClampingModeToSkiaRectConstraint(clampMode)); |
+ canvas->drawImageRect(image.get(), skSrcRect, adjustedDstRect, &paint, WebCoreClampingModeToSkiaRectConstraint(clampMode)); |
canvas->restoreToCount(initialSaveCount); |
if (currentFrameIsLazyDecoded()) |