GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_pixel_channel.gen.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.1-or-later
2/*
3 * gp_pixel_channel.gen.h
4 *
5 * GENERATED on 2025 08 01 21:54:28 from gp_pixel_channel.gen.h.t
6 *
7 * DO NOT MODIFY THIS FILE DIRECTLY!
8 */
9#ifndef GP_PIXEL_CHANNEL_GEN_H
10#define GP_PIXEL_CHANNEL_GEN_H
11
12/*
13 * Pixel channel operations.
14 *
15 * Copyright (C) 2011 Tomas Gavenciak <gavento@ucw.cz>
16 * Copyright (C) 2013-2025 Cyril Hrubis <metan@ucw.cz>
17 */
18
28#include <core/gp_clamp.h>
30
34#define GP_PIXEL_GET_R_RGB101010(p) (GP_GET_BITS(20, 10, (p)))
35#define GP_PIXEL_GET_G_RGB101010(p) (GP_GET_BITS(10, 10, (p)))
36#define GP_PIXEL_GET_B_RGB101010(p) (GP_GET_BITS(0, 10, (p)))
37
38/*
39 * macros to create gp_pixel of pixel type RGB101010 directly from given values.
40 * The values MUST be already clipped/converted to relevant value ranges.
41 */
42#define GP_PIXEL_CREATE_RGB101010(R, G, B) (0\
43 + ((R) << 20) \
44 + ((G) << 10) \
45 + ((B) << 0) \
46 )
47
48/*
49 * macros to do per-channel operations on a pixel.
50 */
54#define GP_PIXEL_GET_R_xRGB8888(p) (GP_GET_BITS(16, 8, (p)))
55#define GP_PIXEL_GET_G_xRGB8888(p) (GP_GET_BITS(8, 8, (p)))
56#define GP_PIXEL_GET_B_xRGB8888(p) (GP_GET_BITS(0, 8, (p)))
57
58/*
59 * macros to create gp_pixel of pixel type xRGB8888 directly from given values.
60 * The values MUST be already clipped/converted to relevant value ranges.
61 */
62#define GP_PIXEL_CREATE_xRGB8888(R, G, B) (0\
63 + ((R) << 16) \
64 + ((G) << 8) \
65 + ((B) << 0) \
66 )
67
68/*
69 * macros to do per-channel operations on a pixel.
70 */
74#define GP_PIXEL_GET_R_RGBA8888(p) (GP_GET_BITS(24, 8, (p)))
75#define GP_PIXEL_GET_G_RGBA8888(p) (GP_GET_BITS(16, 8, (p)))
76#define GP_PIXEL_GET_B_RGBA8888(p) (GP_GET_BITS(8, 8, (p)))
77#define GP_PIXEL_GET_A_RGBA8888(p) (GP_GET_BITS(0, 8, (p)))
78
79/*
80 * macros to create gp_pixel of pixel type RGBA8888 directly from given values.
81 * The values MUST be already clipped/converted to relevant value ranges.
82 */
83#define GP_PIXEL_CREATE_RGBA8888(R, G, B, A) (0\
84 + ((R) << 24) \
85 + ((G) << 16) \
86 + ((B) << 8) \
87 + ((A) << 0) \
88 )
89
90/*
91 * macros to do per-channel operations on a pixel.
92 */
96#define GP_PIXEL_GET_R_RGB888(p) (GP_GET_BITS(16, 8, (p)))
97#define GP_PIXEL_GET_G_RGB888(p) (GP_GET_BITS(8, 8, (p)))
98#define GP_PIXEL_GET_B_RGB888(p) (GP_GET_BITS(0, 8, (p)))
99
100/*
101 * macros to create gp_pixel of pixel type RGB888 directly from given values.
102 * The values MUST be already clipped/converted to relevant value ranges.
103 */
104#define GP_PIXEL_CREATE_RGB888(R, G, B) (0\
105 + ((R) << 16) \
106 + ((G) << 8) \
107 + ((B) << 0) \
108 )
109
110/*
111 * macros to do per-channel operations on a pixel.
112 */
116#define GP_PIXEL_GET_B_BGR888(p) (GP_GET_BITS(16, 8, (p)))
117#define GP_PIXEL_GET_G_BGR888(p) (GP_GET_BITS(8, 8, (p)))
118#define GP_PIXEL_GET_R_BGR888(p) (GP_GET_BITS(0, 8, (p)))
119
120/*
121 * macros to create gp_pixel of pixel type BGR888 directly from given values.
122 * The values MUST be already clipped/converted to relevant value ranges.
123 */
124#define GP_PIXEL_CREATE_BGR888(B, G, R) (0\
125 + ((B) << 16) \
126 + ((G) << 8) \
127 + ((R) << 0) \
128 )
129
130/*
131 * macros to do per-channel operations on a pixel.
132 */
136#define GP_PIXEL_GET_R_RGB555(p) (GP_GET_BITS(10, 5, (p)))
137#define GP_PIXEL_GET_G_RGB555(p) (GP_GET_BITS(5, 5, (p)))
138#define GP_PIXEL_GET_B_RGB555(p) (GP_GET_BITS(0, 5, (p)))
139
140/*
141 * macros to create gp_pixel of pixel type RGB555 directly from given values.
142 * The values MUST be already clipped/converted to relevant value ranges.
143 */
144#define GP_PIXEL_CREATE_RGB555(R, G, B) (0\
145 + ((R) << 10) \
146 + ((G) << 5) \
147 + ((B) << 0) \
148 )
149
150/*
151 * macros to do per-channel operations on a pixel.
152 */
156#define GP_PIXEL_GET_R_RGB565(p) (GP_GET_BITS(11, 5, (p)))
157#define GP_PIXEL_GET_G_RGB565(p) (GP_GET_BITS(5, 6, (p)))
158#define GP_PIXEL_GET_B_RGB565(p) (GP_GET_BITS(0, 5, (p)))
159
160/*
161 * macros to create gp_pixel of pixel type RGB565 directly from given values.
162 * The values MUST be already clipped/converted to relevant value ranges.
163 */
164#define GP_PIXEL_CREATE_RGB565(R, G, B) (0\
165 + ((R) << 11) \
166 + ((G) << 5) \
167 + ((B) << 0) \
168 )
169
170/*
171 * macros to do per-channel operations on a pixel.
172 */
176#define GP_PIXEL_GET_R_RGB666(p) (GP_GET_BITS(12, 6, (p)))
177#define GP_PIXEL_GET_G_RGB666(p) (GP_GET_BITS(6, 6, (p)))
178#define GP_PIXEL_GET_B_RGB666(p) (GP_GET_BITS(0, 6, (p)))
179
180/*
181 * macros to create gp_pixel of pixel type RGB666 directly from given values.
182 * The values MUST be already clipped/converted to relevant value ranges.
183 */
184#define GP_PIXEL_CREATE_RGB666(R, G, B) (0\
185 + ((R) << 12) \
186 + ((G) << 6) \
187 + ((B) << 0) \
188 )
189
190/*
191 * macros to do per-channel operations on a pixel.
192 */
196#define GP_PIXEL_GET_R_RGB332(p) (GP_GET_BITS(5, 3, (p)))
197#define GP_PIXEL_GET_G_RGB332(p) (GP_GET_BITS(2, 3, (p)))
198#define GP_PIXEL_GET_B_RGB332(p) (GP_GET_BITS(0, 2, (p)))
199
200/*
201 * macros to create gp_pixel of pixel type RGB332 directly from given values.
202 * The values MUST be already clipped/converted to relevant value ranges.
203 */
204#define GP_PIXEL_CREATE_RGB332(R, G, B) (0\
205 + ((R) << 5) \
206 + ((G) << 2) \
207 + ((B) << 0) \
208 )
209
210/*
211 * macros to do per-channel operations on a pixel.
212 */
216#define GP_PIXEL_GET_K_CMYK8888(p) (GP_GET_BITS(24, 8, (p)))
217#define GP_PIXEL_GET_Y_CMYK8888(p) (GP_GET_BITS(16, 8, (p)))
218#define GP_PIXEL_GET_M_CMYK8888(p) (GP_GET_BITS(8, 8, (p)))
219#define GP_PIXEL_GET_C_CMYK8888(p) (GP_GET_BITS(0, 8, (p)))
220
221/*
222 * macros to create gp_pixel of pixel type CMYK8888 directly from given values.
223 * The values MUST be already clipped/converted to relevant value ranges.
224 */
225#define GP_PIXEL_CREATE_CMYK8888(K, Y, M, C) (0\
226 + ((K) << 24) \
227 + ((Y) << 16) \
228 + ((M) << 8) \
229 + ((C) << 0) \
230 )
231
232/*
233 * macros to do per-channel operations on a pixel.
234 */
238#define GP_PIXEL_GET_P_P2(p) (GP_GET_BITS(0, 2, (p)))
239
240/*
241 * macros to create gp_pixel of pixel type P2 directly from given values.
242 * The values MUST be already clipped/converted to relevant value ranges.
243 */
244#define GP_PIXEL_CREATE_P2(P) (0\
245 + ((P) << 0) \
246 )
247
248/*
249 * macros to do per-channel operations on a pixel.
250 */
254#define GP_PIXEL_GET_P_P4(p) (GP_GET_BITS(0, 4, (p)))
255
256/*
257 * macros to create gp_pixel of pixel type P4 directly from given values.
258 * The values MUST be already clipped/converted to relevant value ranges.
259 */
260#define GP_PIXEL_CREATE_P4(P) (0\
261 + ((P) << 0) \
262 )
263
264/*
265 * macros to do per-channel operations on a pixel.
266 */
270#define GP_PIXEL_GET_P_P8(p) (GP_GET_BITS(0, 8, (p)))
271
272/*
273 * macros to create gp_pixel of pixel type P8 directly from given values.
274 * The values MUST be already clipped/converted to relevant value ranges.
275 */
276#define GP_PIXEL_CREATE_P8(P) (0\
277 + ((P) << 0) \
278 )
279
280/*
281 * macros to do per-channel operations on a pixel.
282 */
286#define GP_PIXEL_GET_V_G1_DB(p) (GP_GET_BITS(0, 1, (p)))
287
288/*
289 * macros to create gp_pixel of pixel type G1_DB directly from given values.
290 * The values MUST be already clipped/converted to relevant value ranges.
291 */
292#define GP_PIXEL_CREATE_G1_DB(V) (0\
293 + ((V) << 0) \
294 )
295
296/*
297 * macros to do per-channel operations on a pixel.
298 */
302#define GP_PIXEL_GET_V_G2_DB(p) (GP_GET_BITS(0, 2, (p)))
303
304/*
305 * macros to create gp_pixel of pixel type G2_DB directly from given values.
306 * The values MUST be already clipped/converted to relevant value ranges.
307 */
308#define GP_PIXEL_CREATE_G2_DB(V) (0\
309 + ((V) << 0) \
310 )
311
312/*
313 * macros to do per-channel operations on a pixel.
314 */
318#define GP_PIXEL_GET_V_G4_DB(p) (GP_GET_BITS(0, 4, (p)))
319
320/*
321 * macros to create gp_pixel of pixel type G4_DB directly from given values.
322 * The values MUST be already clipped/converted to relevant value ranges.
323 */
324#define GP_PIXEL_CREATE_G4_DB(V) (0\
325 + ((V) << 0) \
326 )
327
328/*
329 * macros to do per-channel operations on a pixel.
330 */
334#define GP_PIXEL_GET_V_G1_UB(p) (GP_GET_BITS(0, 1, (p)))
335
336/*
337 * macros to create gp_pixel of pixel type G1_UB directly from given values.
338 * The values MUST be already clipped/converted to relevant value ranges.
339 */
340#define GP_PIXEL_CREATE_G1_UB(V) (0\
341 + ((V) << 0) \
342 )
343
344/*
345 * macros to do per-channel operations on a pixel.
346 */
350#define GP_PIXEL_GET_V_G2_UB(p) (GP_GET_BITS(0, 2, (p)))
351
352/*
353 * macros to create gp_pixel of pixel type G2_UB directly from given values.
354 * The values MUST be already clipped/converted to relevant value ranges.
355 */
356#define GP_PIXEL_CREATE_G2_UB(V) (0\
357 + ((V) << 0) \
358 )
359
360/*
361 * macros to do per-channel operations on a pixel.
362 */
366#define GP_PIXEL_GET_V_G4_UB(p) (GP_GET_BITS(0, 4, (p)))
367
368/*
369 * macros to create gp_pixel of pixel type G4_UB directly from given values.
370 * The values MUST be already clipped/converted to relevant value ranges.
371 */
372#define GP_PIXEL_CREATE_G4_UB(V) (0\
373 + ((V) << 0) \
374 )
375
376/*
377 * macros to do per-channel operations on a pixel.
378 */
382#define GP_PIXEL_GET_V_G8(p) (GP_GET_BITS(0, 8, (p)))
383
384/*
385 * macros to create gp_pixel of pixel type G8 directly from given values.
386 * The values MUST be already clipped/converted to relevant value ranges.
387 */
388#define GP_PIXEL_CREATE_G8(V) (0\
389 + ((V) << 0) \
390 )
391
392/*
393 * macros to do per-channel operations on a pixel.
394 */
398#define GP_PIXEL_GET_V_GA88(p) (GP_GET_BITS(0, 8, (p)))
399#define GP_PIXEL_GET_A_GA88(p) (GP_GET_BITS(8, 8, (p)))
400
401/*
402 * macros to create gp_pixel of pixel type GA88 directly from given values.
403 * The values MUST be already clipped/converted to relevant value ranges.
404 */
405#define GP_PIXEL_CREATE_GA88(V, A) (0\
406 + ((V) << 0) \
407 + ((A) << 8) \
408 )
409
410/*
411 * macros to do per-channel operations on a pixel.
412 */
416#define GP_PIXEL_GET_V_G16(p) (GP_GET_BITS(0, 16, (p)))
417
418/*
419 * macros to create gp_pixel of pixel type G16 directly from given values.
420 * The values MUST be already clipped/converted to relevant value ranges.
421 */
422#define GP_PIXEL_CREATE_G16(V) (0\
423 + ((V) << 0) \
424 )
425
426/*
427 * macros to do per-channel operations on a pixel.
428 */
429#define GP_PIXEL_CHANS_ADD_RGB101010(pixel, perc) \
430 GP_PIXEL_CREATE_RGB101010( \
431 GP_SAT_ADD(GP_PIXEL_GET_R_RGB101010(pixel), 0x3ff * perc / 100, 0x3ff), \
432 GP_SAT_ADD(GP_PIXEL_GET_G_RGB101010(pixel), 0x3ff * perc / 100, 0x3ff), \
433 GP_SAT_ADD(GP_PIXEL_GET_B_RGB101010(pixel), 0x3ff * perc / 100, 0x3ff) \
434 )
435
436#define GP_PIXEL_CHANS_ADD_xRGB8888(pixel, perc) \
437 GP_PIXEL_CREATE_xRGB8888( \
438 GP_SAT_ADD(GP_PIXEL_GET_R_xRGB8888(pixel), 0xff * perc / 100, 0xff), \
439 GP_SAT_ADD(GP_PIXEL_GET_G_xRGB8888(pixel), 0xff * perc / 100, 0xff), \
440 GP_SAT_ADD(GP_PIXEL_GET_B_xRGB8888(pixel), 0xff * perc / 100, 0xff) \
441 )
442
443#define GP_PIXEL_CHANS_ADD_RGBA8888(pixel, perc) \
444 GP_PIXEL_CREATE_RGBA8888( \
445 GP_SAT_ADD(GP_PIXEL_GET_R_RGBA8888(pixel), 0xff * perc / 100, 0xff), \
446 GP_SAT_ADD(GP_PIXEL_GET_G_RGBA8888(pixel), 0xff * perc / 100, 0xff), \
447 GP_SAT_ADD(GP_PIXEL_GET_B_RGBA8888(pixel), 0xff * perc / 100, 0xff), \
448 GP_PIXEL_GET_A_RGBA8888(pixel) \
449 )
450
451#define GP_PIXEL_CHANS_ADD_RGB888(pixel, perc) \
452 GP_PIXEL_CREATE_RGB888( \
453 GP_SAT_ADD(GP_PIXEL_GET_R_RGB888(pixel), 0xff * perc / 100, 0xff), \
454 GP_SAT_ADD(GP_PIXEL_GET_G_RGB888(pixel), 0xff * perc / 100, 0xff), \
455 GP_SAT_ADD(GP_PIXEL_GET_B_RGB888(pixel), 0xff * perc / 100, 0xff) \
456 )
457
458#define GP_PIXEL_CHANS_ADD_BGR888(pixel, perc) \
459 GP_PIXEL_CREATE_BGR888( \
460 GP_SAT_ADD(GP_PIXEL_GET_B_BGR888(pixel), 0xff * perc / 100, 0xff), \
461 GP_SAT_ADD(GP_PIXEL_GET_G_BGR888(pixel), 0xff * perc / 100, 0xff), \
462 GP_SAT_ADD(GP_PIXEL_GET_R_BGR888(pixel), 0xff * perc / 100, 0xff) \
463 )
464
465#define GP_PIXEL_CHANS_ADD_RGB555(pixel, perc) \
466 GP_PIXEL_CREATE_RGB555( \
467 GP_SAT_ADD(GP_PIXEL_GET_R_RGB555(pixel), 0x1f * perc / 100, 0x1f), \
468 GP_SAT_ADD(GP_PIXEL_GET_G_RGB555(pixel), 0x1f * perc / 100, 0x1f), \
469 GP_SAT_ADD(GP_PIXEL_GET_B_RGB555(pixel), 0x1f * perc / 100, 0x1f) \
470 )
471
472#define GP_PIXEL_CHANS_ADD_RGB565(pixel, perc) \
473 GP_PIXEL_CREATE_RGB565( \
474 GP_SAT_ADD(GP_PIXEL_GET_R_RGB565(pixel), 0x1f * perc / 100, 0x1f), \
475 GP_SAT_ADD(GP_PIXEL_GET_G_RGB565(pixel), 0x3f * perc / 100, 0x3f), \
476 GP_SAT_ADD(GP_PIXEL_GET_B_RGB565(pixel), 0x1f * perc / 100, 0x1f) \
477 )
478
479#define GP_PIXEL_CHANS_ADD_RGB666(pixel, perc) \
480 GP_PIXEL_CREATE_RGB666( \
481 GP_SAT_ADD(GP_PIXEL_GET_R_RGB666(pixel), 0x3f * perc / 100, 0x3f), \
482 GP_SAT_ADD(GP_PIXEL_GET_G_RGB666(pixel), 0x3f * perc / 100, 0x3f), \
483 GP_SAT_ADD(GP_PIXEL_GET_B_RGB666(pixel), 0x3f * perc / 100, 0x3f) \
484 )
485
486#define GP_PIXEL_CHANS_ADD_RGB332(pixel, perc) \
487 GP_PIXEL_CREATE_RGB332( \
488 GP_SAT_ADD(GP_PIXEL_GET_R_RGB332(pixel), 0x7 * perc / 100, 0x7), \
489 GP_SAT_ADD(GP_PIXEL_GET_G_RGB332(pixel), 0x7 * perc / 100, 0x7), \
490 GP_SAT_ADD(GP_PIXEL_GET_B_RGB332(pixel), 0x3 * perc / 100, 0x3) \
491 )
492
493#define GP_PIXEL_CHANS_ADD_CMYK8888(pixel, perc) \
494 GP_PIXEL_CREATE_CMYK8888( \
495 GP_SAT_ADD(GP_PIXEL_GET_K_CMYK8888(pixel), 0xff * perc / 100, 0xff), \
496 GP_SAT_ADD(GP_PIXEL_GET_Y_CMYK8888(pixel), 0xff * perc / 100, 0xff), \
497 GP_SAT_ADD(GP_PIXEL_GET_M_CMYK8888(pixel), 0xff * perc / 100, 0xff), \
498 GP_SAT_ADD(GP_PIXEL_GET_C_CMYK8888(pixel), 0xff * perc / 100, 0xff) \
499 )
500
501#define GP_PIXEL_CHANS_ADD_P2(pixel, perc) \
502 GP_PIXEL_CREATE_P2( \
503 GP_SAT_ADD(GP_PIXEL_GET_P_P2(pixel), 0x3 * perc / 100, 0x3) \
504 )
505
506#define GP_PIXEL_CHANS_ADD_P4(pixel, perc) \
507 GP_PIXEL_CREATE_P4( \
508 GP_SAT_ADD(GP_PIXEL_GET_P_P4(pixel), 0xf * perc / 100, 0xf) \
509 )
510
511#define GP_PIXEL_CHANS_ADD_P8(pixel, perc) \
512 GP_PIXEL_CREATE_P8( \
513 GP_SAT_ADD(GP_PIXEL_GET_P_P8(pixel), 0xff * perc / 100, 0xff) \
514 )
515
516#define GP_PIXEL_CHANS_ADD_G1_DB(pixel, perc) \
517 GP_PIXEL_CREATE_G1_DB( \
518 GP_SAT_ADD(GP_PIXEL_GET_V_G1_DB(pixel), 0x1 * perc / 100, 0x1) \
519 )
520
521#define GP_PIXEL_CHANS_ADD_G2_DB(pixel, perc) \
522 GP_PIXEL_CREATE_G2_DB( \
523 GP_SAT_ADD(GP_PIXEL_GET_V_G2_DB(pixel), 0x3 * perc / 100, 0x3) \
524 )
525
526#define GP_PIXEL_CHANS_ADD_G4_DB(pixel, perc) \
527 GP_PIXEL_CREATE_G4_DB( \
528 GP_SAT_ADD(GP_PIXEL_GET_V_G4_DB(pixel), 0xf * perc / 100, 0xf) \
529 )
530
531#define GP_PIXEL_CHANS_ADD_G1_UB(pixel, perc) \
532 GP_PIXEL_CREATE_G1_UB( \
533 GP_SAT_ADD(GP_PIXEL_GET_V_G1_UB(pixel), 0x1 * perc / 100, 0x1) \
534 )
535
536#define GP_PIXEL_CHANS_ADD_G2_UB(pixel, perc) \
537 GP_PIXEL_CREATE_G2_UB( \
538 GP_SAT_ADD(GP_PIXEL_GET_V_G2_UB(pixel), 0x3 * perc / 100, 0x3) \
539 )
540
541#define GP_PIXEL_CHANS_ADD_G4_UB(pixel, perc) \
542 GP_PIXEL_CREATE_G4_UB( \
543 GP_SAT_ADD(GP_PIXEL_GET_V_G4_UB(pixel), 0xf * perc / 100, 0xf) \
544 )
545
546#define GP_PIXEL_CHANS_ADD_G8(pixel, perc) \
547 GP_PIXEL_CREATE_G8( \
548 GP_SAT_ADD(GP_PIXEL_GET_V_G8(pixel), 0xff * perc / 100, 0xff) \
549 )
550
551#define GP_PIXEL_CHANS_ADD_GA88(pixel, perc) \
552 GP_PIXEL_CREATE_GA88( \
553 GP_SAT_ADD(GP_PIXEL_GET_V_GA88(pixel), 0xff * perc / 100, 0xff), \
554 GP_PIXEL_GET_A_GA88(pixel) \
555 )
556
557#define GP_PIXEL_CHANS_ADD_G16(pixel, perc) \
558 GP_PIXEL_CREATE_G16( \
559 GP_SAT_ADD(GP_PIXEL_GET_V_G16(pixel), 0xffff * perc / 100, 0xffff) \
560 )
561
562#endif /* GP_PIXEL_CHANNEL_GEN_H */
Fast value clamping.
Helper macros to get and set bytes.