Vision Apps User Guide
Font and 2D Drawing API

This module has the interface for drawing fonts and 2D primitives like lines. More...

Files

file  draw2d.h
 Font and 2D Drawing API.
 

Data Structures

struct  Draw2D_FontProperty
 
struct  Draw2D_BmpProperty
 
struct  Draw2D_BufInfo
 Buffer information into which font and 2d primitives will be draw. More...
 
struct  Draw2D_FontPrm
 Font parameters. More...
 
struct  Draw2D_BmpPrm
 Bitmap parameters. More...
 
struct  Draw2D_LinePrm
 Line draw parameters. More...
 
struct  Draw2D_RegionPrm
 Region Params. More...
 

Macros

#define DRAW2D_MAX_PLANES   (3)
 
#define RGB888_TO_RGB565(r, g, b)   ((((uint32_t)(r>>3) & 0x1F) << 11) | (((uint32_t)(g>>2) & 0x3F) << 5) | (((uint32_t)(b>>3) & 0x1F)))
 Macro that converts RGB888 to RGB565. More...
 
#define RGB888_TO_BGRA444(r, g, b, a)   ((((uint32_t)(r>>4) & 0xF) << 0) | (((uint32_t)(g>>4) & 0xF) << 4) | (((uint32_t)(b>>4) & 0xF)<<8)| (((uint32_t)(a>>4) & 0xF)<<12))
 
#define DRAW2D_TRANSPARENT_COLOR   (RGB888_TO_RGB565(0, 0, 0))
 
#define DRAW2D_TRANSPARENT_COLOR_FORMAT   (DRAW2D_DF_BGR16_565)
 
#define DRAW2D_BMP_IDX_TI_LOGO_0   (0)
 
#define DRAW2D_BMP_IDX_TI_LOGO_1   (1)
 
#define DRAW2D_BMP_IDX_TI_LOGO_2   (2)
 
#define DRAW2D_BMP_IDX_TI_LOGO_3   (3)
 
#define DRAW2D_BMP_IDX_TI_LOGO_4   (4)
 
#define DRAW2D_BMP_IDX_TI_LOGO_5   (5)
 
#define DRAW2D_BMP_IDX_DOF_COLOUR_MAP   (6)
 
#define DRAW2D_BMP_IDX_SDE_COLOUR_MAP   (7)
 

Typedefs

typedef void * Draw2D_Handle
 Draw 2D object handle. More...
 

Enumerations

enum  Draw2D_DataFormat {
  DRAW2D_DF_YUV422I_UYVY = 0x0000, DRAW2D_DF_YUV422I_YUYV, DRAW2D_DF_YUV422I_YVYU, DRAW2D_DF_YUV422I_VYUY,
  DRAW2D_DF_YUV422SP_UV, DRAW2D_DF_YUV422SP_VU, DRAW2D_DF_YUV422P, DRAW2D_DF_YUV420SP_UV,
  DRAW2D_DF_YUV420SP_VU, DRAW2D_DF_YUV420P, DRAW2D_DF_YUV444P, DRAW2D_DF_YUV444I,
  DRAW2D_DF_RGB16_565, DRAW2D_DF_BGRA16_4444, DRAW2D_DF_RGB24_888, DRAW2D_DF_ARGB32_8888,
  DRAW2D_DF_RGBA32_8888, DRAW2D_DF_BGR16_565, DRAW2D_DF_BGR24_888, DRAW2D_DF_ABGR32_8888,
  DRAW2D_DF_BGRA32_8888, DRAW2D_DF_MISC, DRAW2D_DF_INVALID, DRAW2D_DF_FORCE32BITS = 0xFFFFFFFF
}
 Enums for data format. More...
 

Functions

int32_t Draw2D_create (Draw2D_Handle *pCtx)
 Create a context for drawing. More...
 
int32_t Draw2D_delete (Draw2D_Handle pCtx)
 Delete a previously created drawing context. More...
 
