spiv: Fix image list counter
[gfxprim.git] / libs / core / GP_Pixel.gen.c.t
blob8a13a568b81012d4ddba5edeacd29616b53e8a3c
1 @ include source.t
2 /*
3  * Pixel type definitions and functions
4  *
5  * Copyright (C) 2011-2012 Tomas Gavenciak <gavento@ucw.cz>
6  * Copyright (C) 2011-2014 Cyril Hrubis <metan@ucw.cz>
7  */
9 #include <stdio.h>
10 #include "GP_Pixel.h"
11 #include "GP_GetSetBits.h"
13 @ def getflags(pt):
14 @     flags = []
15 @     if pt.is_alpha():
16 @         flags.append('GP_PIXEL_HAS_ALPHA')
17 @     if pt.is_rgb():
18 @         flags.append('GP_PIXEL_IS_RGB')
19 @     if pt.is_palette():
20 @         flags.append('GP_PIXEL_IS_PALETTE')
21 @     if pt.is_gray():
22 @         flags.append('GP_PIXEL_IS_GRAYSCALE')
23 @     if pt.is_cmyk():
24 @         flags.append('GP_PIXEL_IS_CMYK')
25 @     if flags:
26 @         return ' | '.join(flags)
27 @     else:
28 @         return 0
29 @ end
32  * Description of all known pixel types
33  */
34 const GP_PixelTypeDescription GP_PixelTypes [GP_PIXEL_MAX] = {
35 @ for pt in pixeltypes:
36         /* GP_PIXEL_{{ pt.name }} */ {
37                 .type   = GP_PIXEL_{{ pt.name }},
38                 .name   = "{{ pt.name }}",
39                 .size   = {{ pt.pixelsize.size }},
40                 .bit_endian  = {{ pt.pixelsize.bit_endian_const }},
41                 .numchannels = {{ len(pt.chanslist) }},
42                 .bitmap      = "{{ ''.join(pt.bits) }}",
43                 .flags       = {{ getflags(pt) }},
44                 .channels    = {
45 @     for c in pt.chanslist:
46                         { .name = "{{ c[0] }}", .offset = {{ c[1] }}, .size = {{ c[2] }} },
47 @     end
48                 }
49         },
50 @ end
53 @ for pt in pixeltypes:
54 @     if not pt.is_unknown():
56  * snprintf a human readable value of pixel type {{pt.name}}
57  */
58 static void GP_PixelSNPrint_{{ pt.name }}(char *buf, size_t len, GP_Pixel p)
60         snprintf(buf, len, "{{ pt.name }} 0x%0{{ (pt.pixelsize.size+3)//4 }}x {{ '=%d '.join(pt.chan_names) + '=%d' }}",
61                 GP_GET_BITS(0, {{ pt.pixelsize.size }}, p),
62                 {{ arr_to_params(pt.chan_names, 'GP_Pixel_GET_', '_' + pt.name + '(p)') }});
65 @ end
67 void GP_PixelSNPrint(char *buf, size_t len, GP_Pixel p, GP_PixelType pixel_type)
69         GP_FN_PER_PIXELTYPE(GP_PixelSNPrint, pixel_type, buf, len, p);
72 void GP_PixelPrint(GP_Pixel p, GP_PixelType pixel_type)
74         char buf[256];
75         GP_PixelSNPrint(buf, sizeof(buf), p, pixel_type);
76         puts(buf);