GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions
gp_pixmap.h File Reference

A pixel buffer. More...

#include <stdint.h>
#include <unistd.h>
#include <core/gp_common.h>
#include <core/gp_types.h>
#include <core/gp_pixel.h>
#include <core/gp_gamma_correction.h>

Go to the source code of this file.

Data Structures

struct  gp_pixmap
 A pixmap buffer. More...
 

Macros

#define GP_PIXEL_ADDR(pixmap, x, y)
 Returns pixel addres in an image.
 
#define GP_PIXEL_IS_CLIPPED(pixmap, x, y)
 Returns true when pixel is clipped out of pixmap.
 

Enumerations

enum  gp_pixmap_init_flags { GP_PIXMAP_FREE_PIXELS = 0x01 }
 A pixmap init flags. More...
 
enum  gp_pixmap_copy_flags { GP_COPY_WITH_PIXELS = 0x01 , GP_COPY_WITH_ROTATION = 0x02 }
 A pixmap copy flags. More...
 

Functions

gp_pixmapgp_pixmap_alloc (gp_size w, gp_size h, gp_pixel_type type)
 Allocates a pixmap.
 
int gp_pixmap_gamma_set (gp_pixmap *self, gp_correction_type corr_type, float gamma)
 Sets a correction for the pixmap.
 
void gp_pixmap_free (gp_pixmap *self)
 Frees a pixmap.
 
gp_pixmapgp_pixmap_init (gp_pixmap *pixmap, gp_size w, gp_size h, gp_pixel_type type, void *pixels, enum gp_pixmap_init_flags flags)
 Initializes allocated pixmap structure.
 
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().
 
int gp_pixmap_resize (gp_pixmap *self, gp_size w, gp_size h)
 Resizes pixmap.
 
gp_pixmapgp_pixmap_copy (const gp_pixmap *src, enum gp_pixmap_copy_flags flags)
 Copies a pixmap.
 
gp_pixmapgp_sub_pixmap (const gp_pixmap *src, gp_pixmap *subpixmap, gp_coord x, gp_coord y, gp_size w, gp_size h)
 Initializes a subpixmap.
 
gp_pixmapgp_sub_pixmap_alloc (const gp_pixmap *src, gp_coord x, gp_coord y, gp_size w, gp_size h)
 Allocate and initalize a subpixmap.
 
void gp_pixmap_print_info (const gp_pixmap *self)
 Prints pixmap information into stdout.
 
void gp_pixmap_rotate_cw (gp_pixmap *self)
 Rotates pixmap flags clockwise.
 
void gp_pixmap_rotate_ccw (gp_pixmap *self)
 Rotates pixmap flags counter clock wise.
 
static int gp_pixmap_rotation_equal (const gp_pixmap *c1, const gp_pixmap *c2)
 Compares rotation flags for two pixmaps.
 
static void gp_pixmap_rotation_set (gp_pixmap *self, int axes_swap, int x_swap, int y_swap)
 Sets pixmap rotation flags.
 
static void gp_pixmap_rotation_copy (const gp_pixmap *src, gp_pixmap *dst)
 Copies rotation flags from one pixmap to another.
 
static gp_size gp_pixmap_w (const gp_pixmap *self)
 Returns pixmap width taking axes swap into account.
 
static gp_size gp_pixmap_h (const gp_pixmap *self)
 Returns pixmap height taking axes swap into account.
 

Detailed Description

A pixel buffer.

Definition in file gp_pixmap.h.

Macro Definition Documentation

◆ GP_PIXEL_ADDR

#define GP_PIXEL_ADDR (   pixmap,
  x,
 
)
Value:
((pixmap)->pixels \
+ (y) * (pixmap)->bytes_per_row \
+ ((x + (pixmap)->offset) * gp_pixel_size((pixmap)->pixel_type)) / 8)

Returns pixel addres in an image.

Determines the address of a pixel within the pixmap's buffer.

Rows and columns are specified in the image origiinal orientation i.e. this macro ignores the rotation flags.

Definition at line 109 of file gp_pixmap.h.

Enumeration Type Documentation

◆ gp_pixmap_copy_flags

A pixmap copy flags.

Enumerator
GP_COPY_WITH_PIXELS 

Copy bitmap pixels too. If not set pixels are uninitalized

GP_COPY_WITH_ROTATION 

Copy image rotation flags. If not set flags are set to (0, 0, 0)

Definition at line 256 of file gp_pixmap.h.

◆ gp_pixmap_init_flags

A pixmap init flags.

Enumerator
GP_PIXMAP_FREE_PIXELS 

If set the pixmap->pixels is freed on gp_pixmap_free()

Definition at line 178 of file gp_pixmap.h.

Function Documentation

◆ gp_pixmap_copy()

gp_pixmap * gp_pixmap_copy ( const gp_pixmap src,
enum gp_pixmap_copy_flags  flags 
)

Copies a pixmap.

Allocates a pixmap with exactly same data as source pixmap.

Parameters
srcAn input pixmap.
flagsAn enum gp_pixmap_copy_flags.
Returns
A newly allocated and initialized pixmap or NULL in a case of a failure.

◆ gp_pixmap_h()

static gp_size gp_pixmap_h ( const gp_pixmap self)
inlinestatic

Returns pixmap height taking axes swap into account.

