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>
This commit is contained in:
Brian Osman 2016-11-07 09:42:37 -05:00 committed by Skia Commit-Bot
parent 43513543de
commit 12313f072b
4 changed files with 34 additions and 1 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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] {

View File

@ -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; }