Vision Apps User Guide
draw2d.h
Go to the documentation of this file.
1 /******************************************************************************
2 Copyright (c) [2012 - 2017] Texas Instruments Incorporated
3 
4 All rights reserved not granted herein.
5 
6 Limited License.
7 
8  Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive
9  license under copyrights and patents it now or hereafter owns or controls to
10  make, have made, use, import, offer to sell and sell ("Utilize") this software
11  subject to the terms herein. With respect to the foregoing patent license,
12  such license is granted solely to the extent that any such patent is necessary
13  to Utilize the software alone. The patent license shall not apply to any
14  combinations which include this software, other than combinations with devices
15  manufactured by or for TI ("TI Devices"). No hardware patent is licensed
16  hereunder.
17 
18  Redistributions must preserve existing copyright notices and reproduce this
19  license (including the above copyright notice and the disclaimer and
20  (if applicable) source code license limitations below) in the documentation
21  and/or other materials provided with the distribution
22 
23  Redistribution and use in binary form, without modification, are permitted
24  provided that the following conditions are met:
25 
26  * No reverse engineering, decompilation, or disassembly of this software
27  is permitted with respect to any software provided in binary form.
28 
29  * Any redistribution and use are licensed by TI for use only with TI Devices.
30 
31  * Nothing shall obligate TI to provide you with source code for the software
32  licensed and provided to you in object code.
33 
34  If software source code is provided to you, modification and redistribution of
35  the source code are permitted provided that the following conditions are met:
36 
37  * Any redistribution and use of the source code, including any resulting
38  derivative works, are licensed by TI for use only with TI Devices.
39 
40  * Any redistribution and use of any object code compiled from the source code
41  and any resulting derivative works, are licensed by TI for use only with TI
42  Devices.
43 
44  Neither the name of Texas Instruments Incorporated nor the names of its
45  suppliers may be used to endorse or promote products derived from this software
46  without specific prior written permission.
47 
48  DISCLAIMER.
49 
50  THIS SOFTWARE IS PROVIDED BY TI AND TI�S LICENSORS "AS IS" AND ANY EXPRESS OR
51  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
52  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
53  IN NO EVENT SHALL TI AND TI�S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT,
54  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
56  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
57  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
58  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
59  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 ******************************************************************************/
61 
91 #ifndef _DRAW_2D_H_
92 #define _DRAW_2D_H_
93 
94 #ifdef __cplusplus
95 extern "C" {
96 #endif
97 
98 /*******************************************************************************
99  * INCLUDE FILES
100  *******************************************************************************
101  */
102 #include <TI/tivx.h>
103 
104 #include <stdlib.h>
105 #include <stdint.h>
106 #include <string.h>
107 #include <assert.h>
108 #include <math.h>
109 /*******************************************************************************
110  * Defines
111  *******************************************************************************
112  */
113 
114  #define DRAW2D_MAX_PLANES (3)
115 
124  typedef enum
125  {
178 
185 #define RGB888_TO_RGB565(r,g,b) ((((uint32_t)(r>>3) & 0x1F) << 11) | (((uint32_t)(g>>2) & 0x3F) << 5) | (((uint32_t)(b>>3) & 0x1F)))
186 #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))
187 
188 #define DRAW2D_TRANSPARENT_COLOR (RGB888_TO_RGB565(0, 0, 0))
189 #define DRAW2D_TRANSPARENT_COLOR_FORMAT (DRAW2D_DF_BGR16_565)
190 
191 /* white logo with transperency */
192 #define DRAW2D_BMP_IDX_TI_LOGO_0 (0)
193 /* red+white logo with black background */
194 #define DRAW2D_BMP_IDX_TI_LOGO_1 (1)
195 /* white logo with black background */
196 #define DRAW2D_BMP_IDX_TI_LOGO_2 (2)
197 /* white logo with black background */
198 #define DRAW2D_BMP_IDX_TI_LOGO_3 (3)
199 /* red+white logo (small) with black background */
200 #define DRAW2D_BMP_IDX_TI_LOGO_4 (4)
201 /* white logo (small) with black background */
202 #define DRAW2D_BMP_IDX_TI_LOGO_5 (5)
203 /* DOF Colour Map */
204 #define DRAW2D_BMP_IDX_DOF_COLOUR_MAP (6)
205 /* Stereo Vision Colour Map */
206 #define DRAW2D_BMP_IDX_SDE_COLOUR_MAP (7)
207 
208 
209 /*
210  * \brief Font property
211  */
212 typedef struct {
213 
214  uint8_t *addr;
217  uint32_t width;
220  uint32_t height;
223  uint32_t bpp;
226  uint32_t lineOffset;
229  uint32_t num;
232  uint32_t colorFormat;
239 
240 /*
241  * \brief Font property
242  */
243 typedef struct {
244 
245  uint8_t *addr;
248  uint32_t width;
251  uint32_t height;
254  uint32_t bpp;
257  uint32_t lineOffset;
260  uint32_t colorFormat;
267 
271 typedef struct
272 {
273  uint8_t *bufAddr[DRAW2D_MAX_PLANES];
276  uint32_t bufWidth;
279  uint32_t bufHeight;
282  uint32_t bufPitch[DRAW2D_MAX_PLANES];
285  uint32_t dataFormat;
310 
314 typedef struct
315 {
316  uint32_t fontIdx;
321 
325 typedef struct
326 {
327  uint32_t bmpIdx;
331 } Draw2D_BmpPrm;
332 
336 typedef struct
337 {
338  uint32_t lineColor;
347  uint32_t lineSize;
351  uint32_t lineColorFormat;
361 
369 typedef struct
370 {
371  uint32_t startX;
373  uint32_t startY;
375  uint32_t height;
377  uint32_t width;
379  uint32_t color;
381  uint32_t colorFormat;
390 
394 typedef void *Draw2D_Handle;
395 
396 
397 /*
398  * Functions
399  */
400 
410 int32_t Draw2D_create(Draw2D_Handle *pCtx);
411 
419 int32_t Draw2D_delete(Draw2D_Handle pCtx);
420 
421 
433 int32_t Draw2D_setBufInfo(Draw2D_Handle pCtx, Draw2D_BufInfo *pBufInfo);
434 
445 void Draw2D_updateBufAddr(Draw2D_Handle pCtx, uint8_t **bufAddr);
446 
454 int32_t Draw2D_clearBuf(Draw2D_Handle pCtx);
455 
468 int32_t Draw2D_drawString(Draw2D_Handle pCtx,
469  uint32_t startX,
470  uint32_t startY,
471  char *str,
472  Draw2D_FontPrm *pPrm);
473 
488  uint32_t startX,
489  uint32_t startY,
490  char *str,
491  Draw2D_FontPrm *pPrm,
492  uint32_t rotate);
493 
509 int32_t Draw2D_clearString(Draw2D_Handle pCtx,
510  uint32_t startX,
511  uint32_t startY,
512  uint32_t stringLength,
513  Draw2D_FontPrm *pPrm);
514 
515 
526 
537 
557 int32_t Draw2D_drawLine(Draw2D_Handle pCtx,
558  uint32_t startX,
559  uint32_t startY,
560  uint32_t endX,
561  uint32_t endY,
562  Draw2D_LinePrm *pPrm);
563 
582 int32_t Draw2D_drawRect(Draw2D_Handle pCtx,
583  uint32_t startX,
584  uint32_t startY,
585  uint32_t width,
586  uint32_t height,
587  Draw2D_LinePrm *pPrm);
588 
600 int32_t Draw2D_clearRegion(Draw2D_Handle pCtx,
601  uint32_t startX,
602  uint32_t startY,
603  uint32_t width,
604  uint32_t height);
605 
606 
616 
617 
634 void Draw2D_drawPixel(Draw2D_Handle pCtx, uint32_t px, uint32_t py, uint32_t color, uint32_t colorFormat);
635 
636 
648 int32_t Draw2D_drawBmp(Draw2D_Handle pCtx,
649  uint32_t startX,
650  uint32_t startY,
651  Draw2D_BmpPrm *pPrm);
652 
665 int32_t Draw2D_drawBmp_rot(Draw2D_Handle pCtx,
666  uint32_t startX,
667  uint32_t startY,
668  Draw2D_BmpPrm *pPrm,
669  uint32_t rotate);
670 
679 int32_t Draw2D_insertBmp(Draw2D_Handle pCtx,
680  char *input_file,
681  int32_t startX,
682  int32_t startY);
683 
695  void *buf,
696  uint32_t buf_size,
697  int32_t startX,
698  int32_t startY);
699 
706 void Draw2D_setFontColor(uint16_t colorText, uint16_t colorBorder, uint16_t colorBg );
707 
709 void Draw2D_resetFontColor();
710 
724 static inline uint32_t Draw2D_floor(uint32_t val, uint32_t align)
725 {
726  return (((val) / (align)) * (align));
727 }
728 
729 #ifdef __cplusplus
730 }
731 #endif /* __cplusplus */
732 
733 #endif /* _DRAW_2D_H_ */
734 
735 /* @} */
736 
737 /* Nothing beyond this point */
Bitmap parameters.
Definition: draw2d.h:325
uint32_t height
Definition: draw2d.h:251
int32_t Draw2D_fillRegion(Draw2D_Handle pCtx, Draw2D_RegionPrm *prm)
Draw a region in the drawing buffer with custom color.
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.
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.
Definition: draw2d.h:164
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.
Definition: draw2d.h:148
int32_t Draw2D_create(Draw2D_Handle *pCtx)
Create a context for drawing.
static uint32_t Draw2D_floor(uint32_t val, uint32_t align)
Initialize In queue parameters of a link.
Definition: draw2d.h:724
uint32_t bmpIdx
Definition: draw2d.h:327
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.
uint8_t * addr
Definition: draw2d.h:245
int32_t Draw2D_drawBmp(Draw2D_Handle pCtx, uint32_t startX, uint32_t startY, Draw2D_BmpPrm *pPrm)
Draw a bitmap into the drawing buffer.
Definition: draw2d.h:168
uint32_t startX
Definition: draw2d.h:371
Definition: draw2d.h:212
Definition: draw2d.h:140
Definition: draw2d.h:128
uint32_t height
Definition: draw2d.h:375
Region Params.
Definition: draw2d.h:369
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.
Definition: draw2d.h:132
uint32_t lineOffset
Definition: draw2d.h:226
Buffer information into which font and 2d primitives will be draw.
Definition: draw2d.h:271
void Draw2D_resetFontColor()
Restore font to default.
uint32_t num
Definition: draw2d.h:229
void Draw2D_updateBufAddr(Draw2D_Handle pCtx, uint8_t **bufAddr)
Update drawing buffer.
uint32_t dataFormat
Definition: draw2d.h:285
Draw2D_DataFormat
Enums for data format.
Definition: draw2d.h:124
Definition: draw2d.h:130
uint32_t color
Definition: draw2d.h:379
Definition: draw2d.h:136
uint32_t colorFormat
Definition: draw2d.h:232
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...
uint8_t * addr
Definition: draw2d.h:214
#define DRAW2D_MAX_PLANES
Definition: draw2d.h:114
Definition: draw2d.h:160
uint32_t height
Definition: draw2d.h:220
uint32_t lineColor
Definition: draw2d.h:338
Definition: draw2d.h:162
Definition: draw2d.h:146
uint32_t bufWidth
Definition: draw2d.h:276
Definition: draw2d.h:138
uint32_t startY
Definition: draw2d.h:373
uint32_t lineOffset
Definition: draw2d.h:257
uint32_t colorFormat
Definition: draw2d.h:260
void * Draw2D_Handle
Draw 2D object handle.
Definition: draw2d.h:394
Definition: draw2d.h:158
uint32_t transperentColor
Definition: draw2d.h:294
Definition: draw2d.h:243
Definition: draw2d.h:154
uint32_t fontIdx
Definition: draw2d.h:316
uint32_t bpp
Definition: draw2d.h:223
Definition: draw2d.h:126
uint32_t bpp
Definition: draw2d.h:254
Line draw parameters.
Definition: draw2d.h:336
uint32_t width
Definition: draw2d.h:377
Definition: draw2d.h:152
uint32_t width
Definition: draw2d.h:217
int32_t Draw2D_delete(Draw2D_Handle pCtx)
Delete a previously created drawing context.
Definition: draw2d.h:142
Definition: draw2d.h:144
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.
uint32_t bufHeight
Definition: draw2d.h:279
uint32_t colorFormat
Definition: draw2d.h:381
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.
uint32_t transperentColorFormat
Definition: draw2d.h:303
Font parameters.
Definition: draw2d.h:314
uint32_t width
Definition: draw2d.h:248
Definition: draw2d.h:150
int32_t Draw2D_setBufInfo(Draw2D_Handle pCtx, Draw2D_BufInfo *pBufInfo)
Associated a drawing buffer with a drawing context.
void Draw2D_setFontColor(uint16_t colorText, uint16_t colorBorder, uint16_t colorBg)
Sets a global color to use for fonts in RGB565 format.
Definition: draw2d.h:170
Definition: draw2d.h:166
int32_t Draw2D_clearBuf(Draw2D_Handle pCtx)
Fill buffer with transperency color.
Definition: draw2d.h:134
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.
Definition: draw2d.h:172
int32_t Draw2D_getFontProperty(Draw2D_FontPrm *pPrm, Draw2D_FontProperty *pProp)
Get properties of a given font.
uint32_t lineSize
Definition: draw2d.h:347
Definition: draw2d.h:156
void Draw2D_drawPixel(Draw2D_Handle pCtx, uint32_t px, uint32_t py, uint32_t color, uint32_t colorFormat)
Draw pixel of a given color.
int32_t Draw2D_getBmpProperty(Draw2D_BmpPrm *pPrm, Draw2D_BmpProperty *pProp)
Get properties of a given bitmap.
uint32_t lineColorFormat
Definition: draw2d.h:351