Debian Codegraph @

mednafen/video/surface.h

raw symbols SCIP
1 #ifndef __MDFN_SURFACE_H
2 #define __MDFN_SURFACE_H
3
4 #if defined(WANT_32BPP)
5 #define RED_SHIFT 16
6 #define GREEN_SHIFT 8
7 #define BLUE_SHIFT 0
8 #define ALPHA_SHIFT 24
9 #define MAKECOLOR(r, g, b, a) ((r << RED_SHIFT) | (g << GREEN_SHIFT) | (b << BLUE_SHIFT) | (a << ALPHA_SHIFT))
10 #elif defined(WANT_16BPP) && defined(FRONTEND_SUPPORTS_RGB565)
11 /* 16bit color - RGB565 */
12 #define RED_MASK 0xf800
13 #define GREEN_MASK 0x7e0
14 #define BLUE_MASK 0x1f
15 #define RED_EXPAND 3
16 #define GREEN_EXPAND 2
17 #define BLUE_EXPAND 3
18 #define RED_SHIFT 11
19 #define GREEN_SHIFT 5
20 #define BLUE_SHIFT 0
21 #define MAKECOLOR(r, g, b, a) (((r >> RED_EXPAND) << RED_SHIFT) | ((g >> GREEN_EXPAND) << GREEN_SHIFT) | ((b >> BLUE_EXPAND) << BLUE_SHIFT))
22 #elif defined(WANT_16BPP) && !defined(FRONTEND_SUPPORTS_RGB565)
23 /* 16bit color - RGB555 */
24 #define RED_MASK 0x7c00
25 #define GREEN_MASK 0x3e0
26 #define BLUE_MASK 0x1f
27 #define RED_EXPAND 3
28 #define GREEN_EXPAND 3
29 #define BLUE_EXPAND 3
30 #define RED_SHIFT 10
31 #define GREEN_SHIFT 5
32 #define BLUE_SHIFT 0
33 #define MAKECOLOR(r, g, b, a) (((r >> RED_EXPAND) << RED_SHIFT) | ((g >> GREEN_EXPAND) << GREEN_SHIFT) | ((b >> BLUE_EXPAND) << BLUE_SHIFT))
34 #endif
35
36 struct MDFN_PaletteEntry
37 {
38 uint8 r, g, b;
39 };
40
41 typedef struct
42 {
43 int32 x, y, w, h;
44 } MDFN_Rect;
45
46 enum
47 {
48 MDFN_COLORSPACE_RGB = 0,
49 MDFN_COLORSPACE_YCbCr = 1,
50 MDFN_COLORSPACE_YUV = 2, // TODO, maybe.
51 };
52
53 class MDFN_PixelFormat
54 {
55 public:
56
57 MDFN_PixelFormat();
58 MDFN_PixelFormat(const unsigned int p_colorspace, const uint8 p_rs, const uint8 p_gs, const uint8 p_bs, const uint8 p_as);
59
60 unsigned int bpp;
61 unsigned int colorspace;
62
63 union
64 {
65 uint8 Rshift; // Bit position of the lowest bit of the red component
66 uint8 Yshift;
67 };
68
69 union
70 {
71 uint8 Gshift; // [...] green component
72 uint8 Ushift;
73 uint8 Cbshift;
74 };
75
76 union
77 {
78 uint8 Bshift; // [...] blue component
79 uint8 Vshift;
80 uint8 Crshift;
81 };
82
83 uint8 Ashift; // [...] alpha component.
84 }; // MDFN_PixelFormat;
85
86 // Supports 32-bit RGBA
87 // 16-bit is WIP
88 class MDFN_Surface //typedef struct
89 {
90 public:
91
92 MDFN_Surface();
93 MDFN_Surface(void *const p_pixels, const uint32 p_width, const uint32 p_height, const uint32 p_pitchinpix, const MDFN_PixelFormat &nf);
94
95 ~MDFN_Surface();
96
97 uint8 *pixels8;
98 uint16 *pixels16;
99 uint32 *pixels;
100
101 // w, h, and pitch32 should always be > 0
102 int32 w;
103 int32 h;
104
105 union
106 {
107 int32 pitch32; // In pixels, not in bytes.
108 int32 pitchinpix; // New name, new code should use this.
109 };
110
111 MDFN_PaletteEntry *palette;
112
113 MDFN_PixelFormat format;
114
115 void SetFormat(const MDFN_PixelFormat &new_format, bool convert);
116
117 private:
118 void Init(void *const p_pixels, const uint32 p_width, const uint32 p_height, const uint32 p_pitchinpix, const MDFN_PixelFormat &nf);
119 };
120
121 #endif