aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2016-11-07 09:42:37 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-07 15:16:50 +0000
commit12313f072b3563d652a789e28140f70b48e57e03 (patch)
tree84986d857081b919315f69d56d9d2436a1b1b3f5
parent43513543de102500121afb9222dfdd8f35c50ca7 (diff)
Add/promote gamma helpers to SkColorSpace_Base
When decoding images with strange transfer functions, we need to pick an "equivalent" drawable format and color space. These help when doing that. Our default answer is to use F16 linear, but some GPUs may not be able to draw that, in which case we'll fall back to sRGB 8888. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4453 Change-Id: I7f7342423d2a57fb45c965e1a023d255cdafedee Reviewed-on: https://skia-review.googlesource.com/4453 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org> Reviewed-by: Matt Sarett <msarett@google.com>
-rw-r--r--src/core/SkColorSpace_A2B.h11
-rw-r--r--src/core/SkColorSpace_Base.h14
-rw-r--r--src/core/SkColorSpace_XYZ.cpp7
-rw-r--r--src/core/SkColorSpace_XYZ.h3
4 files changed, 34 insertions, 1 deletions
diff --git a/src/core/SkColorSpace_A2B.h b/src/core/SkColorSpace_A2B.h
index 844800588b..726e3d7fdd 100644
--- a/src/core/SkColorSpace_A2B.h
+++ b/src/core/SkColorSpace_A2B.h
@@ -56,6 +56,17 @@ public:
return false;
}
+ sk_sp<SkColorSpace> makeLinearGamma() override {
+ // TODO: Analyze the extrema of our projection into XYZ and use suitable primaries?
+ // For now, just fall back to a default, because we don't have a good answer.
+ return SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named);
+ }
+
+ sk_sp<SkColorSpace> makeSRGBGamma() override {
+ // See comment in makeLinearGamma
+ return SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named);
+ }
+
Type type() const override { return Type::kA2B; }
class Element {
diff --git a/src/core/SkColorSpace_Base.h b/src/core/SkColorSpace_Base.h
index a3cf6e0b13..3dbf351c72 100644
--- a/src/core/SkColorSpace_Base.h
+++ b/src/core/SkColorSpace_Base.h
@@ -193,6 +193,20 @@ public:
virtual bool onGammaIsLinear() const = 0;
+ /**
+ * Returns a color space with the same gamut as this one, but with a linear gamma.
+ * For color spaces whose gamut can not be described in terms of XYZ D50, returns
+ * linear sRGB.
+ */
+ virtual sk_sp<SkColorSpace> makeLinearGamma() = 0;
+
+ /**
+ * Returns a color space with the same gamut as this one, with with the sRGB transfer
+ * function. For color spaces whose gamut can not be described in terms of XYZ D50, returns
+ * sRGB.
+ */
+ virtual sk_sp<SkColorSpace> makeSRGBGamma() = 0;
+
enum class Type : uint8_t {
kXYZ,
kA2B
diff --git a/src/core/SkColorSpace_XYZ.cpp b/src/core/SkColorSpace_XYZ.cpp
index 35d3d29364..f99702d19b 100644
--- a/src/core/SkColorSpace_XYZ.cpp
+++ b/src/core/SkColorSpace_XYZ.cpp
@@ -63,6 +63,13 @@ sk_sp<SkColorSpace> SkColorSpace_XYZ::makeLinearGamma() {
return SkColorSpace_Base::MakeRGB(kLinear_SkGammaNamed, fToXYZD50);
}
+sk_sp<SkColorSpace> SkColorSpace_XYZ::makeSRGBGamma() {
+ if (this->gammaCloseToSRGB()) {
+ return sk_ref_sp(this);
+ }
+ return SkColorSpace_Base::MakeRGB(kSRGB_SkGammaNamed, fToXYZD50);
+}
+
void SkColorSpace_XYZ::toDstGammaTables(const uint8_t* tables[3], sk_sp<SkData>* storage,
int numTables) const {
fToDstGammaOnce([this, numTables] {
diff --git a/src/core/SkColorSpace_XYZ.h b/src/core/SkColorSpace_XYZ.h
index 07f44cab4c..a179c1a501 100644
--- a/src/core/SkColorSpace_XYZ.h
+++ b/src/core/SkColorSpace_XYZ.h
@@ -25,7 +25,8 @@ public:
Type type() const override { return Type::kXYZ; }
- sk_sp<SkColorSpace> makeLinearGamma();
+ sk_sp<SkColorSpace> makeLinearGamma() override;
+ sk_sp<SkColorSpace> makeSRGBGamma() override;
SkGammaNamed gammaNamed() const { return fGammaNamed; }