GFXprim
2D bitmap graphics library with emphasis on speed and correctness
|
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. | |
A graphic drawing algorithms.
|
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().
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.
src | A source pixmap. |
x0 | A left rectangle corner coordinate in src. |
y0 | A top rectangle corner coordinate in src. |
w0 | A rectangle width. |
h0 | A rectangle height. |
dst | A destination pixmap. |
x1 | A left rectangle corner coordinate in dst. |
y1 | A top rectangle corner coordinate in dst. |
Referenced by gp_blit().
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.
src | A source pixmap. |
x0 | A left rectangle corner coordinate in src. |
y0 | A top rectangle corner coordinate in src. |
x1 | A right rectangle corner coordinate in src. |
y1 | A bottom rectangle corner coordinate in src. |
dst | A destination pixmap. |
x2 | A left rectangle corner coordinate in dst. |
y2 | A top rectangle corner coordinate in dst. |
void gp_circle | ( | gp_pixmap * | pixmap, |
gp_coord | xcenter, | ||
gp_coord | ycenter, | ||
gp_size | r, | ||
gp_pixel | pixel | ||
) |
Draws a circle.
pixmap | A pixmap to draw into. |
xcenter | A circle center coordinate. |
ycenter | A circle center coordinate. |
r | A circle radius, r=0 draws a single pixel. |
pixel | A pixel value to be used for the drawing. |
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.
pixmap | A pixmap to draw into. |
xcenter | A circle center coordinate. |
ycenter | A circle center coordinate. |
r | A circle radius, r=0 draws a single pixel. |
seg_flag | A bitmask of circle segments to draw. |
pixel | A pixel value to be used for the drawing. |
Fills pixmap with given pixel value.
pixmap | A pixmap to be filled. |
val | A pixel value to fill the pixmap with. |
void gp_fill_circle | ( | gp_pixmap * | pixmap, |
gp_coord | xcenter, | ||
gp_coord | ycenter, | ||
gp_size | r, | ||
gp_pixel | pixel | ||
) |
Draws a filled circle.
pixmap | A pixmap to draw into. |
xcenter | A circle center coordinate. |
ycenter | A circle center coordinate. |
r | A circle radius, r=0 draws a single pixel. |
pixel | A pixel value to be used for the drawing. |
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.
pixmap | A pixmap to draw into. |
xcenter | A circle center coordinate. |
ycenter | A circle center coordinate. |
r | A circle radius, r=0 draws a single pixel. |
seg_flag | A bitmask of circle segments to draw. |
pixel | A pixel value to be used for the drawing. |
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.
pixmap | A pixmap to draw the polygon into. |
x_off | A x offset to draw the polygon at. |
y_off | A y offset to draw the polygon at. |
vertex_count | The number of coordinates in the xy array. |
xy | An array of a 2 * vertex_count numbers in the [x0, y0, ..., xn, yn] format. |
pixel | A pixel value to be used to draw the polygon. |
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.
pixmap | A pixmap to draw into. |
xcenter | A circle center coordinate. |
ycenter | A circle center coordinate. |
r1 | A first circle radius, r=0 draws a single pixel. |
r2 | A second circle radius, r=0 draws a single pixel. |
pixel | A pixel value to be used for the drawing. |
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.
pixmap | A pixmap to draw into. |
xcenter | A circle center coordinate. |
ycenter | A circle center coordinate. |
r1 | A first circle radius, r=0 draws a single pixel. |
r2 | A second circle radius, r=0 draws a single pixel. |
seg_flag | A bitmask of circle segments to draw. |
pixel | A pixel value to be used for the drawing. |
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.
pixmap | A pixmap to get the pixel from. |
x | A x coordinate to get the pixel from. |
y | A y coordinate to get the pixel from. |
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().
pixmap | A pixmap to put the pixel into. |
x | A x coordinate to put the pixel at. |
y | A y coordinate to put the pixel at. |
Definition at line 52 of file gp_get_put_pixel.h.
References gp_getpixel_raw().
Referenced by gp_getpixel_raw().
|
inlinestatic |
Horizontal line drawing algorithm.
An alias for gp_hline_xxy().
Definition at line 64 of file gp_hline.h.
References gp_hline_xxy().
Horizontal line drawing algorithm.
pixmap | A pixmap to draw into. |
x0 | A starting point x coordinate. |
x1 | An ending point x coordinate. |
y | A y coordinate. |
pixel | A pixel value to be used for the drawing. |
Referenced by gp_hline().
Horizontal line drawing algorithm.
pixmap | A pixmap to draw into. |
x | A starting point x coordinate. |
w | A line width, a lenght of the line. |
y | A y coordinate. |
pixel | A pixel value to be used for the drawing. |
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).
pixmap | A pixmap to draw into. |
x0 | A starting point x coordinate. |
y0 | A starting point y coordinate. |
x1 | An ending point x coordinate. |
y1 | An ending point y coordinate. |
pixel | A pixel value to be used for the drawing. |
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).
pixmap | A pixmap to draw into. |
x0 | A starting point x coordinate. |
y0 | A starting point y coordinate. |
x1 | An ending point x coordinate. |
y1 | An ending point y coordinate. |
r | A radius, r=0 is single pixel line. |
pixel | A pixel value to be used for the drawing. |
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().
pixmap | A pixmap to draw the polygon into. |
x_off | A x offset to draw the polygon at. |
y_off | A y offset to draw the polygon at. |
vertex_count | The number of coordinates in the xy array. |
xy | An array of a 2 * vertex_count numbers in the [x0, y0, ..., xn, yn] format. |
pixel | A pixel value to be used to draw the polygon. |
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().
pixmap | A pixmap to draw the polygon into. |
x_off | A x offset to draw the polygon at. |
y_off | A y offset to draw the polygon at. |
vertex_count | The number of coordinates in the xy array. |
xy | An array of a 2 * vertex_count numbers in the [x0, y0, ..., xn, yn] format. |
r | A radius, r=0 is single pixel line. |
pixel | A pixel value to be used to draw the polygon. |
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.
pixmap | A pixmap to put the pixel into. |
x | A x coordinate to put the pixel at. |
y | A y coordinate to put the pixel at. |
p | A pixel value. |
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().
pixmap | A pixmap to put the pixel into. |
x | A x coordinate to put the pixel at. |
y | A y coordinate to put the pixel at. |
p | A pixel value. |
Definition at line 107 of file gp_get_put_pixel.h.
References gp_putpixel_raw().
Referenced by gp_putpixel_raw().
void gp_ring | ( | gp_pixmap * | pixmap, |
gp_coord | xcenter, | ||
gp_coord | ycenter, | ||
gp_size | r1, | ||
gp_size | r2, | ||
gp_pixel | pixel | ||
) |
Draws a ring.
pixmap | A pixmap to draw into. |
xcenter | A circle center coordinate. |
ycenter | A circle center coordinate. |
r1 | A first circle radius, r=0 draws a single pixel. |
r2 | A second circle radius, r=0 draws a single pixel. |
pixel | A pixel value to be used for the drawing. |
|
inlinestatic |
Horizontal line drawing algorithm.
An alias for gp_hline_xyy().
Definition at line 57 of file gp_vline.h.
References gp_vline_xyy().
Vertical line drawing algorithm.
pixmap | A pixmap to draw into. |
x | A x coordinate. |
y | A starting point y coordinate. |
h | A line height, a lenght of the line. |
pixel | A pixel value to be used for the drawing. |
Vertical line drawing algorithm.
pixmap | A pixmap to draw into. |
x | A x coordinate. |
y0 | A starting point y coordinate. |
y1 | An ending point y coordinate. |
pixel | A pixel value to be used for the drawing. |
Referenced by gp_vline().