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 | |
Kevin Lubick | 3296f7b | 2022-08-11 08:17:29 -0400 | [diff] [blame] | 12 | #include <cstdint> |
| 13 | |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 14 | class SkMasks { |
| 15 | public: |
Kevin Lubick | f664a19 | 2024-01-18 14:59:38 +0000 | [diff] [blame] | 16 | // Contains all of the information for a single mask |
Herb Derby | 5ddc34c | 2020-02-01 20:38:30 -0500 | [diff] [blame] | 17 | struct MaskInfo { |
| 18 | uint32_t mask; |
| 19 | uint32_t shift; // To the left |
| 20 | uint32_t size; // Of mask width |
| 21 | }; |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 22 | |
Kevin Lubick | f664a19 | 2024-01-18 14:59:38 +0000 | [diff] [blame] | 23 | constexpr SkMasks(const MaskInfo red, |
| 24 | const MaskInfo green, |
| 25 | const MaskInfo blue, |
| 26 | const MaskInfo alpha) |
| 27 | : fRed(red), fGreen(green), fBlue(blue), fAlpha(alpha) {} |
Herb Derby | 5ddc34c | 2020-02-01 20:38:30 -0500 | [diff] [blame] | 28 | |
Kevin Lubick | f664a19 | 2024-01-18 14:59:38 +0000 | [diff] [blame] | 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 | |
Kevin Lubick | f664a19 | 2024-01-18 14:59:38 +0000 | [diff] [blame] | 46 | // Getter for the alpha mask |
| 47 | // The alpha mask may be used in other decoding modes |
| 48 | uint32_t getAlphaMask() const { return fAlpha.mask; } |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 49 | |
| 50 | private: |
msarett | 7411438 | 2015-03-16 11:55:18 -0700 | [diff] [blame] | 51 | const MaskInfo fRed; |
| 52 | const MaskInfo fGreen; |
| 53 | const MaskInfo fBlue; |
| 54 | const MaskInfo fAlpha; |
| 55 | }; |
msarett | 4ab9d5f | 2015-08-06 15:34:42 -0700 | [diff] [blame] | 56 | |
| 57 | #endif |