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