Chromium Code Reviews| Index: tests/ColorSpaceTest.cpp |
| diff --git a/tests/ColorSpaceTest.cpp b/tests/ColorSpaceTest.cpp |
| index 313eed86f118a9b9632f4c514baa5e21813dc801..955dbcd1a7fefb24fa628b807f1ca110c1f90dc0 100644 |
| --- a/tests/ColorSpaceTest.cpp |
| +++ b/tests/ColorSpaceTest.cpp |
| @@ -12,15 +12,48 @@ |
| #include "png.h" |
| +static bool almost_equal(float a, float b) { |
| + return SkTAbs(a - b) < 0.001f; |
| +} |
| + |
| +static void test_space(skiatest::Reporter* r, SkColorSpace* space, |
|
msarett
2016/05/03 13:01:13
Nice!
|
| + const float red[], const float green[], const float blue[], |
| + const float gamma[]) { |
| + SkMatrix44 mat = space->xyz(); |
| + |
| + const float src[] = { |
| + 1, 0, 0, 1, |
| + 0, 1, 0, 1, |
| + 0, 0, 1, 1, |
| + }; |
| + float dst[4]; |
| + SkDebugf("\n"); |
|
msarett
2016/05/03 13:01:13
Delete SkDebugf statements?
reed1
2016/05/03 17:44:51
Done.
|
| + for (int i = 0; i < 3; ++i) { |
| + REPORTER_ASSERT(r, almost_equal(gamma[i], space->gamma().fVec[i])); |
| + |
| + mat.mapScalars(&src[i*4], dst); |
| + REPORTER_ASSERT(r, almost_equal(red[i], dst[0])); |
| + REPORTER_ASSERT(r, almost_equal(green[i], dst[1])); |
| + REPORTER_ASSERT(r, almost_equal(blue[i], dst[2])); |
| +// SkDebugf("%g %g %g\n", dst[0], dst[1], dst[2]); |
| + } |
| +} |
| + |
| +DEF_TEST(ColorSpace_sRGB, r) { |
| + const float srgb_r[] = { 0.4358f, 0.2224f, 0.0139f }; |
| + const float srgb_g[] = { 0.3853f, 0.7170f, 0.0971f }; |
| + const float srgb_b[] = { 0.1430f, 0.0606f, 0.7139f }; |
| + const float srgb_gamma[] = { 2.2f, 2.2f, 2.2f }; |
| + test_space(r, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).get(), |
| + srgb_r, srgb_g, srgb_b, srgb_gamma); |
| + |
| +} |
| + |
| static SkStreamAsset* resource(const char path[]) { |
| SkString fullPath = GetResourcePath(path); |
| return SkStream::NewFromFile(fullPath.c_str()); |
| } |
| -static bool almost_equal(float a, float b) { |
| - return SkTAbs(a - b) < 0.001f; |
| -} |
| - |
| DEF_TEST(ColorSpaceParsePngICCProfile, r) { |
| SkAutoTDelete<SkStream> stream(resource("color_wheel_with_profile.png")); |
| REPORTER_ASSERT(r, nullptr != stream); |
| @@ -35,25 +68,11 @@ DEF_TEST(ColorSpaceParsePngICCProfile, r) { |
| SkColorSpace* colorSpace = codec->getColorSpace(); |
| REPORTER_ASSERT(r, nullptr != colorSpace); |
| - // No need to use almost equal here. The color profile that we have extracted |
| - // actually has a table of gammas. And our current implementation guesses 2.2f. |
| - SkFloat3 gammas = colorSpace->gamma(); |
| - REPORTER_ASSERT(r, 2.2f == gammas.fVec[0]); |
| - REPORTER_ASSERT(r, 2.2f == gammas.fVec[1]); |
| - REPORTER_ASSERT(r, 2.2f == gammas.fVec[2]); |
| - |
| - // These nine values were extracted from the color profile in isolation (before |
| - // we embedded it in the png). Here we check that we still extract the same values. |
| - SkFloat3x3 xyz = colorSpace->xyz(); |
| - REPORTER_ASSERT(r, almost_equal(0.436066f, xyz.fMat[0])); |
| - REPORTER_ASSERT(r, almost_equal(0.222488f, xyz.fMat[1])); |
| - REPORTER_ASSERT(r, almost_equal(0.013916f, xyz.fMat[2])); |
| - REPORTER_ASSERT(r, almost_equal(0.385147f, xyz.fMat[3])); |
| - REPORTER_ASSERT(r, almost_equal(0.716873f, xyz.fMat[4])); |
| - REPORTER_ASSERT(r, almost_equal(0.0970764f, xyz.fMat[5])); |
| - REPORTER_ASSERT(r, almost_equal(0.143066f, xyz.fMat[6])); |
| - REPORTER_ASSERT(r, almost_equal(0.0606079f, xyz.fMat[7])); |
| - REPORTER_ASSERT(r, almost_equal(0.714096f, xyz.fMat[8])); |
| + 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); |
| #endif |
| } |
| @@ -73,24 +92,9 @@ DEF_TEST(ColorSpaceParseJpegICCProfile, r) { |
| SkColorSpace* colorSpace = codec->getColorSpace(); |
| REPORTER_ASSERT(r, nullptr != colorSpace); |
| - // It's important to use almost equal here. This profile sets gamma as |
| - // 563 / 256, which actually comes out to about 2.19922. |
| - SkFloat3 gammas = colorSpace->gamma(); |
| - REPORTER_ASSERT(r, almost_equal(2.2f, gammas.fVec[0])); |
| - REPORTER_ASSERT(r, almost_equal(2.2f, gammas.fVec[1])); |
| - REPORTER_ASSERT(r, almost_equal(2.2f, gammas.fVec[2])); |
| - |
| - // These nine values were extracted from the color profile. Until we know any |
| - // better, we'll assume these are the right values and test that we continue |
| - // to extract them properly. |
| - SkFloat3x3 xyz = colorSpace->xyz(); |
| - REPORTER_ASSERT(r, almost_equal(0.385117f, xyz.fMat[0])); |
| - REPORTER_ASSERT(r, almost_equal(0.716904f, xyz.fMat[1])); |
| - REPORTER_ASSERT(r, almost_equal(0.0970612f, xyz.fMat[2])); |
| - REPORTER_ASSERT(r, almost_equal(0.143051f, xyz.fMat[3])); |
| - REPORTER_ASSERT(r, almost_equal(0.0606079f, xyz.fMat[4])); |
| - REPORTER_ASSERT(r, almost_equal(0.713913f, xyz.fMat[5])); |
| - REPORTER_ASSERT(r, almost_equal(0.436035f, xyz.fMat[6])); |
| - REPORTER_ASSERT(r, almost_equal(0.222488f, xyz.fMat[7])); |
| - REPORTER_ASSERT(r, almost_equal(0.013916f, xyz.fMat[8])); |
| + 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); |
| } |