| 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 |
#include <cstdint> |
| 13 |
|
| 14 |
class SkMasks { |
| 15 |
public: |
| 16 |
// Contains all of the information for a single mask |
| 17 |
struct MaskInfo { |
| 18 |
uint32_t mask; |
| 19 |
uint32_t shift; // To the left |
| 20 |
uint32_t size; // Of mask width |
| 21 |
}; |
| 22 |
|
| 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) {} |
| 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 { return fAlpha.mask; } |
| 49 |
|
| 50 |
private: |
| 51 |
const MaskInfo fRed; |
| 52 |
const MaskInfo fGreen; |
| 53 |
const MaskInfo fBlue; |
| 54 |
const MaskInfo fAlpha; |
| 55 |
}; |
| 56 |
|
| 57 |
#endif |