blob: 0c4fd7aa33d836b223fa23d1b0d0941c30281d1b [file] [log] [blame]
msarett31d097e82016-10-11 12:15:03 -07001/*
2 * Copyright 2016 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 SkColorSpaceXform_DEFINED
9#define SkColorSpaceXform_DEFINED
10
11#include "SkImageInfo.h"
12
13class SkColorSpace;
14
Matt Sarettafc0b0f2016-10-18 10:21:45 -040015class SK_API SkColorSpaceXform : SkNoncopyable {
msarett31d097e82016-10-11 12:15:03 -070016public:
17
18 /**
19 * Create an object to handle color space conversions.
20 *
21 * @param srcSpace The encoded color space.
22 * @param dstSpace The destination color space.
23 *
24 */
25 static std::unique_ptr<SkColorSpaceXform> New(SkColorSpace* srcSpace, SkColorSpace* dstSpace);
26
27 enum ColorFormat {
28 kRGBA_8888_ColorFormat,
29 kBGRA_8888_ColorFormat,
Matt Sarett379938e2017-01-12 18:34:29 -050030
31 // Unsigned, big-endian, 16-bit integer
Matt Sarett7a090c42017-01-17 12:22:48 -050032 kRGB_U16_BE_ColorFormat, // Src only
Matt Sarett379938e2017-01-12 18:34:29 -050033 kRGBA_U16_BE_ColorFormat, // Src only
34
35 kRGBA_F16_ColorFormat, // Dst only
36 kRGBA_F32_ColorFormat, // Dst only
msarett31d097e82016-10-11 12:15:03 -070037 };
38
39 /**
40 * Apply the color conversion to a |src| buffer, storing the output in the |dst| buffer.
41 *
42 * F16 and F32 are only supported as dst color formats, and only when the dst color space
43 * is linear. This function will return false in unsupported cases.
44 *
45 * @param dst Stored in the format described by |dstColorFormat|
46 * @param src Stored in the format described by |srcColorFormat|
47 * @param len Number of pixels in the buffers
48 * @param dstColorFormat Describes color format of |dst|
49 * @param srcColorFormat Describes color format of |src|
msarett31d097e82016-10-11 12:15:03 -070050 * @param alphaType Describes alpha properties of the |dst| (and |src|)
51 * kUnpremul preserves input alpha values
52 * kPremul performs a premultiplication and also preserves alpha values
53 * kOpaque optimization hint, |dst| alphas set to 1
54 *
55 */
56 bool apply(ColorFormat dstFormat, void* dst, ColorFormat srcFormat, const void* src, int count,
Matt Sarettf4898862016-10-16 10:20:41 -040057 SkAlphaType alphaType) const;
msarett31d097e82016-10-11 12:15:03 -070058
59 virtual ~SkColorSpaceXform() {}
60
61protected:
msarett31d097e82016-10-11 12:15:03 -070062 SkColorSpaceXform() {}
63};
64
65#endif