image/svg+xml
Brteve's API for EveApps
Version 0.0.1
The reference document for common folder of EveApps project.
 
Loading...
Searching...
No Matches
Image.c File Reference

Image helper functions. More...

#include "Platform.h"
#include "EVE_CoCmd.h"
#include "Common.h"
#include "Image.h"

Go to the source code of this file.

Macros

#define USE_COCMD_SETBITMAP   1
 Configuration.
 
#define ENABLE_ROTATEAROUND   1
 
#define MAX_ANGLE   360
 Graphics definitions.
 
#define CIRCLE_MAX   65536
 
#define ANGLE(x)   (x * 100 * CIRCLE_MAX / (MAX_ANGLE * 100))
 Graphics unity.
 
#define VP(x)   (x*16)
 

Functions

static uint32_t getformatW (uint32_t format)
 
static uint32_t getformatH (uint32_t format)
 
static void setupBitmap (EVE_HalContext *phost, Img_t *image)
 
static void rotateBitmap (EVE_HalContext *phost, Img_t *image)
 
static void drawBitmap (EVE_HalContext *phost, Img_t *image)
 
int Image_Setup_Rotate (float angle, uint32_t rootx, uint32_t rooty)
 
int Image_Copy_To_RamG (EVE_HalContext *phost, Img_t *image, uint32_t isRestart)
 
int Image_Copy_To_RamG_And_Draw_Image (EVE_HalContext *phost, Img_t *image, uint32_t isRestart)
 
int Image_Draw (EVE_HalContext *phost, Img_t *image)
 
int Image_Draw_From_RAM_G (EVE_HalContext *phost, uint32_t address, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint16_t bitmapLayout, uint32_t extFormat, uint8_t tag)
 
int Image_Draw_From_Flash (EVE_HalContext *phost, uint32_t address, uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint16_t bitmapLayout, uint32_t extFormat, uint8_t tag)
 

Variables

static float mangle = 0
 Status stores.
 
static uint32_t mrootx = 0
 
static uint32_t mrooty = 0
 
static int misRotate = 0
 

Detailed Description

Image helper functions.

Author
Tuan Nguyen tuan..nosp@m.nguy.nosp@m.en@br.nosp@m.tchi.nosp@m.p.com
Date
2019

MIT License

Copyright (c) [2019] [Bridgetek Pte Ltd (BRTChip)]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file Image.c.

Macro Definition Documentation

◆ ANGLE

#define ANGLE (   x)    (x * 100 * CIRCLE_MAX / (MAX_ANGLE * 100))

Graphics unity.

Definition at line 53 of file Image.c.

◆ CIRCLE_MAX

#define CIRCLE_MAX   65536

Definition at line 50 of file Image.c.

◆ ENABLE_ROTATEAROUND

#define ENABLE_ROTATEAROUND   1

Definition at line 47 of file Image.c.

◆ MAX_ANGLE

#define MAX_ANGLE   360

Graphics definitions.

Definition at line 49 of file Image.c.

◆ USE_COCMD_SETBITMAP

#define USE_COCMD_SETBITMAP   1

Configuration.

Definition at line 46 of file Image.c.

◆ VP

#define VP (   x)    (x*16)

Definition at line 56 of file Image.c.

Function Documentation

◆ drawBitmap()

static void drawBitmap ( EVE_HalContext phost,
Img_t image 
)
static

Definition at line 161 of file Image.c.

161 {
162 if (image->tag != 0) { // set TAG if the image need to process gesture events
163 App_WrCoCmd_Buffer(phost, TAG(image->tag));
164 } else {
165 App_WrCoCmd_Buffer(phost, TAG(0));
166 }
168 App_WrCoCmd_Buffer(phost, VERTEX2F(VP( image->x), VP(image->y)));
169}
#define VERTEX2F(x, y)
#define BEGIN(prim)
#define BITMAPS
#define TAG(s)
#define App_WrCoCmd_Buffer(phost, cmd)
Definition Gpu_Hal.h:437
#define VP(x)
Definition Image.c:56
uint8_t tag
Definition Image.h:46
uint32_t x
Definition Image.h:40
uint32_t y
Definition Image.h:41

◆ getformatH()

static uint32_t getformatH ( uint32_t  format)
static

Definition at line 80 of file Image.c.