int32_t Draw2D_setBufInfo (Draw2D_Handle pCtx, Draw2D_BufInfo *pBufInfo)
 Associated a drawing buffer with a drawing context. More...
 
void Draw2D_updateBufAddr (Draw2D_Handle pCtx, uint8_t **bufAddr)
 Update drawing buffer. More...
 
int32_t Draw2D_clearBuf (Draw2D_Handle pCtx)
 Fill buffer with transperency color. More...
 
int32_t Draw2D_drawString (Draw2D_Handle pCtx, uint32_t startX, uint32_t startY, char *str, Draw2D_FontPrm *pPrm)
 Draw string of character into the drawing buffer. More...
 
int32_t Draw2D_drawString_rot (Draw2D_Handle pCtx, uint32_t startX, uint32_t startY, char *str, Draw2D_FontPrm *pPrm, uint32_t rotate)
 Draw string of character into the drawing buffer. More...
 
int32_t Draw2D_clearString (Draw2D_Handle pCtx, uint32_t startX, uint32_t startY, uint32_t stringLength, Draw2D_FontPrm *pPrm)
 Clear a area equal to stringLength in the drawing buffer. More...
 
int32_t Draw2D_getFontProperty (Draw2D_FontPrm *pPrm, Draw2D_FontProperty *pProp)
 Get properties of a given font. More...
 
int32_t Draw2D_getBmpProperty (Draw2D_BmpPrm *pPrm, Draw2D_BmpProperty *pProp)
 Get properties of a given bitmap. More...
 
int32_t Draw2D_drawLine (Draw2D_Handle pCtx, uint32_t startX, uint32_t startY, uint32_t endX, uint32_t endY, Draw2D_LinePrm *pPrm)
 Draw a line in the drawing buffer. More...
 
int32_t Draw2D_drawRect (Draw2D_Handle pCtx, uint32_t startX, uint32_t startY, uint32_t width, uint32_t height, Draw2D_LinePrm *pPrm)
 Draw a rectangle in the drawing buffer. More...
 
int32_t Draw2D_clearRegion (Draw2D_Handle pCtx, uint32_t startX, uint32_t startY, uint32_t width, uint32_t height)
 Clear a region in the drawing buffer with transperency color. More...
 
int32_t Draw2D_fillRegion (Draw2D_Handle pCtx, Draw2D_RegionPrm *prm)
 Draw a region in the drawing buffer with custom color. More...
 
void Draw2D_drawPixel (Draw2D_Handle pCtx, uint32_t px, uint32_t py, uint32_t color, uint32_t colorFormat)
 Draw pixel of a given color. More...
 
int32_t Draw2D_drawBmp (Draw2D_Handle pCtx, uint32_t startX, uint32_t startY, Draw2D_BmpPrm *pPrm)
 Draw a bitmap into the drawing buffer. More...
 
int32_t Draw2D_drawBmp_rot (Draw2D_Handle pCtx, uint32_t startX, uint32_t startY, Draw2D_BmpPrm *pPrm, uint32_t rotate)
 Draw a bitmap into the drawing buffer. More...
 
int32_t Draw2D_insertBmp (Draw2D_Handle pCtx, char *input_file, int32_t startX, int32_t startY)
 Draw a bitmap from BMP file at a specified display buffer location. More...
 
int32_t Draw2D_insertBmpFromMemory (Draw2D_Handle pCtx, void *buf, uint32_t buf_size, int32_t startX, int32_t startY)
 Draw a bitmap from BMP file (pre-copied at a memory location) at a specified display buffer location. More...
 
void Draw2D_setFontColor (uint16_t colorText, uint16_t colorBorder, uint16_t colorBg)
 Sets a global color to use for fonts in RGB565 format. More...
 
void Draw2D_resetFontColor ()
 Restore font to default. More...
 
static uint32_t Draw2D_floor (uint32_t val, uint32_t align)
 Initialize In queue parameters of a link. More...
 

Detailed Description

This module has the interface for drawing fonts and 2D primitives like lines.

