• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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      */
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;
59 
60     /*
61      *
62      * Getter for the alpha mask
63      * The alpha mask may be used in other decoding modes
64      *
65      */
getAlphaMask()66      uint32_t getAlphaMask() const {
67         return fAlpha.mask;
68      }
69 
70 private:
71 
72     /*
73      *
74      * Constructor
75      *
76      */
77     SkMasks(const MaskInfo& red, const MaskInfo& green, const MaskInfo& blue,
78             const MaskInfo& alpha);
79 
80     const MaskInfo fRed;
81     const MaskInfo fGreen;
82     const MaskInfo fBlue;
83     const MaskInfo fAlpha;
84 };
85 
86 #endif
87