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

Side by Side Diff: tests/ColorSpaceXformTest.cpp

Issue 2171623002: Revert of Refactor parsing and storage of SkGammas (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 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/core/SkColorSpace_ICC.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 "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 #include "SkColorSpace.h" 11 #include "SkColorSpace.h"
12 #include "SkColorSpace_Base.h" 12 #include "SkColorSpace_Base.h"
13 #include "SkColorSpaceXform.h" 13 #include "SkColorSpaceXform.h"
14 #include "Test.h" 14 #include "Test.h"
15 15
16 class ColorSpaceXformTest { 16 class ColorSpaceXformTest {
17 public: 17 public:
18 static std::unique_ptr<SkColorSpaceXform> CreateIdentityXform(const sk_sp<Sk Gammas>& gammas) { 18 static std::unique_ptr<SkColorSpaceXform> CreateIdentityXform(const sk_sp<Sk Gammas>& gammas) {
19 // Logically we can pass any matrix here. For simplicty, pass I(), i.e. D50 XYZ gamut. 19 // Logically we can pass any matrix here. For simplicty, pass I(), i.e. D50 XYZ gamut.
20 sk_sp<SkColorSpace> space(new SkColorSpace_Base( 20 sk_sp<SkColorSpace> space(new SkColorSpace_Base(nullptr, gammas, SkMatri x::I(), nullptr));
21 nullptr, SkColorSpace::kNonStandard_GammaNamed, gammas, SkMatrix ::I(), nullptr));
22 return SkColorSpaceXform::New(space, space); 21 return SkColorSpaceXform::New(space, space);
23 } 22 }
24 }; 23 };
25 24
26 static bool almost_equal(int x, int y) { 25 static bool almost_equal(int x, int y) {
27 return SkTAbs(x - y) <= 1; 26 return SkTAbs(x - y) <= 1;
28 } 27 }
29 28
30 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga mmas) { 29 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga mmas) {
31 // Arbitrary set of 10 pixels 30 // Arbitrary set of 10 pixels
(...skipping 16 matching lines...) Expand all
48 SkGetPackedG32(dstPixels[i]))); 47 SkGetPackedG32(dstPixels[i])));
49 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF), 48 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF),
50 SkGetPackedB32(dstPixels[i]))); 49 SkGetPackedB32(dstPixels[i])));
51 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF), 50 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF),
52 SkGetPackedA32(dstPixels[i]))); 51 SkGetPackedA32(dstPixels[i])));
53 } 52 }
54 } 53 }
55 54
56 DEF_TEST(ColorSpaceXform_TableGamma, r) { 55 DEF_TEST(ColorSpaceXform_TableGamma, r) {
57 // Lookup-table based gamma curves 56 // Lookup-table based gamma curves
57 SkGammaCurve red, green, blue;
58 constexpr size_t tableSize = 10; 58 constexpr size_t tableSize = 10;
59 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(float) * tableSize) ; 59 red.fTable = std::unique_ptr<float[]>(new float[tableSize]);
60 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas()); 60 green.fTable = std::unique_ptr<float[]>(new float[tableSize]);
61 gammas->fRedType = gammas->fGreenType = gammas->fBlueType = SkGammas::Type:: kTable_Type; 61 blue.fTable = std::unique_ptr<float[]>(new float[tableSize]);
62 gammas->fRedData.fTable.fSize = gammas->fGreenData.fTable.fSize = 62 red.fTableSize = green.fTableSize = blue.fTableSize = 10;
63 gammas->fBlueData.fTable.fSize = tableSize; 63 red.fTable[0] = green.fTable[0] = blue.fTable[0] = 0.00f;
64 gammas->fRedData.fTable.fOffset = gammas->fGreenData.fTable.fOffset = 64 red.fTable[1] = green.fTable[1] = blue.fTable[1] = 0.05f;
65 gammas->fBlueData.fTable.fOffset = 0; 65 red.fTable[2] = green.fTable[2] = blue.fTable[2] = 0.10f;
66 float* table = SkTAddOffset<float>(memory, sizeof(SkGammas)); 66 red.fTable[3] = green.fTable[3] = blue.fTable[3] = 0.15f;
67 67 red.fTable[4] = green.fTable[4] = blue.fTable[4] = 0.25f;
68 table[0] = 0.00f; 68 red.fTable[5] = green.fTable[5] = blue.fTable[5] = 0.35f;
69 table[1] = 0.05f; 69 red.fTable[6] = green.fTable[6] = blue.fTable[6] = 0.45f;
70 table[2] = 0.10f; 70 red.fTable[7] = green.fTable[7] = blue.fTable[7] = 0.60f;
71 table[3] = 0.15f; 71 red.fTable[8] = green.fTable[8] = blue.fTable[8] = 0.75f;
72 table[4] = 0.25f; 72 red.fTable[9] = green.fTable[9] = blue.fTable[9] = 1.00f;
73 table[5] = 0.35f; 73 sk_sp<SkGammas> gammas =
74 table[6] = 0.45f; 74 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu e));
75 table[7] = 0.60f;
76 table[8] = 0.75f;
77 table[9] = 1.00f;
78 test_identity_xform(r, gammas); 75 test_identity_xform(r, gammas);
79 } 76 }
80 77
81 DEF_TEST(ColorSpaceXform_ParametricGamma, r) { 78 DEF_TEST(ColorSpaceXform_ParametricGamma, r) {
82 // Parametric gamma curves 79 // Parametric gamma curves
83 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(SkGammas::Params)); 80 SkGammaCurve red, green, blue;
84 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas());
85 gammas->fRedType = gammas->fGreenType = gammas->fBlueType = SkGammas::Type:: kParam_Type;
86 gammas->fRedData.fParamOffset = gammas->fGreenData.fParamOffset =
87 gammas->fBlueData.fParamOffset = 0;
88 SkGammas::Params* params = SkTAddOffset<SkGammas::Params>(memory, sizeof(SkG ammas));
89 81
90 // Interval, switch xforms at 0.0031308f 82 // Interval, switch xforms at 0.0031308f
91 params->fD = 0.04045f; 83 red.fD = green.fD = blue.fD = 0.04045f;
92 84
93 // First equation: 85 // First equation:
94 params->fE = 1.0f / 12.92f; 86 red.fE = green.fE = blue.fE = 1.0f / 12.92f;
95 params->fF = 0.0f;
96 87
97 // Second equation: 88 // Second equation:
98 // Note that the function is continuous (it's actually sRGB). 89 // Note that the function is continuous (it's actually sRGB).
99 params->fA = 1.0f / 1.055f; 90 red.fA = green.fA = blue.fA = 1.0f / 1.055f;
100 params->fB = 0.055f / 1.055f; 91 red.fB = green.fB = blue.fB = 0.055f / 1.055f;
101 params->fC = 0.0f; 92 red.fC = green.fC = blue.fC = 0.0f;
102 params->fG = 2.4f; 93 red.fG = green.fG = blue.fG = 2.4f;
94 sk_sp<SkGammas> gammas =
95 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu e));
103 test_identity_xform(r, gammas); 96 test_identity_xform(r, gammas);
104 } 97 }
105 98
106 DEF_TEST(ColorSpaceXform_ExponentialGamma, r) { 99 DEF_TEST(ColorSpaceXform_ExponentialGamma, r) {
107 // Exponential gamma curves 100 // Exponential gamma curves
108 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new SkGammas()); 101 SkGammaCurve red, green, blue;
109 gammas->fRedType = gammas->fGreenType = gammas->fBlueType = SkGammas::Type:: kValue_Type; 102 red.fValue = green.fValue = blue.fValue = 1.4f;
110 gammas->fRedData.fValue = gammas->fGreenData.fValue = gammas->fBlueData.fVal ue = 1.4f; 103 sk_sp<SkGammas> gammas =
104 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu e));
111 test_identity_xform(r, gammas); 105 test_identity_xform(r, gammas);
112 } 106 }
113
114 DEF_TEST(ColorSpaceXform_NonMatchingGamma, r) {
115 constexpr size_t tableSize = 10;
116 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(float) * tableSize +
117 sizeof(SkGammas::Params));
118 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas());
119
120 float* table = SkTAddOffset<float>(memory, sizeof(SkGammas));
121 table[0] = 0.00f;
122 table[1] = 0.15f;
123 table[2] = 0.20f;
124 table[3] = 0.25f;
125 table[4] = 0.35f;
126 table[5] = 0.45f;
127 table[6] = 0.55f;
128 table[7] = 0.70f;
129 table[8] = 0.85f;
130 table[9] = 1.00f;
131
132 SkGammas::Params* params = SkTAddOffset<SkGammas::Params>(memory, sizeof(SkG ammas) +
133 sizeof(float) * ta bleSize);
134 params->fA = 1.0f / 1.055f;
135 params->fB = 0.055f / 1.055f;
136 params->fC = 0.0f;
137 params->fD = 0.04045f;
138 params->fE = 1.0f / 12.92f;
139 params->fF = 0.0f;
140 params->fG = 2.4f;
141
142 gammas->fRedType = SkGammas::Type::kValue_Type;
143 gammas->fRedData.fValue = 1.2f;
144
145 gammas->fGreenType = SkGammas::Type::kTable_Type;
146 gammas->fGreenData.fTable.fSize = tableSize;
147 gammas->fGreenData.fTable.fOffset = 0;
148
149 gammas->fBlueType = SkGammas::Type::kParam_Type;
150 gammas->fBlueData.fParamOffset = sizeof(float) * tableSize;
151
152 test_identity_xform(r, gammas);
153 }
OLDNEW
« no previous file with comments | « src/core/SkColorSpace_ICC.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698