NOTE: This is limited demo API and not a comprehensive 2D drawing library

Macro Definition Documentation

◆ DRAW2D_MAX_PLANES

#define DRAW2D_MAX_PLANES   (3)

◆ RGB888_TO_RGB565

#define RGB888_TO_RGB565 (   r,
  g,
 
)    ((((uint32_t)(r>>3) & 0x1F) << 11) | (((uint32_t)(g>>2) & 0x3F) << 5) | (((uint32_t)(b>>3) & 0x1F)))

Macro that converts RGB888 to RGB565.

◆ RGB888_TO_BGRA444

#define RGB888_TO_BGRA444 (   r,
  g,
  b,
 
)    ((((uint32_t)(r>>4) & 0xF) << 0) | (((uint32_t)(g>>4) & 0xF) << 4) | (((uint32_t)(b>>4) & 0xF)<<8)| (((uint32_t)(a>>4) & 0xF)<<12))

◆ DRAW2D_TRANSPARENT_COLOR

#define DRAW2D_TRANSPARENT_COLOR   (RGB888_TO_RGB565(0, 0, 0))

◆ DRAW2D_TRANSPARENT_COLOR_FORMAT

#define DRAW2D_TRANSPARENT_COLOR_FORMAT   (DRAW2D_DF_BGR16_565)

◆ DRAW2D_BMP_IDX_TI_LOGO_0

#define DRAW2D_BMP_IDX_TI_LOGO_0   (0)

◆ DRAW2D_BMP_IDX_TI_LOGO_1

#define DRAW2D_BMP_IDX_TI_LOGO_1   (1)

◆ DRAW2D_BMP_IDX_TI_LOGO_2

#define DRAW2D_BMP_IDX_TI_LOGO_2   (2)

◆ DRAW2D_BMP_IDX_TI_LOGO_3

#define DRAW2D_BMP_IDX_TI_LOGO_3   (3)

◆ DRAW2D_BMP_IDX_TI_LOGO_4

#define DRAW2D_BMP_IDX_TI_LOGO_4   (4)

◆ DRAW2D_BMP_IDX_TI_LOGO_5

#define DRAW2D_BMP_IDX_TI_LOGO_5   (5)

◆ DRAW2D_BMP_IDX_DOF_COLOUR_MAP

#define DRAW2D_BMP_IDX_DOF_COLOUR_MAP   (6)

◆ DRAW2D_BMP_IDX_SDE_COLOUR_MAP

#define DRAW2D_BMP_IDX_SDE_COLOUR_MAP   (7)

Typedef Documentation

◆ Draw2D_Handle

typedef void* Draw2D_Handle

Draw 2D object handle.

Enumeration Type Documentation

◆ Draw2D_DataFormat

Enums for data format.

All data formats may not be supported by all links. For supported data formats please look link header file.

Enumerator
DRAW2D_DF_YUV422I_UYVY 

YUV 422 Interleaved format - UYVY.

DRAW2D_DF_YUV422I_YUYV 

YUV 422 Interleaved format - YUYV.

DRAW2D_DF_YUV422I_YVYU 

YUV 422 Interleaved format - YVYU.

DRAW2D_DF_YUV422I_VYUY 

YUV 422 Interleaved format - VYUY.

DRAW2D_DF_YUV422SP_UV 

YUV 422 Semi-Planar - Y separate, UV interleaved.

DRAW2D_DF_YUV422SP_VU 

YUV 422 Semi-Planar - Y separate, VU interleaved.

DRAW2D_DF_YUV422P 

YUV 422 Planar - Y, U and V separate.

DRAW2D_DF_YUV420SP_UV 

YUV 420 Semi-Planar - Y separate, UV interleaved.

DRAW2D_DF_YUV420SP_VU 

YUV 420 Semi-Planar - Y separate, VU interleaved.

DRAW2D_DF_YUV420P 

YUV 420 Planar - Y, U and V separate.

DRAW2D_DF_YUV444P 

YUV 444 Planar - Y, U and V separate.

