OLD | NEW |
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 "SkCodecPriv.h" | 10 #include "SkCodecPriv.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 table[5] = 0.35f; | 79 table[5] = 0.35f; |
80 table[6] = 0.45f; | 80 table[6] = 0.45f; |
81 table[7] = 0.60f; | 81 table[7] = 0.60f; |
82 table[8] = 0.75f; | 82 table[8] = 0.75f; |
83 table[9] = 1.00f; | 83 table[9] = 1.00f; |
84 test_identity_xform(r, gammas); | 84 test_identity_xform(r, gammas); |
85 } | 85 } |
86 | 86 |
87 DEF_TEST(ColorSpaceXform_ParametricGamma, r) { | 87 DEF_TEST(ColorSpaceXform_ParametricGamma, r) { |
88 // Parametric gamma curves | 88 // Parametric gamma curves |
89 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(SkGammas::Params)); | 89 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(SkColorSpaceTransfe
rFn)); |
90 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas()); | 90 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas()); |
91 gammas->fRedType = gammas->fGreenType = gammas->fBlueType = SkGammas::Type::
kParam_Type; | 91 gammas->fRedType = gammas->fGreenType = gammas->fBlueType = SkGammas::Type::
kParam_Type; |
92 gammas->fRedData.fParamOffset = gammas->fGreenData.fParamOffset = | 92 gammas->fRedData.fParamOffset = gammas->fGreenData.fParamOffset = |
93 gammas->fBlueData.fParamOffset = 0; | 93 gammas->fBlueData.fParamOffset = 0; |
94 SkGammas::Params* params = SkTAddOffset<SkGammas::Params>(memory, sizeof(SkG
ammas)); | 94 SkColorSpaceTransferFn* params = SkTAddOffset<SkColorSpaceTransferFn> |
| 95 (memory, sizeof(SkGammas)); |
95 | 96 |
96 // Interval, switch xforms at 0.0031308f | 97 // Interval, switch xforms at 0.0031308f |
97 params->fD = 0.04045f; | 98 params->fD = 0.04045f; |
98 | 99 |
99 // First equation: | 100 // First equation: |
100 params->fE = 1.0f / 12.92f; | 101 params->fE = 1.0f / 12.92f; |
101 params->fF = 0.0f; | 102 params->fF = 0.0f; |
102 | 103 |
103 // Second equation: | 104 // Second equation: |
104 // Note that the function is continuous (it's actually sRGB). | 105 // Note that the function is continuous (it's actually sRGB). |
(...skipping 17 matching lines...) Expand all Loading... |
122 gammas->fRedType = gammas->fGreenType = gammas->fBlueType = SkGammas::Type::
kNamed_Type; | 123 gammas->fRedType = gammas->fGreenType = gammas->fBlueType = SkGammas::Type::
kNamed_Type; |
123 gammas->fRedData.fNamed = kSRGB_SkGammaNamed; | 124 gammas->fRedData.fNamed = kSRGB_SkGammaNamed; |
124 gammas->fGreenData.fNamed = k2Dot2Curve_SkGammaNamed; | 125 gammas->fGreenData.fNamed = k2Dot2Curve_SkGammaNamed; |
125 gammas->fBlueData.fNamed = kLinear_SkGammaNamed; | 126 gammas->fBlueData.fNamed = kLinear_SkGammaNamed; |
126 test_identity_xform(r, gammas); | 127 test_identity_xform(r, gammas); |
127 } | 128 } |
128 | 129 |
129 DEF_TEST(ColorSpaceXform_NonMatchingGamma, r) { | 130 DEF_TEST(ColorSpaceXform_NonMatchingGamma, r) { |
130 constexpr size_t tableSize = 10; | 131 constexpr size_t tableSize = 10; |
131 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(float) * tableSize
+ | 132 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(float) * tableSize
+ |
132 sizeof(SkGammas::Params)); | 133 sizeof(SkColorSpaceTransferFn)); |
133 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas()); | 134 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas()); |
134 | 135 |
135 float* table = SkTAddOffset<float>(memory, sizeof(SkGammas)); | 136 float* table = SkTAddOffset<float>(memory, sizeof(SkGammas)); |
136 table[0] = 0.00f; | 137 table[0] = 0.00f; |
137 table[1] = 0.15f; | 138 table[1] = 0.15f; |
138 table[2] = 0.20f; | 139 table[2] = 0.20f; |
139 table[3] = 0.25f; | 140 table[3] = 0.25f; |
140 table[4] = 0.35f; | 141 table[4] = 0.35f; |
141 table[5] = 0.45f; | 142 table[5] = 0.45f; |
142 table[6] = 0.55f; | 143 table[6] = 0.55f; |
143 table[7] = 0.70f; | 144 table[7] = 0.70f; |
144 table[8] = 0.85f; | 145 table[8] = 0.85f; |
145 table[9] = 1.00f; | 146 table[9] = 1.00f; |
146 | 147 |
147 SkGammas::Params* params = SkTAddOffset<SkGammas::Params>(memory, sizeof(SkG
ammas) + | 148 SkColorSpaceTransferFn* params = SkTAddOffset<SkColorSpaceTransferFn>(memory
, |
148 sizeof(float) * ta
bleSize); | 149 sizeof(SkGammas) + sizeof(float) * tableSize); |
149 params->fA = 1.0f / 1.055f; | 150 params->fA = 1.0f / 1.055f; |
150 params->fB = 0.055f / 1.055f; | 151 params->fB = 0.055f / 1.055f; |
151 params->fC = 0.0f; | 152 params->fC = 0.0f; |
152 params->fD = 0.04045f; | 153 params->fD = 0.04045f; |
153 params->fE = 1.0f / 12.92f; | 154 params->fE = 1.0f / 12.92f; |
154 params->fF = 0.0f; | 155 params->fF = 0.0f; |
155 params->fG = 2.4f; | 156 params->fG = 2.4f; |
156 | 157 |
157 gammas->fRedType = SkGammas::Type::kValue_Type; | 158 gammas->fRedType = SkGammas::Type::kValue_Type; |
158 gammas->fRedData.fValue = 1.2f; | 159 gammas->fRedData.fValue = 1.2f; |
(...skipping 23 matching lines...) Expand all Loading... |
182 sk_sp<SkData> iccData = SkData::MakeFromFileName(filename.c_str()); | 183 sk_sp<SkData> iccData = SkData::MakeFromFileName(filename.c_str()); |
183 REPORTER_ASSERT_MESSAGE(r, iccData, "upperRight.icc profile required for tes
t"); | 184 REPORTER_ASSERT_MESSAGE(r, iccData, "upperRight.icc profile required for tes
t"); |
184 sk_sp<SkColorSpace> srcSpace = SkColorSpace::NewICC(iccData->bytes(), iccDat
a->size()); | 185 sk_sp<SkColorSpace> srcSpace = SkColorSpace::NewICC(iccData->bytes(), iccDat
a->size()); |
185 sk_sp<SkColorSpace> dstSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Na
med); | 186 sk_sp<SkColorSpace> dstSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Na
med); |
186 auto xform = SkColorSpaceXform::New(srcSpace.get(), dstSpace.get()); | 187 auto xform = SkColorSpaceXform::New(srcSpace.get(), dstSpace.get()); |
187 bool result = xform->apply(SkColorSpaceXform::kRGBA_8888_ColorFormat, dst.ge
t(), | 188 bool result = xform->apply(SkColorSpaceXform::kRGBA_8888_ColorFormat, dst.ge
t(), |
188 SkColorSpaceXform::kRGBA_8888_ColorFormat, src.ge
t(), len, | 189 SkColorSpaceXform::kRGBA_8888_ColorFormat, src.ge
t(), len, |
189 kUnpremul_SkAlphaType); | 190 kUnpremul_SkAlphaType); |
190 REPORTER_ASSERT(r, result); | 191 REPORTER_ASSERT(r, result); |
191 } | 192 } |
OLD | NEW |