GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_get_put_pixel.gen.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.1-or-later
2/*
3 * gp_get_put_pixel.gen.h
4 *
5 * GENERATED on 2024 04 14 13:01:17 from gp_get_put_pixel.gen.h.t
6 *
7 * DO NOT MODIFY THIS FILE DIRECTLY!
8 */
9#ifndef GP_GET_PUT_PIXEL_GEN_H
10#define GP_GET_PUT_PIXEL_GEN_H
11
12/*
13 * Access pixel bytes, get and put pixel
14 * Do not include directly, use gp_pixel.h
15 *
16 * Copyright (C) 2011-2024 Cyril Hrubis <metan@ucw.cz>
17 * Copyright (C) 2011 Tomas Gavenciak <gavento@ucw.cz>
18 */
19
75#include <core/gp_pixmap.h>
76
77
86#define GP_PIXEL_ADDR_1BPP_DB(pixmap, x, y) \
87 ((gp_pixel*)(((void*)((pixmap)->pixels)) + (pixmap)->bytes_per_row * (y) + \
88 (1 * ((pixmap)->offset + x)) / 8))
89
96#define GP_PIXEL_ADDR_SHIFT_1BPP_DB(pixmap, x) \
97 (((x + (pixmap)->offset) % 8) * 1)
98
102#define GP_PIXEL_ADDR_OFFSET_1BPP_DB(pixmap, x) \
103 (((pixmap)->offset + x) % 8)
104
117{
118 /*
119 * Whole pixel is stored in one byte
120 *
121 * The full list = {1, 2, 4}
122 */
124 GP_PIXEL_ADDR_1BPP_DB(c, x, y));
125}
126
138{
139 /*
140 * Whole pixel is stored one byte
141 *
142 * The full list = {1, 2, 4}
143 */
145 GP_PIXEL_ADDR_1BPP_DB(c, x, y), p);
146}
147
148static inline void gp_putpixel_raw_clipped_1BPP_DB(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
149{
150 if (GP_PIXEL_IS_CLIPPED(c, x, y))
151 return;
152
153 gp_putpixel_raw_1BPP_DB(c, x, y, p);
154}
155
164#define GP_PIXEL_ADDR_1BPP_UB(pixmap, x, y) \
165 ((gp_pixel*)(((void*)((pixmap)->pixels)) + (pixmap)->bytes_per_row * (y) + \
166 (1 * ((pixmap)->offset + x)) / 8))
167
174#define GP_PIXEL_ADDR_SHIFT_1BPP_UB(pixmap, x) \
175 (7 - ((x + (pixmap)->offset) % 8) * 1)
176
180#define GP_PIXEL_ADDR_OFFSET_1BPP_UB(pixmap, x) \
181 (((pixmap)->offset + x) % 8)
182
195{
196 /*
197 * Whole pixel is stored in one byte
198 *
199 * The full list = {1, 2, 4}
200 */
202 GP_PIXEL_ADDR_1BPP_UB(c, x, y));
203}
204
216{
217 /*
218 * Whole pixel is stored one byte
219 *
220 * The full list = {1, 2, 4}
221 */
223 GP_PIXEL_ADDR_1BPP_UB(c, x, y), p);
224}
225
226static inline void gp_putpixel_raw_clipped_1BPP_UB(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
227{
228 if (GP_PIXEL_IS_CLIPPED(c, x, y))
229 return;
230
231 gp_putpixel_raw_1BPP_UB(c, x, y, p);
232}
233
242#define GP_PIXEL_ADDR_2BPP_DB(pixmap, x, y) \
243 ((gp_pixel*)(((void*)((pixmap)->pixels)) + (pixmap)->bytes_per_row * (y) + \
244 (2 * ((pixmap)->offset + x)) / 8))
245
252#define GP_PIXEL_ADDR_SHIFT_2BPP_DB(pixmap, x) \
253 (((x + (pixmap)->offset) % 4) * 2)
254
258#define GP_PIXEL_ADDR_OFFSET_2BPP_DB(pixmap, x) \
259 (((pixmap)->offset + x) % 4)
260
273{
274 /*
275 * Whole pixel is stored in one byte
276 *
277 * The full list = {1, 2, 4}
278 */
280 GP_PIXEL_ADDR_2BPP_DB(c, x, y));
281}
282
294{
295 /*
296 * Whole pixel is stored one byte
297 *
298 * The full list = {1, 2, 4}
299 */
301 GP_PIXEL_ADDR_2BPP_DB(c, x, y), p);
302}
303
304static inline void gp_putpixel_raw_clipped_2BPP_DB(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
305{
306 if (GP_PIXEL_IS_CLIPPED(c, x, y))
307 return;
308
309 gp_putpixel_raw_2BPP_DB(c, x, y, p);
310}
311
320#define GP_PIXEL_ADDR_2BPP_UB(pixmap, x, y) \
321 ((gp_pixel*)(((void*)((pixmap)->pixels)) + (pixmap)->bytes_per_row * (y) + \
322 (2 * ((pixmap)->offset + x)) / 8))
323
330#define GP_PIXEL_ADDR_SHIFT_2BPP_UB(pixmap, x) \
331 (6 - ((x + (pixmap)->offset) % 4) * 2)
332
336#define GP_PIXEL_ADDR_OFFSET_2BPP_UB(pixmap, x) \
337 (((pixmap)->offset + x) % 4)
338
351{
352 /*
353 * Whole pixel is stored in one byte
354 *
355 * The full list = {1, 2, 4}
356 */
358 GP_PIXEL_ADDR_2BPP_UB(c, x, y));
359}
360
372{
373 /*
374 * Whole pixel is stored one byte
375 *
376 * The full list = {1, 2, 4}
377 */
379 GP_PIXEL_ADDR_2BPP_UB(c, x, y), p);
380}
381
382static inline void gp_putpixel_raw_clipped_2BPP_UB(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
383{
384 if (GP_PIXEL_IS_CLIPPED(c, x, y))
385 return;
386
387 gp_putpixel_raw_2BPP_UB(c, x, y, p);
388}
389
398#define GP_PIXEL_ADDR_4BPP_DB(pixmap, x, y) \
399 ((gp_pixel*)(((void*)((pixmap)->pixels)) + (pixmap)->bytes_per_row * (y) + \
400 (4 * ((pixmap)->offset + x)) / 8))
401
408#define GP_PIXEL_ADDR_SHIFT_4BPP_DB(pixmap, x) \
409 (((x + (pixmap)->offset) % 2) * 4)
410
414#define GP_PIXEL_ADDR_OFFSET_4BPP_DB(pixmap, x) \
415 (((pixmap)->offset + x) % 2)
416
429{
430 /*
431 * Whole pixel is stored in one byte
432 *
433 * The full list = {1, 2, 4}
434 */
436 GP_PIXEL_ADDR_4BPP_DB(c, x, y));
437}
438
450{
451 /*
452 * Whole pixel is stored one byte
453 *
454 * The full list = {1, 2, 4}
455 */
457 GP_PIXEL_ADDR_4BPP_DB(c, x, y), p);
458}
459
460static inline void gp_putpixel_raw_clipped_4BPP_DB(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
461{
462 if (GP_PIXEL_IS_CLIPPED(c, x, y))
463 return;
464
465 gp_putpixel_raw_4BPP_DB(c, x, y, p);
466}
467
476#define GP_PIXEL_ADDR_4BPP_UB(pixmap, x, y) \
477 ((gp_pixel*)(((void*)((pixmap)->pixels)) + (pixmap)->bytes_per_row * (y) + \
478 (4 * ((pixmap)->offset + x)) / 8))
479
486#define GP_PIXEL_ADDR_SHIFT_4BPP_UB(pixmap, x) \
487 (4 - ((x + (pixmap)->offset) % 2) * 4)
488
492#define GP_PIXEL_ADDR_OFFSET_4BPP_UB(pixmap, x) \
493 (((pixmap)->offset + x) % 2)
494
507{
508 /*
509 * Whole pixel is stored in one byte
510 *
511 * The full list = {1, 2, 4}
512 */
514 GP_PIXEL_ADDR_4BPP_UB(c, x, y));
515}
516
528{
529 /*
530 * Whole pixel is stored one byte
531 *
532 * The full list = {1, 2, 4}
533 */
535 GP_PIXEL_ADDR_4BPP_UB(c, x, y), p);
536}
537
538static inline void gp_putpixel_raw_clipped_4BPP_UB(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
539{
540 if (GP_PIXEL_IS_CLIPPED(c, x, y))
541 return;
542
543 gp_putpixel_raw_4BPP_UB(c, x, y, p);
544}
545
554#define GP_PIXEL_ADDR_8BPP(pixmap, x, y) \
555 ((gp_pixel*)(((void*)((pixmap)->pixels)) + (pixmap)->bytes_per_row * (y) + \
556 (8 * (x)) / 8))
557
564#define GP_PIXEL_ADDR_SHIFT_8BPP(pixmap, x) \
565 (0)
566
570#define GP_PIXEL_ADDR_OFFSET_8BPP(pixmap, x) \
571 (0)
572
585{
586 /*
587 * 8 BPP is byte aligned
588 */
589 return *((uint8_t*)GP_PIXEL_ADDR_8BPP(c, x, y));
590}
591
603{
604 /*
605 * 8 BPP is byte aligned
606 */
607 *((uint8_t*)GP_PIXEL_ADDR_8BPP(c, x, y)) = p;
608}
609
610static inline void gp_putpixel_raw_clipped_8BPP(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
611{
612 if (GP_PIXEL_IS_CLIPPED(c, x, y))
613 return;
614
615 gp_putpixel_raw_8BPP(c, x, y, p);
616}
617
626#define GP_PIXEL_ADDR_16BPP(pixmap, x, y) \
627 ((gp_pixel*)(((void*)((pixmap)->pixels)) + (pixmap)->bytes_per_row * (y) + \
628 (16 * (x)) / 8))
629
636#define GP_PIXEL_ADDR_SHIFT_16BPP(pixmap, x) \
637 (0)
638
642#define GP_PIXEL_ADDR_OFFSET_16BPP(pixmap, x) \
643 (0)
644
657{
658 /*
659 * 16 BPP is expected to have aligned pixels
660 */
661 return *((uint16_t*)GP_PIXEL_ADDR_16BPP(c, x, y));
662}
663
675{
676 /*
677 * 16 BPP is expected to have aligned pixels
678 */
679 *((uint16_t*)GP_PIXEL_ADDR_16BPP(c, x, y)) = p;
680}
681
682static inline void gp_putpixel_raw_clipped_16BPP(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
683{
684 if (GP_PIXEL_IS_CLIPPED(c, x, y))
685 return;
686
687 gp_putpixel_raw_16BPP(c, x, y, p);
688}
689
698#define GP_PIXEL_ADDR_24BPP(pixmap, x, y) \
699 ((gp_pixel*)(((void*)((pixmap)->pixels)) + (pixmap)->bytes_per_row * (y) + \
700 (24 * (x)) / 8))
701
708#define GP_PIXEL_ADDR_SHIFT_24BPP(pixmap, x) \
709 (0)
710
714#define GP_PIXEL_ADDR_OFFSET_24BPP(pixmap, x) \
715 (0)
716
729{
730 /*
731 * The pixel is stored in two or three bytes
732 *
733 * The max from subgroup (of mod 8 factor group) generated by
734 * pixel_size mod 8 + pixel_size <= 24
735 *
736 * The full list = {11, 13, 14, 15, 17, 18, 20, 24}
737 *
738 * Hint: If the pixel size is coprime to 8 the group is generated by
739 * pixel_size mod 8 and maximal size thus is pixel_size + 7
740 */
742 GP_PIXEL_ADDR_24BPP(c, x, y));
743}
744
756{
757 /*
758 * The pixel is stored in two or three bytes
759 *
760 * The max from subgroup (of mod 8 factor group) generated by
761 * pixel_size mod 8 + pixel_size <= 24
762 *
763 * The full list = {11, 13, 14, 15, 17, 18, 20, 24}
764 *
765 * Hint: If the pixel size is coprime to 8 the group is generated by
766 * pixel_size mod 8 and maximal size thus is pixel_size + 7
767 */
769 GP_PIXEL_ADDR_24BPP(c, x, y), p);
770}
771
772static inline void gp_putpixel_raw_clipped_24BPP(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
773{
774 if (GP_PIXEL_IS_CLIPPED(c, x, y))
775 return;
776
777 gp_putpixel_raw_24BPP(c, x, y, p);
778}
779
788#define GP_PIXEL_ADDR_32BPP(pixmap, x, y) \
789 ((gp_pixel*)(((void*)((pixmap)->pixels)) + (pixmap)->bytes_per_row * (y) + \
790 (32 * (x)) / 8))
791
798#define GP_PIXEL_ADDR_SHIFT_32BPP(pixmap, x) \
799 (0)
800
804#define GP_PIXEL_ADDR_OFFSET_32BPP(pixmap, x) \
805 (0)
806
819{
820 /*
821 * 32 BPP is expected to have aligned pixels
822 */
823 return *((uint32_t*)GP_PIXEL_ADDR_32BPP(c, x, y));
824}
825
837{
838 /*
839 * 32 BPP is expected to have aligned pixels
840 */
841 *((uint32_t*)GP_PIXEL_ADDR_32BPP(c, x, y)) = p;
842}
843
844static inline void gp_putpixel_raw_clipped_32BPP(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
845{
846 if (GP_PIXEL_IS_CLIPPED(c, x, y))
847 return;
848
849 gp_putpixel_raw_32BPP(c, x, y, p);
850}
851
860#define GP_PIXEL_ADDR_18BPP_DB(pixmap, x, y) \
861 ((gp_pixel*)(((void*)((pixmap)->pixels)) + (pixmap)->bytes_per_row * (y) + \
862 (18 * ((pixmap)->offset + x)) / 8))
863
870#define GP_PIXEL_ADDR_SHIFT_18BPP_DB(pixmap, x) \
871 ((18 * (x + (pixmap)->offset)) % 8)
872
876#define GP_PIXEL_ADDR_OFFSET_18BPP_DB(pixmap, x) \
877 (0)
878
891{
892 /*
893 * The pixel is stored in two or three bytes
894 *
895 * The max from subgroup (of mod 8 factor group) generated by
896 * pixel_size mod 8 + pixel_size <= 24
897 *
898 * The full list = {11, 13, 14, 15, 17, 18, 20, 24}
899 *
900 * Hint: If the pixel size is coprime to 8 the group is generated by
901 * pixel_size mod 8 and maximal size thus is pixel_size + 7
902 */
904 GP_PIXEL_ADDR_18BPP_DB(c, x, y));
905}
906
918{
919 /*
920 * The pixel is stored in two or three bytes
921 *
922 * The max from subgroup (of mod 8 factor group) generated by
923 * pixel_size mod 8 + pixel_size <= 24
924 *
925 * The full list = {11, 13, 14, 15, 17, 18, 20, 24}
926 *
927 * Hint: If the pixel size is coprime to 8 the group is generated by
928 * pixel_size mod 8 and maximal size thus is pixel_size + 7
929 */
931 GP_PIXEL_ADDR_18BPP_DB(c, x, y), p);
932}
933
934static inline void gp_putpixel_raw_clipped_18BPP_DB(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
935{
936 if (GP_PIXEL_IS_CLIPPED(c, x, y))
937 return;
938
939 gp_putpixel_raw_18BPP_DB(c, x, y, p);
940}
941#endif /* GP_GET_PUT_PIXEL_GEN_H */
uint32_t gp_pixel
Pixel integer value.
Definition gp_types.h:33
int gp_coord
Integer type for coordinates i.e. x, y, ...
Definition gp_types.h:19
static void gp_putpixel_raw_18BPP_DB(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
gp_putpixel for 18BPP_DB
static gp_pixel gp_getpixel_raw_24BPP(const gp_pixmap *c, gp_coord x, gp_coord y)
gp_getpixel for 24BPP
static void gp_putpixel_raw_1BPP_DB(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
gp_putpixel for 1BPP_DB
#define GP_PIXEL_ADDR_SHIFT_4BPP_DB(pixmap, x)
A macro to get bit-shift of pixel in 4BPP_DB pixmap.
static void gp_putpixel_raw_1BPP_UB(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
gp_putpixel for 1BPP_UB
static gp_pixel gp_getpixel_raw_1BPP_DB(const gp_pixmap *c, gp_coord x, gp_coord y)
gp_getpixel for 1BPP_DB
static void gp_putpixel_raw_16BPP(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
gp_putpixel for 16BPP
static void gp_putpixel_raw_24BPP(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
gp_putpixel for 24BPP
#define GP_PIXEL_ADDR_SHIFT_2BPP_DB(pixmap, x)
A macro to get bit-shift of pixel in 2BPP_DB pixmap.
static gp_pixel gp_getpixel_raw_1BPP_UB(const gp_pixmap *c, gp_coord x, gp_coord y)
gp_getpixel for 1BPP_UB
static void gp_putpixel_raw_4BPP_DB(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
gp_putpixel for 4BPP_DB
#define GP_PIXEL_ADDR_SHIFT_1BPP_DB(pixmap, x)
A macro to get bit-shift of pixel in 1BPP_DB pixmap.
static void gp_putpixel_raw_32BPP(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
gp_putpixel for 32BPP
static gp_pixel gp_getpixel_raw_2BPP_UB(const gp_pixmap *c, gp_coord x, gp_coord y)
gp_getpixel for 2BPP_UB
static gp_pixel gp_getpixel_raw_18BPP_DB(const gp_pixmap *c, gp_coord x, gp_coord y)
gp_getpixel for 18BPP_DB
static void gp_putpixel_raw_4BPP_UB(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
gp_putpixel for 4BPP_UB
static gp_pixel gp_getpixel_raw_8BPP(const gp_pixmap *c, gp_coord x, gp_coord y)
gp_getpixel for 8BPP
static gp_pixel gp_getpixel_raw_4BPP_DB(const gp_pixmap *c, gp_coord x, gp_coord y)
gp_getpixel for 4BPP_DB
static void gp_putpixel_raw_2BPP_DB(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
gp_putpixel for 2BPP_DB
#define GP_PIXEL_ADDR_1BPP_UB(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 1BPP_UB pixmap.
static gp_pixel gp_getpixel_raw_32BPP(const gp_pixmap *c, gp_coord x, gp_coord y)
gp_getpixel for 32BPP
#define GP_PIXEL_ADDR_18BPP_DB(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 18BPP_DB pixmap.
#define GP_PIXEL_ADDR_2BPP_UB(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 2BPP_UB pixmap.
static void gp_putpixel_raw_8BPP(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
gp_putpixel for 8BPP
static void gp_putpixel_raw_2BPP_UB(gp_pixmap *c, gp_coord x, gp_coord y, gp_pixel p)
gp_putpixel for 2BPP_UB
static gp_pixel gp_getpixel_raw_4BPP_UB(const gp_pixmap *c, gp_coord x, gp_coord y)
gp_getpixel for 4BPP_UB
#define GP_PIXEL_ADDR_SHIFT_4BPP_UB(pixmap, x)
A macro to get bit-shift of pixel in 4BPP_UB pixmap.
#define GP_PIXEL_ADDR_4BPP_DB(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 4BPP_DB pixmap.
#define GP_PIXEL_ADDR_24BPP(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 24BPP pixmap.
#define GP_PIXEL_ADDR_4BPP_UB(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 4BPP_UB pixmap.
#define GP_PIXEL_ADDR_SHIFT_24BPP(pixmap, x)
A macro to get bit-shift of pixel in 24BPP pixmap.
static gp_pixel gp_getpixel_raw_2BPP_DB(const gp_pixmap *c, gp_coord x, gp_coord y)
gp_getpixel for 2BPP_DB
#define GP_PIXEL_ADDR_1BPP_DB(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 1BPP_DB pixmap.
#define GP_PIXEL_ADDR_8BPP(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 8BPP pixmap.
#define GP_PIXEL_ADDR_32BPP(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 32BPP pixmap.
static gp_pixel gp_getpixel_raw_16BPP(const gp_pixmap *c, gp_coord x, gp_coord y)
gp_getpixel for 16BPP
#define GP_PIXEL_ADDR_SHIFT_1BPP_UB(pixmap, x)
A macro to get bit-shift of pixel in 1BPP_UB pixmap.
#define GP_PIXEL_ADDR_SHIFT_2BPP_UB(pixmap, x)
A macro to get bit-shift of pixel in 2BPP_UB pixmap.
#define GP_PIXEL_ADDR_SHIFT_18BPP_DB(pixmap, x)
A macro to get bit-shift of pixel in 18BPP_DB pixmap.
#define GP_PIXEL_ADDR_2BPP_DB(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 2BPP_DB pixmap.
#define GP_PIXEL_ADDR_16BPP(pixmap, x, y)
A macro to get address of a starting byte for a pixel in a 16BPP pixmap.
Helper macros to get and set bits given offset and length.
#define GP_GET_BITS1_ALIGNED(offset, len, buf)
Align-safe get bits.
#define GP_SET_BITS1_ALIGNED(offset, len, dest, val)
Align-safe set bits.
#define GP_SET_BITS3_ALIGNED(offset, len, dest, val)
Align-safe set bits.
#define GP_GET_BITS3_ALIGNED(offset, len, buf)
Align-safe get bits.
A pixel buffer.
#define GP_PIXEL_IS_CLIPPED(pixmap, x, y)
Returns true when pixel is clipped out of pixmap.
Definition gp_pixmap.h:127
A pixmap buffer.
Definition gp_pixmap.h:33