diff options
author | msarett <msarett@google.com> | 2016-03-04 13:27:35 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-04 13:27:35 -0800 |
commit | 6a738217eaeb9aed45a07efdfc1ae52372430d87 (patch) | |
tree | 2e72d8f573fd4911ecd0290aa6ce8a4106e3b296 /tests/ColorSpaceTest.cpp | |
parent | 97220199d46cb3b885303878a30b311c628a9337 (diff) |
Set SkColorSpace object for PNGs and parse ICC profiles
Code for ICC profile parsing adapted from:
https://codereview.chromium.org/1707033002/
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1726823002
Review URL: https://codereview.chromium.org/1726823002
Diffstat (limited to 'tests/ColorSpaceTest.cpp')
-rw-r--r-- | tests/ColorSpaceTest.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/ColorSpaceTest.cpp b/tests/ColorSpaceTest.cpp new file mode 100644 index 0000000000..cf7560228f --- /dev/null +++ b/tests/ColorSpaceTest.cpp @@ -0,0 +1,51 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "Resources.h" +#include "SkCodec.h" +#include "SkColorSpace.h" +#include "Test.h" + +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.0001f; +} + +DEF_TEST(ColorSpaceParseICCProfile, r) { + SkAutoTDelete<SkStream> stream(resource("color_wheel_with_profile.png")); + REPORTER_ASSERT(r, nullptr != stream); + + SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); + REPORTER_ASSERT(r, nullptr != codec); + + 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])); +} |