summaryrefslogtreecommitdiff
path: root/subprojects/pixpat/pixpat-native/src/formats/rgb.h
blob: 19d007ab9a9d44aed647e27c852990cf991fb567 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#pragma once

// RGB packed layouts: 8-bit / 16-bit (sub-byte) / 32-bit (10-bit) /
// 64-bit-normalized, all single-plane single-pixel-per-storage-word.
// Names follow the kms++/pixutils register-order convention (MSB-first
// in the storage word), so XRGB8888 has X at bits 31..24 and B at 7..0.

#include "../layout.h"
#include "../io/packed.h"

namespace pixpat::formats
{

// Helper: every format in this file pairs with PackedSource/PackedSink.
// Each format struct exposes Source / Sink aliases so the catalog row
// in format_catalog.h can stay name-only.
#define PIXPAT_RGB_PACKED(name, ...)                              \
	struct name : Layout<ColorKind::RGB, 1, 1, __VA_ARGS__> { \
		using Source = PackedSource<name>;                \
		using Sink   = PackedSink<name>;                  \
	}

// ---------------------------------------------------------------------
// 32-bit packed RGB, 8-bit components.
// ---------------------------------------------------------------------

PIXPAT_RGB_PACKED(XRGB8888,
                  Plane<uint32_t,
                        Comp{ C::B, 8, 0 },
                        Comp{ C::G, 8, 8 },
                        Comp{ C::R, 8, 16 },
                        Comp{ C::X, 8, 24 }>);

PIXPAT_RGB_PACKED(ARGB8888,
                  Plane<uint32_t,
                        Comp{ C::B, 8, 0 },
                        Comp{ C::G, 8, 8 },
                        Comp{ C::R, 8, 16 },
                        Comp{ C::A, 8, 24 }>);

PIXPAT_RGB_PACKED(XBGR8888,
                  Plane<uint32_t,
                        Comp{ C::R, 8, 0 },
                        Comp{ C::G, 8, 8 },
                        Comp{ C::B, 8, 16 },
                        Comp{ C::X, 8, 24 }>);

PIXPAT_RGB_PACKED(ABGR8888,
                  Plane<uint32_t,
                        Comp{ C::R, 8, 0 },
                        Comp{ C::G, 8, 8 },
                        Comp{ C::B, 8, 16 },
                        Comp{ C::A, 8, 24 }>);

PIXPAT_RGB_PACKED(RGBX8888,
                  Plane<uint32_t,
                        Comp{ C::X, 8, 0 },
                        Comp{ C::B, 8, 8 },
                        Comp{ C::G, 8, 16 },
                        Comp{ C::R, 8, 24 }>);

PIXPAT_RGB_PACKED(RGBA8888,
                  Plane<uint32_t,
                        Comp{ C::A, 8, 0 },
                        Comp{ C::B, 8, 8 },
                        Comp{ C::G, 8, 16 },
                        Comp{ C::R, 8, 24 }>);

PIXPAT_RGB_PACKED(BGRX8888,
                  Plane<uint32_t,
                        Comp{ C::X, 8, 0 },
                        Comp{ C::R, 8, 8 },
                        Comp{ C::G, 8, 16 },
                        Comp{ C::B, 8, 24 }>);

PIXPAT_RGB_PACKED(BGRA8888,
                  Plane<uint32_t,
                        Comp{ C::A, 8, 0 },
                        Comp{ C::R, 8, 8 },
                        Comp{ C::G, 8, 16 },
                        Comp{ C::B, 8, 24 }>);

// ---------------------------------------------------------------------
// 24-bit packed RGB, three bytes per pixel. storage_t is uint32_t but
// only bytes_per_pixel = 3 are read/written via memcpy.
// ---------------------------------------------------------------------

PIXPAT_RGB_PACKED(RGB888,
                  Plane<uint32_t,
                        Comp{ C::B, 8, 0 },
                        Comp{ C::G, 8, 8 },
                        Comp{ C::R, 8, 16 }>);

PIXPAT_RGB_PACKED(BGR888,
                  Plane<uint32_t,
                        Comp{ C::R, 8, 0 },
                        Comp{ C::G, 8, 8 },
                        Comp{ C::B, 8, 16 }>);

// ---------------------------------------------------------------------
// 16-bit packed RGB, sub-byte components.
// ---------------------------------------------------------------------

PIXPAT_RGB_PACKED(RGB565,
                  Plane<uint16_t,
                        Comp{ C::B, 5, 0 },
                        Comp{ C::G, 6, 5 },
                        Comp{ C::R, 5, 11 }>);

PIXPAT_RGB_PACKED(BGR565,
                  Plane<uint16_t,
                        Comp{ C::R, 5, 0 },
                        Comp{ C::G, 6, 5 },
                        Comp{ C::B, 5, 11 }>);

// 8-bit packed RGB: 3-bit R / 3-bit G / 2-bit B in a single byte.

PIXPAT_RGB_PACKED(RGB332,
                  Plane<uint8_t,
                        Comp{ C::B, 2, 0 },
                        Comp{ C::G, 3, 2 },
                        Comp{ C::R, 3, 5 }>);

PIXPAT_RGB_PACKED(XRGB1555,
                  Plane<uint16_t,
                        Comp{ C::B, 5, 0 },
                        Comp{ C::G, 5, 5 },
                        Comp{ C::R, 5, 10 },
                        Comp{ C::X, 1, 15 }>);

PIXPAT_RGB_PACKED(ARGB1555,
                  Plane<uint16_t,
                        Comp{ C::B, 5, 0 },
                        Comp{ C::G, 5, 5 },
                        Comp{ C::R, 5, 10 },
                        Comp{ C::A, 1, 15 }>);

PIXPAT_RGB_PACKED(XBGR1555,
                  Plane<uint16_t,
                        Comp{ C::R, 5, 0 },
                        Comp{ C::G, 5, 5 },
                        Comp{ C::B, 5, 10 },
                        Comp{ C::X, 1, 15 }>);

PIXPAT_RGB_PACKED(ABGR1555,
                  Plane<uint16_t,
                        Comp{ C::R, 5, 0 },
                        Comp{ C::G, 5, 5 },
                        Comp{ C::B, 5, 10 },
                        Comp{ C::A, 1, 15 }>);

PIXPAT_RGB_PACKED(XRGB4444,
                  Plane<uint16_t,
                        Comp{ C::B, 4, 0 },
                        Comp{ C::G, 4, 4 },
                        Comp{ C::R, 4, 8 },
                        Comp{ C::X, 4, 12 }>);

PIXPAT_RGB_PACKED(ARGB4444,
                  Plane<uint16_t,
                        Comp{ C::B, 4, 0 },
                        Comp{ C::G, 4, 4 },
                        Comp{ C::R, 4, 8 },
                        Comp{ C::A, 4, 12 }>);

PIXPAT_RGB_PACKED(XBGR4444,
                  Plane<uint16_t,
                        Comp{ C::R, 4, 0 },
                        Comp{ C::G, 4, 4 },
                        Comp{ C::B, 4, 8 },
                        Comp{ C::X, 4, 12 }>);

PIXPAT_RGB_PACKED(ABGR4444,
                  Plane<uint16_t,
                        Comp{ C::R, 4, 0 },
                        Comp{ C::G, 4, 4 },
                        Comp{ C::B, 4, 8 },
                        Comp{ C::A, 4, 12 }>);

PIXPAT_RGB_PACKED(RGBX4444,
                  Plane<uint16_t,
                        Comp{ C::X, 4, 0 },
                        Comp{ C::B, 4, 4 },
                        Comp{ C::G, 4, 8 },
                        Comp{ C::R, 4, 12 }>);

PIXPAT_RGB_PACKED(RGBA4444,
                  Plane<uint16_t,
                        Comp{ C::A, 4, 0 },
                        Comp{ C::B, 4, 4 },
                        Comp{ C::G, 4, 8 },
                        Comp{ C::R, 4, 12 }>);

// ---------------------------------------------------------------------
// 32-bit packed RGB, 10-bit components.
// ---------------------------------------------------------------------

PIXPAT_RGB_PACKED(XRGB2101010,
                  Plane<uint32_t,
                        Comp{ C::B, 10, 0 },
                        Comp{ C::G, 10, 10 },
                        Comp{ C::R, 10, 20 },
                        Comp{ C::X, 2, 30 }>);

PIXPAT_RGB_PACKED(ARGB2101010,
                  Plane<uint32_t,
                        Comp{ C::B, 10, 0 },
                        Comp{ C::G, 10, 10 },
                        Comp{ C::R, 10, 20 },
                        Comp{ C::A, 2, 30 }>);

PIXPAT_RGB_PACKED(XBGR2101010,
                  Plane<uint32_t,
                        Comp{ C::R, 10, 0 },
                        Comp{ C::G, 10, 10 },
                        Comp{ C::B, 10, 20 },
                        Comp{ C::X, 2, 30 }>);

PIXPAT_RGB_PACKED(ABGR2101010,
                  Plane<uint32_t,
                        Comp{ C::R, 10, 0 },
                        Comp{ C::G, 10, 10 },
                        Comp{ C::B, 10, 20 },
                        Comp{ C::A, 2, 30 }>);

PIXPAT_RGB_PACKED(RGBX1010102,
                  Plane<uint32_t,
                        Comp{ C::X, 2, 0 },
                        Comp{ C::B, 10, 2 },
                        Comp{ C::G, 10, 12 },
                        Comp{ C::R, 10, 22 }>);

PIXPAT_RGB_PACKED(RGBA1010102,
                  Plane<uint32_t,
                        Comp{ C::A, 2, 0 },
                        Comp{ C::B, 10, 2 },
                        Comp{ C::G, 10, 12 },
                        Comp{ C::R, 10, 22 }>);

PIXPAT_RGB_PACKED(BGRX1010102,
                  Plane<uint32_t,
                        Comp{ C::X, 2, 0 },
                        Comp{ C::R, 10, 2 },
                        Comp{ C::G, 10, 12 },
                        Comp{ C::B, 10, 22 }>);

PIXPAT_RGB_PACKED(BGRA1010102,
                  Plane<uint32_t,
                        Comp{ C::A, 2, 0 },
                        Comp{ C::R, 10, 2 },
                        Comp{ C::G, 10, 12 },
                        Comp{ C::B, 10, 22 }>);

// ---------------------------------------------------------------------
// 64-bit normalized wide RGB (16 bits per component).
// ---------------------------------------------------------------------

PIXPAT_RGB_PACKED(ABGR16161616,
                  Plane<uint64_t,
                        Comp{ C::R, 16, 0 },
                        Comp{ C::G, 16, 16 },
                        Comp{ C::B, 16, 32 },
                        Comp{ C::A, 16, 48 }>);

#undef PIXPAT_RGB_PACKED

} // namespace pixpat::formats