blob: eb72e8a77af956db6f6dd3f3e143cf2c2a1daadf [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
Kevin Lubick3296f7b2022-08-11 08:17:29 -040012#include <cstdint>
13
msarett74114382015-03-16 11:55:18 -070014class SkMasks {
15public:
Kevin Lubickf664a192024-01-18 14:59:38 +000016 // Contains all of the information for a single mask
Herb Derby5ddc34c2020-02-01 20:38:30 -050017 struct MaskInfo {
18 uint32_t mask;
19 uint32_t shift; // To the left
20 uint32_t size; // Of mask width
21 };
msarett74114382015-03-16 11:55:18 -070022
Kevin Lubickf664a192024-01-18 14:59:38 +000023 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 Derby5ddc34c2020-02-01 20:38:30 -050028
Kevin Lubickf664a192024-01-18 14:59:38 +000029 // 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
Kevin Lubickf664a192024-01-18 14:59:38 +000046 // Getter for the alpha mask
47 // The alpha mask may be used in other decoding modes
48 uint32_t getAlphaMask() const { return fAlpha.mask; }
msarett74114382015-03-16 11:55:18 -070049
50private:
msarett74114382015-03-16 11:55:18 -070051 const MaskInfo fRed;
52 const MaskInfo fGreen;
53 const MaskInfo fBlue;
54 const MaskInfo fAlpha;
55};
msarett4ab9d5f2015-08-06 15:34:42 -070056
57#endif