4 Access pixel bytes, Get and PutPixel
5 Do not include directly, use GP_Pixel.h
10 #include "GP_Common.h"
14 %% for ps in pixelsizes
16 * macro to get address of pixel in a {{ ps.suffix }} context
18 #define GP_PIXEL_ADDR_{{ ps.suffix }}(context, x, y) \
19 ((GP_Pixel*)(((void*)((context)->pixels)) + (context)->bytes_per_row * (y) + ({{ ps.size }} * (x)) / 8))
22 * macro to get bit-offset of pixel in {{ ps.suffix }} context
24 #define GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x) \
25 %% if not ps.needs_bit_endian()
28 %% if ps.bit_endian == LE
30 (((x) % {{ 8 // ps.size }}) * {{ ps.size }})
32 (({{ ps.size }} * (x)) % 8)
36 ({{ 8 - ps.size }} - ((x) % {{ 8 // ps.size }}) * {{ ps.size }})
38 {{ error('Insanity check: big bit-endian with >8 bpp. Are you sure?') }}
44 * GP_GetPixel for {{ ps.suffix }}
46 static inline GP_Pixel GP_GetPixel_Raw_{{ ps.suffix }}(const GP_Context *c, int x, int y)
48 return GP_GET_BITS(GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x), {{ ps.size }},
49 *(GP_PIXEL_ADDR_{{ ps.suffix}}(c, x, y)));
53 * GP_PutPixel for {{ ps.suffix }}
55 static inline void GP_PutPixel_Raw_{{ ps.suffix }}(GP_Context *c, int x, int y, GP_Pixel p)
57 GP_SET_BITS(GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x), {{ ps.size }},
58 *(GP_PIXEL_ADDR_{{ ps.suffix}}(c, x, y)), p);