SkMasks.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright 2015 Google Inc.
  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 SkMasks_DEFINED
  8. #define SkMasks_DEFINED
  9. #include "include/core/SkTypes.h"
  10. /*
  11. *
  12. * Contains useful mask routines for SkMaskSwizzler
  13. *
  14. */
  15. class SkMasks {
  16. public:
  17. /*
  18. *
  19. * Input bit masks format
  20. *
  21. */
  22. struct InputMasks {
  23. uint32_t red;
  24. uint32_t green;
  25. uint32_t blue;
  26. uint32_t alpha;
  27. };
  28. /*
  29. *
  30. * Contains all of the information for a single mask
  31. *
  32. */
  33. struct MaskInfo {
  34. uint32_t mask;
  35. uint32_t shift;
  36. uint32_t size;
  37. };
  38. /*
  39. *
  40. * Create the masks object
  41. *
  42. */
  43. static SkMasks* CreateMasks(InputMasks masks, int bytesPerPixel);
  44. /*
  45. *
  46. * Get a color component
  47. *
  48. */
  49. uint8_t getRed(uint32_t pixel) const;
  50. uint8_t getGreen(uint32_t pixel) const;
  51. uint8_t getBlue(uint32_t pixel) const;
  52. uint8_t getAlpha(uint32_t pixel) const;
  53. /*
  54. *
  55. * Getter for the alpha mask
  56. * The alpha mask may be used in other decoding modes
  57. *
  58. */
  59. uint32_t getAlphaMask() const {
  60. return fAlpha.mask;
  61. }
  62. private:
  63. /*
  64. *
  65. * Constructor
  66. *
  67. */
  68. SkMasks(const MaskInfo& red, const MaskInfo& green, const MaskInfo& blue,
  69. const MaskInfo& alpha);
  70. const MaskInfo fRed;
  71. const MaskInfo fGreen;
  72. const MaskInfo fBlue;
  73. const MaskInfo fAlpha;
  74. };
  75. #endif