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

A graphic drawing algorithms. More...

Functions

void gp_blit_xyxy (const gp_pixmap *src, gp_coord x0, gp_coord y0, gp_coord x1, gp_coord y1, gp_pixmap *dst, gp_coord x2, gp_coord y2)
 Blits a rectangle from src into a dst.
 
void gp_blit_xywh (const gp_pixmap *src, gp_coord x0, gp_coord y0, gp_size w0, gp_size h0, gp_pixmap *dst, gp_coord x1, gp_coord y1)
 Blits a rectangle from src into a dst.
 
static void gp_blit (const gp_pixmap *src, gp_coord x0, gp_coord y0, gp_size w0, gp_size h0, gp_pixmap *dst, gp_coord x1, gp_coord y1)
 Blits a rectangle from src into a dst.
 
void gp_fill (gp_pixmap *pixmap, gp_pixel val)
 Fills pixmap with given pixel value.
 
gp_pixel gp_getpixel (const gp_pixmap *pixmap, gp_coord x, gp_coord y)
 Gets a pixel value.
 
static gp_pixel gp_getpixel_raw (const gp_pixmap *pixmap, gp_coord x, gp_coord y)
 Gets a pixel value.
 
void gp_putpixel (gp_pixmap *pixmap, gp_coord x, gp_coord y, gp_pixel p)
 Puts a pixel value.
 
static void gp_putpixel_raw (gp_pixmap *pixmap, gp_coord x, gp_coord y, gp_pixel p)
 Puts a pixel value.
 
void gp_circle (gp_pixmap *pixmap, gp_coord xcenter, gp_coord ycenter, gp_size r, gp_pixel pixel)
 Draws a circle.
 
void gp_fill_circle (gp_pixmap *pixmap, gp_coord xcenter, gp_coord ycenter, gp_size r, gp_pixel pixel)
 Draws a filled circle.
 
void gp_ring (gp_pixmap *pixmap, gp_coord xcenter, gp_coord ycenter, gp_size r1, gp_size r2, gp_pixel pixel)
 Draws a ring.
 
void gp_fill_ring (gp_pixmap *pixmap, gp_coord xcenter, gp_coord ycenter, gp_size r1, gp_size r2, gp_pixel pixel)
 Draws a filled ring.
 
void gp_circle_seg (gp_pixmap *pixmap, gp_coord xcenter, gp_coord ycenter, gp_size r, uint8_t seg_flag, gp_pixel pixel)
 Draws a circle segment.
 
void gp_fill_circle_seg (gp_pixmap *pixmap, gp_coord xcenter, gp_coord ycenter, gp_size r, uint8_t seg_flag, gp_pixel pixel)
 Draws a filled circle segment.
 
void gp_fill_ring_seg (gp_pixmap *pixmap, gp_coord xcenter, gp_coord ycenter, gp_size r1, gp_size r2, uint8_t seg_flag, gp_pixel pixel)
 Draws a filled ring segment.
 
void gp_hline_xxy (gp_pixmap *pixmap, gp_coord x0, gp_coord x1, gp_coord y, gp_pixel pixel)
 Horizontal line drawing algorithm.
 
void gp_hline_xyw (gp_pixmap *pixmap, gp_coord x, gp_coord y, gp_size w, gp_pixel pixel)
 Horizontal line drawing algorithm.
 
static void gp_hline (gp_pixmap *pixmap, gp_coord x0, gp_coord x1, gp_coord y, gp_pixel p)
 Horizontal line drawing algorithm.
 
void gp_line (gp_pixmap *pixmap, gp_coord x0, gp_coord y0, gp_coord x1, gp_coord y1, gp_pixel pixel)
 Classical Bresenham line drawing algorithm.
 
void gp_line_th (gp_pixmap *pixmap, gp_coord x0, gp_coord y0, gp_coord x1, gp_coord y1, gp_size r, gp_pixel pixel)
 Murphy thick line drawing algorithm.
 
void gp_polygon (gp_pixmap *pixmap, gp_coord x_off, gp_coord y_off, unsigned int vertex_count, const gp_coord *xy, gp_pixel pixel)
 Draws a polygon outline.
 
