Reland "Add SkColorSpace factory from 3x3 row-major gamut and transfer function"
Moved named common transfer functions and gamuts to constexpr values in
SkColorSpace.h, in SkNamedTransferFn and SkNamedGamut namespaces.
Converted nearly all SkColorSpace::MakeRGB calls within Skia to use the
new factory with the named values. Multiple clients want a way to
extract named transfer function and gamut - this still doesn't provide
that, but this may be a better path forward for honestly advertising how
SkColorSpace works internally.
Originally landed as:
https://skia.googlesource.com/skia/+/a9549ab31630fc244094e6f1692371cbaf87f666
Re-landing with a new serialization format, but maintaining ability to
load old serialized color spaces, for SKP compatibility.
Bug: skia:
Change-Id: Ib84a6e1cd5d7d9816175773fdbaff2ca32658667
Reviewed-on: https://skia-review.googlesource.com/c/181176
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/tests/AndroidCodecTest.cpp b/tests/AndroidCodecTest.cpp
index 3381d4f..49415f8 100644
--- a/tests/AndroidCodecTest.cpp
+++ b/tests/AndroidCodecTest.cpp
@@ -15,7 +15,6 @@
#include "SkEncodedImageFormat.h"
#include "SkImageGenerator.h"
#include "SkImageInfo.h"
-#include "SkMatrix44.h"
#include "SkPixmapPriv.h"
#include "SkRefCnt.h"
#include "SkSize.h"
@@ -157,8 +156,7 @@
return;
}
- auto expected = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- SkColorSpace::kDCIP3_D65_Gamut);
+ auto expected = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
REPORTER_ASSERT(r, SkColorSpace::Equals(cs.get(), expected.get()));
}
@@ -190,17 +188,15 @@
REPORTER_ASSERT(r, !cs->isSRGB());
REPORTER_ASSERT(r, cs->gammaCloseToSRGB());
- SkMatrix44 matrix;
+ skcms_Matrix3x3 matrix;
cs->toXYZD50(&matrix);
- SkMatrix44 expected;
- static constexpr float kExpected[] = {
- 0.426254272f, 0.369018555f, 0.168914795f,
- 0.226013184f, 0.685974121f, 0.0880126953f,
- 0.0116729736f, 0.0950927734f, 0.71812439f,
- };
- expected.set3x3RowMajorf(kExpected);
- REPORTER_ASSERT(r, matrix == expected);
+ static constexpr skcms_Matrix3x3 kExpected = {{
+ { 0.426254272f, 0.369018555f, 0.168914795f },
+ { 0.226013184f, 0.685974121f, 0.0880126953f },
+ { 0.0116729736f, 0.0950927734f, 0.71812439f },
+ }};
+ REPORTER_ASSERT(r, 0 == memcmp(&matrix, &kExpected, sizeof(skcms_Matrix3x3)));
}
DEF_TEST(AndroidCodec_orientation, r) {
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp
index bf30dd9..8aeb0c4 100644
--- a/tests/CanvasTest.cpp
+++ b/tests/CanvasTest.cpp
@@ -813,8 +813,8 @@
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
DEF_TEST(Canvas_LegacyColorBehavior, r) {
- sk_sp<SkColorSpace> cs = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- SkColorSpace::kAdobeRGB_Gamut);
+ sk_sp<SkColorSpace> cs = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB,
+ SkNamedGamut::kAdobeRGB);
// Make a Adobe RGB bitmap.
SkBitmap bitmap;
diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
index bd988f6..8c918a8 100644
--- a/tests/CodecTest.cpp
+++ b/tests/CodecTest.cpp
@@ -26,7 +26,6 @@
#include "SkMD5.h"
#include "SkMakeUnique.h"
#include "SkMalloc.h"
-#include "SkMatrix44.h"
#include "SkPixmap.h"
#include "SkPngChunkReader.h"
#include "SkPngEncoder.h"
@@ -1025,7 +1024,7 @@
const int dstWidth = subsetWidth / opts.fSampleSize;
const int dstHeight = subsetHeight / opts.fSampleSize;
- auto colorSpace = SkColorSpace::MakeRGB(g2Dot2_TransferFn, SkColorSpace::kAdobeRGB_Gamut);
+ auto colorSpace = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, SkNamedGamut::kAdobeRGB);
SkImageInfo dstInfo = codec->getInfo().makeWH(dstWidth, dstHeight)
.makeColorType(kN32_SkColorType)
.makeColorSpace(colorSpace);
@@ -1591,22 +1590,21 @@
// Test with P3 color space.
SkDynamicMemoryWStream p3Buf;
- sk_sp<SkColorSpace> p3 = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- SkColorSpace::kDCIP3_D65_Gamut);
+ sk_sp<SkColorSpace> p3 = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
pixmap.setColorSpace(p3);
encode_format(&p3Buf, pixmap, format);
sk_sp<SkData> p3Data = p3Buf.detachAsData();
std::unique_ptr<SkCodec> p3Codec(SkCodec::MakeFromData(p3Data));
REPORTER_ASSERT(r, p3Codec->getInfo().colorSpace()->gammaCloseToSRGB());
- SkMatrix44 mat0, mat1;
+ skcms_Matrix3x3 mat0, mat1;
bool success = p3->toXYZD50(&mat0);
REPORTER_ASSERT(r, success);
success = p3Codec->getInfo().colorSpace()->toXYZD50(&mat1);
REPORTER_ASSERT(r, success);
- for (int i = 0; i < 4; i++) {
- for (int j = 0; j < 4; j++) {
- REPORTER_ASSERT(r, color_space_almost_equal(mat0.get(i, j), mat1.get(i, j)));
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 3; j++) {
+ REPORTER_ASSERT(r, color_space_almost_equal(mat0.vals[i][j], mat1.vals[i][j]));
}
}
}
diff --git a/tests/ColorSpaceTest.cpp b/tests/ColorSpaceTest.cpp
index 42986e9..1deb8ee 100644
--- a/tests/ColorSpaceTest.cpp
+++ b/tests/ColorSpaceTest.cpp
@@ -11,7 +11,6 @@
#include "SkColorSpacePriv.h"
#include "SkData.h"
#include "SkImageInfo.h"
-#include "SkMatrix44.h"
#include "SkRefCnt.h"
#include "SkStream.h"
#include "SkTypes.h"
@@ -34,20 +33,13 @@
REPORTER_ASSERT(r, nullptr != space);
REPORTER_ASSERT(r, expectedGamma == space->gammaNamed());
- SkMatrix44 mat;
+ skcms_Matrix3x3 mat;
space->toXYZD50(&mat);
- const float src[] = {
- 1, 0, 0, 1,
- 0, 1, 0, 1,
- 0, 0, 1, 1,
- };
const float* ref[3] = { red, green, blue };
- float dst[4];
for (int i = 0; i < 3; ++i) {
- mat.mapScalars(&src[i*4], dst);
- REPORTER_ASSERT(r, almost_equal(ref[i][0], dst[0]));
- REPORTER_ASSERT(r, almost_equal(ref[i][1], dst[1]));
- REPORTER_ASSERT(r, almost_equal(ref[i][2], dst[2]));
+ REPORTER_ASSERT(r, almost_equal(ref[i][0], mat.vals[0][i]));
+ REPORTER_ASSERT(r, almost_equal(ref[i][1], mat.vals[1][i]));
+ REPORTER_ASSERT(r, almost_equal(ref[i][2], mat.vals[2][i]));
}
}
@@ -70,12 +62,6 @@
test_space(r, colorSpace.get(), red, green, blue, expectedGamma);
}
-static constexpr float g_sRGB_XYZ[]{
- 0.4358f, 0.3853f, 0.1430f, // Rx, Gx, Bx
- 0.2224f, 0.7170f, 0.0606f, // Ry, Gy, Gz
- 0.0139f, 0.0971f, 0.7139f, // Rz, Gz, Bz
-};
-
static constexpr float g_sRGB_R[]{ 0.4358f, 0.2224f, 0.0139f };
static constexpr float g_sRGB_G[]{ 0.3853f, 0.7170f, 0.0971f };
static constexpr float g_sRGB_B[]{ 0.1430f, 0.0606f, 0.7139f };
@@ -93,9 +79,9 @@
kSRGB_SkGammaNamed);
#endif
- const float red[] = { 0.385117f, 0.716904f, 0.0970612f };
+ const float red[] = { 0.385117f, 0.716904f, 0.0970612f };
const float green[] = { 0.143051f, 0.0606079f, 0.713913f };
- const float blue[] = { 0.436035f, 0.222488f, 0.013916f };
+ const float blue[] = { 0.436035f, 0.222488f, 0.013916f };
test_path(r, "images/icc-v2-gbr.jpg", red, green, blue, k2Dot2Curve_SkGammaNamed);
test_path(r, "images/webp-color-profile-crash.webp",
@@ -108,80 +94,6 @@
red, green, blue, kNonStandard_SkGammaNamed);
}
-DEF_TEST(ColorSpaceSRGBCompare, r) {
- // Create an sRGB color space by name
- sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::MakeSRGB();
-
- // Create an sRGB color space by value
- SkMatrix44 srgbToxyzD50;
- srgbToxyzD50.set3x3RowMajorf(g_sRGB_XYZ);
- sk_sp<SkColorSpace> rgbColorSpace =
- SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, srgbToxyzD50);
- REPORTER_ASSERT(r, rgbColorSpace == namedColorSpace);
-
- SkColorSpaceTransferFn srgbFn;
- srgbFn.fA = (1.0f / 1.055f);
- srgbFn.fB = (0.055f / 1.055f);
- srgbFn.fC = (1.0f / 12.92f);
- srgbFn.fD = 0.04045f;
- srgbFn.fE = 0.0f;
- srgbFn.fF = 0.0f;
- srgbFn.fG = 2.4f;
- sk_sp<SkColorSpace> rgbColorSpace2 = SkColorSpace::MakeRGB(srgbFn, srgbToxyzD50);
- REPORTER_ASSERT(r, rgbColorSpace2 == namedColorSpace);
-
- // Change a single value from the sRGB matrix
- srgbToxyzD50.set(2, 2, 0.5f);
- sk_sp<SkColorSpace> strangeColorSpace =
- SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, srgbToxyzD50);
- REPORTER_ASSERT(r, strangeColorSpace != namedColorSpace);
-}
-
-DEF_TEST(ColorSpaceSRGBLinearCompare, r) {
- // Create the linear sRGB color space by name
- sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::MakeSRGBLinear();
-
- // Create the linear sRGB color space via the sRGB color space's makeLinearGamma()
- auto srgb = SkColorSpace::MakeSRGB();
- sk_sp<SkColorSpace> viaSrgbColorSpace = srgb->makeLinearGamma();
- REPORTER_ASSERT(r, namedColorSpace == viaSrgbColorSpace);
-
- // Create a linear sRGB color space by value
- SkMatrix44 srgbToxyzD50;
- srgbToxyzD50.set3x3RowMajorf(g_sRGB_XYZ);
- sk_sp<SkColorSpace> rgbColorSpace =
- SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, srgbToxyzD50);
- REPORTER_ASSERT(r, rgbColorSpace == namedColorSpace);
-
- SkColorSpaceTransferFn linearExpFn;
- linearExpFn.fA = 1.0f;
- linearExpFn.fB = 0.0f;
- linearExpFn.fC = 0.0f;
- linearExpFn.fD = 0.0f;
- linearExpFn.fE = 0.0f;
- linearExpFn.fF = 0.0f;
- linearExpFn.fG = 1.0f;
- sk_sp<SkColorSpace> rgbColorSpace2 = SkColorSpace::MakeRGB(linearExpFn, srgbToxyzD50);
- REPORTER_ASSERT(r, rgbColorSpace2 == namedColorSpace);
-
- SkColorSpaceTransferFn linearFn;
- linearFn.fA = 0.0f;
- linearFn.fB = 0.0f;
- linearFn.fC = 1.0f;
- linearFn.fD = 1.0f;
- linearFn.fE = 0.0f;
- linearFn.fF = 0.0f;
- linearFn.fG = 0.0f;
- sk_sp<SkColorSpace> rgbColorSpace3 = SkColorSpace::MakeRGB(linearFn, srgbToxyzD50);
- REPORTER_ASSERT(r, rgbColorSpace3 == namedColorSpace);
-
- // Change a single value from the sRGB matrix
- srgbToxyzD50.set(2, 2, 0.5f);
- sk_sp<SkColorSpace> strangeColorSpace =
- SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, srgbToxyzD50);
- REPORTER_ASSERT(r, strangeColorSpace != namedColorSpace);
-}
-
static void test_serialize(skiatest::Reporter* r, sk_sp<SkColorSpace> space, bool isNamed) {
sk_sp<SkData> data1 = space->serialize();
@@ -219,15 +131,19 @@
test("icc_profiles/HP_ZR30w.icc");
test("icc_profiles/HP_Z32x.icc");
- SkColorSpaceTransferFn fn;
- fn.fA = 1.0f;
- fn.fB = 0.0f;
- fn.fC = 1.0f;
- fn.fD = 0.5f;
- fn.fE = 0.0f;
- fn.fF = 0.0f;
- fn.fG = 1.0f;
- SkMatrix44 toXYZ(SkMatrix44::kIdentity_Constructor);
+ skcms_TransferFunction fn;
+ fn.a = 1.0f;
+ fn.b = 0.0f;
+ fn.c = 1.0f;
+ fn.d = 0.5f;
+ fn.e = 0.0f;
+ fn.f = 0.0f;
+ fn.g = 1.0f;
+ skcms_Matrix3x3 toXYZ = {{
+ { 1, 0, 0 },
+ { 0, 1, 0 },
+ { 0, 0, 1 },
+ }};
test_serialize(r, SkColorSpace::MakeRGB(fn, toXYZ), false);
}
@@ -248,15 +164,19 @@
sk_sp<SkColorSpace> z30 = parse("icc_profiles/HP_ZR30w.icc");
sk_sp<SkColorSpace> z32 = parse("icc_profiles/HP_Z32x.icc");
- SkColorSpaceTransferFn fn;
- fn.fA = 1.0f;
- fn.fB = 0.0f;
- fn.fC = 1.0f;
- fn.fD = 0.5f;
- fn.fE = 0.0f;
- fn.fF = 0.0f;
- fn.fG = 1.0f;
- SkMatrix44 toXYZ(SkMatrix44::kIdentity_Constructor);
+ skcms_TransferFunction fn;
+ fn.a = 1.0f;
+ fn.b = 0.0f;
+ fn.c = 1.0f;
+ fn.d = 0.5f;
+ fn.e = 0.0f;
+ fn.f = 0.0f;
+ fn.g = 1.0f;
+ skcms_Matrix3x3 toXYZ = {{
+ { 1, 0, 0 },
+ { 0, 1, 0 },
+ { 0, 0, 1 },
+ }};
sk_sp<SkColorSpace> rgb4 = SkColorSpace::MakeRGB(fn, toXYZ);
REPORTER_ASSERT(r, SkColorSpace::Equals(nullptr, nullptr));
@@ -273,28 +193,20 @@
REPORTER_ASSERT(r, !SkColorSpace::Equals(srgb.get(), rgb4.get()));
}
-static inline bool matrix_almost_equal(const SkMatrix44& a, const SkMatrix44& b) {
- return almost_equal(a.get(0, 0), b.get(0, 0)) &&
- almost_equal(a.get(0, 1), b.get(0, 1)) &&
- almost_equal(a.get(0, 2), b.get(0, 2)) &&
- almost_equal(a.get(0, 3), b.get(0, 3)) &&
- almost_equal(a.get(1, 0), b.get(1, 0)) &&
- almost_equal(a.get(1, 1), b.get(1, 1)) &&
- almost_equal(a.get(1, 2), b.get(1, 2)) &&
- almost_equal(a.get(1, 3), b.get(1, 3)) &&
- almost_equal(a.get(2, 0), b.get(2, 0)) &&
- almost_equal(a.get(2, 1), b.get(2, 1)) &&
- almost_equal(a.get(2, 2), b.get(2, 2)) &&
- almost_equal(a.get(2, 3), b.get(2, 3)) &&
- almost_equal(a.get(3, 0), b.get(3, 0)) &&
- almost_equal(a.get(3, 1), b.get(3, 1)) &&
- almost_equal(a.get(3, 2), b.get(3, 2)) &&
- almost_equal(a.get(3, 3), b.get(3, 3));
+static inline bool matrix_almost_equal(const skcms_Matrix3x3& a, const skcms_Matrix3x3& b) {
+ for (int r = 0; r < 3; ++r) {
+ for (int c = 0; c < 3; ++c) {
+ if (!almost_equal(a.vals[r][c], b.vals[r][c])) {
+ return false;
+ }
+ }
+ }
+ return true;
}
static inline void check_primaries(skiatest::Reporter* r, const SkColorSpacePrimaries& primaries,
- const SkMatrix44& reference) {
- SkMatrix44 toXYZ;
+ const skcms_Matrix3x3& reference) {
+ skcms_Matrix3x3 toXYZ;
bool result = primaries.toXYZD50(&toXYZ);
REPORTER_ASSERT(r, result);
REPORTER_ASSERT(r, matrix_almost_equal(toXYZ, reference));
@@ -302,21 +214,16 @@
DEF_TEST(ColorSpace_Primaries, r) {
// sRGB primaries (D65)
- SkColorSpacePrimaries srgb;
- srgb.fRX = 0.64f;
- srgb.fRY = 0.33f;
- srgb.fGX = 0.30f;
- srgb.fGY = 0.60f;
- srgb.fBX = 0.15f;
- srgb.fBY = 0.06f;
- srgb.fWX = 0.3127f;
- srgb.fWY = 0.3290f;
- SkMatrix44 srgbToXYZ;
- bool result = srgb.toXYZD50(&srgbToXYZ);
+ skcms_Matrix3x3 srgbToXYZ;
+ bool result = skcms_PrimariesToXYZD50(
+ 0.64f, 0.33f,
+ 0.30f, 0.60f,
+ 0.15f, 0.06f,
+ 0.3127f, 0.3290f,
+ &srgbToXYZ);
REPORTER_ASSERT(r, result);
- sk_sp<SkColorSpace> space = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- srgbToXYZ);
+ sk_sp<SkColorSpace> space = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, srgbToXYZ);
REPORTER_ASSERT(r, SkColorSpace::MakeSRGB() == space);
// ProPhoto (D50)
@@ -329,10 +236,11 @@
proPhoto.fBY = 0.0001f;
proPhoto.fWX = 0.34567f;
proPhoto.fWY = 0.35850f;
- SkMatrix44 proToXYZ;
- proToXYZ.set3x3(0.7976749f, 0.2880402f, 0.0000000f,
- 0.1351917f, 0.7118741f, 0.0000000f,
- 0.0313534f, 0.0000857f, 0.8252100f);
+ skcms_Matrix3x3 proToXYZ = {{
+ { 0.7976749f, 0.1351917f, 0.0313534f },
+ { 0.2880402f, 0.7118741f, 0.0000857f },
+ { 0.0000000f, 0.0000000f, 0.8252100f },
+ }};
check_primaries(r, proPhoto, proToXYZ);
// NTSC (C)
@@ -345,10 +253,11 @@
ntsc.fBY = 0.08f;
ntsc.fWX = 0.31006f;
ntsc.fWY = 0.31616f;
- SkMatrix44 ntscToXYZ;
- ntscToXYZ.set3x3(0.6343706f, 0.3109496f, -0.0011817f,
- 0.1852204f, 0.5915984f, 0.0555518f,
- 0.1446290f, 0.0974520f, 0.7708399f);
+ skcms_Matrix3x3 ntscToXYZ = {{
+ { 0.6343706f, 0.1852204f, 0.1446290f },
+ { 0.3109496f, 0.5915984f, 0.0974520f },
+ { -0.0011817f, 0.0555518f, 0.7708399f }
+ }};
check_primaries(r, ntsc, ntscToXYZ);
// DCI P3 (D65)
@@ -361,9 +270,8 @@
p3.fBY = 0.060f;
p3.fWX = 0.3127f;
p3.fWY = 0.3290f;
- space = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- SkColorSpace::kDCIP3_D65_Gamut);
- SkMatrix44 reference;
+ space = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
+ skcms_Matrix3x3 reference;
SkAssertResult(space->toXYZD50(&reference));
check_primaries(r, p3, reference);
@@ -377,8 +285,7 @@
rec2020.fBY = 0.046f;
rec2020.fWX = 0.3127f;
rec2020.fWY = 0.3290f;
- space = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- SkColorSpace::kRec2020_Gamut);
+ space = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kRec2020);
SkAssertResult(space->toXYZD50(&reference));
check_primaries(r, rec2020, reference);
}
@@ -386,18 +293,16 @@
DEF_TEST(ColorSpace_MatrixHash, r) {
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
- SkColorSpaceTransferFn fn;
- fn.fA = 1.0f;
- fn.fB = 0.0f;
- fn.fC = 0.0f;
- fn.fD = 0.0f;
- fn.fE = 0.0f;
- fn.fF = 0.0f;
- fn.fG = 3.0f;
+ skcms_TransferFunction fn;
+ fn.a = 1.0f;
+ fn.b = 0.0f;
+ fn.c = 0.0f;
+ fn.d = 0.0f;
+ fn.e = 0.0f;
+ fn.f = 0.0f;
+ fn.g = 3.0f;
- SkMatrix44 srgbMat;
- srgbMat.set3x3RowMajorf(gSRGB_toXYZD50);
- sk_sp<SkColorSpace> strange = SkColorSpace::MakeRGB(fn, srgbMat);
+ sk_sp<SkColorSpace> strange = SkColorSpace::MakeRGB(fn, SkNamedGamut::kSRGB);
REPORTER_ASSERT(r, srgb->toXYZD50Hash() == strange->toXYZD50Hash());
}
@@ -405,15 +310,15 @@
DEF_TEST(ColorSpace_IsSRGB, r) {
sk_sp<SkColorSpace> srgb0 = SkColorSpace::MakeSRGB();
- SkColorSpaceTransferFn fn;
- fn.fA = 1.0f;
- fn.fB = 0.0f;
- fn.fC = 0.0f;
- fn.fD = 0.0f;
- fn.fE = 0.0f;
- fn.fF = 0.0f;
- fn.fG = 2.2f;
- sk_sp<SkColorSpace> twoDotTwo = SkColorSpace::MakeRGB(fn, SkColorSpace::kSRGB_Gamut);
+ skcms_TransferFunction fn;
+ fn.a = 1.0f;
+ fn.b = 0.0f;
+ fn.c = 0.0f;
+ fn.d = 0.0f;
+ fn.e = 0.0f;
+ fn.f = 0.0f;
+ fn.g = 2.2f;
+ sk_sp<SkColorSpace> twoDotTwo = SkColorSpace::MakeRGB(fn, SkNamedGamut::kSRGB);
REPORTER_ASSERT(r, srgb0->isSRGB());
REPORTER_ASSERT(r, !twoDotTwo->isSRGB());
diff --git a/tests/DeferredDisplayListTest.cpp b/tests/DeferredDisplayListTest.cpp
index 3f03ae1..8e49446 100644
--- a/tests/DeferredDisplayListTest.cpp
+++ b/tests/DeferredDisplayListTest.cpp
@@ -296,8 +296,7 @@
case 4:
// This just needs to be a colorSpace different from that returned by MakeSRGB().
// In this case we just change the gamut.
- fColorSpace = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- SkColorSpace::kAdobeRGB_Gamut);
+ fColorSpace = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kAdobeRGB);
break;
case kSampleCount:
fSampleCount = 4;
diff --git a/tests/ICCTest.cpp b/tests/ICCTest.cpp
index f82bfa4..efe39a4 100644
--- a/tests/ICCTest.cpp
+++ b/tests/ICCTest.cpp
@@ -15,56 +15,13 @@
#include "../third_party/skcms/skcms.h"
-DEF_TEST(WriteICCProfile, r) {
- auto adobeRGB = SkColorSpace::MakeRGB(g2Dot2_TransferFn, SkColorSpace::kAdobeRGB_Gamut);
-
- struct {
- SkColorSpaceTransferFn fn;
- const float* toXYZD50;
- const char* desc;
- sk_sp<SkColorSpace> want;
- } tests[] = {
- {g2Dot2_TransferFn, gAdobeRGB_toXYZD50, "AdobeRGB", adobeRGB},
- { gSRGB_TransferFn, gSRGB_toXYZD50, "sRGB", SkColorSpace::MakeSRGB()},
- };
-
- for (auto test : tests) {
- sk_sp<SkData> profile = SkWriteICCProfile(test.fn, test.toXYZD50);
- REPORTER_ASSERT(r, profile);
-
- skcms_ICCProfile parsed;
- REPORTER_ASSERT(r, skcms_Parse(profile->data(), profile->size(), &parsed));
-
- sk_sp<SkColorSpace> got = SkColorSpace::Make(parsed);
- REPORTER_ASSERT(r, got);
- REPORTER_ASSERT(r, SkColorSpace::Equals(got.get(), test.want.get()));
-
- skcms_ICCTag desc;
- REPORTER_ASSERT(r, skcms_GetTagBySignature(&parsed,
- SkSetFourByteTag('d','e','s','c'),
- &desc));
-
- // Rather than really carefully break down the 'desc' tag,
- // just check our expected description is somewhere in there (as big-endian UTF-16).
- uint8_t big_endian_utf16[16];
- for (size_t i = 0; i < strlen(test.desc); i++) {
- big_endian_utf16[2*i+0] = 0;
- big_endian_utf16[2*i+1] = test.desc[i];
- }
-
- SkString haystack((const char*)desc.buf, desc.size),
- needle ((const char*)big_endian_utf16, 2*strlen(test.desc));
- REPORTER_ASSERT(r, haystack.contains(needle.c_str()));
- }
-}
-
DEF_TEST(AdobeRGB, r) {
if (sk_sp<SkData> profile = GetResourceAsData("icc_profiles/AdobeRGB1998.icc")) {
skcms_ICCProfile parsed;
REPORTER_ASSERT(r, skcms_Parse(profile->data(), profile->size(), &parsed));
auto got = SkColorSpace::Make(parsed);
- auto want = SkColorSpace::MakeRGB(g2Dot2_TransferFn, SkColorSpace::kAdobeRGB_Gamut);
+ auto want = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, SkNamedGamut::kAdobeRGB);
REPORTER_ASSERT(r, SkColorSpace::Equals(got.get(), want.get()));
}
}
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 9b78821..1ad49dd 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -1168,13 +1168,13 @@
REPORTER_ASSERT(r, srgb.get() == image->colorSpace());
image = GetResourceAsImage("images/webp-color-profile-lossy.webp");
- SkColorSpaceTransferFn fn;
+ skcms_TransferFunction fn;
bool success = image->colorSpace()->isNumericalTransferFn(&fn);
REPORTER_ASSERT(r, success);
- REPORTER_ASSERT(r, color_space_almost_equal(1.8f, fn.fG));
+ REPORTER_ASSERT(r, color_space_almost_equal(1.8f, fn.g));
- sk_sp<SkColorSpace> rec2020 = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- SkColorSpace::kRec2020_Gamut);
+ sk_sp<SkColorSpace> rec2020 = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB,
+ SkNamedGamut::kRec2020);
image = create_picture_image(rec2020);
REPORTER_ASSERT(r, SkColorSpace::Equals(rec2020.get(), image->colorSpace()));
@@ -1195,11 +1195,10 @@
}
DEF_TEST(Image_makeColorSpace, r) {
- sk_sp<SkColorSpace> p3 = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- SkColorSpace::kDCIP3_D65_Gamut);
- SkColorSpaceTransferFn fn;
- fn.fA = 1.f; fn.fB = 0.f; fn.fC = 0.f; fn.fD = 0.f; fn.fE = 0.f; fn.fF = 0.f; fn.fG = 1.8f;
- sk_sp<SkColorSpace> adobeGamut = SkColorSpace::MakeRGB(fn, SkColorSpace::kAdobeRGB_Gamut);
+ sk_sp<SkColorSpace> p3 = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
+ skcms_TransferFunction fn;
+ fn.a = 1.f; fn.b = 0.f; fn.c = 0.f; fn.d = 0.f; fn.e = 0.f; fn.f = 0.f; fn.g = 1.8f;
+ sk_sp<SkColorSpace> adobeGamut = SkColorSpace::MakeRGB(fn, SkNamedGamut::kAdobeRGB);
SkBitmap srgbBitmap;
srgbBitmap.allocPixels(SkImageInfo::MakeS32(1, 1, kOpaque_SkAlphaType));
diff --git a/tests/NonlinearBlendingTest.cpp b/tests/NonlinearBlendingTest.cpp
index e91dda8..768d964 100644
--- a/tests/NonlinearBlendingTest.cpp
+++ b/tests/NonlinearBlendingTest.cpp
@@ -12,8 +12,7 @@
DEF_TEST(SkColorSpaceXformSteps_vs_skcms, r) {
auto srgb = SkColorSpace::MakeSRGB();
- auto dp3 = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- SkColorSpace::kDCIP3_D65_Gamut);
+ auto dp3 = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3);
skcms_ICCProfile srgb_profile;
srgb->toProfile(&srgb_profile);
diff --git a/tests/SkColorSpaceXformStepsTest.cpp b/tests/SkColorSpaceXformStepsTest.cpp
index f0ae414..6b15385 100644
--- a/tests/SkColorSpaceXformStepsTest.cpp
+++ b/tests/SkColorSpaceXformStepsTest.cpp
@@ -11,8 +11,8 @@
DEF_TEST(SkColorSpaceXformSteps, r) {
auto srgb = SkColorSpace::MakeSRGB(),
- adobe = SkColorSpace::MakeRGB(g2Dot2_TransferFn, SkColorSpace::kAdobeRGB_Gamut),
- srgb22 = SkColorSpace::MakeRGB(g2Dot2_TransferFn, SkColorSpace:: kSRGB_Gamut),
+ adobe = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, SkNamedGamut::kAdobeRGB),
+ srgb22 = SkColorSpace::MakeRGB(SkNamedTransferFn::k2Dot2, SkNamedGamut::kSRGB),
srgb1 = srgb ->makeLinearGamma(),
adobe1 = adobe->makeLinearGamma();
diff --git a/tests/TableColorFilterTest.cpp b/tests/TableColorFilterTest.cpp
index 857aa7e..bb5df60 100644
--- a/tests/TableColorFilterTest.cpp
+++ b/tests/TableColorFilterTest.cpp
@@ -17,8 +17,7 @@
DEF_TEST(TableColorFilter, r) {
// Using a wide source gamut will make saturated colors go well out of range of sRGB.
- auto rec2020 = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
- SkColorSpace::kRec2020_Gamut);
+ auto rec2020 = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kRec2020);
sk_sp<SkColorFilter> to_srgb = SkToSRGBColorFilter::Make(rec2020);
// Any table will work fine here. An identity table makes testing easy.
diff --git a/tests/ToSRGBColorFilter.cpp b/tests/ToSRGBColorFilter.cpp
index 01c5673..519ffb8 100644
--- a/tests/ToSRGBColorFilter.cpp
+++ b/tests/ToSRGBColorFilter.cpp
@@ -22,8 +22,7 @@
REPORTER_ASSERT(r, nullptr == SkToSRGBColorFilter::Make(nullptr));
// Here's a realistic conversion.
- auto dci_p3 = SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma,
- SkColorSpace::kDCIP3_D65_Gamut);
+ auto dci_p3 = SkColorSpace::MakeRGB(SkNamedTransferFn::kLinear, SkNamedGamut::kDCIP3);
REPORTER_ASSERT(r, nullptr != SkToSRGBColorFilter::Make(dci_p3));
}