80 {
81 switch (format){
82 case COMPRESSED_RGBA_ASTC_4x4_KHR : return 4;
83 case COMPRESSED_RGBA_ASTC_5x4_KHR : return 4;
84 case COMPRESSED_RGBA_ASTC_5x5_KHR : return 5;
85 case COMPRESSED_RGBA_ASTC_6x5_KHR : return 5;
86 case COMPRESSED_RGBA_ASTC_6x6_KHR : return 6;
87 case COMPRESSED_RGBA_ASTC_8x5_KHR : return 5;
88 case COMPRESSED_RGBA_ASTC_8x6_KHR : return 6;
89 case COMPRESSED_RGBA_ASTC_8x8_KHR : return 8;
90 case COMPRESSED_RGBA_ASTC_10x5_KHR : return 5;
91 case COMPRESSED_RGBA_ASTC_10x6_KHR : return 6;
92 case COMPRESSED_RGBA_ASTC_10x8_KHR : return 8;
93 case COMPRESSED_RGBA_ASTC_10x10_KHR: return 10;
94 case COMPRESSED_RGBA_ASTC_12x10_KHR: return 10;
95 case COMPRESSED_RGBA_ASTC_12x12_KHR: return 12;
96 default:
97 return 4;
98 }
99}
#define COMPRESSED_RGBA_ASTC_10x5_KHR
#define COMPRESSED_RGBA_ASTC_10x10_KHR
#define COMPRESSED_RGBA_ASTC_12x10_KHR
#define COMPRESSED_RGBA_ASTC_5x4_KHR
#define COMPRESSED_RGBA_ASTC_5x5_KHR
#define COMPRESSED_RGBA_ASTC_8x5_KHR
#define COMPRESSED_RGBA_ASTC_10x8_KHR
#define COMPRESSED_RGBA_ASTC_10x6_KHR
#define COMPRESSED_RGBA_ASTC_8x8_KHR
#define COMPRESSED_RGBA_ASTC_8x6_KHR
#define COMPRESSED_RGBA_ASTC_6x5_KHR
#define COMPRESSED_RGBA_ASTC_6x6_KHR
#define COMPRESSED_RGBA_ASTC_12x12_KHR
#define COMPRESSED_RGBA_ASTC_4x4_KHR

◆ getformatW()

static uint32_t getformatW ( uint32_t  format)
static

Definition at line 59 of file Image.c.

59 {
60 switch (format){
61 case COMPRESSED_RGBA_ASTC_4x4_KHR : return 4 ;
62 case COMPRESSED_RGBA_ASTC_5x4_KHR : return 5 ;
63 case COMPRESSED_RGBA_ASTC_5x5_KHR : return 5 ;
64 case COMPRESSED_RGBA_ASTC_6x5_KHR : return 6 ;
65 case COMPRESSED_RGBA_ASTC_6x6_KHR : return 6 ;
66 case COMPRESSED_RGBA_ASTC_8x5_KHR : return 8 ;
67 case COMPRESSED_RGBA_ASTC_8x6_KHR : return 8 ;
68 case COMPRESSED_RGBA_ASTC_8x8_KHR : return 8 ;
69 case COMPRESSED_RGBA_ASTC_10x5_KHR : return 10;
70 case COMPRESSED_RGBA_ASTC_10x6_KHR : return 10;
71 case COMPRESSED_RGBA_ASTC_10x8_KHR : return 10;
72 case COMPRESSED_RGBA_ASTC_10x10_KHR: return 10;
73 case COMPRESSED_RGBA_ASTC_12x10_KHR: return 12;
74 case COMPRESSED_RGBA_ASTC_12x12_KHR: return 12;
75 default:
76 return 4;
77 }
78}

◆ Image_Copy_To_RamG()

int Image_Copy_To_RamG ( EVE_HalContext phost,
Img_t image,
uint32_t  isRestart 
)

Definition at line 180 of file Image.c.

180 {
181 static uint32_t ramgAddr = RAM_G;
182
183 if (isRestart == 1) {
184 ramgAddr = 0;
185 }
186
187 image->isFlash = 0;
188 image->addressRamg = ramgAddr;
189
190 EVE_CoCmd_flashRead(phost, ramgAddr, image->addressFlash, image->size);
191
192 ramgAddr += image->size;
193
194 return 1;
195}
static void EVE_CoCmd_flashRead(EVE_HalContext *phost, uint32_t dest, uint32_t src, uint32_t num)
Read from Flash to RAM_G. Call EVE_Cmd_waitFlush to wait for completion.
Definition EVE_CoCmd.h:679
#define RAM_G
Definition EVE_GpuDefs.h:77
unsigned int uint32_t
uint8_t isFlash
Definition Image.h:47
uint32_t size
Definition Image.h:39
uint32_t addressFlash
Definition Image.h:37
uint32_t addressRamg
Definition Image.h:38

