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