Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Unified Diff: tests/ColorSpaceTest.cpp

Issue 1943833002: return 4x4 matrix from SkColorSpace (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix redirect header Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/utils/SkMatrix44.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ColorSpaceTest.cpp
diff --git a/tests/ColorSpaceTest.cpp b/tests/ColorSpaceTest.cpp
index e5ecbc83462c610b66d7e03bfbef35b168548737..5ae5a648a0cc20c81af505cd4a27096fe147685b 100644
--- a/tests/ColorSpaceTest.cpp
+++ b/tests/ColorSpaceTest.cpp
@@ -12,15 +12,50 @@
#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,
+ const float red[], const float green[], const float blue[],
+ const float expectedGammas[]) {
+#ifdef SK_DEBUG
+ const SkColorSpace::SkGammas& gammas = space->gammas();
+ REPORTER_ASSERT(r, almost_equal(expectedGammas[0], gammas.red()));
+ REPORTER_ASSERT(r, almost_equal(expectedGammas[1], gammas.green()));
+ REPORTER_ASSERT(r, almost_equal(expectedGammas[2], gammas.blue()));
+#endif
+
+ SkMatrix44 mat = space->xyz();
+ const float src[] = {
+ 1, 0, 0, 1,
+ 0, 1, 0, 1,
+ 0, 0, 1, 1,
+ };
+ float dst[4];
+ for (int i = 0; i < 3; ++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]));
+ }
+}
+
+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,27 +70,11 @@ DEF_TEST(ColorSpaceParsePngICCProfile, r) {
SkColorSpace* colorSpace = codec->getColorSpace();
REPORTER_ASSERT(r, nullptr != colorSpace);
- // The color profile that we have extracted has represents gamma with a lookup table.
- // So we expect the gamma value to be zero.
-#ifdef SK_DEBUG
- const SkColorSpace::SkGammas& gammas = colorSpace->gammas();
- REPORTER_ASSERT(r, 0.0f == gammas.red());
- REPORTER_ASSERT(r, 0.0f == gammas.green());
- REPORTER_ASSERT(r, 0.0f == gammas.blue());
-#endif
-
- // 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[] = { 0, 0, 0 }; // table-based gamma returns 0 from this its float-getter
+ test_space(r, colorSpace, red, green, blue, gamma);
#endif
}
@@ -75,26 +94,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.
-#ifdef SK_DEBUG
- const SkColorSpace::SkGammas& gammas = colorSpace->gammas();
- REPORTER_ASSERT(r, almost_equal(2.2f, gammas.red()));
- REPORTER_ASSERT(r, almost_equal(2.2f, gammas.green()));
- REPORTER_ASSERT(r, almost_equal(2.2f, gammas.blue()));
-#endif
-
- // 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);
}
« no previous file with comments | « src/utils/SkMatrix44.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698