PicoVGA  1.0-cmake
VGA/TV display on Raspberry Pico
Canvas

Description

Drawing board for shapes and images.

Canvas is a drawing board. It is a support library for working with graphical surfaces and images. The sCanvas structure is a set of parameters that describe the graphical surface, for use in drawing functions. A graphical surface can be either a graphical frame buffer or an image, even in Flash. To draw in a graphical surface, first attach a canvas to it as a definition describing the structure of the area. Likewise, if you want to draw an image to the surface, first create a canvas for the image with its parameters. The parameters are a pointer to the image data, the image dimensions, and the format. The drawing area can be a graphic area with a depth of 1, 2, 4, 8 bits or with attributes. In the case of drawing an image to a canvas, the source and target canvas must have the same format. In the case of transformation matrices, only an 8-bit graphic format can be drawn.

Note
In PicoVGA, a default canvas Canvas is available. A graphic frame buffer is automatically attached to it when initialized with the Video() function. Otherwise, it can be used arbitrarily in the program.

Data Structures

struct  sCanvas
 Canvas descriptor. More...
 
class  cMat2Df
 2D Transformation Matrix More...
 

Macros

#define CANVAS_8   0
 8-bit pixels
 
#define CANVAS_4   1
 4-bit pixels
 
#define CANVAS_2   2
 2-bit pixels
 
#define CANVAS_1   3
 
#define CANVAS_PLANE2   4
 4 colors on 2 planes
 
#define CANVAS_ATTRIB8   5
 

Enumerations

enum  {
  DRAWIMG_WRAP, DRAWIMG_NOBORDER, DRAWIMG_CLAMP, DRAWING_COLOR,
  DRAWIMG_TRANSP, DRAWIMG_PERSP
}
 DrawImgMat mode. More...
 

Functions

void DrawRect (sCanvas *canvas, int x, int y, int w, int h, u8 col)
 Draw rectangle. More...
 
void DrawFrame (sCanvas *canvas, int x, int y, int w, int h, u8 col)
 Draw frame of 1 pixel thickness. More...
 
void DrawClear (sCanvas *canvas)
 Clear canvas (fill with black color) More...
 
void DrawPoint (sCanvas *canvas, int x, int y, u8 col)
 Draw a pixel. More...
 
void DrawLine (sCanvas *canvas, int x1, int y1, int x2, int y2, u8 col)
 Draw a line. More...
 
void DrawFillCircle (sCanvas *canvas, int x0, int y0, int r, u8 col, u8 mask=0xff)
 Draw filled circle. More...
 
void DrawCircle (sCanvas *canvas, int x0, int y0, int r, u8 col, u8 mask=0xff)
 Draw circle. More...
 
void DrawText (sCanvas *canvas, const char *text, int x, int y, u8 col, const void *font, int fontheight=8, int scalex=1, int scaley=1)
 Draw text (transparent background) More...
 
void DrawTextBg (sCanvas *canvas, const char *text, int x, int y, u8 col, u8 bgcol, const void *font, int fontheight=8, int scalex=1, int scaley=1)
 Draw text with background color. More...
 
void DrawImg (sCanvas *canvas, sCanvas *src, int xd, int yd, int xs, int ys, int w, int h)
 Draw image (without transparency) More...
 
void DrawBlit (sCanvas *canvas, sCanvas *src, int xd, int yd, int xs, int ys, int w, int h, u8 col)
 Draw image with transparency. More...
 
void DrawImgMat (sCanvas *canvas, const sCanvas *src, int x, int y, int w, int h, const class cMat2Df *m, u8 mode, u8 color)
 Draw 8-bit image with 2D transformation matrix. More...
 
void DrawTileMap (sCanvas *canvas, const sCanvas *src, const u8 *map, int mapwbits, int maphbits, int tilebits, int x, int y, int w, int h, const cMat2Df *mat, u8 horizon)
 Draw tile map using perspective projection. More...
 
void DrawImgLine (sCanvas *canvas, sCanvas *src, int xd, int yd, int xs, int ys, int wd, int ws)
 Draw image line interpolated. More...
 

Macro Definition Documentation

◆ CANVAS_ATTRIB8

#define CANVAS_ATTRIB8   5

2x4 bit color attributes per 8x8 pixel sample draw functions: bit 0..3 = draw color bit 4 = draw color is background color

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

DrawImgMat mode.

Enumerator
DRAWIMG_WRAP 

Wrap image.

DRAWIMG_NOBORDER 

No border (transparent border)

DRAWIMG_CLAMP 

Clamp image (use last pixel as border)

DRAWING_COLOR 

Color border.

DRAWIMG_TRANSP 

Transparent image with key color.

DRAWIMG_PERSP 

Perspective floor.

Function Documentation

◆ DrawRect()

void DrawRect ( sCanvas canvas,
int  x,
int  y,
int  w,
int  h,
u8  col 
)

Draw rectangle.

Parameters
canvasCanvas
xHorizontal position
yVeritical position
wWidth
hHeight
colColor

◆ DrawFrame()

void DrawFrame ( sCanvas canvas,
int  x,
int  y,
int  w,
int  h,
u8  col 
)

Draw frame of 1 pixel thickness.

Parameters
canvasCanvas
xHorizontal position
yVeritical position
wWidth
hHeight
colColor

◆ DrawClear()

void DrawClear ( sCanvas canvas)

Clear canvas (fill with black color)

Parameters
canvasCanvas

◆ DrawPoint()

void DrawPoint ( sCanvas canvas,
int  x,
int  y,
u8  col 
)

Draw a pixel.

Parameters
canvasCanvas
xHorizontal position
yVeritical position
colColor

