GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Pixmap

Data Structures

struct  gp_pixmap
 A pixmap buffer. More...
 

Macros

#define GP_PIXEL_IS_CLIPPED(pixmap, x, y)
 Returns true when pixel is clipped out of pixmap.
 

Functions

gp_pixmapgp_pixmap_alloc_ex (gp_size w, gp_size h, gp_pixel_type type, uint32_t stride)
 Allocates a pixmap.
 
static gp_pixmapgp_pixmap_alloc (gp_size w, gp_size h, gp_pixel_type type)
 Allocates a pixmap.
 
int gp_pixmap_correction_set (gp_pixmap *self, gp_correction_desc *corr_desc)
 Sets a correction for the pixmap.
 
static int gp_pixmap_gamma_set (gp_pixmap *self, float gamma)
 Sets a gamma correction for the pixmap.
 
static int gp_pixmap_srgb_set (gp_pixmap *self)
 Sets a sRGB correction for the pixmap.
 
void gp_pixmap_free (gp_pixmap *self)
 Frees a pixmap.
 
static gp_pixmapgp_pixmap_from_data (gp_size w, gp_size h, gp_pixel_type type, void *pixels, enum gp_pixmap_init_flags flags)
 Creates a pixmap from a buffer allocated by malloc().
 

Detailed Description

Macro Definition Documentation

◆ GP_PIXEL_IS_CLIPPED

#define GP_PIXEL_IS_CLIPPED ( pixmap,
x,
y )
Value:
((x) < 0 || x >= (typeof(x)) pixmap->w \
|| (y) < 0 || y >= (typeof(y)) pixmap->h) \

Returns true when pixel is clipped out of pixmap.

This macro does not take into account the rotation flags. Pixel has to be rotated with GP_TRANSFORM_POINT() first.

Definition at line 131 of file gp_pixmap.h.

Function Documentation

◆ gp_pixmap_alloc()

static gp_pixmap * gp_pixmap_alloc ( gp_size w,
gp_size h,
gp_pixel_type type )
inlinestatic

Allocates a pixmap.

This is a shortcut for gp_pixmap_alloc_ex() without the stride parameter (stride set to 0 to be determined by the library).

Parameters
wA pixmap width.
hA pixmap height.
typeA pixel type.
Returns
A newly allocated pixmap or NULL in a case of malloc() failure.

Definition at line 185 of file gp_pixmap.h.

References gp_pixmap_alloc_ex().

◆ gp_pixmap_alloc_ex()

gp_pixmap * gp_pixmap_alloc_ex ( gp_size w,
gp_size h,
gp_pixel_type type,
uint32_t stride )

Allocates a pixmap.

The pixmap consists of two parts, the gp_pixmap structure and pixels buffer.

Upon creation the pixmap rotation flags are set to (0, 0, 0) and gamma is set to NULL. If gamma correction is needed it has to be initialized by gp_pixmap_gamma_set() or gp_pixmap_srgb_set().

It's possible to allocate a pixmap with zero w and h and in that case the gp_pixmap::pixels pointer will be set to NULL. Such pixmap must be resized with gp_pixmap_resize() to non-zero w and h in order to actually draw any pixels.

The content of gp_pixmap::pixels buffer is undefined.

The pixmap has to be freed with gp_pixmap_free() when no longer needed.

Parameters
wA pixmap width.
hA pixmap height.
typeA pixel type.
strideThe length in bytes of an image buffer row. Must be larger or equal than pixel size in bytes multiplied by width. It's determinted automatically when 0 is passed.
Returns
A newly allocated and initialized pixmap.
NULL in a case of failure and errno is set.
Exceptions
EINVALInvalid pixel type or stride.
ENOMEMMemory allocation failure.
EOVERFLOWOne of the multiplications did overflow when pixel buffer size was calculated.

Referenced by gp_pixmap_alloc().

◆ gp_pixmap_correction_set()

int gp_pixmap_correction_set ( gp_pixmap * self,
gp_correction_desc * corr_desc )

Sets a correction for the pixmap.

If there was a gamma correction allready set for the pixmap the original correction reference counters are decremented and the correction is replaced with a new table.

Parameters
selfA pixmap.
corr_descA correction description.
Returns
Zero on success. May fail if underlying malloc() has failed.

Referenced by gp_pixmap_gamma_set(), and gp_pixmap_srgb_set().

◆ gp_pixmap_free()

void gp_pixmap_free ( gp_pixmap * self)

Frees a pixmap.

If pixmap->free_pixels is set also free pixel data, this flag is set automatically by gp_pixmap_alloc() and gp_pixmap_alloc_ex().

Parameters
selfA pixmap to free.

◆ gp_pixmap_from_data()

static gp_pixmap * gp_pixmap_from_data ( gp_size w,
gp_size h,
gp_pixel_type type,
void * pixels,
enum gp_pixmap_init_flags flags )
inlinestatic

Creates a pixmap from a buffer allocated by malloc().

This is actually shorthand for allocating the gp_pixmap structure and calling gp_pixmap_init() on the resulting pointer.

Attention
The user has to make sure that the pixels array has correct size and format.
Parameters
wPixmap width
hPixmap height
typeA pixel type, describes how pixels are organized in the data buffer.
pixelsA pointer to a buffer with the pixel data.
flagsA bitmask or of the enum gp_pixmap_init_flags
Returns
A newly allocated and initialized pixmap or NULL in a case of a failure.

Definition at line 346 of file gp_pixmap.h.

References gp_pixmap_init().

◆ gp_pixmap_gamma_set()

static int gp_pixmap_gamma_set ( gp_pixmap * self,
float gamma )
inlinestatic

Sets a gamma correction for the pixmap.

This is a shorthand for:

.gamma = gamma;
};
@ GP_CORRECTION_TYPE_GAMMA
Classical gamma correction.
int gp_pixmap_correction_set(gp_pixmap *self, gp_correction_desc *corr_desc)
Sets a correction for the pixmap.
A correction description.
Parameters
selfA pixmap.
gammaA gamma value.
Returns
Zero on success. May fail if underlying malloc() has failed.

Definition at line 224 of file gp_pixmap.h.

References GP_CORRECTION_TYPE_GAMMA, and gp_pixmap_correction_set().

◆ gp_pixmap_srgb_set()

static int gp_pixmap_srgb_set ( gp_pixmap * self)
inlinestatic

Sets a sRGB correction for the pixmap.

This is a shorthand for:

};
@ GP_CORRECTION_TYPE_SRGB
Standard RGB.
Parameters
selfA pixmap.
Returns
Zero on success. May fail if underlying malloc() has failed.

Definition at line 251 of file gp_pixmap.h.

References GP_CORRECTION_TYPE_SRGB, and gp_pixmap_correction_set().