• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <memory.h>
13 
14 class SK_API SkColorMatrix {
15 public:
16     void setIdentity();
17     void setScale(float rScale, float gScale, float bScale, float aScale = 1.0f);
18 
setRowMajor(const float src[20])19     void setRowMajor(const float src[20]) {
20         memcpy(fMat, src, sizeof(fMat));
21     }
22 
getRowMajor(float dst[20])23     void getRowMajor(float dst[20]) const {
24         memcpy(dst, fMat, sizeof(fMat));
25     }
26 
27     enum Axis {
28         kR_Axis = 0,
29         kG_Axis = 1,
30         kB_Axis = 2
31     };
32     void setRotate(Axis, float degrees);
33     void setSinCos(Axis, float sine, float cosine);
34     void preRotate(Axis, float degrees);
35     void postRotate(Axis, float degrees);
36     void postTranslate(float dr, float dg, float db, float da);
37 
38     void setConcat(const SkColorMatrix& a, const SkColorMatrix& b);
preConcat(const SkColorMatrix & mat)39     void preConcat(const SkColorMatrix& mat) { this->setConcat(*this, mat); }
postConcat(const SkColorMatrix & mat)40     void postConcat(const SkColorMatrix& mat) { this->setConcat(mat, *this); }
41 
42     void setSaturation(float sat);
43     void setRGB2YUV();
44     void setYUV2RGB();
45 
46     bool operator==(const SkColorMatrix& other) const {
47         return 0 == memcmp(fMat, other.fMat, sizeof(fMat));
48     }
49 
50     bool operator!=(const SkColorMatrix& other) const { return !((*this) == other); }
51 
get20(float m[20])52     float* get20(float m[20]) const {
53         memcpy(m, fMat, sizeof(fMat));
54         return m;
55     }
set20(const float m[20])56     void set20(const float m[20]) {
57         memcpy(fMat, m, sizeof(fMat));
58     }
59 
60 private:
61     float fMat[20];
62 
63     friend class SkColorFilters;
64 };
65 
66 #endif
67