gfx.h File Reference

#include "cfg/cfg_gfx.h"
#include <cfg/compiler.h>
#include <cpu/attr.h>

Go to the source code of this file.

Data Structures

struct  Rect
 Describe a rectangular area with coordinates expressed in pixels. More...
struct  Bitmap
 Control structure to draw in a bitmap. More...
struct  Image
 Hold image pixels. More...

Defines

#define CONFIG_CHART_TYPE_X   uint8_t
 Type for the chart dataset.
#define CONFIG_CHART_TYPE_Y   uint8_t
 Type for the chart dataset.
#define RECT_WIDTH(r)   ((r)->xmax - (r)->xmin)
 Return the width of a rectangle in pixels.
#define RECT_HEIGHT(r)   ((r)->ymax - (r)->ymin)
 Return the height of a rectangle in pixels.
#define RAST_SIZE(width, height)   ( (((width) + 7) / 8) * (height) )
 Compute the size in bytes of a raster suitable for holding a bitmap of width x height pixels.
Known pixel formats for bitmap representation.

#define BITMAP_FMT_PLANAR_H_MSB   1
 Planar pixels, horizontal bytes, MSB left.
#define BITMAP_FMT_PLANAR_V_LSB   2
 Planar pixels, vertical bytes, LSB top.

Typedefs

typedef float vcoord_t
 Common type for coordinates expressed in logical units.
typedef struct Rect Rect
 Describe a rectangular area with coordinates expressed in pixels.
typedef struct Bitmap Bitmap
 Control structure to draw in a bitmap.
typedef struct Image Image
 Hold image pixels.

Functions

void gfx_bitmapInit (Bitmap *bm, uint8_t *raster, coord_t w, coord_t h)
 Initialize a Bitmap structure with the provided parameters.
void gfx_bitmapClear (Bitmap *bm)
 Clear the whole bitmap surface to the background color.
void gfx_blit (Bitmap *dst, const Rect *rect, const Bitmap *src, coord_t srcx, coord_t srcy)
 Copy a rectangular area of a bitmap on another bitmap.
void gfx_blitRaster (Bitmap *dst, coord_t dx, coord_t dy, const uint8_t *raster, coord_t w, coord_t h, coord_t stride)
 Blit a raster to a Bitmap.
void gfx_blitImage (Bitmap *dst, coord_t dx, coord_t dy, const Image *image)
 Blit an Image to a Bitmap.
void gfx_line (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2)
 Draw a sloped line segment.
void gfx_rectDraw (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2)
 Draw the perimeter of an hollow rectangle.
void gfx_rectFillC (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t color)
 Fill a rectangular area with color.
void gfx_rectFill (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2)
 Draw a filled rectangle.
void gfx_rectClear (Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2)
 Clear a rectangular area.
void gfx_moveTo (Bitmap *bm, coord_t x, coord_t y)
 Move the current pen position to the specified coordinates.
void gfx_lineTo (Bitmap *bm, coord_t x, coord_t y)
 Draw a line from the current pen position to the new coordinates.
void gfx_setClipRect (Bitmap *bm, coord_t xmin, coord_t ymin, coord_t xmax, coord_t ymax)
 Set the bitmap clipping rectangle to the specified coordinates.
void gfx_setViewRect (Bitmap *bm, vcoord_t x1, vcoord_t y1, vcoord_t x2, vcoord_t y2)
 Imposta gli estremi del sistema di coordinate cartesiane rispetto al rettangolo di clipping della bitmap.
coord_t gfx_transformX (Bitmap *bm, vcoord_t x)
 Transform a coordinate from the current reference system to a pixel offset within the bitmap.
coord_t gfx_transformY (Bitmap *bm, vcoord_t y)
 Transform a coordinate from the current reference system to a pixel offset within the bitmap.
void gfx_vline (Bitmap *bm, vcoord_t x1, vcoord_t y1, vcoord_t x2, vcoord_t y2)
 Draw a line from (x1;y1) to (x2;y2).

Variables

EXTERN_C_BEGIN typedef int coord_t
 Common type for coordinates expressed in pixel units.

Detailed Description

Definition in file gfx.h.


Define Documentation

#define BITMAP_FMT_PLANAR_H_MSB   1

Planar pixels, horizontal bytes, MSB left.

Definition at line 60 of file gfx.h.

#define BITMAP_FMT_PLANAR_V_LSB   2

Planar pixels, vertical bytes, LSB top.

Definition at line 61 of file gfx.h.

#define RECT_HEIGHT (  )     ((r)->ymax - (r)->ymin)

Return the height of a rectangle in pixels.

Note:
The argument r is evaluated twice.

Definition at line 122 of file gfx.h.

#define RECT_WIDTH (  )     ((r)->xmax - (r)->xmin)

Return the width of a rectangle in pixels.

Note:
The argument r is evaluated twice.

Definition at line 115 of file gfx.h.


Typedef Documentation

typedef struct Bitmap Bitmap

Control structure to draw in a bitmap.

typedef struct Image Image

Hold image pixels.

typedef struct Rect Rect

Describe a rectangular area with coordinates expressed in pixels.

The rectangle is represented in terms of its top/left and right/bottom borders.

