openMSX
PixelFormat.hh
Go to the documentation of this file.
1#ifndef PIXELFORMAT_HH
2#define PIXELFORMAT_HH
3
4#include "narrow.hh"
5#include <cstdint>
6
7namespace openmsx {
8
10{
11public:
12 PixelFormat() = default;
13 PixelFormat(unsigned bpp_,
14 uint32_t Rmask_, uint8_t Rshift_, uint8_t Rloss_,
15 uint32_t Gmask_, uint8_t Gshift_, uint8_t Gloss_,
16 uint32_t Bmask_, uint8_t Bshift_, uint8_t Bloss_,
17 uint32_t Amask_, uint8_t Ashift_, uint8_t Aloss_)
18 : Rmask (Rmask_), Gmask (Gmask_), Bmask (Bmask_), Amask (Amask_)
19 , Rshift(Rshift_), Gshift(Gshift_), Bshift(Bshift_), Ashift(Ashift_)
20 , Rloss (Rloss_), Gloss (Gloss_), Bloss (Bloss_), Aloss (Aloss_)
21 , bpp(narrow<uint8_t>(bpp_))
22 , bytesPerPixel(narrow<uint8_t>((bpp + 7) / 8)) {}
23
24 [[nodiscard]] unsigned getBpp() const { return bpp; }
25 [[nodiscard]] unsigned getBytesPerPixel() const { return bytesPerPixel; }
26
27 [[nodiscard]] unsigned getRmask() const { return Rmask; }
28 [[nodiscard]] unsigned getGmask() const { return Gmask; }
29 [[nodiscard]] unsigned getBmask() const { return Bmask; }
30 [[nodiscard]] unsigned getAmask() const { return Amask; }
31
32 [[nodiscard]] unsigned getRshift() const { return Rshift; }
33 [[nodiscard]] unsigned getGshift() const { return Gshift; }
34 [[nodiscard]] unsigned getBshift() const { return Bshift; }
35 [[nodiscard]] unsigned getAshift() const { return Ashift; }
36
37 [[nodiscard]] unsigned getRloss() const { return Rloss; }
38 [[nodiscard]] unsigned getGloss() const { return Gloss; }
39 [[nodiscard]] unsigned getBloss() const { return Bloss; }
40 [[nodiscard]] unsigned getAloss() const { return Aloss; }
41
42 [[nodiscard]] unsigned map(unsigned r, unsigned g, unsigned b) const
43 {
44 return ((r >> Rloss) << Rshift) |
45 ((g >> Gloss) << Gshift) |
46 ((b >> Bloss) << Bshift) |
47 Amask;
48 }
49
50private:
51 uint32_t Rmask, Gmask, Bmask, Amask;
52 uint8_t Rshift, Gshift, Bshift, Ashift;
53 uint8_t Rloss, Gloss, Bloss, Aloss;
54 uint8_t bpp, bytesPerPixel;
55};
56
57} // namespace openmsx
58
59#endif
int g
PixelFormat(unsigned bpp_, uint32_t Rmask_, uint8_t Rshift_, uint8_t Rloss_, uint32_t Gmask_, uint8_t Gshift_, uint8_t Gloss_, uint32_t Bmask_, uint8_t Bshift_, uint8_t Bloss_, uint32_t Amask_, uint8_t Ashift_, uint8_t Aloss_)
Definition: PixelFormat.hh:13
unsigned getAshift() const
Definition: PixelFormat.hh:35
unsigned getGloss() const
Definition: PixelFormat.hh:38
unsigned getBshift() const
Definition: PixelFormat.hh:34
unsigned map(unsigned r, unsigned g, unsigned b) const
Definition: PixelFormat.hh:42
unsigned getBpp() const
Definition: PixelFormat.hh:24
unsigned getBloss() const
Definition: PixelFormat.hh:39
unsigned getRshift() const
Definition: PixelFormat.hh:32
unsigned getGmask() const
Definition: PixelFormat.hh:28
unsigned getAmask() const
Definition: PixelFormat.hh:30
unsigned getAloss() const
Definition: PixelFormat.hh:40
unsigned getGshift() const
Definition: PixelFormat.hh:33
unsigned getBytesPerPixel() const
Definition: PixelFormat.hh:25
unsigned getRmask() const
Definition: PixelFormat.hh:27
unsigned getBmask() const
Definition: PixelFormat.hh:29
unsigned getRloss() const
Definition: PixelFormat.hh:37
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr To narrow(From from) noexcept
Definition: narrow.hh:37