Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Public Attributes | List of all members
SkColorSpaceXformSteps Struct Reference

#include <SkColorSpaceXformSteps.h>

Classes

struct  Flags
 

Public Member Functions

 SkColorSpaceXformSteps ()
 
 SkColorSpaceXformSteps (const SkColorSpace *src, SkAlphaType srcAT, const SkColorSpace *dst, SkAlphaType dstAT)
 
template<typename S , typename D >
 SkColorSpaceXformSteps (const S &src, const D &dst)
 
void apply (float rgba[4]) const
 
void apply (SkRasterPipeline *) const
 

Public Attributes

Flags flags
 
skcms_TransferFunction srcTF
 
skcms_TransferFunction dstTFInv
 
float src_to_dst_matrix [9]
 

Detailed Description

Definition at line 19 of file SkColorSpaceXformSteps.h.

Constructor & Destructor Documentation

◆ SkColorSpaceXformSteps() [1/3]

SkColorSpaceXformSteps::SkColorSpaceXformSteps ( )
inline

Definition at line 37 of file SkColorSpaceXformSteps.h.

37{}

◆ SkColorSpaceXformSteps() [2/3]

SkColorSpaceXformSteps::SkColorSpaceXformSteps ( const SkColorSpace src,
SkAlphaType  srcAT,
const SkColorSpace dst,
SkAlphaType  dstAT 
)

Definition at line 23 of file SkColorSpaceXformSteps.cpp.

24 {
25 // Opaque outputs are treated as the same alpha type as the source input.
26 // TODO: we'd really like to have a good way of explaining why we think this is useful.
27 if (dstAT == kOpaque_SkAlphaType) {
28 dstAT = srcAT;
29 }
30
31 // We have some options about what to do with null src or dst here.
32 // This pair seems to be the most consistent with legacy expectations.
33 if (!src) { src = sk_srgb_singleton(); }
34 if (!dst) { dst = src; }
35
36 if (src->hash() == dst->hash() && srcAT == dstAT) {
38 return;
39 }
40
41 this->flags.unpremul = srcAT == kPremul_SkAlphaType;
42 this->flags.linearize = !src->gammaIsLinear();
43 this->flags.gamut_transform = src->toXYZD50Hash() != dst->toXYZD50Hash();
44 this->flags.encode = !dst->gammaIsLinear();
45 this->flags.premul = srcAT != kOpaque_SkAlphaType && dstAT == kPremul_SkAlphaType;
46
47 if (this->flags.gamut_transform) {
48 skcms_Matrix3x3 src_to_dst; // TODO: switch src_to_dst_matrix to row-major
49 src->gamutTransformTo(dst, &src_to_dst);
50
51 this->src_to_dst_matrix[0] = src_to_dst.vals[0][0];
52 this->src_to_dst_matrix[1] = src_to_dst.vals[1][0];
53 this->src_to_dst_matrix[2] = src_to_dst.vals[2][0];
54
55 this->src_to_dst_matrix[3] = src_to_dst.vals[0][1];
56 this->src_to_dst_matrix[4] = src_to_dst.vals[1][1];
57 this->src_to_dst_matrix[5] = src_to_dst.vals[2][1];
58
59 this->src_to_dst_matrix[6] = src_to_dst.vals[0][2];
60 this->src_to_dst_matrix[7] = src_to_dst.vals[1][2];
61 this->src_to_dst_matrix[8] = src_to_dst.vals[2][2];
62 } else {
63 #ifdef SK_DEBUG
64 skcms_Matrix3x3 srcM, dstM;
65 src->toXYZD50(&srcM);
66 dst->toXYZD50(&dstM);
67 SkASSERT(0 == memcmp(&srcM, &dstM, 9*sizeof(float)) && "Hash collision");
68 #endif
69 }
70
71 // Fill out all the transfer functions we'll use.
72 src-> transferFn(&this->srcTF );
73 dst->invTransferFn(&this->dstTFInv);
74
75 // If we linearize then immediately reencode with the same transfer function, skip both.
76 if ( this->flags.linearize &&
77 !this->flags.gamut_transform &&
78 this->flags.encode &&
79 src->transferFnHash() == dst->transferFnHash())
80 {
81 #ifdef SK_DEBUG
83 dst->transferFn(&dstTF);
84 for (int i = 0; i < 7; i++) {
85 SkASSERT( (&srcTF.g)[i] == (&dstTF.g)[i] && "Hash collision" );
86 }
87 #endif
88 this->flags.linearize = false;
89 this->flags.encode = false;
90 }
91
92 // Skip unpremul...premul if there are no non-linear operations between.
93 if ( this->flags.unpremul &&
94 !this->flags.linearize &&
95 !this->flags.encode &&
96 this->flags.premul)
97 {
98 this->flags.unpremul = false;
99 this->flags.premul = false;
100 }
101}
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkColorSpace * sk_srgb_singleton()
bool gammaIsLinear() const
void invTransferFn(skcms_TransferFunction *fn) const
static bool Equals(const SkColorSpace *, const SkColorSpace *)
uint32_t toXYZD50Hash() const
Definition: SkColorSpace.h:161
dst
Definition: cp.py:12
skcms_TransferFunction srcTF
skcms_TransferFunction dstTFInv
float vals[3][3]
Definition: skcms_public.h:27

◆ SkColorSpaceXformSteps() [3/3]

template<typename S , typename D >
SkColorSpaceXformSteps::SkColorSpaceXformSteps ( const S &  src,
const D dst 
)
inline

Definition at line 42 of file SkColorSpaceXformSteps.h.

43 : SkColorSpaceXformSteps(src.colorSpace(), src.alphaType(),
44 dst.colorSpace(), dst.alphaType()) {}

Member Function Documentation

◆ apply() [1/2]

void SkColorSpaceXformSteps::apply ( float  rgba[4]) const

◆ apply() [2/2]

void SkColorSpaceXformSteps::apply ( SkRasterPipeline p) const

Definition at line 139 of file SkColorSpaceXformSteps.cpp.

139 {
140 if (flags.unpremul) { p->append(SkRasterPipelineOp::unpremul); }
141 if (flags.linearize) { p->appendTransferFunction(srcTF); }
142 if (flags.gamut_transform) { p->append(SkRasterPipelineOp::matrix_3x3, &src_to_dst_matrix); }
143 if (flags.encode) { p->appendTransferFunction(dstTFInv); }
144 if (flags.premul) { p->append(SkRasterPipelineOp::premul); }
145}
static uint32_t premul(uint32_t color)

Member Data Documentation

◆ dstTFInv

skcms_TransferFunction SkColorSpaceXformSteps::dstTFInv

Definition at line 52 of file SkColorSpaceXformSteps.h.

◆ flags

Flags SkColorSpaceXformSteps::flags

Definition at line 49 of file SkColorSpaceXformSteps.h.

◆ src_to_dst_matrix

float SkColorSpaceXformSteps::src_to_dst_matrix[9]

Definition at line 53 of file SkColorSpaceXformSteps.h.

◆ srcTF

skcms_TransferFunction SkColorSpaceXformSteps::srcTF

Definition at line 51 of file SkColorSpaceXformSteps.h.


The documentation for this struct was generated from the following files: