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 | |
Mike Klein | 5b58b7c | 2018-05-22 13:47:52 +0000 | [diff] [blame] | 8 | #include "SkTypes.h" |
Ravi Mistry | 113d05f | 2016-12-17 01:31:03 +0000 | [diff] [blame] | 9 | |
Brian Osman | 8dc68c6 | 2018-05-30 12:57:45 -0400 | [diff] [blame] | 10 | #include "Resources.h" |
| 11 | #include "SkColorSpacePriv.h" |
| 12 | #include "SkICC.h" |
| 13 | #include "SkString.h" |
| 14 | #include "Test.h" |
| 15 | #include "../third_party/skcms/skcms.h" |
Ravi Mistry | 113d05f | 2016-12-17 01:31:03 +0000 | [diff] [blame] | 16 | |
Brian Osman | 8dc68c6 | 2018-05-30 12:57:45 -0400 | [diff] [blame] | 17 | DEF_TEST(WriteICCProfile, r) { |
| 18 | auto adobeRGB = SkColorSpace::MakeRGB(g2Dot2_TransferFn, SkColorSpace::kAdobeRGB_Gamut); |
Mike Klein | 5b58b7c | 2018-05-22 13:47:52 +0000 | [diff] [blame] | 19 | |
Brian Osman | 8dc68c6 | 2018-05-30 12:57:45 -0400 | [diff] [blame] | 20 | struct { |
| 21 | SkColorSpaceTransferFn fn; |
| 22 | const float* toXYZD50; |
| 23 | const char* desc; |
| 24 | sk_sp<SkColorSpace> want; |
| 25 | } tests[] = { |
| 26 | {g2Dot2_TransferFn, gAdobeRGB_toXYZD50, "AdobeRGB", adobeRGB}, |
| 27 | { gSRGB_TransferFn, gSRGB_toXYZD50, "sRGB", SkColorSpace::MakeSRGB()}, |
| 28 | }; |
Mike Klein | 5b58b7c | 2018-05-22 13:47:52 +0000 | [diff] [blame] | 29 | |
Brian Osman | 8dc68c6 | 2018-05-30 12:57:45 -0400 | [diff] [blame] | 30 | for (auto test : tests) { |
| 31 | sk_sp<SkData> profile = SkWriteICCProfile(test.fn, test.toXYZD50); |
| 32 | REPORTER_ASSERT(r, profile); |
Mike Klein | 5b58b7c | 2018-05-22 13:47:52 +0000 | [diff] [blame] | 33 | |
Brian Osman | 8dc68c6 | 2018-05-30 12:57:45 -0400 | [diff] [blame] | 34 | skcms_ICCProfile parsed; |
| 35 | REPORTER_ASSERT(r, skcms_Parse(profile->data(), profile->size(), &parsed)); |
Mike Klein | 5b58b7c | 2018-05-22 13:47:52 +0000 | [diff] [blame] | 36 | |
Brian Osman | 8dc68c6 | 2018-05-30 12:57:45 -0400 | [diff] [blame] | 37 | sk_sp<SkColorSpace> got = SkColorSpace::Make(parsed); |
| 38 | REPORTER_ASSERT(r, got); |
| 39 | REPORTER_ASSERT(r, SkColorSpace::Equals(got.get(), test.want.get())); |
Mike Klein | 5b58b7c | 2018-05-22 13:47:52 +0000 | [diff] [blame] | 40 | |
Brian Osman | 8dc68c6 | 2018-05-30 12:57:45 -0400 | [diff] [blame] | 41 | skcms_ICCTag desc; |
| 42 | REPORTER_ASSERT(r, skcms_GetTagBySignature(&parsed, |
| 43 | SkSetFourByteTag('d','e','s','c'), |
| 44 | &desc)); |
Mike Klein | 5b58b7c | 2018-05-22 13:47:52 +0000 | [diff] [blame] | 45 | |
Brian Osman | 8dc68c6 | 2018-05-30 12:57:45 -0400 | [diff] [blame] | 46 | // Rather than really carefully break down the 'desc' tag, |
| 47 | // just check our expected description is somewhere in there (as big-endian UTF-16). |
| 48 | uint8_t big_endian_utf16[16]; |
| 49 | for (size_t i = 0; i < strlen(test.desc); i++) { |
| 50 | big_endian_utf16[2*i+0] = 0; |
| 51 | big_endian_utf16[2*i+1] = test.desc[i]; |
Ravi Mistry | 113d05f | 2016-12-17 01:31:03 +0000 | [diff] [blame] | 52 | } |
Brian Osman | 8dc68c6 | 2018-05-30 12:57:45 -0400 | [diff] [blame] | 53 | |
| 54 | SkString haystack((const char*)desc.buf, desc.size), |
| 55 | needle ((const char*)big_endian_utf16, 2*strlen(test.desc)); |
| 56 | REPORTER_ASSERT(r, haystack.contains(needle.c_str())); |
Ravi Mistry | 113d05f | 2016-12-17 01:31:03 +0000 | [diff] [blame] | 57 | } |
Brian Osman | 8dc68c6 | 2018-05-30 12:57:45 -0400 | [diff] [blame] | 58 | } |
Ravi Mistry | 113d05f | 2016-12-17 01:31:03 +0000 | [diff] [blame] | 59 | |
Brian Osman | 8dc68c6 | 2018-05-30 12:57:45 -0400 | [diff] [blame] | 60 | DEF_TEST(AdobeRGB, r) { |
| 61 | if (sk_sp<SkData> profile = GetResourceAsData("icc_profiles/AdobeRGB1998.icc")) { |
| 62 | skcms_ICCProfile parsed; |
| 63 | REPORTER_ASSERT(r, skcms_Parse(profile->data(), profile->size(), &parsed)); |
Ravi Mistry | 113d05f | 2016-12-17 01:31:03 +0000 | [diff] [blame] | 64 | |
Brian Osman | 8dc68c6 | 2018-05-30 12:57:45 -0400 | [diff] [blame] | 65 | auto got = SkColorSpace::Make(parsed); |
| 66 | auto want = SkColorSpace::MakeRGB(g2Dot2_TransferFn, SkColorSpace::kAdobeRGB_Gamut); |
| 67 | REPORTER_ASSERT(r, SkColorSpace::Equals(got.get(), want.get())); |
Matt Sarett | 1bfcf88 | 2016-12-19 18:37:34 -0500 | [diff] [blame] | 68 | } |
Brian Osman | 8dc68c6 | 2018-05-30 12:57:45 -0400 | [diff] [blame] | 69 | } |