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 postTranslate(SkScalar rTrans, SkScalar gTrans, SkScalar bTrans, 36 SkScalar aTrans = 0); 37 38 enum Axis { 39 kR_Axis = 0, 40 kG_Axis = 1, 41 kB_Axis = 2 42 }; 43 void setRotate(Axis, SkScalar degrees); 44 void setSinCos(Axis, SkScalar sine, SkScalar cosine); 45 void preRotate(Axis, SkScalar degrees); 46 void postRotate(Axis, SkScalar degrees); 47 48 void setConcat(const SkColorMatrix& a, const SkColorMatrix& b); preConcat(const SkColorMatrix & mat)49 void preConcat(const SkColorMatrix& mat) { this->setConcat(*this, mat); } postConcat(const SkColorMatrix & mat)50 void postConcat(const SkColorMatrix& mat) { this->setConcat(mat, *this); } 51 52 void setSaturation(SkScalar sat); 53 void setRGB2YUV(); 54 void setYUV2RGB(); 55 56 bool operator==(const SkColorMatrix& other) const { 57 return 0 == memcmp(fMat, other.fMat, sizeof(fMat)); 58 } 59 60 bool operator!=(const SkColorMatrix& other) const { return !((*this) == other); } 61 62 static bool NeedsClamping(const SkScalar[20]); 63 static void SetConcat(SkScalar result[20], const SkScalar outer[20], const SkScalar inner[20]); 64 }; 65 66 #endif 67