root / proj / libs / graph / src / graph.c @ 332
History | View | Annotate | Download (14.3 KB)
1 | 178 | up20180642 | #include <lcom/lcf.h> |
---|---|---|---|
2 | |||
3 | 168 | up20180642 | #include "graph.h" |
4 | 183 | up20180642 | |
5 | 168 | up20180642 | #include "errors.h" |
6 | #include <stdio.h> |
||
7 | |||
8 | 253 | up20180642 | #define VC_BIOS_SERV 0x10 /** @brief Interrupt service of video card */ |
9 | #define VBE_CALL 0x4F /** @brief VBE call function specifier */ |
||
10 | |||
11 | 324 | up20180642 | #define MBYTE_BASE 0x0 /** @brief Base address (zero address) */ |
12 | #define MBYTE_SIZE 0xFFFFF /** @brief Size of a mebibyte */ |
||
13 | 253 | up20180642 | |
14 | // Graphics Functions
|
||
15 | 324 | up20180642 | #define VBE_CTRL_INFO 0x00 /** @brief Get VBE Controller Information */ |
16 | 253 | up20180642 | #define VBE_MD_INFO 0x01 /** @brief Get VBE Mode Information */ |
17 | #define SET_VBE_MD 0x02 /** @brief Set VBE Mode */ |
||
18 | |||
19 | // Error codes (AH)
|
||
20 | #define AH_SUCCESS 0x00 /** @brief Success code on BIOS call */ |
||
21 | 324 | up20180642 | #define AH_FUNC_CALL_FAIL 0x01 /** @brief Function call failed */ |
22 | #define AH_FUNC_NOT_SUPP 0x02 /** @brief Function call is not supported in current HW configuration */ |
||
23 | #define AH_FUNC_INVALID 0x03 /** @brief Invalid function in current video mode */ |
||
24 | 253 | up20180642 | |
25 | 174 | up20180642 | /// MACROS
|
26 | 324 | up20180642 | #define FAR2PHYS(n) ((((n)>>12) & 0xFFFFFFF0) + ((n) & 0x0000FFFF)) |
27 | 174 | up20180642 | |
28 | /// STRUCT
|
||
29 | typedef struct __attribute__((packed)) { |
||
30 | |||
31 | char VbeSignature[4] ; |
||
32 | uint16_t VbeVersion ; |
||
33 | uint32_t OemStringPtr ; |
||
34 | uint8_t Capabilities[4] ;
|
||
35 | uint32_t VideoModePtr ; |
||
36 | uint16_t TotalMemory ; |
||
37 | |||
38 | uint16_t OemSoftwareRev ; |
||
39 | uint32_t OemVendorNamePtr ; |
||
40 | uint32_t OemProductNamePtr ; |
||
41 | uint32_t OemProductRevPtr ; |
||
42 | char Reserved[222] ; |
||
43 | |||
44 | char OemData[256] ; |
||
45 | } VbeInfoBlock; |
||
46 | |||
47 | 168 | up20180642 | static vbe_mode_info_t vbe_mem_info;
|
48 | |||
49 | 174 | up20180642 | /// PRIVATE GET
|
50 | static uint16_t (graph_get_bits_pixel) (void){ return vbe_mem_info.BitsPerPixel; } |
||
51 | static phys_bytes (graph_get_phys_addr) (void){ return vbe_mem_info.PhysBasePtr; } |
||
52 | static unsigned (graph_get_vram_size) (void){ return vbe_mem_info.XResolution * vbe_mem_info.YResolution * graph_get_bytes_pixel(); } |
||
53 | //static uint16_t (graph_get_RedMaskSize) (void){ return vbe_mem_info.RedMaskSize ; }
|
||
54 | //static uint16_t (graph_get_GreenMaskSize)(void){ return vbe_mem_info.GreenMaskSize; }
|
||
55 | //static uint16_t (graph_get_BlueMaskSize) (void){ return vbe_mem_info.BlueMaskSize ; }
|
||
56 | |||
57 | 208 | up20180642 | /// PUBLIC GET
|
58 | uint16_t (graph_get_XRes) (void){ return vbe_mem_info.XResolution; } |
||
59 | uint16_t (graph_get_YRes) (void){ return vbe_mem_info.YResolution; } |
||
60 | uint16_t (graph_get_bytes_pixel) (void){ return (graph_get_bits_pixel() + 7) >> 3; } |
||
61 | |||
62 | ///
|
||
63 | 174 | up20180642 | static int (get_permission)(unsigned int base_addr, unsigned int size) { |
64 | 168 | up20180642 | struct minix_mem_range mmr;
|
65 | mmr.mr_base = base_addr; |
||
66 | mmr.mr_limit = base_addr + size; |
||
67 | return sys_privctl(SELF, SYS_PRIV_ADD_MEM, &mmr);
|
||
68 | } |
||
69 | |||
70 | 174 | up20180642 | //static int (get_permissions_first_mbyte)(void) {
|
71 | 168 | up20180642 | // return get_permission(MBYTE_BASE, MBYTE_SIZE);
|
72 | //}
|
||
73 | |||
74 | 174 | up20180642 | /// MEMORY
|
75 | 178 | up20180642 | static uint8_t *video_mem = NULL; /** @brief Frame-buffer VM address. */ |
76 | 174 | up20180642 | static uint8_t *video_buf = NULL; /** @brief Primary buffer for drawing before copying to video_mem. */ |
77 | static mmap_t mem_map;
|
||
78 | static int (graph_free_memory)(void) { |
||
79 | int r = SUCCESS;
|
||
80 | free(video_buf); video_buf = NULL;
|
||
81 | r = !lm_free(&mem_map); |
||
82 | return r;
|
||
83 | } |
||
84 | static int (graph_map_vram)(void) { |
||
85 | int r;
|
||
86 | const unsigned vram_base = graph_get_phys_addr(); |
||
87 | const unsigned vram_size = graph_get_vram_size(); |
||
88 | if ((r = get_permission(vram_base, vram_size))) {
|
||
89 | if (graph_free_memory()) {
|
||
90 | printf("%s: lm_free failed\n", __func__);
|
||
91 | } |
||
92 | panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r);
|
||
93 | 168 | up20180642 | } |
94 | |||
95 | 174 | up20180642 | video_mem = vm_map_phys(SELF, (void *)vram_base, vram_size);
|
96 | 168 | up20180642 | |
97 | 174 | up20180642 | if (video_mem == MAP_FAILED) {
|
98 | if (graph_free_memory()) {
|
||
99 | printf("%s: lm_free failed\n", __func__);
|
||
100 | } |
||
101 | panic("%s: couldn't map video memory.", __func__);
|
||
102 | } |
||
103 | |||
104 | video_buf = malloc(vram_size); |
||
105 | |||
106 | 168 | up20180642 | return SUCCESS;
|
107 | } |
||
108 | |||
109 | 174 | up20180642 | /// INFO GET
|
110 | static int (vbe_get_mode_information)(uint16_t mode) { |
||
111 | 168 | up20180642 | memset(&vbe_mem_info, 0, sizeof(vbe_mode_info_t)); // reset values |
112 | |||
113 | struct reg86 reg_86;
|
||
114 | memset(®_86, 0, sizeof(struct reg86)); // reset struct |
||
115 | |||
116 | vbe_mode_info_t *virtual_addr = lm_alloc(sizeof(vbe_mode_info_t), &mem_map);
|
||
117 | |||
118 | reg_86.intno = VC_BIOS_SERV; |
||
119 | reg_86.ah = VBE_CALL; |
||
120 | reg_86.al = VBE_MD_INFO; |
||
121 | reg_86.cx = mode; |
||
122 | reg_86.es = PB2BASE(mem_map.phys); |
||
123 | reg_86.di = PB2OFF(mem_map.phys); |
||
124 | // BIOS CALL
|
||
125 | if (sys_int86(®_86) || reg_86.ah != AH_SUCCESS) {
|
||
126 | printf("%s: sys_int86 failed\n", __func__);
|
||
127 | if (graph_free_memory()) {
|
||
128 | printf("%s: lm_free failed\n", __func__);
|
||
129 | } |
||
130 | return BIOS_CALL_ERROR;
|
||
131 | } |
||
132 | |||
133 | memcpy((void*)&vbe_mem_info, (void*)virtual_addr, mem_map.size); |
||
134 | return SUCCESS;
|
||
135 | } |
||
136 | 174 | up20180642 | /*
|
137 | static int (vbe_get_controller_information)(vg_vbe_contr_info_t *info_p) {
|
||
138 | 168 | up20180642 | memset(info_p, 0, sizeof(vg_vbe_contr_info_t)); // reset values
|
139 | |||
140 | mmap_t controller_map;
|
||
141 | |||
142 | struct reg86 reg_86;
|
||
143 | memset(®_86, 0, sizeof(struct reg86)); // reset struct
|
||
144 | |||
145 | VbeInfoBlock *virtual_addr = lm_alloc(sizeof(VbeInfoBlock), &controller_map);
|
||
146 | |||
147 | uint32_t virtual_base = (uint32_t)(virtual_addr) - controller_map.phys;
|
||
148 | |||
149 | virtual_addr->VbeSignature[0] = 'V';
|
||
150 | virtual_addr->VbeSignature[1] = 'B';
|
||
151 | virtual_addr->VbeSignature[2] = 'E';
|
||
152 | virtual_addr->VbeSignature[3] = '2';
|
||
153 | |||
154 | |||
155 | reg_86.intno = VC_BIOS_SERV;
|
||
156 | reg_86.ah = VBE_CALL;
|
||
157 | reg_86.al = VBE_CTRL_INFO;
|
||
158 | reg_86.es = PB2BASE(controller_map.phys);
|
||
159 | reg_86.di = PB2OFF(controller_map.phys);
|
||
160 | // BIOS CALL
|
||
161 | if (sys_int86(®_86) || reg_86.ah != AH_SUCCESS) {
|
||
162 | printf("%s: sys_int86 failed\n", __func__);
|
||
163 | if (!lm_free(&controller_map)) {
|
||
164 | printf("%s: lm_free failed\n", __func__);
|
||
165 | }
|
||
166 | return BIOS_CALL_ERROR;
|
||
167 | }
|
||
168 | |||
169 | info_p->VBESignature[0] = virtual_addr->VbeSignature[0];
|
||
170 | info_p->VBESignature[1] = virtual_addr->VbeSignature[1];
|
||
171 | info_p->VBESignature[2] = virtual_addr->VbeSignature[2];
|
||
172 | info_p->VBESignature[3] = virtual_addr->VbeSignature[3];
|
||
173 | |||
174 | uint8_t lsb, msb;
|
||
175 | util_get_LSB(virtual_addr->VbeVersion, &lsb);
|
||
176 | util_get_MSB(virtual_addr->VbeVersion, &msb);
|
||
177 | info_p->VBEVersion[0] = lsb;
|
||
178 | info_p->VBEVersion[1] = msb;
|
||
179 | |||
180 | info_p->TotalMemory = (virtual_addr->TotalMemory << 6);
|
||
181 | |||
182 | // Convert Far Far Pointer to Virtual Address
|
||
183 | |||
184 | uint32_t phys_ptr = FAR2PHYS(virtual_addr->OemStringPtr);
|
||
185 | uint32_t virtual_ptr = phys_ptr + virtual_base;
|
||
186 | info_p->OEMString = (char*)(virtual_ptr);
|
||
187 | |||
188 | phys_ptr = FAR2PHYS(virtual_addr->VideoModePtr);
|
||
189 | virtual_ptr = phys_ptr + virtual_base;
|
||
190 | info_p->VideoModeList = (uint16_t*)(virtual_ptr);
|
||
191 | |||
192 | phys_ptr = FAR2PHYS(virtual_addr->OemVendorNamePtr);
|
||
193 | virtual_ptr = phys_ptr + virtual_base;
|
||
194 | info_p->OEMVendorNamePtr = (char*)(virtual_ptr);
|
||
195 | |||
196 | phys_ptr = FAR2PHYS(virtual_addr->OemProductNamePtr);
|
||
197 | virtual_ptr = phys_ptr + virtual_base;
|
||
198 | info_p->OEMProductNamePtr = (char*)(virtual_ptr);
|
||
199 | |||
200 | phys_ptr = FAR2PHYS(virtual_addr->OemProductRevPtr);
|
||
201 | virtual_ptr = phys_ptr + virtual_base;
|
||
202 | info_p->OEMProductRevPtr = (char*)(virtual_ptr);
|
||
203 | |||
204 | if (!lm_free(&controller_map)) {
|
||
205 | printf("%s: lm_free failed\n", __func__);
|
||
206 | return LCF_ERROR;
|
||
207 | }
|
||
208 | |||
209 | return SUCCESS;
|
||
210 | }
|
||
211 | 174 | up20180642 | */
|
212 | 168 | up20180642 | |
213 | 174 | up20180642 | /// INIT
|
214 | static int (graph_set_mode)(uint16_t mode) { |
||
215 | 168 | up20180642 | struct reg86 reg_86;
|
216 | |||
217 | memset(®_86, 0, sizeof(struct reg86)); // reset struct |
||
218 | |||
219 | // Set Reg86
|
||
220 | reg_86.intno = VC_BIOS_SERV; |
||
221 | reg_86.ah = VBE_CALL; |
||
222 | reg_86.al = SET_VBE_MD; |
||
223 | reg_86.bx = mode | LINEAR_FRAME_BUFFER_MD; |
||
224 | |||
225 | // BIOS CALL
|
||
226 | if (sys_int86(®_86) || reg_86.ah != AH_SUCCESS) {
|
||
227 | printf("%s: sys_int86 failed\n", __func__);
|
||
228 | return BIOS_CALL_ERROR;
|
||
229 | } |
||
230 | |||
231 | return SUCCESS;
|
||
232 | } |
||
233 | 174 | up20180642 | int (graph_init)(uint16_t mode){
|
234 | if (vbe_get_mode_information(mode)) {
|
||
235 | printf("%s: failed to get information for mode %x.\n", __func__, mode);
|
||
236 | return 1; |
||
237 | } |
||
238 | 168 | up20180642 | |
239 | 174 | up20180642 | graph_map_vram(); // if function fails it aborts program
|
240 | |||
241 | if (graph_set_mode(mode)) {
|
||
242 | printf("%s: failed to set graphic mode %x.\n", __func__, mode);
|
||
243 | return 1; |
||
244 | }; |
||
245 | return SUCCESS;
|
||
246 | } |
||
247 | |||
248 | /// CLEANUP
|
||
249 | int (graph_cleanup)(void){ |
||
250 | int r = SUCCESS;
|
||
251 | if ((r = vg_exit()))
|
||
252 | printf("%s: vg_exit failed to exit to text mode.\n", __func__);
|
||
253 | if ((r = graph_free_memory()))
|
||
254 | printf("%s: lm_free failed\n", __func__);
|
||
255 | return r;
|
||
256 | } |
||
257 | |||
258 | /// PIXEL DRAWING
|
||
259 | 332 | up20180642 | void (graph_set_pixel)(uint16_t x, uint16_t y, uint32_t color) {
|
260 | memcpy(video_buf + (x+y*graph_get_XRes())*graph_get_bytes_pixel(), &color, graph_get_bytes_pixel()); |
||
261 | 168 | up20180642 | } |
262 | 208 | up20180642 | void (graph_set_pixel_pos)(unsigned pos, uint32_t color){ |
263 | 207 | up20180642 | memcpy(video_buf + pos, &color, graph_get_bytes_pixel()); |
264 | 168 | up20180642 | } |
265 | 208 | up20180642 | int (graph_clear_screen)(void){ memset(video_buf, 0, graph_get_vram_size()); return SUCCESS; } |
266 | int (graph_draw)(void){ memcpy(video_mem, video_buf, graph_get_vram_size()); return SUCCESS; } |
||
267 | 174 | up20180642 | |
268 | 211 | up20180642 | ///SPRITE
|
269 | 332 | up20180642 | #include "sprite.h" |
270 | |||
271 | 211 | up20180642 | #include "utils.h" |
272 | #include "fast_math.h" |
||
273 | #include <math.h> |
||
274 | |||
275 | struct basic_sprite{
|
||
276 | uint8_t *map; |
||
277 | uint16_t w, h; |
||
278 | int16_t u0, v0; |
||
279 | }; |
||
280 | 321 | up20180642 | basic_sprite_t* (basic_sprite_ctor)(const char *const *xpm, int16_t u0, int16_t v0){ |
281 | 211 | up20180642 | basic_sprite_t *ret = malloc(sizeof(basic_sprite_t));
|
282 | if(ret == NULL) return NULL; |
||
283 | enum xpm_image_type type = XPM_8_8_8_8;
|
||
284 | xpm_image_t img; |
||
285 | ret->map = xpm_load((xpm_map_t)xpm, type, &img); |
||
286 | if(ret->map == NULL){ |
||
287 | 216 | up20180642 | basic_sprite_dtor(ret); |
288 | 211 | up20180642 | return NULL; |
289 | } |
||
290 | ret->w = img.width; |
||
291 | ret->h = img.height; |
||
292 | ret->u0 = u0; |
||
293 | ret->v0 = v0; |
||
294 | return ret;
|
||
295 | } |
||
296 | void (basic_sprite_dtor)(basic_sprite_t *p){
|
||
297 | if(p == NULL) return; |
||
298 | free(p->map); |
||
299 | free(p); |
||
300 | } |
||
301 | const uint8_t* (basic_sprite_get_map)(const basic_sprite_t *p){ return p->map; } |
||
302 | uint16_t (basic_sprite_get_w) (const basic_sprite_t *p){ return p->w ; } |
||
303 | uint16_t (basic_sprite_get_h) (const basic_sprite_t *p){ return p->h ; } |
||
304 | int16_t (basic_sprite_get_u0) (const basic_sprite_t *p){ return p->u0 ; } |
||
305 | int16_t (basic_sprite_get_v0) (const basic_sprite_t *p){ return p->v0 ; } |
||
306 | |||
307 | struct sprite{
|
||
308 | const basic_sprite_t *bsp;
|
||
309 | int16_t x, y; //position in screen
|
||
310 | 306 | up20180642 | int16_t su0, sv0; |
311 | 321 | up20180642 | double theta, s, c;
|
312 | double scale;
|
||
313 | 306 | up20180642 | uint8_t *sbuf; |
314 | 211 | up20180642 | }; |
315 | sprite_t* (sprite_ctor)(const basic_sprite_t *bsp){
|
||
316 | sprite_t *ret = malloc(sizeof(sprite_t));
|
||
317 | if(ret == NULL) return NULL; |
||
318 | ret->bsp = bsp; |
||
319 | 306 | up20180642 | ret->sbuf = NULL;
|
320 | 211 | up20180642 | ret->x = 0;
|
321 | ret->y = 0;
|
||
322 | sprite_set_angle(ret, 0.0); |
||
323 | 306 | up20180642 | sprite_set_scale(ret, 1.0); |
324 | 211 | up20180642 | return ret;
|
325 | } |
||
326 | void (sprite_dtor)(sprite_t *p){
|
||
327 | if(p == NULL) return; |
||
328 | 306 | up20180642 | free(p->sbuf); |
329 | 211 | up20180642 | free(p); |
330 | } |
||
331 | void (sprite_set_pos) (sprite_t *p, int16_t x , int16_t y ){ p->x = x; p->y = y; }
|
||
332 | void (sprite_set_angle) (sprite_t *p, double angle ){ p->theta = angle; p->c = fm_cos(p->theta); p->s = fm_sin(p->theta); } |
||
333 | 306 | up20180642 | void (sprite_set_scale) (sprite_t *p, double scale ){ |
334 | 323 | up20180642 | if(deq(p->scale, scale)) return; |
335 | 306 | up20180642 | p->scale = scale; |
336 | |||
337 | 323 | up20180642 | p->su0 = (int16_t)(p->bsp->u0*p->scale); |
338 | p->sv0 = (int16_t)(p->bsp->u0*p->scale); |
||
339 | 306 | up20180642 | |
340 | const uint16_t W = basic_sprite_get_w(p->bsp),
|
||
341 | H = basic_sprite_get_h(p->bsp); |
||
342 | 323 | up20180642 | uint16_t sW = (uint16_t)(W*scale), sH = (uint16_t)(H*scale); |
343 | 306 | up20180642 | p->sbuf = realloc(p->sbuf, sW*sH*4);
|
344 | const uint8_t *map = basic_sprite_get_map(p->bsp);
|
||
345 | for(uint16_t sx = 0; sx < sW; ++sx){ |
||
346 | for(uint16_t sy = 0; sy < sH; ++sy){ |
||
347 | 323 | up20180642 | uint16_t x = (uint16_t)(sx/scale), y = (uint16_t)(sy/scale); |
348 | 306 | up20180642 | if(x > W || y > H) continue; |
349 | memcpy(p->sbuf+4*(sx+sy*sW), map+4*(x+y*W), 4); |
||
350 | } |
||
351 | } |
||
352 | } |
||
353 | 211 | up20180642 | int16_t (sprite_get_x)(const sprite_t *p){ return p->x; } |
354 | int16_t (sprite_get_y)(const sprite_t *p){ return p->y; } |
||
355 | 231 | up20180655 | double (sprite_get_angle)(const sprite_t *p){ return p->theta; } |
356 | 216 | up20180642 | uint16_t (sprite_get_w)(const sprite_t *p){ return basic_sprite_get_w(p->bsp); } |
357 | uint16_t (sprite_get_h)(const sprite_t *p){ return basic_sprite_get_h(p->bsp); } |
||
358 | 323 | up20180642 | static void (sprite_src2sbuf)(const sprite_t *p, int16_t x, int16_t y, int16_t *u, int16_t *v){ |
359 | 306 | up20180642 | if(p->theta == 0.0){ |
360 | *u = x - p->x + p->su0; |
||
361 | *v = y - p->y + p->sv0; |
||
362 | }else{
|
||
363 | 321 | up20180642 | double dx = x - p->x;
|
364 | double dy = y - p->y;
|
||
365 | 323 | up20180642 | int16_t du = (int16_t)(dx*p->c - dy*p->s - 0.5f); |
366 | int16_t dv = (int16_t)(dx*p->s + dy*p->c - 0.5f); |
||
367 | 306 | up20180642 | *u = du + p->su0; |
368 | *v = dv + p->sv0; |
||
369 | } |
||
370 | 211 | up20180642 | } |
371 | 323 | up20180642 | static void (sprite_sbuf2src)(const sprite_t *p, int16_t u, int16_t v, int16_t *x, int16_t *y){ |
372 | 306 | up20180642 | int16_t du = u - p->su0; |
373 | int16_t dv = v - p->sv0; |
||
374 | 211 | up20180642 | double dx = du*p->c + dv*p->s;
|
375 | double dy = -du*p->s + dv*p->c;
|
||
376 | 323 | up20180642 | *x = (int16_t)(dx + 0.5 + p->x); |
377 | *y = (int16_t)(dy + 0.5 + p->y); |
||
378 | 211 | up20180642 | } |
379 | 306 | up20180642 | |
380 | 211 | up20180642 | void (sprite_draw)(const sprite_t *p){ |
381 | 323 | up20180642 | const uint16_t sw = (uint16_t)(p->scale*basic_sprite_get_w(p->bsp));
|
382 | const uint16_t sh = (uint16_t)(p->scale*basic_sprite_get_h(p->bsp));
|
||
383 | 211 | up20180642 | int16_t xmin, xmax, ymin, ymax; { |
384 | int16_t x, y; |
||
385 | 323 | up20180642 | sprite_sbuf2src(p, 0 , 0 , &x, &y); |
386 | 211 | up20180642 | xmin = x; xmax = x; ymin = y; ymax = y; |
387 | 323 | up20180642 | sprite_sbuf2src(p, (int16_t)sw, 0 , &x, &y);
|
388 | xmin = min16(x, xmin); xmax = max16(x, xmax); ymin = min16(y, ymin); ymax = max16(y, ymax); |
||
389 | sprite_sbuf2src(p, 0 , (int16_t)sh, &x, &y);
|
||
390 | xmin = min16(x, xmin); xmax = max16(x, xmax); ymin = min16(y, ymin); ymax = max16(y, ymax); |
||
391 | sprite_sbuf2src(p, (int16_t)sw, (int16_t)sh, &x, &y); |
||
392 | xmin = min16(x, xmin); xmax = max16(x, xmax); ymin = min16(y, ymin); ymax = max16(y, ymax); |
||
393 | xmin = max16(xmin-2, 0); xmax = min16(xmax+2, (int16_t)graph_get_XRes()); |
||
394 | ymin = max16(ymin-2, 0); ymax = min16(ymax+2, (int16_t)graph_get_YRes()); |
||
395 | 211 | up20180642 | } |
396 | 250 | up20180655 | const uint16_t bytes_pixel = 3/*graph_get_bytes_pixel()*/; |
397 | 211 | up20180642 | for(int16_t u, v, y = ymin; y < ymax; ++y){
|
398 | 212 | up20180642 | uint8_t *place = video_buf + (xmin + y*graph_get_XRes())*bytes_pixel; |
399 | for(int16_t x = xmin; x < xmax; ++x, place += bytes_pixel){
|
||
400 | 306 | up20180642 | sprite_src2sbuf(p, x, y, &u, &v); |
401 | //u = x; v = y;
|
||
402 | if(0 <= u && u < sw && 0 <= v && v < sh){ |
||
403 | const uint8_t *c_p = p->sbuf+(v*sw+u)*4; |
||
404 | if(*(c_p+3) < ALPHA_THRESHOLD){ //alpha |
||
405 | 212 | up20180642 | memcpy(place, c_p, bytes_pixel); |
406 | 306 | up20180642 | } |
407 | 211 | up20180642 | } |
408 | } |
||
409 | } |
||
410 | } |