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 | #include "include/private/SkImageInfoPriv.h" |
14 | #include "src/core/SkVM_fwd.h" |
15 | |
16 | class SkRasterPipeline; |
17 | |
18 | struct SkColorSpaceXformSteps { |
19 | |
20 | struct Flags { |
21 | bool unpremul = false; |
22 | bool linearize = false; |
23 | bool gamut_transform = false; |
24 | bool encode = false; |
25 | bool premul = false; |
26 | |
27 | uint32_t mask() const { |
28 | return (unpremul ? 1 : 0) |
29 | | (linearize ? 2 : 0) |
30 | | (gamut_transform ? 4 : 0) |
31 | | (encode ? 8 : 0) |
32 | | (premul ? 16 : 0); |
33 | } |
34 | }; |
35 | |
36 | SkColorSpaceXformSteps(SkColorSpace* src, SkAlphaType srcAT, |
37 | SkColorSpace* dst, SkAlphaType dstAT); |
38 | |
39 | template <typename S, typename D> |
40 | SkColorSpaceXformSteps(const S& src, const D& dst) |
41 | : SkColorSpaceXformSteps(src.colorSpace(), src.alphaType(), |
42 | dst.colorSpace(), dst.alphaType()) {} |
43 | |
44 | void apply(float rgba[4]) const; |
45 | void apply(SkRasterPipeline*, bool src_is_normalized) const; |
46 | skvm::Color program(skvm::Builder*, skvm::Uniforms*, skvm::Color) const; |
47 | |
48 | void apply(SkRasterPipeline* p, SkColorType srcCT) const { |
49 | return this->apply(p, SkColorTypeIsNormalized(srcCT)); |
50 | } |
51 | |
52 | Flags flags; |
53 | |
54 | bool srcTF_is_sRGB, |
55 | dstTF_is_sRGB; |
56 | skcms_TransferFunction srcTF, // Apply for linearize. |
57 | dstTFInv; // Apply for encode. |
58 | float src_to_dst_matrix[9]; // Apply this 3x3 column-major matrix for gamut_transform. |
59 | }; |
60 | |
61 | #endif//SkColorSpaceXformSteps_DEFINED |
62 | |