void gp_polygon_th (gp_pixmap *pixmap, gp_coord x_off, gp_coord y_off, unsigned int vertex_count, const gp_coord *xy, gp_size r, gp_pixel pixel)
 Draws a thick polygon outline.
 
void gp_fill_polygon (gp_pixmap *pixmap, gp_coord x_off, gp_coord y_off, unsigned int vertex_count, const gp_coord *xy, gp_pixel pixel)
 Fills a polygon.
 
void gp_vline_xyy (gp_pixmap *pixmap, gp_coord x, gp_coord y0, gp_coord y1, gp_pixel pixel)
 Vertical line drawing algorithm.
 
void gp_vline_xyh (gp_pixmap *pixmap, gp_coord x, gp_coord y, gp_size h, gp_pixel pixel)
 Vertical line drawing algorithm.
 
static void gp_vline (gp_pixmap *pixmap, gp_coord x, gp_coord y0, gp_coord y1, gp_pixel pixel)
 Horizontal line drawing algorithm.
 

Detailed Description

A graphic drawing algorithms.

Function Documentation

◆ gp_blit()

static void gp_blit ( const gp_pixmap src,
gp_coord  x0,
gp_coord  y0,
gp_size  w0,
gp_size  h0,
gp_pixmap dst,
gp_coord  x1,
gp_coord  y1 
)
inlinestatic

Blits a rectangle from src into a dst.

An alias for gp_blit_xywh().

Definition at line 90 of file gp_blit.h.

References gp_blit_xywh().

◆ gp_blit_xywh()

void gp_blit_xywh ( const gp_pixmap src,
gp_coord  x0,
gp_coord  y0,
gp_size  w0,
gp_size  h0,
gp_pixmap dst,
gp_coord  x1,
gp_coord  y1 
)

Blits a rectangle from src into a dst.

This blit automatically converts between different gp_pixel_type, however they operate on a single pixel value at a time, if you are converting from a higher bit depths the results are suboptimal, expecially conversions to 1bpp does not end up as a recognizable image. In these cases an error distribution dithering gp_dither_type should be used instead.

Blits rectangle from src defined by x0, y0, x1, y1 (x1, y1 included) to dst starting on x2, y2.

Parameters
srcA source pixmap.
x0A left rectangle corner coordinate in src.
y0A top rectangle corner coordinate in src.
w0A rectangle width.
h0A rectangle height.
dstA destination pixmap.
x1A left rectangle corner coordinate in dst.
y1A top rectangle corner coordinate in dst.

Referenced by gp_blit().

◆ gp_blit_xyxy()

void gp_blit_xyxy ( const gp_pixmap src,
gp_coord  x0,
gp_coord  y0,
gp_coord  x1,
gp_coord  y1,
gp_pixmap dst,
gp_coord  x2,
gp_coord  y2 
)

Blits a rectangle from src into a dst.

This blit automatically converts between different gp_pixel_type, however they operate on a single pixel value at a time, if you are converting from a higher bit depths the results are suboptimal, expecially conversions to 1bpp does not end up as a recognizable image. In these cases an error distribution dithering gp_dither_type should be used instead.

Blits rectangle from src defined by x0, y0, x1, y1 (x1, y1 included) to dst starting on x2, y2.

Parameters
srcA source pixmap.
x0A left rectangle corner coordinate in src.
y0A top rectangle corner coordinate in src.
x1A right rectangle corner coordinate in src.
y1A bottom rectangle corner coordinate in src.
dstA destination pixmap.
x2A left rectangle corner coordinate in dst.
y2A top rectangle corner coordinate in dst.

◆ gp_circle()

void gp_circle ( gp_pixmap pixmap,
gp_coord  xcenter,
gp_coord  ycenter,
gp_size  r,
gp_pixel  pixel 
)

Draws a circle.

Parameters
pixmapA pixmap to draw into.
xcenterA circle center coordinate.
ycenterA circle center coordinate.
rA circle radius, r=0 draws a single pixel.
pixelA pixel value to be used for the drawing.

◆ gp_circle_seg()

void gp_circle_seg ( gp_pixmap pixmap,
gp_coord  xcenter,
gp_coord  ycenter,
gp_size  r,
uint8_t  seg_flag,
gp_pixel  pixel 
)

