loaders: TIFF: Fix warnings.
[gfxprim/pasky.git] / libs / core / GP_Pixel.gen.c.t
blob302655f4b027d8b14b50e5255ed3d4f13a7d0649
1 /*****************************************************************************
2  * This file is part of gfxprim library.                                     *
3  *                                                                           *
4  * Gfxprim is free software; you can redistribute it and/or                  *
5  * modify it under the terms of the GNU Lesser General Public                *
6  * License as published by the Free Software Foundation; either              *
7  * version 2.1 of the License, or (at your option) any later version.        *
8  *                                                                           *
9  * Gfxprim is distributed in the hope that it will be useful,                *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
12  * Lesser General Public License for more details.                           *
13  *                                                                           *
14  * You should have received a copy of the GNU Lesser General Public          *
15  * License along with gfxprim; if not, write to the Free Software            *
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor,                        *
17  * Boston, MA  02110-1301  USA                                               *
18  *                                                                           *
19  * Copyright (C) 2011-2012 Tomas Gavenciak <gavento@ucw.cz>                  *
20  * Copyright (C) 2011-2013 Cyril Hrubis    <metan@ucw.cz>                    *
21  *                                                                           *
22  *****************************************************************************/
24 %% extends "base.c.t"
26 %% block descr
27 Pixel type definitions and functions
28 %% endblock
30 %% block body
31 #include <stdio.h>
32 #include "GP_Pixel.h"
33 #include "GP_GetSetBits.h"
35 %%- macro getflags(pt)
36 {% if pt.is_alpha() %} | GP_PIXEL_HAS_ALPHA{% endif -%}
37 {% if pt.is_rgb() %} | GP_PIXEL_IS_RGB{% endif -%}
38 {% if pt.is_palette() %} | GP_PIXEL_IS_PALETTE{% endif -%}
39 {% if pt.is_gray() %} | GP_PIXEL_IS_GRAYSCALE{% endif -%}
40 {% if pt.is_cmyk() %} | GP_PIXEL_IS_CMYK{% endif -%}
41 %%- endmacro
44  * Description of all known pixel types
45  */
46 const GP_PixelTypeDescription GP_PixelTypes [GP_PIXEL_MAX] = {
47 %%  for pt in pixeltypes
48         /* GP_PIXEL_{{ pt.name }} */ {
49                 .type   = GP_PIXEL_{{ pt.name }},
50                 .name   = "{{ pt.name }}",
51                 .size   = {{ pt.pixelsize.size }},
52                 .bit_endian  = {{ pt.pixelsize.bit_endian_const }},
53                 .numchannels = {{ len(pt.chanslist) }},
54                 .bitmap      = "{{ pt.bits|join("") }}",
55                 .flags       = 0{{ getflags(pt) }},
56                 .channels    = {
57 %%   for c in pt.chanslist
58                         { .name = "{{ c[0] }}", .offset = {{ c[1] }}, .size = {{ c[2] }} },
59 %%   endfor
60         } },
61 %%  endfor
64 %%  for pt in pixeltypes
65 %%   if not pt.is_unknown()
67  * snprintf a human readable value of pixel type {{pt.name}}
68  */
69 static void GP_PixelSNPrint_{{ pt.name }}(char *buf, size_t len, GP_Pixel p)
71         snprintf(buf, len, "{{ pt.name }} 0x%0{{ (pt.pixelsize.size+3)//4 }}x{% for c in pt.chanslist %} {{ c[0] }}=%d{% endfor %}",
72         GP_GET_BITS(0, {{ pt.pixelsize.size }}, p){% for c in pt.chanslist %}, GP_Pixel_GET_{{ c.name}}_{{ pt.name }}(p){% endfor %});
75 %%   endif
76 %%  endfor
78 void GP_PixelSNPrint(char *buf, size_t len, GP_Pixel p, GP_PixelType pixel_type)
80         GP_FN_PER_PIXELTYPE(GP_PixelSNPrint, pixel_type, buf, len, p);
83 void GP_PixelPrint(GP_Pixel p, GP_PixelType pixel_type)
85         char buf[256];
86         GP_PixelSNPrint(buf, sizeof(buf), p, pixel_type);
87         puts(buf);
90 %% endblock body