• 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 "SkScalar.h"
12 
13 class SK_API SkColorMatrix {
14 public:
15     enum {
16         kCount = 20
17     };
18     SkScalar    fMat[kCount];
19 
20     enum Elem {
21         kR_Scale    = 0,
22         kG_Scale    = 6,
23         kB_Scale    = 12,
24         kA_Scale    = 18,
25 
26         kR_Trans    = 4,
27         kG_Trans    = 9,
28         kB_Trans    = 14,
29         kA_Trans    = 19,
30     };
31 
32     void setIdentity();
33     void setScale(SkScalar rScale, SkScalar gScale, SkScalar bScale,
34                   SkScalar aScale = SK_Scalar1);
35     void preScale(SkScalar rScale, SkScalar gScale, SkScalar bScale,
36                   SkScalar aScale = SK_Scalar1);
37     void postScale(SkScalar rScale, SkScalar gScale, SkScalar bScale,
38                    SkScalar aScale = SK_Scalar1);
39     void postTranslate(SkScalar rTrans, SkScalar gTrans, SkScalar bTrans,
40                        SkScalar aTrans = 0);
41 
42     enum Axis {
43         kR_Axis = 0,
44         kG_Axis = 1,
45         kB_Axis = 2
46     };
47     void setRotate(Axis, SkScalar degrees);
48     void setSinCos(Axis, SkScalar sine, SkScalar cosine);
49     void preRotate(Axis, SkScalar degrees);
50     void postRotate(Axis, SkScalar degrees);
51 
52     void setConcat(const SkColorMatrix& a, const SkColorMatrix& b);
preConcat(const SkColorMatrix & mat)53     void preConcat(const SkColorMatrix& mat) { this->setConcat(*this, mat); }
postConcat(const SkColorMatrix & mat)54     void postConcat(const SkColorMatrix& mat) { this->setConcat(mat, *this); }
55 
56     void setSaturation(SkScalar sat);
57     void setRGB2YUV();
58     void setYUV2RGB();
59 
60     bool operator==(const SkColorMatrix& other) const {
61         return 0 == memcmp(fMat, other.fMat, sizeof(fMat));
62     }
63 
64     bool operator!=(const SkColorMatrix& other) const { return !((*this) == other); }
65 
66     static bool NeedsClamping(const SkScalar[20]);
67     static void SetConcat(SkScalar result[20], const SkScalar outer[20], const SkScalar inner[20]);
68 };
69 
70 #endif
71