SkColorMatrix.h 1.8 KB

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