Skia
2D Graphics Library
SkColorFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2006 The Android Open Source Project
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 SkColorFilter_DEFINED
9 #define SkColorFilter_DEFINED
10 
11 #include "include/core/SkColor.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/private/base/SkAPI.h"
15 
16 #include <cstddef>
17 #include <cstdint>
18 #include <utility>
19 
20 class SkColorMatrix;
21 class SkColorSpace;
22 class SkColorTable;
23 
24 enum class SkBlendMode;
25 struct SkDeserialProcs;
26 
35 class SK_API SkColorFilter : public SkFlattenable {
36 public:
41  bool asAColorMode(SkColor* color, SkBlendMode* mode) const;
42 
47  bool asAColorMatrix(float matrix[20]) const;
48 
49  // Returns true if the filter is guaranteed to never change the alpha of a color it filters.
50  bool isAlphaUnchanged() const;
51 
53 
58  SkColor4f filterColor4f(const SkColor4f& srcColor, SkColorSpace* srcCS,
59  SkColorSpace* dstCS) const;
60 
67 
73 
74  static sk_sp<SkColorFilter> Deserialize(const void* data, size_t size,
75  const SkDeserialProcs* procs = nullptr);
76 
77 private:
78  SkColorFilter() = default;
79  friend class SkColorFilterBase;
80 
81  using INHERITED = SkFlattenable;
82 };
83 
84 class SK_API SkColorFilters {
85 public:
87  sk_sp<SkColorFilter> inner) {
88  return outer ? outer->makeComposed(std::move(inner))
89  : std::move(inner);
90  }
91 
92  // Blends between the constant color (src) and input color (dst) based on the SkBlendMode.
93  // If the color space is null, the constant color is assumed to be defined in sRGB.
96 
98  static sk_sp<SkColorFilter> Matrix(const float rowMajor[20]);
99 
100  // A version of Matrix which operates in HSLA space instead of RGBA.
101  // I.e. HSLA-to-RGBA(Matrix(RGBA-to-HSLA(input))).
103  static sk_sp<SkColorFilter> HSLAMatrix(const float rowMajor[20]);
104 
108 
120  static sk_sp<SkColorFilter> Table(const uint8_t table[256]);
121 
128  static sk_sp<SkColorFilter> TableARGB(const uint8_t tableA[256],
129  const uint8_t tableR[256],
130  const uint8_t tableG[256],
131  const uint8_t tableB[256]);
132 
137 
145 
146 private:
147  SkColorFilters() = delete;
148 };
149 
150 #endif
SkBlendMode
Blends are operators that take in two colors (source, destination) and return a new color.
Definition: SkBlendMode.h:38
Types, consts, functions, and macros for colors.
uint32_t SkColor
32-bit ARGB color value, unpremultiplied.
Definition: SkColor.h:37
ColorFilters are optional objects in the drawing pipeline.
Definition: SkColorFilter.h:35
bool asAColorMode(SkColor *color, SkBlendMode *mode) const
If the filter can be represented by a source color plus Mode, this returns true, and sets (if not NUL...
bool asAColorMatrix(float matrix[20]) const
If the filter can be represented by a 5x4 matrix, this returns true, and sets the matrix appropriatel...
bool isAlphaUnchanged() const
sk_sp< SkColorFilter > makeComposed(sk_sp< SkColorFilter > inner) const
Construct a colorfilter whose effect is to first apply the inner filter and then apply this filter,...
SkColor4f filterColor4f(const SkColor4f &srcColor, SkColorSpace *srcCS, SkColorSpace *dstCS) const
Converts the src color (in src colorspace), into the dst colorspace, then applies this filter to it,...
sk_sp< SkColorFilter > makeWithWorkingColorSpace(sk_sp< SkColorSpace >) const
Return a colorfilter that will compute this filter in a specific color space.
static sk_sp< SkColorFilter > Deserialize(const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
SkColor filterColor(SkColor) const
Definition: SkColorFilter.h:84
static sk_sp< SkColorFilter > Lighting(SkColor mul, SkColor add)
Create a colorfilter that multiplies the RGB channels by one color, and then adds a second color,...
static sk_sp< SkColorFilter > LinearToSRGBGamma()
static sk_sp< SkColorFilter > Blend(const SkColor4f &c, sk_sp< SkColorSpace >, SkBlendMode mode)
static sk_sp< SkColorFilter > HSLAMatrix(const float rowMajor[20])
static sk_sp< SkColorFilter > Blend(SkColor c, SkBlendMode mode)
static sk_sp< SkColorFilter > TableARGB(const uint8_t tableA[256], const uint8_t tableR[256], const uint8_t tableG[256], const uint8_t tableB[256])
Create a table colorfilter, with a different table for each component [A, R, G, B].
static sk_sp< SkColorFilter > HSLAMatrix(const SkColorMatrix &)
static sk_sp< SkColorFilter > Table(sk_sp< SkColorTable > table)
Create a table colorfilter that holds a ref to the shared color table.
static sk_sp< SkColorFilter > Matrix(const float rowMajor[20])
static sk_sp< SkColorFilter > SRGBToLinearGamma()
static sk_sp< SkColorFilter > Compose(const sk_sp< SkColorFilter > &outer, sk_sp< SkColorFilter > inner)
Definition: SkColorFilter.h:86
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)
static sk_sp< SkColorFilter > Table(const uint8_t table[256])
Create a table colorfilter, copying the table into the filter, and applying it to all 4 components.
static sk_sp< SkColorFilter > Lerp(float t, sk_sp< SkColorFilter > dst, sk_sp< SkColorFilter > src)
Definition: SkColorMatrix.h:18
Definition: SkColorSpace.h:107
SkColorTable holds the lookup tables for each channel (ARGB) used to define the filter behavior of Sk...
Definition: SkColorTable.h:25
SkFlattenable is the base class for objects that need to be flattened into a data stream for either t...
Definition: SkFlattenable.h:28
SkFlattenable()
Definition: SkFlattenable.h:43
RGBA color value, holding four floating point components.
Definition: SkSerialProcs.h:97