Index: tests/ColorSpaceTest.cpp |
diff --git a/tests/ColorSpaceTest.cpp b/tests/ColorSpaceTest.cpp |
index da69ea7e0f6e76546f487fb44dfff139d4a7acea..b26cec20aec254f461417efc6f64c0c14c6591fe 100644 |
--- a/tests/ColorSpaceTest.cpp |
+++ b/tests/ColorSpaceTest.cpp |
@@ -46,10 +46,11 @@ const float g_sRGB_XYZ[] = { 0.4358f, 0.2224f, 0.0139f, // R |
0.3853f, 0.7170f, 0.0971f, // G |
0.1430f, 0.0606f, 0.7139f }; // B |
+const float g_sRGB_gamma[] = { 2.2f, 2.2f, 2.2f }; |
+ |
DEF_TEST(ColorSpace_sRGB, r) { |
- const float srgb_gamma[] = { 2.2f, 2.2f, 2.2f }; |
test_space(r, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).get(), |
- g_sRGB_XYZ, &g_sRGB_XYZ[3], &g_sRGB_XYZ[6], srgb_gamma); |
+ g_sRGB_XYZ, &g_sRGB_XYZ[3], &g_sRGB_XYZ[6], g_sRGB_gamma); |
} |
@@ -72,11 +73,7 @@ DEF_TEST(ColorSpaceParsePngICCProfile, r) { |
SkColorSpace* colorSpace = codec->getColorSpace(); |
REPORTER_ASSERT(r, nullptr != colorSpace); |
- const float red[] = { 0.436066f, 0.222488f, 0.013916f }; |
- const float green[] = { 0.385147f, 0.716873f, 0.0970764f }; |
- const float blue[] = { 0.143066f, 0.0606079f, 0.714096f }; |
- const float gamma[] = { 2.2f, 2.2f, 2.2f }; |
- test_space(r, colorSpace, red, green, blue, gamma); |
+ test_space(r, colorSpace, &g_sRGB_XYZ[0], &g_sRGB_XYZ[3], &g_sRGB_XYZ[6], g_sRGB_gamma); |
#endif |
} |
@@ -99,24 +96,45 @@ DEF_TEST(ColorSpaceParseJpegICCProfile, r) { |
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 gamma[] = { 2.2f, 2.2f, 2.2f }; |
- test_space(r, colorSpace, red, green, blue, gamma); |
+ test_space(r, colorSpace, red, green, blue, g_sRGB_gamma); |
} |
DEF_TEST(ColorSpaceSRGBCompare, r) { |
// Create an sRGB color space by name |
sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
- |
// Create an sRGB color space by value |
SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); |
- float sRGBGammas[3] = { 2.2f, 2.2f, 2.2f }; |
srgbToxyzD50.set3x3ColMajorf(g_sRGB_XYZ); |
- sk_sp<SkColorSpace> rgbColorSpace = SkColorSpace::NewRGB(sRGBGammas, srgbToxyzD50); |
- REPORTER_ASSERT(r, namedColorSpace == namedColorSpace); |
+ sk_sp<SkColorSpace> rgbColorSpace = SkColorSpace::NewRGB(g_sRGB_gamma, srgbToxyzD50); |
+ REPORTER_ASSERT(r, rgbColorSpace == namedColorSpace); |
// Change a single value from the sRGB matrix |
srgbToxyzD50.set(2, 2, 0.5f); |
- sk_sp<SkColorSpace> strangeColorSpace = SkColorSpace::NewRGB(sRGBGammas, srgbToxyzD50); |
+ sk_sp<SkColorSpace> strangeColorSpace = SkColorSpace::NewRGB(g_sRGB_gamma, srgbToxyzD50); |
REPORTER_ASSERT(r, strangeColorSpace != namedColorSpace); |
} |
+ |
+DEF_TEST(ColorSpaceWriteICC, r) { |
+ // Test writing a new ICC profile |
+ sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
+ sk_sp<SkData> namedData = as_CSB(namedColorSpace)->writeToICC(); |
+ sk_sp<SkColorSpace> iccColorSpace = SkColorSpace::NewICC(namedData->data(), namedData->size()); |
+ test_space(r, iccColorSpace.get(), g_sRGB_XYZ, &g_sRGB_XYZ[3], &g_sRGB_XYZ[6], g_sRGB_gamma); |
+ REPORTER_ASSERT(r, iccColorSpace == namedColorSpace); |
+ |
+ // Test saving the original ICC data |
+ sk_sp<SkData> monitorData = SkData::MakeFromFileName( |
+ GetResourcePath("monitor_profiles/HP_ZR30w.icc").c_str()); |
+ REPORTER_ASSERT(r, monitorData); |
+ if (!monitorData) { |
+ return; |
scroggo
2016/05/24 19:12:20
This should probably fail the test or print someth
msarett
2016/05/24 19:14:27
It should fail the statement above "REPORTER_ASSER
scroggo
2016/05/24 19:14:59
D'oh! Yes it should. Nvm...
|
+ } |
+ sk_sp<SkColorSpace> monitorSpace = SkColorSpace::NewICC(monitorData->data(), |
+ monitorData->size()); |
+ sk_sp<SkData> newMonitorData = as_CSB(monitorSpace)->writeToICC(); |
+ sk_sp<SkColorSpace> newMonitorSpace = SkColorSpace::NewICC(newMonitorData->data(), |
+ newMonitorData->size()); |
+ REPORTER_ASSERT(r, monitorSpace->xyz() == newMonitorSpace->xyz()); |
+ REPORTER_ASSERT(r, as_CSB(monitorSpace)->gammas() == as_CSB(newMonitorSpace)->gammas()); |
+} |