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 "SkColorPriv.h" | 8 #include "SkColorPriv.h" |
9 #include "SkColorSpace_Base.h" | 9 #include "SkColorSpace_Base.h" |
10 #include "SkColorSpacePriv.h" | 10 #include "SkColorSpacePriv.h" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 nullptr, | 249 nullptr, |
250 nullptr, | 250 nullptr, |
251 &build_table_linear_to_gamma, | 251 &build_table_linear_to_gamma, |
252 &build_table_linear_to_gamma, | 252 &build_table_linear_to_gamma, |
253 &build_table_linear_to_gamma, | 253 &build_table_linear_to_gamma, |
254 }; | 254 }; |
255 | 255 |
256 // Build tables to transform src gamma to linear. | 256 // Build tables to transform src gamma to linear. |
257 template <typename T> | 257 template <typename T> |
258 static void build_gamma_tables(const T* outGammaTables[3], T* gammaTableStorage,
int gammaTableSize, | 258 static void build_gamma_tables(const T* outGammaTables[3], T* gammaTableStorage,
int gammaTableSize, |
259 const sk_sp<SkColorSpace>& space, const GammaFns<
T>& fns, | 259 SkColorSpace* space, const GammaFns<T>& fns, bool
gammasAreMatching) |
260 bool gammasAreMatching) { | 260 { |
261 switch (as_CSB(space)->gammaNamed()) { | 261 switch (as_CSB(space)->gammaNamed()) { |
262 case kSRGB_SkGammaNamed: | 262 case kSRGB_SkGammaNamed: |
263 outGammaTables[0] = outGammaTables[1] = outGammaTables[2] = fns.fSRG
BTable; | 263 outGammaTables[0] = outGammaTables[1] = outGammaTables[2] = fns.fSRG
BTable; |
264 break; | 264 break; |
265 case k2Dot2Curve_SkGammaNamed: | 265 case k2Dot2Curve_SkGammaNamed: |
266 outGammaTables[0] = outGammaTables[1] = outGammaTables[2] = fns.f2Do
t2Table; | 266 outGammaTables[0] = outGammaTables[1] = outGammaTables[2] = fns.f2Do
t2Table; |
267 break; | 267 break; |
268 case kLinear_SkGammaNamed: | 268 case kLinear_SkGammaNamed: |
269 outGammaTables[0] = outGammaTables[1] = outGammaTables[2] = nullptr; | 269 outGammaTables[0] = outGammaTables[1] = outGammaTables[2] = nullptr; |
270 break; | 270 break; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 if (!color_space_almost_equal(srcToDst.getFloat(i,j), expected)) { | 335 if (!color_space_almost_equal(srcToDst.getFloat(i,j), expected)) { |
336 return false; | 336 return false; |
337 } | 337 } |
338 } | 338 } |
339 } | 339 } |
340 return true; | 340 return true; |
341 } | 341 } |
342 | 342 |
343 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 343 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
344 | 344 |
345 std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(const sk_sp<SkColorSpa
ce>& srcSpace, | 345 std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(SkColorSpace* srcSpace
, |
346 const sk_sp<SkColorSpa
ce>& dstSpace) { | 346 SkColorSpace* dstSpace
) { |
347 if (!srcSpace || !dstSpace) { | 347 if (!srcSpace || !dstSpace) { |
348 // Invalid input | 348 // Invalid input |
349 return nullptr; | 349 return nullptr; |
350 } | 350 } |
351 | 351 |
352 ColorSpaceMatch csm = kNone_ColorSpaceMatch; | 352 ColorSpaceMatch csm = kNone_ColorSpaceMatch; |
353 SkMatrix44 srcToDst(SkMatrix44::kUninitialized_Constructor); | 353 SkMatrix44 srcToDst(SkMatrix44::kUninitialized_Constructor); |
354 if (SkColorSpace::Equals(srcSpace.get(), dstSpace.get())) { | 354 if (SkColorSpace::Equals(srcSpace, dstSpace)) { |
355 srcToDst.setIdentity(); | 355 srcToDst.setIdentity(); |
356 csm = kFull_ColorSpaceMatch; | 356 csm = kFull_ColorSpaceMatch; |
357 } else { | 357 } else { |
358 srcToDst.setConcat(as_CSB(dstSpace)->fromXYZD50(), srcSpace->toXYZD50())
; | 358 srcToDst.setConcat(as_CSB(dstSpace)->fromXYZD50(), srcSpace->toXYZD50())
; |
359 | 359 |
360 if (is_almost_identity(srcToDst)) { | 360 if (is_almost_identity(srcToDst)) { |
361 srcToDst.setIdentity(); | 361 srcToDst.setIdentity(); |
362 csm = kGamut_ColorSpaceMatch; | 362 csm = kGamut_ColorSpaceMatch; |
363 } | 363 } |
364 } | 364 } |
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 | 1203 |
1204 // It's likely that each component will have the same gamma. In thi
s case, | 1204 // It's likely that each component will have the same gamma. In thi
s case, |
1205 // we only need to build one table. | 1205 // we only need to build one table. |
1206 return gammasAreMatching ? 1 : 3; | 1206 return gammasAreMatching ? 1 : 3; |
1207 } | 1207 } |
1208 } | 1208 } |
1209 } | 1209 } |
1210 | 1210 |
1211 template <SrcGamma kSrc, DstGamma kDst, ColorSpaceMatch kCSM> | 1211 template <SrcGamma kSrc, DstGamma kDst, ColorSpaceMatch kCSM> |
1212 SkColorSpaceXform_Base<kSrc, kDst, kCSM> | 1212 SkColorSpaceXform_Base<kSrc, kDst, kCSM> |
1213 ::SkColorSpaceXform_Base(const sk_sp<SkColorSpace>& srcSpace, const SkMatrix44&
srcToDst, | 1213 ::SkColorSpaceXform_Base(SkColorSpace* srcSpace, const SkMatrix44& srcToDst, SkC
olorSpace* dstSpace) |
1214 const sk_sp<SkColorSpace>& dstSpace) | |
1215 : fColorLUT(sk_ref_sp((SkColorLookUpTable*) as_CSB(srcSpace)->colorLUT())) | 1214 : fColorLUT(sk_ref_sp((SkColorLookUpTable*) as_CSB(srcSpace)->colorLUT())) |
1216 { | 1215 { |
1217 srcToDst.asColMajorf(fSrcToDst); | 1216 srcToDst.asColMajorf(fSrcToDst); |
1218 | 1217 |
1219 const int numSrcTables = num_tables(srcSpace.get()); | 1218 const int numSrcTables = num_tables(srcSpace); |
1220 const int numDstTables = num_tables(dstSpace.get()); | 1219 const int numDstTables = num_tables(dstSpace); |
1221 const size_t srcTableBytes = numSrcTables * 256 * sizeof(float); | 1220 const size_t srcTableBytes = numSrcTables * 256 * sizeof(float); |
1222 const size_t dstTableBytes = numDstTables * kDstGammaTableSize * sizeof(uint
8_t); | 1221 const size_t dstTableBytes = numDstTables * kDstGammaTableSize * sizeof(uint
8_t); |
1223 fStorage.reset(srcTableBytes + dstTableBytes); | 1222 fStorage.reset(srcTableBytes + dstTableBytes); |
1224 float* srcStorage = (float*) fStorage.get(); | 1223 float* srcStorage = (float*) fStorage.get(); |
1225 uint8_t* dstStorage = SkTAddOffset<uint8_t>(fStorage.get(), srcTableBytes); | 1224 uint8_t* dstStorage = SkTAddOffset<uint8_t>(fStorage.get(), srcTableBytes); |
1226 | 1225 |
1227 const bool srcGammasAreMatching = (1 >= numSrcTables); | 1226 const bool srcGammasAreMatching = (1 >= numSrcTables); |
1228 const bool dstGammasAreMatching = (1 >= numDstTables); | 1227 const bool dstGammasAreMatching = (1 >= numDstTables); |
1229 build_gamma_tables(fSrcGammaTables, srcStorage, 256, srcSpace, kToLinear, sr
cGammasAreMatching); | 1228 build_gamma_tables(fSrcGammaTables, srcStorage, 256, srcSpace, kToLinear, sr
cGammasAreMatching); |
1230 build_gamma_tables(fDstGammaTables, dstStorage, kDstGammaTableSize, dstSpace
, kFromLinear, | 1229 build_gamma_tables(fDstGammaTables, dstStorage, kDstGammaTableSize, dstSpace
, kFromLinear, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 return; | 1357 return; |
1359 } | 1358 } |
1360 default: | 1359 default: |
1361 SkASSERT(false); | 1360 SkASSERT(false); |
1362 return; | 1361 return; |
1363 } | 1362 } |
1364 } | 1363 } |
1365 | 1364 |
1366 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 1365 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
1367 | 1366 |
1368 std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkColorSpace>&
space) { | 1367 std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(SkColorSpace* space) { |
1369 return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base | 1368 return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base |
1370 <kTable_SrcGamma, kTable_DstGamma, kNone_ColorSpaceMatch> | 1369 <kTable_SrcGamma, kTable_DstGamma, kNone_ColorSpaceMatch> |
1371 (space, SkMatrix::I(), space)); | 1370 (space, SkMatrix::I(), space)); |
1372 } | 1371 } |
OLD | NEW |