Tweak PixelType definitons
[gfxprim.git] / core / GP_Pixel.h
blobfeb7eac8e0aef70750be178ef918c9fe9665121a
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) 2009-2010 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
21 * *
22 * Copyright (C) 2009-2010 Cyril Hrubis <metan@ucw.cz> *
23 * *
24 *****************************************************************************/
26 #ifndef GP_PIXEL_H
27 #define GP_PIXEL_H
29 #include <stdbool.h>
30 #include <stdint.h>
32 #include "GP_Color.h"
33 #include "GP_Common.h"
34 #include "GP_RetCode.h"
36 struct GP_Context;
39 * GP_PixelType is typedef enum of PixelTypes,
41 * each named GP_PIXEL_<TYPENAME>, such as GP_PIXEL_GRB888
42 * see the beginning of GP_Pixel.gen.h for a complete list
44 * The type always contains GP_PIXEL_UNKNOWN = 0 and
45 * GP_PIXEL_MAX as the last value (also the number of valid types)
46 * The types are numbered to use the entire range 0 .. GP_PIXEL_MAX-1
50 * GP_Pixel is just uint32_t
53 typedef uint32_t GP_Pixel;
55 /* Generated header */
56 #include "GP_Pixel.gen.h"
59 * Information about ordering of pixels in byte for 1, 2 and 4 bpp
60 * used in a one bit variable in GP_Context
63 typedef enum {
64 /* less significant bits contain pixels with lower indices */
65 GP_BIT_ENDIAN_LE = 0,
66 /* more significant bits contain pixels with lower indices */
67 GP_BIT_ENDIAN_BE,
68 } GP_BIT_ENDIAN;
71 * Description of one channel
72 * Assumes all the channel names to be at most 7 chars long
74 * The common channel names are:
75 * R, G, B - as usual
76 * V - value, for grayscale
77 * A - opacity (0=transparent)
78 * P - palette (index)
81 typedef struct {
82 char name[8]; /* Channel name */
83 uint8_t offset; /* Offset in bits */
84 uint8_t size; /* Bit-size */
85 } GP_PixelTypeChannel;
88 * Maximum number of channels in a PixelType
91 #define GP_PIXELTYPE_MAX_CHANNELS 8
94 * Description of one PixelType
95 * Assumes name with at most 15 chars
96 * Assumes at most 8 channels
99 typedef struct {
100 GP_PixelType type; /* Number of the type */
101 const char name[16]; /* Name */
102 uint8_t size; /* Size in bits */
103 GP_BIT_ENDIAN bit_endian; /* Order of pixels in a byte */
104 uint8_t numchannels; /* Number of channels */
105 /* String describing the bit-representaton (as in "RRRRRGGGGGGBBBBB")*/
106 const char bitmap[sizeof(GP_Pixel) * 8 + 1];
107 /* Individual channels */
108 const GP_PixelTypeChannel channels[GP_PIXELTYPE_MAX_CHANNELS];
109 } GP_PixelTypeDescription;
112 * Array of size GP_PIXEL_MAX describing known pixel types
115 extern const GP_PixelTypeDescription const GP_PixelTypes[];
118 * Convert pixel type to name.
121 static inline const char *GP_PixelTypeName(GP_PixelType type)
123 GP_CHECK(type < GP_PIXEL_MAX);
124 return GP_PixelTypes[type].name;
128 * Returns number of bits per pixel.
131 static inline uint32_t GP_PixelSize(GP_PixelType type)
133 GP_CHECK(type < GP_PIXEL_MAX);
134 return GP_PixelTypes[type].size;
138 /* Below -- TODO sync with new pixel type */
141 * Returns GP_PixelType to GP_ColorType mapping.
143 //GP_ColorType GP_PixelTypeToColorType(GP_PixelType type);
146 * Converts a color to the specified pixel type.
148 //GP_RetCode GP_ColorToPixelType(GP_PixelType pixel_type, GP_Color color, GP_Pixel *pixel);
151 * Converts a color to a pixel value suitable for the specified context.
153 //GP_RetCode GP_ColorToPixel(struct GP_Context *context, GP_Color color, GP_Pixel *pixel);
158 //GP_RetCode GP_ColorNameToPixel(struct GP_Context *context, GP_ColorName name, GP_Pixel *pixel);
161 * Converts a color name to the specified pixel type.
163 //GP_RetCode GP_ColorNameToPixelType(GP_PixelType pixel_type, GP_ColorName name, GP_Pixel *pixel);
166 * Converts a color specified by its R, G, B components to a pixel value
167 * compatible with the specified context.
169 GP_RetCode GP_RGBToPixel(struct GP_Context *context, uint8_t r, uint8_t g, uint8_t b, GP_Pixel *pixel);
171 #endif /* GP_PIXEL_H */