diff options
author | msarett <msarett@google.com> | 2016-10-11 12:15:03 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-10-11 12:15:03 -0700 |
commit | 31d097e865f266c8398f45114e4c75c0dfdef058 (patch) | |
tree | 474aa98958055b0d7e85483c014fccb4235ef7ef /include/core/SkColorSpaceXform.h | |
parent | 7a1c53d0f67dcc98937ee5f06c6ba3f3b24882c6 (diff) |
Add SkColorSpaceXform to the public API
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2390263002
Review-Url: https://codereview.chromium.org/2390263002
Diffstat (limited to 'include/core/SkColorSpaceXform.h')
-rw-r--r-- | include/core/SkColorSpaceXform.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/include/core/SkColorSpaceXform.h b/include/core/SkColorSpaceXform.h new file mode 100644 index 0000000000..15b3d49ee4 --- /dev/null +++ b/include/core/SkColorSpaceXform.h @@ -0,0 +1,67 @@ +/* + * Copyright 2016 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkColorSpaceXform_DEFINED +#define SkColorSpaceXform_DEFINED + +#include "SkImageInfo.h" + +class SkColorSpace; + +class SkColorSpaceXform : SkNoncopyable { +public: + + /** + * Create an object to handle color space conversions. + * + * @param srcSpace The encoded color space. + * @param dstSpace The destination color space. + * + */ + static std::unique_ptr<SkColorSpaceXform> New(SkColorSpace* srcSpace, SkColorSpace* dstSpace); + + enum ColorFormat { + kRGBA_8888_ColorFormat, + kBGRA_8888_ColorFormat, + kRGBA_F16_ColorFormat, + kRGBA_F32_ColorFormat, + }; + + /** + * Apply the color conversion to a |src| buffer, storing the output in the |dst| buffer. + * + * F16 and F32 are only supported as dst color formats, and only when the dst color space + * is linear. This function will return false in unsupported cases. + * + * @param dst Stored in the format described by |dstColorFormat| + * @param src Stored in the format described by |srcColorFormat| + * @param len Number of pixels in the buffers + * @param dstColorFormat Describes color format of |dst| + * @param srcColorFormat Describes color format of |src| + * Must be kRGBA_8888 or kBGRA_8888 + * @param alphaType Describes alpha properties of the |dst| (and |src|) + * kUnpremul preserves input alpha values + * kPremul performs a premultiplication and also preserves alpha values + * kOpaque optimization hint, |dst| alphas set to 1 + * + */ + bool apply(ColorFormat dstFormat, void* dst, ColorFormat srcFormat, const void* src, int count, + SkAlphaType alphaType) const { + return this->onApply(dstFormat, dst, srcFormat, src, count, alphaType); + } + + + virtual ~SkColorSpaceXform() {} + +protected: + virtual bool onApply(ColorFormat dstFormat, void* dst, ColorFormat srcFormat, const void* src, + int count, SkAlphaType alphaType) const = 0; + + SkColorSpaceXform() {} +}; + +#endif |