3 * Pixel type definitions and functions
5 * Copyright (C) 2011-2012 Tomas Gavenciak <gavento@ucw.cz>
6 * Copyright (C) 2011-2014 Cyril Hrubis <metan@ucw.cz>
11 #include "GP_GetSetBits.h"
16 @ flags.append('GP_PIXEL_HAS_ALPHA')
18 @ flags.append('GP_PIXEL_IS_RGB')
20 @ flags.append('GP_PIXEL_IS_PALETTE')
22 @ flags.append('GP_PIXEL_IS_GRAYSCALE')
24 @ flags.append('GP_PIXEL_IS_CMYK')
26 @ return ' | '.join(flags)
32 * Description of all known pixel types
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) }},
45 @ for c in pt.chanslist:
46 { .name = "{{ c[0] }}", .offset = {{ c[1] }}, .size = {{ c[2] }} },
53 @ for pt in pixeltypes:
54 @ if not pt.is_unknown():
56 * snprintf a human readable value of pixel type {{pt.name}}
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)') }});
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)
75 GP_PixelSNPrint(buf, sizeof(buf), p, pixel_type);