Index: third_party/WebKit/Source/platform/graphics/Color.cpp |
diff --git a/third_party/WebKit/Source/platform/graphics/Color.cpp b/third_party/WebKit/Source/platform/graphics/Color.cpp |
index dc9364edbde2bea1f7c0a43392244b658f961551..2d4a6cb474efed653ad3c038051d28be3aaa9d7b 100644 |
--- a/third_party/WebKit/Source/platform/graphics/Color.cpp |
+++ b/third_party/WebKit/Source/platform/graphics/Color.cpp |
@@ -26,6 +26,11 @@ |
#include "platform/graphics/Color.h" |
#include "platform/Decimal.h" |
+#include "platform/graphics/ColorSpaceFilter.h" |
+#include "platform/graphics/ColorSpaceProfile.h" |
+#include "platform/graphics/GraphicsScreen.h" |
+#include "platform/graphics/skia/SkiaUtils.h" |
+#include "third_party/skia/include/core/SkColorFilter.h" |
#include "wtf/Assertions.h" |
#include "wtf/HexNumber.h" |
#include "wtf/MathExtras.h" |
@@ -454,4 +459,28 @@ RGBA32 premultipliedARGBFromColor(const Color& color) |
return pixelColor; |
} |
+Color Color::toDeviceColor(const Color& color) |
+{ |
+ if (!imageColorProfilesEnabled()) |
+ return color; |
+ |
+ RELEASE_ASSERT(currentScreenId()); |
+ |
+ // FIXME: the default color transform sRGB->screen is hot: Find a way to cache it. Add API to retrieve it. |
+ |
+ RefPtr<SkColorFilter> colorTransform = createColorSpaceFilter(screenColorProfile(ScreenDevice::sRGB).get(), screenColorProfile(currentScreenId()).get()); |
+ if (!colorTransform) |
+ return Color::asDeviceColor(color); |
+ |
+ RELEASE_ASSERT(!color.isDeviceColor()); |
+ |
+ SkColor skColor = colorTransform->filterColor(SkColorSetARGB(color.alpha(), color.red(), color.green(), color.blue())); |
+ int r = SkColorGetR(skColor); |
+ int g = SkColorGetG(skColor); |
+ int b = SkColorGetB(skColor); |
+ int a = SkColorGetA(skColor); |
+ |
+ return Color::asDeviceColor(Color(r, g, b, a)); |
+} |
+ |
} // namespace blink |