diff options
-rw-r--r-- | src/core/SkColorSpaceXform_skcms.cpp | 4 | ||||
-rw-r--r-- | tests/ColorSpaceTest.cpp | 2 | ||||
-rw-r--r-- | third_party/skcms/skcms.h | 4 | ||||
-rw-r--r-- | third_party/skcms/src/ICCProfile.c | 124 |
4 files changed, 71 insertions, 63 deletions
diff --git a/src/core/SkColorSpaceXform_skcms.cpp b/src/core/SkColorSpaceXform_skcms.cpp index 4fd7cbf3da..6bffd4adb8 100644 --- a/src/core/SkColorSpaceXform_skcms.cpp +++ b/src/core/SkColorSpaceXform_skcms.cpp @@ -18,7 +18,7 @@ public: : fSrcProfile(srcProfile) , fDstProfile(dstProfile) , fPremulFormat(premulFormat) { - skcms_EnsureUsableAsDestination(&fDstProfile, &skcms_sRGB_profile); + skcms_EnsureUsableAsDestination(&fDstProfile, skcms_sRGB_profile()); #ifndef SK_DONT_OPTIMIZE_SRC_PROFILES_FOR_SPEED skcms_OptimizeForSpeed(&fSrcProfile); @@ -133,7 +133,7 @@ sk_sp<SkColorSpace> SkColorSpace::Make(const skcms_ICCProfile* profile) { return nullptr; } - if (skcms_ApproximatelyEqualProfiles(profile, &skcms_sRGB_profile)) { + if (skcms_ApproximatelyEqualProfiles(profile, skcms_sRGB_profile())) { return SkColorSpace::MakeSRGB(); } diff --git a/tests/ColorSpaceTest.cpp b/tests/ColorSpaceTest.cpp index 05e6893875..e95c528ea5 100644 --- a/tests/ColorSpaceTest.cpp +++ b/tests/ColorSpaceTest.cpp @@ -438,7 +438,7 @@ DEF_TEST(ColorSpace_IsSRGB, r) { #if defined(SK_USE_SKCMS) DEF_TEST(ColorSpace_skcms_IsSRGB, r) { - sk_sp<SkColorSpace> srgb = SkColorSpace::Make(&skcms_sRGB_profile); + sk_sp<SkColorSpace> srgb = SkColorSpace::Make(skcms_sRGB_profile()); REPORTER_ASSERT(r, srgb->isSRGB()); } #endif diff --git a/third_party/skcms/skcms.h b/third_party/skcms/skcms.h index 94dfe03892..2053fe6828 100644 --- a/third_party/skcms/skcms.h +++ b/third_party/skcms/skcms.h @@ -113,9 +113,9 @@ typedef struct skcms_ICCProfile { } skcms_ICCProfile; // The sRGB color profile is so commonly used that we offer a canonical skcms_ICCProfile for it. -SKCMS_API extern const skcms_ICCProfile skcms_sRGB_profile; +SKCMS_API const skcms_ICCProfile* skcms_sRGB_profile(void); // Ditto for XYZD50, the most common profile connection space. -SKCMS_API extern const skcms_ICCProfile skcms_XYZD50_profile; +SKCMS_API const skcms_ICCProfile* skcms_XYZD50_profile(void); // Practical equality test for two skcms_ICCProfiles. // The implementation is subject to change, but it will always try to answer diff --git a/third_party/skcms/src/ICCProfile.c b/third_party/skcms/src/ICCProfile.c index 90ce6fcaf2..322e0975f1 100644 --- a/third_party/skcms/src/ICCProfile.c +++ b/third_party/skcms/src/ICCProfile.c @@ -781,63 +781,71 @@ bool skcms_Parse(const void* buf, size_t len, skcms_ICCProfile* profile) { return usable_as_src(profile); } -const skcms_ICCProfile skcms_sRGB_profile = { - // These fields are moot when not a skcms_Parse()'d profile. - .buffer = NULL, - .size = 0, - .tag_count = 0, - - // We choose to represent sRGB with its canonical transfer function, - // and with its canonical XYZD50 gamut matrix. - .data_color_space = make_signature('R', 'G', 'B', ' '), - .pcs = make_signature('X', 'Y', 'Z', ' '), - .has_trc = true, - .has_toXYZD50 = true, - .has_A2B = false, - - .trc = { - {{0, {2.4f, (float)(1/1.055), (float)(0.055/1.055), (float)(1/12.92), 0.04045f, 0, 0 }}}, - {{0, {2.4f, (float)(1/1.055), (float)(0.055/1.055), (float)(1/12.92), 0.04045f, 0, 0 }}}, - {{0, {2.4f, (float)(1/1.055), (float)(0.055/1.055), (float)(1/12.92), 0.04045f, 0, 0 }}}, - }, - - .toXYZD50 = {{ - { 0.436065674f, 0.385147095f, 0.143066406f }, - { 0.222488403f, 0.716873169f, 0.060607910f }, - { 0.013916016f, 0.097076416f, 0.714096069f }, - }}, - - .has_poly_tf = { true, true, true }, - .poly_tf = { - {0.293833881617f, 0.704207003117f, (float)(1/12.92), 0.04045f}, - {0.293833881617f, 0.704207003117f, (float)(1/12.92), 0.04045f}, - {0.293833881617f, 0.704207003117f, (float)(1/12.92), 0.04045f}, - }, -}; -const skcms_ICCProfile skcms_XYZD50_profile = { - .buffer = NULL, - .size = 0, - .tag_count = 0, - - .data_color_space = make_signature('R', 'G', 'B', ' '), - .pcs = make_signature('X', 'Y', 'Z', ' '), - .has_trc = true, - .has_toXYZD50 = true, - .has_A2B = false, - - .trc = { - {{0, {1,1,0,0,0,0,0}}}, - {{0, {1,1,0,0,0,0,0}}}, - {{0, {1,1,0,0,0,0,0}}}, - }, - - .toXYZD50 = {{ - {1,0,0}, - {0,1,0}, - {0,0,1}, - }}, -}; +const skcms_ICCProfile* skcms_sRGB_profile() { + static const skcms_ICCProfile sRGB_profile = { + // These fields are moot when not a skcms_Parse()'d profile. + .buffer = NULL, + .size = 0, + .tag_count = 0, + + // We choose to represent sRGB with its canonical transfer function, + // and with its canonical XYZD50 gamut matrix. + .data_color_space = make_signature('R', 'G', 'B', ' '), + .pcs = make_signature('X', 'Y', 'Z', ' '), + .has_trc = true, + .has_toXYZD50 = true, + .has_A2B = false, + + .trc = { + {{0, {2.4f, (float)(1/1.055), (float)(0.055/1.055), (float)(1/12.92), 0.04045f, 0, 0 }}}, + {{0, {2.4f, (float)(1/1.055), (float)(0.055/1.055), (float)(1/12.92), 0.04045f, 0, 0 }}}, + {{0, {2.4f, (float)(1/1.055), (float)(0.055/1.055), (float)(1/12.92), 0.04045f, 0, 0 }}}, + }, + + .toXYZD50 = {{ + { 0.436065674f, 0.385147095f, 0.143066406f }, + { 0.222488403f, 0.716873169f, 0.060607910f }, + { 0.013916016f, 0.097076416f, 0.714096069f }, + }}, + + .has_poly_tf = { true, true, true }, + .poly_tf = { + {0.293833881617f, 0.704207003117f, (float)(1/12.92), 0.04045f}, + {0.293833881617f, 0.704207003117f, (float)(1/12.92), 0.04045f}, + {0.293833881617f, 0.704207003117f, (float)(1/12.92), 0.04045f}, + }, + }; + return &sRGB_profile; +} + +const skcms_ICCProfile* skcms_XYZD50_profile() { + static const skcms_ICCProfile XYZD50_profile = { + .buffer = NULL, + .size = 0, + .tag_count = 0, + + .data_color_space = make_signature('R', 'G', 'B', ' '), + .pcs = make_signature('X', 'Y', 'Z', ' '), + .has_trc = true, + .has_toXYZD50 = true, + .has_A2B = false, + + .trc = { + {{0, {1,1,0,0,0,0,0}}}, + {{0, {1,1,0,0,0,0,0}}}, + {{0, {1,1,0,0,0,0,0}}}, + }, + + .toXYZD50 = {{ + {1,0,0}, + {0,1,0}, + {0,0,1}, + }}, + }; + + return &XYZD50_profile; +} const uint8_t skcms_252_random_bytes[] = { 8, 179, 128, 204, 253, 38, 134, 184, 68, 102, 32, 138, 99, 39, 169, 215, @@ -885,13 +893,13 @@ bool skcms_ApproximatelyEqualProfiles(const skcms_ICCProfile* A, const skcms_ICC dstB[252]; if (!skcms_Transform( skcms_252_random_bytes, fmt, skcms_AlphaFormat_Unpremul, A, - dstA, skcms_PixelFormat_RGB_888, skcms_AlphaFormat_Unpremul, &skcms_XYZD50_profile, + dstA, skcms_PixelFormat_RGB_888, skcms_AlphaFormat_Unpremul, skcms_XYZD50_profile(), npixels)) { return false; } if (!skcms_Transform( skcms_252_random_bytes, fmt, skcms_AlphaFormat_Unpremul, B, - dstB, skcms_PixelFormat_RGB_888, skcms_AlphaFormat_Unpremul, &skcms_XYZD50_profile, + dstB, skcms_PixelFormat_RGB_888, skcms_AlphaFormat_Unpremul, skcms_XYZD50_profile(), npixels)) { return false; } |