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