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 15 class SK_API SkColorSpaceXform : SkNoncopyable { 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, 30 31 // Unsigned, big-endian, 16-bit integer 32 kRGB_U16_BE_ColorFormat, // Src only 33 kRGBA_U16_BE_ColorFormat, // Src only 34 35 kRGBA_F16_ColorFormat, 36 kRGBA_F32_ColorFormat, 37 38 kBGR_565_ColorFormat, // Dst only, kOpaque only 39 }; 40 41 /** 42 * Apply the color conversion to a |src| buffer, storing the output in the |dst| buffer. 43 * 44 * F16 and F32 are only supported when the color space is linear. This function will return 45 * false in unsupported cases. 46 * 47 * @param dst Stored in the format described by |dstColorFormat| 48 * @param src Stored in the format described by |srcColorFormat| 49 * @param len Number of pixels in the buffers 50 * @param dstColorFormat Describes color format of |dst| 51 * @param srcColorFormat Describes color format of |src| 52 * @param alphaType Describes alpha properties of the |dst| (and |src|) 53 * kUnpremul preserves input alpha values 54 * kPremul performs a premultiplication and also preserves alpha values 55 * kOpaque optimization hint, |dst| alphas set to 1 56 * 57 */ 58 bool apply(ColorFormat dstFormat, void* dst, ColorFormat srcFormat, const void* src, int count, 59 SkAlphaType alphaType) const; 60 ~SkColorSpaceXform()61 virtual ~SkColorSpaceXform() {} 62 63 enum AlphaOp { 64 kPreserve_AlphaOp, // just transfer src-alpha to dst-alpha 65 kPremul_AlphaOp, // like kPreserve, but multiplies RGB by it 66 kSrcIsOpaque_AlphaOp, // src alphas are all 1, this is a perf hint 67 }; 68 static bool Apply(SkColorSpace* dstCS, ColorFormat dstFormat, void* dst, 69 SkColorSpace* srcCS, ColorFormat srcFormat, const void* src, 70 int count, AlphaOp); 71 72 protected: SkColorSpaceXform()73 SkColorSpaceXform() {} 74 }; 75 76 #endif 77