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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkTypes.h" |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 11 | |
Herb Derby | 5ddc34c | 2020-02-01 20:38:30 -0500 | [diff] [blame] | 12 | // Contains useful mask routines for SkMaskSwizzler |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 13 | class SkMasks { |
| 14 | public: |
Herb Derby | 5ddc34c | 2020-02-01 20:38:30 -0500 | [diff] [blame] | 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 | }; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 21 | |
Herb Derby | 5ddc34c | 2020-02-01 20:38:30 -0500 | [diff] [blame] | 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 |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 30 | struct InputMasks { |
| 31 | uint32_t red; |
| 32 | uint32_t green; |
| 33 | uint32_t blue; |
| 34 | uint32_t alpha; |
| 35 | }; |
| 36 | |
Herb Derby | 5ddc34c | 2020-02-01 20:38:30 -0500 | [diff] [blame] | 37 | // Create the masks object |
Mike Klein | 65e8417 | 2019-02-13 12:25:55 -0500 | [diff] [blame] | 38 | static SkMasks* CreateMasks(InputMasks masks, int bytesPerPixel); |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 39 | |
Herb Derby | 5ddc34c | 2020-02-01 20:38:30 -0500 | [diff] [blame] | 40 | // Get a color component |
scroggo | 8b17dcb | 2015-09-30 12:26:49 -0700 | [diff] [blame] | 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; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 45 | |
Herb Derby | 5ddc34c | 2020-02-01 20:38:30 -0500 | [diff] [blame] | 46 | // Getter for the alpha mask |
| 47 | // The alpha mask may be used in other decoding modes |
scroggo | 8b17dcb | 2015-09-30 12:26:49 -0700 | [diff] [blame] | 48 | uint32_t getAlphaMask() const { |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 49 | return fAlpha.mask; |
| 50 | } |
| 51 | |
| 52 | private: |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 53 | const MaskInfo fRed; |
| 54 | const MaskInfo fGreen; |
| 55 | const MaskInfo fBlue; |
| 56 | const MaskInfo fAlpha; |
| 57 | }; |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 58 | |
| 59 | #endif |