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

Side by Side Diff: tests/ColorSpaceXformTest.cpp

Issue 2159253005: 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 = 61 blue.fTable = std::unique_ptr<float[]>(new float[tableSize]);
62 SkGammas::Type::kTable_Type; 62 red.fTableSize = green.fTableSize = blue.fTableSize = 10;
63 gammas->fRedData.fTable.fSize = gammas->fGreenData.fTable.fSize = 63 red.fTable[0] = green.fTable[0] = blue.fTable[0] = 0.00f;
64 gammas->fBlueData.fTable.fSize = tableSize; 64 red.fTable[1] = green.fTable[1] = blue.fTable[1] = 0.05f;
65 gammas->fRedData.fTable.fOffset = gammas->fGreenData.fTable.fOffset = 65 red.fTable[2] = green.fTable[2] = blue.fTable[2] = 0.10f;
66 gammas->fBlueData.fTable.fOffset = 0; 66 red.fTable[3] = green.fTable[3] = blue.fTable[3] = 0.15f;
67 float* table = SkTAddOffset<float>(memory, sizeof(SkGammas)); 67 red.fTable[4] = green.fTable[4] = blue.fTable[4] = 0.25f;
68 68 red.fTable[5] = green.fTable[5] = blue.fTable[5] = 0.35f;
69 table[0] = 0.00f; 69 red.fTable[6] = green.fTable[6] = blue.fTable[6] = 0.45f;
70 table[1] = 0.05f; 70 red.fTable[7] = green.fTable[7] = blue.fTable[7] = 0.60f;
71 table[2] = 0.10f; 71 red.fTable[8] = green.fTable[8] = blue.fTable[8] = 0.75f;
72 table[3] = 0.15f; 72 red.fTable[9] = green.fTable[9] = blue.fTable[9] = 1.00f;
73 table[4] = 0.25f; 73 sk_sp<SkGammas> gammas =
74 table[5] = 0.35f; 74 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu e));
75 table[6] = 0.45f;
76 table[7] = 0.60f;
77 table[8] = 0.75f;
78 table[9] = 1.00f;
79 test_identity_xform(r, gammas); 75 test_identity_xform(r, gammas);
80 } 76 }
81 77
82 DEF_TEST(ColorSpaceXform_ParametricGamma, r) { 78 DEF_TEST(ColorSpaceXform_ParametricGamma, r) {
83 // Parametric gamma curves 79 // Parametric gamma curves
84 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(SkGammas::Params)); 80 SkGammaCurve red, green, blue;
85 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas());
86 gammas->fRedType = gammas->fGreenType = gammas->fBlueType =
87 SkGammas::Type::kParam_Type;
88 gammas->fRedData.fParamOffset = gammas->fGreenData.fParamOffset =
89 gammas->fBlueData.fParamOffset = 0;
90 SkGammas::Params* params = SkTAddOffset<SkGammas::Params>(memory, sizeof(SkG ammas));
91 81
92 // Interval, switch xforms at 0.0031308f 82 // Interval, switch xforms at 0.0031308f
93 params->fD = 0.04045f; 83 red.fD = green.fD = blue.fD = 0.04045f;
94 84
95 // First equation: 85 // First equation:
96 params->fE = 1.0f / 12.92f; 86 red.fE = green.fE = blue.fE = 1.0f / 12.92f;
97 params->fF = 0.0f;
98 87
99 // Second equation: 88 // Second equation:
100 // Note that the function is continuous (it's actually sRGB). 89 // Note that the function is continuous (it's actually sRGB).
101 params->fA = 1.0f / 1.055f; 90 red.fA = green.fA = blue.fA = 1.0f / 1.055f;
102 params->fB = 0.055f / 1.055f; 91 red.fB = green.fB = blue.fB = 0.055f / 1.055f;
103 params->fC = 0.0f; 92 red.fC = green.fC = blue.fC = 0.0f;
104 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));
105 test_identity_xform(r, gammas); 96 test_identity_xform(r, gammas);
106 } 97 }
107 98
108 DEF_TEST(ColorSpaceXform_ExponentialGamma, r) { 99 DEF_TEST(ColorSpaceXform_ExponentialGamma, r) {
109 // Exponential gamma curves 100 // Exponential gamma curves
110 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new SkGammas()); 101 SkGammaCurve red, green, blue;
111 gammas->fRedType = gammas->fGreenType = gammas->fBlueType = 102 red.fValue = green.fValue = blue.fValue = 1.4f;
112 SkGammas::Type::kValue_Type; 103 sk_sp<SkGammas> gammas =
113 gammas->fRedData.fValue = gammas->fGreenData.fValue = gammas->fBlueData.fVal ue = 1.4f; 104 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu e));
114 test_identity_xform(r, gammas); 105 test_identity_xform(r, gammas);
115 } 106 }
116
117 DEF_TEST(ColorSpaceXform_NonMatchingGamma, r) {
118 constexpr size_t tableSize = 10;
119 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(float) * tableSize +
120 sizeof(SkGammas::Params));
121 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas());
122
123 float* table = SkTAddOffset<float>(memory, sizeof(SkGammas));
124 table[0] = 0.00f;
125 table[1] = 0.15f;
126 table[2] = 0.20f;
127 table[3] = 0.25f;
128 table[4] = 0.35f;
129 table[5] = 0.45f;
130 table[6] = 0.55f;
131 table[7] = 0.70f;
132 table[8] = 0.85f;
133 table[9] = 1.00f;
134
135 SkGammas::Params* params = SkTAddOffset<SkGammas::Params>(memory, sizeof(SkG ammas) +
136 sizeof(float) * ta bleSize);
137 params->fA = 1.0f / 1.055f;
138 params->fB = 0.055f / 1.055f;
139 params->fC = 0.0f;
140 params->fD = 0.04045f;
141 params->fE = 1.0f / 12.92f;
142 params->fF = 0.0f;
143 params->fG = 2.4f;
144
145 gammas->fRedType = SkGammas::Type::kValue_Type;
146 gammas->fRedData.fValue = 1.2f;
147
148 gammas->fGreenType = SkGammas::Type::kTable_Type;
149 gammas->fGreenData.fTable.fSize = tableSize;
150 gammas->fGreenData.fTable.fOffset = 0;
151
152 gammas->fBlueType = SkGammas::Type::kParam_Type;
153 gammas->fBlueData.fParamOffset = sizeof(float) * tableSize;
154
155 test_identity_xform(r, gammas);
156 }
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