DRAW2D_DF_YUV444I 

YUV 444 interleaved - YUVYUV...

DRAW2D_DF_RGB16_565 

RGB565 16-bit - 5-bits R, 6-bits G, 5-bits B.

DRAW2D_DF_BGRA16_4444 

BGRA 16-bit - 4-bits R, 4-bits G, 4-bits B, 4-bits Alpha (LSB).

DRAW2D_DF_RGB24_888 

RGB24 24-bit - 8-bits R, 8-bits G, 8-bits B.

DRAW2D_DF_ARGB32_8888 

ARGB32 32-bit - 8-bits R, 8-bits G, 8-bits B, 8-bit Alpha (MSB).

DRAW2D_DF_RGBA32_8888 

RGBA32 32-bit - 8-bits R, 8-bits G, 8-bits B, 8-bit Alpha (LSB).

DRAW2D_DF_BGR16_565 

BGR565 16-bit - 5-bits B, 6-bits G, 5-bits R.

DRAW2D_DF_BGR24_888 

BGR888 24-bit - 8-bits B, 8-bits G, 8-bits R.

DRAW2D_DF_ABGR32_8888 

ABGR8888 32-bit - 8-bits B, 8-bits G, 8-bits R, 8-bit Alpha (MSB).

DRAW2D_DF_BGRA32_8888 

BGRA8888 32-bit - 8-bits B, 8-bits G, 8-bits R, 8-bit Alpha (LSB).

DRAW2D_DF_MISC 

For future purpose.

DRAW2D_DF_INVALID 

Invalid data format. Could be used to initialize variables.

DRAW2D_DF_FORCE32BITS 

This should be the last value after the max enumeration value. This is to make sure enum size defaults to 32 bits always regardless of compiler.

Function Documentation

◆ Draw2D_create()

int32_t Draw2D_create ( Draw2D_Handle pCtx)

Create a context for drawing.

   MUST be called before calling any other Draw2D API
Parameters
pCtx[OUT] Created Draw 2D context
Returns
VX_SUCCESS on success

◆ Draw2D_delete()

int32_t Draw2D_delete ( Draw2D_Handle  pCtx)

Delete a previously created drawing context.

Parameters
pCtx[IN] Draw 2D context
Returns
VX_SUCCESS on success

◆ Draw2D_setBufInfo()

int32_t Draw2D_setBufInfo ( Draw2D_Handle  pCtx,
Draw2D_BufInfo pBufInfo 
)

Associated a drawing buffer with a drawing context.

   This API MUST be called after Draw2D_create() and before any drawing
   API
Parameters
pCtx[IN] Draw 2D context
pBufInfo[IN] Buffer information
Returns
VX_SUCCESS on success

◆ Draw2D_updateBufAddr()

void Draw2D_updateBufAddr ( Draw2D_Handle  pCtx,
uint8_t **  bufAddr 
)

Update drawing buffer.

   This API can be used to update the buffer address when needed
Parameters
pCtx[IN] Draw 2D context
bufAddr[IN] Array of buffer addresses
Returns
VX_SUCCESS on success

◆ Draw2D_clearBuf()

int32_t Draw2D_clearBuf ( Draw2D_Handle  pCtx)

Fill buffer with transperency color.

Parameters
pCtx[IN] Draw 2D context
Returns
VX_SUCCESS on success

◆ Draw2D_drawString()

int32_t Draw2D_drawString ( Draw2D_Handle  pCtx,
uint32_t  startX,
uint32_t  startY,
char *  str,
Draw2D_FontPrm pPrm 
)

Draw string of character into the drawing buffer.

Parameters
pCtx[IN] Draw 2D context
startX[IN] X-position in the buffer
startY[IN] Y-position in the buffer
str[IN] Ascii string to draw
pPrm[IN] Font to use when drawing, when set to NULL default properties used
Returns
VX_SUCCESS on success

◆ Draw2D_drawString_rot()