Draws a circle segment.

Parameters
pixmapA pixmap to draw into.
xcenterA circle center coordinate.
ycenterA circle center coordinate.
rA circle radius, r=0 draws a single pixel.
seg_flagA bitmask of circle segments to draw.
pixelA pixel value to be used for the drawing.

◆ gp_fill()

void gp_fill ( gp_pixmap pixmap,
gp_pixel  val 
)

Fills pixmap with given pixel value.

Parameters
pixmapA pixmap to be filled.
valA pixel value to fill the pixmap with.

◆ gp_fill_circle()

void gp_fill_circle ( gp_pixmap pixmap,
gp_coord  xcenter,
gp_coord  ycenter,
gp_size  r,
gp_pixel  pixel 
)

Draws a filled circle.

Parameters
pixmapA pixmap to draw into.
xcenterA circle center coordinate.
ycenterA circle center coordinate.
rA circle radius, r=0 draws a single pixel.
pixelA pixel value to be used for the drawing.

◆ gp_fill_circle_seg()

void gp_fill_circle_seg ( gp_pixmap pixmap,
gp_coord  xcenter,
gp_coord  ycenter,
gp_size  r,
uint8_t  seg_flag,
gp_pixel  pixel 
)

Draws a filled circle segment.

Parameters
pixmapA pixmap to draw into.
xcenterA circle center coordinate.
ycenterA circle center coordinate.
rA circle radius, r=0 draws a single pixel.
seg_flagA bitmask of circle segments to draw.
pixelA pixel value to be used for the drawing.

◆ gp_fill_polygon()

void gp_fill_polygon ( gp_pixmap pixmap,
gp_coord  x_off,
gp_coord  y_off,
unsigned int  vertex_count,
const gp_coord xy,
gp_pixel  pixel 
)

Fills a polygon.

Parameters
pixmapA pixmap to draw the polygon into.
x_offA x offset to draw the polygon at.
y_offA y offset to draw the polygon at.
vertex_countThe number of coordinates in the xy array.
xyAn array of a 2 * vertex_count numbers in the [x0, y0, ..., xn, yn] format.
pixelA pixel value to be used to draw the polygon.

◆ gp_fill_ring()

void gp_fill_ring ( gp_pixmap pixmap,
gp_coord  xcenter,
gp_coord  ycenter,
gp_size  r1,
gp_size  r2,
gp_pixel  pixel 
)

Draws a filled ring.

Parameters
pixmapA pixmap to draw into.
xcenterA circle center coordinate.
ycenterA circle center coordinate.
r1A first circle radius, r=0 draws a single pixel.
r2A second circle radius, r=0 draws a single pixel.
pixelA pixel value to be used for the drawing.

◆ gp_fill_ring_seg()

void gp_fill_ring_seg ( gp_pixmap pixmap,
gp_coord  xcenter,
gp_coord  ycenter,
gp_size  r1,
gp_size  r2,
uint8_t  seg_flag,
gp_pixel  pixel 
)

Draws a filled ring segment.

Parameters
pixmapA pixmap to draw into.
xcenterA circle center coordinate.
ycenterA circle center coordinate.
r1A first circle radius, r=0 draws a single pixel.
r2A second circle radius, r=0 draws a single pixel.
seg_flagA bitmask of circle segments to draw.
pixelA pixel value to be used for the drawing.

◆ gp_getpixel()

gp_pixel gp_getpixel ( const gp_pixmap pixmap,
gp_coord  x,
gp_coord  y 
)

Gets a pixel value.

This is a safe and slow function that does coordinate transformations (see GP_TRANSFORM_POINT) and clipping, i.e. reads outside of the gp_pixmap::pixels return 0.

Parameters
pixmapA pixmap to get the pixel from.
xA x coordinate to get the pixel from.
yA y coordinate to get the pixel from.
Returns
A pixel value at give coordinates or 0 for pixels outside bitmap.

◆ gp_getpixel_raw()

static gp_pixel gp_getpixel_raw ( const gp_pixmap pixmap,
gp_coord  x,
gp_coord  y 
)
inlinestatic

Gets a pixel value.

