Skia
2D Graphics Library
SkColorMatrix.h
Go to the documentation of this file.
1 /*
2  * Copyright 2007 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 SkColorMatrix_DEFINED
9 #define SkColorMatrix_DEFINED
10 
11 #include "include/core/SkTypes.h"
12 
13 #include <algorithm>
14 #include <array>
15 
16 enum SkYUVColorSpace : int;
17 
18 class SK_API SkColorMatrix {
19 public:
20  constexpr SkColorMatrix() : SkColorMatrix(1, 0, 0, 0, 0,
21  0, 1, 0, 0, 0,
22  0, 0, 1, 0, 0,
23  0, 0, 0, 1, 0) {}
24 
25  constexpr SkColorMatrix(float m00, float m01, float m02, float m03, float m04,
26  float m10, float m11, float m12, float m13, float m14,
27  float m20, float m21, float m22, float m23, float m24,
28  float m30, float m31, float m32, float m33, float m34)
29  : fMat { m00, m01, m02, m03, m04,
30  m10, m11, m12, m13, m14,
31  m20, m21, m22, m23, m24,
32  m30, m31, m32, m33, m34 } {}
33 
36 
37  void setIdentity();
38  void setScale(float rScale, float gScale, float bScale, float aScale = 1.0f);
39 
40  void postTranslate(float dr, float dg, float db, float da);
41 
42  void setConcat(const SkColorMatrix& a, const SkColorMatrix& b);
43  void preConcat(const SkColorMatrix& mat) { this->setConcat(*this, mat); }
44  void postConcat(const SkColorMatrix& mat) { this->setConcat(mat, *this); }
45 
46  void setSaturation(float sat);
47 
48  void setRowMajor(const float src[20]) { std::copy_n(src, 20, fMat.begin()); }
49  void getRowMajor(float dst[20]) const { std::copy_n(fMat.begin(), 20, dst); }
50 
51 private:
52  std::array<float, 20> fMat;
53 
54  friend class SkColorFilters;
55 };
56 
57 #endif
SkYUVColorSpace
Definition: SkImageInfo.h:68
Definition: SkColorFilter.h:84
Definition: SkColorMatrix.h:18
constexpr SkColorMatrix(float m00, float m01, float m02, float m03, float m04, float m10, float m11, float m12, float m13, float m14, float m20, float m21, float m22, float m23, float m24, float m30, float m31, float m32, float m33, float m34)
Definition: SkColorMatrix.h:25
static SkColorMatrix RGBtoYUV(SkYUVColorSpace)
void postConcat(const SkColorMatrix &mat)
Definition: SkColorMatrix.h:44
void preConcat(const SkColorMatrix &mat)
Definition: SkColorMatrix.h:43
constexpr SkColorMatrix()
Definition: SkColorMatrix.h:20
static SkColorMatrix YUVtoRGB(SkYUVColorSpace)
void setRowMajor(const float src[20])
Definition: SkColorMatrix.h:48
void getRowMajor(float dst[20]) const
Definition: SkColorMatrix.h:49
void setIdentity()
void setConcat(const SkColorMatrix &a, const SkColorMatrix &b)
void postTranslate(float dr, float dg, float db, float da)
void setSaturation(float sat)
void setScale(float rScale, float gScale, float bScale, float aScale=1.0f)