blob: 0efd9939c39731fa105166a09454f4356eb95641 [file] [log] [blame]
msarettdc27a642016-06-06 12:02:31 -07001/*
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"
msarettc0444612016-09-16 11:45:58 -070010#include "SkCodecPriv.h"
msarettdc27a642016-06-06 12:02:31 -070011#include "SkColorPriv.h"
12#include "SkColorSpace.h"
raftias25636012016-11-11 15:27:39 -080013#include "SkColorSpace_A2B.h"
raftias94888332016-10-18 10:02:51 -070014#include "SkColorSpace_XYZ.h"
msarett31d097e82016-10-11 12:15:03 -070015#include "SkColorSpaceXform_Base.h"
msarettdc27a642016-06-06 12:02:31 -070016#include "Test.h"
17
raftias54761282016-12-01 13:44:07 -050018static constexpr int kChannels = 3;
19
msarettdc27a642016-06-06 12:02:31 -070020class ColorSpaceXformTest {
21public:
mtkleinb4359632016-07-18 11:16:14 -070022 static std::unique_ptr<SkColorSpaceXform> CreateIdentityXform(const sk_sp<SkGammas>& gammas) {
23 // Logically we can pass any matrix here. For simplicty, pass I(), i.e. D50 XYZ gamut.
raftias94888332016-10-18 10:02:51 -070024 sk_sp<SkColorSpace> space(new SkColorSpace_XYZ(
Matt Sarettf3880932017-03-24 10:06:03 -040025 kNonStandard_SkGammaNamed, gammas, SkMatrix::I(), nullptr));
msarett9dc6cf62016-08-23 17:53:06 -070026
27 // Use special testing entry point, so we don't skip the xform, even though src == dst.
raftias94888332016-10-18 10:02:51 -070028 return SlowIdentityXform(static_cast<SkColorSpace_XYZ*>(space.get()));
msarettdc27a642016-06-06 12:02:31 -070029 }
raftias25636012016-11-11 15:27:39 -080030
31 static std::unique_ptr<SkColorSpaceXform> CreateIdentityXform_A2B(
32 SkGammaNamed gammaNamed, const sk_sp<SkGammas>& gammas) {
33 std::vector<SkColorSpace_A2B::Element> srcElements;
34 // sRGB
35 const float values[16] = {
36 0.4358f, 0.3853f, 0.1430f, 0.0f,
37 0.2224f, 0.7170f, 0.0606f, 0.0f,
38 0.0139f, 0.0971f, 0.7139f, 0.0f,
39 0.0000f, 0.0000f, 0.0000f, 1.0f
40 };
41 SkMatrix44 arbitraryMatrix{SkMatrix44::kUninitialized_Constructor};
42 arbitraryMatrix.setRowMajorf(values);
43 if (kNonStandard_SkGammaNamed == gammaNamed) {
raftias54761282016-12-01 13:44:07 -050044 SkASSERT(gammas);
raftias25636012016-11-11 15:27:39 -080045 srcElements.push_back(SkColorSpace_A2B::Element(gammas));
46 } else {
raftias54761282016-12-01 13:44:07 -050047 srcElements.push_back(SkColorSpace_A2B::Element(gammaNamed, kChannels));
raftias25636012016-11-11 15:27:39 -080048 }
49 srcElements.push_back(SkColorSpace_A2B::Element(arbitraryMatrix));
raftias54761282016-12-01 13:44:07 -050050 auto srcSpace =
51 ColorSpaceXformTest::CreateA2BSpace(SkColorSpace_A2B::PCS::kXYZ,
raftias54761282016-12-01 13:44:07 -050052 std::move(srcElements));
raftias25636012016-11-11 15:27:39 -080053 sk_sp<SkColorSpace> dstSpace(new SkColorSpace_XYZ(gammaNamed, gammas, arbitraryMatrix,
Matt Sarettf3880932017-03-24 10:06:03 -040054 nullptr));
raftias25636012016-11-11 15:27:39 -080055
56 return SkColorSpaceXform::New(static_cast<SkColorSpace_A2B*>(srcSpace.get()),
57 static_cast<SkColorSpace_XYZ*>(dstSpace.get()));
58 }
59
60 static sk_sp<SkColorSpace> CreateA2BSpace(SkColorSpace_A2B::PCS pcs,
61 std::vector<SkColorSpace_A2B::Element> elements) {
Leon Scroggins IIIf78b55c2017-10-31 13:49:14 -040062 return sk_sp<SkColorSpace>(new SkColorSpace_A2B(SkColorSpace::kRGB_Type,
63 std::move(elements),
raftias54761282016-12-01 13:44:07 -050064 pcs, nullptr));
raftias25636012016-11-11 15:27:39 -080065 }
msarettdc27a642016-06-06 12:02:31 -070066};
67
Mike Kleinc7d9c0b2017-04-17 14:43:59 -040068static bool almost_equal(int x, int y, int tol=1) {
69 return SkTAbs(x-y) <= tol;
msarettb3906762016-06-22 14:07:48 -070070}
71
Matt Sarettf4898862016-10-16 10:20:41 -040072static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& gammas,
73 bool repeat) {
msarettdc27a642016-06-06 12:02:31 -070074 // Arbitrary set of 10 pixels
75 constexpr int width = 10;
76 constexpr uint32_t srcPixels[width] = {
77 0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271,
msarettb3906762016-06-22 14:07:48 -070078 0xFF32AB52, 0xFF0383BC, 0xFF000102, 0xFFFFFFFF, 0xFFDDEEFF, };
msarettdc27a642016-06-06 12:02:31 -070079 uint32_t dstPixels[width];
80
mtkleinb4359632016-07-18 11:16:14 -070081 // Create and perform an identity xform.
82 std::unique_ptr<SkColorSpaceXform> xform = ColorSpaceXformTest::CreateIdentityXform(gammas);
msarett31d097e82016-10-11 12:15:03 -070083 bool result = xform->apply(select_xform_format(kN32_SkColorType), dstPixels,
84 SkColorSpaceXform::kBGRA_8888_ColorFormat, srcPixels, width,
85 kOpaque_SkAlphaType);
86 REPORTER_ASSERT(r, result);
msarettdc27a642016-06-06 12:02:31 -070087
mtkleinb4359632016-07-18 11:16:14 -070088 // Since the src->dst matrix is the identity, and the gamma curves match,
89 // the pixels should be unchanged.
msarettdc27a642016-06-06 12:02:31 -070090 for (int i = 0; i < width; i++) {
msarettb3906762016-06-22 14:07:48 -070091 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 0) & 0xFF),
msarettcf7b8772016-09-22 12:37:04 -070092 SkGetPackedB32(dstPixels[i])));
msarettb3906762016-06-22 14:07:48 -070093 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 8) & 0xFF),
msarett9dc6cf62016-08-23 17:53:06 -070094 SkGetPackedG32(dstPixels[i])));
msarettb3906762016-06-22 14:07:48 -070095 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF),
msarettcf7b8772016-09-22 12:37:04 -070096 SkGetPackedR32(dstPixels[i])));
msarettb3906762016-06-22 14:07:48 -070097 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF),
msarett9dc6cf62016-08-23 17:53:06 -070098 SkGetPackedA32(dstPixels[i])));
msarettdc27a642016-06-06 12:02:31 -070099 }
Matt Sarettf4898862016-10-16 10:20:41 -0400100
101 if (repeat) {
102 // We should cache part of the transform after the run. So it is interesting
103 // to make sure it still runs correctly the second time.
104 test_identity_xform(r, gammas, false);
105 }
msarettdc27a642016-06-06 12:02:31 -0700106}
107
raftias25636012016-11-11 15:27:39 -0800108static void test_identity_xform_A2B(skiatest::Reporter* r, SkGammaNamed gammaNamed,
Mike Kleinc7d9c0b2017-04-17 14:43:59 -0400109 const sk_sp<SkGammas>& gammas, int tol=1) {
raftias25636012016-11-11 15:27:39 -0800110 // Arbitrary set of 10 pixels
111 constexpr int width = 10;
112 constexpr uint32_t srcPixels[width] = {
113 0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271,
114 0xFF32AB52, 0xFF0383BC, 0xFF000102, 0xFFFFFFFF, 0xFFDDEEFF, };
115 uint32_t dstPixels[width];
116
117 // Create and perform an identity xform.
118 auto xform = ColorSpaceXformTest::CreateIdentityXform_A2B(gammaNamed, gammas);
119 bool result = xform->apply(select_xform_format(kN32_SkColorType), dstPixels,
120 SkColorSpaceXform::kBGRA_8888_ColorFormat, srcPixels, width,
121 kOpaque_SkAlphaType);
122 REPORTER_ASSERT(r, result);
123
124 // Since the src->dst matrix is the identity, and the gamma curves match,
Mike Kleinc7d9c0b2017-04-17 14:43:59 -0400125 // the pixels should be ~unchanged.
raftias25636012016-11-11 15:27:39 -0800126 for (int i = 0; i < width; i++) {
127 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 0) & 0xFF),
Mike Kleinc7d9c0b2017-04-17 14:43:59 -0400128 SkGetPackedB32(dstPixels[i]), tol));
raftias25636012016-11-11 15:27:39 -0800129 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 8) & 0xFF),
Mike Kleinc7d9c0b2017-04-17 14:43:59 -0400130 SkGetPackedG32(dstPixels[i]), tol));
raftias25636012016-11-11 15:27:39 -0800131 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF),
Mike Kleinc7d9c0b2017-04-17 14:43:59 -0400132 SkGetPackedR32(dstPixels[i]), tol));
raftias25636012016-11-11 15:27:39 -0800133 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF),
Mike Kleinc7d9c0b2017-04-17 14:43:59 -0400134 SkGetPackedA32(dstPixels[i]), tol));
raftias25636012016-11-11 15:27:39 -0800135 }
raftias25636012016-11-11 15:27:39 -0800136}
137
msarettdc27a642016-06-06 12:02:31 -0700138DEF_TEST(ColorSpaceXform_TableGamma, r) {
139 // Lookup-table based gamma curves
msarettdc27a642016-06-06 12:02:31 -0700140 constexpr size_t tableSize = 10;
msarett1b93bd12016-07-21 07:11:26 -0700141 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(float) * tableSize);
raftias54761282016-12-01 13:44:07 -0500142 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas(kChannels));
143 for (int i = 0; i < kChannels; ++i) {
144 gammas->fType[i] = SkGammas::Type::kTable_Type;
145 gammas->fData[i].fTable.fSize = tableSize;
146 gammas->fData[i].fTable.fOffset = 0;
147 }
148
msarett1b93bd12016-07-21 07:11:26 -0700149 float* table = SkTAddOffset<float>(memory, sizeof(SkGammas));
msarett1b93bd12016-07-21 07:11:26 -0700150 table[0] = 0.00f;
151 table[1] = 0.05f;
152 table[2] = 0.10f;
153 table[3] = 0.15f;
154 table[4] = 0.25f;
155 table[5] = 0.35f;
156 table[6] = 0.45f;
157 table[7] = 0.60f;
158 table[8] = 0.75f;
159 table[9] = 1.00f;
Mike Kleinc7d9c0b2017-04-17 14:43:59 -0400160 // This table's pretty small compared to real ones in the wild (think 256),
161 // so we give test_identity_xform_A2B a wide tolerance.
162 // This lets us implement table transfer functions with a single lookup.
163 const int tolerance = 13;
164
Matt Sarettf4898862016-10-16 10:20:41 -0400165 test_identity_xform(r, gammas, true);
Mike Kleinc7d9c0b2017-04-17 14:43:59 -0400166 test_identity_xform_A2B(r, kNonStandard_SkGammaNamed, gammas, tolerance);
msarettdc27a642016-06-06 12:02:31 -0700167}
168
169DEF_TEST(ColorSpaceXform_ParametricGamma, r) {
170 // Parametric gamma curves
Matt Sarettdf44fc52016-10-11 16:57:50 -0400171 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(SkColorSpaceTransferFn));
raftias54761282016-12-01 13:44:07 -0500172 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas(kChannels));
173 for (int i = 0; i < kChannels; ++i) {
174 gammas->fType[i] = SkGammas::Type::kParam_Type;
175 gammas->fData[i].fParamOffset = 0;
176 }
177
Matt Sarettdf44fc52016-10-11 16:57:50 -0400178 SkColorSpaceTransferFn* params = SkTAddOffset<SkColorSpaceTransferFn>
179 (memory, sizeof(SkGammas));
msarettdc27a642016-06-06 12:02:31 -0700180
Matt Sarett24107172016-12-19 14:33:35 -0500181 // Interval.
msarett1b93bd12016-07-21 07:11:26 -0700182 params->fD = 0.04045f;
msarettdc27a642016-06-06 12:02:31 -0700183
msarettb3906762016-06-22 14:07:48 -0700184 // First equation:
Matt Sarett24107172016-12-19 14:33:35 -0500185 params->fC = 1.0f / 12.92f;
msarett1b93bd12016-07-21 07:11:26 -0700186 params->fF = 0.0f;
msarettdc27a642016-06-06 12:02:31 -0700187
msarettb3906762016-06-22 14:07:48 -0700188 // Second equation:
189 // Note that the function is continuous (it's actually sRGB).
msarett1b93bd12016-07-21 07:11:26 -0700190 params->fA = 1.0f / 1.055f;
191 params->fB = 0.055f / 1.055f;
Matt Sarett24107172016-12-19 14:33:35 -0500192 params->fE = 0.0f;
msarett1b93bd12016-07-21 07:11:26 -0700193 params->fG = 2.4f;
Matt Sarettf4898862016-10-16 10:20:41 -0400194 test_identity_xform(r, gammas, true);
raftias54761282016-12-01 13:44:07 -0500195 test_identity_xform_A2B(r, kNonStandard_SkGammaNamed, gammas);
msarettdc27a642016-06-06 12:02:31 -0700196}
197
198DEF_TEST(ColorSpaceXform_ExponentialGamma, r) {
199 // Exponential gamma curves
raftias54761282016-12-01 13:44:07 -0500200 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new SkGammas(kChannels));
201 for (int i = 0; i < kChannels; ++i) {
202 gammas->fType[i] = SkGammas::Type::kValue_Type;
203 gammas->fData[i].fValue = 1.4f;
204 }
Matt Sarettf4898862016-10-16 10:20:41 -0400205 test_identity_xform(r, gammas, true);
raftias54761282016-12-01 13:44:07 -0500206 test_identity_xform_A2B(r, kNonStandard_SkGammaNamed, gammas);
msarett1b93bd12016-07-21 07:11:26 -0700207}
208
msarett55bcc8e2016-09-09 07:48:05 -0700209DEF_TEST(ColorSpaceXform_NamedGamma, r) {
raftias54761282016-12-01 13:44:07 -0500210 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new SkGammas(kChannels));
211 gammas->fType[0] = gammas->fType[1] = gammas->fType[2] = SkGammas::Type::kNamed_Type;
212 gammas->fData[0].fNamed = kSRGB_SkGammaNamed;
213 gammas->fData[1].fNamed = k2Dot2Curve_SkGammaNamed;
214 gammas->fData[2].fNamed = kLinear_SkGammaNamed;
Matt Sarettf4898862016-10-16 10:20:41 -0400215 test_identity_xform(r, gammas, true);
raftias54761282016-12-01 13:44:07 -0500216 test_identity_xform_A2B(r, kNonStandard_SkGammaNamed, gammas);
217 test_identity_xform_A2B(r, kSRGB_SkGammaNamed, nullptr);
218 test_identity_xform_A2B(r, k2Dot2Curve_SkGammaNamed, nullptr);
219 test_identity_xform_A2B(r, kLinear_SkGammaNamed, nullptr);
msarett55bcc8e2016-09-09 07:48:05 -0700220}
221
msarett1b93bd12016-07-21 07:11:26 -0700222DEF_TEST(ColorSpaceXform_NonMatchingGamma, r) {
223 constexpr size_t tableSize = 10;
224 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(float) * tableSize +
Matt Sarettdf44fc52016-10-11 16:57:50 -0400225 sizeof(SkColorSpaceTransferFn));
raftias54761282016-12-01 13:44:07 -0500226 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas(kChannels));
msarett1b93bd12016-07-21 07:11:26 -0700227
228 float* table = SkTAddOffset<float>(memory, sizeof(SkGammas));
229 table[0] = 0.00f;
230 table[1] = 0.15f;
231 table[2] = 0.20f;
232 table[3] = 0.25f;
233 table[4] = 0.35f;
234 table[5] = 0.45f;
235 table[6] = 0.55f;
236 table[7] = 0.70f;
237 table[8] = 0.85f;
238 table[9] = 1.00f;
239
Matt Sarettdf44fc52016-10-11 16:57:50 -0400240 SkColorSpaceTransferFn* params = SkTAddOffset<SkColorSpaceTransferFn>(memory,
241 sizeof(SkGammas) + sizeof(float) * tableSize);
msarett1b93bd12016-07-21 07:11:26 -0700242 params->fA = 1.0f / 1.055f;
243 params->fB = 0.055f / 1.055f;
Matt Sarett24107172016-12-19 14:33:35 -0500244 params->fC = 1.0f / 12.92f;
msarett1b93bd12016-07-21 07:11:26 -0700245 params->fD = 0.04045f;
Matt Sarett24107172016-12-19 14:33:35 -0500246 params->fE = 0.0f;
msarett1b93bd12016-07-21 07:11:26 -0700247 params->fF = 0.0f;
248 params->fG = 2.4f;
249
raftias54761282016-12-01 13:44:07 -0500250 gammas->fType[0] = SkGammas::Type::kValue_Type;
251 gammas->fData[0].fValue = 1.2f;
msarett1b93bd12016-07-21 07:11:26 -0700252
Mike Klein44375172017-04-17 19:32:05 -0400253 // See ColorSpaceXform_TableGamma... we've decided to allow some tolerance
254 // for SkJumper's implementation of tables.
255 const int tolerance = 12;
raftias54761282016-12-01 13:44:07 -0500256 gammas->fType[1] = SkGammas::Type::kTable_Type;
257 gammas->fData[1].fTable.fSize = tableSize;
258 gammas->fData[1].fTable.fOffset = 0;
msarett1b93bd12016-07-21 07:11:26 -0700259
raftias54761282016-12-01 13:44:07 -0500260 gammas->fType[2] = SkGammas::Type::kParam_Type;
261 gammas->fData[2].fParamOffset = sizeof(float) * tableSize;
msarett1b93bd12016-07-21 07:11:26 -0700262
Matt Sarettf4898862016-10-16 10:20:41 -0400263 test_identity_xform(r, gammas, true);
Mike Klein44375172017-04-17 19:32:05 -0400264 test_identity_xform_A2B(r, kNonStandard_SkGammaNamed, gammas, tolerance);
raftias25636012016-11-11 15:27:39 -0800265}
266
267DEF_TEST(ColorSpaceXform_A2BCLUT, r) {
268 constexpr int inputChannels = 3;
269 constexpr int gp = 4; // # grid points
270
271 constexpr int numEntries = gp*gp*gp*3;
raftias54761282016-12-01 13:44:07 -0500272 const uint8_t gridPoints[3] = {gp, gp, gp};
raftias25636012016-11-11 15:27:39 -0800273 void* memory = sk_malloc_throw(sizeof(SkColorLookUpTable) + sizeof(float) * numEntries);
274 sk_sp<SkColorLookUpTable> colorLUT(new (memory) SkColorLookUpTable(inputChannels, gridPoints));
275 // make a CLUT that rotates R, G, and B ie R->G, G->B, B->R
276 float* table = SkTAddOffset<float>(memory, sizeof(SkColorLookUpTable));
277 for (int r = 0; r < gp; ++r) {
278 for (int g = 0; g < gp; ++g) {
279 for (int b = 0; b < gp; ++b) {
280 table[3*(gp*gp*r + gp*g + b) + 0] = g * (1.f / (gp - 1.f));
281 table[3*(gp*gp*r + gp*g + b) + 1] = b * (1.f / (gp - 1.f));
282 table[3*(gp*gp*r + gp*g + b) + 2] = r * (1.f / (gp - 1.f));
283 }
284 }
285 }
286
287 // build an even distribution of pixels every (7 / 255) steps
288 // to test the xform on
289 constexpr int pixelgp = 7;
290 constexpr int numPixels = pixelgp*pixelgp*pixelgp;
291 SkAutoTMalloc<uint32_t> srcPixels(numPixels);
292 int srcIndex = 0;
293 for (int r = 0; r < pixelgp; ++r) {
294 for (int g = 0; g < pixelgp; ++g) {
295 for (int b = 0; b < pixelgp; ++b) {
296 const int red = (int) (r * (255.f / (pixelgp - 1.f)));
297 const int green = (int) (g * (255.f / (pixelgp - 1.f)));
298 const int blue = (int) (b * (255.f / (pixelgp - 1.f)));
299 srcPixels[srcIndex] = SkColorSetRGB(red, green, blue);
300 ++srcIndex;
301 }
302 }
303 }
304 SkAutoTMalloc<uint32_t> dstPixels(numPixels);
305
306 // src space is identity besides CLUT
307 std::vector<SkColorSpace_A2B::Element> srcElements;
308 srcElements.push_back(SkColorSpace_A2B::Element(std::move(colorLUT)));
309 auto srcSpace = ColorSpaceXformTest::CreateA2BSpace(SkColorSpace_A2B::PCS::kXYZ,
310 std::move(srcElements));
311 // dst space is entirely identity
312 auto dstSpace = SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, SkMatrix44::I());
313 auto xform = SkColorSpaceXform::New(srcSpace.get(), dstSpace.get());
314 bool result = xform->apply(SkColorSpaceXform::kRGBA_8888_ColorFormat, dstPixels.get(),
315 SkColorSpaceXform::kRGBA_8888_ColorFormat, srcPixels.get(),
316 numPixels, kOpaque_SkAlphaType);
317 REPORTER_ASSERT(r, result);
318
319 for (int i = 0; i < numPixels; ++i) {
320 REPORTER_ASSERT(r, almost_equal(SkColorGetR(srcPixels[i]),
321 SkColorGetG(dstPixels[i])));
322 REPORTER_ASSERT(r, almost_equal(SkColorGetG(srcPixels[i]),
323 SkColorGetB(dstPixels[i])));
324 REPORTER_ASSERT(r, almost_equal(SkColorGetB(srcPixels[i]),
325 SkColorGetR(dstPixels[i])));
326 }
msarettdc27a642016-06-06 12:02:31 -0700327}
raftiasc6cc28c2016-09-29 14:31:44 -0400328
Matt Sarettc55bc9a2017-01-13 13:58:57 -0500329DEF_TEST(SkColorSpaceXform_LoadTail, r) {
Matt Sarettacdb6d32017-01-13 15:42:45 -0500330 std::unique_ptr<uint64_t[]> srcPixel(new uint64_t[1]);
Matt Sarettc55bc9a2017-01-13 13:58:57 -0500331 srcPixel[0] = 0;
332 uint32_t dstPixel;
Brian Osman10b81422017-12-14 10:27:21 -0500333 sk_sp<SkColorSpace> p3 = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
334 SkColorSpace::kDCIP3_D65_Gamut);
Matt Sarett77a7a1b2017-02-07 13:56:11 -0500335 sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
Brian Osman10b81422017-12-14 10:27:21 -0500336 std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(p3.get(), srgb.get());
Matt Sarettc55bc9a2017-01-13 13:58:57 -0500337
338 // ASAN will catch us if we read past the tail.
339 bool success = xform->apply(SkColorSpaceXform::kRGBA_8888_ColorFormat, &dstPixel,
Matt Sarettacdb6d32017-01-13 15:42:45 -0500340 SkColorSpaceXform::kRGBA_U16_BE_ColorFormat, srcPixel.get(), 1,
Matt Sarettc55bc9a2017-01-13 13:58:57 -0500341 kUnpremul_SkAlphaType);
342 REPORTER_ASSERT(r, success);
343}
344