In some cases, rectangles are assumed to obey to the following invariants:

xmin <= xmax ymin <= ymax

Oddly, the xmin and ymin coordinates are inclusive, while the xmax and ymax coordinates are non-inclusive. This design decision makes several computations simpler and lets you specify empty (0x0) rectangles without breaking the invariants.

Computing the size of a rectangle can be done by simply subtracting the maximum X or Y coordinate from the minimum X or Y coordinate.


Function Documentation

void gfx_bitmapClear ( Bitmap bm  ) 

Clear the whole bitmap surface to the background color.

Note:
This function does not update the current pen position.
This function bypasses the current clipping area.

Definition at line 97 of file bitmap.c.

void gfx_bitmapInit ( Bitmap bm,
uint8_t *  raster,
coord_t  w,
coord_t  h 
)

Initialize a Bitmap structure with the provided parameters.

Note:
The pen position is reset to the origin.

Definition at line 62 of file bitmap.c.

void gfx_blit ( Bitmap dst,
const Rect rect,
const Bitmap src,
coord_t  srcx,
coord_t  srcy 
)

Copy a rectangular area of a bitmap on another bitmap.

Blitting is a common copy operation involving two bitmaps. A rectangular area of the source bitmap is copied bit-wise to a different position in the destination bitmap.

Note:
Using the same bitmap for src and dst is unsupported.
Parameters:
dst Bitmap where the operation writes.
rect The (xmin;ymin) coordinates provide the top/left offset for drawing in the destination bitmap. If the source bitmap is larger than the rectangle, drawing is clipped.
src Bitmap containing the source pixels.
srcx Starting X offset in the source bitmap.
srcy Starting Y offset in the source bitmap.

Definition at line 164 of file bitmap.c.

void gfx_blitImage ( Bitmap dst,
coord_t  dxmin,
coord_t  dymin,
const Image image 
)

Blit an Image to a Bitmap.

See also:
gfx_blit()

Definition at line 222 of file bitmap.c.

void gfx_blitRaster ( Bitmap dst,
coord_t  dxmin,
coord_t  dymin,
const uint8_t *  raster,
coord_t  w,
coord_t  h,
coord_t  stride 
)

Blit a raster to a Bitmap.

See also:
gfx_blit()

Definition at line 197 of file bitmap.c.

void gfx_line ( Bitmap bm,
coord_t  x1,
coord_t  y1,
coord_t  x2,
coord_t  y2 
)

Draw a sloped line segment.

Draw a sloped line segment identified by the provided start and end coordinates on the bitmap bm.

The line endpoints are clipped inside the current bitmap clipping rectangle using the Cohen-Sutherland algorithm, which is very fast.

Note:
The point at coordinates x2 y2 is not drawn.
This function does not update the current pen position.

Definition at line 184 of file line.c.

void gfx_lineTo ( Bitmap bm,
coord_t  x,
coord_t  y 
)

Draw a line from the current pen position to the new coordinates.

Note:
This function moves the current pen position to the new coordinates.
See also:
gfx_line()

Definition at line 264 of file line.c.

void gfx_moveTo ( Bitmap bm,
coord_t  x,
coord_t  y 
)

Move the current pen position to the specified coordinates.

The pen position is used for drawing operations such as gfx_lineTo(), which can be used to draw polygons.

Definition at line 250 of file line.c.

void gfx_rectClear ( Bitmap bm,
coord_t  x1,
coord_t  y1,
coord_t  x2,
coord_t  y2 
)

Clear a rectangular area.

Note:
The bottom-right border of the rectangle is not cleared.
This function does not update the current pen position.

Definition at line 354 of file line.c.

void gfx_rectDraw ( Bitmap bm,
coord_t  x1,
coord_t  y1,
coord_t  x2,
coord_t  y2 
)

Draw the perimeter of an hollow rectangle.

Note:
The bottom-right corner of the rectangle is drawn at (x2-1;y2-1).
This function does not update the current pen position.

Definition at line 277 of file line.c.

void gfx_rectFill ( Bitmap bm,
coord_t  x1,
coord_t  y1,
coord_t  x2,
coord_t  y2 
)

Draw a filled rectangle.

Note:
The bottom-right border of the rectangle is not drawn.
This function does not update the current pen position.

Definition at line 341 of file line.c.

void gfx_rectFillC ( Bitmap bm,
coord_t  x1,
coord_t  y1,
coord_t  x2,
coord_t  y2,
uint8_t  color 
)

Fill a rectangular area with color.

Note:
The bottom-right border of the rectangle is not drawn.
This function does not update the current pen position.

Definition at line 298 of file line.c.

void gfx_setClipRect ( Bitmap bm,
coord_t  minx,
coord_t  miny,
coord_t  maxx,
coord_t  maxy 
)

Set the bitmap clipping rectangle to the specified coordinates.

All drawing performed on the bitmap will be clipped inside this rectangle.

The clipping rectangle is also used as a bounding box for the logical view of the virtual coordinate system.

Note:
Following the convention used for all other operations, the top-left pixels of the rectangle are included, while the bottom-right pixels are considered outside the clipping region.
See also:
gfx_setViewRect

Definition at line 248 of file bitmap.c.