canvas->save();
for (int i = 0; i < kNumColors; i++) {
- sk_sp<SkColorSpace> space =
- SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)->makeLinearGamma();
+ sk_sp<SkColorSpace> space = SkColorSpace::NewNamed(SkColorSpace::kSRGBLinear_Named);
sk_sp<SkShader> s = SkShader::MakeColorShader(colors[i], space);
SkPaint paint;
paint.setShader(s);
* Often used by images and monitors.
*/
kAdobeRGB_Named,
+
+ /**
+ * Colorspace with the sRGB primaries, but a linear (1.0) gamma. Commonly used for
+ * half-float surfaces, and high precision individual colors (gradient stops, etc...)
+ */
+ kSRGBLinear_Named,
};
enum RenderTargetGamma : uint8_t {
return SkColorSpace::NewNamed(kAdobeRGB_Named);
}
break;
+ case kLinear_SkGammaNamed:
+ if (xyz_almost_equal(toXYZD50, gSRGB_toXYZD50)) {
+ return SkColorSpace::NewNamed(kSRGBLinear_Named);
+ }
+ break;
case kNonStandard_SkGammaNamed:
// This is not allowed.
return nullptr;
static SkColorSpace* gAdobeRGB;
static SkColorSpace* gSRGB;
+static SkColorSpace* gSRGBLinear;
sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) {
static SkOnce sRGBOnce;
static SkOnce adobeRGBOnce;
+ static SkOnce sRGBLinearOnce;
switch (named) {
case kSRGB_Named: {
});
return sk_ref_sp<SkColorSpace>(gAdobeRGB);
}
+ case kSRGBLinear_Named: {
+ sRGBLinearOnce([] {
+ SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor);
+ srgbToxyzD50.set3x3RowMajorf(gSRGB_toXYZD50);
+
+ // Force the mutable type mask to be computed. This avoids races.
+ (void)srgbToxyzD50.getType();
+ gSRGBLinear = new SkColorSpace_Base(kLinear_SkGammaNamed, srgbToxyzD50);
+ });
+ return sk_ref_sp<SkColorSpace>(gSRGBLinear);
+ }
default:
break;
}
SkASSERT(k0_Version == version);
header.fVersion = (uint8_t) version;
- SkASSERT(named <= SkColorSpace::kAdobeRGB_Named);
+ SkASSERT(named <= SkColorSpace::kSRGBLinear_Named);
header.fNamed = (uint8_t) named;
SkASSERT(gammaNamed <= kNonStandard_SkGammaNamed);
ColorSpaceHeader::Pack(k0_Version, kAdobeRGB_Named,
as_CSB(this)->fGammaNamed, 0);
}
+ return sizeof(ColorSpaceHeader);
+ } else if (this == gSRGBLinear) {
+ if (memory) {
+ *((ColorSpaceHeader*)memory) =
+ ColorSpaceHeader::Pack(k0_Version, kSRGBLinear_Named,
+ as_CSB(this)->fGammaNamed, 0);
+ }
+ return sizeof(ColorSpaceHeader);
}
// If we have a named gamma, write the enum and the matrix.
}
// Color space refers to fColors4f, so it's always linear gamma
- fColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)->makeLinearGamma();
+ fColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGBLinear_Named);
} else {
SkASSERT(desc.fColors4f && desc.fColorSpace && desc.fColorSpace->gammaIsLinear());
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named));
break;
case GradientBitmapType::kHalfFloat:
- info = SkImageInfo::Make(kCache32Count, 1, kRGBA_F16_SkColorType,
- kPremul_SkAlphaType,
- SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)
- ->makeLinearGamma());
+ info = SkImageInfo::Make(
+ kCache32Count, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType,
+ SkColorSpace::NewNamed(SkColorSpace::kSRGBLinear_Named));
break;
default:
SkFAIL("Unexpected bitmap type");
REPORTER_ASSERT(r, strangeColorSpace != namedColorSpace);
}
+DEF_TEST(ColorSpaceSRGBLinearCompare, r) {
+ // Create the linear sRGB color space by name
+ sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGBLinear_Named);
+
+ // Create the linear sRGB color space via the sRGB color space's makeLinearGamma()
+ sk_sp<SkColorSpace> viaSrgbColorSpace =
+ SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)->makeLinearGamma();
+ REPORTER_ASSERT(r, namedColorSpace == viaSrgbColorSpace);
+
+ // Create a linear sRGB color space by value
+ SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor);
+ srgbToxyzD50.set3x3RowMajorf(g_sRGB_XYZ);
+ sk_sp<SkColorSpace> rgbColorSpace =
+ SkColorSpace::NewRGB(SkColorSpace::kLinear_RenderTargetGamma, srgbToxyzD50);
+ REPORTER_ASSERT(r, rgbColorSpace == namedColorSpace);
+
+ // Change a single value from the sRGB matrix
+ srgbToxyzD50.set(2, 2, 0.5f);
+ sk_sp<SkColorSpace> strangeColorSpace =
+ SkColorSpace::NewRGB(SkColorSpace::kLinear_RenderTargetGamma, srgbToxyzD50);
+ REPORTER_ASSERT(r, strangeColorSpace != namedColorSpace);
+}
+
class ColorSpaceTest {
public:
static sk_sp<SkData> WriteToICC(SkColorSpace* space) {
DEF_TEST(ColorSpace_Named, r) {
const struct {
SkColorSpace::Named fNamed;
- bool fIsSRGB;
+ SkGammaNamed fExpectedGamma;
} recs[] {
- { SkColorSpace::kSRGB_Named, true },
- { SkColorSpace::kAdobeRGB_Named, false },
+ { SkColorSpace::kSRGB_Named, kSRGB_SkGammaNamed },
+ { SkColorSpace::kAdobeRGB_Named, k2Dot2Curve_SkGammaNamed },
+ { SkColorSpace::kSRGBLinear_Named, kLinear_SkGammaNamed },
};
for (auto rec : recs) {
auto cs = SkColorSpace::NewNamed(rec.fNamed);
REPORTER_ASSERT(r, cs);
if (cs) {
- if (rec.fIsSRGB) {
- REPORTER_ASSERT(r, kSRGB_SkGammaNamed == as_CSB(cs)->gammaNamed());
- } else {
- REPORTER_ASSERT(r, k2Dot2Curve_SkGammaNamed == as_CSB(cs)->gammaNamed());
- }
+ REPORTER_ASSERT(r, rec.fExpectedGamma == as_CSB(cs)->gammaNamed());
}
}
DEF_TEST(ColorSpace_Serialize, r) {
test_serialize(r, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).get(), true);
test_serialize(r, SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named).get(), true);
+ test_serialize(r, SkColorSpace::NewNamed(SkColorSpace::kSRGBLinear_Named).get(), true);
sk_sp<SkData> monitorData = SkData::MakeFromFileName(
GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
SkMatrix44 srgbMatrix = srgbColorSpace->toXYZD50();
const float oddGamma[] = { 2.4f, 2.4f, 2.4f };
auto oddColorSpace = SkColorSpace_Base::NewRGB(oddGamma, srgbMatrix);
- auto linearColorSpace = srgbColorSpace->makeLinearGamma();
+ auto linearColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGBLinear_Named);
const struct {
SkColorType fColorType;