◆ Image_Copy_To_RamG_And_Draw_Image()

int Image_Copy_To_RamG_And_Draw_Image ( EVE_HalContext phost,
Img_t image,
uint32_t  isRestart 
)

Definition at line 197 of file Image.c.

197 {
198 static uint32_t ramgAddr = RAM_G;
199
200 if (isRestart == 1) {
201 ramgAddr = 0;
202 }
203
204 image->isFlash = 0;
205 image->addressRamg = ramgAddr;
206
207 EVE_CoCmd_flashRead(phost, ramgAddr, image->addressFlash, image->size);
208 Image_Draw(phost, image);
209
210 ramgAddr += image->size;
211
212 return 1;
213}
int Image_Draw(EVE_HalContext *phost, Img_t *image)
Definition Image.c:215

◆ Image_Draw()

int Image_Draw ( EVE_HalContext phost,
Img_t image 
)

Definition at line 215 of file Image.c.

215 {
217 setupBitmap(phost, image);
218 if (misRotate) {
219 rotateBitmap(phost, image);
220 misRotate = 0;
221 }
222 drawBitmap(phost, image);
223
225
226 return 1;
227}
#define SAVE_CONTEXT()
#define RESTORE_CONTEXT()
static void setupBitmap(EVE_HalContext *phost, Img_t *image)
Definition Image.c:101
static int misRotate
Definition Image.c:43
static void rotateBitmap(EVE_HalContext *phost, Img_t *image)
Definition Image.c:138
static void drawBitmap(EVE_HalContext *phost, Img_t *image)
Definition Image.c:161

◆ Image_Draw_From_Flash()

int Image_Draw_From_Flash ( EVE_HalContext phost,
uint32_t  address,
uint32_t  x,
uint32_t  y,
uint32_t  w,
uint32_t  h,
uint16_t  bitmapLayout,
uint32_t  extFormat,
uint8_t  tag 
)

Definition at line 244 of file Image.c.

245 {
246 Img_t image;
247 image.isFlash = 1;
248 image.addressFlash = address;
249 image.bitmapLayout = bitmapLayout;
250 image.extFormat = extFormat;
251 image.x = x;
252 image.y = y;
253 image.w = w;
254 image.h = h;
255 image.index = 0;
256 image.tag = tag;
257 return Image_Draw(phost, &image);
258}
Definition Image.h:35
uint32_t w
Definition Image.h:42
uint16_t extFormat
Definition Image.h:45
uint16_t bitmapLayout
Definition Image.h:44
uint32_t index
Definition Image.h:36
uint32_t h
Definition Image.h:43

◆ Image_Draw_From_RAM_G()

int Image_Draw_From_RAM_G ( EVE_HalContext phost,
uint32_t  address,
uint32_t  x,
uint32_t  y,
uint32_t  w,
uint32_t  h,
uint16_t  bitmapLayout,
uint32_t  extFormat,
uint8_t  tag 
)

Definition at line 229 of file Image.c.

230 {
231 Img_t image;
232 image.isFlash = 0;
233 image.addressRamg = address;
234 image.bitmapLayout = bitmapLayout;
235 image.extFormat = extFormat;
236 image.x = x;
237 image.y = y;
238 image.h = h;
239 image.w = w;
240 image.index = 0;
241 image.tag = tag;
242 return Image_Draw(phost, &image);
243}

◆ Image_Setup_Rotate()

int Image_Setup_Rotate ( float  angle,
uint32_t  rootx,
uint32_t  rooty 
)

Definition at line 171 of file Image.c.

171 {
172 misRotate = 1;
173 mangle = angle;
174 mrootx = rootx;
175 mrooty = rooty;
176
177 return 1;
178}
static uint32_t mrooty
Definition Image.c:42
static uint32_t mrootx
Definition Image.c:41
static float mangle
Status stores.
Definition Image.c:40

◆ rotateBitmap()

static void rotateBitmap ( EVE_HalContext phost,
Img_t image 
)
static

Definition at line 138 of file Image.c.

