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

Side by Side Diff: tests/ColorSpaceXformTest.cpp

Issue 2117773002: Refactor parsing and storage of SkGammas (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Read fixed 0.16 properly 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(nullptr, gammas, SkMatri x::I(), nullptr)); 20 sk_sp<SkColorSpace> space(new SkColorSpace_Base(
21 nullptr, SkColorSpace::kNonStandard_GammaNamed, gammas, SkMatrix ::I(), nullptr));
21 return SkColorSpaceXform::New(space, space); 22 return SkColorSpaceXform::New(space, space);
22 } 23 }
23 }; 24 };
24 25
25 static bool almost_equal(int x, int y) { 26 static bool almost_equal(int x, int y) {
26 return SkTAbs(x - y) <= 1; 27 return SkTAbs(x - y) <= 1;
27 } 28 }
28 29
29 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga mmas) { 30 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga mmas) {
30 // Arbitrary set of 10 pixels 31 // Arbitrary set of 10 pixels
(...skipping 16 matching lines...) Expand all
47 SkGetPackedG32(dstPixels[i]))); 48 SkGetPackedG32(dstPixels[i])));
48 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF), 49 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF),
49 SkGetPackedB32(dstPixels[i]))); 50 SkGetPackedB32(dstPixels[i])));
50 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF), 51 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF),
51 SkGetPackedA32(dstPixels[i]))); 52 SkGetPackedA32(dstPixels[i])));
52 } 53 }
53 } 54 }
54 55
55 DEF_TEST(ColorSpaceXform_TableGamma, r) { 56 DEF_TEST(ColorSpaceXform_TableGamma, r) {
56 // Lookup-table based gamma curves 57 // Lookup-table based gamma curves
57 SkGammaCurve red, green, blue;
58 constexpr size_t tableSize = 10; 58 constexpr size_t tableSize = 10;
59 red.fTable = std::unique_ptr<float[]>(new float[tableSize]); 59 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(float) * tableSize) ;
60 green.fTable = std::unique_ptr<float[]>(new float[tableSize]); 60 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas());
61 blue.fTable = std::unique_ptr<float[]>(new float[tableSize]); 61 gammas->fRedType = gammas->fGreenType = gammas->fBlueType = SkGammas::Type:: kTable_Type;
62 red.fTableSize = green.fTableSize = blue.fTableSize = 10; 62 gammas->fRedData.fTable.fSize = gammas->fGreenData.fTable.fSize =
63 red.fTable[0] = green.fTable[0] = blue.fTable[0] = 0.00f; 63 gammas->fBlueData.fTable.fSize = tableSize;
64 red.fTable[1] = green.fTable[1] = blue.fTable[1] = 0.05f; 64 gammas->fRedData.fTable.fOffset = gammas->fGreenData.fTable.fOffset =
65 red.fTable[2] = green.fTable[2] = blue.fTable[2] = 0.10f; 65 gammas->fBlueData.fTable.fOffset = 0;
66 red.fTable[3] = green.fTable[3] = blue.fTable[3] = 0.15f; 66 float* table = SkTAddOffset<float>(memory, sizeof(SkGammas));
67 red.fTable[4] = green.fTable[4] = blue.fTable[4] = 0.25f; 67
68 red.fTable[5] = green.fTable[5] = blue.fTable[5] = 0.35f; 68 table[0] = 0.00f;
69 red.fTable[6] = green.fTable[6] = blue.fTable[6] = 0.45f; 69 table[1] = 0.05f;
70 red.fTable[7] = green.fTable[7] = blue.fTable[7] = 0.60f; 70 table[2] = 0.10f;
71 red.fTable[8] = green.fTable[8] = blue.fTable[8] = 0.75f; 71 table[3] = 0.15f;
72 red.fTable[9] = green.fTable[9] = blue.fTable[9] = 1.00f; 72 table[4] = 0.25f;
73 sk_sp<SkGammas> gammas = 73 table[5] = 0.35f;
74 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu e)); 74 table[6] = 0.45f;
75 table[7] = 0.60f;
76 table[8] = 0.75f;
77 table[9] = 1.00f;
75 test_identity_xform(r, gammas); 78 test_identity_xform(r, gammas);
76 } 79 }
77 80
78 DEF_TEST(ColorSpaceXform_ParametricGamma, r) { 81 DEF_TEST(ColorSpaceXform_ParametricGamma, r) {
79 // Parametric gamma curves 82 // Parametric gamma curves
80 SkGammaCurve red, green, blue; 83 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(SkGammas::Params));
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));
81 89
82 // Interval, switch xforms at 0.0031308f 90 // Interval, switch xforms at 0.0031308f
83 red.fD = green.fD = blue.fD = 0.04045f; 91 params->fD = 0.04045f;
84 92
85 // First equation: 93 // First equation:
86 red.fE = green.fE = blue.fE = 1.0f / 12.92f; 94 params->fE = 1.0f / 12.92f;
95 params->fF = 0.0f;
87 96
88 // Second equation: 97 // Second equation:
89 // Note that the function is continuous (it's actually sRGB). 98 // Note that the function is continuous (it's actually sRGB).
90 red.fA = green.fA = blue.fA = 1.0f / 1.055f; 99 params->fA = 1.0f / 1.055f;
91 red.fB = green.fB = blue.fB = 0.055f / 1.055f; 100 params->fB = 0.055f / 1.055f;
92 red.fC = green.fC = blue.fC = 0.0f; 101 params->fC = 0.0f;
93 red.fG = green.fG = blue.fG = 2.4f; 102 params->fG = 2.4f;
94 sk_sp<SkGammas> gammas =
95 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu e));
96 test_identity_xform(r, gammas); 103 test_identity_xform(r, gammas);
97 } 104 }
98 105
99 DEF_TEST(ColorSpaceXform_ExponentialGamma, r) { 106 DEF_TEST(ColorSpaceXform_ExponentialGamma, r) {
100 // Exponential gamma curves 107 // Exponential gamma curves
101 SkGammaCurve red, green, blue; 108 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new SkGammas());
102 red.fValue = green.fValue = blue.fValue = 1.4f; 109 gammas->fRedType = gammas->fGreenType = gammas->fBlueType = SkGammas::Type:: kValue_Type;
103 sk_sp<SkGammas> gammas = 110 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));
105 test_identity_xform(r, gammas); 111 test_identity_xform(r, gammas);
106 } 112 }
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