Parameters
selfA pixmap.
Returns
A pixmap height taking axes swap into an account.

Definition at line 425 of file gp_pixmap.h.

References gp_pixmap::axes_swap, gp_pixmap::h, and gp_pixmap::w.

◆ gp_pixmap_init()

gp_pixmap * gp_pixmap_init ( gp_pixmap pixmap,
gp_size  w,
gp_size  h,
gp_pixel_type  type,
void *  pixels,
enum gp_pixmap_init_flags  flags 
)

Initializes allocated pixmap structure.

Initalize pixmap structure, pixels pointer is not dereferenced so it's safe to pass NULL there and allocate it later with size pixmap->bpr * pixmap->h.

BEWARE: The user has to make sure that the pixels array has correct size and format.

Parameters
pixmapA pointer to a pixmap structure to be initialized with a data.
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
Returns pointer to pixmap that is passed as first argument.

Referenced by gp_pixmap_from_data().

◆ gp_pixmap_print_info()

void gp_pixmap_print_info ( const gp_pixmap self)

Prints pixmap information into stdout.

Parameters
selfA pixmap to print an info about.

◆ gp_pixmap_resize()

int gp_pixmap_resize ( gp_pixmap self,
gp_size  w,
gp_size  h 
)

Resizes pixmap.

This only resizes the buffer, the pixel values are uninitialized after the operation!

If you are looking for functions to resize an image you are looking for resampling filters.

Parameters
selfA pixmap.
wA new width.
hA new height.
Returns
Zero on success non-zero on failure if underlying malloc() has failed.

◆ gp_pixmap_rotate_ccw()

void gp_pixmap_rotate_ccw ( gp_pixmap self)

Rotates pixmap flags counter clock wise.

Parameters
selfA pixmap.

The underlying pixmap buffer is not changed, only the rotation flags are affected.

◆ gp_pixmap_rotate_cw()

void gp_pixmap_rotate_cw ( gp_pixmap self)

Rotates pixmap flags clockwise.

Parameters
selfA pixmap.

The underlying pixmap buffer is not changed, only the rotation flags are affected.

◆ gp_pixmap_rotation_copy()

static void gp_pixmap_rotation_copy ( const gp_pixmap src,
gp_pixmap dst 
)
inlinestatic

Copies rotation flags from one pixmap to another.

Parameters
srcA source pixmap for rotation flags.
dstA destination pixmap for rotation flags.

Definition at line 397 of file gp_pixmap.h.

References gp_pixmap::axes_swap, gp_pixmap::x_swap, and gp_pixmap::y_swap.

◆ gp_pixmap_rotation_equal()

static int gp_pixmap_rotation_equal ( const gp_pixmap c1,
const gp_pixmap c2 
)
inlinestatic

Compares rotation flags for two pixmaps.

Parameters
c1A pixmap.
c2A pixmap.
Returns
True if rotation flags are equal.

Definition at line 367 of file gp_pixmap.h.

References gp_pixmap::axes_swap, gp_pixmap::x_swap, and gp_pixmap::y_swap.

◆ gp_pixmap_rotation_set()

static void gp_pixmap_rotation_set ( gp_pixmap self,
int  axes_swap,
int  x_swap,
int  y_swap 
)
inlinestatic

Sets pixmap rotation flags.

Parameters
selfA pixmap.
axes_swapSet to 1 if axes should be swapped.
x_swapSet to 1 if x axis should be mirrored.
y_swapSet to 1 if y axis should be mirrored.

Definition at line 383 of file gp_pixmap.h.

References gp_pixmap::axes_swap, gp_pixmap::x_swap, and gp_pixmap::y_swap.

◆ gp_pixmap_w()

static gp_size gp_pixmap_w ( const gp_pixmap self)
inlinestatic

Returns pixmap width taking axes swap into account.

Parameters
selfA pixmap.
Returns
A pixmap width taking axes swap into an account.

Definition at line 411 of file gp_pixmap.h.

References gp_pixmap::axes_swap, gp_pixmap::h, and gp_pixmap::w.

◆ gp_sub_pixmap()

gp_pixmap * gp_sub_pixmap ( const gp_pixmap src,
gp_pixmap subpixmap,
gp_coord  x,
gp_coord  y,
gp_size  w,
gp_size  h 
)

Initializes a subpixmap.

The subpixmap has to fit into the source pixmap!

The original image must not be freed including its gamma tables until the resulting subpixmap is being in use.

Parameters
srcAn input pixmap.
subpixmapA pointer to a pixmap to initialize.
xA starting coordinate of the subpixmap.
yA starting coordinate of the subpixmap.
wA subpixmap width.
hA subpixmap height.
Returns
The pointer passed as subpixmap argument.

◆ gp_sub_pixmap_alloc()

gp_pixmap * gp_sub_pixmap_alloc ( const gp_pixmap src,
gp_coord  x,
gp_coord  y,
gp_size  w,
gp_size  h 
)

Allocate and initalize a subpixmap.

The subpixmap has to fit into the source pixmap!

The original image must not be freed including its gamma tables until the resulting subpixmap is being in use.

Parameters
srcAn input pixmap.
xA starting coordinate of the subpixmap.
yA starting coordinate of the subpixmap.
wA subpixmap width.
hA subpixmap height.
Returns
A newly allocated and initialized subpixmap or NULL in a case of failure.