Fixed pointer types in Put/GetPixel. Fix pixel offset.
[gfxprim.git] / include / core / GP_GetPutPixel.gen.h.t
blob26a73d736caf3474c5e448bbe589b3c37da9d3c6
1 %% extends "base.h.t"
3 %% block descr
4 Access pixel bytes, Get and PutPixel
5 Do not include directly, use GP_Pixel.h
6 %% endblock
8 %% block body
10 #include "GP_Common.h"
12 struct GP_Context;
14 %% for ps in pixelsizes
15 /* 
16  * macro to get address of pixel in a {{ ps.suffix }} context
17  */
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
23  */
24 #define GP_PIXEL_ADDR_OFFSET_{{ ps.suffix }}(x) \
25 %% if not ps.needs_bit_endian()
26         (0)
27 %% else
28 %% if ps.bit_endian == LE
29 %% if ps.size < 8
30         (((x) % {{ 8 // ps.size }}) * {{ ps.size }})
31 %% else
32         (({{ ps.size }} * (x)) % 8)
33 %% endif
34 %% else
35 %% if ps.size < 8
36         ({{ 8 - ps.size }} - ((x) % {{ 8 // ps.size }}) * {{ ps.size }})
37 %% else
38         {{ error('Insanity check: big bit-endian with >8 bpp. Are you sure?') }}
39 %% endif
40 %% endif
41 %% endif
44  * GP_GetPixel for {{ ps.suffix }} 
45  */
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 }} 
54  */
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);
61 %% endfor
63 %% endblock body