blob: 912ae8ac0137ff5cfda17ca589d0fab8208d0bce [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
Mike Kleinb82edcc2018-07-10 18:25:03 +000014class SkRasterPipeline;
15
Mike Klein6968f9c2018-05-24 12:33:23 -040016struct SkColorSpaceXformSteps {
Brian Osmanf018b7d2018-06-13 17:21:19 -040017 struct Flags {
18 bool unpremul;
19 bool linearize;
20 bool gamut_transform;
21 bool encode;
22 bool premul;
23
24 uint32_t mask() const {
25 return (unpremul ? 1 : 0)
26 | (linearize ? 2 : 0)
27 | (gamut_transform ? 4 : 0)
28 | (encode ? 8 : 0)
29 | (premul ? 16 : 0);
30 }
31 };
32
Mike Klein6968f9c2018-05-24 12:33:23 -040033 SkColorSpaceXformSteps(SkColorSpace* src, SkAlphaType srcAT,
34 SkColorSpace* dst);
35
Mike Klein2f2a7032018-06-05 12:24:55 -040036 static SkColorSpaceXformSteps UnpremulToUnpremul(SkColorSpace* src, SkColorSpace* dst) {
37 // The need to transform unpremul to unpremul comes up often enough that it's
38 // nice to centralize it here, especially because this use of kOpaque_SkAlphaType
39 // isn't the most intuitive. We basically want to always skip unpremul and premul.
40 return SkColorSpaceXformSteps(src, kOpaque_SkAlphaType, dst);
41 }
42
Brian Osmanf018b7d2018-06-13 17:21:19 -040043 void apply(float rgba[4]) const;
Mike Kleinb82edcc2018-07-10 18:25:03 +000044 void apply(SkRasterPipeline*) const;
Brian Osmanf018b7d2018-06-13 17:21:19 -040045
46 Flags flags;
Mike Klein6968f9c2018-05-24 12:33:23 -040047
Mike Kleinc3a54192018-07-11 11:14:03 -040048 bool srcTF_is_sRGB,
49 dstTF_is_sRGB;
Mike Klein34ab0f22018-05-30 11:07:47 -040050 SkColorSpaceTransferFn srcTF, // Apply for linearize.
51 dstTFInv; // Apply for encode.
Brian Osmanf018b7d2018-06-13 17:21:19 -040052 float src_to_dst_matrix[9]; // Apply this 3x3 column-major matrix for gamut_transform.
Mike Klein6968f9c2018-05-24 12:33:23 -040053};
54
Mike Klein6968f9c2018-05-24 12:33:23 -040055#endif//SkColorSpaceXformSteps_DEFINED