GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_pixel.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos
4 * <jiri.bluebear.dluhos@gmail.com>
5 *
6 * Copyright (C) 2009-2024 Cyril Hrubis <metan@ucw.cz>
7 *
8 * Copyright (C) 2011 Tomas Gavenciak <gavento@ucw.cz>
9 */
10
16#ifndef CORE_GP_PIXEL_H
17#define CORE_GP_PIXEL_H
18
19#include <stdint.h>
20
21#include <core/gp_types.h>
22#include <core/gp_common.h>
23
24#define GP_PIXEL_BITS (sizeof(gp_pixel) * 8)
25
26#include <core/gp_pixel.gen.h>
28#include <core/gp_pixel_alias.h>
30
44typedef struct gp_pixel_channel {
46 char name[8];
48 uint8_t offset;
50 uint8_t size;
56 uint8_t lin_size;
58
74
83 const char name[16];
85 uint8_t size;
87 uint8_t pack;
89 uint8_t numchannels;
93 const char bitmap[GP_PIXEL_BITS + 1];
96};
97
102
103#define GP_VALID_PIXELTYPE(type) (((type) > 0) && ((type) < GP_PIXEL_MAX))
104
105#define GP_CHECK_VALID_PIXELTYPE(type) \
106 GP_CHECK(GP_VALID_PIXELTYPE(type), "Invalid PixelType %d", (type))
107
108/*
109 * Convert pixel type to name.
110 */
111static inline const char *gp_pixel_type_name(gp_pixel_type type)
112{
113 GP_CHECK_VALID_PIXELTYPE(type);
114 return gp_pixel_types[type].name;
115}
116
117/*
118 * Returns number of bits per pixel.
119 */
120static inline uint32_t gp_pixel_size(gp_pixel_type type)
121{
122 GP_CHECK_VALID_PIXELTYPE(type);
123 return gp_pixel_types[type].size;
124}
125
133{
134 GP_CHECK_VALID_PIXELTYPE(type);
135 return &gp_pixel_types[type];
136}
137
144static inline unsigned int gp_pixel_channel_count(gp_pixel_type type)
145{
146 GP_CHECK_VALID_PIXELTYPE(type);
147 return gp_pixel_types[type].numchannels;
148}
149
157static inline uint8_t gp_pixel_channel_bits(gp_pixel_type type, uint8_t channel)
158{
159 GP_CHECK_VALID_PIXELTYPE(type);
160 return gp_pixel_types[type].channels[channel].size;
161}
162
170static inline uint8_t gp_pixel_channel_lin_bits(gp_pixel_type type, uint8_t channel)
171{
172 GP_CHECK_VALID_PIXELTYPE(type);
173 return gp_pixel_types[type].channels[channel].lin_size;
174}
175
183static inline const char *gp_pixel_channel_name(gp_pixel_type type,
184 uint8_t channel)
185{
186 GP_CHECK_VALID_PIXELTYPE(type);
187 return gp_pixel_types[type].channels[channel].name;
188}
189
198 uint8_t channel)
199{
200 GP_CHECK_VALID_PIXELTYPE(type);
201 return gp_pixel_types[type].channels[channel].name[0] == 'A';
202}
203
204/*
205 * Print a human-readable representation of a pixel value to a string.
206 * Arguments as for snprintf().
207 */
208void gp_pixel_snprint(char *buf, size_t len, gp_pixel pixel, gp_pixel_type type);
209
210/*
211 * Prints human-readable representation of pixel value into the stdout.
212 */
213void gp_pixel_print(gp_pixel pixel, gp_pixel_type type);
214
215/*
216 * Returns pixel type for passed human-readable name (e.g. RGB888).
217 */
218gp_pixel_type gp_pixel_type_by_name(const char *name);
219
236 gp_pixel bmask, gp_pixel amask,
237 uint8_t bits_per_pixel);
238
259gp_pixel_type gp_pixel_rgb_lookup(uint32_t rsize, uint32_t roff,
260 uint32_t gsize, uint32_t goff,
261 uint32_t bsize, uint32_t boff,
262 uint32_t asize, uint32_t aoff,
263 uint8_t bits_per_pixel);
264
279
288gp_pixel gp_pixel_chan_mask(gp_pixel_type pixel_type, const char *chan_name);
289
302
303#endif /* CORE_GP_PIXEL_H */
Common macros.
A common types.
uint32_t gp_pixel
Pixel integer value.
Definition gp_types.h:33
Helper macros to get and set bits given offset and length.
A pixel defintions generated from gen/include/gfxprim_config.py.
#define GP_PIXEL_CHANS_MAX
Maximal number of channels per all defined pixel types.
gp_pixel_type
List of all pixel types.
@ GP_PIXEL_MAX
Last valid pixel type has value GP_PIXEL_MAX-1.
int gp_pixel_has_flags(gp_pixel_type pixel_type, gp_pixel_flags flags)
Function to determine pixel attributes.
static int gp_pixel_channel_is_alpha(gp_pixel_type type, uint8_t channel)
Returns true if pixel channel is alpha channel.
Definition gp_pixel.h:197
gp_pixel gp_pixel_chan_mask(gp_pixel_type pixel_type, const char *chan_name)
Returns channel mask for a given pixel type and channel name.
const gp_pixel_type_desc gp_pixel_types[GP_PIXEL_MAX]
Array with description for all pixel types.
gp_pixel gp_pixel_chans_add(gp_pixel_type pixel_type, gp_pixel pixel, int add)
Does per-channel saturated addition.
static uint8_t gp_pixel_channel_bits(gp_pixel_type type, uint8_t channel)
Returns number of bits for a pixel channel.
Definition gp_pixel.h:157
gp_pixel_type gp_pixel_rgb_match(gp_pixel rmask, gp_pixel gmask, gp_pixel bmask, gp_pixel amask, uint8_t bits_per_pixel)
Matches a RGB pixel type againts known pixel types.
static uint8_t gp_pixel_channel_lin_bits(gp_pixel_type type, uint8_t channel)
Returns number of bits for a linearized pixel channel.
Definition gp_pixel.h:170
static const gp_pixel_type_desc * gp_pixel_desc(gp_pixel_type type)
Returns a pixel type description for a pixel type enum.
Definition gp_pixel.h:132
static unsigned int gp_pixel_channel_count(gp_pixel_type type)
Returns a numbers of pixel channels.
Definition gp_pixel.h:144
gp_pixel_type gp_pixel_rgb_lookup(uint32_t rsize, uint32_t roff, uint32_t gsize, uint32_t goff, uint32_t bsize, uint32_t boff, uint32_t asize, uint32_t aoff, uint8_t bits_per_pixel)
Looks up a RGB pixel type against know pixel types.
gp_pixel_flags
Pixel type flags for various pixel properties.
Definition gp_pixel.h:62
@ GP_PIXEL_IS_PALETTE
Pixel is palette.
Definition gp_pixel.h:68
@ GP_PIXEL_HAS_ALPHA
Pixel has an alpha channel.
Definition gp_pixel.h:64
@ GP_PIXEL_IS_CMYK
Pixel has CMYK channels.
Definition gp_pixel.h:70
@ GP_PIXEL_IS_GRAYSCALE
Pixel is grayscale.
Definition gp_pixel.h:72
@ GP_PIXEL_IS_RGB
Pixel has RGB channels.
Definition gp_pixel.h:66
static const char * gp_pixel_channel_name(gp_pixel_type type, uint8_t channel)
Returns number of bits for a pixel channel.
Definition gp_pixel.h:183
Pixel type aliases.
A pixel channel manipulations generated from gen/include/gfxprim_config.py.
Description of one pixel channel.
Definition gp_pixel.h:44
uint8_t offset
Definition gp_pixel.h:48
uint8_t lin_size
Definition gp_pixel.h:56
A description of a gp_pixel_type Assumes name with at most 15 chars.
Definition gp_pixel.h:79
const gp_pixel_channel channels[4]
An individual channel descriptions.
Definition gp_pixel.h:95
uint8_t pack
A pixel packing.
Definition gp_pixel.h:87
const char bitmap[(sizeof(gp_pixel) *8)+1]
String describing the bit-representaton (as in "RRRRRGGGGGGBBBBB")
Definition gp_pixel.h:93
gp_pixel_flags flags
Bitwise or of gp_pixel_flags.
Definition gp_pixel.h:91
uint8_t size
A pixel size in bits.
Definition gp_pixel.h:85
const char name[16]
A name e.g. xRGB8888.
Definition gp_pixel.h:83
gp_pixel_type type
An id of the pixel type.
Definition gp_pixel.h:81
uint8_t numchannels
A number of channels.
Definition gp_pixel.h:89