allow Gray and RGB profiles to be equal
We really just need to distinguish Gray/RGB from CMYK.
Bug: oss-fuzz:24430
Change-Id: I8d4c55eea9734bba53c3d238d32cc6e60f551704
Reviewed-on: https://skia-review.googlesource.com/c/skcms/+/306979
Reviewed-by: Leon Scroggins <scroggo@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
diff --git a/skcms.cc b/skcms.cc
index 0489a8a..3b78060 100644
--- a/skcms.cc
+++ b/skcms.cc
@@ -1314,7 +1314,10 @@
// skcms_252_random_bytes are 252 of a random shuffle of all possible bytes.
// 252 is evenly divisible by 3 and 4. Only 192, 10, 241, and 43 are missing.
- if (A->data_color_space != B->data_color_space) {
+ // We want to allow otherwise equivalent profiles tagged as grayscale and RGB
+ // to be treated as equal. But CMYK profiles are a totally different ballgame.
+ const auto CMYK = skcms_Signature_CMYK;
+ if ((A->data_color_space == CMYK) != (B->data_color_space == CMYK)) {
return false;
}
diff --git a/tests.c b/tests.c
index 8689d12..a69e2f8 100644
--- a/tests.c
+++ b/tests.c
@@ -1301,6 +1301,15 @@
expect(0 == memcmp(&exact, srgb, sizeof(skcms_ICCProfile)));
}
+static void test_GrayscaleAndRGBCanBeEqual() {
+ const skcms_ICCProfile* srgb = skcms_sRGB_profile();
+ skcms_ICCProfile gray = *srgb;
+ gray.data_color_space = skcms_Signature_Gray;
+
+ expect(skcms_ApproximatelyEqualProfiles(srgb, &gray));
+ expect(skcms_ApproximatelyEqualProfiles(&gray, srgb));
+}
+
static void test_Clamp() {
// Test that we clamp out-of-gamut values when converting to fixed point,
// not just to byte value range but also to gamut (for compatibility with
@@ -1716,6 +1725,7 @@
test_PrimariesToXYZ();
test_Programmatic_sRGB();
test_ExactlyEqual();
+ test_GrayscaleAndRGBCanBeEqual();
test_AliasedTransforms();
test_Palette8();
test_TF_invert();