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

Side by Side Diff: tests/ColorSpaceTest.cpp

Issue 2269333002: Parse ICC profiles from webps (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 4 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/codec/SkWebpCodec.cpp ('k') | no next file » | 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 SkColorSpace::GammaNamed expectedGamma) {
23 23
24 REPORTER_ASSERT(r, nullptr != space);
24 REPORTER_ASSERT(r, expectedGamma == space->gammaNamed()); 25 REPORTER_ASSERT(r, expectedGamma == space->gammaNamed());
25 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 const float g_sRGB_XYZ[] = { 0.4358f, 0.2224f, 0.0139f, // R
43 0.3853f, 0.7170f, 0.0971f, // G
44 0.1430f, 0.0606f, 0.7139f }; // B
45
46 DEF_TEST(ColorSpace_sRGB, r) {
47 test_space(r, SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named).get(),
48 g_sRGB_XYZ, &g_sRGB_XYZ[3], &g_sRGB_XYZ[6], SkColorSpace::kSRGB_G ammaNamed);
49
50 }
51
52 static SkStreamAsset* resource(const char path[]) { 42 static SkStreamAsset* resource(const char path[]) {
53 SkString fullPath = GetResourcePath(path); 43 SkString fullPath = GetResourcePath(path);
54 return SkStream::NewFromFile(fullPath.c_str()); 44 return SkStream::NewFromFile(fullPath.c_str());
55 } 45 }
56 46
57 DEF_TEST(ColorSpaceParsePngICCProfile, r) { 47 static void test_path(skiatest::Reporter* r, const char* path,
58 SkAutoTDelete<SkStream> stream(resource("color_wheel_with_profile.png")); 48 const float red[], const float green[], const float blue[] ,
49 const SkColorSpace::GammaNamed expectedGamma) {
50 SkAutoTDelete<SkStream> stream(resource(path));
59 REPORTER_ASSERT(r, nullptr != stream); 51 REPORTER_ASSERT(r, nullptr != stream);
60 if (!stream) { 52 if (!stream) {
61 return; 53 return;
62 } 54 }
63 55
64 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); 56 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
65 REPORTER_ASSERT(r, nullptr != codec); 57 REPORTER_ASSERT(r, nullptr != codec);
66
67 #if (PNG_LIBPNG_VER_MAJOR > 1) || (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_M INOR >= 6)
68 SkColorSpace* colorSpace = codec->getInfo().colorSpace();
69 REPORTER_ASSERT(r, nullptr != colorSpace);
70
71 test_space(r, colorSpace, &g_sRGB_XYZ[0], &g_sRGB_XYZ[3], &g_sRGB_XYZ[6],
72 SkColorSpace::kSRGB_GammaNamed);
73 #endif
74 }
75
76 DEF_TEST(ColorSpaceParseJpegICCProfile, r) {
77 SkAutoTDelete<SkStream> stream(resource("icc-v2-gbr.jpg"));
78 REPORTER_ASSERT(r, nullptr != stream);
79 if (!stream) {
80 return;
81 }
82
83 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
84 REPORTER_ASSERT(r, nullptr != codec);
85 if (!codec) { 58 if (!codec) {
86 return; 59 return;
87 } 60 }
88 61
89 SkColorSpace* colorSpace = codec->getInfo().colorSpace(); 62 SkColorSpace* colorSpace = codec->getInfo().colorSpace();
90 REPORTER_ASSERT(r, nullptr != colorSpace); 63 test_space(r, colorSpace, red, green, blue, expectedGamma);
64 }
65
66 const float g_sRGB_XYZ[] = { 0.4358f, 0.2224f, 0.0139f, // R
67 0.3853f, 0.7170f, 0.0971f, // G
68 0.1430f, 0.0606f, 0.7139f }; // B
69
70 DEF_TEST(ColorSpace_sRGB, r) {
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);
73
74 }
75
76 DEF_TEST(ColorSpaceParseICCProfiles, r) {
77
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],
80 SkColorSpace::kSRGB_GammaNamed);
81 #endif
91 82
92 const float red[] = { 0.385117f, 0.716904f, 0.0970612f }; 83 const float red[] = { 0.385117f, 0.716904f, 0.0970612f };
93 const float green[] = { 0.143051f, 0.0606079f, 0.713913f }; 84 const float green[] = { 0.143051f, 0.0606079f, 0.713913f };
94 const float blue[] = { 0.436035f, 0.222488f, 0.013916f }; 85 const float blue[] = { 0.436035f, 0.222488f, 0.013916f };
95 test_space(r, colorSpace, red, green, blue, SkColorSpace::k2Dot2Curve_GammaN amed); 86 test_path(r, "icc-v2-gbr.jpg", red, green, blue, SkColorSpace::k2Dot2Curve_G ammaNamed);
87
88 test_path(r, "webp-color-profile-crash.webp",
89 red, green, blue, SkColorSpace::kNonStandard_GammaNamed);
90 test_path(r, "webp-color-profile-lossless.webp",
91 red, green, blue, SkColorSpace::kNonStandard_GammaNamed);
92 test_path(r, "webp-color-profile-lossy.webp",
93 red, green, blue, SkColorSpace::kNonStandard_GammaNamed);
94 test_path(r, "webp-color-profile-lossy-alpha.webp",
95 red, green, blue, SkColorSpace::kNonStandard_GammaNamed);
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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 REPORTER_ASSERT(r, !SkColorSpace::Equals(srgb.get(), nullptr)); 244 REPORTER_ASSERT(r, !SkColorSpace::Equals(srgb.get(), nullptr));
245 REPORTER_ASSERT(r, !SkColorSpace::Equals(adobe.get(), srgb.get())); 245 REPORTER_ASSERT(r, !SkColorSpace::Equals(adobe.get(), srgb.get()));
246 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), srgb.get())); 246 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), srgb.get()));
247 REPORTER_ASSERT(r, !SkColorSpace::Equals(z32.get(), z30.get())); 247 REPORTER_ASSERT(r, !SkColorSpace::Equals(z32.get(), z30.get()));
248 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), srgb.get())); 248 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), srgb.get()));
249 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), upperRight.get())) ; 249 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperLeft.get(), upperRight.get())) ;
250 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), upperRight.get())); 250 REPORTER_ASSERT(r, !SkColorSpace::Equals(z30.get(), upperRight.get()));
251 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperRight.get(), adobe.get())); 251 REPORTER_ASSERT(r, !SkColorSpace::Equals(upperRight.get(), adobe.get()));
252 REPORTER_ASSERT(r, !SkColorSpace::Equals(rgb1.get(), rgb2.get())); 252 REPORTER_ASSERT(r, !SkColorSpace::Equals(rgb1.get(), rgb2.get()));
253 } 253 }
OLDNEW
« no previous file with comments | « src/codec/SkWebpCodec.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698