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