int32_t Draw2D_drawString_rot ( Draw2D_Handle  pCtx,
uint32_t  startX,
uint32_t  startY,
char *  str,
Draw2D_FontPrm pPrm,
uint32_t  rotate 
)

Draw string of character into the drawing buffer.

Parameters
pCtx[IN] Draw 2D context
startX[IN] X-position in the buffer
startY[IN] Y-position in the buffer
str[IN] Ascii string to draw
pPrm[IN] Font to use when drawing, when set to NULL default properties used
rotate[IN] Set 1 to rotate
Returns
VX_SUCCESS on success

◆ Draw2D_clearString()

int32_t Draw2D_clearString ( Draw2D_Handle  pCtx,
uint32_t  startX,
uint32_t  startY,
uint32_t  stringLength,
Draw2D_FontPrm pPrm 
)

Clear a area equal to stringLength in the drawing buffer.

   This is used to erase a string of previously written characters.
   Internal this draws the 'SPACE' stringLength times
Parameters
pCtx[IN] Draw 2D context
startX[IN] start X-position in the buffer
startY[IN] start Y-position in the buffer
stringLength[IN] Length of string to clear
pPrm[IN] Font to use when drawing, when set to NULL default properties used
Returns
VX_SUCCESS on success

◆ Draw2D_getFontProperty()

int32_t Draw2D_getFontProperty ( Draw2D_FontPrm pPrm,
Draw2D_FontProperty pProp 
)

Get properties of a given font.

Parameters
pPrm[IN] Font to use when drawing, when set to NULL default properties used
pProp[OUT] Font properties like width x height, bpp etc
Returns
VX_SUCCESS on success

◆ Draw2D_getBmpProperty()

int32_t Draw2D_getBmpProperty ( Draw2D_BmpPrm pPrm,
Draw2D_BmpProperty pProp 
)

Get properties of a given bitmap.

Parameters
pPrm[IN] Bitmap to use when drawing, when set to NULL default properties used
pProp[OUT] Bitmap properties like width x height, bpp etc
Returns
VX_SUCCESS on success

◆ Draw2D_drawLine()

int32_t Draw2D_drawLine ( Draw2D_Handle  pCtx,
uint32_t  startX,
uint32_t  startY,
uint32_t  endX,
uint32_t  endY,
Draw2D_LinePrm pPrm 
)

Draw a line in the drawing buffer.

   Currently only horizontal or vertical lines can be drawn
   So make sure endX or endY  is equal to startX or startY

   To clear a line, call the same API with color as transperency
   color in line properties
Parameters
pCtx[IN] Draw 2D context
startX[IN] start X-position in the buffer
startY[IN] start Y-position in the buffer
endX[IN] end X-position in the buffer
endY[IN] end Y-position in the buffer
pPrm[IN] Line properties to use when drawing, when set to NULL default properties used
Returns
VX_SUCCESS on success

◆ Draw2D_drawRect()

int32_t Draw2D_drawRect ( Draw2D_Handle  pCtx,
uint32_t  startX,
uint32_t  startY,
uint32_t  width,
uint32_t  height,
Draw2D_LinePrm pPrm 
)

Draw a rectangle in the drawing buffer.

   Internally uses Draw2D_drawLine() 4 times to draw the rectangle

   To clear a rectangle, call the same API with color as transperency
   color in line properties
Parameters
pCtx[IN] Draw 2D context
startX[IN] start X-position in the buffer
startY[IN] start Y-position in the buffer
width[IN] width of rectangle in pixels
height[IN] height of rectangle in lines
pPrm[IN] Line properties to use when drawing, when set to NULL default properties used
Returns
VX_SUCCESS on success

◆ Draw2D_clearRegion()

int32_t Draw2D_clearRegion ( Draw2D_Handle  pCtx,
uint32_t  startX,
uint32_t  startY,
uint32_t  width,
uint32_t  height 
)

Clear a region in the drawing buffer with transperency color.

Parameters
pCtx[IN] Draw 2D context
startX[IN] start X-position in the buffer
startY[IN] start Y-position in the buffer
width[IN] width of region in pixels
height[IN] height of region in lines
Returns
VX_SUCCESS on success

