aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/core/SkColorSpace.h16
-rw-r--r--src/core/SkColorSpace.cpp4
-rw-r--r--tests/ColorSpaceTest.cpp20
3 files changed, 40 insertions, 0 deletions
diff --git a/include/core/SkColorSpace.h b/include/core/SkColorSpace.h
index 978660b135..c945703549 100644
--- a/include/core/SkColorSpace.h
+++ b/include/core/SkColorSpace.h
@@ -106,6 +106,8 @@ public:
/**
* Returns true if the color space gamma is near enough to be approximated as sRGB.
+ * This includes the canonical sRGB transfer function as well as a 2.2f exponential
+ * transfer function.
*/
bool gammaCloseToSRGB() const;
@@ -129,6 +131,20 @@ public:
bool toXYZD50(SkMatrix44* toXYZD50) const;
/**
+ * Returns true if the color space is sRGB.
+ * Returns false otherwise.
+ *
+ * This allows a little bit of tolerance, given that we might see small numerical error
+ * in some cases: converting ICC fixed point to float, converting white point to D50,
+ * rounding decisions on transfer function and matrix.
+ *
+ * This does not consider a 2.2f exponential transfer function to be sRGB. While these
+ * functions are similar (and it is sometimes useful to consider them together), this
+ * function checks for logical equality.
+ */
+ bool isSRGB() const;
+
+ /**
* Returns nullptr on failure. Fails when we fallback to serializing ICC data and
* the data is too large to serialize.
*/
diff --git a/src/core/SkColorSpace.cpp b/src/core/SkColorSpace.cpp
index e059bebc99..3677fb6342 100644
--- a/src/core/SkColorSpace.cpp
+++ b/src/core/SkColorSpace.cpp
@@ -299,6 +299,10 @@ bool SkColorSpace::toXYZD50(SkMatrix44* toXYZD50) const {
return false;
}
+bool SkColorSpace::isSRGB() const {
+ return gSRGB == this || gSRGBNonLinearBlending == this;
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
sk_sp<SkColorSpace> SkColorSpace_Base::makeWithoutFlags() {
diff --git a/tests/ColorSpaceTest.cpp b/tests/ColorSpaceTest.cpp
index 73a49807f3..059fa591fa 100644
--- a/tests/ColorSpaceTest.cpp
+++ b/tests/ColorSpaceTest.cpp
@@ -478,3 +478,23 @@ DEF_TEST(ColorSpace_MatrixHash, r) {
REPORTER_ASSERT(r, *as_CSB(srgb)->toXYZD50() == *as_CSB(strange)->toXYZD50());
REPORTER_ASSERT(r, as_CSB(srgb)->toXYZD50Hash() == as_CSB(strange)->toXYZD50Hash());
}
+
+DEF_TEST(ColorSpace_IsSRGB, r) {
+ sk_sp<SkColorSpace> srgb0 = SkColorSpace::MakeSRGB();
+ sk_sp<SkColorSpace> srgb1 = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
+ SkColorSpace::kSRGB_Gamut, SkColorSpace::kNonLinearBlending_ColorSpaceFlag);
+
+ SkColorSpaceTransferFn fn;
+ fn.fA = 1.0f;
+ fn.fB = 0.0f;
+ fn.fC = 0.0f;
+ fn.fD = 0.0f;
+ fn.fE = 0.0f;
+ fn.fF = 0.0f;
+ fn.fG = 2.2f;
+ sk_sp<SkColorSpace> twoDotTwo = SkColorSpace::MakeRGB(fn, SkColorSpace::kSRGB_Gamut);
+
+ REPORTER_ASSERT(r, srgb0->isSRGB());
+ REPORTER_ASSERT(r, srgb1->isSRGB());
+ REPORTER_ASSERT(r, !twoDotTwo->isSRGB());
+}