msarett | 31d097e8 | 2016-10-11 12:15:03 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 13 | class SkColorSpace; |
| 14 | |
Matt Sarett | afc0b0f | 2016-10-18 10:21:45 -0400 | [diff] [blame] | 15 | class SK_API SkColorSpaceXform : SkNoncopyable { |
msarett | 31d097e8 | 2016-10-11 12:15:03 -0700 | [diff] [blame] | 16 | public: |
| 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 Sarett | 379938e | 2017-01-12 18:34:29 -0500 | [diff] [blame] | 30 | |
| 31 | // Unsigned, big-endian, 16-bit integer |
Matt Sarett | 7a090c4 | 2017-01-17 12:22:48 -0500 | [diff] [blame^] | 32 | kRGB_U16_BE_ColorFormat, // Src only |
Matt Sarett | 379938e | 2017-01-12 18:34:29 -0500 | [diff] [blame] | 33 | kRGBA_U16_BE_ColorFormat, // Src only |
| 34 | |
| 35 | kRGBA_F16_ColorFormat, // Dst only |
| 36 | kRGBA_F32_ColorFormat, // Dst only |
msarett | 31d097e8 | 2016-10-11 12:15:03 -0700 | [diff] [blame] | 37 | }; |
| 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| |
msarett | 31d097e8 | 2016-10-11 12:15:03 -0700 | [diff] [blame] | 50 | * @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 Sarett | f489886 | 2016-10-16 10:20:41 -0400 | [diff] [blame] | 57 | SkAlphaType alphaType) const; |
msarett | 31d097e8 | 2016-10-11 12:15:03 -0700 | [diff] [blame] | 58 | |
| 59 | virtual ~SkColorSpaceXform() {} |
| 60 | |
| 61 | protected: |
msarett | 31d097e8 | 2016-10-11 12:15:03 -0700 | [diff] [blame] | 62 | SkColorSpaceXform() {} |
| 63 | }; |
| 64 | |
| 65 | #endif |