Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Unified Diff: src/core/SkColorSpace.cpp

Issue 2377763002: Added kSRGBLinear_Named color space, along with tests (Closed)
Patch Set: Update assert. Better comment. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkColorSpace.h ('k') | src/effects/gradients/SkGradientShader.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkColorSpace.cpp
diff --git a/src/core/SkColorSpace.cpp b/src/core/SkColorSpace.cpp
index 90fc96e111ea0eddc2f24a01565aaacb4b36f59c..225cfe146451d7e0f154abec8e9d1b0441326582 100644
--- a/src/core/SkColorSpace.cpp
+++ b/src/core/SkColorSpace.cpp
@@ -113,6 +113,11 @@ sk_sp<SkColorSpace> SkColorSpace_Base::NewRGB(SkGammaNamed gammaNamed, const SkM
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;
@@ -136,10 +141,12 @@ sk_sp<SkColorSpace> SkColorSpace::NewRGB(RenderTargetGamma gamma, const SkMatrix
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: {
@@ -164,6 +171,17 @@ sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named 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;
}
@@ -238,7 +256,7 @@ struct ColorSpaceHeader {
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);
@@ -273,6 +291,14 @@ size_t SkColorSpace::writeToMemory(void* memory) const {
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.
« no previous file with comments | « include/core/SkColorSpace.h ('k') | src/effects/gradients/SkGradientShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698