Version of gp_getpixel() without transformations nor border checking. This is faster than the non-raw variant but stil somewhat slow since the function has to handle different types of gp_pixel_pack. If you are going for speed use the pixel pack specific function e.g. gp_getpixel_raw_32BPP().

Warning
If x or y are outside of gp_pixmap::pixels the function will read ouside of the buffer.
Parameters
pixmapA pixmap to put the pixel into.
xA x coordinate to put the pixel at.
yA y coordinate to put the pixel at.
Returns
A pixel value.

Definition at line 52 of file gp_get_put_pixel.h.

References gp_getpixel_raw().

Referenced by gp_getpixel_raw().

◆ gp_hline()

static void gp_hline ( gp_pixmap pixmap,
gp_coord  x0,
gp_coord  x1,
gp_coord  y,
gp_pixel  p 
)
inlinestatic

Horizontal line drawing algorithm.

An alias for gp_hline_xxy().

Definition at line 64 of file gp_hline.h.

References gp_hline_xxy().

◆ gp_hline_xxy()

void gp_hline_xxy ( gp_pixmap pixmap,
gp_coord  x0,
gp_coord  x1,
gp_coord  y,
gp_pixel  pixel 
)

Horizontal line drawing algorithm.

Parameters
pixmapA pixmap to draw into.
x0A starting point x coordinate.
x1An ending point x coordinate.
yA y coordinate.
pixelA pixel value to be used for the drawing.

Referenced by gp_hline().

◆ gp_hline_xyw()

void gp_hline_xyw ( gp_pixmap pixmap,
gp_coord  x,
gp_coord  y,
gp_size  w,
gp_pixel  pixel 
)

Horizontal line drawing algorithm.

Parameters
pixmapA pixmap to draw into.
xA starting point x coordinate.
wA line width, a lenght of the line.
yA y coordinate.
pixelA pixel value to be used for the drawing.

◆ gp_line()

void gp_line ( gp_pixmap pixmap,
gp_coord  x0,
gp_coord  y0,
gp_coord  x1,
gp_coord  y1,
gp_pixel  pixel 
)

Classical Bresenham line drawing algorithm.

Classical Bresenham with a nice little trick on the top of the original algorithm, we only track half of the line and paint it from both sides at the same time.

Draws a line from (x0, y0) to (x1, y1), inclusive. The starting and ending point can be specified in any order (the implementation guarantees that exactly the same set of pixels will be drawn in both cases).

Parameters
pixmapA pixmap to draw into.
x0A starting point x coordinate.
y0A starting point y coordinate.
x1An ending point x coordinate.
y1An ending point y coordinate.
pixelA pixel value to be used for the drawing.

◆ gp_line_th()

void gp_line_th ( gp_pixmap pixmap,
gp_coord  x0,
gp_coord  y0,
gp_coord  x1,
gp_coord  y1,
gp_size  r,
gp_pixel  pixel 
)

Murphy thick line drawing algorithm.

This is a modified Bresenham, we run two Bresenham line algorithms, outher one that track the line and inner one that draws lines perpendicular to the line we track. The outher Bresenham also tracks initial errors for the inner one.

We do a nice little trick on the top of the original algorithm, we only track half of the line and paint it from both sides at the same time.

Draws a line from (x0, y0) to (x1, y1), inclusive. The starting and ending point can be specified in any order (the implementation guarantees that exactly the same set of pixels will be drawn in both cases).

Parameters
pixmapA pixmap to draw into.
x0A starting point x coordinate.
y0A starting point y coordinate.
x1An ending point x coordinate.
y1An ending point y coordinate.
rA radius, r=0 is single pixel line.
pixelA pixel value to be used for the drawing.

◆ gp_polygon()

void gp_polygon ( gp_pixmap pixmap,
gp_coord  x_off,
gp_coord  y_off,
unsigned int  vertex_count,
const gp_coord xy,
gp_pixel  pixel 
)

Draws a polygon outline.

Traces a polygon by drawing lines between subsequent coordinates with gp_line().

Parameters
pixmapA pixmap to draw the polygon into.
x_offA x offset to draw the polygon at.
y_offA y offset to draw the polygon at.
vertex_countThe number of coordinates in the xy array.
xyAn array of a 2 * vertex_count numbers in the [x0, y0, ..., xn, yn] format.
pixelA pixel value to be used to draw the polygon.

