Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Unified Diff: third_party/WebKit/Source/platform/graphics/ColorSpace.cpp

Issue 2652313004: Implement color-gamut media query (Closed)
Patch Set: fix windows build Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/ColorSpace.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/graphics/ColorSpace.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/ColorSpace.cpp b/third_party/WebKit/Source/platform/graphics/ColorSpace.cpp
index 423da80de12b5d9a46cc4f582641087b1078f5a0..4b2694c50386a996bb1960ebb4acc7fef6af1fdb 100644
--- a/third_party/WebKit/Source/platform/graphics/ColorSpace.cpp
+++ b/third_party/WebKit/Source/platform/graphics/ColorSpace.cpp
@@ -33,6 +33,8 @@
#include "platform/graphics/ColorSpace.h"
#include "platform/graphics/skia/SkiaUtils.h"
+#include "public/platform/WebScreenInfo.h"
+#include "third_party/skia/include/core/SkColorSpaceXform.h"
#include "third_party/skia/include/effects/SkTableColorFilter.h"
#include "wtf/MathExtras.h"
#include <algorithm>
@@ -116,6 +118,59 @@ sk_sp<SkColorFilter> createColorSpaceFilter(ColorSpace srcColorSpace,
return SkTableColorFilter::MakeARGB(0, lookupTable, lookupTable, lookupTable);
}
+ColorSpaceGamut getColorSpaceGamut(const WebScreenInfo& screenInfo) {
+ const gfx::ICCProfile& profile = screenInfo.iccProfile;
+ if (profile == gfx::ICCProfile())
+ return ColorSpaceGamut::Unknown;
+
+ return ColorSpaceUtilities::getColorSpaceGamut(
+ profile.GetColorSpace().ToSkColorSpace().get());
+}
+
+ColorSpaceGamut getColorSpaceGamut(SkColorSpace* colorSpace) {
Noel Gordon 2017/01/31 02:29:57 The color profile media spec does not say how to c
+ sk_sp<SkColorSpace> scRGB(
+ SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named));
+ std::unique_ptr<SkColorSpaceXform> transform(
+ SkColorSpaceXform::New(colorSpace, scRGB.get()));
+
+ if (!transform)
+ return ColorSpaceGamut::Unknown;
+
+ unsigned char in[3][4];
+ float out[3][4];
+ memset(in, 0, sizeof(in));
+ in[0][0] = 255;
+ in[1][1] = 255;
+ in[2][2] = 255;
+ in[0][3] = 255;
+ in[1][3] = 255;
+ in[2][3] = 255;
+ transform->apply(SkColorSpaceXform::kRGBA_F32_ColorFormat, out,
+ SkColorSpaceXform::kRGBA_8888_ColorFormat, in, 3,
+ kOpaque_SkAlphaType);
+ float score = out[0][0] * out[1][1] * out[2][2];
Noel Gordon 2017/01/31 02:29:57 Aside: by the looks, this appears to compute a sco
hubbe 2017/01/31 04:06:20 While I agree that this is a hacky method, I do th
+
+ if (score < 0.9)
+ return ColorSpaceGamut::LessThanNTSC;
+ if (score < 0.95)
+ return ColorSpaceGamut::NTSC; // actual score 0.912839
+ if (score < 1.1)
+ return ColorSpaceGamut::SRGB; // actual score 1.0
+ if (score < 1.3)
+ return ColorSpaceGamut::AlmostP3;
+ if (score < 1.425)
+ return ColorSpaceGamut::P3; // actual score 1.401899
+ if (score < 1.5)
+ return ColorSpaceGamut::AdobeRGB; // actual score 1.458385
+ if (score < 2.0)
+ return ColorSpaceGamut::Wide;
+ if (score < 2.2)
+ return ColorSpaceGamut::BT2020; // actual score 2.104520
+ if (score < 2.7)
+ return ColorSpaceGamut::ProPhoto; // actual score 2.913247
+ return ColorSpaceGamut::UltraWide;
+}
+
} // namespace ColorSpaceUtilities
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/ColorSpace.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698