Debian Codegraph @

lvgl/src/draw/sw/arm2d/lv_draw_sw_arm2d.h

raw symbols SCIP
1 /**
2 * @file lv_draw_sw_arm2d.h
3 *
4 */
5
6 #ifndef LV_DRAW_SW_ARM2D_H
7 #define LV_DRAW_SW_ARM2D_H
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 /* *INDENT-OFF* */
14
15 /*********************
16 * INCLUDES
17 *********************/
18
19 #include "../../../lv_conf_internal.h"
20 #include "../../../misc/lv_area_private.h"
21 #include "../../../draw/lv_draw_private.h"
22 #include "../../../draw/lv_draw_image_private.h"
23
24 #if LV_USE_DRAW_ARM2D_SYNC
25
26 #define __ARM_2D_IMPL__
27 #include "arm_2d.h"
28 #include "__arm_2d_impl.h"
29
30 #if defined(__IS_COMPILER_ARM_COMPILER_5__)
31 #pragma diag_suppress 174,177,188,68,513,144,1296
32 #elif defined(__IS_COMPILER_IAR__)
33 #pragma diag_suppress=Pa093
34 #elif defined(__IS_COMPILER_GCC__)
35 #pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
36 #endif
37
38 /*********************
39 * DEFINES
40 *********************/
41 #ifndef LV_DRAW_SW_RGB565_SWAP
42 #define LV_DRAW_SW_RGB565_SWAP(__buf_ptr, __buf_size_px) \
43 lv_draw_sw_rgb565_swap_helium((__buf_ptr), (__buf_size_px))
44 #endif
45
46 #ifndef LV_DRAW_SW_IMAGE
47 #define LV_DRAW_SW_IMAGE(__transformed, \
48 __cf, \
49 __src_buf, \
50 __img_coords, \
51 __src_stride, \
52 __blend_area, \
53 __draw_task, \
54 __draw_dsc) \
55 lv_draw_sw_image_helium( (__transformed), \
56 (__cf), \
57 (uint8_t *)(__src_buf), \
58 (__img_coords), \
59 (__src_stride), \
60 (__blend_area), \
61 (__draw_task), \
62 (__draw_dsc))
63 #endif
64
65 #ifndef LV_DRAW_SW_RGB565_RECOLOR
66 #define LV_DRAW_SW_RGB565_RECOLOR(__src_buf, __blend_area, __color, __opa) \
67 lv_draw_sw_image_recolor_rgb565( (__src_buf), \
68 &(__blend_area), \
69 (__color), \
70 (__opa))
71 #endif
72
73 #ifndef LV_DRAW_SW_RGB888_RECOLOR
74 #define LV_DRAW_SW_RGB888_RECOLOR( __src_buf, \
75 __blend_area, \
76 __color, \
77 __opa, \
78 __cf) \
79 lv_draw_sw_image_recolor_rgb888( (__src_buf), \
80 &(__blend_area), \
81 (__color), \
82 (__opa), \
83 (__cf))
84 #endif
85
86 /**********************
87 * TYPEDEFS
88 **********************/
89
90 /**********************
91 * GLOBAL PROTOTYPES
92 **********************/
93 extern void arm_2d_helper_swap_rgb16(uint16_t * phwBuffer, uint32_t wCount);
94
95 /**********************
96 * MACROS
97 **********************/
98
99 #define __RECOLOUR_BEGIN() \
100 do { \
101 lv_color_t *rgb_tmp_buf = NULL; \
102 if(draw_dsc->recolor_opa > LV_OPA_MIN) { \
103 if(LV_COLOR_FORMAT_RGB565 == des_cf) { \
104 rgb_tmp_buf \
105 = lv_malloc(src_w * src_h * sizeof(uint16_t)); \
106 if (NULL == rgb_tmp_buf) { \
107 LV_LOG_WARN( \
108 "Failed to allocate memory for accelerating recolor, " \
109 "use normal route instead."); \
110 break; \
111 } \
112 lv_memcpy( rgb_tmp_buf, \
113 src_buf, \
114 src_w * src_h * sizeof(uint16_t)); \
115 arm_2d_size_t copy_size = { \
116 .iWidth = src_w, \
117 .iHeight = src_h, \
118 }; \
119 /* apply re-color */ \
120 __arm_2d_impl_rgb565_colour_filling_with_opacity( \
121 (uint16_t *)rgb_tmp_buf, \
122 src_w, \
123 &copy_size, \
124 lv_color_to_u16(draw_dsc->recolor), \
125 draw_dsc->recolor_opa); \
126 \
127 /* replace src_buf for the following operation */ \
128 src_buf = (const uint8_t *)rgb_tmp_buf; \
129 } \
130 else if(LV_COLOR_FORMAT_XRGB8888 == des_cf) { \
131 rgb_tmp_buf \
132 = lv_malloc(src_w * src_h * sizeof(uint32_t)); \
133 if (NULL == rgb_tmp_buf) { \
134 LV_LOG_WARN( \
135 "Failed to allocate memory for accelerating recolor, " \
136 "use normal route instead."); \
137 break; \
138 } \
139 lv_memcpy( rgb_tmp_buf, \
140 src_buf, \
141 src_w * src_h * sizeof(uint32_t)); \
142 arm_2d_size_t copy_size = { \
143 .iWidth = src_w, \
144 .iHeight = src_h, \
145 }; \
146 /* apply re-color */ \
147 __arm_2d_impl_cccn888_colour_filling_with_opacity( \
148 (uint32_t *)rgb_tmp_buf, \
149 src_w, \
150 &copy_size, \
151 lv_color_to_u32(draw_dsc->recolor), \
152 draw_dsc->recolor_opa); \
153 \
154 /* replace src_buf for the following operation */ \
155 src_buf = (const uint8_t *)rgb_tmp_buf; \
156 } \
157 } \
158 do {
159
160 #define __RECOLOUR_END() \
161 } while(0); \
162 if (NULL != rgb_tmp_buf) { \
163 lv_free(rgb_tmp_buf); \
164 } \
165 } while(0);
166
167 static inline lv_result_t lv_draw_sw_rgb565_swap_helium(void * buf, uint32_t buf_size_px)
168 {
169 arm_2d_helper_swap_rgb16((uint16_t *)buf, buf_size_px);
170 return LV_RESULT_OK;
171 }
172
173 static inline lv_result_t lv_draw_sw_image_helium(
174 bool is_transform,
175 lv_color_format_t src_cf,
176 const uint8_t *src_buf,
177 const lv_area_t * coords,
178 int32_t src_stride,
179 const lv_area_t * des_area,
180 lv_draw_task_t * t,
181 const lv_draw_image_dsc_t * draw_dsc)
182 {
183 lv_result_t result = LV_RESULT_INVALID;
184 lv_layer_t * layer = t->target_layer;
185 lv_color_format_t des_cf = layer->color_format;
186 static bool arm_2d_initialized = false;
187
188 if (!arm_2d_initialized) {
189 arm_2d_initialized = true;
190 arm_2d_init();
191 }
192
193 do {
194 if (!is_transform) {
195 break;
196 }
197 #if ARM_2D_VERSION < 10202ul
198 if(draw_dsc->scale_x != draw_dsc->scale_y) {
199 break;
200 }
201 #endif
202 /* filter the unsupported colour format combination */
203 if((LV_COLOR_FORMAT_RGB565 == des_cf)
204 && !( (LV_COLOR_FORMAT_RGB565 == src_cf)
205 || (LV_COLOR_FORMAT_RGB565A8 == src_cf)
206 #if __ARM_2D_CFG_SUPPORT_CCCA8888_IMPLICIT_CONVERSION__ && ARM_2D_VERSION > 10201ul
207 || (LV_COLOR_FORMAT_ARGB8888 == src_cf)
208 || (LV_COLOR_FORMAT_XRGB8888 == src_cf)
209 #endif
210 || (LV_COLOR_FORMAT_A8 == src_cf))) {
211 break;
212 }
213 #if ARM_2D_VERSION > 10201ul
214 if((LV_COLOR_FORMAT_XRGB8888 == des_cf)
215 && !( (LV_COLOR_FORMAT_ARGB8888 == src_cf)
216 || (LV_COLOR_FORMAT_XRGB8888 == src_cf)
217 || (LV_COLOR_FORMAT_A8 == src_cf))) {
218 break;
219 }
220 #else
221 if((LV_COLOR_FORMAT_XRGB8888 == des_cf)
222 || (LV_COLOR_FORMAT_RGB888 == des_cf)
223 || (LV_COLOR_FORMAT_ARGB8888 == des_cf)) {
224 break;
225 }
226 #endif
227
228 /* ------------- prepare parameters for arm-2d APIs - BEGIN --------- */
229
230 lv_area_t blend_area;
231 if(!lv_area_intersect(&blend_area, des_area, &t->clip_area)) {
232 break;
233 }
234
235 int32_t src_w = lv_area_get_width(coords);
236 int32_t src_h = lv_area_get_height(coords);
237
238 arm_2d_size_t src_size = {
239 .iWidth = (int16_t)src_w,
240 .iHeight = (int16_t)src_h,
241 };
242
243 // arm_2d_size_t des_size;
244
245 // do{
246 // int32_t des_w = lv_area_get_width(&blend_area);
247 // int32_t des_h = lv_area_get_height(&blend_area);
248
249 // LV_ASSERT(des_w <= INT16_MAX);
250 // LV_ASSERT(des_h <= INT16_MAX);
251
252 // des_size.iWidth = (int16_t)des_w;
253 // des_size.iHeight = (int16_t)des_h;
254 // } while(0);
255 //
256 // arm_2d_size_t copy_size = {
257 // .iWidth = MIN(des_size.iWidth, src_size.iWidth),
258 // .iHeight = MIN(des_size.iHeight, src_size.iHeight),
259 // };
260 //
261 // int32_t des_stride = lv_draw_buf_width_to_stride(
262 // lv_area_get_width(&layer->buf_area),
263 // des_cf);
264 // uint8_t *des_buf_moved = (uint8_t *)lv_draw_layer_go_to_xy(
265 // layer,
266 // blend_area.x1 - layer->buf_area.x1,
267 // blend_area.y1 - layer->buf_area.y1);
268 uint8_t *des_buf = (uint8_t *)lv_draw_layer_go_to_xy(layer, 0, 0);
269 uint8_t opa = draw_dsc->opa;
270
271 /* ------------- prepare parameters for arm-2d APIs - END ----------- */
272 __RECOLOUR_BEGIN()
273
274 static arm_2d_tile_t target_tile_origin;
275 static arm_2d_tile_t target_tile;
276 arm_2d_region_t clip_region;
277 static arm_2d_region_t target_region;
278
279 target_region = (arm_2d_region_t) {
280 .tLocation = {
281 .iX = (int16_t)(coords->x1 - t->clip_area.x1),
282 .iY = (int16_t)(coords->y1 - t->clip_area.y1),
283 },
284 .tSize = src_size,
285 };
286
287 target_tile_origin = (arm_2d_tile_t) {
288 .tRegion = {
289 .tSize = {
290 .iWidth = (int16_t)lv_area_get_width(&layer->buf_area),
291 .iHeight = (int16_t)lv_area_get_height(&layer->buf_area),
292 },
293 },
294 .tInfo = {
295 .bIsRoot = true,
296 },
297 .phwBuffer = (uint16_t *)des_buf,
298 };
299
300 clip_region = (arm_2d_region_t) {
301 .tLocation = {
302 .iX = (int16_t)(t->clip_area.x1 - layer->buf_area.x1),
303 .iY = (int16_t)(t->clip_area.y1 - layer->buf_area.y1),
304 },
305 .tSize = {
306 .iWidth = (int16_t)lv_area_get_width(&t->clip_area),
307 .iHeight = (int16_t)lv_area_get_height(&t->clip_area),
308 },
309 };
310
311 arm_2d_tile_generate_child(&target_tile_origin,
312 &clip_region,
313 &target_tile,
314 false);
315
316 static arm_2d_tile_t source_tile;
317
318 source_tile = (arm_2d_tile_t) {
319 .tRegion = {
320 .tSize = {
321 .iWidth = (int16_t)src_w,
322 .iHeight = (int16_t)src_h,
323 },
324 },
325 .tInfo = {
326 .bIsRoot = true,
327 },
328 .pchBuffer = (uint8_t *)src_buf,
329 };
330
331 #if ARM_2D_VERSION > 10201ul
332 static const bool bIsNewFrame = true;
333 arm_2d_point_float_t source_center, target_center;
334 source_center.fX = draw_dsc->pivot.x;
335 source_center.fY = draw_dsc->pivot.y;
336 target_center.fX = target_region.tLocation.iX + draw_dsc->pivot.x;
337 target_center.fY = target_region.tLocation.iY + draw_dsc->pivot.y;
338 #else
339 static arm_2d_location_t source_center, target_center;
340 source_center.iX = draw_dsc->pivot.x;
341 source_center.iY = draw_dsc->pivot.y;
342 target_center = target_region.tLocation;
343 target_center.iX += draw_dsc->pivot.x;
344 target_center.iY += draw_dsc->pivot.y;
345 #endif
346 if(LV_COLOR_FORMAT_A8 == src_cf) {
347
348 source_tile.tInfo.bHasEnforcedColour = true;
349 source_tile.tInfo.tColourInfo.chScheme = ARM_2D_COLOUR_GRAY8;
350
351 if(LV_COLOR_FORMAT_RGB565 == des_cf) {
352
353 #if ARM_2D_VERSION > 10201ul
354 arm_2dp_rgb565_fill_colour_with_mask_opacity_and_transform_xy(
355 NULL,
356 &source_tile,
357 &target_tile,
358 NULL,
359 source_center,
360 ARM_2D_ANGLE((draw_dsc->rotation / 10.0f)),
361 draw_dsc->scale_x / 256.0f,
362 draw_dsc->scale_y / 256.0f,
363 lv_color_to_u16(draw_dsc->recolor),
364 opa,
365 &target_center
366 );
367 #else
368 arm_2d_rgb565_fill_colour_with_mask_opacity_and_transform(
369 &source_tile,
370 &target_tile,
371 NULL,
372 source_center,
373 ARM_2D_ANGLE((draw_dsc->rotation / 10.0f)),
374 draw_dsc->scale_x / 256.0f,
375 lv_color_to_u16(draw_dsc->recolor),
376 opa,
377 &target_center
378 );
379 #endif
380 }
381 else if(LV_COLOR_FORMAT_XRGB8888 == des_cf) {
382 #if ARM_2D_VERSION > 10201ul
383
384 arm_2dp_cccn888_fill_colour_with_mask_opacity_and_transform_xy(
385 NULL,
386 &source_tile,
387 &target_tile,
388 NULL,
389 source_center,
390 ARM_2D_ANGLE((draw_dsc->rotation / 10.0f)),
391 draw_dsc->scale_x / 256.0f,
392 draw_dsc->scale_y / 256.0f,
393 lv_color_to_int(draw_dsc->recolor),
394 opa,
395 &target_center
396 );
397
398 #else
399 arm_2d_cccn888_fill_colour_with_mask_opacity_and_transform(
400 &source_tile,
401 &target_tile,
402 NULL,
403 source_center,
404 ARM_2D_ANGLE((draw_dsc->rotation / 10.0f)),
405 draw_dsc->scale_x / 256.0f,
406 lv_color_to_int(draw_dsc->recolor),
407 opa,
408 &target_center
409 );
410 #endif
411 }
412 else {
413 break;
414 }
415
416 }
417 else if(LV_COLOR_FORMAT_RGB565A8 == src_cf) {
418 LV_ASSERT(LV_COLOR_FORMAT_RGB565 == des_cf);
419
420 /* mask_buf = src_buf + src_stride * src_w / header->w * src_h; */
421 const uint8_t *mask_buf = src_buf + src_stride * src_h;
422 int32_t mask_stride = src_stride / 2;
423
424 static arm_2d_tile_t mask_tile;
425 mask_tile = source_tile;
426
427 mask_tile.tInfo.bHasEnforcedColour = true;
428 mask_tile.tInfo.tColourInfo.chScheme = ARM_2D_COLOUR_GRAY8;
429 mask_tile.pchBuffer = (uint8_t *)mask_buf;
430
431 #if ARM_2D_VERSION > 10201ul
432
433 arm_2dp_rgb565_tile_transform_xy_with_src_mask_and_opacity(
434 NULL,
435 &source_tile,
436 &mask_tile,
437 &target_tile,
438 NULL,
439 source_center,
440 ARM_2D_ANGLE((draw_dsc->rotation / 10.0f)),
441 draw_dsc->scale_x / 256.0f,
442 draw_dsc->scale_y / 256.0f,
443 opa,
444 &target_center
445 );
446
447 #else
448 if(opa >= LV_OPA_MAX) {
449 arm_2d_rgb565_tile_transform_with_src_mask(
450 &source_tile,
451 &mask_tile,
452 &target_tile,
453 NULL,
454 source_center,
455 ARM_2D_ANGLE((draw_dsc->rotation / 10.0f)),
456 draw_dsc->scale_x / 256.0f,
457 &target_center
458 );
459 }
460 else {
461 arm_2d_rgb565_tile_transform_with_src_mask_and_opacity(
462 &source_tile,
463 &mask_tile,
464 &target_tile,
465 NULL,
466 source_center,
467 ARM_2D_ANGLE((draw_dsc->rotation / 10.0f)),
468 draw_dsc->scale_x / 256.0f,
469 opa,
470 &target_center
471 );
472 }
473 #endif
474 }
475 else if(LV_COLOR_FORMAT_RGB565 == src_cf) {
476 LV_ASSERT(LV_COLOR_FORMAT_RGB565 == des_cf);
477
478 #if ARM_2D_VERSION > 10201ul
479
480 arm_2dp_rgb565_tile_transform_xy_only_with_opacity(
481 NULL,
482 &source_tile,
483 &target_tile,
484 NULL,
485 source_center,
486 ARM_2D_ANGLE((draw_dsc->rotation / 10.0f)),
487 draw_dsc->scale_x / 256.0f,
488 draw_dsc->scale_y / 256.0f,
489 opa,
490 &target_center
491 );
492
493 #else
494 if(opa >= LV_OPA_MAX) {
495 #if ARM_2D_VERSION >= 10106
496 arm_2d_rgb565_tile_transform_only(
497 &source_tile,
498 &target_tile,
499 NULL,
500 source_center,
501 ARM_2D_ANGLE((draw_dsc->rotation / 10.0f)),
502 draw_dsc->scale_x / 256.0f,
503 &target_center);
504 #else
505
506 arm_2dp_rgb565_tile_transform_only_prepare(
507 NULL,
508 &source_tile,
509 source_center,
510 ARM_2D_ANGLE((draw_dsc->rotation / 10.0f)),
511 (float)(draw_dsc->scale_x / 256.0f));
512
513 arm_2dp_tile_transform(NULL,
514 &target_tile,
515 NULL,
516 &target_center);
517 #endif
518 }
519 else {
520 arm_2d_rgb565_tile_transform_only_with_opacity(
521 &source_tile,
522 &target_tile,
523 NULL,
524 source_center,
525 ARM_2D_ANGLE((draw_dsc->rotation / 10.0f)),
526 draw_dsc->scale_x / 256.0f,
527 opa,
528 &target_center
529 );
530 }
531 #endif
532 }
533 #if ARM_2D_VERSION > 10201ul
534 else if(LV_COLOR_FORMAT_ARGB8888 == src_cf) {
535 if (LV_COLOR_FORMAT_XRGB8888 == des_cf) {
536 source_tile.tInfo.bHasEnforcedColour = true;
537 source_tile.tInfo.tColourInfo.chScheme = ARM_2D_COLOUR_CCCA8888;
538
539 arm_2dp_cccn888_tile_transform_xy_only_with_opacity(
540 NULL,
541 &source_tile,
542 &target_tile,
543 NULL,
544 source_center,
545 ARM_2D_ANGLE((draw_dsc->rotation / 10.0f)),
546 draw_dsc->scale_x / 256.0f,
547 draw_dsc->scale_y / 256.0f,
548 opa,
549 &target_center
550 );
551 }
552 else if(LV_COLOR_FORMAT_RGB565 == des_cf) {
553 source_tile.tInfo.bHasEnforcedColour = true;
554 source_tile.tInfo.tColourInfo.chScheme = ARM_2D_COLOUR_CCCA8888;
555
556 arm_2dp_rgb565_tile_transform_xy_only_with_opacity(
557 NULL,
558 &source_tile,
559 &target_tile,
560 NULL,
561 source_center,
562 ARM_2D_ANGLE((draw_dsc->rotation / 10.0f)),
563 draw_dsc->scale_x / 256.0f,
564 draw_dsc->scale_y / 256.0f,
565 opa,
566 &target_center
567 );
568 }
569 }
570 else if(LV_COLOR_FORMAT_XRGB8888 == src_cf) {
571 if(LV_COLOR_FORMAT_XRGB8888 == des_cf) {
572 arm_2dp_cccn888_tile_transform_xy_only_with_opacity(
573 NULL,
574 &source_tile,
575 &target_tile,
576 NULL,
577 source_center,
578 ARM_2D_ANGLE((draw_dsc->rotation / 10.0f)),
579 draw_dsc->scale_x / 256.0f,
580 draw_dsc->scale_y / 256.0f,
581 opa,
582 &target_center
583 );
584 }
585 else if(LV_COLOR_FORMAT_RGB565 == des_cf) {
586
587 source_tile.tInfo.bHasEnforcedColour = true;
588 source_tile.tInfo.tColourInfo.chScheme = ARM_2D_COLOUR_CCCA8888;
589
590 arm_2dp_rgb565_tile_transform_xy_only_with_opacity(
591 NULL,
592 &source_tile,
593 &target_tile,
594 NULL,
595 source_center,
596 ARM_2D_ANGLE((draw_dsc->rotation / 10.0f)),
597 draw_dsc->scale_x / 256.0f,
598 draw_dsc->scale_y / 256.0f,
599 opa,
600 &target_center
601 );
602
603 }
604 #endif
605 }
606 else {
607 break;
608 }
609
610 result = LV_RESULT_OK;
611
612 __RECOLOUR_END()
613 } while(0);
614
615 return result;
616 }
617
618 static inline lv_result_t lv_draw_sw_image_recolor_rgb565(
619 const uint8_t *src_buf,
620 const lv_area_t * blend_area,
621 lv_color_t color,
622 lv_opa_t opa)
623 {
624 int32_t src_w = lv_area_get_width(blend_area);
625 int32_t src_h = lv_area_get_height(blend_area);
626
627 arm_2d_size_t copy_size = {
628 .iWidth = (int16_t)src_w,
629 .iHeight = (int16_t)src_h,
630 };
631
632 __arm_2d_impl_rgb565_colour_filling_with_opacity(
633 (uint16_t *)src_buf,
634 src_w,
635 &copy_size,
636 lv_color_to_u16(color),
637 opa);
638
639 return LV_RESULT_OK;
640 }
641
642 static inline lv_result_t lv_draw_sw_image_recolor_rgb888(
643 const uint8_t *src_buf,
644 const lv_area_t * blend_area,
645 lv_color_t color,
646 lv_opa_t opa,
647 lv_color_format_t src_cf)
648 {
649 if(LV_COLOR_FORMAT_XRGB8888 != src_cf) {
650 return LV_RESULT_INVALID;
651 }
652
653 int32_t src_w = lv_area_get_width(blend_area);
654 int32_t src_h = lv_area_get_height(blend_area);
655
656 arm_2d_size_t copy_size = {
657 .iWidth = (int16_t)src_w,
658 .iHeight = (int16_t)src_h,
659 };
660
661 __arm_2d_impl_cccn888_colour_filling_with_opacity(
662 (uint32_t *)src_buf,
663 src_w,
664 &copy_size,
665 lv_color_to_u32(color),
666 opa);
667
668 return LV_RESULT_OK;
669 }
670
671 #endif /* LV_USE_DRAW_ARM2D_SYNC */
672
673 /* *INDENT-ON* */
674
675 #ifdef __cplusplus
676 } /*extern "C"*/
677 #endif
678
679 #endif /*LV_DRAW_SW_ARM2D_H */