◆ gp_polygon_th()

void gp_polygon_th ( gp_pixmap pixmap,
gp_coord  x_off,
gp_coord  y_off,
unsigned int  vertex_count,
const gp_coord xy,
gp_size  r,
gp_pixel  pixel 
)

Draws a thick polygon outline.

Traces a polygon by drawing lines between subsequent coordinates with gp_line_th().

Parameters
pixmapA pixmap to draw the polygon into.
x_offA x offset to draw the polygon at.
y_offA y offset to draw the polygon at.
vertex_countThe number of coordinates in the xy array.
xyAn array of a 2 * vertex_count numbers in the [x0, y0, ..., xn, yn] format.
rA radius, r=0 is single pixel line.
pixelA pixel value to be used to draw the polygon.

◆ gp_putpixel()

void gp_putpixel ( gp_pixmap pixmap,
gp_coord  x,
gp_coord  y,
gp_pixel  p 
)

Puts a pixel value.

This is a safe and slow function that does coordinate transformations (see GP_TRANSFORM_POINT) and clipping i.e. writes outside of the gp_pixmap::pixels are ignored.

If you are going to loop over all pixels in a pixmap you should use gp_putpixel_raw() variant that is not clipped nor transformed.

Parameters
pixmapA pixmap to put the pixel into.
xA x coordinate to put the pixel at.
yA y coordinate to put the pixel at.
pA pixel value.

◆ gp_putpixel_raw()

static void gp_putpixel_raw ( gp_pixmap pixmap,
gp_coord  x,
gp_coord  y,
gp_pixel  p 
)
inlinestatic

Puts a pixel value.

Version of gp_putpixel() without transformations nor border checking. This is faster than the non-raw variant but stil somewhat slow since the function has to handle all different types of gp_pixel_pack. If you are going for speed use the pixel pack specific function e.g. gp_putpixel_raw_32BPP().

Warning
If x or y are outside of gp_pixmap::pixels the function will write ouside of the buffer.
Parameters
pixmapA pixmap to put the pixel into.
xA x coordinate to put the pixel at.
yA y coordinate to put the pixel at.
pA pixel value.

Definition at line 107 of file gp_get_put_pixel.h.

References gp_putpixel_raw().

Referenced by gp_putpixel_raw().

◆ gp_ring()

void gp_ring ( gp_pixmap pixmap,
gp_coord  xcenter,
gp_coord  ycenter,
gp_size  r1,
gp_size  r2,
gp_pixel  pixel 
)

Draws a ring.

Parameters
pixmapA pixmap to draw into.
xcenterA circle center coordinate.
ycenterA circle center coordinate.
r1A first circle radius, r=0 draws a single pixel.
r2A second circle radius, r=0 draws a single pixel.
pixelA pixel value to be used for the drawing.

◆ gp_vline()

static void gp_vline ( gp_pixmap pixmap,
gp_coord  x,
gp_coord  y0,
gp_coord  y1,
gp_pixel  pixel 
)
inlinestatic

Horizontal line drawing algorithm.

An alias for gp_hline_xyy().

Definition at line 57 of file gp_vline.h.

References gp_vline_xyy().

◆ gp_vline_xyh()

void gp_vline_xyh ( gp_pixmap pixmap,
gp_coord  x,
gp_coord  y,
gp_size  h,
gp_pixel  pixel 
)

Vertical line drawing algorithm.

Parameters
pixmapA pixmap to draw into.
xA x coordinate.
yA starting point y coordinate.
hA line height, a lenght of the line.
pixelA pixel value to be used for the drawing.

◆ gp_vline_xyy()

void gp_vline_xyy ( gp_pixmap pixmap,
gp_coord  x,
gp_coord  y0,
gp_coord  y1,
gp_pixel  pixel 
)

Vertical line drawing algorithm.

Parameters
pixmapA pixmap to draw into.
xA x coordinate.
y0A starting point y coordinate.
y1An ending point y coordinate.
pixelA pixel value to be used for the drawing.

Referenced by gp_vline().