Rename GP_Pixel_Access to GP_GetPutPixel
[gfxprim.git] / pylib / gfxprim / generators / core / make_GP_Pixel.py
blob21cb25236e8f1a1465f42ce0b03fd0bec4a2ae3c
1 #!/usr/bin/python
3 # Script generating:
5 # GP_Pixel.gen.c, GP_Pixel.gen.h
6 # GP_Pixel_Scale.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):
21 h.rhead(
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"
25 " */\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] %}"
29 "{% if s2>s1 %}"
30 "#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) * {{ multcoef(s1, s2) }})\n"
31 "{% else %}"
32 "#define GP_SCALE_VAL_{{s1}}_{{s2}}(val) ((val) >> {{ s1 - s2 }})\n"
33 "{% endif %}"
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):
42 c.rhead(
43 '#include <stdio.h>\n'
44 '#include "GP_Pixel.h"\n\n')
46 ## Enum of types
47 gen_GP_PixelType(h, c)
49 ## PixelType parameters in C
50 gen_GP_PixelTypes(h, c)
52 ## List of types
53 for t in pixeltypes.values():
54 if t.name != 'UNKNOWN':
55 h.rbody(str_start(t))
56 h.rbody(str_description(t))
57 c.rbody(str_start(t))
58 c.rbody(str_description(t))
60 gen_print(t, h, c)
61 gen_get_chs(t, h, c)
62 gen_get_pixel_addr(t, h, c)
64 ## Conversion macros
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
77 for bpp in bitsizes:
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
83 for bpp in bitsizes:
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)