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