Chromium Code Reviews| Index: tests/ColorSpaceTest.cpp |
| diff --git a/tests/ColorSpaceTest.cpp b/tests/ColorSpaceTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a8903656c99cc0b35c192b08b73d25b71831a006 |
| --- /dev/null |
| +++ b/tests/ColorSpaceTest.cpp |
| @@ -0,0 +1,47 @@ |
| +/* |
| + * 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); |
| + |
| + SkFloat3 gammas = colorSpace->gamma(); |
| + REPORTER_ASSERT(r, 2.2f == gammas.fVec[0]); |
|
reed1
2016/03/02 01:29:54
interesting that you don't need/use almost_equal h
msarett
2016/03/02 14:09:40
I think we are lucky. Maybe we should use almost
|
| + REPORTER_ASSERT(r, 2.2f == gammas.fVec[1]); |
| + REPORTER_ASSERT(r, 2.2f == gammas.fVec[2]); |
| + |
| + SkFloat3x3 xyz = colorSpace->xyz(); |
| + REPORTER_ASSERT(r, almost_equal(0.436066f, xyz.fMat[0])); |
|
reed1
2016/03/02 01:29:54
// We got these 9 values from ... ?
msarett
2016/03/02 14:09:41
I printed out the profile when extracting it from
|
| + 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])); |
| +} |