◆ DrawLine()

void DrawLine ( sCanvas canvas,
int  x1,
int  y1,
int  x2,
int  y2,
u8  col 
)

Draw a line.

Parameters
canvasCanvas
x1Horizontal start position
y1Veritical start position
x2Horizontal end position
y2Veritical end position
colColor

◆ DrawFillCircle()

void DrawFillCircle ( sCanvas canvas,
int  x0,
int  y0,
int  r,
u8  col,
u8  mask = 0xff 
)

Draw filled circle.

Parameters
canvasCanvas
x0Horizontal center coordinate
y0Veritical center coordinate
rRadius
colColor (with CANVAS_ATTRIB8 format: bit 0..3 = draw color, bit 4 = draw color is background color)
maskMask. Specifies, using bits 0 to 7, which eighths of the circle are drawn.
        . B2|B1 .
      B3 .  |  . B0
      ------o------
      B4 .  |  . B7
        . B5|B6 .

◆ DrawCircle()

void DrawCircle ( sCanvas canvas,
int  x0,
int  y0,
int  r,
u8  col,
u8  mask = 0xff 
)

Draw circle.

Parameters
canvasCanvas
x0Horizontal center coordinate
y0Veritical center coordinate
rRadius
colColor (with CANVAS_ATTRIB8 format: bit 0..3 = draw color, bit 4 = draw color is background color)
maskMask. Specifies, using bits 0 to 7, which eighths of the circle are drawn.
        . B2|B1 .
      B3 .  |  . B0
      ------o------
      B4 .  |  . B7
        . B5|B6 .

◆ DrawText()

void DrawText ( sCanvas canvas,
const char *  text,
int  x,
int  y,
u8  col,
const void *  font,
int  fontheight = 8,
int  scalex = 1,
int  scaley = 1 
)

Draw text (transparent background)

Parameters
canvasCanvas
textC string to draw
xHorizontal position
yVerticle position
colText color
fontPointer to 1-bit font
fontheightHeight of font in pixels (default 8)
scalexMagnification scale in X dimension
scaleyMagnification scale in Y dimension

◆ DrawTextBg()

void DrawTextBg ( sCanvas canvas,
const char *  text,
int  x,
int  y,
u8  col,
u8  bgcol,
const void *  font,
int  fontheight = 8,
int  scalex = 1,
int  scaley = 1 
)

Draw text with background color.

Parameters
canvasCanvas
textC string to draw
xHorizontal position
yVerticle position
colText color
bgcolBackground color
fontPointer to 1-bit font
fontheightHeight of font in pixels (default 8)
scalexMagnification scale in X dimension
scaleyMagnification scale in Y dimension

◆ DrawImg()

void DrawImg ( sCanvas canvas,
sCanvas src,
int  xd,
int  yd,
int  xs,
int  ys,
int  w,
int  h 
)

Draw image (without transparency)

Parameters
canvasDestination canvas
srcSource canvas
xdDestination horizontal postion
ydDestination vertical position
xsSource horizontal position
ysSource vertical position
wWidth
hHeight

◆ DrawBlit()

void DrawBlit ( sCanvas canvas,
sCanvas src,
int  xd,
int  yd,
int  xs,
int  ys,
int  w,
int  h,
u8  col 
)

Draw image with transparency.

Note
Source and destination must have same format. CANVAS_ATTRIB8 format replaced by DrawImg() function.
Parameters
canvasDestination canvas
srcSource canvas
xdDestination horizontal postion
ydDestination vertical position
xsSource horizontal position
ysSource vertical position
wWidth
hHeight
colTransparency key color

◆ DrawImgMat()

void DrawImgMat ( sCanvas canvas,
const sCanvas src,
int  x,
int  y,
int  w,
int  h,
const class cMat2Df m,
u8  mode,
u8  color 
)

Draw 8-bit image with 2D transformation matrix.

Note
To wrap and perspective mode: Width and height of source image must be power of 2.
Parameters
canvasDestination canvas
srcSource canvas with image
xDestination horizontal postion
yDestination vertical position
wDestination width
hDestination height
mTransformation matrix (should be prepared using cMat2Df::PrepDrawImg() function)
modeMode enum value
colorKey or border color

◆ DrawTileMap()

void DrawTileMap ( sCanvas canvas,
const sCanvas src,
const u8 *  map,
int  mapwbits,
int  maphbits,
int  tilebits,
int  x,
int  y,
int  w,
int  h,
const cMat2Df mat,
u8  horizon 
)

Draw tile map using perspective projection.

Parameters
canvasDestination canvas
srcSource canvas with column of 8-bit square tiles (width = tile size, must be power of 2)
mapByte map of tile indices
mapwbitsNumber of bits of map width (number of tiles; width must be power of 2)
maphbitsNumber of bits of map height (number of tiles; height must be power of 2)
tilebitsNumber of bits of tile size (e.g. 5 = tile 32x32 pixel)
xDestination horizontal postion
yDestination vertical position
wDestination width
hDestination height
matTransformation matrix (should be prepared using cMat2Df::PrepDrawImg() function)
horizonHorizon offset (0 = do not use perspective projection)

◆ DrawImgLine()

void DrawImgLine ( sCanvas canvas,
sCanvas src,
int  xd,
int  yd,
int  xs,
int  ys,
int  wd,
int  ws 
)

Draw image line interpolated.

Note
Overflow in X direction is not checked
Parameters
canvasDestination canvas (8-bit pixel format)
srcSource canvas (source image in 8-bit pixel format)
xdDestination horizontal postion
ydDestination vertical position
xsSource horizontal position
ysSource vertical position
wdDestination width
wsSource width