Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: tests/ColorSpaceTest.cpp

Issue 2318663003: Delete SkColorSpace::gammaNamed() from public API (Closed) Base URL: https://skia.googlesource.com/skia.git@delunknownnamed
Patch Set: Rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/image/SkSurface_Raster.cpp ('k') | tests/ColorSpaceXformTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkColorSpace_Base.h" 11 #include "SkColorSpace_Base.h"
12 #include "Test.h" 12 #include "Test.h"
13 13
14 #include "png.h" 14 #include "png.h"
15 15
16 static bool almost_equal(float a, float b) { 16 static bool almost_equal(float a, float b) {
17 return SkTAbs(a - b) < 0.001f; 17 return SkTAbs(a - b) < 0.001f;
18 } 18 }
19 19
20 static void test_space(skiatest::Reporter* r, SkColorSpace* space, 20 static void test_space(skiatest::Reporter* r, SkColorSpace* space,
21 const float red[], const float green[], const float blue[ ], 21 const float red[], const float green[], const float blue[ ],
22 const SkColorSpace::GammaNamed expectedGamma) { 22 const SkGammaNamed expectedGamma) {
23 23
24 REPORTER_ASSERT(r, nullptr != space); 24 REPORTER_ASSERT(r, nullptr != space);
25 REPORTER_ASSERT(r, expectedGamma == space->gammaNamed()); 25 REPORTER_ASSERT(r, expectedGamma == as_CSB(space)->gammaNamed());
26 26
27 const SkMatrix44& mat = space->xyz(); 27 const SkMatrix44& mat = space->xyz();
28 const float src[] = { 28 const float src[] = {
29 1, 0, 0, 1, 29 1, 0, 0, 1,
30 0, 1, 0, 1, 30 0, 1, 0, 1,
31 0, 0, 1, 1, 31 0, 0, 1, 1,
32 }; 32 };
33 float dst[4]; 33 float dst[4];
34 for (int i = 0; i < 3; ++i) { 34 for (int i = 0; i < 3; ++i) {
35 mat.mapScalars(&src[i*4], dst); 35 mat.mapScalars(&src[i*4], dst);
36 REPORTER_ASSERT(r, almost_equal(red[i], dst[0])); 36 REPORTER_ASSERT(r, almost_equal(red[i], dst[0]));
37 REPORTER_ASSERT(r, almost_equal(green[i], dst[1])); 37 REPORTER_ASSERT(r, almost_equal(green[i], dst[1]));
38 REPORTER_ASSERT(r, almost_equal(blue[i], dst[2])); 38 REPORTER_ASSERT(r, almost_equal(blue[i], dst[2]));
39 } 39 }
40 } 40 }
41 41
42 static SkStreamAsset* resource(const char path[]) { 42 static SkStreamAsset* resource(const char path[]) {
43 SkString fullPath = GetResourcePath(path); 43 SkString fullPath = GetResourcePath(path);
44 return SkStream::NewFromFile(fullPath.c_str()); 44 return SkStream::NewFromFile(fullPath.c_str());
45 } 45 }
46 46
47 static void test_path(skiatest::Reporter* r, const char* path, 47 static void test_path(skiatest::Reporter* r, const char* path,
48 const float red[], const float green[], const float blue[] , 48 const float red[], const float green[], const float blue[] ,
49 const SkColorSpace::GammaNamed expectedGamma) { 49 const SkGammaNamed expectedGamma) {
50 SkAutoTDelete<SkStream> stream(resource(path)); 50 SkAutoTDelete<SkStream> stream(resource(path));
51 REPORTER_ASSERT(r, nullptr != stream); 51 REPORTER_ASSERT(r, nullptr != stream);
52 if (!stream) { 52 if (!stream) {
53 return; 53 return;
54 } 54 }
55 55
56 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); 56 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
57 REPORTER_ASSERT(r, nullptr != codec); 57 REPORTER_ASSERT(r, nullptr != codec);
58 if (!codec) { 58 if (!codec) {
59 return; 59 return;
60 } 60 }
61 61
62 SkColorSpace* colorSpace = codec->getInfo().colorSpace(); 62 SkColorSpace* colorSpace = codec->getInfo().colorSpace();
63 test_space(r, colorSpace, red, green, blue, expectedGamma); 63 test_space(r, colorSpace, red, green, blue, expectedGamma);
64 } 64 }
65 65
66 const float g_sRGB_XYZ[] = { 0.4358f, 0.2224f, 0.0139f, // R 66 const float g_sRGB_XYZ[] = { 0.4358f, 0.2224f, 0.0139f, // R
67 0.3853f, 0.7170f, 0.0971f, // G 67 0.3853f, 0.7170f, 0.0971f, // G
68 0.1430f, 0.0606f, 0.7139f }; // B 68 0.1430f, 0.0606f, 0.7139f }; // B
69 69
70 DEF_TEST(ColorSpace_sRGB, r) { 70 DEF_TEST(ColorSpace_sRGB, r) {
71 test_space(r, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).get(), 71 test_space(r, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).get(),
72 g_sRGB_XYZ, &g_sRGB_XYZ[3], &g_sRGB_XYZ[6], SkColorSpace::kSRGB_G ammaNamed); 72 g_sRGB_XYZ, &g_sRGB_XYZ[3], &g_sRGB_XYZ[6], kSRGB_SkGammaNamed);
73 73
74 } 74 }
75 75
76 DEF_TEST(ColorSpaceParseICCProfiles, r) { 76 DEF_TEST(ColorSpaceParseICCProfiles, r) {
77 77
78 #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_M INOR >= 6) 78 #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_M INOR >= 6)
79 test_path(r, "color_wheel_with_profile.png", &g_sRGB_XYZ[0], &g_sRGB_XYZ[3], &g_sRGB_XYZ[6], 79 test_path(r, "color_wheel_with_profile.png", &g_sRGB_XYZ[0], &g_sRGB_XYZ[3], &g_sRGB_XYZ[6],
80 SkColorSpace::kSRGB_GammaNamed); 80 kSRGB_SkGammaNamed);
81 #endif 81 #endif
82 82
83 const float red[] = { 0.385117f, 0.716904f, 0.0970612f }; 83 const float red[] = { 0.385117f, 0.716904f, 0.0970612f };
84 const float green[] = { 0.143051f, 0.0606079f, 0.713913f }; 84 const float green[] = { 0.143051f, 0.0606079f, 0.713913f };
85 const float blue[] = { 0.436035f, 0.222488f, 0.013916f }; 85 const float blue[] = { 0.436035f, 0.222488f, 0.013916f };
86 test_path(r, "icc-v2-gbr.jpg", red, green, blue, SkColorSpace::k2Dot2Curve_G ammaNamed); 86 test_path(r, "icc-v2-gbr.jpg", red, green, blue, k2Dot2Curve_SkGammaNamed);
87 87
88 test_path(r, "webp-color-profile-crash.webp", 88 test_path(r, "webp-color-profile-crash.webp",
89 red, green, blue, SkColorSpace::kNonStandard_GammaNamed); 89 red, green, blue, kNonStandard_SkGammaNamed);
90 test_path(r, "webp-color-profile-lossless.webp", 90 test_path(r, "webp-color-profile-lossless.webp",
91 red, green, blue, SkColorSpace::kNonStandard_GammaNamed); 91 red, green, blue, kNonStandard_SkGammaNamed);
92 test_path(r, "webp-color-profile-lossy.webp", 92 test_path(r, "webp-color-profile-lossy.webp",
93 red, green, blue, SkColorSpace::kNonStandard_GammaNamed); 93 red, green, blue, kNonStandard_SkGammaNamed);
94 test_path(r, "webp-color-profile-lossy-alpha.webp", 94 test_path(r, "webp-color-profile-lossy-alpha.webp",
95 red, green, blue, SkColorSpace::kNonStandard_GammaNamed); 95 red, green, blue, kNonStandard_SkGammaNamed);
96 } 96 }
97 97
98 DEF_TEST(ColorSpaceSRGBCompare, r) { 98 DEF_TEST(ColorSpaceSRGBCompare, r) {
99 // Create an sRGB color space by name 99 // Create an sRGB color space by name
100 sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::k SRGB_Named); 100 sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::k SRGB_Named);
101 101
102 // Create an sRGB color space by value 102 // Create an sRGB color space by value
103 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor); 103 SkMatrix44 srgbToxyzD50(SkMatrix44::kUninitialized_Constructor);
104 srgbToxyzD50.set3x3RowMajorf(g_sRGB_XYZ); 104 srgbToxyzD50.set3x3RowMajorf(g_sRGB_XYZ);
105 sk_sp<SkColorSpace> rgbColorSpace = SkColorSpace::NewRGB(SkColorSpace::kSRGB _GammaNamed, 105 sk_sp<SkColorSpace> rgbColorSpace = SkColorSpace::NewRGB(SkColorSpace::kSRGB _GammaNamed,
(...skipping 13 matching lines...) Expand all
119 return as_CSB(space)->writeToICC(); 119 return as_CSB(space)->writeToICC();
120 } 120 }
121 }; 121 };
122 122
123 DEF_TEST(ColorSpaceWriteICC, r) { 123 DEF_TEST(ColorSpaceWriteICC, r) {
124 // Test writing a new ICC profile 124 // Test writing a new ICC profile
125 sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::k SRGB_Named); 125 sk_sp<SkColorSpace> namedColorSpace = SkColorSpace::NewNamed(SkColorSpace::k SRGB_Named);
126 sk_sp<SkData> namedData = ColorSpaceTest::WriteToICC(namedColorSpace.get()); 126 sk_sp<SkData> namedData = ColorSpaceTest::WriteToICC(namedColorSpace.get());
127 sk_sp<SkColorSpace> iccColorSpace = SkColorSpace::NewICC(namedData->data(), namedData->size()); 127 sk_sp<SkColorSpace> iccColorSpace = SkColorSpace::NewICC(namedData->data(), namedData->size());
128 test_space(r, iccColorSpace.get(), g_sRGB_XYZ, &g_sRGB_XYZ[3], &g_sRGB_XYZ[6 ], 128 test_space(r, iccColorSpace.get(), g_sRGB_XYZ, &g_sRGB_XYZ[3], &g_sRGB_XYZ[6 ],
129 SkColorSpace::k2Dot2Curve_GammaNamed); 129 k2Dot2Curve_SkGammaNamed);
130 // FIXME (msarett): Test disabled. sRGB profiles are written approximately as 2.2f curves. 130 // FIXME (msarett): Test disabled. sRGB profiles are written approximately as 2.2f curves.
131 // REPORTER_ASSERT(r, iccColorSpace == namedColorSpace); 131 // REPORTER_ASSERT(r, iccColorSpace == namedColorSpace);
132 132
133 // Test saving the original ICC data 133 // Test saving the original ICC data
134 sk_sp<SkData> monitorData = SkData::MakeFromFileName( 134 sk_sp<SkData> monitorData = SkData::MakeFromFileName(
135 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str()); 135 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
136 REPORTER_ASSERT(r, monitorData); 136 REPORTER_ASSERT(r, monitorData);
137 if (!monitorData) { 137 if (!monitorData) {
138 return; 138 return;
139 } 139 }
140 sk_sp<SkColorSpace> monitorSpace = SkColorSpace::NewICC(monitorData->data(), 140 sk_sp<SkColorSpace> monitorSpace = SkColorSpace::NewICC(monitorData->data(),
141 monitorData->size()) ; 141 monitorData->size()) ;
142 sk_sp<SkData> newMonitorData = ColorSpaceTest::WriteToICC(monitorSpace.get() ); 142 sk_sp<SkData> newMonitorData = ColorSpaceTest::WriteToICC(monitorSpace.get() );
143 sk_sp<SkColorSpace> newMonitorSpace = SkColorSpace::NewICC(newMonitorData->d ata(), 143 sk_sp<SkColorSpace> newMonitorSpace = SkColorSpace::NewICC(newMonitorData->d ata(),
144 newMonitorData->s ize()); 144 newMonitorData->s ize());
145 REPORTER_ASSERT(r, monitorSpace->xyz() == newMonitorSpace->xyz()); 145 REPORTER_ASSERT(r, monitorSpace->xyz() == newMonitorSpace->xyz());
146 REPORTER_ASSERT(r, monitorSpace->gammaNamed() == newMonitorSpace->gammaNamed ()); 146 REPORTER_ASSERT(r, as_CSB(monitorSpace)->gammaNamed() == as_CSB(newMonitorSp ace)->gammaNamed());
147 } 147 }
148 148
149 DEF_TEST(ColorSpace_Named, r) { 149 DEF_TEST(ColorSpace_Named, r) {
150 const struct { 150 const struct {
151 SkColorSpace::Named fNamed; 151 SkColorSpace::Named fNamed;
152 bool fIsSRGB; 152 bool fIsSRGB;
153 } recs[] { 153 } recs[] {
154 { SkColorSpace::kSRGB_Named, true }, 154 { SkColorSpace::kSRGB_Named, true },
155 { SkColorSpace::kAdobeRGB_Named, false }, 155 { SkColorSpace::kAdobeRGB_Named, false },
156 }; 156 };
157 157
158 for (auto rec : recs) { 158 for (auto rec : recs) {
159 auto cs = SkColorSpace::NewNamed(rec.fNamed); 159 auto cs = SkColorSpace::NewNamed(rec.fNamed);
160 REPORTER_ASSERT(r, cs); 160 REPORTER_ASSERT(r, cs);
161 if (cs) { 161 if (cs) {
162 if (rec.fIsSRGB) { 162 if (rec.fIsSRGB) {
163 REPORTER_ASSERT(r, SkColorSpace::kSRGB_GammaNamed == cs->gammaNa med()); 163 REPORTER_ASSERT(r, kSRGB_SkGammaNamed == as_CSB(cs)->gammaNamed( ));
164 } else { 164 } else {
165 REPORTER_ASSERT(r, SkColorSpace::k2Dot2Curve_GammaNamed == cs->g ammaNamed()); 165 REPORTER_ASSERT(r, k2Dot2Curve_SkGammaNamed == as_CSB(cs)->gamma Named());
166 } 166 }
167 } 167 }
168 } 168 }
169 169
170 SkImageInfo info = SkImageInfo::MakeS32(10, 10, kPremul_SkAlphaType); 170 SkImageInfo info = SkImageInfo::MakeS32(10, 10, kPremul_SkAlphaType);
171 REPORTER_ASSERT(r, info.gammaCloseToSRGB()); 171 REPORTER_ASSERT(r, info.gammaCloseToSRGB());
172 } 172 }
173 173
174 static void test_serialize(skiatest::Reporter* r, SkColorSpace* space, bool isNa med) { 174 static void test_serialize(skiatest::Reporter* r, SkColorSpace* space, bool isNa med) {
175 sk_sp<SkData> data1 = space->serialize(); 175 sk_sp<SkData> data1 = space->serialize();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 REPORTER_ASSERT(r, !SkColorSpace::Equals(srgb.get(), nullptr)); 242 REPORTER_ASSERT(r, !SkColorSpace::Equals(srgb.get(), nullptr));
243 REPORTER_ASSERT(r, !SkColorSpace::Equals(adobe.get(), srgb.get())); 243 REPORTER_ASSERT(r, !SkColorSpace::Equals(adobe.get(), srgb.get()));
244 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), srgb.get())); 244 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), srgb.get()));
245 REPORTER_ASSERT(r, !SkColorSpace::Equals(z32.get(), z30.get())); 245 REPORTER_ASSERT(r, !SkColorSpace::Equals(z32.get(), z30.get()));
246 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), srgb.get())); 246 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), srgb.get()));
247 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), upperRight.get())) ; 247 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), upperRight.get())) ;
248 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), upperRight.get())); 248 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), upperRight.get()));
249 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperRight.get(), adobe.get())); 249 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperRight.get(), adobe.get()));
250 REPORTER_ASSERT(r, !SkColorSpace::Equals(rgb1.get(), rgb2.get())); 250 REPORTER_ASSERT(r, !SkColorSpace::Equals(rgb1.get(), rgb2.get()));
251 } 251 }
OLDNEW
« no previous file with comments | « src/image/SkSurface_Raster.cpp ('k') | tests/ColorSpaceXformTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698