spiv: Fix image list counter
[gfxprim.git] / libs / core / GP_Convert.gen.c.t
blob674e04dccdf71b5e910e7bf9236b428ba9a1c125
1 @ include source.t
2 /*
3  * Convert PixelType values macros and functions
4  *
5  * Copyright (C) 2011      Tomas Gavenciak <gavento@ucw.cz>
6  * Copyright (C) 2011-2014 Cyril Hrubis <metan@ucw.cz>
7  */
9 #include "GP_Convert.h"
11 @ # Loop around pixel types central for the conversion.
12 @ for pt in [pixeltypes_dict['RGB888'], pixeltypes_dict['RGBA8888']]:
14 GP_Pixel GP_{{ pt.name }}ToPixel(GP_Pixel pixel, GP_PixelType type)
16         GP_Pixel p = 0;
17         switch (type) {
18 @     for tf in pixeltypes:
19 @         if tf.is_unknown():
20                 case GP_PIXEL_UNKNOWN:
21                         GP_ABORT("Cannot convert {{ pt.name }} to GP_PIXEL_UNKNOWN");
22                         break;
23 @         elif tf.is_palette():
24                 case GP_PIXEL_{{ tf.name }}:
25                         GP_ABORT("Cannot convert {{ pt.name }} to palette type {{ tf.name }}");
26                         break;
27 @         else:
28                 case GP_PIXEL_{{ tf.name }}:
29                         GP_Pixel_{{ pt.name }}_TO_{{ tf.name }}(pixel, p);
30                         break;
31 @     end
32                 default:
33                         GP_ABORT("Unknown PixelType %ud", type);
34         }
35         return p;
38 GP_Pixel GP_PixelTo{{ pt.name }}(GP_Pixel pixel, GP_PixelType type)
40         GP_Pixel p = 0;
41         switch (type) {
42 @     for sf in pixeltypes:
43 @         if sf.is_unknown():
44                 case GP_PIXEL_UNKNOWN:
45                         GP_ABORT("Cannot convert from GP_PIXEL_UNKNOWN");
46                         break;
47 @         elif sf.is_palette():
48                 case GP_PIXEL_{{ sf.name }}:
49                         GP_ABORT("Cannot convert from palette type {{ sf.name }} (yet)");
50                         break;
51 @         else:
52                 case GP_PIXEL_{{ sf.name }}:
53                         GP_Pixel_{{ sf.name }}_TO_{{ pt.name }}(pixel, p);
54                         break;
55 @     end
56                 default:
57                         GP_ABORT("Unknown PixelType %u", type);
58         }
59         return p;