blob: 3b2a88cddca745408ba4c8f117185ffd2b83a3fc [file] [log] [blame]
Mike Klein6968f9c2018-05-24 12:33:23 -04001/*
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 "SkColorSpace.h"
12#include "SkImageInfo.h"
13
14struct SkColorSpaceXformSteps {
Brian Osmanf018b7d2018-06-13 17:21:19 -040015 struct Flags {
16 bool unpremul;
17 bool linearize;
18 bool gamut_transform;
19 bool encode;
20 bool premul;
21
22 uint32_t mask() const {
23 return (unpremul ? 1 : 0)
24 | (linearize ? 2 : 0)
25 | (gamut_transform ? 4 : 0)
26 | (encode ? 8 : 0)
27 | (premul ? 16 : 0);
28 }
29 };
30
Mike Klein6968f9c2018-05-24 12:33:23 -040031 SkColorSpaceXformSteps(SkColorSpace* src, SkAlphaType srcAT,
32 SkColorSpace* dst);
33
Mike Klein2f2a7032018-06-05 12:24:55 -040034 static SkColorSpaceXformSteps UnpremulToUnpremul(SkColorSpace* src, SkColorSpace* dst) {
35 // The need to transform unpremul to unpremul comes up often enough that it's
36 // nice to centralize it here, especially because this use of kOpaque_SkAlphaType
37 // isn't the most intuitive. We basically want to always skip unpremul and premul.
38 return SkColorSpaceXformSteps(src, kOpaque_SkAlphaType, dst);
39 }
40
Brian Osmanf018b7d2018-06-13 17:21:19 -040041 void apply(float rgba[4]) const;
42
43 Flags flags;
Mike Klein6968f9c2018-05-24 12:33:23 -040044
Mike Klein34ab0f22018-05-30 11:07:47 -040045 SkColorSpaceTransferFn srcTF, // Apply for linearize.
46 dstTFInv; // Apply for encode.
Brian Osmanf018b7d2018-06-13 17:21:19 -040047 float src_to_dst_matrix[9]; // Apply this 3x3 column-major matrix for gamut_transform.
Mike Klein6968f9c2018-05-24 12:33:23 -040048};
49
Mike Klein6968f9c2018-05-24 12:33:23 -040050#endif//SkColorSpaceXformSteps_DEFINED