1 /* 2 * Copyright 2018 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkColorSpaceXformSteps_DEFINED 9 #define SkColorSpaceXformSteps_DEFINED 10 11 #include "include/core/SkColorSpace.h" 12 #include "include/core/SkImageInfo.h" 13 14 class SkRasterPipeline; 15 16 struct SkColorSpaceXformSteps { 17 // Returns true if SkColorSpaceXformSteps must be applied 18 // to draw content in `src` into a destination in `dst`. 19 static bool Required(SkColorSpace* src, SkColorSpace* dst); 20 21 struct Flags { 22 bool unpremul = false; 23 bool linearize = false; 24 bool gamut_transform = false; 25 bool encode = false; 26 bool premul = false; 27 maskSkColorSpaceXformSteps::Flags28 uint32_t mask() const { 29 return (unpremul ? 1 : 0) 30 | (linearize ? 2 : 0) 31 | (gamut_transform ? 4 : 0) 32 | (encode ? 8 : 0) 33 | (premul ? 16 : 0); 34 } 35 }; 36 37 SkColorSpaceXformSteps(SkColorSpace* src, SkAlphaType srcAT, 38 SkColorSpace* dst, SkAlphaType dstAT); 39 40 void apply(float rgba[4]) const; 41 void apply(SkRasterPipeline*, bool src_is_normalized) const; 42 applySkColorSpaceXformSteps43 void apply(SkRasterPipeline* p, SkColorType srcCT) const { 44 #if 0 45 this->apply(p, srcCT < kRGBA_F16_SkColorType); 46 #else 47 // F16Norm is normalized, but to make diffing with F16 easier we 48 // intentionally take the slower, non-normalized path here. 49 this->apply(p, srcCT < kRGBA_F16Norm_SkColorType); 50 #endif 51 } 52 53 Flags flags; 54 55 bool srcTF_is_sRGB, 56 dstTF_is_sRGB; 57 skcms_TransferFunction srcTF, // Apply for linearize. 58 dstTFInv; // Apply for encode. 59 float src_to_dst_matrix[9]; // Apply this 3x3 column-major matrix for gamut_transform. 60 }; 61 62 #endif//SkColorSpaceXformSteps_DEFINED 63