138 {
139 uint16_t translateX = 1, translateY = image->h - image->w;
140
141 if (image->w < image->h) {
142 translateX = image->h - image->w;
143 translateY = 1;
144 }
145#if ENABLE_ROTATEAROUND
148 EVE_CoCmd_setMatrix(phost);
149#else
150 // Use rotate and translate
152 EVE_CoCmd_translate(phost, (translateX + mrootx) * CIRCLE_MAX,
153 (translateY + mrooty) * CIRCLE_MAX);
155 EVE_CoCmd_translate(phost, -(0 + mrootx) * CIRCLE_MAX,
156 -(0 + mrooty) * CIRCLE_MAX);
157 EVE_CoCmd_setMatrix(phost);
158#endif
159}
static void EVE_CoCmd_rotate(EVE_HalContext *phost, int32_t a)
Send CMD_ROTATE.
Definition EVE_CoCmd.h:1056
static void EVE_CoCmd_loadIdentity(EVE_HalContext *phost)
Send CMD_LOADIDENTITY.
Definition EVE_CoCmd.h:998
static void EVE_CoCmd_translate(EVE_HalContext *phost, int32_t tx, int32_t ty)
Send CMD_TRANSLATE.
Definition EVE_CoCmd.h:1018
static void EVE_CoCmd_setMatrix(EVE_HalContext *phost)
Send CMD_SETMATRIX.
Definition EVE_CoCmd.h:1072
static void EVE_CoCmd_rotateAround(EVE_HalContext *phost, int32_t x, int32_t y, int32_t a, int32_t s)
Send CMD_ROTATEAROUND.
Definition EVE_CoCmd.h:1211
unsigned short uint16_t
int int32_t
#define CIRCLE_MAX
Definition Image.c:50
#define ANGLE(x)
Graphics unity.
Definition Image.c:53

◆ setupBitmap()

static void setupBitmap ( EVE_HalContext phost,
Img_t image 
)
static

Definition at line 101 of file Image.c.

101 {
102 uint32_t address = image->addressRamg;
103
104#if USE_COCMD_SETBITMAP
105 if (image->isFlash) {
106 address = ATFLASH(image->addressFlash);
107 }
108 EVE_CoCmd_setBitmap(phost, address, image->bitmapLayout, image->w, image->h);
109#else
110 uint32_t frameSize = image->w * 2;
111 uint32_t frameW = image->w;
112 uint32_t frameH = image->h;
113
114 if (image->w < image->h) {
115 frameSize = image->h * 2;
116 }
117 if (misRotate) {
118 frameW = frameH = frameSize;
119 }
120
121 // Only support ASTC
122 uint16_t lh, linestride;
123 const uint16_t atscBlockSize = 16;
124 uint16_t formatW = getformatW(image->bitmapLayout), formatH = getformatH(image->bitmapLayout);
125
126 linestride = atscBlockSize * ((image->w + formatW - 1) / formatW);
127 lh = (image->h + formatH - 1) / formatH;
128
129 App_WrCoCmd_Buffer(phost, BITMAP_SOURCE(address));
130 App_WrCoCmd_Buffer(phost, BITMAP_LAYOUT(image->bitmapLayout, linestride, lh));
131 App_WrCoCmd_Buffer(phost, BITMAP_LAYOUT_H(linestride >> 10, lh >> 9));
133 App_WrCoCmd_Buffer(phost, BITMAP_SIZE(NEAREST, BORDER, BORDER, frameW, frameH));
134 App_WrCoCmd_Buffer(phost, BITMAP_SIZE_H(frameW >> 9, frameH >> 9));
135#endif
136}
#define ATFLASH(x)
Definition Common.h:65
static void EVE_CoCmd_setBitmap(EVE_HalContext *phost, uint32_t source, uint16_t fmt, uint16_t w, uint16_t h)
Send CMD_SETBITMAP.
Definition EVE_CoCmd.h:1184
#define NEAREST
#define BITMAP_LAYOUT(format, linestride, height)
#define BITMAP_SIZE_H(width, height)
#define BITMAP_EXT_FORMAT(format)
#define BITMAP_SOURCE(addr)
#define BORDER
#define BITMAP_LAYOUT_H(linestride, height)
#define BITMAP_SIZE(filter, wrapx, wrapy, width, height)
static uint32_t getformatW(uint32_t format)
Definition Image.c:59
static uint32_t getformatH(uint32_t format)
Definition Image.c:80

Variable Documentation

◆ mangle

float mangle = 0
static

Status stores.

Definition at line 40 of file Image.c.

◆ misRotate

int misRotate = 0
static

Definition at line 43 of file Image.c.

◆ mrootx

uint32_t mrootx = 0
static

Definition at line 41 of file Image.c.

◆ mrooty

uint32_t mrooty = 0
static

Definition at line 42 of file Image.c.