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>
27#include <core/gp_pixel_alias.h>
29
43typedef struct gp_pixel_channel {
45 char name[8];
47 uint8_t offset;
49 uint8_t size;
51
67
76 const char name[16];
78 uint8_t size;
80 uint8_t pack;
82 uint8_t numchannels;
86 const char bitmap[GP_PIXEL_BITS + 1];
89};
90
95
96#define GP_VALID_PIXELTYPE(type) (((type) > 0) && ((type) < GP_PIXEL_MAX))
97
98#define GP_CHECK_VALID_PIXELTYPE(type) \
99 GP_CHECK(GP_VALID_PIXELTYPE(type), "Invalid PixelType %d", (type))
100
101/*
102 * Convert pixel type to name.
103 */
104static inline const char *gp_pixel_type_name(gp_pixel_type type)
105{
106 GP_CHECK_VALID_PIXELTYPE(type);
107 return gp_pixel_types[type].name;
108}
109
110/*
111 * Returns number of bits per pixel.
112 */
113static inline uint32_t gp_pixel_size(gp_pixel_type type)
114{
115 GP_CHECK_VALID_PIXELTYPE(type);
116 return gp_pixel_types[type].size;
117}
118
119static inline const gp_pixel_type_desc *gp_pixel_desc(gp_pixel_type type)
120{
121 GP_CHECK_VALID_PIXELTYPE(type);
122 return &gp_pixel_types[type];
123}
124
125static inline unsigned int gp_pixel_channel_count(gp_pixel_type type)
126{
127 GP_CHECK_VALID_PIXELTYPE(type);
128 return gp_pixel_types[type].numchannels;
129}
130
131static inline uint8_t gp_pixel_channel_bits(gp_pixel_type type, uint8_t channel)
132{
133 GP_CHECK_VALID_PIXELTYPE(type);
134 return gp_pixel_types[type].channels[channel].size;
135}
136
137static inline const char *gp_pixel_channel_name(gp_pixel_type type,
138 uint8_t channel)
139{
140 GP_CHECK_VALID_PIXELTYPE(type);
141 return gp_pixel_types[type].channels[channel].name;
142}
143
144/*
145 * Print a human-readable representation of a pixel value to a string.
146 * Arguments as for snprintf().
147 */
148void gp_pixel_snprint(char *buf, size_t len, gp_pixel pixel, gp_pixel_type type);
149
150/*
151 * Prints human-readable representation of pixel value into the stdout.
152 */
153void gp_pixel_print(gp_pixel pixel, gp_pixel_type type);
154
155/*
156 * Returns pixel type for passed human-readable name (e.g. RGB888).
157 */
158gp_pixel_type gp_pixel_type_by_name(const char *name);
159
176 gp_pixel bmask, gp_pixel amask,
177 uint8_t bits_per_pixel);
178
199gp_pixel_type gp_pixel_rgb_lookup(uint32_t rsize, uint32_t roff,
200 uint32_t gsize, uint32_t goff,
201 uint32_t bsize, uint32_t boff,
202 uint32_t asize, uint32_t aoff,
203 uint8_t bits_per_pixel);
204
219
228gp_pixel gp_pixel_chan_mask(gp_pixel_type pixel_type, const char *chan_name);
229
242
243#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.
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.
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.
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:55
@ GP_PIXEL_IS_PALETTE
Pixel is palette.
Definition gp_pixel.h:61
@ GP_PIXEL_HAS_ALPHA
Pixel has an alpha channel.
Definition gp_pixel.h:57
@ GP_PIXEL_IS_CMYK
Pixel has CMYK channels.
Definition gp_pixel.h:63
@ GP_PIXEL_IS_GRAYSCALE
Pixel is grayscale.
Definition gp_pixel.h:65
@ GP_PIXEL_IS_RGB
Pixel has RGB channels.
Definition gp_pixel.h:59
Pixel type aliases.
Description of one pixel channel.
Definition gp_pixel.h:43
uint8_t offset
Definition gp_pixel.h:47
A description of a gp_pixel_type Assumes name with at most 15 chars.
Definition gp_pixel.h:72
const gp_pixel_channel channels[4]
An individual channel descriptions.
Definition gp_pixel.h:88
uint8_t pack
A pixel packing.
Definition gp_pixel.h:80
const char bitmap[(sizeof(gp_pixel) *8)+1]
String describing the bit-representaton (as in "RRRRRGGGGGGBBBBB")
Definition gp_pixel.h:86
gp_pixel_flags flags
Bitwise or of gp_pixel_flags.
Definition gp_pixel.h:84
uint8_t size
A pixel size in bits.
Definition gp_pixel.h:78
const char name[16]
A name e.g. xRGB8888.
Definition gp_pixel.h:76
gp_pixel_type type
An id of the pixel type.
Definition gp_pixel.h:74
uint8_t numchannels
A number of channels.
Definition gp_pixel.h:82