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
Go to the documentation of this file.
1
32#include "Platform.h"
33#include "EVE_CoCmd.h"
34
35#include "Common.h"
36#include "Image.h"
37#include "EVE_CoCmd.h"
38
40static float mangle = 0;
41static uint32_t mrootx = 0;
42static uint32_t mrooty = 0;
43static int misRotate = 0;
44
46#define USE_COCMD_SETBITMAP 1
47#define ENABLE_ROTATEAROUND 1
49#define MAX_ANGLE 360
50#define CIRCLE_MAX 65536
51
53#define ANGLE(x) (x * 100 * CIRCLE_MAX / (MAX_ANGLE * 100))
54
55#ifndef VP
56#define VP(x) (x*16)
57#endif
58
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}
79
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}
100
101static void setupBitmap(EVE_HalContext *phost, Img_t *image) {
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}
137
138static void rotateBitmap(EVE_HalContext *phost, Img_t *image) {
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}
160
161static void drawBitmap(EVE_HalContext *phost, Img_t *image) {
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}
170
171int Image_Setup_Rotate(float angle, uint32_t rootx, uint32_t rooty) {
172 misRotate = 1;
173 mangle = angle;
174 mrootx = rootx;
175 mrooty = rooty;
176
177 return 1;
178}
179
180int Image_Copy_To_RamG(EVE_HalContext *phost, Img_t *image, uint32_t isRestart) {
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}
196
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}
214
215int Image_Draw(EVE_HalContext *phost, Img_t *image) {
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}
228
230 uint16_t bitmapLayout, uint32_t extFormat, uint8_t tag) {
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}
245 uint16_t bitmapLayout, uint32_t extFormat, uint8_t tag) {
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}
259
Common functions.
#define ATFLASH(x)
Definition Common.h:65
EVE's co-processor commmands.
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
static void EVE_CoCmd_rotate(EVE_HalContext *phost, int32_t a)
Send CMD_ROTATE.
Definition EVE_CoCmd.h:1056
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
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
#define COMPRESSED_RGBA_ASTC_10x5_KHR
#define VERTEX2F(x, y)
#define COMPRESSED_RGBA_ASTC_10x10_KHR
#define SAVE_CONTEXT()
#define COMPRESSED_RGBA_ASTC_12x10_KHR
#define COMPRESSED_RGBA_ASTC_5x4_KHR
#define COMPRESSED_RGBA_ASTC_5x5_KHR
#define NEAREST
#define BITMAP_LAYOUT(format, linestride, height)
#define BEGIN(prim)
#define BITMAPS
#define COMPRESSED_RGBA_ASTC_8x5_KHR
#define BITMAP_SIZE_H(width, height)
#define COMPRESSED_RGBA_ASTC_10x8_KHR
#define RESTORE_CONTEXT()
#define BITMAP_EXT_FORMAT(format)
#define COMPRESSED_RGBA_ASTC_10x6_KHR
#define TAG(s)
#define BITMAP_SOURCE(addr)
#define BORDER
#define COMPRESSED_RGBA_ASTC_8x8_KHR
#define COMPRESSED_RGBA_ASTC_8x6_KHR
#define BITMAP_LAYOUT_H(linestride, height)
#define COMPRESSED_RGBA_ASTC_6x5_KHR
#define BITMAP_SIZE(filter, wrapx, wrapy, width, height)
#define COMPRESSED_RGBA_ASTC_6x6_KHR
#define COMPRESSED_RGBA_ASTC_12x12_KHR
#define COMPRESSED_RGBA_ASTC_4x4_KHR
#define RAM_G
Definition EVE_GpuDefs.h:77
unsigned short uint16_t
int int32_t
unsigned int uint32_t
unsigned char uint8_t
#define App_WrCoCmd_Buffer(phost, cmd)
Definition Gpu_Hal.h:437
int Image_Copy_To_RamG_And_Draw_Image(EVE_HalContext *phost, Img_t *image, uint32_t isRestart)
Definition Image.c:197
static void setupBitmap(EVE_HalContext *phost, Img_t *image)
Definition Image.c:101
static int misRotate
Definition Image.c:43
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 Image.c:229
int Image_Copy_To_RamG(EVE_HalContext *phost, Img_t *image, uint32_t isRestart)
Definition Image.c:180
#define CIRCLE_MAX
Definition Image.c:50
#define VP(x)
Definition Image.c:56
static void rotateBitmap(EVE_HalContext *phost, Img_t *image)
Definition Image.c:138
static uint32_t mrooty
Definition Image.c:42
static uint32_t getformatW(uint32_t format)
Definition Image.c:59
static void drawBitmap(EVE_HalContext *phost, Img_t *image)
Definition Image.c:161
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 Image.c:244
int Image_Draw(EVE_HalContext *phost, Img_t *image)
Definition Image.c:215
#define ANGLE(x)
Graphics unity.
Definition Image.c:53
static uint32_t getformatH(uint32_t format)
Definition Image.c:80
static uint32_t mrootx
Definition Image.c:41
int Image_Setup_Rotate(float angle, uint32_t rootx, uint32_t rooty)
Definition Image.c:171
static float mangle
Status stores.
Definition Image.c:40
Image helper functions.
Definition Image.h:35
uint32_t w
Definition Image.h:42
uint8_t isFlash
Definition Image.h:47
uint16_t extFormat
Definition Image.h:45
uint16_t bitmapLayout
Definition Image.h:44
uint8_t tag
Definition Image.h:46
uint32_t x
Definition Image.h:40
uint32_t size
Definition Image.h:39
uint32_t index
Definition Image.h:36
uint32_t addressFlash
Definition Image.h:37
uint32_t addressRamg
Definition Image.h:38
uint32_t h
Definition Image.h:43
uint32_t y
Definition Image.h:41