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