diff options
author | Matt Sarett <msarett@google.com> | 2017-03-06 11:11:23 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-06 17:26:09 +0000 |
commit | d83545e4904ba78c6bc7b82169e9be5070f64e32 (patch) | |
tree | 885c81d369c652cf06ef9d293e0f21a597d3bd36 | |
parent | 92004807f2dffea2d4a694e49434ce4c0bcfb28d (diff) |
Add SkColorSpace::isSRGB()
BUG=skia:
Change-Id: I124480a15e0c3cb01f4e22397c0a116f2d1c0d7d
Reviewed-on: https://skia-review.googlesource.com/9239
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Matt Sarett <msarett@google.com>
-rw-r--r-- | include/core/SkColorSpace.h | 16 | ||||
-rw-r--r-- | src/core/SkColorSpace.cpp | 4 | ||||
-rw-r--r-- | tests/ColorSpaceTest.cpp | 20 |
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()); +} |