Ravi Mistry | 113d05f | 2016-12-17 01:31:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "Resources.h" |
| 9 | #include "SkColorSpace.h" |
| 10 | #include "SkData.h" |
| 11 | #include "SkICC.h" |
| 12 | #include "SkMatrix44.h" |
| 13 | #include "Test.h" |
| 14 | |
| 15 | static bool almost_equal(float a, float b) { |
| 16 | return SkTAbs(a - b) < 0.001f; |
| 17 | } |
| 18 | |
| 19 | static inline void test_to_xyz_d50(skiatest::Reporter* r, SkICC* icc, bool shouldSucceed, |
| 20 | const float* reference) { |
Matt Sarett | d4b9c35 | 2016-12-18 13:49:43 -0500 | [diff] [blame^] | 21 | SkMatrix44 result(SkMatrix44::kUninitialized_Constructor); |
Ravi Mistry | 113d05f | 2016-12-17 01:31:03 +0000 | [diff] [blame] | 22 | REPORTER_ASSERT(r, shouldSucceed == icc->toXYZD50(&result)); |
| 23 | if (shouldSucceed) { |
| 24 | float resultVals[16]; |
| 25 | result.asColMajorf(resultVals); |
| 26 | for (int i = 0; i < 16; i++) { |
| 27 | REPORTER_ASSERT(r, almost_equal(resultVals[i], reference[i])); |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | DEF_TEST(ICC_ToXYZD50, r) { |
| 33 | const float z30Reference[16] = { |
| 34 | 0.59825f, 0.27103f, 0.00603f, 0.0f, 0.22243f, 0.67447f, 0.07368f, 0.0f, 0.14352f, 0.05449f, |
| 35 | 0.74519f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, |
| 36 | }; |
| 37 | |
| 38 | sk_sp<SkData> data = SkData::MakeFromFileName( |
| 39 | GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str()); |
| 40 | sk_sp<SkICC> z30 = SkICC::Make(data->data(), data->size()); |
| 41 | test_to_xyz_d50(r, z30.get(), true, z30Reference); |
| 42 | |
| 43 | const float z32Reference[16] = { |
| 44 | 0.61583f, 0.28789f, 0.00513f, 0.0f, 0.20428f, 0.66972f, 0.06609f, 0.0f, 0.14409f, 0.04237f, |
| 45 | 0.75368f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, |
| 46 | }; |
| 47 | |
| 48 | data = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32x.icc").c_str()); |
| 49 | sk_sp<SkICC> z32 = SkICC::Make(data->data(), data->size()); |
| 50 | test_to_xyz_d50(r, z32.get(), true, z32Reference); |
| 51 | |
| 52 | data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLeft.icc").c_str()); |
| 53 | sk_sp<SkICC> upperLeft = SkICC::Make(data->data(), data->size()); |
| 54 | test_to_xyz_d50(r, upperLeft.get(), false, z32Reference); |
| 55 | |
| 56 | data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRight.icc").c_str()); |
| 57 | sk_sp<SkICC> upperRight = SkICC::Make(data->data(), data->size()); |
| 58 | test_to_xyz_d50(r, upperRight.get(), false, z32Reference); |
| 59 | } |
| 60 | |
| 61 | static inline void test_is_numerical_transfer_fn(skiatest::Reporter* r, SkICC* icc, |
| 62 | bool shouldSucceed, |
| 63 | const SkColorSpaceTransferFn& reference) { |
| 64 | SkColorSpaceTransferFn result; |
| 65 | REPORTER_ASSERT(r, shouldSucceed == icc->isNumericalTransferFn(&result)); |
| 66 | if (shouldSucceed) { |
| 67 | REPORTER_ASSERT(r, 0 == memcmp(&result, &reference, sizeof(SkColorSpaceTransferFn))); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | DEF_TEST(ICC_IsNumericalTransferFn, r) { |
| 72 | SkColorSpaceTransferFn referenceFn; |
| 73 | referenceFn.fA = 1.0f; |
| 74 | referenceFn.fB = 0.0f; |
| 75 | referenceFn.fC = 0.0f; |
| 76 | referenceFn.fD = 0.0f; |
| 77 | referenceFn.fE = 0.0f; |
| 78 | referenceFn.fF = 0.0f; |
| 79 | referenceFn.fG = 2.2f; |
| 80 | |
| 81 | sk_sp<SkData> data = SkData::MakeFromFileName( |
| 82 | GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str()); |
| 83 | sk_sp<SkICC> z30 = SkICC::Make(data->data(), data->size()); |
| 84 | test_is_numerical_transfer_fn(r, z30.get(), true, referenceFn); |
| 85 | |
| 86 | data = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32x.icc").c_str()); |
| 87 | sk_sp<SkICC> z32 = SkICC::Make(data->data(), data->size()); |
| 88 | test_is_numerical_transfer_fn(r, z32.get(), true, referenceFn); |
| 89 | |
| 90 | data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLeft.icc").c_str()); |
| 91 | sk_sp<SkICC> upperLeft = SkICC::Make(data->data(), data->size()); |
| 92 | test_is_numerical_transfer_fn(r, upperLeft.get(), false, referenceFn); |
| 93 | |
| 94 | data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRight.icc").c_str()); |
| 95 | sk_sp<SkICC> upperRight = SkICC::Make(data->data(), data->size()); |
| 96 | test_is_numerical_transfer_fn(r, upperRight.get(), false, referenceFn); |
| 97 | } |