◆ Draw2D_fillRegion()

int32_t Draw2D_fillRegion ( Draw2D_Handle  pCtx,
Draw2D_RegionPrm prm 
)

Draw a region in the drawing buffer with custom color.

Parameters
pCtx[IN] Draw 2D context
prm[IN] Region Parameters
Returns
VX_SUCCESS on success

◆ Draw2D_drawPixel()

void Draw2D_drawPixel ( Draw2D_Handle  pCtx,
uint32_t  px,
uint32_t  py,
uint32_t  color,
uint32_t  colorFormat 
)

Draw pixel of a given color.

   Representation of color in this function depends on the data format
   set during Draw2D_setBufInfo()

   ex, 16-bit value for RGB565 data format
Parameters
pCtx[IN] Draw 2D context
px[IN] X-position in the buffer
py[IN] Y-position in the buffer
color[IN] Color used to draw the pixel
colorFormat[IN] Color format of the color
Returns
VX_SUCCESS on success

◆ Draw2D_drawBmp()

int32_t Draw2D_drawBmp ( Draw2D_Handle  pCtx,
uint32_t  startX,
uint32_t  startY,
Draw2D_BmpPrm pPrm 
)

Draw a bitmap into the drawing buffer.

Parameters
pCtx[IN] Draw 2D context
startX[IN] X-position in the buffer
startY[IN] Y-position in the buffer
pPrm[IN] Bitmap to use when drawing, when set to NULL default properties used
Returns
VX_SUCCESS on success

◆ Draw2D_drawBmp_rot()

int32_t Draw2D_drawBmp_rot ( Draw2D_Handle  pCtx,
uint32_t  startX,
uint32_t  startY,
Draw2D_BmpPrm pPrm,
uint32_t  rotate 
)

Draw a bitmap into the drawing buffer.

Parameters
pCtx[IN] Draw 2D context
startX[IN] X-position in the buffer
startY[IN] Y-position in the buffer
pPrm[IN] Bitmap to use when drawing, when set to NULL default properties used
rotate[IN] rotation angle, 0: 90 deg, 1: 180 deg, 2: 270 deg
Returns
VX_SUCCESS on success

◆ Draw2D_insertBmp()

int32_t Draw2D_insertBmp ( Draw2D_Handle  pCtx,
char *  input_file,
int32_t  startX,
int32_t  startY 
)

Draw a bitmap from BMP file at a specified display buffer location.

Parameters
pCtx[IN] Draw 2D context
input_file[IN] input .BMP file name
startX[IN] X position in display buffer
startY[IN] Y position in display buffer

◆ Draw2D_insertBmpFromMemory()

int32_t Draw2D_insertBmpFromMemory ( Draw2D_Handle  pCtx,
void *  buf,
uint32_t  buf_size,
int32_t  startX,
int32_t  startY 
)

Draw a bitmap from BMP file (pre-copied at a memory location) at a specified display buffer location.

Parameters
pCtx[IN] Draw 2D context
buf[IN] .BMP file in memory location
buf_size[IN] size of BMP file buffer
startX[IN] X position in display buffer
startY[IN] Y position in display buffer

◆ Draw2D_setFontColor()

void Draw2D_setFontColor ( uint16_t  colorText,
uint16_t  colorBorder,
uint16_t  colorBg 
)

Sets a global color to use for fonts in RGB565 format.

Parameters
colorText[IN] Color of text
colorBorder[IN] Color of text border
colorBg[IN] Color of text background

◆ Draw2D_resetFontColor()

void Draw2D_resetFontColor ( )

Restore font to default.

◆ Draw2D_floor()

static uint32_t Draw2D_floor ( uint32_t  val,
uint32_t  align 
)
inlinestatic

Initialize In queue parameters of a link.

Parameters
val[IN] Value to be rounded off
align[IN] Value to which val to be rounded
Returns
aligned value of val