DEF_TEST(ColorSpace_Primaries, r) { // sRGB primaries (D65) 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(SkNamedTransferFn::kSRGB, srgbToXYZ); REPORTER_ASSERT(r, SkColorSpace::MakeSRGB() == space); // ProPhoto (D50) SkColorSpacePrimaries proPhoto; proPhoto.fRX = 0.7347f; proPhoto.fRY = 0.2653f; proPhoto.fGX = 0.1596f; proPhoto.fGY = 0.8404f; proPhoto.fBX = 0.0366f; proPhoto.fBY = 0.0001f; proPhoto.fWX = 0.34567f; proPhoto.fWY = 0.35850f; 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) SkColorSpacePrimaries ntsc; ntsc.fRX = 0.67f; ntsc.fRY = 0.33f; ntsc.fGX = 0.21f; ntsc.fGY = 0.71f; ntsc.fBX = 0.14f; ntsc.fBY = 0.08f; ntsc.fWX = 0.31006f; ntsc.fWY = 0.31616f; 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) SkColorSpacePrimaries p3; p3.fRX = 0.680f; p3.fRY = 0.320f; p3.fGX = 0.265f; p3.fGY = 0.690f; p3.fBX = 0.150f; p3.fBY = 0.060f; p3.fWX = 0.3127f; p3.fWY = 0.3290f; space = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kDCIP3); skcms_Matrix3x3 reference; SkAssertResult(space->toXYZD50(&reference)); check_primaries(r, p3, reference); // Rec 2020 (D65) SkColorSpacePrimaries rec2020; rec2020.fRX = 0.708f; rec2020.fRY = 0.292f; rec2020.fGX = 0.170f; rec2020.fGY = 0.797f; rec2020.fBX = 0.131f; rec2020.fBY = 0.046f; rec2020.fWX = 0.3127f; rec2020.fWY = 0.3290f; space = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kRec2020); SkAssertResult(space->toXYZD50(&reference)); check_primaries(r, rec2020, reference); }
bool SkColorSpacePrimaries::toXYZD50(skcms_Matrix3x3* toXYZ_D50) const { return skcms_PrimariesToXYZD50(fRX, fRY, fGX, fGY, fBX, fBY, fWX, fWY, toXYZ_D50); }