blob: 07c64ca7e6a466452ff2c005cde4af0da36dbcb4 [file] [log] [blame]
msarett74114382015-03-16 11:55:18 -07001/*
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 */
msarett4ab9d5f2015-08-06 15:34:42 -07007#ifndef SkMasks_DEFINED
8#define SkMasks_DEFINED
9
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkTypes.h"
msarett74114382015-03-16 11:55:18 -070011
Herb Derby5ddc34c2020-02-01 20:38:30 -050012// Contains useful mask routines for SkMaskSwizzler
msarett74114382015-03-16 11:55:18 -070013class SkMasks {
14public:
Herb Derby5ddc34c2020-02-01 20:38:30 -050015 //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 };
msarett74114382015-03-16 11:55:18 -070021
Herb Derby5ddc34c2020-02-01 20:38:30 -050022 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
msarett74114382015-03-16 11:55:18 -070030 struct InputMasks {
31 uint32_t red;
32 uint32_t green;
33 uint32_t blue;
34 uint32_t alpha;
35 };
36
Herb Derby5ddc34c2020-02-01 20:38:30 -050037 // Create the masks object
Mike Klein65e84172019-02-13 12:25:55 -050038 static SkMasks* CreateMasks(InputMasks masks, int bytesPerPixel);
msarett74114382015-03-16 11:55:18 -070039
Herb Derby5ddc34c2020-02-01 20:38:30 -050040 // Get a color component
scroggo8b17dcb2015-09-30 12:26:49 -070041 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;
msarett74114382015-03-16 11:55:18 -070045
Herb Derby5ddc34c2020-02-01 20:38:30 -050046 // Getter for the alpha mask
47 // The alpha mask may be used in other decoding modes
scroggo8b17dcb2015-09-30 12:26:49 -070048 uint32_t getAlphaMask() const {
msarett74114382015-03-16 11:55:18 -070049 return fAlpha.mask;
50 }
51
52private:
msarett74114382015-03-16 11:55:18 -070053 const MaskInfo fRed;
54 const MaskInfo fGreen;
55 const MaskInfo fBlue;
56 const MaskInfo fAlpha;
57};
msarett4ab9d5f2015-08-06 15:34:42 -070058
59#endif