msarett | 6a73821 | 2016-03-04 13:27:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "Resources.h" |
| 9 | #include "SkCodec.h" |
| 10 | #include "SkColorSpace.h" |
msarett | 8cc2091 | 2016-05-23 09:29:29 -0700 | [diff] [blame] | 11 | #include "SkColorSpace_Base.h" |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 12 | #include "SkColorSpace_XYZ.h" |
msarett | 6a73821 | 2016-03-04 13:27:35 -0800 | [diff] [blame] | 13 | #include "Test.h" |
| 14 | |
msarett | 53add95 | 2016-03-07 17:25:12 -0800 | [diff] [blame] | 15 | #include "png.h" |
| 16 | |
reed | 50d3b57 | 2016-05-03 12:13:21 -0700 | [diff] [blame] | 17 | static bool almost_equal(float a, float b) { |
| 18 | return SkTAbs(a - b) < 0.001f; |
| 19 | } |
| 20 | |
| 21 | static void test_space(skiatest::Reporter* r, SkColorSpace* space, |
| 22 | const float red[], const float green[], const float blue[], |
msarett | 600c737 | 2016-09-07 12:03:53 -0700 | [diff] [blame] | 23 | const SkGammaNamed expectedGamma) { |
msarett | bb9f774 | 2016-05-17 09:31:20 -0700 | [diff] [blame] | 24 | |
msarett | 9d15dab | 2016-08-24 07:36:06 -0700 | [diff] [blame] | 25 | REPORTER_ASSERT(r, nullptr != space); |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 26 | SkASSERT(SkColorSpace_Base::Type::kXYZ == as_CSB(space)->type()); |
| 27 | SkColorSpace_XYZ* csXYZ = static_cast<SkColorSpace_XYZ*>(space); |
| 28 | REPORTER_ASSERT(r, expectedGamma == csXYZ->gammaNamed()); |
msarett | bb9f774 | 2016-05-17 09:31:20 -0700 | [diff] [blame] | 29 | |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 30 | const SkMatrix44& mat = *csXYZ->toXYZD50(); |
reed | 50d3b57 | 2016-05-03 12:13:21 -0700 | [diff] [blame] | 31 | const float src[] = { |
| 32 | 1, 0, 0, 1, |
| 33 | 0, 1, 0, 1, |
| 34 | 0, 0, 1, 1, |
| 35 | }; |
brianosman | de68d6c | 2016-09-09 10:36:17 -0700 | [diff] [blame] | 36 | const float* ref[3] = { red, green, blue }; |
reed | 50d3b57 | 2016-05-03 12:13:21 -0700 | [diff] [blame] | 37 | float dst[4]; |
| 38 | for (int i = 0; i < 3; ++i) { |
| 39 | mat.mapScalars(&src[i*4], dst); |
brianosman | de68d6c | 2016-09-09 10:36:17 -0700 | [diff] [blame] | 40 | REPORTER_ASSERT(r, almost_equal(ref[i][0], dst[0])); |
| 41 | REPORTER_ASSERT(r, almost_equal(ref[i][1], dst[1])); |
| 42 | REPORTER_ASSERT(r, almost_equal(ref[i][2], dst[2])); |
reed | 50d3b57 | 2016-05-03 12:13:21 -0700 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
msarett | 9d15dab | 2016-08-24 07:36:06 -0700 | [diff] [blame] | 46 | static void test_path(skiatest::Reporter* r, const char* path, |
| 47 | const float red[], const float green[], const float blue[], |
msarett | 600c737 | 2016-09-07 12:03:53 -0700 | [diff] [blame] | 48 | const SkGammaNamed expectedGamma) { |
bungeman | f93d711 | 2016-09-16 06:24:20 -0700 | [diff] [blame] | 49 | SkAutoTDelete<SkStream> stream(GetResourceAsStream(path)); |
msarett | 0e6274f | 2016-03-21 08:04:40 -0700 | [diff] [blame] | 50 | REPORTER_ASSERT(r, nullptr != stream); |
Brian Salomon | d2100f2 | 2016-03-25 17:02:20 -0400 | [diff] [blame] | 51 | if (!stream) { |
| 52 | return; |
| 53 | } |
msarett | 0e6274f | 2016-03-21 08:04:40 -0700 | [diff] [blame] | 54 | |
| 55 | SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); |
| 56 | REPORTER_ASSERT(r, nullptr != codec); |
Brian Salomon | d2100f2 | 2016-03-25 17:02:20 -0400 | [diff] [blame] | 57 | if (!codec) { |
| 58 | return; |
| 59 | } |
msarett | 0e6274f | 2016-03-21 08:04:40 -0700 | [diff] [blame] | 60 | |
msarett | 530c844 | 2016-07-21 11:57:49 -0700 | [diff] [blame] | 61 | SkColorSpace* colorSpace = codec->getInfo().colorSpace(); |
msarett | 9d15dab | 2016-08-24 07:36:06 -0700 | [diff] [blame] | 62 | test_space(r, colorSpace, red, green, blue, expectedGamma); |
| 63 | } |
| 64 | |
brianosman | de68d6c | 2016-09-09 10:36:17 -0700 | [diff] [blame] | 65 | static constexpr float g_sRGB_XYZ[]{ |
| 66 | 0.4358f, 0.3853f, 0.1430f, // Rx, Gx, Bx |
| 67 | 0.2224f, 0.7170f, 0.0606f, // Ry, Gy, Gz |
| 68 | 0.0139f, 0.0971f, 0.7139f, // Rz, Gz, Bz |
| 69 | }; |
| 70 | |
| 71 | static constexpr float g_sRGB_R[]{ 0.4358f, 0.2224f, 0.0139f }; |
| 72 | static constexpr float g_sRGB_G[]{ 0.3853f, 0.7170f, 0.0971f }; |
| 73 | static constexpr float g_sRGB_B[]{ 0.1430f, 0.0606f, 0.7139f }; |
msarett | 9d15dab | 2016-08-24 07:36:06 -0700 | [diff] [blame] | 74 | |
| 75 | DEF_TEST(ColorSpace_sRGB, r) { |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 76 | test_space(r, SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get(), |
brianosman | de68d6c | 2016-09-09 10:36:17 -0700 | [diff] [blame] | 77 | g_sRGB_R, g_sRGB_G, g_sRGB_B, kSRGB_SkGammaNamed); |
msarett | 9d15dab | 2016-08-24 07:36:06 -0700 | [diff] [blame] | 78 | |
| 79 | } |
| 80 | |
| 81 | DEF_TEST(ColorSpaceParseICCProfiles, r) { |
| 82 | |
| 83 | #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 6) |
brianosman | de68d6c | 2016-09-09 10:36:17 -0700 | [diff] [blame] | 84 | test_path(r, "color_wheel_with_profile.png", g_sRGB_R, g_sRGB_G, g_sRGB_B, |
msarett | 600c737 | 2016-09-07 12:03:53 -0700 | [diff] [blame] | 85 | kSRGB_SkGammaNamed); |
msarett | 9d15dab | 2016-08-24 07:36:06 -0700 | [diff] [blame] | 86 | #endif |
msarett | 0e6274f | 2016-03-21 08:04:40 -0700 | [diff] [blame] | 87 | |
reed | 50d3b57 | 2016-05-03 12:13:21 -0700 | [diff] [blame] | 88 | const float red[] = { 0.385117f, 0.716904f, 0.0970612f }; |
| 89 | const float green[] = { 0.143051f, 0.0606079f, 0.713913f }; |
| 90 | const float blue[] = { 0.436035f, 0.222488f, 0.013916f }; |
msarett | 600c737 | 2016-09-07 12:03:53 -0700 | [diff] [blame] | 91 | test_path(r, "icc-v2-gbr.jpg", red, green, blue, k2Dot2Curve_SkGammaNamed); |
msarett | 9d15dab | 2016-08-24 07:36:06 -0700 | [diff] [blame] | 92 | |
| 93 | test_path(r, "webp-color-profile-crash.webp", |
msarett | 600c737 | 2016-09-07 12:03:53 -0700 | [diff] [blame] | 94 | red, green, blue, kNonStandard_SkGammaNamed); |
msarett | 9d15dab | 2016-08-24 07:36:06 -0700 | [diff] [blame] | 95 | test_path(r, "webp-color-profile-lossless.webp", |
msarett | 600c737 | 2016-09-07 12:03:53 -0700 | [diff] [blame] | 96 | red, green, blue, kNonStandard_SkGammaNamed); |
msarett | 9d15dab | 2016-08-24 07:36:06 -0700 | [diff] [blame] | 97 | test_path(r, "webp-color-profile-lossy.webp", |
msarett | 600c737 | 2016-09-07 12:03:53 -0700 | [diff] [blame] | 98 | red, green, blue, kNonStandard_SkGammaNamed); |
msarett | 9d15dab | 2016-08-24 07:36:06 -0700 | [diff] [blame] | 99 | test_path(r, "webp-color-profile-lossy-alpha.webp", |
msarett | 600c737 | 2016-09-07 12:03:53 -0700 | [diff] [blame] | 100 | red, green, blue, kNonStandard_SkGammaNamed); |
msarett | 0e6274f | 2016-03-21 08:04:40 -0700 | [diff] [blame] | 101 | } |
msarett | 02125d1 | 2016-05-03 14:24:47 -0700 | [diff] [blame] | 102 | |
| 103 | DEF_TEST(ColorSpaceSRGBCompare, r) { |
| 104 | // Create an sRGB color space by name |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 105 | sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); |
msarett | 02125d1 | 2016-05-03 14:24:47 -0700 | [diff] [blame] | 106 | |
| 107 | // Create an sRGB color space by value |
| 108 | SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); |
msarett | c1a3e24 | 2016-06-23 12:42:29 -0700 | [diff] [blame] | 109 | srgbToxyzD50.set3x3RowMajorf(g_sRGB_XYZ); |
msarett | 48ba2b8 | 2016-09-07 18:55:49 -0700 | [diff] [blame] | 110 | sk_sp<SkColorSpace> rgbColorSpace = |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 111 | SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, srgbToxyzD50); |
msarett | ab926f0 | 2016-05-25 08:53:40 -0700 | [diff] [blame] | 112 | REPORTER_ASSERT(r, rgbColorSpace == namedColorSpace); |
msarett | 02125d1 | 2016-05-03 14:24:47 -0700 | [diff] [blame] | 113 | |
| 114 | // Change a single value from the sRGB matrix |
| 115 | srgbToxyzD50.set(2, 2, 0.5f); |
msarett | 48ba2b8 | 2016-09-07 18:55:49 -0700 | [diff] [blame] | 116 | sk_sp<SkColorSpace> strangeColorSpace = |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 117 | SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, srgbToxyzD50); |
msarett | 02125d1 | 2016-05-03 14:24:47 -0700 | [diff] [blame] | 118 | REPORTER_ASSERT(r, strangeColorSpace != namedColorSpace); |
| 119 | } |
msarett | ab926f0 | 2016-05-25 08:53:40 -0700 | [diff] [blame] | 120 | |
brianosman | eec8304 | 2016-09-27 15:11:47 -0700 | [diff] [blame] | 121 | DEF_TEST(ColorSpaceSRGBLinearCompare, r) { |
| 122 | // Create the linear sRGB color space by name |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 123 | sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named); |
brianosman | eec8304 | 2016-09-27 15:11:47 -0700 | [diff] [blame] | 124 | |
| 125 | // Create the linear sRGB color space via the sRGB color space's makeLinearGamma() |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 126 | auto srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 127 | auto srgbXYZ = static_cast<SkColorSpace_XYZ*>(srgb.get()); |
| 128 | sk_sp<SkColorSpace> viaSrgbColorSpace = srgbXYZ->makeLinearGamma(); |
brianosman | eec8304 | 2016-09-27 15:11:47 -0700 | [diff] [blame] | 129 | REPORTER_ASSERT(r, namedColorSpace == viaSrgbColorSpace); |
| 130 | |
| 131 | // Create a linear sRGB color space by value |
| 132 | SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); |
| 133 | srgbToxyzD50.set3x3RowMajorf(g_sRGB_XYZ); |
| 134 | sk_sp<SkColorSpace> rgbColorSpace = |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 135 | SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, srgbToxyzD50); |
brianosman | eec8304 | 2016-09-27 15:11:47 -0700 | [diff] [blame] | 136 | REPORTER_ASSERT(r, rgbColorSpace == namedColorSpace); |
| 137 | |
| 138 | // Change a single value from the sRGB matrix |
| 139 | srgbToxyzD50.set(2, 2, 0.5f); |
| 140 | sk_sp<SkColorSpace> strangeColorSpace = |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 141 | SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, srgbToxyzD50); |
brianosman | eec8304 | 2016-09-27 15:11:47 -0700 | [diff] [blame] | 142 | REPORTER_ASSERT(r, strangeColorSpace != namedColorSpace); |
| 143 | } |
| 144 | |
msarett | c213f0d | 2016-08-01 14:23:32 -0700 | [diff] [blame] | 145 | class ColorSpaceTest { |
| 146 | public: |
| 147 | static sk_sp<SkData> WriteToICC(SkColorSpace* space) { |
| 148 | return as_CSB(space)->writeToICC(); |
| 149 | } |
| 150 | }; |
| 151 | |
msarett | ab926f0 | 2016-05-25 08:53:40 -0700 | [diff] [blame] | 152 | DEF_TEST(ColorSpaceWriteICC, r) { |
| 153 | // Test writing a new ICC profile |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 154 | sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); |
msarett | c213f0d | 2016-08-01 14:23:32 -0700 | [diff] [blame] | 155 | sk_sp<SkData> namedData = ColorSpaceTest::WriteToICC(namedColorSpace.get()); |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 156 | sk_sp<SkColorSpace> iccColorSpace = SkColorSpace::MakeICC(namedData->data(), namedData->size()); |
brianosman | de68d6c | 2016-09-09 10:36:17 -0700 | [diff] [blame] | 157 | test_space(r, iccColorSpace.get(), g_sRGB_R, g_sRGB_G, g_sRGB_B, k2Dot2Curve_SkGammaNamed); |
msarett | c4ce6b5 | 2016-06-16 07:37:41 -0700 | [diff] [blame] | 158 | // FIXME (msarett): Test disabled. sRGB profiles are written approximately as 2.2f curves. |
| 159 | // REPORTER_ASSERT(r, iccColorSpace == namedColorSpace); |
msarett | ab926f0 | 2016-05-25 08:53:40 -0700 | [diff] [blame] | 160 | |
| 161 | // Test saving the original ICC data |
| 162 | sk_sp<SkData> monitorData = SkData::MakeFromFileName( |
msarett | a714bc3 | 2016-07-29 08:58:33 -0700 | [diff] [blame] | 163 | GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str()); |
msarett | ab926f0 | 2016-05-25 08:53:40 -0700 | [diff] [blame] | 164 | REPORTER_ASSERT(r, monitorData); |
| 165 | if (!monitorData) { |
| 166 | return; |
| 167 | } |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 168 | sk_sp<SkColorSpace> monitorSpace = SkColorSpace::MakeICC(monitorData->data(), |
| 169 | monitorData->size()); |
msarett | c213f0d | 2016-08-01 14:23:32 -0700 | [diff] [blame] | 170 | sk_sp<SkData> newMonitorData = ColorSpaceTest::WriteToICC(monitorSpace.get()); |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 171 | sk_sp<SkColorSpace> newMonitorSpace = SkColorSpace::MakeICC(newMonitorData->data(), |
| 172 | newMonitorData->size()); |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 173 | SkASSERT(SkColorSpace_Base::Type::kXYZ == as_CSB(monitorSpace)->type()); |
| 174 | SkColorSpace_XYZ* monitorSpaceXYZ = static_cast<SkColorSpace_XYZ*>(monitorSpace.get()); |
| 175 | SkASSERT(SkColorSpace_Base::Type::kXYZ == as_CSB(newMonitorSpace)->type()); |
| 176 | SkColorSpace_XYZ* newMonitorSpaceXYZ = static_cast<SkColorSpace_XYZ*>(newMonitorSpace.get()); |
| 177 | REPORTER_ASSERT(r, *monitorSpaceXYZ->toXYZD50() == *newMonitorSpaceXYZ->toXYZD50()); |
Brian Osman | bbf251b | 2016-10-19 14:56:07 -0400 | [diff] [blame] | 178 | REPORTER_ASSERT(r, monitorSpaceXYZ->toXYZD50Hash() == newMonitorSpaceXYZ->toXYZD50Hash()); |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 179 | REPORTER_ASSERT(r, monitorSpaceXYZ->gammaNamed() == newMonitorSpaceXYZ->gammaNamed()); |
msarett | ab926f0 | 2016-05-25 08:53:40 -0700 | [diff] [blame] | 180 | } |
reed | fbce71f | 2016-06-02 12:40:22 -0700 | [diff] [blame] | 181 | |
| 182 | DEF_TEST(ColorSpace_Named, r) { |
| 183 | const struct { |
| 184 | SkColorSpace::Named fNamed; |
brianosman | eec8304 | 2016-09-27 15:11:47 -0700 | [diff] [blame] | 185 | SkGammaNamed fExpectedGamma; |
reed | fbce71f | 2016-06-02 12:40:22 -0700 | [diff] [blame] | 186 | } recs[] { |
brianosman | eec8304 | 2016-09-27 15:11:47 -0700 | [diff] [blame] | 187 | { SkColorSpace::kSRGB_Named, kSRGB_SkGammaNamed }, |
| 188 | { SkColorSpace::kAdobeRGB_Named, k2Dot2Curve_SkGammaNamed }, |
| 189 | { SkColorSpace::kSRGBLinear_Named, kLinear_SkGammaNamed }, |
reed | fbce71f | 2016-06-02 12:40:22 -0700 | [diff] [blame] | 190 | }; |
| 191 | |
| 192 | for (auto rec : recs) { |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 193 | auto cs = SkColorSpace::MakeNamed(rec.fNamed); |
msarett | 47ae5c5 | 2016-09-06 10:01:48 -0700 | [diff] [blame] | 194 | REPORTER_ASSERT(r, cs); |
reed | fbce71f | 2016-06-02 12:40:22 -0700 | [diff] [blame] | 195 | if (cs) { |
raftias | 9488833 | 2016-10-18 10:02:51 -0700 | [diff] [blame] | 196 | SkASSERT(SkColorSpace_Base::Type::kXYZ == as_CSB(cs)->type()); |
| 197 | SkColorSpace_XYZ* csXYZ = static_cast<SkColorSpace_XYZ*>(cs.get()); |
| 198 | REPORTER_ASSERT(r, rec.fExpectedGamma == csXYZ->gammaNamed()); |
reed | fbce71f | 2016-06-02 12:40:22 -0700 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | |
| 202 | SkImageInfo info = SkImageInfo::MakeS32(10, 10, kPremul_SkAlphaType); |
reed | dabe5d3 | 2016-06-21 10:28:14 -0700 | [diff] [blame] | 203 | REPORTER_ASSERT(r, info.gammaCloseToSRGB()); |
reed | fbce71f | 2016-06-02 12:40:22 -0700 | [diff] [blame] | 204 | } |
msarett | 111a42d | 2016-06-22 08:18:54 -0700 | [diff] [blame] | 205 | |
| 206 | static void test_serialize(skiatest::Reporter* r, SkColorSpace* space, bool isNamed) { |
msarett | a0605bf | 2016-07-28 10:47:50 -0700 | [diff] [blame] | 207 | sk_sp<SkData> data1 = space->serialize(); |
| 208 | |
| 209 | size_t bytes = space->writeToMemory(nullptr); |
| 210 | sk_sp<SkData> data2 = SkData::MakeUninitialized(bytes); |
| 211 | space->writeToMemory(data2->writable_data()); |
| 212 | |
| 213 | sk_sp<SkColorSpace> newSpace1 = SkColorSpace::Deserialize(data1->data(), data1->size()); |
| 214 | sk_sp<SkColorSpace> newSpace2 = SkColorSpace::Deserialize(data2->data(), data2->size()); |
msarett | 111a42d | 2016-06-22 08:18:54 -0700 | [diff] [blame] | 215 | |
| 216 | if (isNamed) { |
msarett | a0605bf | 2016-07-28 10:47:50 -0700 | [diff] [blame] | 217 | REPORTER_ASSERT(r, space == newSpace1.get()); |
| 218 | REPORTER_ASSERT(r, space == newSpace2.get()); |
msarett | 111a42d | 2016-06-22 08:18:54 -0700 | [diff] [blame] | 219 | } else { |
msarett | d9015a4 | 2016-08-22 12:29:31 -0700 | [diff] [blame] | 220 | REPORTER_ASSERT(r, SkColorSpace::Equals(space, newSpace1.get())); |
| 221 | REPORTER_ASSERT(r, SkColorSpace::Equals(space, newSpace2.get())); |
msarett | 111a42d | 2016-06-22 08:18:54 -0700 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
| 225 | DEF_TEST(ColorSpace_Serialize, r) { |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 226 | test_serialize(r, SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named).get(), true); |
| 227 | test_serialize(r, SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named).get(), true); |
| 228 | test_serialize(r, SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named).get(), true); |
msarett | 111a42d | 2016-06-22 08:18:54 -0700 | [diff] [blame] | 229 | |
| 230 | sk_sp<SkData> monitorData = SkData::MakeFromFileName( |
msarett | a714bc3 | 2016-07-29 08:58:33 -0700 | [diff] [blame] | 231 | GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str()); |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 232 | test_serialize(r, SkColorSpace::MakeICC(monitorData->data(), monitorData->size()).get(), false); |
msarett | a714bc3 | 2016-07-29 08:58:33 -0700 | [diff] [blame] | 233 | monitorData = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32x.icc").c_str()); |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 234 | test_serialize(r, SkColorSpace::MakeICC(monitorData->data(), monitorData->size()).get(), false); |
msarett | a714bc3 | 2016-07-29 08:58:33 -0700 | [diff] [blame] | 235 | monitorData = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLeft.icc").c_str()); |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 236 | test_serialize(r, SkColorSpace::MakeICC(monitorData->data(), monitorData->size()).get(), false); |
msarett | a714bc3 | 2016-07-29 08:58:33 -0700 | [diff] [blame] | 237 | monitorData = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRight.icc").c_str()); |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 238 | test_serialize(r, SkColorSpace::MakeICC(monitorData->data(), monitorData->size()).get(), false); |
msarett | d9015a4 | 2016-08-22 12:29:31 -0700 | [diff] [blame] | 239 | |
| 240 | const float gammas[] = { 1.1f, 1.2f, 1.7f, }; |
| 241 | SkMatrix44 toXYZ(SkMatrix44::kIdentity_Constructor); |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 242 | test_serialize(r, SkColorSpace::MakeRGB(gammas, toXYZ).get(), false); |
Matt Sarett | df44fc5 | 2016-10-11 16:57:50 -0400 | [diff] [blame] | 243 | |
| 244 | SkColorSpaceTransferFn fn; |
| 245 | fn.fA = 1.0f; |
| 246 | fn.fB = 0.0f; |
| 247 | fn.fC = 0.0f; |
| 248 | fn.fD = 0.5f; |
| 249 | fn.fE = 1.0f; |
| 250 | fn.fF = 0.0f; |
| 251 | fn.fG = 1.0f; |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 252 | test_serialize(r, SkColorSpace::MakeRGB(fn, toXYZ).get(), false); |
msarett | 111a42d | 2016-06-22 08:18:54 -0700 | [diff] [blame] | 253 | } |
| 254 | |
msarett | abbd6d5 | 2016-08-01 09:43:08 -0700 | [diff] [blame] | 255 | DEF_TEST(ColorSpace_Equals, r) { |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 256 | sk_sp<SkColorSpace> srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); |
| 257 | sk_sp<SkColorSpace> adobe = SkColorSpace::MakeNamed(SkColorSpace::kAdobeRGB_Named); |
msarett | abbd6d5 | 2016-08-01 09:43:08 -0700 | [diff] [blame] | 258 | sk_sp<SkData> data = SkData::MakeFromFileName( |
| 259 | GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str()); |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 260 | sk_sp<SkColorSpace> z30 = SkColorSpace::MakeICC(data->data(), data->size()); |
msarett | abbd6d5 | 2016-08-01 09:43:08 -0700 | [diff] [blame] | 261 | data = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32x.icc").c_str()); |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 262 | sk_sp<SkColorSpace> z32 = SkColorSpace::MakeICC(data->data(), data->size()); |
msarett | abbd6d5 | 2016-08-01 09:43:08 -0700 | [diff] [blame] | 263 | data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLeft.icc").c_str()); |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 264 | sk_sp<SkColorSpace> upperLeft = SkColorSpace::MakeICC(data->data(), data->size()); |
msarett | abbd6d5 | 2016-08-01 09:43:08 -0700 | [diff] [blame] | 265 | data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRight.icc").c_str()); |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 266 | sk_sp<SkColorSpace> upperRight = SkColorSpace::MakeICC(data->data(), data->size()); |
msarett | d9015a4 | 2016-08-22 12:29:31 -0700 | [diff] [blame] | 267 | const float gammas1[] = { 1.1f, 1.2f, 1.3f, }; |
| 268 | const float gammas2[] = { 1.1f, 1.2f, 1.7f, }; |
| 269 | SkMatrix44 toXYZ(SkMatrix44::kIdentity_Constructor); |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 270 | sk_sp<SkColorSpace> rgb1 = SkColorSpace::MakeRGB(gammas1, toXYZ); |
| 271 | sk_sp<SkColorSpace> rgb2 = SkColorSpace::MakeRGB(gammas2, toXYZ); |
| 272 | sk_sp<SkColorSpace> rgb3 = SkColorSpace::MakeRGB(gammas1, toXYZ); |
msarett | abbd6d5 | 2016-08-01 09:43:08 -0700 | [diff] [blame] | 273 | |
Matt Sarett | df44fc5 | 2016-10-11 16:57:50 -0400 | [diff] [blame] | 274 | SkColorSpaceTransferFn fn; |
| 275 | fn.fA = 1.0f; |
| 276 | fn.fB = 0.0f; |
| 277 | fn.fC = 0.0f; |
| 278 | fn.fD = 0.5f; |
| 279 | fn.fE = 1.0f; |
| 280 | fn.fF = 0.0f; |
| 281 | fn.fG = 1.0f; |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 282 | sk_sp<SkColorSpace> rgb4 = SkColorSpace::MakeRGB(fn, toXYZ); |
Matt Sarett | df44fc5 | 2016-10-11 16:57:50 -0400 | [diff] [blame] | 283 | |
msarett | abbd6d5 | 2016-08-01 09:43:08 -0700 | [diff] [blame] | 284 | REPORTER_ASSERT(r, SkColorSpace::Equals(nullptr, nullptr)); |
| 285 | REPORTER_ASSERT(r, SkColorSpace::Equals(srgb.get(), srgb.get())); |
| 286 | REPORTER_ASSERT(r, SkColorSpace::Equals(adobe.get(), adobe.get())); |
| 287 | REPORTER_ASSERT(r, SkColorSpace::Equals(z30.get(), z30.get())); |
| 288 | REPORTER_ASSERT(r, SkColorSpace::Equals(z32.get(), z32.get())); |
| 289 | REPORTER_ASSERT(r, SkColorSpace::Equals(upperLeft.get(), upperLeft.get())); |
| 290 | REPORTER_ASSERT(r, SkColorSpace::Equals(upperRight.get(), upperRight.get())); |
msarett | d9015a4 | 2016-08-22 12:29:31 -0700 | [diff] [blame] | 291 | REPORTER_ASSERT(r, SkColorSpace::Equals(rgb1.get(), rgb1.get())); |
| 292 | REPORTER_ASSERT(r, SkColorSpace::Equals(rgb1.get(), rgb3.get())); |
Matt Sarett | df44fc5 | 2016-10-11 16:57:50 -0400 | [diff] [blame] | 293 | REPORTER_ASSERT(r, SkColorSpace::Equals(rgb4.get(), rgb4.get())); |
msarett | abbd6d5 | 2016-08-01 09:43:08 -0700 | [diff] [blame] | 294 | |
| 295 | REPORTER_ASSERT(r, !SkColorSpace::Equals(nullptr, srgb.get())); |
| 296 | REPORTER_ASSERT(r, !SkColorSpace::Equals(srgb.get(), nullptr)); |
| 297 | REPORTER_ASSERT(r, !SkColorSpace::Equals(adobe.get(), srgb.get())); |
| 298 | REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), srgb.get())); |
| 299 | REPORTER_ASSERT(r, !SkColorSpace::Equals(z32.get(), z30.get())); |
| 300 | REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), srgb.get())); |
| 301 | REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), upperRight.get())); |
| 302 | REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), upperRight.get())); |
| 303 | REPORTER_ASSERT(r, !SkColorSpace::Equals(upperRight.get(), adobe.get())); |
msarett | d9015a4 | 2016-08-22 12:29:31 -0700 | [diff] [blame] | 304 | REPORTER_ASSERT(r, !SkColorSpace::Equals(rgb1.get(), rgb2.get())); |
Matt Sarett | df44fc5 | 2016-10-11 16:57:50 -0400 | [diff] [blame] | 305 | REPORTER_ASSERT(r, !SkColorSpace::Equals(rgb1.get(), rgb4.get())); |
msarett | abbd6d5 | 2016-08-01 09:43:08 -0700 | [diff] [blame] | 306 | } |
msarett | a5a31dd | 2016-10-11 09:41:16 -0700 | [diff] [blame] | 307 | |
| 308 | DEF_TEST(ColorSpace_Primaries, r) { |
| 309 | // sRGB primaries |
| 310 | SkColorSpacePrimaries primaries; |
| 311 | primaries.fRX = 0.64f; |
| 312 | primaries.fRY = 0.33f; |
| 313 | primaries.fGX = 0.30f; |
| 314 | primaries.fGY = 0.60f; |
| 315 | primaries.fBX = 0.15f; |
| 316 | primaries.fBY = 0.06f; |
| 317 | primaries.fWX = 0.3127f; |
| 318 | primaries.fWY = 0.3290f; |
| 319 | |
| 320 | SkMatrix44 toXYZ(SkMatrix44::kUninitialized_Constructor); |
| 321 | bool result = primaries.toXYZD50(&toXYZ); |
| 322 | REPORTER_ASSERT(r, result); |
| 323 | |
Brian Osman | 526972e | 2016-10-24 09:24:02 -0400 | [diff] [blame^] | 324 | sk_sp<SkColorSpace> space = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma, toXYZ); |
| 325 | REPORTER_ASSERT(r, SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named) == space); |
msarett | a5a31dd | 2016-10-11 09:41:16 -0700 | [diff] [blame] | 326 | } |