5 # GP_Pixel.gen.c, GP_Pixel.gen.h
7 # GP_Pixel_Access.gen.h
9 # 2011 - Tomas Gavenciak <gavento@ucw.cz>
12 from gfxprim
.generators
.generator
import *
13 from gfxprim
.generators
.pixeltype
import *
14 from gfxprim
.generators
.core
.gen_pixeltype
import *
15 from gfxprim
.generators
.core
.gen_pixel_access
import *
17 @generator(CHeaderGenerator(name
= 'GP_Pixel_Scale.gen.h'),
18 descr
= 'Fast value scaling macros\nDo not include directly, use GP_Pixel.h',
19 authors
= ["2011 - Tomas Gavenciak <gavento@ucw.cz>"])
20 def core_GP_Pixel_Scale_gen(h
):
22 "/* helper macros to transfer s1-bit value to s2-bit value\n"
23 " * NOTE: efficient and accurate for both up- and downscaling,\n"
24 " * WARNING: GP_SCALE_VAL requires constants numebrs as first two parameters\n"
26 "#define GP_SCALE_VAL(s1, s2, val) ( GP_SCALE_VAL_##s1##_##s2(val) )\n\n"
28 "{% for s1 in [1, 2, 4, 8] %}{% for s2 in [1, 2, 4, 8] %}"
30 "#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) * {{ multcoef(s1, s2) }})\n"
32 "#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) >> {{ s1 - s2 }})\n"
34 "{% endfor %}{% endfor %}", multcoef
= lambda s1
,s2
: hex(sum([1<<i
*s1
for i
in range(s2
/s1
)]))
37 @generator(CHeaderGenerator(name
='GP_Pixel.gen.h'),
38 CSourceGenerator(name
='GP_Pixel.gen.c'),
39 descr
= 'Pixel type definitions and functions\nDo not include directly, use GP_Pixel.h',
40 authors
= ["2011 - Tomas Gavenciak <gavento@ucw.cz>"])
41 def core_GP_Pixel_gen(h
, c
):
43 '#include <stdio.h>\n'
44 '#include "GP_Pixel.h"\n\n')
47 gen_GP_PixelType(h
, c
)
49 ## PixelType parameters in C
50 gen_GP_PixelTypes(h
, c
)
53 for t
in pixeltypes
.values():
54 if t
.name
!= 'UNKNOWN':
56 h
.rbody(str_description(t
))
58 c
.rbody(str_description(t
))
62 gen_get_pixel_addr(t
, h
, c
)
65 gen_convert_to(pixeltypes
['RGB565'], pixeltypes
['RGBA8888'], h
, c
)
66 gen_convert_to(pixeltypes
['RGBA8888'], pixeltypes
['V2'], h
, c
)
67 gen_convert_to(pixeltypes
['VA12'], pixeltypes
['RGBA8888'], h
, c
)
70 @generator(CHeaderGenerator(name
= 'GP_GetPutPixel.gen.h'),
71 descr
= 'Access pixel bytes, Get and PutPixel\nDo not include directly, use GP_Pixel.h',
72 authors
= ["2011 - Tomas Gavenciak <gavento@ucw.cz>"])
73 def core_GP_Pixel_Scale_gen(h
):
74 h
.rhead('#include "GP_Common.h"\n\n');
75 h
.rhead('struct GP_Context;\n\n');
76 # Per-bpp adress/offset macros
78 for bit_endian
in bit_endians
:
79 if (bpp
< 8) or (bit_endian
== bit_endians
[0]):
80 gen_get_pixel_addr_bpp(bpp
, get_size_suffix(bpp
, bit_endian
), h
)
82 # Per-bpp adress/offset macros
84 for bit_endian
in bit_endians
:
85 if (bpp
< 8) or (bit_endian
== bit_endians
[0]):
86 gen_getpixel_bpp(bpp
, get_size_suffix(bpp
, bit_endian
), h
)
87 gen_putpixel_bpp(bpp
, get_size_suffix(bpp
, bit_endian
), h
)