| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "Resources.h" | 8 #include "Resources.h" |
| 9 #include "SkCodec.h" | 9 #include "SkCodec.h" |
| 10 #include "SkColorSpace.h" | 10 #include "SkColorSpace.h" |
| 11 #include "Test.h" | 11 #include "Test.h" |
| 12 | 12 |
| 13 #include "png.h" | 13 #include "png.h" |
| 14 | 14 |
| 15 static SkStreamAsset* resource(const char path[]) { | 15 static SkStreamAsset* resource(const char path[]) { |
| 16 SkString fullPath = GetResourcePath(path); | 16 SkString fullPath = GetResourcePath(path); |
| 17 return SkStream::NewFromFile(fullPath.c_str()); | 17 return SkStream::NewFromFile(fullPath.c_str()); |
| 18 } | 18 } |
| 19 | 19 |
| 20 #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_M
INOR >= 6) | |
| 21 static bool almost_equal(float a, float b) { | 20 static bool almost_equal(float a, float b) { |
| 22 return SkTAbs(a - b) < 0.0001f; | 21 return SkTAbs(a - b) < 0.001f; |
| 23 } | 22 } |
| 24 #endif | |
| 25 | 23 |
| 26 DEF_TEST(ColorSpaceParseICCProfile, r) { | 24 DEF_TEST(ColorSpaceParsePngICCProfile, r) { |
| 27 SkAutoTDelete<SkStream> stream(resource("color_wheel_with_profile.png")); | 25 SkAutoTDelete<SkStream> stream(resource("color_wheel_with_profile.png")); |
| 28 REPORTER_ASSERT(r, nullptr != stream); | 26 REPORTER_ASSERT(r, nullptr != stream); |
| 29 | 27 |
| 30 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); | 28 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); |
| 31 REPORTER_ASSERT(r, nullptr != codec); | 29 REPORTER_ASSERT(r, nullptr != codec); |
| 32 | 30 |
| 33 #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_M
INOR >= 6) | 31 #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_M
INOR >= 6) |
| 34 SkColorSpace* colorSpace = codec->getColorSpace(); | 32 SkColorSpace* colorSpace = codec->getColorSpace(); |
| 35 REPORTER_ASSERT(r, nullptr != colorSpace); | 33 REPORTER_ASSERT(r, nullptr != colorSpace); |
| 36 | 34 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 48 REPORTER_ASSERT(r, almost_equal(0.222488f, xyz.fMat[1])); | 46 REPORTER_ASSERT(r, almost_equal(0.222488f, xyz.fMat[1])); |
| 49 REPORTER_ASSERT(r, almost_equal(0.013916f, xyz.fMat[2])); | 47 REPORTER_ASSERT(r, almost_equal(0.013916f, xyz.fMat[2])); |
| 50 REPORTER_ASSERT(r, almost_equal(0.385147f, xyz.fMat[3])); | 48 REPORTER_ASSERT(r, almost_equal(0.385147f, xyz.fMat[3])); |
| 51 REPORTER_ASSERT(r, almost_equal(0.716873f, xyz.fMat[4])); | 49 REPORTER_ASSERT(r, almost_equal(0.716873f, xyz.fMat[4])); |
| 52 REPORTER_ASSERT(r, almost_equal(0.0970764f, xyz.fMat[5])); | 50 REPORTER_ASSERT(r, almost_equal(0.0970764f, xyz.fMat[5])); |
| 53 REPORTER_ASSERT(r, almost_equal(0.143066f, xyz.fMat[6])); | 51 REPORTER_ASSERT(r, almost_equal(0.143066f, xyz.fMat[6])); |
| 54 REPORTER_ASSERT(r, almost_equal(0.0606079f, xyz.fMat[7])); | 52 REPORTER_ASSERT(r, almost_equal(0.0606079f, xyz.fMat[7])); |
| 55 REPORTER_ASSERT(r, almost_equal(0.714096f, xyz.fMat[8])); | 53 REPORTER_ASSERT(r, almost_equal(0.714096f, xyz.fMat[8])); |
| 56 #endif | 54 #endif |
| 57 } | 55 } |
| 56 |
| 57 DEF_TEST(ColorSpaceParseJpegICCProfile, r) { |
| 58 SkAutoTDelete<SkStream> stream(resource("icc-v2-gbr.jpg")); |
| 59 REPORTER_ASSERT(r, nullptr != stream); |
| 60 |
| 61 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); |
| 62 REPORTER_ASSERT(r, nullptr != codec); |
| 63 |
| 64 SkColorSpace* colorSpace = codec->getColorSpace(); |
| 65 REPORTER_ASSERT(r, nullptr != colorSpace); |
| 66 |
| 67 // It's important to use almost equal here. This profile sets gamma as |
| 68 // 563 / 256, which actually comes out to about 2.19922. |
| 69 SkFloat3 gammas = colorSpace->gamma(); |
| 70 REPORTER_ASSERT(r, almost_equal(2.2f, gammas.fVec[0])); |
| 71 REPORTER_ASSERT(r, almost_equal(2.2f, gammas.fVec[1])); |
| 72 REPORTER_ASSERT(r, almost_equal(2.2f, gammas.fVec[2])); |
| 73 |
| 74 // These nine values were extracted from the color profile. Until we know a
ny |
| 75 // better, we'll assume these are the right values and test that we continue |
| 76 // to extract them properly. |
| 77 SkFloat3x3 xyz = colorSpace->xyz(); |
| 78 REPORTER_ASSERT(r, almost_equal(0.385117f, xyz.fMat[0])); |
| 79 REPORTER_ASSERT(r, almost_equal(0.716904f, xyz.fMat[1])); |
| 80 REPORTER_ASSERT(r, almost_equal(0.0970612f, xyz.fMat[2])); |
| 81 REPORTER_ASSERT(r, almost_equal(0.143051f, xyz.fMat[3])); |
| 82 REPORTER_ASSERT(r, almost_equal(0.0606079f, xyz.fMat[4])); |
| 83 REPORTER_ASSERT(r, almost_equal(0.713913f, xyz.fMat[5])); |
| 84 REPORTER_ASSERT(r, almost_equal(0.436035f, xyz.fMat[6])); |
| 85 REPORTER_ASSERT(r, almost_equal(0.222488f, xyz.fMat[7])); |
| 86 REPORTER_ASSERT(r, almost_equal(0.013916f, xyz.fMat[8])); |
| 87 } |
| OLD | NEW |