SAIFIINDUSTRIES commited on
Commit
649faa5
·
verified ·
1 Parent(s): b5dc21c

Add Repo: Floatkyun_Ultra-Vision (part 3)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_draw_transform.c +54 -0
  2. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_draw_transform.h +44 -0
  3. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_draw_triangle.c +52 -0
  4. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_draw_triangle.h +42 -0
  5. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_img_buf.c +392 -0
  6. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_img_buf.h +249 -0
  7. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_img_cache.c +215 -0
  8. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_img_cache.h +78 -0
  9. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_img_decoder.c +730 -0
  10. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_img_decoder.h +274 -0
  11. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/pxp/lv_draw_pxp.c +275 -0
  12. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/pxp/lv_draw_pxp.h +72 -0
  13. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/pxp/lv_draw_pxp_blend.c +573 -0
  14. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/pxp/lv_draw_pxp_blend.h +130 -0
  15. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/pxp/lv_gpu_nxp_pxp.c +138 -0
  16. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/pxp/lv_gpu_nxp_pxp.h +166 -0
  17. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/pxp/lv_gpu_nxp_pxp_osa.c +180 -0
  18. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/pxp/lv_gpu_nxp_pxp_osa.h +78 -0
  19. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite.c +557 -0
  20. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite.h +72 -0
  21. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite_arc.c +679 -0
  22. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite_arc.h +83 -0
  23. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite_blend.c +635 -0
  24. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite_blend.h +168 -0
  25. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite_line.c +142 -0
  26. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite_line.h +83 -0
  27. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite_rect.c +459 -0
  28. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite_rect.h +97 -0
  29. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_vglite_buf.c +141 -0
  30. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_vglite_buf.h +124 -0
  31. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_vglite_utils.c +149 -0
  32. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_vglite_utils.h +200 -0
  33. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/renesas/lv_gpu_d2_draw_label.c +292 -0
  34. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/renesas/lv_gpu_d2_ra6m3.c +742 -0
  35. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/renesas/lv_gpu_d2_ra6m3.h +56 -0
  36. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/README.md +28 -0
  37. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl.c +103 -0
  38. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl.h +96 -0
  39. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_arc.c +245 -0
  40. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_bg.c +106 -0
  41. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_composite.c +279 -0
  42. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_composite.h +84 -0
  43. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_img.c +499 -0
  44. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_img.h +86 -0
  45. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_label.c +189 -0
  46. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_layer.c +147 -0
  47. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_layer.h +56 -0
  48. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_line.c +157 -0
  49. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_mask.c +84 -0
  50. Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_mask.h +51 -0
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_draw_transform.c ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_transform.c
3
+ *
4
+ */
5
+
6
+ /*********************
7
+ * INCLUDES
8
+ *********************/
9
+ #include "lv_draw.h"
10
+ #include "lv_draw_transform.h"
11
+ #include "../misc/lv_assert.h"
12
+ #include "../misc/lv_area.h"
13
+
14
+ /*********************
15
+ * DEFINES
16
+ *********************/
17
+
18
+ /**********************
19
+ * TYPEDEFS
20
+ **********************/
21
+
22
+ /**********************
23
+ * STATIC PROTOTYPES
24
+ **********************/
25
+
26
+ /**********************
27
+ * STATIC VARIABLES
28
+ **********************/
29
+
30
+ /**********************
31
+ * MACROS
32
+ **********************/
33
+
34
+ /**********************
35
+ * GLOBAL FUNCTIONS
36
+ **********************/
37
+ void lv_draw_transform(lv_draw_ctx_t * draw_ctx, const lv_area_t * dest_area, const void * src_buf, lv_coord_t src_w,
38
+ lv_coord_t src_h,
39
+ lv_coord_t src_stride, const lv_draw_img_dsc_t * draw_dsc, lv_img_cf_t cf, lv_color_t * cbuf, lv_opa_t * abuf)
40
+ {
41
+ LV_ASSERT_NULL(draw_ctx);
42
+ if(draw_ctx->draw_transform == NULL) {
43
+ LV_LOG_WARN("draw_ctx->draw_transform == NULL");
44
+ return;
45
+ }
46
+
47
+ draw_ctx->draw_transform(draw_ctx, dest_area, src_buf, src_w, src_h, src_stride, draw_dsc, cf, cbuf, abuf);
48
+
49
+ }
50
+
51
+
52
+ /**********************
53
+ * STATIC FUNCTIONS
54
+ **********************/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_draw_transform.h ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_transform.h
3
+ *
4
+ */
5
+
6
+ #ifndef LV_DRAW_TRANSFORM_H
7
+ #define LV_DRAW_TRANSFORM_H
8
+
9
+ #ifdef __cplusplus
10
+ extern "C" {
11
+ #endif
12
+
13
+ /*********************
14
+ * INCLUDES
15
+ *********************/
16
+ #include "../lv_conf_internal.h"
17
+ #include "../misc/lv_area.h"
18
+
19
+ /*********************
20
+ * DEFINES
21
+ *********************/
22
+
23
+ /**********************
24
+ * TYPEDEFS
25
+ **********************/
26
+ struct _lv_draw_ctx_t;
27
+
28
+ /**********************
29
+ * GLOBAL PROTOTYPES
30
+ **********************/
31
+
32
+ void lv_draw_transform(struct _lv_draw_ctx_t * draw_ctx, const lv_area_t * dest_area, const void * src_buf,
33
+ lv_coord_t src_w, lv_coord_t src_h,
34
+ lv_coord_t src_stride, const lv_draw_img_dsc_t * draw_dsc, lv_img_cf_t cf, lv_color_t * cbuf, lv_opa_t * abuf);
35
+
36
+ /**********************
37
+ * MACROS
38
+ **********************/
39
+
40
+ #ifdef __cplusplus
41
+ } /*extern "C"*/
42
+ #endif
43
+
44
+ #endif /*LV_DRAW_TRANSFORM_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_draw_triangle.c ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_triangle.c
3
+ *
4
+ */
5
+
6
+ /*********************
7
+ * INCLUDES
8
+ *********************/
9
+ #include "lv_draw.h"
10
+ #include "lv_draw_triangle.h"
11
+ #include "../misc/lv_math.h"
12
+ #include "../misc/lv_mem.h"
13
+
14
+ /*********************
15
+ * DEFINES
16
+ *********************/
17
+
18
+ /**********************
19
+ * TYPEDEFS
20
+ **********************/
21
+
22
+ /**********************
23
+ * STATIC PROTOTYPES
24
+ **********************/
25
+
26
+ /**********************
27
+ * STATIC VARIABLES
28
+ **********************/
29
+
30
+ /**********************
31
+ * MACROS
32
+ **********************/
33
+
34
+ /**********************
35
+ * GLOBAL FUNCTIONS
36
+ **********************/
37
+
38
+ void lv_draw_polygon(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, const lv_point_t points[],
39
+ uint16_t point_cnt)
40
+ {
41
+ draw_ctx->draw_polygon(draw_ctx, draw_dsc, points, point_cnt);
42
+ }
43
+
44
+ void lv_draw_triangle(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, const lv_point_t points[])
45
+ {
46
+
47
+ draw_ctx->draw_polygon(draw_ctx, draw_dsc, points, 3);
48
+ }
49
+
50
+ /**********************
51
+ * STATIC FUNCTIONS
52
+ **********************/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_draw_triangle.h ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_triangle.h
3
+ *
4
+ */
5
+
6
+ #ifndef LV_DRAW_TRIANGLE_H
7
+ #define LV_DRAW_TRIANGLE_H
8
+
9
+ #ifdef __cplusplus
10
+ extern "C" {
11
+ #endif
12
+
13
+ /*********************
14
+ * INCLUDES
15
+ *********************/
16
+ #include "lv_draw_rect.h"
17
+
18
+ /*********************
19
+ * DEFINES
20
+ *********************/
21
+
22
+ /**********************
23
+ * TYPEDEFS
24
+ **********************/
25
+
26
+ /**********************
27
+ * GLOBAL PROTOTYPES
28
+ **********************/
29
+
30
+ void lv_draw_polygon(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, const lv_point_t points[],
31
+ uint16_t point_cnt);
32
+
33
+ void lv_draw_triangle(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, const lv_point_t points[]);
34
+ /**********************
35
+ * MACROS
36
+ **********************/
37
+
38
+ #ifdef __cplusplus
39
+ } /*extern "C"*/
40
+ #endif
41
+
42
+ #endif /*LV_DRAW_TRIANGLE_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_img_buf.c ADDED
@@ -0,0 +1,392 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_img_buf.c
3
+ *
4
+ */
5
+
6
+ /*********************
7
+ * INCLUDES
8
+ *********************/
9
+ #include <stddef.h>
10
+ #include <string.h>
11
+ #include "lv_img_buf.h"
12
+ #include "lv_draw_img.h"
13
+ #include "../misc/lv_math.h"
14
+ #include "../misc/lv_log.h"
15
+ #include "../misc/lv_mem.h"
16
+
17
+ /*********************
18
+ * DEFINES
19
+ *********************/
20
+
21
+ /**********************
22
+ * TYPEDEFS
23
+ **********************/
24
+
25
+ /**********************
26
+ * STATIC PROTOTYPES
27
+ **********************/
28
+
29
+ /**********************
30
+ * STATIC VARIABLES
31
+ **********************/
32
+
33
+ /**********************
34
+ * MACROS
35
+ **********************/
36
+
37
+ /**********************
38
+ * GLOBAL FUNCTIONS
39
+ **********************/
40
+
41
+ lv_color_t lv_img_buf_get_px_color(const lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_color_t color)
42
+ {
43
+ lv_color_t p_color = lv_color_black();
44
+ uint8_t * buf_u8 = (uint8_t *)dsc->data;
45
+
46
+ if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR || dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED ||
47
+ dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA || dsc->header.cf == LV_IMG_CF_RGB565A8) {
48
+ uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3;
49
+ uint32_t px = dsc->header.w * y * px_size + x * px_size;
50
+ lv_memcpy_small(&p_color, &buf_u8[px], sizeof(lv_color_t));
51
+ #if LV_COLOR_SIZE == 32
52
+ p_color.ch.alpha = 0xFF; /*Only the color should be get so use a default alpha value*/
53
+ #endif
54
+ }
55
+ else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) {
56
+ buf_u8 += 4 * 2;
57
+ uint8_t bit = x & 0x7;
58
+ x = x >> 3;
59
+
60
+ /*Get the current pixel.
61
+ *dsc->header.w + 7 means rounding up to 8 because the lines are byte aligned
62
+ *so the possible real width are 8, 16, 24 ...*/
63
+ uint32_t px = ((dsc->header.w + 7) >> 3) * y + x;
64
+ p_color.full = (buf_u8[px] & (1 << (7 - bit))) >> (7 - bit);
65
+ }
66
+ else if(dsc->header.cf == LV_IMG_CF_INDEXED_2BIT) {
67
+ buf_u8 += 4 * 4;
68
+ uint8_t bit = (x & 0x3) * 2;
69
+ x = x >> 2;
70
+
71
+ /*Get the current pixel.
72
+ *dsc->header.w + 3 means rounding up to 4 because the lines are byte aligned
73
+ *so the possible real width are 4, 8, 12 ...*/
74
+ uint32_t px = ((dsc->header.w + 3) >> 2) * y + x;
75
+ p_color.full = (buf_u8[px] & (3 << (6 - bit))) >> (6 - bit);
76
+ }
77
+ else if(dsc->header.cf == LV_IMG_CF_INDEXED_4BIT) {
78
+ buf_u8 += 4 * 16;
79
+ uint8_t bit = (x & 0x1) * 4;
80
+ x = x >> 1;
81
+
82
+ /*Get the current pixel.
83
+ *dsc->header.w + 1 means rounding up to 2 because the lines are byte aligned
84
+ *so the possible real width are 2, 4, 6 ...*/
85
+ uint32_t px = ((dsc->header.w + 1) >> 1) * y + x;
86
+ p_color.full = (buf_u8[px] & (0xF << (4 - bit))) >> (4 - bit);
87
+ }
88
+ else if(dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) {
89
+ buf_u8 += 4 * 256;
90
+ uint32_t px = dsc->header.w * y + x;
91
+ p_color.full = buf_u8[px];
92
+ }
93
+ else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT || dsc->header.cf == LV_IMG_CF_ALPHA_2BIT ||
94
+ dsc->header.cf == LV_IMG_CF_ALPHA_4BIT || dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) {
95
+ p_color = color;
96
+ }
97
+ return p_color;
98
+ }
99
+
100
+ lv_opa_t lv_img_buf_get_px_alpha(const lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y)
101
+ {
102
+ uint8_t * buf_u8 = (uint8_t *)dsc->data;
103
+
104
+ if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) {
105
+ uint32_t px = dsc->header.w * y * LV_IMG_PX_SIZE_ALPHA_BYTE + x * LV_IMG_PX_SIZE_ALPHA_BYTE;
106
+ return buf_u8[px + LV_IMG_PX_SIZE_ALPHA_BYTE - 1];
107
+ }
108
+ else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT) {
109
+ uint8_t bit = x & 0x7;
110
+ x = x >> 3;
111
+
112
+ /*Get the current pixel.
113
+ *dsc->header.w + 7 means rounding up to 8 because the lines are byte aligned
114
+ *so the possible real width are 8 ,16, 24 ...*/
115
+ uint32_t px = ((dsc->header.w + 7) >> 3) * y + x;
116
+ uint8_t px_opa = (buf_u8[px] & (1 << (7 - bit))) >> (7 - bit);
117
+ return px_opa ? LV_OPA_TRANSP : LV_OPA_COVER;
118
+ }
119
+ else if(dsc->header.cf == LV_IMG_CF_ALPHA_2BIT) {
120
+ const uint8_t opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/
121
+
122
+ uint8_t bit = (x & 0x3) * 2;
123
+ x = x >> 2;
124
+
125
+ /*Get the current pixel.
126
+ *dsc->header.w + 4 means rounding up to 8 because the lines are byte aligned
127
+ *so the possible real width are 4 ,8, 12 ...*/
128
+ uint32_t px = ((dsc->header.w + 3) >> 2) * y + x;
129
+ uint8_t px_opa = (buf_u8[px] & (3 << (6 - bit))) >> (6 - bit);
130
+ return opa_table[px_opa];
131
+ }
132
+ else if(dsc->header.cf == LV_IMG_CF_ALPHA_4BIT) {
133
+ const uint8_t opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/
134
+ 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255
135
+ };
136
+
137
+ uint8_t bit = (x & 0x1) * 4;
138
+ x = x >> 1;
139
+
140
+ /*Get the current pixel.
141
+ *dsc->header.w + 1 means rounding up to 8 because the lines are byte aligned
142
+ *so the possible real width are 2 ,4, 6 ...*/
143
+ uint32_t px = ((dsc->header.w + 1) >> 1) * y + x;
144
+ uint8_t px_opa = (buf_u8[px] & (0xF << (4 - bit))) >> (4 - bit);
145
+ return opa_table[px_opa];
146
+ }
147
+ else if(dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) {
148
+ uint32_t px = dsc->header.w * y + x;
149
+ return buf_u8[px];
150
+ }
151
+
152
+ return LV_OPA_COVER;
153
+ }
154
+
155
+ void lv_img_buf_set_px_alpha(const lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_opa_t opa)
156
+ {
157
+ uint8_t * buf_u8 = (uint8_t *)dsc->data;
158
+
159
+ if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) {
160
+ uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3;
161
+ uint32_t px = dsc->header.w * y * px_size + x * px_size;
162
+ buf_u8[px + px_size - 1] = opa;
163
+ }
164
+ else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT) {
165
+ opa = opa >> 7; /*opa -> [0,1]*/
166
+ uint8_t bit = x & 0x7;
167
+ x = x >> 3;
168
+
169
+ /*Get the current pixel.
170
+ *dsc->header.w + 7 means rounding up to 8 because the lines are byte aligned
171
+ *so the possible real width are 8 ,16, 24 ...*/
172
+ uint32_t px = ((dsc->header.w + 7) >> 3) * y + x;
173
+ buf_u8[px] = buf_u8[px] & ~(1 << (7 - bit));
174
+ buf_u8[px] = buf_u8[px] | ((opa & 0x1) << (7 - bit));
175
+ }
176
+ else if(dsc->header.cf == LV_IMG_CF_ALPHA_2BIT) {
177
+ opa = opa >> 6; /*opa -> [0,3]*/
178
+ uint8_t bit = (x & 0x3) * 2;
179
+ x = x >> 2;
180
+
181
+ /*Get the current pixel.
182
+ *dsc->header.w + 4 means rounding up to 8 because the lines are byte aligned
183
+ *so the possible real width are 4 ,8, 12 ...*/
184
+ uint32_t px = ((dsc->header.w + 3) >> 2) * y + x;
185
+ buf_u8[px] = buf_u8[px] & ~(3 << (6 - bit));
186
+ buf_u8[px] = buf_u8[px] | ((opa & 0x3) << (6 - bit));
187
+ }
188
+ else if(dsc->header.cf == LV_IMG_CF_ALPHA_4BIT) {
189
+ opa = opa >> 4; /*opa -> [0,15]*/
190
+ uint8_t bit = (x & 0x1) * 4;
191
+ x = x >> 1;
192
+
193
+ /*Get the current pixel.
194
+ *dsc->header.w + 1 means rounding up to 8 because the lines are byte aligned
195
+ *so the possible real width are 2 ,4, 6 ...*/
196
+ uint32_t px = ((dsc->header.w + 1) >> 1) * y + x;
197
+ buf_u8[px] = buf_u8[px] & ~(0xF << (4 - bit));
198
+ buf_u8[px] = buf_u8[px] | ((opa & 0xF) << (4 - bit));
199
+ }
200
+ else if(dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) {
201
+ uint32_t px = dsc->header.w * y + x;
202
+ buf_u8[px] = opa;
203
+ }
204
+ }
205
+
206
+ void lv_img_buf_set_px_color(const lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_color_t c)
207
+ {
208
+ uint8_t * buf_u8 = (uint8_t *)dsc->data;
209
+
210
+ if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR || dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) {
211
+ uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3;
212
+ uint32_t px = dsc->header.w * y * px_size + x * px_size;
213
+ lv_memcpy_small(&buf_u8[px], &c, px_size);
214
+ }
215
+ else if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) {
216
+ uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3;
217
+ uint32_t px = dsc->header.w * y * px_size + x * px_size;
218
+ lv_memcpy_small(&buf_u8[px], &c, px_size - 1); /*-1 to not overwrite the alpha value*/
219
+ }
220
+ else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) {
221
+ buf_u8 += sizeof(lv_color32_t) * 2; /*Skip the palette*/
222
+
223
+ uint8_t bit = x & 0x7;
224
+ x = x >> 3;
225
+
226
+ /*Get the current pixel.
227
+ *dsc->header.w + 7 means rounding up to 8 because the lines are byte aligned
228
+ *so the possible real width are 8 ,16, 24 ...*/
229
+ uint32_t px = ((dsc->header.w + 7) >> 3) * y + x;
230
+ buf_u8[px] = buf_u8[px] & ~(1 << (7 - bit));
231
+ buf_u8[px] = buf_u8[px] | ((c.full & 0x1) << (7 - bit));
232
+ }
233
+ else if(dsc->header.cf == LV_IMG_CF_INDEXED_2BIT) {
234
+ buf_u8 += sizeof(lv_color32_t) * 4; /*Skip the palette*/
235
+ uint8_t bit = (x & 0x3) * 2;
236
+ x = x >> 2;
237
+
238
+ /*Get the current pixel.
239
+ *dsc->header.w + 3 means rounding up to 4 because the lines are byte aligned
240
+ *so the possible real width are 4, 8 ,12 ...*/
241
+ uint32_t px = ((dsc->header.w + 3) >> 2) * y + x;
242
+
243
+ buf_u8[px] = buf_u8[px] & ~(3 << (6 - bit));
244
+ buf_u8[px] = buf_u8[px] | ((c.full & 0x3) << (6 - bit));
245
+ }
246
+ else if(dsc->header.cf == LV_IMG_CF_INDEXED_4BIT) {
247
+ buf_u8 += sizeof(lv_color32_t) * 16; /*Skip the palette*/
248
+ uint8_t bit = (x & 0x1) * 4;
249
+ x = x >> 1;
250
+
251
+ /*Get the current pixel.
252
+ *dsc->header.w + 1 means rounding up to 2 because the lines are byte aligned
253
+ *so the possible real width are 2 ,4, 6 ...*/
254
+ uint32_t px = ((dsc->header.w + 1) >> 1) * y + x;
255
+ buf_u8[px] = buf_u8[px] & ~(0xF << (4 - bit));
256
+ buf_u8[px] = buf_u8[px] | ((c.full & 0xF) << (4 - bit));
257
+ }
258
+ else if(dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) {
259
+ buf_u8 += sizeof(lv_color32_t) * 256; /*Skip the palette*/
260
+ uint32_t px = dsc->header.w * y + x;
261
+ buf_u8[px] = c.full;
262
+ }
263
+ }
264
+
265
+ void lv_img_buf_set_palette(const lv_img_dsc_t * dsc, uint8_t id, lv_color_t c)
266
+ {
267
+ if((dsc->header.cf == LV_IMG_CF_ALPHA_1BIT && id > 1) || (dsc->header.cf == LV_IMG_CF_ALPHA_2BIT && id > 3) ||
268
+ (dsc->header.cf == LV_IMG_CF_ALPHA_4BIT && id > 15) || (dsc->header.cf == LV_IMG_CF_ALPHA_8BIT)) {
269
+ LV_LOG_WARN("lv_img_buf_set_px_alpha: invalid 'id'");
270
+ return;
271
+ }
272
+
273
+ lv_color32_t c32;
274
+ c32.full = lv_color_to32(c);
275
+ uint8_t * buf = (uint8_t *)dsc->data;
276
+ lv_memcpy_small(&buf[id * sizeof(c32)], &c32, sizeof(c32));
277
+ }
278
+
279
+ lv_img_dsc_t * lv_img_buf_alloc(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf)
280
+ {
281
+ /*Allocate image descriptor*/
282
+ lv_img_dsc_t * dsc = lv_mem_alloc(sizeof(lv_img_dsc_t));
283
+ if(dsc == NULL)
284
+ return NULL;
285
+
286
+ lv_memset_00(dsc, sizeof(lv_img_dsc_t));
287
+
288
+ /*Get image data size*/
289
+ dsc->data_size = lv_img_buf_get_img_size(w, h, cf);
290
+ if(dsc->data_size == 0) {
291
+ lv_mem_free(dsc);
292
+ return NULL;
293
+ }
294
+
295
+ /*Allocate raw buffer*/
296
+ dsc->data = lv_mem_alloc(dsc->data_size);
297
+ if(dsc->data == NULL) {
298
+ lv_mem_free(dsc);
299
+ return NULL;
300
+ }
301
+ lv_memset_00((uint8_t *)dsc->data, dsc->data_size);
302
+
303
+ /*Fill in header*/
304
+ dsc->header.always_zero = 0;
305
+ dsc->header.w = w;
306
+ dsc->header.h = h;
307
+ dsc->header.cf = cf;
308
+ return dsc;
309
+ }
310
+
311
+ void lv_img_buf_free(lv_img_dsc_t * dsc)
312
+ {
313
+ if(dsc != NULL) {
314
+ if(dsc->data != NULL)
315
+ lv_mem_free((void *)dsc->data);
316
+
317
+ lv_mem_free(dsc);
318
+ }
319
+ }
320
+
321
+ uint32_t lv_img_buf_get_img_size(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf)
322
+ {
323
+ switch(cf) {
324
+ case LV_IMG_CF_TRUE_COLOR:
325
+ return LV_IMG_BUF_SIZE_TRUE_COLOR(w, h);
326
+ case LV_IMG_CF_TRUE_COLOR_ALPHA:
327
+ case LV_IMG_CF_RGB565A8:
328
+ return LV_IMG_BUF_SIZE_TRUE_COLOR_ALPHA(w, h);
329
+ case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED:
330
+ return LV_IMG_BUF_SIZE_TRUE_COLOR_CHROMA_KEYED(w, h);
331
+ case LV_IMG_CF_ALPHA_1BIT:
332
+ return LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h);
333
+ case LV_IMG_CF_ALPHA_2BIT:
334
+ return LV_IMG_BUF_SIZE_ALPHA_2BIT(w, h);
335
+ case LV_IMG_CF_ALPHA_4BIT:
336
+ return LV_IMG_BUF_SIZE_ALPHA_4BIT(w, h);
337
+ case LV_IMG_CF_ALPHA_8BIT:
338
+ return LV_IMG_BUF_SIZE_ALPHA_8BIT(w, h);
339
+ case LV_IMG_CF_INDEXED_1BIT:
340
+ return LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h);
341
+ case LV_IMG_CF_INDEXED_2BIT:
342
+ return LV_IMG_BUF_SIZE_INDEXED_2BIT(w, h);
343
+ case LV_IMG_CF_INDEXED_4BIT:
344
+ return LV_IMG_BUF_SIZE_INDEXED_4BIT(w, h);
345
+ case LV_IMG_CF_INDEXED_8BIT:
346
+ return LV_IMG_BUF_SIZE_INDEXED_8BIT(w, h);
347
+ default:
348
+ return 0;
349
+ }
350
+ }
351
+
352
+ void _lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h, int16_t angle, uint16_t zoom,
353
+ const lv_point_t * pivot)
354
+ {
355
+ #if LV_DRAW_COMPLEX
356
+ if(angle == 0 && zoom == LV_IMG_ZOOM_NONE) {
357
+ res->x1 = 0;
358
+ res->y1 = 0;
359
+ res->x2 = w - 1;
360
+ res->y2 = h - 1;
361
+ return;
362
+ }
363
+
364
+ lv_point_t p[4] = {
365
+ {0, 0},
366
+ {w, 0},
367
+ {0, h},
368
+ {w, h},
369
+ };
370
+ lv_point_transform(&p[0], angle, zoom, pivot);
371
+ lv_point_transform(&p[1], angle, zoom, pivot);
372
+ lv_point_transform(&p[2], angle, zoom, pivot);
373
+ lv_point_transform(&p[3], angle, zoom, pivot);
374
+ res->x1 = LV_MIN4(p[0].x, p[1].x, p[2].x, p[3].x) - 2;
375
+ res->x2 = LV_MAX4(p[0].x, p[1].x, p[2].x, p[3].x) + 2;
376
+ res->y1 = LV_MIN4(p[0].y, p[1].y, p[2].y, p[3].y) - 2;
377
+ res->y2 = LV_MAX4(p[0].y, p[1].y, p[2].y, p[3].y) + 2;
378
+
379
+ #else
380
+ LV_UNUSED(angle);
381
+ LV_UNUSED(zoom);
382
+ LV_UNUSED(pivot);
383
+ res->x1 = 0;
384
+ res->y1 = 0;
385
+ res->x2 = w - 1;
386
+ res->y2 = h - 1;
387
+ #endif
388
+ }
389
+
390
+ /**********************
391
+ * STATIC FUNCTIONS
392
+ **********************/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_img_buf.h ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_img_buf.h
3
+ *
4
+ */
5
+
6
+ #ifndef LV_IMG_BUF_H
7
+ #define LV_IMG_BUF_H
8
+
9
+ #ifdef __cplusplus
10
+ extern "C" {
11
+ #endif
12
+
13
+ /*********************
14
+ * INCLUDES
15
+ *********************/
16
+ #include <stdbool.h>
17
+ #include "../misc/lv_color.h"
18
+ #include "../misc/lv_area.h"
19
+
20
+ /*********************
21
+ * DEFINES
22
+ *********************/
23
+ /*If image pixels contains alpha we need to know how much byte is a pixel*/
24
+ #if LV_COLOR_DEPTH == 1 || LV_COLOR_DEPTH == 8
25
+ #define LV_IMG_PX_SIZE_ALPHA_BYTE 2
26
+ #elif LV_COLOR_DEPTH == 16
27
+ #define LV_IMG_PX_SIZE_ALPHA_BYTE 3
28
+ #elif LV_COLOR_DEPTH == 32
29
+ #define LV_IMG_PX_SIZE_ALPHA_BYTE 4
30
+ #endif
31
+
32
+ #define LV_IMG_BUF_SIZE_TRUE_COLOR(w, h) ((LV_COLOR_SIZE / 8) * w * h)
33
+ #define LV_IMG_BUF_SIZE_TRUE_COLOR_CHROMA_KEYED(w, h) ((LV_COLOR_SIZE / 8) * w * h)
34
+ #define LV_IMG_BUF_SIZE_TRUE_COLOR_ALPHA(w, h) (LV_IMG_PX_SIZE_ALPHA_BYTE * w * h)
35
+
36
+ /*+ 1: to be sure no fractional row*/
37
+ #define LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h) ((((w / 8) + 1) * h))
38
+ #define LV_IMG_BUF_SIZE_ALPHA_2BIT(w, h) ((((w / 4) + 1) * h))
39
+ #define LV_IMG_BUF_SIZE_ALPHA_4BIT(w, h) ((((w / 2) + 1) * h))
40
+ #define LV_IMG_BUF_SIZE_ALPHA_8BIT(w, h) ((w * h))
41
+
42
+ /*4 * X: for palette*/
43
+ #define LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h) (LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h) + 4 * 2)
44
+ #define LV_IMG_BUF_SIZE_INDEXED_2BIT(w, h) (LV_IMG_BUF_SIZE_ALPHA_2BIT(w, h) + 4 * 4)
45
+ #define LV_IMG_BUF_SIZE_INDEXED_4BIT(w, h) (LV_IMG_BUF_SIZE_ALPHA_4BIT(w, h) + 4 * 16)
46
+ #define LV_IMG_BUF_SIZE_INDEXED_8BIT(w, h) (LV_IMG_BUF_SIZE_ALPHA_8BIT(w, h) + 4 * 256)
47
+
48
+ #define _LV_ZOOM_INV_UPSCALE 5
49
+
50
+ /**********************
51
+ * TYPEDEFS
52
+ **********************/
53
+
54
+ /*Image color format*/
55
+ enum {
56
+ LV_IMG_CF_UNKNOWN = 0,
57
+
58
+ LV_IMG_CF_RAW, /**< Contains the file as it is. Needs custom decoder function*/
59
+ LV_IMG_CF_RAW_ALPHA, /**< Contains the file as it is. The image has alpha. Needs custom decoder
60
+ function*/
61
+ LV_IMG_CF_RAW_CHROMA_KEYED, /**< Contains the file as it is. The image is chroma keyed. Needs
62
+ custom decoder function*/
63
+
64
+ LV_IMG_CF_TRUE_COLOR, /**< Color format and depth should match with LV_COLOR settings*/
65
+ LV_IMG_CF_TRUE_COLOR_ALPHA, /**< Same as `LV_IMG_CF_TRUE_COLOR` but every pixel has an alpha byte*/
66
+ LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, /**< Same as `LV_IMG_CF_TRUE_COLOR` but LV_COLOR_TRANSP pixels
67
+ will be transparent*/
68
+
69
+ LV_IMG_CF_INDEXED_1BIT, /**< Can have 2 different colors in a palette (can't be chroma keyed)*/
70
+ LV_IMG_CF_INDEXED_2BIT, /**< Can have 4 different colors in a palette (can't be chroma keyed)*/
71
+ LV_IMG_CF_INDEXED_4BIT, /**< Can have 16 different colors in a palette (can't be chroma keyed)*/
72
+ LV_IMG_CF_INDEXED_8BIT, /**< Can have 256 different colors in a palette (can't be chroma keyed)*/
73
+
74
+ LV_IMG_CF_ALPHA_1BIT, /**< Can have one color and it can be drawn or not*/
75
+ LV_IMG_CF_ALPHA_2BIT, /**< Can have one color but 4 different alpha value*/
76
+ LV_IMG_CF_ALPHA_4BIT, /**< Can have one color but 16 different alpha value*/
77
+ LV_IMG_CF_ALPHA_8BIT, /**< Can have one color but 256 different alpha value*/
78
+
79
+ LV_IMG_CF_RGB888,
80
+ LV_IMG_CF_RGBA8888,
81
+ LV_IMG_CF_RGBX8888,
82
+ LV_IMG_CF_RGB565,
83
+ LV_IMG_CF_RGBA5658,
84
+ LV_IMG_CF_RGB565A8,
85
+
86
+ LV_IMG_CF_RESERVED_15, /**< Reserved for further use.*/
87
+ LV_IMG_CF_RESERVED_16, /**< Reserved for further use.*/
88
+ LV_IMG_CF_RESERVED_17, /**< Reserved for further use.*/
89
+ LV_IMG_CF_RESERVED_18, /**< Reserved for further use.*/
90
+ LV_IMG_CF_RESERVED_19, /**< Reserved for further use.*/
91
+ LV_IMG_CF_RESERVED_20, /**< Reserved for further use.*/
92
+ LV_IMG_CF_RESERVED_21, /**< Reserved for further use.*/
93
+ LV_IMG_CF_RESERVED_22, /**< Reserved for further use.*/
94
+ LV_IMG_CF_RESERVED_23, /**< Reserved for further use.*/
95
+
96
+ LV_IMG_CF_USER_ENCODED_0, /**< User holder encoding format.*/
97
+ LV_IMG_CF_USER_ENCODED_1, /**< User holder encoding format.*/
98
+ LV_IMG_CF_USER_ENCODED_2, /**< User holder encoding format.*/
99
+ LV_IMG_CF_USER_ENCODED_3, /**< User holder encoding format.*/
100
+ LV_IMG_CF_USER_ENCODED_4, /**< User holder encoding format.*/
101
+ LV_IMG_CF_USER_ENCODED_5, /**< User holder encoding format.*/
102
+ LV_IMG_CF_USER_ENCODED_6, /**< User holder encoding format.*/
103
+ LV_IMG_CF_USER_ENCODED_7, /**< User holder encoding format.*/
104
+ };
105
+ typedef uint8_t lv_img_cf_t;
106
+
107
+
108
+ /**
109
+ * The first 8 bit is very important to distinguish the different source types.
110
+ * For more info see `lv_img_get_src_type()` in lv_img.c
111
+ * On big endian systems the order is reversed so cf and always_zero must be at
112
+ * the end of the struct.
113
+ */
114
+ #if LV_BIG_ENDIAN_SYSTEM
115
+ typedef struct {
116
+
117
+ uint32_t h : 11; /*Height of the image map*/
118
+ uint32_t w : 11; /*Width of the image map*/
119
+ uint32_t reserved : 2; /*Reserved to be used later*/
120
+ uint32_t always_zero : 3; /*It the upper bits of the first byte. Always zero to look like a
121
+ non-printable character*/
122
+ uint32_t cf : 5; /*Color format: See `lv_img_color_format_t`*/
123
+
124
+ } lv_img_header_t;
125
+ #else
126
+ typedef struct {
127
+
128
+ uint32_t cf : 5; /*Color format: See `lv_img_color_format_t`*/
129
+ uint32_t always_zero : 3; /*It the upper bits of the first byte. Always zero to look like a
130
+ non-printable character*/
131
+
132
+ uint32_t reserved : 2; /*Reserved to be used later*/
133
+
134
+ uint32_t w : 11; /*Width of the image map*/
135
+ uint32_t h : 11; /*Height of the image map*/
136
+ } lv_img_header_t;
137
+ #endif
138
+
139
+ /** Image header it is compatible with
140
+ * the result from image converter utility*/
141
+ typedef struct {
142
+ lv_img_header_t header; /**< A header describing the basics of the image*/
143
+ uint32_t data_size; /**< Size of the image in bytes*/
144
+ const uint8_t * data; /**< Pointer to the data of the image*/
145
+ } lv_img_dsc_t;
146
+
147
+ /**********************
148
+ * GLOBAL PROTOTYPES
149
+ **********************/
150
+
151
+ /**
152
+ * Allocate an image buffer in RAM
153
+ * @param w width of image
154
+ * @param h height of image
155
+ * @param cf a color format (`LV_IMG_CF_...`)
156
+ * @return an allocated image, or NULL on failure
157
+ */
158
+ lv_img_dsc_t * lv_img_buf_alloc(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf);
159
+
160
+ /**
161
+ * Get the color of an image's pixel
162
+ * @param dsc an image descriptor
163
+ * @param x x coordinate of the point to get
164
+ * @param y x coordinate of the point to get
165
+ * @param color the color of the image. In case of `LV_IMG_CF_ALPHA_1/2/4/8` this color is used.
166
+ * Not used in other cases.
167
+ * @param safe true: check out of bounds
168
+ * @return color of the point
169
+ */
170
+ lv_color_t lv_img_buf_get_px_color(const lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_color_t color);
171
+
172
+ /**
173
+ * Get the alpha value of an image's pixel
174
+ * @param dsc pointer to an image descriptor
175
+ * @param x x coordinate of the point to set
176
+ * @param y x coordinate of the point to set
177
+ * @param safe true: check out of bounds
178
+ * @return alpha value of the point
179
+ */
180
+ lv_opa_t lv_img_buf_get_px_alpha(const lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y);
181
+
182
+ /**
183
+ * Set the color of a pixel of an image. The alpha channel won't be affected.
184
+ * @param dsc pointer to an image descriptor
185
+ * @param x x coordinate of the point to set
186
+ * @param y x coordinate of the point to set
187
+ * @param c color of the point
188
+ * @param safe true: check out of bounds
189
+ */
190
+ void lv_img_buf_set_px_color(const lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_color_t c);
191
+
192
+ /**
193
+ * Set the alpha value of a pixel of an image. The color won't be affected
194
+ * @param dsc pointer to an image descriptor
195
+ * @param x x coordinate of the point to set
196
+ * @param y x coordinate of the point to set
197
+ * @param opa the desired opacity
198
+ * @param safe true: check out of bounds
199
+ */
200
+ void lv_img_buf_set_px_alpha(const lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_opa_t opa);
201
+
202
+ /**
203
+ * Set the palette color of an indexed image. Valid only for `LV_IMG_CF_INDEXED1/2/4/8`
204
+ * @param dsc pointer to an image descriptor
205
+ * @param id the palette color to set:
206
+ * - for `LV_IMG_CF_INDEXED1`: 0..1
207
+ * - for `LV_IMG_CF_INDEXED2`: 0..3
208
+ * - for `LV_IMG_CF_INDEXED4`: 0..15
209
+ * - for `LV_IMG_CF_INDEXED8`: 0..255
210
+ * @param c the color to set
211
+ */
212
+ void lv_img_buf_set_palette(const lv_img_dsc_t * dsc, uint8_t id, lv_color_t c);
213
+
214
+ /**
215
+ * Free an allocated image buffer
216
+ * @param dsc image buffer to free
217
+ */
218
+ void lv_img_buf_free(lv_img_dsc_t * dsc);
219
+
220
+ /**
221
+ * Get the memory consumption of a raw bitmap, given color format and dimensions.
222
+ * @param w width
223
+ * @param h height
224
+ * @param cf color format
225
+ * @return size in bytes
226
+ */
227
+ uint32_t lv_img_buf_get_img_size(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf);
228
+
229
+ /**
230
+ * Get the area of a rectangle if its rotated and scaled
231
+ * @param res store the coordinates here
232
+ * @param w width of the rectangle to transform
233
+ * @param h height of the rectangle to transform
234
+ * @param angle angle of rotation
235
+ * @param zoom zoom, (256 no zoom)
236
+ * @param pivot x,y pivot coordinates of rotation
237
+ */
238
+ void _lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h, int16_t angle, uint16_t zoom,
239
+ const lv_point_t * pivot);
240
+
241
+ /**********************
242
+ * MACROS
243
+ **********************/
244
+
245
+ #ifdef __cplusplus
246
+ } /*extern "C"*/
247
+ #endif
248
+
249
+ #endif /*LV_IMG_BUF_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_img_cache.c ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_img_cache.c
3
+ *
4
+ */
5
+
6
+ /*********************
7
+ * INCLUDES
8
+ *********************/
9
+ #include "../misc/lv_assert.h"
10
+ #include "lv_img_cache.h"
11
+ #include "lv_img_decoder.h"
12
+ #include "lv_draw_img.h"
13
+ #include "../hal/lv_hal_tick.h"
14
+ #include "../misc/lv_gc.h"
15
+
16
+ /*********************
17
+ * DEFINES
18
+ *********************/
19
+ /*Decrement life with this value on every open*/
20
+ #define LV_IMG_CACHE_AGING 1
21
+
22
+ /*Boost life by this factor (multiply time_to_open with this value)*/
23
+ #define LV_IMG_CACHE_LIFE_GAIN 1
24
+
25
+ /*Don't let life to be greater than this limit because it would require a lot of time to
26
+ * "die" from very high values*/
27
+ #define LV_IMG_CACHE_LIFE_LIMIT 1000
28
+
29
+ /**********************
30
+ * TYPEDEFS
31
+ **********************/
32
+
33
+ /**********************
34
+ * STATIC PROTOTYPES
35
+ **********************/
36
+ #if LV_IMG_CACHE_DEF_SIZE
37
+ static bool lv_img_cache_match(const void * src1, const void * src2);
38
+ #endif
39
+
40
+ /**********************
41
+ * STATIC VARIABLES
42
+ **********************/
43
+ #if LV_IMG_CACHE_DEF_SIZE
44
+ static uint16_t entry_cnt;
45
+ #endif
46
+
47
+ /**********************
48
+ * MACROS
49
+ **********************/
50
+
51
+ /**********************
52
+ * GLOBAL FUNCTIONS
53
+ **********************/
54
+
55
+ /**
56
+ * Open an image using the image decoder interface and cache it.
57
+ * The image will be left open meaning if the image decoder open callback allocated memory then it will remain.
58
+ * The image is closed if a new image is opened and the new image takes its place in the cache.
59
+ * @param src source of the image. Path to file or pointer to an `lv_img_dsc_t` variable
60
+ * @param color color The color of the image with `LV_IMG_CF_ALPHA_...`
61
+ * @return pointer to the cache entry or NULL if can open the image
62
+ */
63
+ _lv_img_cache_entry_t * _lv_img_cache_open(const void * src, lv_color_t color, int32_t frame_id)
64
+ {
65
+ /*Is the image cached?*/
66
+ _lv_img_cache_entry_t * cached_src = NULL;
67
+
68
+ #if LV_IMG_CACHE_DEF_SIZE
69
+ if(entry_cnt == 0) {
70
+ LV_LOG_WARN("lv_img_cache_open: the cache size is 0");
71
+ return NULL;
72
+ }
73
+
74
+ _lv_img_cache_entry_t * cache = LV_GC_ROOT(_lv_img_cache_array);
75
+
76
+ /*Decrement all lifes. Make the entries older*/
77
+ uint16_t i;
78
+ for(i = 0; i < entry_cnt; i++) {
79
+ if(cache[i].life > INT32_MIN + LV_IMG_CACHE_AGING) {
80
+ cache[i].life -= LV_IMG_CACHE_AGING;
81
+ }
82
+ }
83
+
84
+ for(i = 0; i < entry_cnt; i++) {
85
+ if(color.full == cache[i].dec_dsc.color.full &&
86
+ frame_id == cache[i].dec_dsc.frame_id &&
87
+ lv_img_cache_match(src, cache[i].dec_dsc.src)) {
88
+ /*If opened increment its life.
89
+ *Image difficult to open should live longer to keep avoid frequent their recaching.
90
+ *Therefore increase `life` with `time_to_open`*/
91
+ cached_src = &cache[i];
92
+ cached_src->life += cached_src->dec_dsc.time_to_open * LV_IMG_CACHE_LIFE_GAIN;
93
+ if(cached_src->life > LV_IMG_CACHE_LIFE_LIMIT) cached_src->life = LV_IMG_CACHE_LIFE_LIMIT;
94
+ LV_LOG_TRACE("image source found in the cache");
95
+ break;
96
+ }
97
+ }
98
+
99
+ /*The image is not cached then cache it now*/
100
+ if(cached_src) return cached_src;
101
+
102
+ /*Find an entry to reuse. Select the entry with the least life*/
103
+ cached_src = &cache[0];
104
+ for(i = 1; i < entry_cnt; i++) {
105
+ if(cache[i].life < cached_src->life) {
106
+ cached_src = &cache[i];
107
+ }
108
+ }
109
+
110
+ /*Close the decoder to reuse if it was opened (has a valid source)*/
111
+ if(cached_src->dec_dsc.src) {
112
+ lv_img_decoder_close(&cached_src->dec_dsc);
113
+ LV_LOG_INFO("image draw: cache miss, close and reuse an entry");
114
+ }
115
+ else {
116
+ LV_LOG_INFO("image draw: cache miss, cached to an empty entry");
117
+ }
118
+ #else
119
+ cached_src = &LV_GC_ROOT(_lv_img_cache_single);
120
+ #endif
121
+ /*Open the image and measure the time to open*/
122
+ uint32_t t_start = lv_tick_get();
123
+ lv_res_t open_res = lv_img_decoder_open(&cached_src->dec_dsc, src, color, frame_id);
124
+ if(open_res == LV_RES_INV) {
125
+ LV_LOG_WARN("Image draw cannot open the image resource");
126
+ lv_memset_00(cached_src, sizeof(_lv_img_cache_entry_t));
127
+ cached_src->life = INT32_MIN; /*Make the empty entry very "weak" to force its us*/
128
+ return NULL;
129
+ }
130
+
131
+ cached_src->life = 0;
132
+
133
+ /*If `time_to_open` was not set in the open function set it here*/
134
+ if(cached_src->dec_dsc.time_to_open == 0) {
135
+ cached_src->dec_dsc.time_to_open = lv_tick_elaps(t_start);
136
+ }
137
+
138
+ if(cached_src->dec_dsc.time_to_open == 0) cached_src->dec_dsc.time_to_open = 1;
139
+
140
+ return cached_src;
141
+ }
142
+
143
+ /**
144
+ * Set the number of images to be cached.
145
+ * More cached images mean more opened image at same time which might mean more memory usage.
146
+ * E.g. if 20 PNG or JPG images are open in the RAM they consume memory while opened in the cache.
147
+ * @param new_entry_cnt number of image to cache
148
+ */
149
+ void lv_img_cache_set_size(uint16_t new_entry_cnt)
150
+ {
151
+ #if LV_IMG_CACHE_DEF_SIZE == 0
152
+ LV_UNUSED(new_entry_cnt);
153
+ LV_LOG_WARN("Can't change cache size because it's disabled by LV_IMG_CACHE_DEF_SIZE = 0");
154
+ #else
155
+ if(LV_GC_ROOT(_lv_img_cache_array) != NULL) {
156
+ /*Clean the cache before free it*/
157
+ lv_img_cache_invalidate_src(NULL);
158
+ lv_mem_free(LV_GC_ROOT(_lv_img_cache_array));
159
+ }
160
+
161
+ /*Reallocate the cache*/
162
+ LV_GC_ROOT(_lv_img_cache_array) = lv_mem_alloc(sizeof(_lv_img_cache_entry_t) * new_entry_cnt);
163
+ LV_ASSERT_MALLOC(LV_GC_ROOT(_lv_img_cache_array));
164
+ if(LV_GC_ROOT(_lv_img_cache_array) == NULL) {
165
+ entry_cnt = 0;
166
+ return;
167
+ }
168
+ entry_cnt = new_entry_cnt;
169
+
170
+ /*Clean the cache*/
171
+ lv_memset_00(LV_GC_ROOT(_lv_img_cache_array), entry_cnt * sizeof(_lv_img_cache_entry_t));
172
+ #endif
173
+ }
174
+
175
+ /**
176
+ * Invalidate an image source in the cache.
177
+ * Useful if the image source is updated therefore it needs to be cached again.
178
+ * @param src an image source path to a file or pointer to an `lv_img_dsc_t` variable.
179
+ */
180
+ void lv_img_cache_invalidate_src(const void * src)
181
+ {
182
+ LV_UNUSED(src);
183
+ #if LV_IMG_CACHE_DEF_SIZE
184
+ _lv_img_cache_entry_t * cache = LV_GC_ROOT(_lv_img_cache_array);
185
+
186
+ uint16_t i;
187
+ for(i = 0; i < entry_cnt; i++) {
188
+ if(src == NULL || lv_img_cache_match(src, cache[i].dec_dsc.src)) {
189
+ if(cache[i].dec_dsc.src != NULL) {
190
+ lv_img_decoder_close(&cache[i].dec_dsc);
191
+ }
192
+
193
+ lv_memset_00(&cache[i], sizeof(_lv_img_cache_entry_t));
194
+ }
195
+ }
196
+ #endif
197
+ }
198
+
199
+ /**********************
200
+ * STATIC FUNCTIONS
201
+ **********************/
202
+
203
+ #if LV_IMG_CACHE_DEF_SIZE
204
+ static bool lv_img_cache_match(const void * src1, const void * src2)
205
+ {
206
+ lv_img_src_t src_type = lv_img_src_get_type(src1);
207
+ if(src_type == LV_IMG_SRC_VARIABLE)
208
+ return src1 == src2;
209
+ if(src_type != LV_IMG_SRC_FILE)
210
+ return false;
211
+ if(lv_img_src_get_type(src2) != LV_IMG_SRC_FILE)
212
+ return false;
213
+ return strcmp(src1, src2) == 0;
214
+ }
215
+ #endif
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_img_cache.h ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_img_cache.h
3
+ *
4
+ */
5
+
6
+ #ifndef LV_IMG_CACHE_H
7
+ #define LV_IMG_CACHE_H
8
+
9
+ #ifdef __cplusplus
10
+ extern "C" {
11
+ #endif
12
+
13
+ /*********************
14
+ * INCLUDES
15
+ *********************/
16
+ #include "lv_img_decoder.h"
17
+
18
+ /*********************
19
+ * DEFINES
20
+ *********************/
21
+
22
+ /**********************
23
+ * TYPEDEFS
24
+ **********************/
25
+
26
+ /**
27
+ * When loading images from the network it can take a long time to download and decode the image.
28
+ *
29
+ * To avoid repeating this heavy load images can be cached.
30
+ */
31
+ typedef struct {
32
+ lv_img_decoder_dsc_t dec_dsc; /**< Image information*/
33
+
34
+ /** Count the cache entries's life. Add `time_to_open` to `life` when the entry is used.
35
+ * Decrement all lifes by one every in every ::lv_img_cache_open.
36
+ * If life == 0 the entry can be reused*/
37
+ int32_t life;
38
+ } _lv_img_cache_entry_t;
39
+
40
+ /**********************
41
+ * GLOBAL PROTOTYPES
42
+ **********************/
43
+
44
+ /**
45
+ * Open an image using the image decoder interface and cache it.
46
+ * The image will be left open meaning if the image decoder open callback allocated memory then it will remain.
47
+ * The image is closed if a new image is opened and the new image takes its place in the cache.
48
+ * @param src source of the image. Path to file or pointer to an `lv_img_dsc_t` variable
49
+ * @param color The color of the image with `LV_IMG_CF_ALPHA_...`
50
+ * @param frame_id the index of the frame. Used only with animated images, set 0 for normal images
51
+ * @return pointer to the cache entry or NULL if can open the image
52
+ */
53
+ _lv_img_cache_entry_t * _lv_img_cache_open(const void * src, lv_color_t color, int32_t frame_id);
54
+
55
+ /**
56
+ * Set the number of images to be cached.
57
+ * More cached images mean more opened image at same time which might mean more memory usage.
58
+ * E.g. if 20 PNG or JPG images are open in the RAM they consume memory while opened in the cache.
59
+ * @param new_entry_cnt number of image to cache
60
+ */
61
+ void lv_img_cache_set_size(uint16_t new_slot_num);
62
+
63
+ /**
64
+ * Invalidate an image source in the cache.
65
+ * Useful if the image source is updated therefore it needs to be cached again.
66
+ * @param src an image source path to a file or pointer to an `lv_img_dsc_t` variable.
67
+ */
68
+ void lv_img_cache_invalidate_src(const void * src);
69
+
70
+ /**********************
71
+ * MACROS
72
+ **********************/
73
+
74
+ #ifdef __cplusplus
75
+ } /*extern "C"*/
76
+ #endif
77
+
78
+ #endif /*LV_IMG_CACHE_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_img_decoder.c ADDED
@@ -0,0 +1,730 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_img_decoder.c
3
+ *
4
+ */
5
+
6
+ /*********************
7
+ * INCLUDES
8
+ *********************/
9
+ #include "lv_img_decoder.h"
10
+ #include "../misc/lv_assert.h"
11
+ #include "../draw/lv_draw_img.h"
12
+ #include "../misc/lv_ll.h"
13
+ #include "../misc/lv_gc.h"
14
+
15
+ /*********************
16
+ * DEFINES
17
+ *********************/
18
+ #define CF_BUILT_IN_FIRST LV_IMG_CF_TRUE_COLOR
19
+ #define CF_BUILT_IN_LAST LV_IMG_CF_RGB565A8
20
+
21
+ /**********************
22
+ * TYPEDEFS
23
+ **********************/
24
+
25
+ typedef struct {
26
+ lv_fs_file_t f;
27
+ lv_color_t * palette;
28
+ lv_opa_t * opa;
29
+ } lv_img_decoder_built_in_data_t;
30
+
31
+ /**********************
32
+ * STATIC PROTOTYPES
33
+ **********************/
34
+ static lv_res_t lv_img_decoder_built_in_line_true_color(lv_img_decoder_dsc_t * dsc, lv_coord_t x, lv_coord_t y,
35
+ lv_coord_t len, uint8_t * buf);
36
+ static lv_res_t lv_img_decoder_built_in_line_alpha(lv_img_decoder_dsc_t * dsc, lv_coord_t x, lv_coord_t y,
37
+ lv_coord_t len, uint8_t * buf);
38
+ static lv_res_t lv_img_decoder_built_in_line_indexed(lv_img_decoder_dsc_t * dsc, lv_coord_t x, lv_coord_t y,
39
+ lv_coord_t len, uint8_t * buf);
40
+
41
+ /**********************
42
+ * STATIC VARIABLES
43
+ **********************/
44
+
45
+ /**********************
46
+ * MACROS
47
+ **********************/
48
+
49
+ /**********************
50
+ * GLOBAL FUNCTIONS
51
+ **********************/
52
+
53
+ /**
54
+ * Initialize the image decoder module
55
+ */
56
+ void _lv_img_decoder_init(void)
57
+ {
58
+ _lv_ll_init(&LV_GC_ROOT(_lv_img_decoder_ll), sizeof(lv_img_decoder_t));
59
+
60
+ lv_img_decoder_t * decoder;
61
+
62
+ /*Create a decoder for the built in color format*/
63
+ decoder = lv_img_decoder_create();
64
+ LV_ASSERT_MALLOC(decoder);
65
+ if(decoder == NULL) {
66
+ LV_LOG_WARN("lv_img_decoder_init: out of memory");
67
+ return;
68
+ }
69
+
70
+ lv_img_decoder_set_info_cb(decoder, lv_img_decoder_built_in_info);
71
+ lv_img_decoder_set_open_cb(decoder, lv_img_decoder_built_in_open);
72
+ lv_img_decoder_set_read_line_cb(decoder, lv_img_decoder_built_in_read_line);
73
+ lv_img_decoder_set_close_cb(decoder, lv_img_decoder_built_in_close);
74
+ }
75
+
76
+ /**
77
+ * Get information about an image.
78
+ * Try the created image decoder one by one. Once one is able to get info that info will be used.
79
+ * @param src the image source. E.g. file name or variable.
80
+ * @param header the image info will be stored here
81
+ * @return LV_RES_OK: success; LV_RES_INV: wasn't able to get info about the image
82
+ */
83
+ lv_res_t lv_img_decoder_get_info(const void * src, lv_img_header_t * header)
84
+ {
85
+ lv_memset_00(header, sizeof(lv_img_header_t));
86
+
87
+ if(src == NULL) return LV_RES_INV;
88
+
89
+ lv_img_src_t src_type = lv_img_src_get_type(src);
90
+ if(src_type == LV_IMG_SRC_VARIABLE) {
91
+ const lv_img_dsc_t * img_dsc = src;
92
+ if(img_dsc->data == NULL) return LV_RES_INV;
93
+ }
94
+
95
+ lv_res_t res = LV_RES_INV;
96
+ lv_img_decoder_t * d;
97
+ _LV_LL_READ(&LV_GC_ROOT(_lv_img_decoder_ll), d) {
98
+ if(d->info_cb) {
99
+ res = d->info_cb(d, src, header);
100
+ if(res == LV_RES_OK) break;
101
+ }
102
+ }
103
+
104
+ return res;
105
+ }
106
+
107
+ lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t * dsc, const void * src, lv_color_t color, int32_t frame_id)
108
+ {
109
+ lv_memset_00(dsc, sizeof(lv_img_decoder_dsc_t));
110
+
111
+ if(src == NULL) return LV_RES_INV;
112
+ lv_img_src_t src_type = lv_img_src_get_type(src);
113
+ if(src_type == LV_IMG_SRC_VARIABLE) {
114
+ const lv_img_dsc_t * img_dsc = src;
115
+ if(img_dsc->data == NULL) return LV_RES_INV;
116
+ }
117
+
118
+ dsc->color = color;
119
+ dsc->src_type = src_type;
120
+ dsc->frame_id = frame_id;
121
+
122
+ if(dsc->src_type == LV_IMG_SRC_FILE) {
123
+ size_t fnlen = strlen(src);
124
+ dsc->src = lv_mem_alloc(fnlen + 1);
125
+ LV_ASSERT_MALLOC(dsc->src);
126
+ if(dsc->src == NULL) {
127
+ LV_LOG_WARN("lv_img_decoder_open: out of memory");
128
+ return LV_RES_INV;
129
+ }
130
+ strcpy((char *)dsc->src, src);
131
+ }
132
+ else {
133
+ dsc->src = src;
134
+ }
135
+
136
+ lv_res_t res = LV_RES_INV;
137
+
138
+ lv_img_decoder_t * decoder;
139
+ _LV_LL_READ(&LV_GC_ROOT(_lv_img_decoder_ll), decoder) {
140
+ /*Info and Open callbacks are required*/
141
+ if(decoder->info_cb == NULL || decoder->open_cb == NULL) continue;
142
+
143
+ res = decoder->info_cb(decoder, src, &dsc->header);
144
+ if(res != LV_RES_OK) continue;
145
+
146
+ dsc->decoder = decoder;
147
+ res = decoder->open_cb(decoder, dsc);
148
+
149
+ /*Opened successfully. It is a good decoder for this image source*/
150
+ if(res == LV_RES_OK) return res;
151
+
152
+ /*Prepare for the next loop*/
153
+ lv_memset_00(&dsc->header, sizeof(lv_img_header_t));
154
+
155
+ dsc->error_msg = NULL;
156
+ dsc->img_data = NULL;
157
+ dsc->user_data = NULL;
158
+ dsc->time_to_open = 0;
159
+ }
160
+
161
+ if(dsc->src_type == LV_IMG_SRC_FILE)
162
+ lv_mem_free((void *)dsc->src);
163
+
164
+ return res;
165
+ }
166
+
167
+ /**
168
+ * Read a line from an opened image
169
+ * @param dsc pointer to `lv_img_decoder_dsc_t` used in `lv_img_decoder_open`
170
+ * @param x start X coordinate (from left)
171
+ * @param y start Y coordinate (from top)
172
+ * @param len number of pixels to read
173
+ * @param buf store the data here
174
+ * @return LV_RES_OK: success; LV_RES_INV: an error occurred
175
+ */
176
+ lv_res_t lv_img_decoder_read_line(lv_img_decoder_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf)
177
+ {
178
+ lv_res_t res = LV_RES_INV;
179
+ if(dsc->decoder->read_line_cb) res = dsc->decoder->read_line_cb(dsc->decoder, dsc, x, y, len, buf);
180
+
181
+ return res;
182
+ }
183
+
184
+ /**
185
+ * Close a decoding session
186
+ * @param dsc pointer to `lv_img_decoder_dsc_t` used in `lv_img_decoder_open`
187
+ */
188
+ void lv_img_decoder_close(lv_img_decoder_dsc_t * dsc)
189
+ {
190
+ if(dsc->decoder) {
191
+ if(dsc->decoder->close_cb) dsc->decoder->close_cb(dsc->decoder, dsc);
192
+
193
+ if(dsc->src_type == LV_IMG_SRC_FILE) {
194
+ lv_mem_free((void *)dsc->src);
195
+ dsc->src = NULL;
196
+ }
197
+ }
198
+ }
199
+
200
+ /**
201
+ * Create a new image decoder
202
+ * @return pointer to the new image decoder
203
+ */
204
+ lv_img_decoder_t * lv_img_decoder_create(void)
205
+ {
206
+ lv_img_decoder_t * decoder;
207
+ decoder = _lv_ll_ins_head(&LV_GC_ROOT(_lv_img_decoder_ll));
208
+ LV_ASSERT_MALLOC(decoder);
209
+ if(decoder == NULL) return NULL;
210
+
211
+ lv_memset_00(decoder, sizeof(lv_img_decoder_t));
212
+
213
+ return decoder;
214
+ }
215
+
216
+ /**
217
+ * Delete an image decoder
218
+ * @param decoder pointer to an image decoder
219
+ */
220
+ void lv_img_decoder_delete(lv_img_decoder_t * decoder)
221
+ {
222
+ _lv_ll_remove(&LV_GC_ROOT(_lv_img_decoder_ll), decoder);
223
+ lv_mem_free(decoder);
224
+ }
225
+
226
+ /**
227
+ * Set a callback to get information about the image
228
+ * @param decoder pointer to an image decoder
229
+ * @param info_cb a function to collect info about an image (fill an `lv_img_header_t` struct)
230
+ */
231
+ void lv_img_decoder_set_info_cb(lv_img_decoder_t * decoder, lv_img_decoder_info_f_t info_cb)
232
+ {
233
+ decoder->info_cb = info_cb;
234
+ }
235
+
236
+ /**
237
+ * Set a callback to open an image
238
+ * @param decoder pointer to an image decoder
239
+ * @param open_cb a function to open an image
240
+ */
241
+ void lv_img_decoder_set_open_cb(lv_img_decoder_t * decoder, lv_img_decoder_open_f_t open_cb)
242
+ {
243
+ decoder->open_cb = open_cb;
244
+ }
245
+
246
+ /**
247
+ * Set a callback to a decoded line of an image
248
+ * @param decoder pointer to an image decoder
249
+ * @param read_line_cb a function to read a line of an image
250
+ */
251
+ void lv_img_decoder_set_read_line_cb(lv_img_decoder_t * decoder, lv_img_decoder_read_line_f_t read_line_cb)
252
+ {
253
+ decoder->read_line_cb = read_line_cb;
254
+ }
255
+
256
+ /**
257
+ * Set a callback to close a decoding session. E.g. close files and free other resources.
258
+ * @param decoder pointer to an image decoder
259
+ * @param close_cb a function to close a decoding session
260
+ */
261
+ void lv_img_decoder_set_close_cb(lv_img_decoder_t * decoder, lv_img_decoder_close_f_t close_cb)
262
+ {
263
+ decoder->close_cb = close_cb;
264
+ }
265
+
266
+ /**
267
+ * Get info about a built-in image
268
+ * @param decoder the decoder where this function belongs
269
+ * @param src the image source: pointer to an `lv_img_dsc_t` variable, a file path or a symbol
270
+ * @param header store the image data here
271
+ * @return LV_RES_OK: the info is successfully stored in `header`; LV_RES_INV: unknown format or other error.
272
+ */
273
+ lv_res_t lv_img_decoder_built_in_info(lv_img_decoder_t * decoder, const void * src, lv_img_header_t * header)
274
+ {
275
+ LV_UNUSED(decoder); /*Unused*/
276
+
277
+ lv_img_src_t src_type = lv_img_src_get_type(src);
278
+ if(src_type == LV_IMG_SRC_VARIABLE) {
279
+ lv_img_cf_t cf = ((lv_img_dsc_t *)src)->header.cf;
280
+ if(cf < CF_BUILT_IN_FIRST || cf > CF_BUILT_IN_LAST) return LV_RES_INV;
281
+
282
+ header->w = ((lv_img_dsc_t *)src)->header.w;
283
+ header->h = ((lv_img_dsc_t *)src)->header.h;
284
+ header->cf = ((lv_img_dsc_t *)src)->header.cf;
285
+ }
286
+ else if(src_type == LV_IMG_SRC_FILE) {
287
+ /*Support only "*.bin" files*/
288
+ if(strcmp(lv_fs_get_ext(src), "bin")) return LV_RES_INV;
289
+
290
+ lv_fs_file_t f;
291
+ lv_fs_res_t res = lv_fs_open(&f, src, LV_FS_MODE_RD);
292
+ if(res == LV_FS_RES_OK) {
293
+ uint32_t rn;
294
+ res = lv_fs_read(&f, header, sizeof(lv_img_header_t), &rn);
295
+ lv_fs_close(&f);
296
+ if(res != LV_FS_RES_OK || rn != sizeof(lv_img_header_t)) {
297
+ LV_LOG_WARN("Image get info get read file header");
298
+ return LV_RES_INV;
299
+ }
300
+ }
301
+
302
+ if(header->cf < CF_BUILT_IN_FIRST || header->cf > CF_BUILT_IN_LAST) return LV_RES_INV;
303
+ }
304
+ else if(src_type == LV_IMG_SRC_SYMBOL) {
305
+ /*The size depend on the font but it is unknown here. It should be handled outside of the
306
+ *function*/
307
+ header->w = 1;
308
+ header->h = 1;
309
+ /*Symbols always have transparent parts. Important because of cover check in the draw
310
+ *function. The actual value doesn't matter because lv_draw_label will draw it*/
311
+ header->cf = LV_IMG_CF_ALPHA_1BIT;
312
+ }
313
+ else {
314
+ LV_LOG_WARN("Image get info found unknown src type");
315
+ return LV_RES_INV;
316
+ }
317
+ return LV_RES_OK;
318
+ }
319
+
320
+ /**
321
+ * Open a built in image
322
+ * @param decoder the decoder where this function belongs
323
+ * @param dsc pointer to decoder descriptor. `src`, `color` are already initialized in it.
324
+ * @return LV_RES_OK: the info is successfully stored in `header`; LV_RES_INV: unknown format or other error.
325
+ */
326
+ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc)
327
+ {
328
+ /*Open the file if it's a file*/
329
+ if(dsc->src_type == LV_IMG_SRC_FILE) {
330
+ /*Support only "*.bin" files*/
331
+ if(strcmp(lv_fs_get_ext(dsc->src), "bin")) return LV_RES_INV;
332
+
333
+ lv_fs_file_t f;
334
+ lv_fs_res_t res = lv_fs_open(&f, dsc->src, LV_FS_MODE_RD);
335
+ if(res != LV_FS_RES_OK) {
336
+ LV_LOG_WARN("Built-in image decoder can't open the file");
337
+ return LV_RES_INV;
338
+ }
339
+
340
+ /*If the file was open successfully save the file descriptor*/
341
+ if(dsc->user_data == NULL) {
342
+ dsc->user_data = lv_mem_alloc(sizeof(lv_img_decoder_built_in_data_t));
343
+ LV_ASSERT_MALLOC(dsc->user_data);
344
+ if(dsc->user_data == NULL) {
345
+ LV_LOG_ERROR("img_decoder_built_in_open: out of memory");
346
+ lv_fs_close(&f);
347
+ return LV_RES_INV;
348
+ }
349
+ lv_memset_00(dsc->user_data, sizeof(lv_img_decoder_built_in_data_t));
350
+ }
351
+
352
+ lv_img_decoder_built_in_data_t * user_data = dsc->user_data;
353
+ lv_memcpy_small(&user_data->f, &f, sizeof(f));
354
+ }
355
+ else if(dsc->src_type == LV_IMG_SRC_VARIABLE) {
356
+ /*The variables should have valid data*/
357
+ if(((lv_img_dsc_t *)dsc->src)->data == NULL) {
358
+ return LV_RES_INV;
359
+ }
360
+ }
361
+
362
+ lv_img_cf_t cf = dsc->header.cf;
363
+ /*Process A8, RGB565A8, need load file to ram after https://github.com/lvgl/lvgl/pull/3337*/
364
+ if(cf == LV_IMG_CF_ALPHA_8BIT || cf == LV_IMG_CF_RGB565A8) {
365
+ if(dsc->src_type == LV_IMG_SRC_VARIABLE) {
366
+ /*In case of uncompressed formats the image stored in the ROM/RAM.
367
+ *So simply give its pointer*/
368
+ dsc->img_data = ((lv_img_dsc_t *)dsc->src)->data;
369
+ return LV_RES_OK;
370
+ }
371
+ else {
372
+ /*If it's a file, read all to memory*/
373
+ uint32_t len = dsc->header.w * dsc->header.h;
374
+ len *= cf == LV_IMG_CF_RGB565A8 ? 3 : 1;
375
+ uint8_t * fs_buf = lv_mem_alloc(len);
376
+ if(fs_buf == NULL) return LV_RES_INV;
377
+
378
+ lv_img_decoder_built_in_data_t * user_data = dsc->user_data;
379
+ lv_fs_seek(&user_data->f, 4, LV_FS_SEEK_SET); /*+4 to skip the header*/
380
+ lv_fs_res_t res = lv_fs_read(&user_data->f, fs_buf, len, NULL);
381
+ if(res != LV_FS_RES_OK) {
382
+ lv_mem_free(fs_buf);
383
+ return LV_RES_INV;
384
+ }
385
+ dsc->img_data = fs_buf;
386
+ return LV_RES_OK;
387
+ }
388
+ }
389
+ /*Process true color formats*/
390
+ else if(cf == LV_IMG_CF_TRUE_COLOR || cf == LV_IMG_CF_TRUE_COLOR_ALPHA ||
391
+ cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) {
392
+ if(dsc->src_type == LV_IMG_SRC_VARIABLE) {
393
+ /*In case of uncompressed formats the image stored in the ROM/RAM.
394
+ *So simply give its pointer*/
395
+ dsc->img_data = ((lv_img_dsc_t *)dsc->src)->data;
396
+ return LV_RES_OK;
397
+ }
398
+ else {
399
+ /*If it's a file it need to be read line by line later*/
400
+ return LV_RES_OK;
401
+ }
402
+ }
403
+ /*Process indexed images. Build a palette*/
404
+ else if(cf == LV_IMG_CF_INDEXED_1BIT || cf == LV_IMG_CF_INDEXED_2BIT || cf == LV_IMG_CF_INDEXED_4BIT ||
405
+ cf == LV_IMG_CF_INDEXED_8BIT) {
406
+ uint8_t px_size = lv_img_cf_get_px_size(cf);
407
+ uint32_t palette_size = 1 << px_size;
408
+
409
+ /*Allocate the palette*/
410
+ if(dsc->user_data == NULL) {
411
+ dsc->user_data = lv_mem_alloc(sizeof(lv_img_decoder_built_in_data_t));
412
+ LV_ASSERT_MALLOC(dsc->user_data);
413
+ if(dsc->user_data == NULL) {
414
+ LV_LOG_ERROR("img_decoder_built_in_open: out of memory");
415
+ return LV_RES_INV;
416
+ }
417
+ lv_memset_00(dsc->user_data, sizeof(lv_img_decoder_built_in_data_t));
418
+ }
419
+
420
+ lv_img_decoder_built_in_data_t * user_data = dsc->user_data;
421
+ user_data->palette = lv_mem_alloc(palette_size * sizeof(lv_color_t));
422
+ LV_ASSERT_MALLOC(user_data->palette);
423
+ user_data->opa = lv_mem_alloc(palette_size * sizeof(lv_opa_t));
424
+ LV_ASSERT_MALLOC(user_data->opa);
425
+ if(user_data->palette == NULL || user_data->opa == NULL) {
426
+ LV_LOG_ERROR("img_decoder_built_in_open: out of memory");
427
+ lv_img_decoder_built_in_close(decoder, dsc);
428
+ return LV_RES_INV;
429
+ }
430
+
431
+ if(dsc->src_type == LV_IMG_SRC_FILE) {
432
+ /*Read the palette from file*/
433
+ lv_fs_seek(&user_data->f, 4, LV_FS_SEEK_SET); /*Skip the header*/
434
+ lv_color32_t cur_color;
435
+ uint32_t i;
436
+ for(i = 0; i < palette_size; i++) {
437
+ lv_fs_read(&user_data->f, &cur_color, sizeof(lv_color32_t), NULL);
438
+ user_data->palette[i] = lv_color_make(cur_color.ch.red, cur_color.ch.green, cur_color.ch.blue);
439
+ user_data->opa[i] = cur_color.ch.alpha;
440
+ }
441
+ }
442
+ else {
443
+ /*The palette begins in the beginning of the image data. Just point to it.*/
444
+ lv_color32_t * palette_p = (lv_color32_t *)((lv_img_dsc_t *)dsc->src)->data;
445
+
446
+ uint32_t i;
447
+ for(i = 0; i < palette_size; i++) {
448
+ user_data->palette[i] = lv_color_make(palette_p[i].ch.red, palette_p[i].ch.green, palette_p[i].ch.blue);
449
+ user_data->opa[i] = palette_p[i].ch.alpha;
450
+ }
451
+ }
452
+
453
+ return LV_RES_OK;
454
+ }
455
+ /*Alpha indexed images.*/
456
+ else if(cf == LV_IMG_CF_ALPHA_1BIT || cf == LV_IMG_CF_ALPHA_2BIT || cf == LV_IMG_CF_ALPHA_4BIT) {
457
+ return LV_RES_OK; /*Nothing to process*/
458
+ }
459
+ /*Unknown format. Can't decode it.*/
460
+ else {
461
+ /*Free the potentially allocated memories*/
462
+ lv_img_decoder_built_in_close(decoder, dsc);
463
+
464
+ LV_LOG_WARN("Image decoder open: unknown color format");
465
+ return LV_RES_INV;
466
+ }
467
+ }
468
+
469
+ /**
470
+ * Decode `len` pixels starting from the given `x`, `y` coordinates and store them in `buf`.
471
+ * Required only if the "open" function can't return with the whole decoded pixel array.
472
+ * @param decoder pointer to the decoder the function associated with
473
+ * @param dsc pointer to decoder descriptor
474
+ * @param x start x coordinate
475
+ * @param y start y coordinate
476
+ * @param len number of pixels to decode
477
+ * @param buf a buffer to store the decoded pixels
478
+ * @return LV_RES_OK: ok; LV_RES_INV: failed
479
+ */
480
+ lv_res_t lv_img_decoder_built_in_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc, lv_coord_t x,
481
+ lv_coord_t y, lv_coord_t len, uint8_t * buf)
482
+ {
483
+ LV_UNUSED(decoder); /*Unused*/
484
+
485
+ lv_res_t res = LV_RES_INV;
486
+
487
+ if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR || dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA ||
488
+ dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) {
489
+ /*For TRUE_COLOR images read line required only for files.
490
+ *For variables the image data was returned in `open`*/
491
+ if(dsc->src_type == LV_IMG_SRC_FILE) {
492
+ res = lv_img_decoder_built_in_line_true_color(dsc, x, y, len, buf);
493
+ }
494
+ }
495
+ else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT || dsc->header.cf == LV_IMG_CF_ALPHA_2BIT ||
496
+ dsc->header.cf == LV_IMG_CF_ALPHA_4BIT || dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) {
497
+ res = lv_img_decoder_built_in_line_alpha(dsc, x, y, len, buf);
498
+ }
499
+ else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT || dsc->header.cf == LV_IMG_CF_INDEXED_2BIT ||
500
+ dsc->header.cf == LV_IMG_CF_INDEXED_4BIT || dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) {
501
+ res = lv_img_decoder_built_in_line_indexed(dsc, x, y, len, buf);
502
+ }
503
+ else {
504
+ LV_LOG_WARN("Built-in image decoder read not supports the color format");
505
+ return LV_RES_INV;
506
+ }
507
+
508
+ return res;
509
+ }
510
+
511
+ /**
512
+ * Close the pending decoding. Free resources etc.
513
+ * @param decoder pointer to the decoder the function associated with
514
+ * @param dsc pointer to decoder descriptor
515
+ */
516
+ void lv_img_decoder_built_in_close(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc)
517
+ {
518
+ LV_UNUSED(decoder); /*Unused*/
519
+
520
+ lv_img_decoder_built_in_data_t * user_data = dsc->user_data;
521
+ if(user_data) {
522
+ if(dsc->src_type == LV_IMG_SRC_FILE) {
523
+ lv_fs_close(&user_data->f);
524
+ }
525
+ if(user_data->palette) lv_mem_free(user_data->palette);
526
+ if(user_data->opa) lv_mem_free(user_data->opa);
527
+
528
+ lv_mem_free(user_data);
529
+ dsc->user_data = NULL;
530
+ }
531
+ }
532
+
533
+ /**********************
534
+ * STATIC FUNCTIONS
535
+ **********************/
536
+
537
+ static lv_res_t lv_img_decoder_built_in_line_true_color(lv_img_decoder_dsc_t * dsc, lv_coord_t x, lv_coord_t y,
538
+ lv_coord_t len, uint8_t * buf)
539
+ {
540
+ lv_img_decoder_built_in_data_t * user_data = dsc->user_data;
541
+ lv_fs_res_t res;
542
+ uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf);
543
+
544
+ uint32_t pos = ((y * dsc->header.w + x) * px_size) >> 3;
545
+ pos += 4; /*Skip the header*/
546
+ res = lv_fs_seek(&user_data->f, pos, LV_FS_SEEK_SET);
547
+ if(res != LV_FS_RES_OK) {
548
+ LV_LOG_WARN("Built-in image decoder seek failed");
549
+ return LV_RES_INV;
550
+ }
551
+ uint32_t btr = len * (px_size >> 3);
552
+ uint32_t br = 0;
553
+ res = lv_fs_read(&user_data->f, buf, btr, &br);
554
+ if(res != LV_FS_RES_OK || btr != br) {
555
+ LV_LOG_WARN("Built-in image decoder read failed");
556
+ return LV_RES_INV;
557
+ }
558
+
559
+ return LV_RES_OK;
560
+ }
561
+
562
+ static lv_res_t lv_img_decoder_built_in_line_alpha(lv_img_decoder_dsc_t * dsc, lv_coord_t x, lv_coord_t y,
563
+ lv_coord_t len, uint8_t * buf)
564
+ {
565
+ const lv_opa_t alpha1_opa_table[2] = {0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/
566
+ const lv_opa_t alpha2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/
567
+ const lv_opa_t alpha4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/
568
+ 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255
569
+ };
570
+
571
+ /*Simply fill the buffer with the color. Later only the alpha value will be modified.*/
572
+ lv_color_t bg_color = dsc->color;
573
+ lv_coord_t i;
574
+ for(i = 0; i < len; i++) {
575
+ #if LV_COLOR_DEPTH == 8 || LV_COLOR_DEPTH == 1
576
+ buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE] = bg_color.full;
577
+ #elif LV_COLOR_DEPTH == 16
578
+ /*Because of Alpha byte 16 bit color can start on odd address which can cause crash*/
579
+ buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE] = bg_color.full & 0xFF;
580
+ buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE + 1] = (bg_color.full >> 8) & 0xFF;
581
+ #elif LV_COLOR_DEPTH == 32
582
+ *((uint32_t *)&buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE]) = bg_color.full;
583
+ #else
584
+ #error "Invalid LV_COLOR_DEPTH. Check it in lv_conf.h"
585
+ #endif
586
+ }
587
+
588
+ const lv_opa_t * opa_table = NULL;
589
+ uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf);
590
+ uint16_t mask = (1 << px_size) - 1; /*E.g. px_size = 2; mask = 0x03*/
591
+
592
+ lv_coord_t w = 0;
593
+ uint32_t ofs = 0;
594
+ int8_t pos = 0;
595
+ switch(dsc->header.cf) {
596
+ case LV_IMG_CF_ALPHA_1BIT:
597
+ w = (dsc->header.w + 7) >> 3; /*E.g. w = 20 -> w = 2 + 1*/
598
+ ofs += w * y + (x >> 3); /*First pixel*/
599
+ pos = 7 - (x & 0x7);
600
+ opa_table = alpha1_opa_table;
601
+ break;
602
+ case LV_IMG_CF_ALPHA_2BIT:
603
+ w = (dsc->header.w + 3) >> 2; /*E.g. w = 13 -> w = 3 + 1 (bytes)*/
604
+ ofs += w * y + (x >> 2); /*First pixel*/
605
+ pos = 6 - (x & 0x3) * 2;
606
+ opa_table = alpha2_opa_table;
607
+ break;
608
+ case LV_IMG_CF_ALPHA_4BIT:
609
+ w = (dsc->header.w + 1) >> 1; /*E.g. w = 13 -> w = 6 + 1 (bytes)*/
610
+ ofs += w * y + (x >> 1); /*First pixel*/
611
+ pos = 4 - (x & 0x1) * 4;
612
+ opa_table = alpha4_opa_table;
613
+ break;
614
+ case LV_IMG_CF_ALPHA_8BIT:
615
+ w = dsc->header.w; /*E.g. x = 7 -> w = 7 (bytes)*/
616
+ ofs += w * y + x; /*First pixel*/
617
+ pos = 0;
618
+ break;
619
+ }
620
+
621
+ lv_img_decoder_built_in_data_t * user_data = dsc->user_data;
622
+ uint8_t * fs_buf = lv_mem_buf_get(w);
623
+ if(fs_buf == NULL) return LV_RES_INV;
624
+
625
+ const uint8_t * data_tmp = NULL;
626
+ if(dsc->src_type == LV_IMG_SRC_VARIABLE) {
627
+ const lv_img_dsc_t * img_dsc = dsc->src;
628
+
629
+ data_tmp = img_dsc->data + ofs;
630
+ }
631
+ else {
632
+ lv_fs_seek(&user_data->f, ofs + 4, LV_FS_SEEK_SET); /*+4 to skip the header*/
633
+ lv_fs_read(&user_data->f, fs_buf, w, NULL);
634
+ data_tmp = fs_buf;
635
+ }
636
+
637
+ for(i = 0; i < len; i++) {
638
+ uint8_t val_act = (*data_tmp >> pos) & mask;
639
+
640
+ buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE + LV_IMG_PX_SIZE_ALPHA_BYTE - 1] =
641
+ dsc->header.cf == LV_IMG_CF_ALPHA_8BIT ? val_act : opa_table[val_act];
642
+
643
+ pos -= px_size;
644
+ if(pos < 0) {
645
+ pos = 8 - px_size;
646
+ data_tmp++;
647
+ }
648
+ }
649
+ lv_mem_buf_release(fs_buf);
650
+ return LV_RES_OK;
651
+ }
652
+
653
+ static lv_res_t lv_img_decoder_built_in_line_indexed(lv_img_decoder_dsc_t * dsc, lv_coord_t x, lv_coord_t y,
654
+ lv_coord_t len, uint8_t * buf)
655
+ {
656
+ uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf);
657
+ uint16_t mask = (1 << px_size) - 1; /*E.g. px_size = 2; mask = 0x03*/
658
+
659
+ lv_coord_t w = 0;
660
+ int8_t pos = 0;
661
+ uint32_t ofs = 0;
662
+ switch(dsc->header.cf) {
663
+ case LV_IMG_CF_INDEXED_1BIT:
664
+ w = (dsc->header.w + 7) >> 3; /*E.g. w = 20 -> w = 2 + 1*/
665
+ ofs += w * y + (x >> 3); /*First pixel*/
666
+ ofs += 8; /*Skip the palette*/
667
+ pos = 7 - (x & 0x7);
668
+ break;
669
+ case LV_IMG_CF_INDEXED_2BIT:
670
+ w = (dsc->header.w + 3) >> 2; /*E.g. w = 13 -> w = 3 + 1 (bytes)*/
671
+ ofs += w * y + (x >> 2); /*First pixel*/
672
+ ofs += 16; /*Skip the palette*/
673
+ pos = 6 - (x & 0x3) * 2;
674
+ break;
675
+ case LV_IMG_CF_INDEXED_4BIT:
676
+ w = (dsc->header.w + 1) >> 1; /*E.g. w = 13 -> w = 6 + 1 (bytes)*/
677
+ ofs += w * y + (x >> 1); /*First pixel*/
678
+ ofs += 64; /*Skip the palette*/
679
+ pos = 4 - (x & 0x1) * 4;
680
+ break;
681
+ case LV_IMG_CF_INDEXED_8BIT:
682
+ w = dsc->header.w; /*E.g. x = 7 -> w = 7 (bytes)*/
683
+ ofs += w * y + x; /*First pixel*/
684
+ ofs += 1024; /*Skip the palette*/
685
+ pos = 0;
686
+ break;
687
+ }
688
+
689
+ lv_img_decoder_built_in_data_t * user_data = dsc->user_data;
690
+
691
+ uint8_t * fs_buf = lv_mem_buf_get(w);
692
+ if(fs_buf == NULL) return LV_RES_INV;
693
+ const uint8_t * data_tmp = NULL;
694
+ if(dsc->src_type == LV_IMG_SRC_VARIABLE) {
695
+ const lv_img_dsc_t * img_dsc = dsc->src;
696
+ data_tmp = img_dsc->data + ofs;
697
+ }
698
+ else {
699
+ lv_fs_seek(&user_data->f, ofs + 4, LV_FS_SEEK_SET); /*+4 to skip the header*/
700
+ lv_fs_read(&user_data->f, fs_buf, w, NULL);
701
+ data_tmp = fs_buf;
702
+ }
703
+
704
+ lv_coord_t i;
705
+ for(i = 0; i < len; i++) {
706
+ uint8_t val_act = (*data_tmp >> pos) & mask;
707
+
708
+ lv_color_t color = user_data->palette[val_act];
709
+ #if LV_COLOR_DEPTH == 8 || LV_COLOR_DEPTH == 1
710
+ buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE] = color.full;
711
+ #elif LV_COLOR_DEPTH == 16
712
+ /*Because of Alpha byte 16 bit color can start on odd address which can cause crash*/
713
+ buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE] = color.full & 0xFF;
714
+ buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE + 1] = (color.full >> 8) & 0xFF;
715
+ #elif LV_COLOR_DEPTH == 32
716
+ *((uint32_t *)&buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE]) = color.full;
717
+ #else
718
+ #error "Invalid LV_COLOR_DEPTH. Check it in lv_conf.h"
719
+ #endif
720
+ buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE + LV_IMG_PX_SIZE_ALPHA_BYTE - 1] = user_data->opa[val_act];
721
+
722
+ pos -= px_size;
723
+ if(pos < 0) {
724
+ pos = 8 - px_size;
725
+ data_tmp++;
726
+ }
727
+ }
728
+ lv_mem_buf_release(fs_buf);
729
+ return LV_RES_OK;
730
+ }
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/lv_img_decoder.h ADDED
@@ -0,0 +1,274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_img_decoder.h
3
+ *
4
+ */
5
+
6
+ #ifndef LV_IMG_DECODER_H
7
+ #define LV_IMG_DECODER_H
8
+
9
+ #ifdef __cplusplus
10
+ extern "C" {
11
+ #endif
12
+
13
+ /*********************
14
+ * INCLUDES
15
+ *********************/
16
+ #include "../lv_conf_internal.h"
17
+
18
+ #include <stdint.h>
19
+ #include "lv_img_buf.h"
20
+ #include "../misc/lv_fs.h"
21
+ #include "../misc/lv_types.h"
22
+ #include "../misc/lv_area.h"
23
+
24
+ /*********************
25
+ * DEFINES
26
+ *********************/
27
+
28
+ /**********************
29
+ * TYPEDEFS
30
+ **********************/
31
+
32
+ /**
33
+ * Source of image.*/
34
+ enum {
35
+ LV_IMG_SRC_VARIABLE, /** Binary/C variable*/
36
+ LV_IMG_SRC_FILE, /** File in filesystem*/
37
+ LV_IMG_SRC_SYMBOL, /** Symbol (@ref lv_symbol_def.h)*/
38
+ LV_IMG_SRC_UNKNOWN, /** Unknown source*/
39
+ };
40
+
41
+ typedef uint8_t lv_img_src_t;
42
+
43
+ /*Decoder function definitions*/
44
+ struct _lv_img_decoder_dsc_t;
45
+ struct _lv_img_decoder_t;
46
+
47
+ /**
48
+ * Get info from an image and store in the `header`
49
+ * @param src the image source. Can be a pointer to a C array or a file name (Use
50
+ * `lv_img_src_get_type` to determine the type)
51
+ * @param header store the info here
52
+ * @return LV_RES_OK: info written correctly; LV_RES_INV: failed
53
+ */
54
+ typedef lv_res_t (*lv_img_decoder_info_f_t)(struct _lv_img_decoder_t * decoder, const void * src,
55
+ lv_img_header_t * header);
56
+
57
+ /**
58
+ * Open an image for decoding. Prepare it as it is required to read it later
59
+ * @param decoder pointer to the decoder the function associated with
60
+ * @param dsc pointer to decoder descriptor. `src`, `color` are already initialized in it.
61
+ */
62
+ typedef lv_res_t (*lv_img_decoder_open_f_t)(struct _lv_img_decoder_t * decoder, struct _lv_img_decoder_dsc_t * dsc);
63
+
64
+ /**
65
+ * Decode `len` pixels starting from the given `x`, `y` coordinates and store them in `buf`.
66
+ * Required only if the "open" function can't return with the whole decoded pixel array.
67
+ * @param decoder pointer to the decoder the function associated with
68
+ * @param dsc pointer to decoder descriptor
69
+ * @param x start x coordinate
70
+ * @param y start y coordinate
71
+ * @param len number of pixels to decode
72
+ * @param buf a buffer to store the decoded pixels
73
+ * @return LV_RES_OK: ok; LV_RES_INV: failed
74
+ */
75
+ typedef lv_res_t (*lv_img_decoder_read_line_f_t)(struct _lv_img_decoder_t * decoder, struct _lv_img_decoder_dsc_t * dsc,
76
+ lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf);
77
+
78
+ /**
79
+ * Close the pending decoding. Free resources etc.
80
+ * @param decoder pointer to the decoder the function associated with
81
+ * @param dsc pointer to decoder descriptor
82
+ */
83
+ typedef void (*lv_img_decoder_close_f_t)(struct _lv_img_decoder_t * decoder, struct _lv_img_decoder_dsc_t * dsc);
84
+
85
+
86
+ typedef struct _lv_img_decoder_t {
87
+ lv_img_decoder_info_f_t info_cb;
88
+ lv_img_decoder_open_f_t open_cb;
89
+ lv_img_decoder_read_line_f_t read_line_cb;
90
+ lv_img_decoder_close_f_t close_cb;
91
+
92
+ #if LV_USE_USER_DATA
93
+ void * user_data;
94
+ #endif
95
+ } lv_img_decoder_t;
96
+
97
+
98
+ /**Describe an image decoding session. Stores data about the decoding*/
99
+ typedef struct _lv_img_decoder_dsc_t {
100
+ /**The decoder which was able to open the image source*/
101
+ lv_img_decoder_t * decoder;
102
+
103
+ /**The image source. A file path like "S:my_img.png" or pointer to an `lv_img_dsc_t` variable*/
104
+ const void * src;
105
+
106
+ /**Color to draw the image. USed when the image has alpha channel only*/
107
+ lv_color_t color;
108
+
109
+ /**Frame of the image, using with animated images*/
110
+ int32_t frame_id;
111
+
112
+ /**Type of the source: file or variable. Can be set in `open` function if required*/
113
+ lv_img_src_t src_type;
114
+
115
+ /**Info about the opened image: color format, size, etc. MUST be set in `open` function*/
116
+ lv_img_header_t header;
117
+
118
+ /** Pointer to a buffer where the image's data (pixels) are stored in a decoded, plain format.
119
+ * MUST be set in `open` function*/
120
+ const uint8_t * img_data;
121
+
122
+ /** How much time did it take to open the image. [ms]
123
+ * If not set `lv_img_cache` will measure and set the time to open*/
124
+ uint32_t time_to_open;
125
+
126
+ /**A text to display instead of the image when the image can't be opened.
127
+ * Can be set in `open` function or set NULL.*/
128
+ const char * error_msg;
129
+
130
+ /**Store any custom data here is required*/
131
+ void * user_data;
132
+ } lv_img_decoder_dsc_t;
133
+
134
+ /**********************
135
+ * GLOBAL PROTOTYPES
136
+ **********************/
137
+
138
+ /**
139
+ * Initialize the image decoder module
140
+ */
141
+ void _lv_img_decoder_init(void);
142
+
143
+ /**
144
+ * Get information about an image.
145
+ * Try the created image decoder one by one. Once one is able to get info that info will be used.
146
+ * @param src the image source. Can be
147
+ * 1) File name: E.g. "S:folder/img1.png" (The drivers needs to registered via `lv_fs_drv_register()`)
148
+ * 2) Variable: Pointer to an `lv_img_dsc_t` variable
149
+ * 3) Symbol: E.g. `LV_SYMBOL_OK`
150
+ * @param header the image info will be stored here
151
+ * @return LV_RES_OK: success; LV_RES_INV: wasn't able to get info about the image
152
+ */
153
+ lv_res_t lv_img_decoder_get_info(const void * src, lv_img_header_t * header);
154
+
155
+ /**
156
+ * Open an image.
157
+ * Try the created image decoders one by one. Once one is able to open the image that decoder is saved in `dsc`
158
+ * @param dsc describes a decoding session. Simply a pointer to an `lv_img_decoder_dsc_t` variable.
159
+ * @param src the image source. Can be
160
+ * 1) File name: E.g. "S:folder/img1.png" (The drivers needs to registered via `lv_fs_drv_register())`)
161
+ * 2) Variable: Pointer to an `lv_img_dsc_t` variable
162
+ * 3) Symbol: E.g. `LV_SYMBOL_OK`
163
+ * @param color The color of the image with `LV_IMG_CF_ALPHA_...`
164
+ * @param frame_id the index of the frame. Used only with animated images, set 0 for normal images
165
+ * @return LV_RES_OK: opened the image. `dsc->img_data` and `dsc->header` are set.
166
+ * LV_RES_INV: none of the registered image decoders were able to open the image.
167
+ */
168
+ lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t * dsc, const void * src, lv_color_t color, int32_t frame_id);
169
+
170
+ /**
171
+ * Read a line from an opened image
172
+ * @param dsc pointer to `lv_img_decoder_dsc_t` used in `lv_img_decoder_open`
173
+ * @param x start X coordinate (from left)
174
+ * @param y start Y coordinate (from top)
175
+ * @param len number of pixels to read
176
+ * @param buf store the data here
177
+ * @return LV_RES_OK: success; LV_RES_INV: an error occurred
178
+ */
179
+ lv_res_t lv_img_decoder_read_line(lv_img_decoder_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_coord_t len,
180
+ uint8_t * buf);
181
+
182
+ /**
183
+ * Close a decoding session
184
+ * @param dsc pointer to `lv_img_decoder_dsc_t` used in `lv_img_decoder_open`
185
+ */
186
+ void lv_img_decoder_close(lv_img_decoder_dsc_t * dsc);
187
+
188
+ /**
189
+ * Create a new image decoder
190
+ * @return pointer to the new image decoder
191
+ */
192
+ lv_img_decoder_t * lv_img_decoder_create(void);
193
+
194
+ /**
195
+ * Delete an image decoder
196
+ * @param decoder pointer to an image decoder
197
+ */
198
+ void lv_img_decoder_delete(lv_img_decoder_t * decoder);
199
+
200
+ /**
201
+ * Set a callback to get information about the image
202
+ * @param decoder pointer to an image decoder
203
+ * @param info_cb a function to collect info about an image (fill an `lv_img_header_t` struct)
204
+ */
205
+ void lv_img_decoder_set_info_cb(lv_img_decoder_t * decoder, lv_img_decoder_info_f_t info_cb);
206
+
207
+ /**
208
+ * Set a callback to open an image
209
+ * @param decoder pointer to an image decoder
210
+ * @param open_cb a function to open an image
211
+ */
212
+ void lv_img_decoder_set_open_cb(lv_img_decoder_t * decoder, lv_img_decoder_open_f_t open_cb);
213
+
214
+ /**
215
+ * Set a callback to a decoded line of an image
216
+ * @param decoder pointer to an image decoder
217
+ * @param read_line_cb a function to read a line of an image
218
+ */
219
+ void lv_img_decoder_set_read_line_cb(lv_img_decoder_t * decoder, lv_img_decoder_read_line_f_t read_line_cb);
220
+
221
+ /**
222
+ * Set a callback to close a decoding session. E.g. close files and free other resources.
223
+ * @param decoder pointer to an image decoder
224
+ * @param close_cb a function to close a decoding session
225
+ */
226
+ void lv_img_decoder_set_close_cb(lv_img_decoder_t * decoder, lv_img_decoder_close_f_t close_cb);
227
+
228
+ /**
229
+ * Get info about a built-in image
230
+ * @param decoder the decoder where this function belongs
231
+ * @param src the image source: pointer to an `lv_img_dsc_t` variable, a file path or a symbol
232
+ * @param header store the image data here
233
+ * @return LV_RES_OK: the info is successfully stored in `header`; LV_RES_INV: unknown format or other error.
234
+ */
235
+ lv_res_t lv_img_decoder_built_in_info(lv_img_decoder_t * decoder, const void * src, lv_img_header_t * header);
236
+
237
+ /**
238
+ * Open a built in image
239
+ * @param decoder the decoder where this function belongs
240
+ * @param dsc pointer to decoder descriptor. `src`, `style` are already initialized in it.
241
+ * @return LV_RES_OK: the info is successfully stored in `header`; LV_RES_INV: unknown format or other error.
242
+ */
243
+ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc);
244
+
245
+ /**
246
+ * Decode `len` pixels starting from the given `x`, `y` coordinates and store them in `buf`.
247
+ * Required only if the "open" function can't return with the whole decoded pixel array.
248
+ * @param decoder pointer to the decoder the function associated with
249
+ * @param dsc pointer to decoder descriptor
250
+ * @param x start x coordinate
251
+ * @param y start y coordinate
252
+ * @param len number of pixels to decode
253
+ * @param buf a buffer to store the decoded pixels
254
+ * @return LV_RES_OK: ok; LV_RES_INV: failed
255
+ */
256
+ lv_res_t lv_img_decoder_built_in_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc, lv_coord_t x,
257
+ lv_coord_t y, lv_coord_t len, uint8_t * buf);
258
+
259
+ /**
260
+ * Close the pending decoding. Free resources etc.
261
+ * @param decoder pointer to the decoder the function associated with
262
+ * @param dsc pointer to decoder descriptor
263
+ */
264
+ void lv_img_decoder_built_in_close(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc);
265
+
266
+ /**********************
267
+ * MACROS
268
+ **********************/
269
+
270
+ #ifdef __cplusplus
271
+ } /*extern "C"*/
272
+ #endif
273
+
274
+ #endif /*LV_IMG_DECODER_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/pxp/lv_draw_pxp.c ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_pxp.c
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2022, 2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ /*********************
31
+ * INCLUDES
32
+ *********************/
33
+
34
+ #include "lv_draw_pxp.h"
35
+
36
+ #if LV_USE_GPU_NXP_PXP
37
+ #include "lv_draw_pxp_blend.h"
38
+
39
+ #if LV_COLOR_DEPTH != 32
40
+ #include "../../../core/lv_refr.h"
41
+ #endif
42
+
43
+ /*********************
44
+ * DEFINES
45
+ *********************/
46
+
47
+ /* Minimum area (in pixels) for PXP blit/fill processing. */
48
+ #ifndef LV_GPU_NXP_PXP_SIZE_LIMIT
49
+ #define LV_GPU_NXP_PXP_SIZE_LIMIT 5000
50
+ #endif
51
+
52
+ /**********************
53
+ * TYPEDEFS
54
+ **********************/
55
+
56
+ /**********************
57
+ * STATIC PROTOTYPES
58
+ **********************/
59
+
60
+ static void lv_draw_pxp_wait_for_finish(lv_draw_ctx_t * draw_ctx);
61
+
62
+ static void lv_draw_pxp_blend(lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc);
63
+
64
+ static void lv_draw_pxp_img_decoded(lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * dsc,
65
+ const lv_area_t * coords, const uint8_t * map_p, lv_img_cf_t cf);
66
+
67
+ static void lv_draw_pxp_buffer_copy(lv_draw_ctx_t * draw_ctx,
68
+ void * dest_buf, lv_coord_t dest_stride, const lv_area_t * dest_area,
69
+ void * src_buf, lv_coord_t src_stride, const lv_area_t * src_area);
70
+
71
+ /**********************
72
+ * STATIC VARIABLES
73
+ **********************/
74
+
75
+ /**********************
76
+ * MACROS
77
+ **********************/
78
+
79
+ /**********************
80
+ * GLOBAL FUNCTIONS
81
+ **********************/
82
+
83
+ void lv_draw_pxp_ctx_init(lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx)
84
+ {
85
+ lv_draw_sw_init_ctx(drv, draw_ctx);
86
+
87
+ lv_draw_pxp_ctx_t * pxp_draw_ctx = (lv_draw_sw_ctx_t *)draw_ctx;
88
+ pxp_draw_ctx->base_draw.draw_img_decoded = lv_draw_pxp_img_decoded;
89
+ pxp_draw_ctx->blend = lv_draw_pxp_blend;
90
+ pxp_draw_ctx->base_draw.wait_for_finish = lv_draw_pxp_wait_for_finish;
91
+ pxp_draw_ctx->base_draw.buffer_copy = lv_draw_pxp_buffer_copy;
92
+ }
93
+
94
+ void lv_draw_pxp_ctx_deinit(lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx)
95
+ {
96
+ lv_draw_sw_deinit_ctx(drv, draw_ctx);
97
+ }
98
+
99
+ /**********************
100
+ * STATIC FUNCTIONS
101
+ **********************/
102
+
103
+ /**
104
+ * During rendering, LVGL might initializes new draw_ctxs and start drawing into
105
+ * a separate buffer (called layer). If the content to be rendered has "holes",
106
+ * e.g. rounded corner, LVGL temporarily sets the disp_drv.screen_transp flag.
107
+ * It means the renderers should draw into an ARGB buffer.
108
+ * With 32 bit color depth it's not a big problem but with 16 bit color depth
109
+ * the target pixel format is ARGB8565 which is not supported by the GPU.
110
+ * In this case, the PXP callbacks should fallback to SW rendering.
111
+ */
112
+ static inline bool need_argb8565_support()
113
+ {
114
+ #if LV_COLOR_DEPTH != 32
115
+ lv_disp_t * disp = _lv_refr_get_disp_refreshing();
116
+
117
+ if(disp->driver->screen_transp == 1)
118
+ return true;
119
+ #endif
120
+
121
+ return false;
122
+ }
123
+
124
+ static void lv_draw_pxp_wait_for_finish(lv_draw_ctx_t * draw_ctx)
125
+ {
126
+ lv_gpu_nxp_pxp_wait();
127
+
128
+ lv_draw_sw_wait_for_finish(draw_ctx);
129
+ }
130
+
131
+ static void lv_draw_pxp_blend(lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc)
132
+ {
133
+ if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
134
+ return;
135
+
136
+ if(need_argb8565_support()) {
137
+ lv_draw_sw_blend_basic(draw_ctx, dsc);
138
+ return;
139
+ }
140
+
141
+ lv_area_t blend_area;
142
+ /*Let's get the blend area which is the intersection of the area to draw and the clip area*/
143
+ if(!_lv_area_intersect(&blend_area, dsc->blend_area, draw_ctx->clip_area))
144
+ return; /*Fully clipped, nothing to do*/
145
+
146
+ /*Make the blend area relative to the buffer*/
147
+ lv_area_move(&blend_area, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
148
+ if(dsc->mask_buf != NULL || dsc->blend_mode != LV_BLEND_MODE_NORMAL ||
149
+ lv_area_get_size(&blend_area) < LV_GPU_NXP_PXP_SIZE_LIMIT) {
150
+ lv_draw_sw_blend_basic(draw_ctx, dsc);
151
+ return;
152
+ }
153
+
154
+ /*Fill/Blend only non masked, normal blended*/
155
+ lv_color_t * dest_buf = draw_ctx->buf;
156
+ lv_coord_t dest_stride = lv_area_get_width(draw_ctx->buf_area);
157
+ const lv_color_t * src_buf = dsc->src_buf;
158
+
159
+ if(src_buf == NULL) {
160
+ lv_gpu_nxp_pxp_fill(dest_buf, &blend_area, dest_stride, dsc->color, dsc->opa);
161
+ }
162
+ else {
163
+ lv_area_t src_area;
164
+ src_area.x1 = blend_area.x1 - (dsc->blend_area->x1 - draw_ctx->buf_area->x1);
165
+ src_area.y1 = blend_area.y1 - (dsc->blend_area->y1 - draw_ctx->buf_area->y1);
166
+ src_area.x2 = src_area.x1 + lv_area_get_width(dsc->blend_area) - 1;
167
+ src_area.y2 = src_area.y1 + lv_area_get_height(dsc->blend_area) - 1;
168
+ lv_coord_t src_stride = lv_area_get_width(dsc->blend_area);
169
+
170
+ lv_gpu_nxp_pxp_blit(dest_buf, &blend_area, dest_stride, src_buf, &src_area, src_stride,
171
+ dsc->opa, LV_DISP_ROT_NONE);
172
+ }
173
+ }
174
+
175
+ static void lv_draw_pxp_img_decoded(lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * dsc,
176
+ const lv_area_t * coords, const uint8_t * map_p, lv_img_cf_t cf)
177
+ {
178
+ if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
179
+ return;
180
+
181
+ if(need_argb8565_support()) {
182
+ lv_draw_sw_img_decoded(draw_ctx, dsc, coords, map_p, cf);
183
+ return;
184
+ }
185
+
186
+ const lv_color_t * src_buf = (const lv_color_t *)map_p;
187
+ if(!src_buf) {
188
+ lv_draw_sw_img_decoded(draw_ctx, dsc, coords, map_p, cf);
189
+ return;
190
+ }
191
+
192
+ lv_area_t rel_coords;
193
+ lv_area_copy(&rel_coords, coords);
194
+ lv_area_move(&rel_coords, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
195
+
196
+ lv_area_t rel_clip_area;
197
+ lv_area_copy(&rel_clip_area, draw_ctx->clip_area);
198
+ lv_area_move(&rel_clip_area, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
199
+
200
+ bool has_scale = (dsc->zoom != LV_IMG_ZOOM_NONE);
201
+ bool has_rotation = (dsc->angle != 0);
202
+ bool unsup_rotation = false;
203
+
204
+ lv_area_t blend_area;
205
+ if(has_rotation)
206
+ lv_area_copy(&blend_area, &rel_coords);
207
+ else if(!_lv_area_intersect(&blend_area, &rel_coords, &rel_clip_area))
208
+ return; /*Fully clipped, nothing to do*/
209
+
210
+ bool has_mask = lv_draw_mask_is_any(&blend_area);
211
+ lv_coord_t src_width = lv_area_get_width(coords);
212
+ lv_coord_t src_height = lv_area_get_height(coords);
213
+
214
+ if(has_rotation) {
215
+ /*
216
+ * PXP can only rotate at 90x angles.
217
+ */
218
+ if(dsc->angle % 900) {
219
+ PXP_LOG_TRACE("Rotation angle %d is not supported. PXP can rotate only 90x angle.", dsc->angle);
220
+ unsup_rotation = true;
221
+ }
222
+
223
+ /*
224
+ * PXP is set to process 16x16 blocks to optimize the system for memory
225
+ * bandwidth and image processing time.
226
+ * The output engine essentially truncates any output pixels after the
227
+ * desired number of pixels has been written.
228
+ * When rotating a source image and the output is not divisible by the block
229
+ * size, the incorrect pixels could be truncated and the final output image
230
+ * can look shifted.
231
+ */
232
+ if(src_width % 16 || src_height % 16) {
233
+ PXP_LOG_TRACE("Rotation is not supported for image w/o alignment to block size 16x16.");
234
+ unsup_rotation = true;
235
+ }
236
+ }
237
+
238
+ if(has_mask || has_scale || unsup_rotation || lv_area_get_size(&blend_area) < LV_GPU_NXP_PXP_SIZE_LIMIT
239
+ #if LV_COLOR_DEPTH != 32
240
+ || lv_img_cf_has_alpha(cf)
241
+ #endif
242
+ ) {
243
+ lv_draw_sw_img_decoded(draw_ctx, dsc, coords, map_p, cf);
244
+ return;
245
+ }
246
+
247
+ lv_color_t * dest_buf = draw_ctx->buf;
248
+ lv_coord_t dest_stride = lv_area_get_width(draw_ctx->buf_area);
249
+
250
+ lv_area_t src_area;
251
+ src_area.x1 = blend_area.x1 - (coords->x1 - draw_ctx->buf_area->x1);
252
+ src_area.y1 = blend_area.y1 - (coords->y1 - draw_ctx->buf_area->y1);
253
+ src_area.x2 = src_area.x1 + src_width - 1;
254
+ src_area.y2 = src_area.y1 + src_height - 1;
255
+ lv_coord_t src_stride = lv_area_get_width(coords);
256
+
257
+ lv_gpu_nxp_pxp_blit_transform(dest_buf, &blend_area, dest_stride, src_buf, &src_area, src_stride,
258
+ dsc, cf);
259
+ }
260
+
261
+ static void lv_draw_pxp_buffer_copy(lv_draw_ctx_t * draw_ctx,
262
+ void * dest_buf, lv_coord_t dest_stride, const lv_area_t * dest_area,
263
+ void * src_buf, lv_coord_t src_stride, const lv_area_t * src_area)
264
+ {
265
+ LV_UNUSED(draw_ctx);
266
+
267
+ if(lv_area_get_size(dest_area) < LV_GPU_NXP_PXP_SIZE_LIMIT) {
268
+ lv_draw_sw_buffer_copy(draw_ctx, dest_buf, dest_stride, dest_area, src_buf, src_stride, src_area);
269
+ return;
270
+ }
271
+
272
+ lv_gpu_nxp_pxp_buffer_copy(dest_buf, dest_area, dest_stride, src_buf, src_area, src_stride);
273
+ }
274
+
275
+ #endif /*LV_USE_GPU_NXP_PXP*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/pxp/lv_draw_pxp.h ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_pxp.h
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2022, 2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ #ifndef LV_DRAW_PXP_H
31
+ #define LV_DRAW_PXP_H
32
+
33
+ #ifdef __cplusplus
34
+ extern "C" {
35
+ #endif
36
+
37
+ /*********************
38
+ * INCLUDES
39
+ *********************/
40
+
41
+ #include "../../../lv_conf_internal.h"
42
+
43
+ #if LV_USE_GPU_NXP_PXP
44
+ #include "../../sw/lv_draw_sw.h"
45
+
46
+ /*********************
47
+ * DEFINES
48
+ *********************/
49
+
50
+ /**********************
51
+ * TYPEDEFS
52
+ **********************/
53
+ typedef lv_draw_sw_ctx_t lv_draw_pxp_ctx_t;
54
+
55
+ /**********************
56
+ * GLOBAL PROTOTYPES
57
+ **********************/
58
+
59
+ void lv_draw_pxp_ctx_init(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx);
60
+
61
+ void lv_draw_pxp_ctx_deinit(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx);
62
+
63
+ /**********************
64
+ * MACROS
65
+ **********************/
66
+ #endif /*LV_USE_GPU_NXP_PXP*/
67
+
68
+ #ifdef __cplusplus
69
+ } /*extern "C"*/
70
+ #endif
71
+
72
+ #endif /*LV_DRAW_PXP_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/pxp/lv_draw_pxp_blend.c ADDED
@@ -0,0 +1,573 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_pxp_blend.c
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2020-2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ /*********************
31
+ * INCLUDES
32
+ *********************/
33
+
34
+ #include "lv_draw_pxp_blend.h"
35
+
36
+ #if LV_USE_GPU_NXP_PXP
37
+ #include "lvgl_support.h"
38
+
39
+ /*********************
40
+ * DEFINES
41
+ *********************/
42
+
43
+ #if LV_COLOR_16_SWAP
44
+ #error Color swap not implemented. Disable LV_COLOR_16_SWAP feature.
45
+ #endif
46
+
47
+ #if LV_COLOR_DEPTH == 16
48
+ #define PXP_OUT_PIXEL_FORMAT kPXP_OutputPixelFormatRGB565
49
+ #define PXP_AS_PIXEL_FORMAT kPXP_AsPixelFormatRGB565
50
+ #define PXP_PS_PIXEL_FORMAT kPXP_PsPixelFormatRGB565
51
+ #define PXP_TEMP_BUF_SIZE LCD_WIDTH * LCD_HEIGHT * 2U
52
+ #elif LV_COLOR_DEPTH == 32
53
+ #define PXP_OUT_PIXEL_FORMAT kPXP_OutputPixelFormatARGB8888
54
+ #define PXP_AS_PIXEL_FORMAT kPXP_AsPixelFormatARGB8888
55
+ #if (!(defined(FSL_FEATURE_PXP_HAS_NO_EXTEND_PIXEL_FORMAT) && FSL_FEATURE_PXP_HAS_NO_EXTEND_PIXEL_FORMAT)) && \
56
+ (!(defined(FSL_FEATURE_PXP_V3) && FSL_FEATURE_PXP_V3))
57
+ #define PXP_PS_PIXEL_FORMAT kPXP_PsPixelFormatARGB8888
58
+ #else
59
+ #define PXP_PS_PIXEL_FORMAT kPXP_PsPixelFormatRGB888
60
+ #endif
61
+ #define PXP_TEMP_BUF_SIZE LCD_WIDTH * LCD_HEIGHT * 4U
62
+ #elif
63
+ #error Only 16bit and 32bit color depth are supported. Set LV_COLOR_DEPTH to 16 or 32.
64
+ #endif
65
+
66
+ /**********************
67
+ * TYPEDEFS
68
+ **********************/
69
+
70
+ /**********************
71
+ * STATIC PROTOTYPES
72
+ **********************/
73
+
74
+ static LV_ATTRIBUTE_MEM_ALIGN uint8_t temp_buf[PXP_TEMP_BUF_SIZE];
75
+
76
+ /**
77
+ * BLock Image Transfer - copy rectangular image from src buffer to dst buffer
78
+ * with combination of transformation (rotation, scale, recolor) and opacity, alpha channel
79
+ * or color keying. This requires two steps. First step is used for transformation into
80
+ * a temporary buffer and the second one will handle the color format or opacity.
81
+ *
82
+ * @param[in/out] dest_buf Destination buffer
83
+ * @param[in] dest_area Area with relative coordinates of destination buffer
84
+ * @param[in] dest_stride Stride of destination buffer in pixels
85
+ * @param[in] src_buf Source buffer
86
+ * @param[in] src_area Area with relative coordinates of source buffer
87
+ * @param[in] src_stride Stride of source buffer in pixels
88
+ * @param[in] dsc Image descriptor
89
+ * @param[in] cf Color format
90
+ */
91
+ static void lv_pxp_blit_opa(lv_color_t * dest_buf, const lv_area_t * dest_area, lv_coord_t dest_stride,
92
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride,
93
+ const lv_draw_img_dsc_t * dsc, lv_img_cf_t cf);
94
+
95
+ /**
96
+ * BLock Image Transfer - copy rectangular image from src buffer to dst buffer
97
+ * with transformation and full opacity.
98
+ *
99
+ * @param[in/out] dest_buf Destination buffer
100
+ * @param[in] dest_area Area with relative coordinates of destination buffer
101
+ * @param[in] dest_stride Stride of destination buffer in pixels
102
+ * @param[in] src_buf Source buffer
103
+ * @param[in] src_area Area with relative coordinates of source buffer
104
+ * @param[in] src_stride Stride of source buffer in pixels
105
+ * @param[in] dsc Image descriptor
106
+ * @param[in] cf Color format
107
+ */
108
+ static void lv_pxp_blit_cover(lv_color_t * dest_buf, lv_area_t * dest_area, lv_coord_t dest_stride,
109
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride,
110
+ const lv_draw_img_dsc_t * dsc, lv_img_cf_t cf);
111
+
112
+ /**
113
+ * BLock Image Transfer - copy rectangular image from src buffer to dst buffer
114
+ * without transformation but handling color format or opacity.
115
+ *
116
+ * @param[in/out] dest_buf Destination buffer
117
+ * @param[in] dest_area Area with relative coordinates of destination buffer
118
+ * @param[in] dest_stride Stride of destination buffer in pixels
119
+ * @param[in] src_buf Source buffer
120
+ * @param[in] src_area Area with relative coordinates of source buffer
121
+ * @param[in] src_stride Stride of source buffer in pixels
122
+ * @param[in] dsc Image descriptor
123
+ * @param[in] cf Color format
124
+ */
125
+ static void lv_pxp_blit_cf(lv_color_t * dest_buf, const lv_area_t * dest_area, lv_coord_t dest_stride,
126
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride,
127
+ const lv_draw_img_dsc_t * dsc, lv_img_cf_t cf);
128
+
129
+ /**********************
130
+ * STATIC VARIABLES
131
+ **********************/
132
+
133
+ /**********************
134
+ * MACROS
135
+ **********************/
136
+
137
+ /**********************
138
+ * GLOBAL FUNCTIONS
139
+ **********************/
140
+
141
+ void lv_gpu_nxp_pxp_fill(lv_color_t * dest_buf, const lv_area_t * dest_area, lv_coord_t dest_stride,
142
+ lv_color_t color, lv_opa_t opa)
143
+ {
144
+ lv_coord_t dest_w = lv_area_get_width(dest_area);
145
+ lv_coord_t dest_h = lv_area_get_height(dest_area);
146
+
147
+ lv_gpu_nxp_pxp_reset();
148
+
149
+ /*OUT buffer configure*/
150
+ pxp_output_buffer_config_t outputConfig = {
151
+ .pixelFormat = PXP_OUT_PIXEL_FORMAT,
152
+ .interlacedMode = kPXP_OutputProgressive,
153
+ .buffer0Addr = (uint32_t)(dest_buf + dest_stride * dest_area->y1 + dest_area->x1),
154
+ .buffer1Addr = (uint32_t)NULL,
155
+ .pitchBytes = dest_stride * sizeof(lv_color_t),
156
+ .width = dest_w,
157
+ .height = dest_h
158
+ };
159
+
160
+ PXP_SetOutputBufferConfig(LV_GPU_NXP_PXP_ID, &outputConfig);
161
+
162
+ if(opa >= (lv_opa_t)LV_OPA_MAX) {
163
+ /*Simple color fill without opacity - AS disabled*/
164
+ PXP_SetAlphaSurfacePosition(LV_GPU_NXP_PXP_ID, 0xFFFFU, 0xFFFFU, 0U, 0U);
165
+
166
+ }
167
+ else {
168
+ /*Fill with opacity - AS used as source (same as OUT)*/
169
+ pxp_as_buffer_config_t asBufferConfig = {
170
+ .pixelFormat = PXP_AS_PIXEL_FORMAT,
171
+ .bufferAddr = (uint32_t)outputConfig.buffer0Addr,
172
+ .pitchBytes = outputConfig.pitchBytes
173
+ };
174
+
175
+ PXP_SetAlphaSurfaceBufferConfig(LV_GPU_NXP_PXP_ID, &asBufferConfig);
176
+ PXP_SetAlphaSurfacePosition(LV_GPU_NXP_PXP_ID, 0U, 0U, dest_w - 1U, dest_h - 1U);
177
+ }
178
+
179
+ /*Disable PS, use as color generator*/
180
+ PXP_SetProcessSurfacePosition(LV_GPU_NXP_PXP_ID, 0xFFFFU, 0xFFFFU, 0U, 0U);
181
+ PXP_SetProcessSurfaceBackGroundColor(LV_GPU_NXP_PXP_ID, lv_color_to32(color));
182
+
183
+ /**
184
+ * Configure Porter-Duff blending - src settings are unused for fill without opacity (opa = 0xff).
185
+ *
186
+ * Note: srcFactorMode and dstFactorMode are inverted in fsl_pxp.h:
187
+ * srcFactorMode is actually applied on PS alpha value
188
+ * dstFactorMode is actually applied on AS alpha value
189
+ */
190
+ pxp_porter_duff_config_t pdConfig = {
191
+ .enable = 1,
192
+ .dstColorMode = kPXP_PorterDuffColorNoAlpha,
193
+ .srcColorMode = kPXP_PorterDuffColorNoAlpha,
194
+ .dstGlobalAlphaMode = kPXP_PorterDuffGlobalAlpha,
195
+ .srcGlobalAlphaMode = kPXP_PorterDuffGlobalAlpha,
196
+ .dstFactorMode = kPXP_PorterDuffFactorStraight,
197
+ .srcFactorMode = (opa >= (lv_opa_t)LV_OPA_MAX) ? kPXP_PorterDuffFactorStraight : kPXP_PorterDuffFactorInversed,
198
+ .dstGlobalAlpha = opa,
199
+ .srcGlobalAlpha = opa,
200
+ .dstAlphaMode = kPXP_PorterDuffAlphaStraight, /*don't care*/
201
+ .srcAlphaMode = kPXP_PorterDuffAlphaStraight /*don't care*/
202
+ };
203
+
204
+ PXP_SetPorterDuffConfig(LV_GPU_NXP_PXP_ID, &pdConfig);
205
+
206
+ lv_gpu_nxp_pxp_run();
207
+ }
208
+
209
+ void lv_gpu_nxp_pxp_blit(lv_color_t * dest_buf, const lv_area_t * dest_area, lv_coord_t dest_stride,
210
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride,
211
+ lv_opa_t opa, lv_disp_rot_t angle)
212
+ {
213
+ lv_coord_t dest_w = lv_area_get_width(dest_area);
214
+ lv_coord_t dest_h = lv_area_get_height(dest_area);
215
+ lv_coord_t src_w = lv_area_get_width(src_area);
216
+ lv_coord_t src_h = lv_area_get_height(src_area);
217
+
218
+ lv_gpu_nxp_pxp_reset();
219
+
220
+ /* convert rotation angle */
221
+ pxp_rotate_degree_t pxp_rot;
222
+ switch(angle) {
223
+ case LV_DISP_ROT_NONE:
224
+ pxp_rot = kPXP_Rotate0;
225
+ break;
226
+ case LV_DISP_ROT_90:
227
+ pxp_rot = kPXP_Rotate90;
228
+ break;
229
+ case LV_DISP_ROT_180:
230
+ pxp_rot = kPXP_Rotate180;
231
+ break;
232
+ case LV_DISP_ROT_270:
233
+ pxp_rot = kPXP_Rotate270;
234
+ break;
235
+ default:
236
+ pxp_rot = kPXP_Rotate0;
237
+ break;
238
+ }
239
+ PXP_SetRotateConfig(LV_GPU_NXP_PXP_ID, kPXP_RotateOutputBuffer, pxp_rot, kPXP_FlipDisable);
240
+
241
+ pxp_as_blend_config_t asBlendConfig = {
242
+ .alpha = opa,
243
+ .invertAlpha = false,
244
+ .alphaMode = kPXP_AlphaRop,
245
+ .ropMode = kPXP_RopMergeAs
246
+ };
247
+
248
+ if(opa >= (lv_opa_t)LV_OPA_MAX) {
249
+ /*Simple blit, no effect - Disable PS buffer*/
250
+ PXP_SetProcessSurfacePosition(LV_GPU_NXP_PXP_ID, 0xFFFFU, 0xFFFFU, 0U, 0U);
251
+ }
252
+ else {
253
+ pxp_ps_buffer_config_t psBufferConfig = {
254
+ .pixelFormat = PXP_PS_PIXEL_FORMAT,
255
+ .swapByte = false,
256
+ .bufferAddr = (uint32_t)(dest_buf + dest_stride * dest_area->y1 + dest_area->x1),
257
+ .bufferAddrU = 0U,
258
+ .bufferAddrV = 0U,
259
+ .pitchBytes = dest_stride * sizeof(lv_color_t)
260
+ };
261
+
262
+ asBlendConfig.alphaMode = kPXP_AlphaOverride;
263
+
264
+ PXP_SetProcessSurfaceBufferConfig(LV_GPU_NXP_PXP_ID, &psBufferConfig);
265
+ PXP_SetProcessSurfacePosition(LV_GPU_NXP_PXP_ID, 0U, 0U, dest_w - 1U, dest_h - 1U);
266
+ }
267
+
268
+ /*AS buffer - source image*/
269
+ pxp_as_buffer_config_t asBufferConfig = {
270
+ .pixelFormat = PXP_AS_PIXEL_FORMAT,
271
+ .bufferAddr = (uint32_t)(src_buf + src_stride * src_area->y1 + src_area->x1),
272
+ .pitchBytes = src_stride * sizeof(lv_color_t)
273
+ };
274
+ PXP_SetAlphaSurfaceBufferConfig(LV_GPU_NXP_PXP_ID, &asBufferConfig);
275
+ PXP_SetAlphaSurfacePosition(LV_GPU_NXP_PXP_ID, 0U, 0U, src_w - 1U, src_h - 1U);
276
+ PXP_SetAlphaSurfaceBlendConfig(LV_GPU_NXP_PXP_ID, &asBlendConfig);
277
+ PXP_EnableAlphaSurfaceOverlayColorKey(LV_GPU_NXP_PXP_ID, false);
278
+
279
+ /*Output buffer.*/
280
+ pxp_output_buffer_config_t outputBufferConfig = {
281
+ .pixelFormat = (pxp_output_pixel_format_t)PXP_OUT_PIXEL_FORMAT,
282
+ .interlacedMode = kPXP_OutputProgressive,
283
+ .buffer0Addr = (uint32_t)(dest_buf + dest_stride * dest_area->y1 + dest_area->x1),
284
+ .buffer1Addr = (uint32_t)0U,
285
+ .pitchBytes = dest_stride * sizeof(lv_color_t),
286
+ .width = dest_w,
287
+ .height = dest_h
288
+ };
289
+ PXP_SetOutputBufferConfig(LV_GPU_NXP_PXP_ID, &outputBufferConfig);
290
+
291
+ lv_gpu_nxp_pxp_run();
292
+ }
293
+
294
+ void lv_gpu_nxp_pxp_blit_transform(lv_color_t * dest_buf, lv_area_t * dest_area, lv_coord_t dest_stride,
295
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride,
296
+ const lv_draw_img_dsc_t * dsc, lv_img_cf_t cf)
297
+ {
298
+ bool has_recolor = (dsc->recolor_opa != LV_OPA_TRANSP);
299
+ bool has_rotation = (dsc->angle != 0);
300
+
301
+ if(has_recolor || has_rotation) {
302
+ if(dsc->opa >= (lv_opa_t)LV_OPA_MAX && !lv_img_cf_has_alpha(cf) && !lv_img_cf_is_chroma_keyed(cf)) {
303
+ lv_pxp_blit_cover(dest_buf, dest_area, dest_stride, src_buf, src_area, src_stride, dsc, cf);
304
+ return;
305
+ }
306
+ else {
307
+ /*Recolor and/or rotation with alpha or opacity is done in two steps.*/
308
+ lv_pxp_blit_opa(dest_buf, dest_area, dest_stride, src_buf, src_area, src_stride, dsc, cf);
309
+ return;
310
+ }
311
+ }
312
+
313
+ lv_pxp_blit_cf(dest_buf, dest_area, dest_stride, src_buf, src_area, src_stride, dsc, cf);
314
+ }
315
+
316
+ void lv_gpu_nxp_pxp_buffer_copy(lv_color_t * dest_buf, const lv_area_t * dest_area, lv_coord_t dest_stride,
317
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride)
318
+ {
319
+ lv_coord_t src_width = lv_area_get_width(src_area);
320
+ lv_coord_t src_height = lv_area_get_height(src_area);
321
+
322
+ lv_gpu_nxp_pxp_reset();
323
+
324
+ const pxp_pic_copy_config_t picCopyConfig = {
325
+ .srcPicBaseAddr = (uint32_t)src_buf,
326
+ .srcPitchBytes = src_stride * sizeof(lv_color_t),
327
+ .srcOffsetX = src_area->x1,
328
+ .srcOffsetY = src_area->y1,
329
+ .destPicBaseAddr = (uint32_t)dest_buf,
330
+ .destPitchBytes = dest_stride * sizeof(lv_color_t),
331
+ .destOffsetX = dest_area->x1,
332
+ .destOffsetY = dest_area->y1,
333
+ .width = src_width,
334
+ .height = src_height,
335
+ .pixelFormat = PXP_AS_PIXEL_FORMAT
336
+ };
337
+
338
+ PXP_StartPictureCopy(LV_GPU_NXP_PXP_ID, &picCopyConfig);
339
+
340
+ lv_gpu_nxp_pxp_wait();
341
+ }
342
+
343
+ /**********************
344
+ * STATIC FUNCTIONS
345
+ **********************/
346
+
347
+ static void lv_pxp_blit_opa(lv_color_t * dest_buf, const lv_area_t * dest_area, lv_coord_t dest_stride,
348
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride,
349
+ const lv_draw_img_dsc_t * dsc, lv_img_cf_t cf)
350
+ {
351
+ lv_area_t temp_area;
352
+ lv_area_copy(&temp_area, dest_area);
353
+ lv_coord_t temp_stride = dest_stride;
354
+ lv_coord_t temp_w = lv_area_get_width(&temp_area);
355
+ lv_coord_t temp_h = lv_area_get_height(&temp_area);
356
+
357
+ /*Step 1: Transform with full opacity to temporary buffer*/
358
+ lv_pxp_blit_cover((lv_color_t *)temp_buf, &temp_area, temp_stride, src_buf, src_area, src_stride, dsc, cf);
359
+
360
+ /*Switch width and height if angle requires it*/
361
+ if(dsc->angle == 900 || dsc->angle == 2700) {
362
+ temp_area.x2 = temp_area.x1 + temp_h - 1;
363
+ temp_area.y2 = temp_area.y1 + temp_w - 1;
364
+ }
365
+
366
+ /*Step 2: Blit temporary result with required opacity to output*/
367
+ lv_pxp_blit_cf(dest_buf, &temp_area, dest_stride, (lv_color_t *)temp_buf, &temp_area, temp_stride, dsc, cf);
368
+ }
369
+ static void lv_pxp_blit_cover(lv_color_t * dest_buf, lv_area_t * dest_area, lv_coord_t dest_stride,
370
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride,
371
+ const lv_draw_img_dsc_t * dsc, lv_img_cf_t cf)
372
+ {
373
+ lv_coord_t dest_w = lv_area_get_width(dest_area);
374
+ lv_coord_t dest_h = lv_area_get_height(dest_area);
375
+ lv_coord_t src_w = lv_area_get_width(src_area);
376
+ lv_coord_t src_h = lv_area_get_height(src_area);
377
+
378
+ bool has_recolor = (dsc->recolor_opa != LV_OPA_TRANSP);
379
+ bool has_rotation = (dsc->angle != 0);
380
+
381
+ lv_point_t pivot = dsc->pivot;
382
+ lv_coord_t piv_offset_x;
383
+ lv_coord_t piv_offset_y;
384
+
385
+ lv_gpu_nxp_pxp_reset();
386
+
387
+ if(has_rotation) {
388
+ /*Convert rotation angle and calculate offsets caused by pivot*/
389
+ pxp_rotate_degree_t pxp_angle;
390
+ switch(dsc->angle) {
391
+ case 0:
392
+ pxp_angle = kPXP_Rotate0;
393
+ piv_offset_x = 0;
394
+ piv_offset_y = 0;
395
+ break;
396
+ case 900:
397
+ piv_offset_x = pivot.x + pivot.y - dest_h;
398
+ piv_offset_y = pivot.y - pivot.x;
399
+ pxp_angle = kPXP_Rotate90;
400
+ break;
401
+ case 1800:
402
+ piv_offset_x = 2 * pivot.x - dest_w;
403
+ piv_offset_y = 2 * pivot.y - dest_h;
404
+ pxp_angle = kPXP_Rotate180;
405
+ break;
406
+ case 2700:
407
+ piv_offset_x = pivot.x - pivot.y;
408
+ piv_offset_y = pivot.x + pivot.y - dest_w;
409
+ pxp_angle = kPXP_Rotate270;
410
+ break;
411
+ default:
412
+ piv_offset_x = 0;
413
+ piv_offset_y = 0;
414
+ pxp_angle = kPXP_Rotate0;
415
+ }
416
+ PXP_SetRotateConfig(LV_GPU_NXP_PXP_ID, kPXP_RotateOutputBuffer, pxp_angle, kPXP_FlipDisable);
417
+ lv_area_move(dest_area, piv_offset_x, piv_offset_y);
418
+ }
419
+
420
+ /*AS buffer - source image*/
421
+ pxp_as_buffer_config_t asBufferConfig = {
422
+ .pixelFormat = PXP_AS_PIXEL_FORMAT,
423
+ .bufferAddr = (uint32_t)(src_buf + src_stride * src_area->y1 + src_area->x1),
424
+ .pitchBytes = src_stride * sizeof(lv_color_t)
425
+ };
426
+ PXP_SetAlphaSurfaceBufferConfig(LV_GPU_NXP_PXP_ID, &asBufferConfig);
427
+ PXP_SetAlphaSurfacePosition(LV_GPU_NXP_PXP_ID, 0U, 0U, src_w - 1U, src_h - 1U);
428
+
429
+ /*Disable PS buffer*/
430
+ PXP_SetProcessSurfacePosition(LV_GPU_NXP_PXP_ID, 0xFFFFU, 0xFFFFU, 0U, 0U);
431
+ if(has_recolor)
432
+ /*Use as color generator*/
433
+ PXP_SetProcessSurfaceBackGroundColor(LV_GPU_NXP_PXP_ID, lv_color_to32(dsc->recolor));
434
+
435
+ /*Output buffer*/
436
+ pxp_output_buffer_config_t outputBufferConfig = {
437
+ .pixelFormat = (pxp_output_pixel_format_t)PXP_OUT_PIXEL_FORMAT,
438
+ .interlacedMode = kPXP_OutputProgressive,
439
+ .buffer0Addr = (uint32_t)(dest_buf + dest_stride * dest_area->y1 + dest_area->x1),
440
+ .buffer1Addr = (uint32_t)0U,
441
+ .pitchBytes = dest_stride * sizeof(lv_color_t),
442
+ .width = dest_w,
443
+ .height = dest_h
444
+ };
445
+ PXP_SetOutputBufferConfig(LV_GPU_NXP_PXP_ID, &outputBufferConfig);
446
+
447
+ if(has_recolor || lv_img_cf_has_alpha(cf)) {
448
+ /**
449
+ * Configure Porter-Duff blending.
450
+ *
451
+ * Note: srcFactorMode and dstFactorMode are inverted in fsl_pxp.h:
452
+ * srcFactorMode is actually applied on PS alpha value
453
+ * dstFactorMode is actually applied on AS alpha value
454
+ */
455
+ pxp_porter_duff_config_t pdConfig = {
456
+ .enable = 1,
457
+ .dstColorMode = kPXP_PorterDuffColorWithAlpha,
458
+ .srcColorMode = kPXP_PorterDuffColorNoAlpha,
459
+ .dstGlobalAlphaMode = kPXP_PorterDuffGlobalAlpha,
460
+ .srcGlobalAlphaMode = lv_img_cf_has_alpha(cf) ? kPXP_PorterDuffLocalAlpha : kPXP_PorterDuffGlobalAlpha,
461
+ .dstFactorMode = kPXP_PorterDuffFactorStraight,
462
+ .srcFactorMode = kPXP_PorterDuffFactorInversed,
463
+ .dstGlobalAlpha = has_recolor ? dsc->recolor_opa : 0x00,
464
+ .srcGlobalAlpha = 0xff,
465
+ .dstAlphaMode = kPXP_PorterDuffAlphaStraight, /*don't care*/
466
+ .srcAlphaMode = kPXP_PorterDuffAlphaStraight
467
+ };
468
+ PXP_SetPorterDuffConfig(LV_GPU_NXP_PXP_ID, &pdConfig);
469
+ }
470
+
471
+ lv_gpu_nxp_pxp_run();
472
+ }
473
+
474
+ static void lv_pxp_blit_cf(lv_color_t * dest_buf, const lv_area_t * dest_area, lv_coord_t dest_stride,
475
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride,
476
+ const lv_draw_img_dsc_t * dsc, lv_img_cf_t cf)
477
+ {
478
+ lv_coord_t dest_w = lv_area_get_width(dest_area);
479
+ lv_coord_t dest_h = lv_area_get_height(dest_area);
480
+ lv_coord_t src_w = lv_area_get_width(src_area);
481
+ lv_coord_t src_h = lv_area_get_height(src_area);
482
+
483
+ lv_gpu_nxp_pxp_reset();
484
+
485
+ pxp_as_blend_config_t asBlendConfig = {
486
+ .alpha = dsc->opa,
487
+ .invertAlpha = false,
488
+ .alphaMode = kPXP_AlphaRop,
489
+ .ropMode = kPXP_RopMergeAs
490
+ };
491
+
492
+ if(dsc->opa >= (lv_opa_t)LV_OPA_MAX && !lv_img_cf_is_chroma_keyed(cf) && !lv_img_cf_has_alpha(cf)) {
493
+ /*Simple blit, no effect - Disable PS buffer*/
494
+ PXP_SetProcessSurfacePosition(LV_GPU_NXP_PXP_ID, 0xFFFFU, 0xFFFFU, 0U, 0U);
495
+ }
496
+ else {
497
+ /*PS must be enabled to fetch background pixels.
498
+ PS and OUT buffers are the same, blend will be done in-place*/
499
+ pxp_ps_buffer_config_t psBufferConfig = {
500
+ .pixelFormat = PXP_PS_PIXEL_FORMAT,
501
+ .swapByte = false,
502
+ .bufferAddr = (uint32_t)(dest_buf + dest_stride * dest_area->y1 + dest_area->x1),
503
+ .bufferAddrU = 0U,
504
+ .bufferAddrV = 0U,
505
+ .pitchBytes = dest_stride * sizeof(lv_color_t)
506
+ };
507
+ if(dsc->opa >= (lv_opa_t)LV_OPA_MAX) {
508
+ asBlendConfig.alphaMode = lv_img_cf_has_alpha(cf) ? kPXP_AlphaEmbedded : kPXP_AlphaOverride;
509
+ }
510
+ else {
511
+ asBlendConfig.alphaMode = lv_img_cf_has_alpha(cf) ? kPXP_AlphaMultiply : kPXP_AlphaOverride;
512
+ }
513
+ PXP_SetProcessSurfaceBufferConfig(LV_GPU_NXP_PXP_ID, &psBufferConfig);
514
+ PXP_SetProcessSurfacePosition(LV_GPU_NXP_PXP_ID, 0U, 0U, dest_w - 1U, dest_h - 1U);
515
+ }
516
+
517
+ /*AS buffer - source image*/
518
+ pxp_as_buffer_config_t asBufferConfig = {
519
+ .pixelFormat = PXP_AS_PIXEL_FORMAT,
520
+ .bufferAddr = (uint32_t)(src_buf + src_stride * src_area->y1 + src_area->x1),
521
+ .pitchBytes = src_stride * sizeof(lv_color_t)
522
+ };
523
+ PXP_SetAlphaSurfaceBufferConfig(LV_GPU_NXP_PXP_ID, &asBufferConfig);
524
+ PXP_SetAlphaSurfacePosition(LV_GPU_NXP_PXP_ID, 0U, 0U, src_w - 1U, src_h - 1U);
525
+ PXP_SetAlphaSurfaceBlendConfig(LV_GPU_NXP_PXP_ID, &asBlendConfig);
526
+
527
+ if(lv_img_cf_is_chroma_keyed(cf)) {
528
+ lv_color_t colorKeyLow = LV_COLOR_CHROMA_KEY;
529
+ lv_color_t colorKeyHigh = LV_COLOR_CHROMA_KEY;
530
+
531
+ bool has_recolor = (dsc->recolor_opa != LV_OPA_TRANSP);
532
+
533
+ if(has_recolor) {
534
+ /* New color key after recoloring */
535
+ lv_color_t colorKey = lv_color_mix(dsc->recolor, LV_COLOR_CHROMA_KEY, dsc->recolor_opa);
536
+
537
+ LV_COLOR_SET_R(colorKeyLow, colorKey.ch.red != 0 ? colorKey.ch.red - 1 : 0);
538
+ LV_COLOR_SET_G(colorKeyLow, colorKey.ch.green != 0 ? colorKey.ch.green - 1 : 0);
539
+ LV_COLOR_SET_B(colorKeyLow, colorKey.ch.blue != 0 ? colorKey.ch.blue - 1 : 0);
540
+
541
+ #if LV_COLOR_DEPTH == 16
542
+ LV_COLOR_SET_R(colorKeyHigh, colorKey.ch.red != 0x1f ? colorKey.ch.red + 1 : 0x1f);
543
+ LV_COLOR_SET_G(colorKeyHigh, colorKey.ch.green != 0x3f ? colorKey.ch.green + 1 : 0x3f);
544
+ LV_COLOR_SET_B(colorKeyHigh, colorKey.ch.blue != 0x1f ? colorKey.ch.blue + 1 : 0x1f);
545
+ #else /*LV_COLOR_DEPTH == 32*/
546
+ LV_COLOR_SET_R(colorKeyHigh, colorKey.ch.red != 0xff ? colorKey.ch.red + 1 : 0xff);
547
+ LV_COLOR_SET_G(colorKeyHigh, colorKey.ch.green != 0xff ? colorKey.ch.green + 1 : 0xff);
548
+ LV_COLOR_SET_B(colorKeyHigh, colorKey.ch.blue != 0xff ? colorKey.ch.blue + 1 : 0xff);
549
+ #endif
550
+ }
551
+
552
+ PXP_SetAlphaSurfaceOverlayColorKey(LV_GPU_NXP_PXP_ID, lv_color_to32(colorKeyLow),
553
+ lv_color_to32(colorKeyHigh));
554
+ }
555
+
556
+ PXP_EnableAlphaSurfaceOverlayColorKey(LV_GPU_NXP_PXP_ID, lv_img_cf_is_chroma_keyed(cf));
557
+
558
+ /*Output buffer.*/
559
+ pxp_output_buffer_config_t outputBufferConfig = {
560
+ .pixelFormat = (pxp_output_pixel_format_t)PXP_OUT_PIXEL_FORMAT,
561
+ .interlacedMode = kPXP_OutputProgressive,
562
+ .buffer0Addr = (uint32_t)(dest_buf + dest_stride * dest_area->y1 + dest_area->x1),
563
+ .buffer1Addr = (uint32_t)0U,
564
+ .pitchBytes = dest_stride * sizeof(lv_color_t),
565
+ .width = dest_w,
566
+ .height = dest_h
567
+ };
568
+ PXP_SetOutputBufferConfig(LV_GPU_NXP_PXP_ID, &outputBufferConfig);
569
+
570
+ lv_gpu_nxp_pxp_run();
571
+ }
572
+
573
+ #endif /*LV_USE_GPU_NXP_PXP*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/pxp/lv_draw_pxp_blend.h ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_pxp_blend.h
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2020-2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ #ifndef LV_DRAW_PXP_BLEND_H
31
+ #define LV_DRAW_PXP_BLEND_H
32
+
33
+ #ifdef __cplusplus
34
+ extern "C" {
35
+ #endif
36
+
37
+ /*********************
38
+ * INCLUDES
39
+ *********************/
40
+
41
+ #include "../../../lv_conf_internal.h"
42
+
43
+ #if LV_USE_GPU_NXP_PXP
44
+ #include "lv_gpu_nxp_pxp.h"
45
+ #include "../../sw/lv_draw_sw.h"
46
+
47
+ /*********************
48
+ * DEFINES
49
+ *********************/
50
+
51
+ /**********************
52
+ * TYPEDEFS
53
+ **********************/
54
+
55
+ /**********************
56
+ * GLOBAL PROTOTYPES
57
+ **********************/
58
+
59
+ /**
60
+ * Fill area, with optional opacity.
61
+ *
62
+ * @param[in/out] dest_buf Destination buffer
63
+ * @param[in] dest_area Area with relative coordinates of destination buffer
64
+ * @param[in] dest_stride Stride of destination buffer in pixels
65
+ * @param[in] color Color
66
+ * @param[in] opa Opacity
67
+ */
68
+ void lv_gpu_nxp_pxp_fill(lv_color_t * dest_buf, const lv_area_t * dest_area, lv_coord_t dest_stride,
69
+ lv_color_t color, lv_opa_t opa);
70
+
71
+ /**
72
+ * BLock Image Transfer - copy rectangular image from src_buf to dst_buf with effects.
73
+ * By default, image is copied directly, with optional opacity. This function can also
74
+ * rotate the display output buffer to a specified angle (90x step).
75
+ *
76
+ * @param[in/out] dest_buf Destination buffer
77
+ * @param[in] dest_area Area with relative coordinates of destination buffer
78
+ * @param[in] dest_stride Stride of destination buffer in pixels
79
+ * @param[in] src_buf Source buffer
80
+ * @param[in] src_area Source area with relative coordinates of source buffer
81
+ * @param[in] src_stride Stride of source buffer in pixels
82
+ * @param[in] opa Opacity
83
+ * @param[in] angle Display rotation angle (90x)
84
+ */
85
+ void lv_gpu_nxp_pxp_blit(lv_color_t * dest_buf, const lv_area_t * dest_area, lv_coord_t dest_stride,
86
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride,
87
+ lv_opa_t opa, lv_disp_rot_t angle);
88
+
89
+ /**
90
+ * BLock Image Transfer - copy rectangular image from src_buf to dst_buf with transformation.
91
+ *
92
+ *
93
+ * @param[in/out] dest_buf Destination buffer
94
+ * @param[in] dest_area Area with relative coordinates of destination buffer
95
+ * @param[in] dest_stride Stride of destination buffer in pixels
96
+ * @param[in] src_buf Source buffer
97
+ * @param[in] src_area Area with relative coordinates of source buffer
98
+ * @param[in] src_stride Stride of source buffer in pixels
99
+ * @param[in] dsc Image descriptor
100
+ * @param[in] cf Color format
101
+ */
102
+ void lv_gpu_nxp_pxp_blit_transform(lv_color_t * dest_buf, lv_area_t * dest_area, lv_coord_t dest_stride,
103
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride,
104
+ const lv_draw_img_dsc_t * dsc, lv_img_cf_t cf);
105
+
106
+ /**
107
+ * BLock Image Transfer - copy rectangular image from src_buf to dst_buf, no transformation or blending.
108
+ *
109
+ *
110
+ * @param[in/out] dest_buf Destination buffer
111
+ * @param[in] dest_area Area with relative coordinates of destination buffer
112
+ * @param[in] dest_stride Stride of destination buffer in pixels
113
+ * @param[in] src_buf Source buffer
114
+ * @param[in] src_area Area with relative coordinates of source buffer
115
+ * @param[in] src_stride Stride of source buffer in pixels
116
+ */
117
+ void lv_gpu_nxp_pxp_buffer_copy(lv_color_t * dest_buf, const lv_area_t * dest_area, lv_coord_t dest_stride,
118
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride);
119
+
120
+ /**********************
121
+ * MACROS
122
+ **********************/
123
+
124
+ #endif /*LV_USE_GPU_NXP_PXP*/
125
+
126
+ #ifdef __cplusplus
127
+ } /*extern "C"*/
128
+ #endif
129
+
130
+ #endif /*LV_DRAW_PXP_BLEND_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/pxp/lv_gpu_nxp_pxp.c ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_gpu_nxp_pxp.c
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2020-2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ /*********************
31
+ * INCLUDES
32
+ *********************/
33
+
34
+ #include "lv_gpu_nxp_pxp.h"
35
+
36
+ #if LV_USE_GPU_NXP_PXP
37
+ #include "lv_gpu_nxp_pxp_osa.h"
38
+ #include "../../../core/lv_refr.h"
39
+
40
+ /*********************
41
+ * DEFINES
42
+ *********************/
43
+
44
+ /**********************
45
+ * TYPEDEFS
46
+ **********************/
47
+
48
+ /**********************
49
+ * STATIC PROTOTYPES
50
+ **********************/
51
+
52
+ /**
53
+ * Clean and invalidate cache.
54
+ */
55
+ static inline void invalidate_cache(void);
56
+
57
+ /**********************
58
+ * STATIC VARIABLES
59
+ **********************/
60
+
61
+ static lv_nxp_pxp_cfg_t * pxp_cfg;
62
+
63
+ /**********************
64
+ * MACROS
65
+ **********************/
66
+
67
+ /**********************
68
+ * GLOBAL FUNCTIONS
69
+ **********************/
70
+
71
+ lv_res_t lv_gpu_nxp_pxp_init(void)
72
+ {
73
+ #if LV_USE_GPU_NXP_PXP_AUTO_INIT
74
+ pxp_cfg = lv_gpu_nxp_pxp_get_cfg();
75
+ #endif
76
+
77
+ if(!pxp_cfg || !pxp_cfg->pxp_interrupt_deinit || !pxp_cfg->pxp_interrupt_init ||
78
+ !pxp_cfg->pxp_run || !pxp_cfg->pxp_wait)
79
+ PXP_RETURN_INV("PXP configuration error.");
80
+
81
+ PXP_Init(LV_GPU_NXP_PXP_ID);
82
+
83
+ PXP_EnableCsc1(LV_GPU_NXP_PXP_ID, false); /*Disable CSC1, it is enabled by default.*/
84
+ PXP_SetProcessBlockSize(LV_GPU_NXP_PXP_ID, kPXP_BlockSize16); /*Block size 16x16 for higher performance*/
85
+
86
+ PXP_EnableInterrupts(LV_GPU_NXP_PXP_ID, kPXP_CompleteInterruptEnable);
87
+
88
+ if(pxp_cfg->pxp_interrupt_init() != LV_RES_OK) {
89
+ PXP_DisableInterrupts(LV_GPU_NXP_PXP_ID, kPXP_CompleteInterruptEnable);
90
+ PXP_Deinit(LV_GPU_NXP_PXP_ID);
91
+ PXP_RETURN_INV("PXP interrupt init failed.");
92
+ }
93
+
94
+ return LV_RES_OK;
95
+ }
96
+
97
+ void lv_gpu_nxp_pxp_deinit(void)
98
+ {
99
+ pxp_cfg->pxp_interrupt_deinit();
100
+ PXP_DisableInterrupts(LV_GPU_NXP_PXP_ID, kPXP_CompleteInterruptEnable);
101
+ PXP_Deinit(LV_GPU_NXP_PXP_ID);
102
+ }
103
+
104
+ void lv_gpu_nxp_pxp_reset(void)
105
+ {
106
+ /* Wait for previous command to complete before resetting the registers. */
107
+ lv_gpu_nxp_pxp_wait();
108
+
109
+ PXP_ResetControl(LV_GPU_NXP_PXP_ID);
110
+
111
+ PXP_EnableCsc1(LV_GPU_NXP_PXP_ID, false); /*Disable CSC1, it is enabled by default.*/
112
+ PXP_SetProcessBlockSize(LV_GPU_NXP_PXP_ID, kPXP_BlockSize16); /*Block size 16x16 for higher performance*/
113
+ }
114
+
115
+ void lv_gpu_nxp_pxp_run(void)
116
+ {
117
+ invalidate_cache();
118
+
119
+ pxp_cfg->pxp_run();
120
+ }
121
+
122
+ void lv_gpu_nxp_pxp_wait(void)
123
+ {
124
+ pxp_cfg->pxp_wait();
125
+ }
126
+
127
+ /**********************
128
+ * STATIC FUNCTIONS
129
+ **********************/
130
+
131
+ static inline void invalidate_cache(void)
132
+ {
133
+ lv_disp_t * disp = _lv_refr_get_disp_refreshing();
134
+ if(disp->driver->clean_dcache_cb)
135
+ disp->driver->clean_dcache_cb(disp->driver);
136
+ }
137
+
138
+ #endif /*LV_USE_GPU_NXP_PXP*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/pxp/lv_gpu_nxp_pxp.h ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_gpu_nxp_pxp.h
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2020-2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ #ifndef LV_GPU_NXP_PXP_H
31
+ #define LV_GPU_NXP_PXP_H
32
+
33
+ #ifdef __cplusplus
34
+ extern "C" {
35
+ #endif
36
+
37
+ /*********************
38
+ * INCLUDES
39
+ *********************/
40
+
41
+ #include "../../../lv_conf_internal.h"
42
+
43
+ #if LV_USE_GPU_NXP_PXP
44
+ #include "fsl_cache.h"
45
+ #include "fsl_pxp.h"
46
+
47
+ #include "../../../misc/lv_log.h"
48
+
49
+ /*********************
50
+ * DEFINES
51
+ *********************/
52
+
53
+ /** PXP module instance to use*/
54
+ #define LV_GPU_NXP_PXP_ID PXP
55
+
56
+ /** PXP interrupt line ID*/
57
+ #define LV_GPU_NXP_PXP_IRQ_ID PXP_IRQn
58
+
59
+ #ifndef LV_GPU_NXP_PXP_LOG_ERRORS
60
+ /** Enable logging of PXP errors (\see LV_LOG_ERROR)*/
61
+ #define LV_GPU_NXP_PXP_LOG_ERRORS 1
62
+ #endif
63
+
64
+ #ifndef LV_GPU_NXP_PXP_LOG_TRACES
65
+ /** Enable logging of PXP errors (\see LV_LOG_ERROR)*/
66
+ #define LV_GPU_NXP_PXP_LOG_TRACES 0
67
+ #endif
68
+
69
+ /**********************
70
+ * TYPEDEFS
71
+ **********************/
72
+
73
+ /**
74
+ * NXP PXP device configuration - call-backs used for
75
+ * interrupt init/wait/deinit.
76
+ */
77
+ typedef struct {
78
+ /** Callback for PXP interrupt initialization*/
79
+ lv_res_t (*pxp_interrupt_init)(void);
80
+
81
+ /** Callback for PXP interrupt de-initialization*/
82
+ void (*pxp_interrupt_deinit)(void);
83
+
84
+ /** Callback for PXP start*/
85
+ void (*pxp_run)(void);
86
+
87
+ /** Callback for waiting of PXP completion*/
88
+ void (*pxp_wait)(void);
89
+ } lv_nxp_pxp_cfg_t;
90
+
91
+ /**********************
92
+ * GLOBAL PROTOTYPES
93
+ **********************/
94
+
95
+ /**
96
+ * Reset and initialize PXP device. This function should be called as a part
97
+ * of display init sequence.
98
+ *
99
+ * @retval LV_RES_OK PXP init completed
100
+ * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_PXP_LOG_ERRORS)
101
+ */
102
+ lv_res_t lv_gpu_nxp_pxp_init(void);
103
+
104
+ /**
105
+ * Disable PXP device. Should be called during display deinit sequence.
106
+ */
107
+ void lv_gpu_nxp_pxp_deinit(void);
108
+
109
+ /**
110
+ * Reset PXP device.
111
+ */
112
+ void lv_gpu_nxp_pxp_reset(void);
113
+
114
+ /**
115
+ * Clear cache and start PXP.
116
+ */
117
+ void lv_gpu_nxp_pxp_run(void);
118
+
119
+ /**
120
+ * Wait for PXP completion.
121
+ */
122
+ void lv_gpu_nxp_pxp_wait(void);
123
+
124
+ /**********************
125
+ * MACROS
126
+ **********************/
127
+
128
+ #define PXP_COND_STOP(cond, txt) \
129
+ do { \
130
+ if (cond) { \
131
+ LV_LOG_ERROR("%s. STOP!", txt); \
132
+ for ( ; ; ); \
133
+ } \
134
+ } while(0)
135
+
136
+ #if LV_GPU_NXP_PXP_LOG_ERRORS
137
+ #define PXP_RETURN_INV(fmt, ...) \
138
+ do { \
139
+ LV_LOG_ERROR(fmt, ##__VA_ARGS__); \
140
+ return LV_RES_INV; \
141
+ } while (0)
142
+ #else
143
+ #define PXP_RETURN_INV(fmt, ...) \
144
+ do { \
145
+ return LV_RES_INV; \
146
+ }while(0)
147
+ #endif /*LV_GPU_NXP_PXP_LOG_ERRORS*/
148
+
149
+ #if LV_GPU_NXP_PXP_LOG_TRACES
150
+ #define PXP_LOG_TRACE(fmt, ...) \
151
+ do { \
152
+ LV_LOG(fmt, ##__VA_ARGS__); \
153
+ } while (0)
154
+ #else
155
+ #define PXP_LOG_TRACE(fmt, ...) \
156
+ do { \
157
+ } while (0)
158
+ #endif /*LV_GPU_NXP_PXP_LOG_TRACES*/
159
+
160
+ #endif /*LV_USE_GPU_NXP_PXP*/
161
+
162
+ #ifdef __cplusplus
163
+ } /*extern "C"*/
164
+ #endif
165
+
166
+ #endif /*LV_GPU_NXP_PXP_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/pxp/lv_gpu_nxp_pxp_osa.c ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_gpu_nxp_pxp_osa.c
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2020, 2022, 2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ /*********************
31
+ * INCLUDES
32
+ *********************/
33
+
34
+ #include "lv_gpu_nxp_pxp_osa.h"
35
+
36
+ #if LV_USE_GPU_NXP_PXP && LV_USE_GPU_NXP_PXP_AUTO_INIT
37
+ #include "../../../misc/lv_log.h"
38
+ #include "fsl_pxp.h"
39
+
40
+ #if defined(SDK_OS_FREE_RTOS)
41
+ #include "FreeRTOS.h"
42
+ #include "semphr.h"
43
+ #endif
44
+
45
+ /*********************
46
+ * DEFINES
47
+ *********************/
48
+
49
+ /**********************
50
+ * TYPEDEFS
51
+ **********************/
52
+
53
+ /**********************
54
+ * STATIC PROTOTYPES
55
+ **********************/
56
+
57
+ /**
58
+ * PXP interrupt initialization.
59
+ */
60
+ static lv_res_t _lv_gpu_nxp_pxp_interrupt_init(void);
61
+
62
+ /**
63
+ * PXP interrupt de-initialization.
64
+ */
65
+ static void _lv_gpu_nxp_pxp_interrupt_deinit(void);
66
+
67
+ /**
68
+ * Start the PXP job.
69
+ */
70
+ static void _lv_gpu_nxp_pxp_run(void);
71
+
72
+ /**
73
+ * Wait for PXP completion.
74
+ */
75
+ static void _lv_gpu_nxp_pxp_wait(void);
76
+
77
+ /**********************
78
+ * STATIC VARIABLES
79
+ **********************/
80
+
81
+ #if defined(SDK_OS_FREE_RTOS)
82
+ static SemaphoreHandle_t s_pxpIdleSem;
83
+ #endif
84
+ static volatile bool s_pxpIdle;
85
+
86
+ static lv_nxp_pxp_cfg_t pxp_default_cfg = {
87
+ .pxp_interrupt_init = _lv_gpu_nxp_pxp_interrupt_init,
88
+ .pxp_interrupt_deinit = _lv_gpu_nxp_pxp_interrupt_deinit,
89
+ .pxp_run = _lv_gpu_nxp_pxp_run,
90
+ .pxp_wait = _lv_gpu_nxp_pxp_wait,
91
+ };
92
+
93
+ /**********************
94
+ * MACROS
95
+ **********************/
96
+
97
+ /**********************
98
+ * GLOBAL FUNCTIONS
99
+ **********************/
100
+
101
+ void PXP_IRQHandler(void)
102
+ {
103
+ #if defined(SDK_OS_FREE_RTOS)
104
+ BaseType_t taskAwake = pdFALSE;
105
+ #endif
106
+
107
+ if(kPXP_CompleteFlag & PXP_GetStatusFlags(LV_GPU_NXP_PXP_ID)) {
108
+ PXP_ClearStatusFlags(LV_GPU_NXP_PXP_ID, kPXP_CompleteFlag);
109
+ #if defined(SDK_OS_FREE_RTOS)
110
+ xSemaphoreGiveFromISR(s_pxpIdleSem, &taskAwake);
111
+ portYIELD_FROM_ISR(taskAwake);
112
+ #else
113
+ s_pxpIdle = true;
114
+ #endif
115
+ }
116
+ }
117
+
118
+ lv_nxp_pxp_cfg_t * lv_gpu_nxp_pxp_get_cfg(void)
119
+ {
120
+ return &pxp_default_cfg;
121
+ }
122
+
123
+ /**********************
124
+ * STATIC FUNCTIONS
125
+ **********************/
126
+
127
+ static lv_res_t _lv_gpu_nxp_pxp_interrupt_init(void)
128
+ {
129
+ #if defined(SDK_OS_FREE_RTOS)
130
+ s_pxpIdleSem = xSemaphoreCreateBinary();
131
+ if(s_pxpIdleSem == NULL)
132
+ return LV_RES_INV;
133
+
134
+ NVIC_SetPriority(LV_GPU_NXP_PXP_IRQ_ID, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 1);
135
+ #endif
136
+ s_pxpIdle = true;
137
+
138
+ NVIC_EnableIRQ(LV_GPU_NXP_PXP_IRQ_ID);
139
+
140
+ return LV_RES_OK;
141
+ }
142
+
143
+ static void _lv_gpu_nxp_pxp_interrupt_deinit(void)
144
+ {
145
+ NVIC_DisableIRQ(LV_GPU_NXP_PXP_IRQ_ID);
146
+ #if defined(SDK_OS_FREE_RTOS)
147
+ vSemaphoreDelete(s_pxpIdleSem);
148
+ #endif
149
+ }
150
+
151
+ /**
152
+ * Function to start PXP job.
153
+ */
154
+ static void _lv_gpu_nxp_pxp_run(void)
155
+ {
156
+ s_pxpIdle = false;
157
+
158
+ PXP_EnableInterrupts(LV_GPU_NXP_PXP_ID, kPXP_CompleteInterruptEnable);
159
+ PXP_Start(LV_GPU_NXP_PXP_ID);
160
+ }
161
+
162
+ /**
163
+ * Function to wait for PXP completion.
164
+ */
165
+ static void _lv_gpu_nxp_pxp_wait(void)
166
+ {
167
+ #if defined(SDK_OS_FREE_RTOS)
168
+ /* Return if PXP was never started, otherwise the semaphore will lock forever. */
169
+ if(s_pxpIdle == true)
170
+ return;
171
+
172
+ if(xSemaphoreTake(s_pxpIdleSem, portMAX_DELAY) == pdTRUE)
173
+ s_pxpIdle = true;
174
+ #else
175
+ while(s_pxpIdle == false) {
176
+ }
177
+ #endif
178
+ }
179
+
180
+ #endif /*LV_USE_GPU_NXP_PXP && LV_USE_GPU_NXP_PXP_AUTO_INIT*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/pxp/lv_gpu_nxp_pxp_osa.h ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_gpu_nxp_pxp_osa.h
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2020, 2022 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ #ifndef LV_GPU_NXP_PXP_OSA_H
31
+ #define LV_GPU_NXP_PXP_OSA_H
32
+
33
+ #ifdef __cplusplus
34
+ extern "C" {
35
+ #endif
36
+
37
+ /*********************
38
+ * INCLUDES
39
+ *********************/
40
+
41
+ #include "../../../lv_conf_internal.h"
42
+
43
+ #if LV_USE_GPU_NXP_PXP && LV_USE_GPU_NXP_PXP_AUTO_INIT
44
+ #include "lv_gpu_nxp_pxp.h"
45
+
46
+ /*********************
47
+ * DEFINES
48
+ *********************/
49
+
50
+ /**********************
51
+ * TYPEDEFS
52
+ **********************/
53
+
54
+ /**********************
55
+ * GLOBAL PROTOTYPES
56
+ **********************/
57
+
58
+ /**
59
+ * PXP device interrupt handler. Used to check PXP task completion status.
60
+ */
61
+ void PXP_IRQHandler(void);
62
+
63
+ /**
64
+ * Helper function to get the PXP default configuration.
65
+ */
66
+ lv_nxp_pxp_cfg_t * lv_gpu_nxp_pxp_get_cfg(void);
67
+
68
+ /**********************
69
+ * MACROS
70
+ **********************/
71
+
72
+ #endif /*LV_USE_GPU_NXP_PXP && LV_USE_GPU_NXP_PXP_AUTO_INIT*/
73
+
74
+ #ifdef __cplusplus
75
+ } /*extern "C"*/
76
+ #endif
77
+
78
+ #endif /*LV_GPU_NXP_PXP_OSA_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite.c ADDED
@@ -0,0 +1,557 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_vglite.c
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2022, 2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ /*********************
31
+ * INCLUDES
32
+ *********************/
33
+
34
+ #include "lv_draw_vglite.h"
35
+
36
+ #if LV_USE_GPU_NXP_VG_LITE
37
+ #include <math.h>
38
+ #include "lv_draw_vglite_blend.h"
39
+ #include "lv_draw_vglite_line.h"
40
+ #include "lv_draw_vglite_rect.h"
41
+ #include "lv_draw_vglite_arc.h"
42
+ #include "lv_vglite_buf.h"
43
+
44
+ #if LV_COLOR_DEPTH != 32
45
+ #include "../../../core/lv_refr.h"
46
+ #endif
47
+
48
+ /*********************
49
+ * DEFINES
50
+ *********************/
51
+
52
+ /* Minimum area (in pixels) for VG-Lite blit/fill processing. */
53
+ #ifndef LV_GPU_NXP_VG_LITE_SIZE_LIMIT
54
+ #define LV_GPU_NXP_VG_LITE_SIZE_LIMIT 5000
55
+ #endif
56
+
57
+ /**********************
58
+ * TYPEDEFS
59
+ **********************/
60
+
61
+ /**********************
62
+ * STATIC PROTOTYPES
63
+ **********************/
64
+
65
+ static void lv_draw_vglite_init_buf(lv_draw_ctx_t * draw_ctx);
66
+
67
+ static void lv_draw_vglite_wait_for_finish(lv_draw_ctx_t * draw_ctx);
68
+
69
+ static void lv_draw_vglite_img_decoded(lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * dsc,
70
+ const lv_area_t * coords, const uint8_t * map_p, lv_img_cf_t cf);
71
+
72
+ static void lv_draw_vglite_buffer_copy(lv_draw_ctx_t * draw_ctx,
73
+ void * dest_buf, lv_coord_t dest_stride, const lv_area_t * dest_area,
74
+ void * src_buf, lv_coord_t src_stride, const lv_area_t * src_area);
75
+
76
+ static void lv_draw_vglite_blend(lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc);
77
+
78
+ static void lv_draw_vglite_line(lv_draw_ctx_t * draw_ctx, const lv_draw_line_dsc_t * dsc, const lv_point_t * point1,
79
+ const lv_point_t * point2);
80
+
81
+ static void lv_draw_vglite_rect(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords);
82
+
83
+ static lv_res_t lv_draw_vglite_bg(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords);
84
+
85
+ static lv_res_t lv_draw_vglite_border(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc,
86
+ const lv_area_t * coords);
87
+
88
+ static lv_res_t lv_draw_vglite_outline(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc,
89
+ const lv_area_t * coords);
90
+
91
+ static void lv_draw_vglite_arc(lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * dsc, const lv_point_t * center,
92
+ uint16_t radius, uint16_t start_angle, uint16_t end_angle);
93
+
94
+ /**********************
95
+ * STATIC VARIABLES
96
+ **********************/
97
+
98
+ /**********************
99
+ * MACROS
100
+ **********************/
101
+
102
+ /**********************
103
+ * GLOBAL FUNCTIONS
104
+ **********************/
105
+
106
+ void lv_draw_vglite_ctx_init(lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx)
107
+ {
108
+ lv_draw_sw_init_ctx(drv, draw_ctx);
109
+
110
+ lv_draw_vglite_ctx_t * vglite_draw_ctx = (lv_draw_sw_ctx_t *)draw_ctx;
111
+ vglite_draw_ctx->base_draw.init_buf = lv_draw_vglite_init_buf;
112
+ vglite_draw_ctx->base_draw.draw_line = lv_draw_vglite_line;
113
+ vglite_draw_ctx->base_draw.draw_arc = lv_draw_vglite_arc;
114
+ vglite_draw_ctx->base_draw.draw_rect = lv_draw_vglite_rect;
115
+ vglite_draw_ctx->base_draw.draw_img_decoded = lv_draw_vglite_img_decoded;
116
+ vglite_draw_ctx->blend = lv_draw_vglite_blend;
117
+ vglite_draw_ctx->base_draw.wait_for_finish = lv_draw_vglite_wait_for_finish;
118
+ vglite_draw_ctx->base_draw.buffer_copy = lv_draw_vglite_buffer_copy;
119
+ }
120
+
121
+ void lv_draw_vglite_ctx_deinit(lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx)
122
+ {
123
+ lv_draw_sw_deinit_ctx(drv, draw_ctx);
124
+ }
125
+
126
+ /**********************
127
+ * STATIC FUNCTIONS
128
+ **********************/
129
+
130
+ /**
131
+ * During rendering, LVGL might initializes new draw_ctxs and start drawing into
132
+ * a separate buffer (called layer). If the content to be rendered has "holes",
133
+ * e.g. rounded corner, LVGL temporarily sets the disp_drv.screen_transp flag.
134
+ * It means the renderers should draw into an ARGB buffer.
135
+ * With 32 bit color depth it's not a big problem but with 16 bit color depth
136
+ * the target pixel format is ARGB8565 which is not supported by the GPU.
137
+ * In this case, the VG-Lite callbacks should fallback to SW rendering.
138
+ */
139
+ static inline bool need_argb8565_support()
140
+ {
141
+ #if LV_COLOR_DEPTH != 32
142
+ lv_disp_t * disp = _lv_refr_get_disp_refreshing();
143
+
144
+ if(disp->driver->screen_transp == 1)
145
+ return true;
146
+ #endif
147
+
148
+ return false;
149
+ }
150
+
151
+ static void lv_draw_vglite_init_buf(lv_draw_ctx_t * draw_ctx)
152
+ {
153
+ lv_gpu_nxp_vglite_init_buf(draw_ctx->buf, draw_ctx->buf_area, lv_area_get_width(draw_ctx->buf_area));
154
+ }
155
+
156
+ static void lv_draw_vglite_wait_for_finish(lv_draw_ctx_t * draw_ctx)
157
+ {
158
+ vg_lite_finish();
159
+
160
+ lv_draw_sw_wait_for_finish(draw_ctx);
161
+ }
162
+
163
+ static void lv_draw_vglite_blend(lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc)
164
+ {
165
+ if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
166
+ return;
167
+
168
+ if(need_argb8565_support()) {
169
+ lv_draw_sw_blend_basic(draw_ctx, dsc);
170
+ return;
171
+ }
172
+
173
+ lv_area_t blend_area;
174
+ if(!_lv_area_intersect(&blend_area, dsc->blend_area, draw_ctx->clip_area))
175
+ return; /*Fully clipped, nothing to do*/
176
+
177
+ lv_area_move(&blend_area, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
178
+
179
+ bool done = false;
180
+ /*Fill/Blend only non masked, normal blended*/
181
+ if(dsc->mask_buf == NULL && dsc->blend_mode == LV_BLEND_MODE_NORMAL &&
182
+ lv_area_get_size(&blend_area) >= LV_GPU_NXP_VG_LITE_SIZE_LIMIT) {
183
+ const lv_color_t * src_buf = dsc->src_buf;
184
+
185
+ if(src_buf == NULL) {
186
+ done = (lv_gpu_nxp_vglite_fill(&blend_area, dsc->color, dsc->opa) == LV_RES_OK);
187
+ if(!done)
188
+ VG_LITE_LOG_TRACE("VG-Lite fill failed. Fallback.");
189
+ }
190
+ else {
191
+ lv_area_t src_area;
192
+ src_area.x1 = blend_area.x1 - (dsc->blend_area->x1 - draw_ctx->buf_area->x1);
193
+ src_area.y1 = blend_area.y1 - (dsc->blend_area->y1 - draw_ctx->buf_area->y1);
194
+ src_area.x2 = src_area.x1 + lv_area_get_width(dsc->blend_area) - 1;
195
+ src_area.y2 = src_area.y1 + lv_area_get_height(dsc->blend_area) - 1;
196
+ lv_coord_t src_stride = lv_area_get_width(dsc->blend_area);
197
+
198
+ #if VG_LITE_BLIT_SPLIT_ENABLED
199
+ lv_color_t * dest_buf = draw_ctx->buf;
200
+ lv_coord_t dest_stride = lv_area_get_width(draw_ctx->buf_area);
201
+
202
+ done = (lv_gpu_nxp_vglite_blit_split(dest_buf, &blend_area, dest_stride,
203
+ src_buf, &src_area, src_stride, dsc->opa) == LV_RES_OK);
204
+ #else
205
+ done = (lv_gpu_nxp_vglite_blit(&blend_area, src_buf, &src_area, src_stride, dsc->opa) == LV_RES_OK);
206
+ #endif
207
+
208
+ if(!done)
209
+ VG_LITE_LOG_TRACE("VG-Lite blit failed. Fallback.");
210
+ }
211
+ }
212
+
213
+ if(!done)
214
+ lv_draw_sw_blend_basic(draw_ctx, dsc);
215
+ }
216
+
217
+ static void lv_draw_vglite_img_decoded(lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * dsc,
218
+ const lv_area_t * coords, const uint8_t * map_p, lv_img_cf_t cf)
219
+ {
220
+ if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
221
+ return;
222
+
223
+ if(need_argb8565_support()) {
224
+ lv_draw_sw_img_decoded(draw_ctx, dsc, coords, map_p, cf);
225
+ return;
226
+ }
227
+
228
+ const lv_color_t * src_buf = (const lv_color_t *)map_p;
229
+ if(!src_buf) {
230
+ lv_draw_sw_img_decoded(draw_ctx, dsc, coords, map_p, cf);
231
+ return;
232
+ }
233
+
234
+ lv_area_t rel_coords;
235
+ lv_area_copy(&rel_coords, coords);
236
+ lv_area_move(&rel_coords, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
237
+
238
+ lv_area_t rel_clip_area;
239
+ lv_area_copy(&rel_clip_area, draw_ctx->clip_area);
240
+ lv_area_move(&rel_clip_area, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
241
+
242
+ lv_area_t blend_area;
243
+ bool has_transform = dsc->angle != 0 || dsc->zoom != LV_IMG_ZOOM_NONE;
244
+
245
+ if(has_transform)
246
+ lv_area_copy(&blend_area, &rel_coords);
247
+ else if(!_lv_area_intersect(&blend_area, &rel_coords, &rel_clip_area))
248
+ return; /*Fully clipped, nothing to do*/
249
+
250
+ bool has_mask = lv_draw_mask_is_any(&blend_area);
251
+ bool has_recolor = (dsc->recolor_opa != LV_OPA_TRANSP);
252
+
253
+ bool done = false;
254
+ if(!has_mask && !has_recolor && !lv_img_cf_is_chroma_keyed(cf) &&
255
+ lv_area_get_size(&blend_area) >= LV_GPU_NXP_VG_LITE_SIZE_LIMIT
256
+ #if LV_COLOR_DEPTH != 32
257
+ && !lv_img_cf_has_alpha(cf)
258
+ #endif
259
+ ) {
260
+ lv_area_t src_area;
261
+ src_area.x1 = blend_area.x1 - (coords->x1 - draw_ctx->buf_area->x1);
262
+ src_area.y1 = blend_area.y1 - (coords->y1 - draw_ctx->buf_area->y1);
263
+ src_area.x2 = src_area.x1 + lv_area_get_width(coords) - 1;
264
+ src_area.y2 = src_area.y1 + lv_area_get_height(coords) - 1;
265
+ lv_coord_t src_stride = lv_area_get_width(coords);
266
+
267
+ #if VG_LITE_BLIT_SPLIT_ENABLED
268
+ lv_color_t * dest_buf = draw_ctx->buf;
269
+ lv_coord_t dest_stride = lv_area_get_width(draw_ctx->buf_area);
270
+
271
+ if(has_transform)
272
+ /* VG-Lite blit split with transformation is not supported! */
273
+ done = false;
274
+ else
275
+ done = (lv_gpu_nxp_vglite_blit_split(dest_buf, &blend_area, dest_stride,
276
+ src_buf, &src_area, src_stride, dsc->opa) == LV_RES_OK);
277
+ #else
278
+ if(has_transform)
279
+ done = (lv_gpu_nxp_vglite_blit_transform(&blend_area, &rel_clip_area,
280
+ src_buf, &src_area, src_stride, dsc) == LV_RES_OK);
281
+ else
282
+ done = (lv_gpu_nxp_vglite_blit(&blend_area, src_buf, &src_area, src_stride, dsc->opa) == LV_RES_OK);
283
+ #endif
284
+
285
+ if(!done)
286
+ VG_LITE_LOG_TRACE("VG-Lite blit %sfailed. Fallback.", has_transform ? "transform " : "");
287
+ }
288
+
289
+ if(!done)
290
+ lv_draw_sw_img_decoded(draw_ctx, dsc, coords, map_p, cf);
291
+ }
292
+
293
+ static void lv_draw_vglite_buffer_copy(lv_draw_ctx_t * draw_ctx,
294
+ void * dest_buf, lv_coord_t dest_stride, const lv_area_t * dest_area,
295
+ void * src_buf, lv_coord_t src_stride, const lv_area_t * src_area)
296
+ {
297
+ bool done = false;
298
+
299
+ if(lv_area_get_size(dest_area) >= LV_GPU_NXP_VG_LITE_SIZE_LIMIT) {
300
+ done = lv_gpu_nxp_vglite_buffer_copy(dest_buf, dest_area, dest_stride, src_buf, src_area, src_stride);
301
+ if(!done)
302
+ VG_LITE_LOG_TRACE("VG-Lite buffer copy failed. Fallback.");
303
+ }
304
+
305
+ if(!done)
306
+ lv_draw_sw_buffer_copy(draw_ctx, dest_buf, dest_stride, dest_area, src_buf, src_stride, src_area);
307
+ }
308
+
309
+ static void lv_draw_vglite_line(lv_draw_ctx_t * draw_ctx, const lv_draw_line_dsc_t * dsc, const lv_point_t * point1,
310
+ const lv_point_t * point2)
311
+ {
312
+ if(dsc->width == 0)
313
+ return;
314
+ if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
315
+ return;
316
+ if(point1->x == point2->x && point1->y == point2->y)
317
+ return;
318
+
319
+ if(need_argb8565_support()) {
320
+ lv_draw_sw_line(draw_ctx, dsc, point1, point2);
321
+ return;
322
+ }
323
+
324
+ lv_area_t rel_clip_area;
325
+ rel_clip_area.x1 = LV_MIN(point1->x, point2->x) - dsc->width / 2;
326
+ rel_clip_area.x2 = LV_MAX(point1->x, point2->x) + dsc->width / 2;
327
+ rel_clip_area.y1 = LV_MIN(point1->y, point2->y) - dsc->width / 2;
328
+ rel_clip_area.y2 = LV_MAX(point1->y, point2->y) + dsc->width / 2;
329
+
330
+ lv_area_t clipped_coords;
331
+ if(!_lv_area_intersect(&clipped_coords, &rel_clip_area, draw_ctx->clip_area))
332
+ return; /*Fully clipped, nothing to do*/
333
+
334
+ lv_area_move(&rel_clip_area, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
335
+
336
+ lv_point_t rel_point1 = { point1->x - draw_ctx->buf_area->x1, point1->y - draw_ctx->buf_area->y1 };
337
+ lv_point_t rel_point2 = { point2->x - draw_ctx->buf_area->x1, point2->y - draw_ctx->buf_area->y1 };
338
+
339
+ bool done = false;
340
+ bool has_mask = lv_draw_mask_is_any(&rel_clip_area);
341
+
342
+ if(!has_mask) {
343
+ done = (lv_gpu_nxp_vglite_draw_line(&rel_point1, &rel_point2, &rel_clip_area, dsc) == LV_RES_OK);
344
+ if(!done)
345
+ VG_LITE_LOG_TRACE("VG-Lite draw line failed. Fallback.");
346
+ }
347
+
348
+ if(!done)
349
+ lv_draw_sw_line(draw_ctx, dsc, point1, point2);
350
+ }
351
+
352
+ static void lv_draw_vglite_rect(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords)
353
+ {
354
+ if(need_argb8565_support()) {
355
+ lv_draw_sw_rect(draw_ctx, dsc, coords);
356
+ return;
357
+ }
358
+
359
+ lv_draw_rect_dsc_t vglite_dsc;
360
+
361
+ lv_memcpy(&vglite_dsc, dsc, sizeof(vglite_dsc));
362
+ vglite_dsc.bg_opa = 0;
363
+ vglite_dsc.bg_img_opa = 0;
364
+ vglite_dsc.border_opa = 0;
365
+ vglite_dsc.outline_opa = 0;
366
+ #if LV_DRAW_COMPLEX
367
+ /* Draw the shadow with CPU */
368
+ lv_draw_sw_rect(draw_ctx, &vglite_dsc, coords);
369
+ vglite_dsc.shadow_opa = 0;
370
+ #endif /*LV_DRAW_COMPLEX*/
371
+
372
+ /* Draw the background */
373
+ vglite_dsc.bg_opa = dsc->bg_opa;
374
+ if(lv_draw_vglite_bg(draw_ctx, &vglite_dsc, coords) != LV_RES_OK)
375
+ lv_draw_sw_rect(draw_ctx, &vglite_dsc, coords);
376
+ vglite_dsc.bg_opa = 0;
377
+
378
+ /* Draw the background image
379
+ * It will be done once draw_ctx->draw_img_decoded()
380
+ * callback gets called from lv_draw_sw_rect().
381
+ */
382
+ vglite_dsc.bg_img_opa = dsc->bg_img_opa;
383
+ lv_draw_sw_rect(draw_ctx, &vglite_dsc, coords);
384
+ vglite_dsc.bg_img_opa = 0;
385
+
386
+ /* Draw the border */
387
+ vglite_dsc.border_opa = dsc->border_opa;
388
+ if(lv_draw_vglite_border(draw_ctx, &vglite_dsc, coords) != LV_RES_OK)
389
+ lv_draw_sw_rect(draw_ctx, &vglite_dsc, coords);
390
+ vglite_dsc.border_opa = 0;
391
+
392
+ /* Draw the outline */
393
+ vglite_dsc.outline_opa = dsc->outline_opa;
394
+ if(lv_draw_vglite_outline(draw_ctx, &vglite_dsc, coords) != LV_RES_OK)
395
+ lv_draw_sw_rect(draw_ctx, &vglite_dsc, coords);
396
+ }
397
+
398
+ static lv_res_t lv_draw_vglite_bg(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords)
399
+ {
400
+ if(dsc->bg_opa <= (lv_opa_t)LV_OPA_MIN)
401
+ return LV_RES_INV;
402
+
403
+ lv_area_t rel_coords;
404
+ lv_area_copy(&rel_coords, coords);
405
+
406
+ /*If the border fully covers make the bg area 1px smaller to avoid artifacts on the corners*/
407
+ if(dsc->border_width > 1 && dsc->border_opa >= (lv_opa_t)LV_OPA_MAX && dsc->radius != 0) {
408
+ rel_coords.x1 += (dsc->border_side & LV_BORDER_SIDE_LEFT) ? 1 : 0;
409
+ rel_coords.y1 += (dsc->border_side & LV_BORDER_SIDE_TOP) ? 1 : 0;
410
+ rel_coords.x2 -= (dsc->border_side & LV_BORDER_SIDE_RIGHT) ? 1 : 0;
411
+ rel_coords.y2 -= (dsc->border_side & LV_BORDER_SIDE_BOTTOM) ? 1 : 0;
412
+ }
413
+ lv_area_move(&rel_coords, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
414
+
415
+ lv_area_t rel_clip_area;
416
+ lv_area_copy(&rel_clip_area, draw_ctx->clip_area);
417
+ lv_area_move(&rel_clip_area, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
418
+
419
+ lv_area_t clipped_coords;
420
+ if(!_lv_area_intersect(&clipped_coords, &rel_coords, &rel_clip_area))
421
+ return LV_RES_OK; /*Fully clipped, nothing to do*/
422
+
423
+ bool has_mask = lv_draw_mask_is_any(&rel_coords);
424
+ lv_grad_dir_t grad_dir = dsc->bg_grad.dir;
425
+ lv_color_t bg_color = (grad_dir == (lv_grad_dir_t)LV_GRAD_DIR_NONE) ?
426
+ dsc->bg_color : dsc->bg_grad.stops[0].color;
427
+ if(bg_color.full == dsc->bg_grad.stops[1].color.full)
428
+ grad_dir = LV_GRAD_DIR_NONE;
429
+
430
+ /*
431
+ * Most simple case: just a plain rectangle (no mask, no radius, no gradient)
432
+ * shall be handled by draw_ctx->blend().
433
+ *
434
+ * Complex case: gradient or radius but no mask.
435
+ */
436
+ if(!has_mask && ((dsc->radius != 0) || (grad_dir != (lv_grad_dir_t)LV_GRAD_DIR_NONE))) {
437
+ lv_res_t res = lv_gpu_nxp_vglite_draw_bg(&rel_coords, &rel_clip_area, dsc);
438
+ if(res != LV_RES_OK)
439
+ VG_LITE_LOG_TRACE("VG-Lite draw bg failed. Fallback.");
440
+
441
+ return res;
442
+ }
443
+
444
+ return LV_RES_INV;
445
+ }
446
+
447
+ static lv_res_t lv_draw_vglite_border(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc,
448
+ const lv_area_t * coords)
449
+ {
450
+ if(dsc->border_opa <= (lv_opa_t)LV_OPA_MIN)
451
+ return LV_RES_INV;
452
+ if(dsc->border_width == 0)
453
+ return LV_RES_INV;
454
+ if(dsc->border_post)
455
+ return LV_RES_INV;
456
+ if(dsc->border_side != (lv_border_side_t)LV_BORDER_SIDE_FULL)
457
+ return LV_RES_INV;
458
+
459
+ lv_area_t rel_coords;
460
+ lv_coord_t border_width = dsc->border_width;
461
+
462
+ /* Move border inwards to align with software rendered border */
463
+ rel_coords.x1 = coords->x1 + ceil(border_width / 2.0f);
464
+ rel_coords.x2 = coords->x2 - floor(border_width / 2.0f);
465
+ rel_coords.y1 = coords->y1 + ceil(border_width / 2.0f);
466
+ rel_coords.y2 = coords->y2 - floor(border_width / 2.0f);
467
+
468
+ lv_area_move(&rel_coords, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
469
+
470
+ lv_area_t rel_clip_area;
471
+ lv_area_copy(&rel_clip_area, draw_ctx->clip_area);
472
+ lv_area_move(&rel_clip_area, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
473
+
474
+ lv_area_t clipped_coords;
475
+ if(!_lv_area_intersect(&clipped_coords, &rel_coords, &rel_clip_area))
476
+ return LV_RES_OK; /*Fully clipped, nothing to do*/
477
+
478
+ lv_res_t res = lv_gpu_nxp_vglite_draw_border_generic(&rel_coords, &rel_clip_area, dsc, true);
479
+ if(res != LV_RES_OK)
480
+ VG_LITE_LOG_TRACE("VG-Lite draw border failed. Fallback.");
481
+
482
+ return res;
483
+ }
484
+
485
+ static lv_res_t lv_draw_vglite_outline(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc,
486
+ const lv_area_t * coords)
487
+ {
488
+ if(dsc->outline_opa <= (lv_opa_t)LV_OPA_MIN)
489
+ return LV_RES_INV;
490
+ if(dsc->outline_width == 0)
491
+ return LV_RES_INV;
492
+
493
+ /* Move outline outwards to align with software rendered outline */
494
+ lv_coord_t outline_pad = dsc->outline_pad - 1;
495
+ lv_area_t rel_coords;
496
+ rel_coords.x1 = coords->x1 - outline_pad - floor(dsc->outline_width / 2.0f);
497
+ rel_coords.x2 = coords->x2 + outline_pad + ceil(dsc->outline_width / 2.0f);
498
+ rel_coords.y1 = coords->y1 - outline_pad - floor(dsc->outline_width / 2.0f);
499
+ rel_coords.y2 = coords->y2 + outline_pad + ceil(dsc->outline_width / 2.0f);
500
+
501
+ lv_area_move(&rel_coords, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
502
+
503
+ lv_area_t rel_clip_area;
504
+ lv_area_copy(&rel_clip_area, draw_ctx->clip_area);
505
+ lv_area_move(&rel_clip_area, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
506
+
507
+ lv_area_t clipped_coords;
508
+ if(!_lv_area_intersect(&clipped_coords, &rel_coords, &rel_clip_area))
509
+ return LV_RES_OK; /*Fully clipped, nothing to do*/
510
+
511
+ lv_res_t res = lv_gpu_nxp_vglite_draw_border_generic(&rel_coords, &rel_clip_area, dsc, false);
512
+ if(res != LV_RES_OK)
513
+ VG_LITE_LOG_TRACE("VG-Lite draw outline failed. Fallback.");
514
+
515
+ return res;
516
+ }
517
+
518
+ static void lv_draw_vglite_arc(lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * dsc, const lv_point_t * center,
519
+ uint16_t radius, uint16_t start_angle, uint16_t end_angle)
520
+ {
521
+ bool done = false;
522
+
523
+ #if LV_DRAW_COMPLEX
524
+ if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
525
+ return;
526
+ if(dsc->width == 0)
527
+ return;
528
+ if(start_angle == end_angle)
529
+ return;
530
+
531
+ if(need_argb8565_support()) {
532
+ lv_draw_sw_arc(draw_ctx, dsc, center, radius, start_angle, end_angle);
533
+ return;
534
+ }
535
+
536
+ lv_point_t rel_center = {center->x - draw_ctx->buf_area->x1, center->y - draw_ctx->buf_area->y1};
537
+
538
+ lv_area_t rel_clip_area;
539
+ lv_area_copy(&rel_clip_area, draw_ctx->clip_area);
540
+ lv_area_move(&rel_clip_area, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
541
+
542
+ bool has_mask = lv_draw_mask_is_any(&rel_clip_area);
543
+
544
+ if(!has_mask) {
545
+ done = (lv_gpu_nxp_vglite_draw_arc(&rel_center, (int32_t)radius, (int32_t)start_angle, (int32_t)end_angle,
546
+ &rel_clip_area, dsc) == LV_RES_OK);
547
+ if(!done)
548
+ VG_LITE_LOG_TRACE("VG-Lite draw arc failed. Fallback.");
549
+ }
550
+
551
+ #endif/*LV_DRAW_COMPLEX*/
552
+
553
+ if(!done)
554
+ lv_draw_sw_arc(draw_ctx, dsc, center, radius, start_angle, end_angle);
555
+ }
556
+
557
+ #endif /*LV_USE_GPU_NXP_VG_LITE*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite.h ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_vglite.h
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2022, 2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ #ifndef LV_DRAW_VGLITE_H
31
+ #define LV_DRAW_VGLITE_H
32
+
33
+ #ifdef __cplusplus
34
+ extern "C" {
35
+ #endif
36
+
37
+ /*********************
38
+ * INCLUDES
39
+ *********************/
40
+
41
+ #include "../../../lv_conf_internal.h"
42
+
43
+ #if LV_USE_GPU_NXP_VG_LITE
44
+ #include "../../sw/lv_draw_sw.h"
45
+
46
+ /*********************
47
+ * DEFINES
48
+ *********************/
49
+
50
+ /**********************
51
+ * TYPEDEFS
52
+ **********************/
53
+ typedef lv_draw_sw_ctx_t lv_draw_vglite_ctx_t;
54
+
55
+ /**********************
56
+ * GLOBAL PROTOTYPES
57
+ **********************/
58
+
59
+ void lv_draw_vglite_ctx_init(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx);
60
+
61
+ void lv_draw_vglite_ctx_deinit(struct _lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx);
62
+
63
+ /**********************
64
+ * MACROS
65
+ **********************/
66
+ #endif /*LV_USE_GPU_NXP_VG_LITE*/
67
+
68
+ #ifdef __cplusplus
69
+ } /*extern "C"*/
70
+ #endif
71
+
72
+ #endif /*LV_DRAW_VGLITE_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite_arc.c ADDED
@@ -0,0 +1,679 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_vglite_arc.c
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2021-2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ /*********************
31
+ * INCLUDES
32
+ *********************/
33
+
34
+ #include "lv_draw_vglite_arc.h"
35
+
36
+ #if LV_USE_GPU_NXP_VG_LITE
37
+ #include "lv_vglite_buf.h"
38
+ #include <math.h>
39
+
40
+ /*********************
41
+ * DEFINES
42
+ *********************/
43
+
44
+ #define T_FRACTION 16384.0f
45
+
46
+ #define DICHOTO_ITER 5
47
+
48
+ static const uint16_t TperDegree[90] = {
49
+ 0, 174, 348, 522, 697, 873, 1049, 1226, 1403, 1581,
50
+ 1759, 1938, 2117, 2297, 2477, 2658, 2839, 3020, 3202, 3384,
51
+ 3567, 3749, 3933, 4116, 4300, 4484, 4668, 4852, 5037, 5222,
52
+ 5407, 5592, 5777, 5962, 6148, 6334, 6519, 6705, 6891, 7077,
53
+ 7264, 7450, 7636, 7822, 8008, 8193, 8378, 8564, 8750, 8936,
54
+ 9122, 9309, 9495, 9681, 9867, 10052, 10238, 10424, 10609, 10794,
55
+ 10979, 11164, 11349, 11534, 11718, 11902, 12086, 12270, 12453, 12637,
56
+ 12819, 13002, 13184, 13366, 13547, 13728, 13909, 14089, 14269, 14448,
57
+ 14627, 14805, 14983, 15160, 15337, 15513, 15689, 15864, 16038, 16212
58
+ };
59
+
60
+ /**********************
61
+ * TYPEDEFS
62
+ **********************/
63
+
64
+ /* intermediate arc params */
65
+ typedef struct _vg_arc {
66
+ int32_t angle; /* angle <90deg */
67
+ int32_t quarter; /* 0-3 counter-clockwise */
68
+ int32_t rad; /* radius */
69
+ int32_t p0x; /* point P0 */
70
+ int32_t p0y;
71
+ int32_t p1x; /* point P1 */
72
+ int32_t p1y;
73
+ int32_t p2x; /* point P2 */
74
+ int32_t p2y;
75
+ int32_t p3x; /* point P3 */
76
+ int32_t p3y;
77
+ } vg_arc;
78
+
79
+ typedef struct _cubic_cont_pt {
80
+ float p0;
81
+ float p1;
82
+ float p2;
83
+ float p3;
84
+ } cubic_cont_pt;
85
+
86
+ /**********************
87
+ * STATIC PROTOTYPES
88
+ **********************/
89
+
90
+ static void rotate_point(int32_t angle, int32_t * x, int32_t * y);
91
+ static void add_arc_path(int32_t * arc_path, int * pidx, int32_t radius,
92
+ int32_t start_angle, int32_t end_angle, const lv_point_t * center, bool cw);
93
+
94
+ /**********************
95
+ * STATIC VARIABLES
96
+ **********************/
97
+
98
+ /**********************
99
+ * MACROS
100
+ **********************/
101
+
102
+ /**********************
103
+ * GLOBAL FUNCTIONS
104
+ **********************/
105
+
106
+ lv_res_t lv_gpu_nxp_vglite_draw_arc(const lv_point_t * center, int32_t radius, int32_t start_angle, int32_t end_angle,
107
+ const lv_area_t * clip_area, const lv_draw_arc_dsc_t * dsc)
108
+ {
109
+ vg_lite_error_t err = VG_LITE_SUCCESS;
110
+ lv_color32_t col32 = {.full = lv_color_to32(dsc->color)}; /*Convert color to RGBA8888*/
111
+ vg_lite_path_t path;
112
+ vg_lite_color_t vgcol; /* vglite takes ABGR */
113
+ bool donut = ((end_angle - start_angle) % 360 == 0) ? true : false;
114
+ vg_lite_buffer_t * vgbuf = lv_vglite_get_dest_buf();
115
+
116
+ /* path: max size = 16 cubic bezier (7 words each) */
117
+ int32_t arc_path[16 * 7];
118
+ lv_memset_00(arc_path, sizeof(arc_path));
119
+
120
+ /*** Init path ***/
121
+ lv_coord_t width = dsc->width; /* inner arc radius = outer arc radius - width */
122
+ if(width > (lv_coord_t)radius)
123
+ width = radius;
124
+
125
+ int pidx = 0;
126
+ int32_t cp_x, cp_y; /* control point coords */
127
+
128
+ /* first control point of curve */
129
+ cp_x = radius;
130
+ cp_y = 0;
131
+ rotate_point(start_angle, &cp_x, &cp_y);
132
+ arc_path[pidx++] = VLC_OP_MOVE;
133
+ arc_path[pidx++] = center->x + cp_x;
134
+ arc_path[pidx++] = center->y + cp_y;
135
+
136
+ /* draw 1-5 outer quarters */
137
+ add_arc_path(arc_path, &pidx, radius, start_angle, end_angle, center, true);
138
+
139
+ if(donut) {
140
+ /* close outer circle */
141
+ cp_x = radius;
142
+ cp_y = 0;
143
+ rotate_point(start_angle, &cp_x, &cp_y);
144
+ arc_path[pidx++] = VLC_OP_LINE;
145
+ arc_path[pidx++] = center->x + cp_x;
146
+ arc_path[pidx++] = center->y + cp_y;
147
+ /* start inner circle */
148
+ cp_x = radius - width;
149
+ cp_y = 0;
150
+ rotate_point(start_angle, &cp_x, &cp_y);
151
+ arc_path[pidx++] = VLC_OP_MOVE;
152
+ arc_path[pidx++] = center->x + cp_x;
153
+ arc_path[pidx++] = center->y + cp_y;
154
+
155
+ }
156
+ else if(dsc->rounded != 0U) { /* 1st rounded arc ending */
157
+ cp_x = radius - width / 2;
158
+ cp_y = 0;
159
+ rotate_point(end_angle, &cp_x, &cp_y);
160
+ lv_point_t round_center = {center->x + cp_x, center->y + cp_y};
161
+ add_arc_path(arc_path, &pidx, width / 2, end_angle, (end_angle + 180),
162
+ &round_center, true);
163
+
164
+ }
165
+ else { /* 1st flat ending */
166
+ cp_x = radius - width;
167
+ cp_y = 0;
168
+ rotate_point(end_angle, &cp_x, &cp_y);
169
+ arc_path[pidx++] = VLC_OP_LINE;
170
+ arc_path[pidx++] = center->x + cp_x;
171
+ arc_path[pidx++] = center->y + cp_y;
172
+ }
173
+
174
+ /* draw 1-5 inner quarters */
175
+ add_arc_path(arc_path, &pidx, radius - width, start_angle, end_angle, center, false);
176
+
177
+ /* last control point of curve */
178
+ if(donut) { /* close the loop */
179
+ cp_x = radius - width;
180
+ cp_y = 0;
181
+ rotate_point(start_angle, &cp_x, &cp_y);
182
+ arc_path[pidx++] = VLC_OP_LINE;
183
+ arc_path[pidx++] = center->x + cp_x;
184
+ arc_path[pidx++] = center->y + cp_y;
185
+
186
+ }
187
+ else if(dsc->rounded != 0U) { /* 2nd rounded arc ending */
188
+ cp_x = radius - width / 2;
189
+ cp_y = 0;
190
+ rotate_point(start_angle, &cp_x, &cp_y);
191
+ lv_point_t round_center = {center->x + cp_x, center->y + cp_y};
192
+ add_arc_path(arc_path, &pidx, width / 2, (start_angle + 180), (start_angle + 360),
193
+ &round_center, true);
194
+
195
+ }
196
+ else { /* 2nd flat ending */
197
+ cp_x = radius;
198
+ cp_y = 0;
199
+ rotate_point(start_angle, &cp_x, &cp_y);
200
+ arc_path[pidx++] = VLC_OP_LINE;
201
+ arc_path[pidx++] = center->x + cp_x;
202
+ arc_path[pidx++] = center->y + cp_y;
203
+ }
204
+
205
+ arc_path[pidx++] = VLC_OP_END;
206
+
207
+ err = vg_lite_init_path(&path, VG_LITE_S32, VG_LITE_HIGH, (uint32_t)pidx * sizeof(int32_t), arc_path,
208
+ (vg_lite_float_t)clip_area->x1, (vg_lite_float_t)clip_area->y1,
209
+ ((vg_lite_float_t)clip_area->x2) + 1.0f, ((vg_lite_float_t)clip_area->y2) + 1.0f);
210
+ VG_LITE_ERR_RETURN_INV(err, "Init path failed.");
211
+
212
+ vg_lite_buffer_format_t color_format = LV_COLOR_DEPTH == 16 ? VG_LITE_BGRA8888 : VG_LITE_ABGR8888;
213
+ if(lv_vglite_premult_and_swizzle(&vgcol, col32, dsc->opa, color_format) != LV_RES_OK)
214
+ VG_LITE_RETURN_INV("Premultiplication and swizzle failed.");
215
+
216
+ vg_lite_matrix_t matrix;
217
+ vg_lite_identity(&matrix);
218
+
219
+ lv_vglite_set_scissor(clip_area);
220
+
221
+ /*** Draw arc ***/
222
+ err = vg_lite_draw(vgbuf, &path, VG_LITE_FILL_NON_ZERO, &matrix, VG_LITE_BLEND_SRC_OVER, vgcol);
223
+ VG_LITE_ERR_RETURN_INV(err, "Draw arc failed.");
224
+
225
+ if(lv_vglite_run() != LV_RES_OK)
226
+ VG_LITE_RETURN_INV("Run failed.");
227
+
228
+ lv_vglite_disable_scissor();
229
+
230
+ err = vg_lite_clear_path(&path);
231
+ VG_LITE_ERR_RETURN_INV(err, "Clear path failed.");
232
+
233
+ return LV_RES_OK;
234
+ }
235
+
236
+ /**********************
237
+ * STATIC FUNCTIONS
238
+ **********************/
239
+
240
+ static void copy_arc(vg_arc * dst, vg_arc * src)
241
+ {
242
+ dst->quarter = src->quarter;
243
+ dst->rad = src->rad;
244
+ dst->angle = src->angle;
245
+ dst->p0x = src->p0x;
246
+ dst->p1x = src->p1x;
247
+ dst->p2x = src->p2x;
248
+ dst->p3x = src->p3x;
249
+ dst->p0y = src->p0y;
250
+ dst->p1y = src->p1y;
251
+ dst->p2y = src->p2y;
252
+ dst->p3y = src->p3y;
253
+ }
254
+
255
+ /**
256
+ * Rotate the point according given rotation angle rotation center is 0,0
257
+ */
258
+ static void rotate_point(int32_t angle, int32_t * x, int32_t * y)
259
+ {
260
+ int32_t ori_x = *x;
261
+ int32_t ori_y = *y;
262
+ int16_t alpha = (int16_t)angle;
263
+ *x = ((lv_trigo_cos(alpha) * ori_x) / LV_TRIGO_SIN_MAX) - ((lv_trigo_sin(alpha) * ori_y) / LV_TRIGO_SIN_MAX);
264
+ *y = ((lv_trigo_sin(alpha) * ori_x) / LV_TRIGO_SIN_MAX) + ((lv_trigo_cos(alpha) * ori_y) / LV_TRIGO_SIN_MAX);
265
+ }
266
+
267
+ /**
268
+ * Set full arc control points depending on quarter.
269
+ * Control points match the best approximation of a circle.
270
+ * Arc Quarter position is:
271
+ * Q2 | Q3
272
+ * ---+---
273
+ * Q1 | Q0
274
+ */
275
+ static void set_full_arc(vg_arc * fullarc)
276
+ {
277
+ /* the tangent lenght for the bezier circle approx */
278
+ float tang = ((float)fullarc->rad) * BEZIER_OPTIM_CIRCLE;
279
+ switch(fullarc->quarter) {
280
+ case 0:
281
+ /* first quarter */
282
+ fullarc->p0x = fullarc->rad;
283
+ fullarc->p0y = 0;
284
+ fullarc->p1x = fullarc->rad;
285
+ fullarc->p1y = (int32_t)tang;
286
+ fullarc->p2x = (int32_t)tang;
287
+ fullarc->p2y = fullarc->rad;
288
+ fullarc->p3x = 0;
289
+ fullarc->p3y = fullarc->rad;
290
+ break;
291
+ case 1:
292
+ /* second quarter */
293
+ fullarc->p0x = 0;
294
+ fullarc->p0y = fullarc->rad;
295
+ fullarc->p1x = 0 - (int32_t)tang;
296
+ fullarc->p1y = fullarc->rad;
297
+ fullarc->p2x = 0 - fullarc->rad;
298
+ fullarc->p2y = (int32_t)tang;
299
+ fullarc->p3x = 0 - fullarc->rad;
300
+ fullarc->p3y = 0;
301
+ break;
302
+ case 2:
303
+ /* third quarter */
304
+ fullarc->p0x = 0 - fullarc->rad;
305
+ fullarc->p0y = 0;
306
+ fullarc->p1x = 0 - fullarc->rad;
307
+ fullarc->p1y = 0 - (int32_t)tang;
308
+ fullarc->p2x = 0 - (int32_t)tang;
309
+ fullarc->p2y = 0 - fullarc->rad;
310
+ fullarc->p3x = 0;
311
+ fullarc->p3y = 0 - fullarc->rad;
312
+ break;
313
+ case 3:
314
+ /* fourth quarter */
315
+ fullarc->p0x = 0;
316
+ fullarc->p0y = 0 - fullarc->rad;
317
+ fullarc->p1x = (int32_t)tang;
318
+ fullarc->p1y = 0 - fullarc->rad;
319
+ fullarc->p2x = fullarc->rad;
320
+ fullarc->p2y = 0 - (int32_t)tang;
321
+ fullarc->p3x = fullarc->rad;
322
+ fullarc->p3y = 0;
323
+ break;
324
+ default:
325
+ LV_LOG_ERROR("Invalid arc quarter value.");
326
+ break;
327
+ }
328
+ }
329
+
330
+ /**
331
+ * Linear interpolation between two points 'a' and 'b'
332
+ * 't' parameter is the proportion ratio expressed in range [0 ; T_FRACTION ]
333
+ */
334
+ static inline float lerp(float coord_a, float coord_b, uint16_t t)
335
+ {
336
+ float tf = (float)t;
337
+ return ((T_FRACTION - tf) * coord_a + tf * coord_b) / T_FRACTION;
338
+ }
339
+
340
+ /**
341
+ * Computes a point of bezier curve given 't' param
342
+ */
343
+ static inline float comp_bezier_point(float t, cubic_cont_pt cp)
344
+ {
345
+ float t_sq = t * t;
346
+ float inv_t_sq = (1.0f - t) * (1.0f - t);
347
+ float apt = (1.0f - t) * inv_t_sq * cp.p0 + 3.0f * inv_t_sq * t * cp.p1 + 3.0f * (1.0f - t) * t_sq * cp.p2 + t * t_sq *
348
+ cp.p3;
349
+ return apt;
350
+ }
351
+
352
+ /**
353
+ * Find parameter 't' in curve at point 'pt'
354
+ * proceed by dichotomy on only 1 dimension,
355
+ * works only if the curve is monotonic
356
+ * bezier curve is defined by control points [p0 p1 p2 p3]
357
+ * 'dec' tells if curve is decreasing (true) or increasing (false)
358
+ */
359
+ static uint16_t get_bez_t_from_pos(float pt, cubic_cont_pt cp, bool dec)
360
+ {
361
+ /* initialize dichotomy with boundary 't' values */
362
+ float t_low = 0.0f;
363
+ float t_mid = 0.5f;
364
+ float t_hig = 1.0f;
365
+ float a_pt;
366
+ /* dichotomy loop */
367
+ for(int i = 0; i < DICHOTO_ITER; i++) {
368
+ a_pt = comp_bezier_point(t_mid, cp);
369
+ /* check mid-point position on bezier curve versus targeted point */
370
+ if((a_pt > pt) != dec) {
371
+ t_hig = t_mid;
372
+ }
373
+ else {
374
+ t_low = t_mid;
375
+ }
376
+ /* define new 't' param for mid-point */
377
+ t_mid = (t_low + t_hig) / 2.0f;
378
+ }
379
+ /* return parameter 't' in integer range [0 ; T_FRACTION] */
380
+ return (uint16_t)floorf(t_mid * T_FRACTION + 0.5f);
381
+ }
382
+
383
+ /**
384
+ * Gives relative coords of the control points
385
+ * for the sub-arc starting at angle with given angle span
386
+ */
387
+ static void get_subarc_control_points(vg_arc * arc, int32_t span)
388
+ {
389
+ vg_arc fullarc;
390
+ fullarc.angle = arc->angle;
391
+ fullarc.quarter = arc->quarter;
392
+ fullarc.rad = arc->rad;
393
+ set_full_arc(&fullarc);
394
+
395
+ /* special case of full arc */
396
+ if(arc->angle == 90) {
397
+ copy_arc(arc, &fullarc);
398
+ return;
399
+ }
400
+
401
+ /* compute 1st arc using the geometric construction of curve */
402
+ uint16_t t2 = TperDegree[arc->angle + span];
403
+
404
+ /* lerp for A */
405
+ float a2x = lerp((float)fullarc.p0x, (float)fullarc.p1x, t2);
406
+ float a2y = lerp((float)fullarc.p0y, (float)fullarc.p1y, t2);
407
+ /* lerp for B */
408
+ float b2x = lerp((float)fullarc.p1x, (float)fullarc.p2x, t2);
409
+ float b2y = lerp((float)fullarc.p1y, (float)fullarc.p2y, t2);
410
+ /* lerp for C */
411
+ float c2x = lerp((float)fullarc.p2x, (float)fullarc.p3x, t2);
412
+ float c2y = lerp((float)fullarc.p2y, (float)fullarc.p3y, t2);
413
+
414
+ /* lerp for D */
415
+ float d2x = lerp(a2x, b2x, t2);
416
+ float d2y = lerp(a2y, b2y, t2);
417
+ /* lerp for E */
418
+ float e2x = lerp(b2x, c2x, t2);
419
+ float e2y = lerp(b2y, c2y, t2);
420
+
421
+ float pt2x = lerp(d2x, e2x, t2);
422
+ float pt2y = lerp(d2y, e2y, t2);
423
+
424
+ /* compute sub-arc using the geometric construction of curve */
425
+ uint16_t t1 = TperDegree[arc->angle];
426
+
427
+ /* lerp for A */
428
+ float a1x = lerp((float)fullarc.p0x, (float)fullarc.p1x, t1);
429
+ float a1y = lerp((float)fullarc.p0y, (float)fullarc.p1y, t1);
430
+ /* lerp for B */
431
+ float b1x = lerp((float)fullarc.p1x, (float)fullarc.p2x, t1);
432
+ float b1y = lerp((float)fullarc.p1y, (float)fullarc.p2y, t1);
433
+ /* lerp for C */
434
+ float c1x = lerp((float)fullarc.p2x, (float)fullarc.p3x, t1);
435
+ float c1y = lerp((float)fullarc.p2y, (float)fullarc.p3y, t1);
436
+
437
+ /* lerp for D */
438
+ float d1x = lerp(a1x, b1x, t1);
439
+ float d1y = lerp(a1y, b1y, t1);
440
+ /* lerp for E */
441
+ float e1x = lerp(b1x, c1x, t1);
442
+ float e1y = lerp(b1y, c1y, t1);
443
+
444
+ float pt1x = lerp(d1x, e1x, t1);
445
+ float pt1y = lerp(d1y, e1y, t1);
446
+
447
+ /* find the 't3' parameter for point P(t1) on the sub-arc [P0 A2 D2 P(t2)] using dichotomy
448
+ * use position of x axis only */
449
+ uint16_t t3;
450
+ t3 = get_bez_t_from_pos(pt1x,
451
+ (cubic_cont_pt) {
452
+ .p0 = ((float)fullarc.p0x), .p1 = a2x, .p2 = d2x, .p3 = pt2x
453
+ },
454
+ (bool)(pt2x < (float)fullarc.p0x));
455
+
456
+ /* lerp for B */
457
+ float b3x = lerp(a2x, d2x, t3);
458
+ float b3y = lerp(a2y, d2y, t3);
459
+ /* lerp for C */
460
+ float c3x = lerp(d2x, pt2x, t3);
461
+ float c3y = lerp(d2y, pt2y, t3);
462
+
463
+ /* lerp for E */
464
+ float e3x = lerp(b3x, c3x, t3);
465
+ float e3y = lerp(b3y, c3y, t3);
466
+
467
+ arc->p0x = (int32_t)floorf(0.5f + pt1x);
468
+ arc->p0y = (int32_t)floorf(0.5f + pt1y);
469
+ arc->p1x = (int32_t)floorf(0.5f + e3x);
470
+ arc->p1y = (int32_t)floorf(0.5f + e3y);
471
+ arc->p2x = (int32_t)floorf(0.5f + c3x);
472
+ arc->p2y = (int32_t)floorf(0.5f + c3y);
473
+ arc->p3x = (int32_t)floorf(0.5f + pt2x);
474
+ arc->p3y = (int32_t)floorf(0.5f + pt2y);
475
+ }
476
+
477
+ /**
478
+ * Gives relative coords of the control points
479
+ */
480
+ static void get_arc_control_points(vg_arc * arc, bool start)
481
+ {
482
+ vg_arc fullarc;
483
+ fullarc.angle = arc->angle;
484
+ fullarc.quarter = arc->quarter;
485
+ fullarc.rad = arc->rad;
486
+ set_full_arc(&fullarc);
487
+
488
+ /* special case of full arc */
489
+ if(arc->angle == 90) {
490
+ copy_arc(arc, &fullarc);
491
+ return;
492
+ }
493
+
494
+ /* compute sub-arc using the geometric construction of curve */
495
+ uint16_t t = TperDegree[arc->angle];
496
+ /* lerp for A */
497
+ float ax = lerp((float)fullarc.p0x, (float)fullarc.p1x, t);
498
+ float ay = lerp((float)fullarc.p0y, (float)fullarc.p1y, t);
499
+ /* lerp for B */
500
+ float bx = lerp((float)fullarc.p1x, (float)fullarc.p2x, t);
501
+ float by = lerp((float)fullarc.p1y, (float)fullarc.p2y, t);
502
+ /* lerp for C */
503
+ float cx = lerp((float)fullarc.p2x, (float)fullarc.p3x, t);
504
+ float cy = lerp((float)fullarc.p2y, (float)fullarc.p3y, t);
505
+
506
+ /* lerp for D */
507
+ float dx = lerp(ax, bx, t);
508
+ float dy = lerp(ay, by, t);
509
+ /* lerp for E */
510
+ float ex = lerp(bx, cx, t);
511
+ float ey = lerp(by, cy, t);
512
+
513
+ /* sub-arc's control points are tangents of DeCasteljau's algorithm */
514
+ if(start) {
515
+ arc->p0x = (int32_t)floorf(0.5f + lerp(dx, ex, t));
516
+ arc->p0y = (int32_t)floorf(0.5f + lerp(dy, ey, t));
517
+ arc->p1x = (int32_t)floorf(0.5f + ex);
518
+ arc->p1y = (int32_t)floorf(0.5f + ey);
519
+ arc->p2x = (int32_t)floorf(0.5f + cx);
520
+ arc->p2y = (int32_t)floorf(0.5f + cy);
521
+ arc->p3x = fullarc.p3x;
522
+ arc->p3y = fullarc.p3y;
523
+ }
524
+ else {
525
+ arc->p0x = fullarc.p0x;
526
+ arc->p0y = fullarc.p0y;
527
+ arc->p1x = (int32_t)floorf(0.5f + ax);
528
+ arc->p1y = (int32_t)floorf(0.5f + ay);
529
+ arc->p2x = (int32_t)floorf(0.5f + dx);
530
+ arc->p2y = (int32_t)floorf(0.5f + dy);
531
+ arc->p3x = (int32_t)floorf(0.5f + lerp(dx, ex, t));
532
+ arc->p3y = (int32_t)floorf(0.5f + lerp(dy, ey, t));
533
+ }
534
+ }
535
+
536
+ /**
537
+ * Add the arc control points into the path data for vglite,
538
+ * taking into account the real center of the arc (translation).
539
+ * arc_path: (in/out) the path data array for vglite
540
+ * pidx: (in/out) index of last element added in arc_path
541
+ * q_arc: (in) the arc data containing control points
542
+ * center: (in) the center of the circle in draw coordinates
543
+ * cw: (in) true if arc is clockwise
544
+ */
545
+ static void add_split_arc_path(int32_t * arc_path, int * pidx, vg_arc * q_arc, const lv_point_t * center, bool cw)
546
+ {
547
+ /* assumes first control point already in array arc_path[] */
548
+ int idx = *pidx;
549
+ if(cw) {
550
+ #if BEZIER_DBG_CONTROL_POINTS
551
+ arc_path[idx++] = VLC_OP_LINE;
552
+ arc_path[idx++] = q_arc->p1x + center->x;
553
+ arc_path[idx++] = q_arc->p1y + center->y;
554
+ arc_path[idx++] = VLC_OP_LINE;
555
+ arc_path[idx++] = q_arc->p2x + center->x;
556
+ arc_path[idx++] = q_arc->p2y + center->y;
557
+ arc_path[idx++] = VLC_OP_LINE;
558
+ arc_path[idx++] = q_arc->p3x + center->x;
559
+ arc_path[idx++] = q_arc->p3y + center->y;
560
+ #else
561
+ arc_path[idx++] = VLC_OP_CUBIC;
562
+ arc_path[idx++] = q_arc->p1x + center->x;
563
+ arc_path[idx++] = q_arc->p1y + center->y;
564
+ arc_path[idx++] = q_arc->p2x + center->x;
565
+ arc_path[idx++] = q_arc->p2y + center->y;
566
+ arc_path[idx++] = q_arc->p3x + center->x;
567
+ arc_path[idx++] = q_arc->p3y + center->y;
568
+ #endif
569
+ }
570
+ else { /* reverse points order when counter-clockwise */
571
+ #if BEZIER_DBG_CONTROL_POINTS
572
+ arc_path[idx++] = VLC_OP_LINE;
573
+ arc_path[idx++] = q_arc->p2x + center->x;
574
+ arc_path[idx++] = q_arc->p2y + center->y;
575
+ arc_path[idx++] = VLC_OP_LINE;
576
+ arc_path[idx++] = q_arc->p1x + center->x;
577
+ arc_path[idx++] = q_arc->p1y + center->y;
578
+ arc_path[idx++] = VLC_OP_LINE;
579
+ arc_path[idx++] = q_arc->p0x + center->x;
580
+ arc_path[idx++] = q_arc->p0y + center->y;
581
+ #else
582
+ arc_path[idx++] = VLC_OP_CUBIC;
583
+ arc_path[idx++] = q_arc->p2x + center->x;
584
+ arc_path[idx++] = q_arc->p2y + center->y;
585
+ arc_path[idx++] = q_arc->p1x + center->x;
586
+ arc_path[idx++] = q_arc->p1y + center->y;
587
+ arc_path[idx++] = q_arc->p0x + center->x;
588
+ arc_path[idx++] = q_arc->p0y + center->y;
589
+ #endif
590
+ }
591
+ /* update index i n path array*/
592
+ *pidx = idx;
593
+ }
594
+
595
+ static void add_arc_path(int32_t * arc_path, int * pidx, int32_t radius,
596
+ int32_t start_angle, int32_t end_angle, const lv_point_t * center, bool cw)
597
+ {
598
+ if(end_angle < start_angle) end_angle += 360;
599
+
600
+ /* set number of arcs to draw */
601
+ vg_arc q_arc;
602
+ int32_t start_arc_angle = start_angle % 90;
603
+ int32_t end_arc_angle = end_angle % 90;
604
+ int32_t inv_start_arc_angle = (start_arc_angle > 0) ? (90 - start_arc_angle) : 0;
605
+ int32_t nbarc = (end_angle - start_angle - inv_start_arc_angle - end_arc_angle) / 90;
606
+ q_arc.rad = radius;
607
+
608
+ /* handle special case of start & end point in the same quarter */
609
+ if(((start_angle / 90) == (end_angle / 90)) && (nbarc <= 0)) {
610
+ q_arc.quarter = (start_angle / 90) % 4;
611
+ q_arc.angle = start_arc_angle;
612
+ get_subarc_control_points(&q_arc, end_arc_angle - start_arc_angle);
613
+ add_split_arc_path(arc_path, pidx, &q_arc, center, cw);
614
+ return;
615
+ }
616
+
617
+ if(cw) {
618
+ /* partial starting arc */
619
+ if(start_arc_angle > 0) {
620
+ q_arc.quarter = (start_angle / 90) % 4;
621
+ q_arc.angle = start_arc_angle;
622
+ /* get cubic points relative to center */
623
+ get_arc_control_points(&q_arc, true);
624
+ /* put cubic points in arc_path */
625
+ add_split_arc_path(arc_path, pidx, &q_arc, center, cw);
626
+ }
627
+ /* full arcs */
628
+ for(int32_t q = 0; q < nbarc ; q++) {
629
+ q_arc.quarter = (q + ((start_angle + 89) / 90)) % 4;
630
+ q_arc.angle = 90;
631
+ /* get cubic points relative to center */
632
+ get_arc_control_points(&q_arc, true); /* 2nd parameter 'start' ignored */
633
+ /* put cubic points in arc_path */
634
+ add_split_arc_path(arc_path, pidx, &q_arc, center, cw);
635
+ }
636
+ /* partial ending arc */
637
+ if(end_arc_angle > 0) {
638
+ q_arc.quarter = (end_angle / 90) % 4;
639
+ q_arc.angle = end_arc_angle;
640
+ /* get cubic points relative to center */
641
+ get_arc_control_points(&q_arc, false);
642
+ /* put cubic points in arc_path */
643
+ add_split_arc_path(arc_path, pidx, &q_arc, center, cw);
644
+ }
645
+
646
+ }
647
+ else { /* counter clockwise */
648
+
649
+ /* partial ending arc */
650
+ if(end_arc_angle > 0) {
651
+ q_arc.quarter = (end_angle / 90) % 4;
652
+ q_arc.angle = end_arc_angle;
653
+ /* get cubic points relative to center */
654
+ get_arc_control_points(&q_arc, false);
655
+ /* put cubic points in arc_path */
656
+ add_split_arc_path(arc_path, pidx, &q_arc, center, cw);
657
+ }
658
+ /* full arcs */
659
+ for(int32_t q = nbarc - 1; q >= 0; q--) {
660
+ q_arc.quarter = (q + ((start_angle + 89) / 90)) % 4;
661
+ q_arc.angle = 90;
662
+ /* get cubic points relative to center */
663
+ get_arc_control_points(&q_arc, true); /* 2nd parameter 'start' ignored */
664
+ /* put cubic points in arc_path */
665
+ add_split_arc_path(arc_path, pidx, &q_arc, center, cw);
666
+ }
667
+ /* partial starting arc */
668
+ if(start_arc_angle > 0) {
669
+ q_arc.quarter = (start_angle / 90) % 4;
670
+ q_arc.angle = start_arc_angle;
671
+ /* get cubic points relative to center */
672
+ get_arc_control_points(&q_arc, true);
673
+ /* put cubic points in arc_path */
674
+ add_split_arc_path(arc_path, pidx, &q_arc, center, cw);
675
+ }
676
+ }
677
+ }
678
+
679
+ #endif /*LV_USE_GPU_NXP_VG_LITE*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite_arc.h ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_vglite_arc.h
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2021-2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ #ifndef LV_DRAW_VGLITE_ARC_H
31
+ #define LV_DRAW_VGLITE_ARC_H
32
+
33
+ #ifdef __cplusplus
34
+ extern "C" {
35
+ #endif
36
+
37
+ /*********************
38
+ * INCLUDES
39
+ *********************/
40
+ #include "../../../lv_conf_internal.h"
41
+
42
+ #if LV_USE_GPU_NXP_VG_LITE
43
+ #include "lv_vglite_utils.h"
44
+
45
+ /*********************
46
+ * DEFINES
47
+ *********************/
48
+
49
+ /**********************
50
+ * TYPEDEFS
51
+ **********************/
52
+
53
+ /**********************
54
+ * GLOBAL PROTOTYPES
55
+ **********************/
56
+
57
+ /**
58
+ * Draw arc shape with effects
59
+ *
60
+ * @param[in] center Arc center with relative coordinates
61
+ * @param[in] radius Radius of external arc
62
+ * @param[in] start_angle Starting angle in degrees
63
+ * @param[in] end_angle Ending angle in degrees
64
+ * @param[in] clip_area Clipping area with relative coordinates to dest buff
65
+ * @param[in] dsc Arc description structure (width, rounded ending, opacity)
66
+ *
67
+ * @retval LV_RES_OK Draw completed
68
+ * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
69
+ */
70
+ lv_res_t lv_gpu_nxp_vglite_draw_arc(const lv_point_t * center, int32_t radius, int32_t start_angle, int32_t end_angle,
71
+ const lv_area_t * clip_area, const lv_draw_arc_dsc_t * dsc);
72
+
73
+ /**********************
74
+ * MACROS
75
+ **********************/
76
+
77
+ #endif /*LV_USE_GPU_NXP_VG_LITE*/
78
+
79
+ #ifdef __cplusplus
80
+ } /*extern "C"*/
81
+ #endif
82
+
83
+ #endif /*LV_DRAW_VGLITE_ARC_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite_blend.c ADDED
@@ -0,0 +1,635 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_vglite_blend.c
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2020-2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ /*********************
31
+ * INCLUDES
32
+ *********************/
33
+
34
+ #include "lv_draw_vglite_blend.h"
35
+
36
+ #if LV_USE_GPU_NXP_VG_LITE
37
+ #include "lv_vglite_buf.h"
38
+ #include "lv_vglite_utils.h"
39
+
40
+ /*********************
41
+ * DEFINES
42
+ *********************/
43
+
44
+ /** Stride in px required by VG-Lite HW*/
45
+ #define LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX 16U
46
+
47
+ #if VG_LITE_BLIT_SPLIT_ENABLED
48
+ /**
49
+ * BLIT split threshold - BLITs with width or height higher than this value will be done
50
+ * in multiple steps. Value must be 16-aligned. Don't change.
51
+ */
52
+ #define LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR 352
53
+ #endif
54
+
55
+ /**********************
56
+ * TYPEDEFS
57
+ **********************/
58
+
59
+ /**********************
60
+ * STATIC PROTOTYPES
61
+ **********************/
62
+
63
+ /**
64
+ * Blit image, with optional opacity.
65
+ *
66
+ * @param[in] src_area Source area with relative coordinates of source buffer
67
+ * @param[in] opa Opacity
68
+ *
69
+ * @retval LV_RES_OK Transfer complete
70
+ * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
71
+ */
72
+ static lv_res_t lv_vglite_blit(const lv_area_t * src_area, lv_opa_t opa);
73
+
74
+ /**
75
+ * Check source memory and stride alignment.
76
+ *
77
+ * @param[in] src_buf Source buffer
78
+ * @param[in] src_stride Stride of source buffer in pixels
79
+ *
80
+ * @retval LV_RES_OK Alignment OK
81
+ * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
82
+ */
83
+ static lv_res_t check_src_alignment(const lv_color_t * src_buf, lv_coord_t src_stride);
84
+
85
+ /**
86
+ * Creates matrix that translates to origin of given destination area.
87
+ *
88
+ * @param[in] dest_area Area with relative coordinates of destination buffer
89
+ */
90
+ static inline void lv_vglite_set_translation_matrix(const lv_area_t * dest_area);
91
+
92
+ /**
93
+ * Creates matrix that translates to origin of given destination area with transformation (scale or rotate).
94
+ *
95
+ * @param[in] dest_area Area with relative coordinates of destination buffer
96
+ * @param[in] dsc Image descriptor
97
+ */
98
+ static inline void lv_vglite_set_transformation_matrix(const lv_area_t * dest_area, const lv_draw_img_dsc_t * dsc);
99
+
100
+ #if VG_LITE_BLIT_SPLIT_ENABLED
101
+ /**
102
+ * Move buffer pointer as close as possible to area, but with respect to alignment requirements. X-axis only.
103
+ *
104
+ * @param[in/out] area Area to be updated
105
+ * @param[in/out] buf Pointer to be updated
106
+ */
107
+ static void align_x(lv_area_t * area, lv_color_t ** buf);
108
+
109
+ /**
110
+ * Move buffer pointer to the area start and update variables, Y-axis only.
111
+ *
112
+ * @param[in/out] area Area to be updated
113
+ * @param[in/out] buf Pointer to be updated
114
+ * @param[in] stride Buffer stride in pixels
115
+ */
116
+ static void align_y(lv_area_t * area, lv_color_t ** buf, lv_coord_t stride);
117
+
118
+ /**
119
+ * Blit image split in tiles, with optional opacity.
120
+ *
121
+ * @param[in/out] dest_buf Destination buffer
122
+ * @param[in] dest_area Area with relative coordinates of destination buffer
123
+ * @param[in] dest_stride Stride of destination buffer in pixels
124
+ * @param[in] src_buf Source buffer
125
+ * @param[in] src_area Source area with relative coordinates of source buffer
126
+ * @param[in] src_stride Stride of source buffer in pixels
127
+ * @param[in] opa Opacity
128
+ *
129
+ * @retval LV_RES_OK Transfer complete
130
+ * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
131
+ */
132
+ static lv_res_t lv_vglite_blit_split(lv_color_t * dest_buf, lv_area_t * dest_area, lv_coord_t dest_stride,
133
+ const lv_color_t * src_buf, lv_area_t * src_area, lv_coord_t src_stride,
134
+ lv_opa_t opa);
135
+ #endif /*VG_LITE_BLIT_SPLIT_ENABLED*/
136
+
137
+ /**********************
138
+ * STATIC VARIABLES
139
+ **********************/
140
+
141
+ static vg_lite_matrix_t vgmatrix;
142
+
143
+ /**********************
144
+ * MACROS
145
+ **********************/
146
+
147
+ /**********************
148
+ * GLOBAL FUNCTIONS
149
+ **********************/
150
+
151
+ lv_res_t lv_gpu_nxp_vglite_fill(const lv_area_t * dest_area, lv_color_t color, lv_opa_t opa)
152
+ {
153
+ vg_lite_error_t err = VG_LITE_SUCCESS;
154
+ lv_color32_t col32 = {.full = lv_color_to32(color)}; /*Convert color to RGBA8888*/
155
+ vg_lite_color_t vgcol; /* vglite takes ABGR */
156
+ vg_lite_buffer_t * vgbuf = lv_vglite_get_dest_buf();
157
+
158
+ vg_lite_buffer_format_t color_format = LV_COLOR_DEPTH == 16 ? VG_LITE_BGRA8888 : VG_LITE_ABGR8888;
159
+ if(lv_vglite_premult_and_swizzle(&vgcol, col32, opa, color_format) != LV_RES_OK)
160
+ VG_LITE_RETURN_INV("Premultiplication and swizzle failed.");
161
+
162
+ if(opa >= (lv_opa_t)LV_OPA_MAX) { /*Opaque fill*/
163
+ vg_lite_rectangle_t rect = {
164
+ .x = dest_area->x1,
165
+ .y = dest_area->y1,
166
+ .width = lv_area_get_width(dest_area),
167
+ .height = lv_area_get_height(dest_area)
168
+ };
169
+
170
+ err = vg_lite_clear(vgbuf, &rect, vgcol);
171
+ VG_LITE_ERR_RETURN_INV(err, "Clear failed.");
172
+
173
+ if(lv_vglite_run() != LV_RES_OK)
174
+ VG_LITE_RETURN_INV("Run failed.");
175
+ }
176
+ else { /*fill with transparency*/
177
+
178
+ vg_lite_path_t path;
179
+ int32_t path_data[] = { /*VG rectangular path*/
180
+ VLC_OP_MOVE, dest_area->x1, dest_area->y1,
181
+ VLC_OP_LINE, dest_area->x2 + 1, dest_area->y1,
182
+ VLC_OP_LINE, dest_area->x2 + 1, dest_area->y2 + 1,
183
+ VLC_OP_LINE, dest_area->x1, dest_area->y2 + 1,
184
+ VLC_OP_LINE, dest_area->x1, dest_area->y1,
185
+ VLC_OP_END
186
+ };
187
+
188
+ err = vg_lite_init_path(&path, VG_LITE_S32, VG_LITE_LOW, sizeof(path_data), path_data,
189
+ (vg_lite_float_t) dest_area->x1, (vg_lite_float_t) dest_area->y1,
190
+ ((vg_lite_float_t) dest_area->x2) + 1.0f, ((vg_lite_float_t) dest_area->y2) + 1.0f);
191
+ VG_LITE_ERR_RETURN_INV(err, "Init path failed.");
192
+
193
+ vg_lite_matrix_t matrix;
194
+ vg_lite_identity(&matrix);
195
+
196
+ /*Draw rectangle*/
197
+ err = vg_lite_draw(vgbuf, &path, VG_LITE_FILL_EVEN_ODD, &matrix, VG_LITE_BLEND_SRC_OVER, vgcol);
198
+ VG_LITE_ERR_RETURN_INV(err, "Draw rectangle failed.");
199
+
200
+ if(lv_vglite_run() != LV_RES_OK)
201
+ VG_LITE_RETURN_INV("Run failed.");
202
+
203
+ err = vg_lite_clear_path(&path);
204
+ VG_LITE_ERR_RETURN_INV(err, "Clear path failed.");
205
+ }
206
+
207
+ return LV_RES_OK;
208
+ }
209
+
210
+ #if VG_LITE_BLIT_SPLIT_ENABLED
211
+ lv_res_t lv_gpu_nxp_vglite_blit_split(lv_color_t * dest_buf, lv_area_t * dest_area, lv_coord_t dest_stride,
212
+ const lv_color_t * src_buf, lv_area_t * src_area, lv_coord_t src_stride,
213
+ lv_opa_t opa)
214
+ {
215
+ /* Set src_vgbuf structure. */
216
+ lv_vglite_set_src_buf(src_buf, src_area, src_stride);
217
+
218
+ lv_color_t * orig_dest_buf = dest_buf;
219
+
220
+ lv_res_t rv = lv_vglite_blit_split(dest_buf, dest_area, dest_stride, src_buf, src_area, src_stride, opa);
221
+
222
+ /* Restore the original dest_vgbuf memory address. */
223
+ lv_vglite_set_dest_buf_ptr(orig_dest_buf);
224
+
225
+ return rv;
226
+ }
227
+ #else
228
+ lv_res_t lv_gpu_nxp_vglite_blit(const lv_area_t * dest_area,
229
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride,
230
+ lv_opa_t opa)
231
+ {
232
+ if(check_src_alignment(src_buf, src_stride) != LV_RES_OK)
233
+ VG_LITE_RETURN_INV("Check src alignment failed.");
234
+
235
+ /* Set src_vgbuf structure. */
236
+ lv_vglite_set_src_buf(src_buf, src_area, src_stride);
237
+
238
+ /* Set scissor. */
239
+ lv_vglite_set_scissor(dest_area);
240
+
241
+ /* Set vgmatrix. */
242
+ lv_vglite_set_translation_matrix(dest_area);
243
+
244
+ /* Start blit. */
245
+ lv_res_t rv = lv_vglite_blit(src_area, opa);
246
+
247
+ /* Disable scissor. */
248
+ lv_vglite_disable_scissor();
249
+
250
+ return rv;
251
+ }
252
+
253
+ lv_res_t lv_gpu_nxp_vglite_blit_transform(const lv_area_t * dest_area, const lv_area_t * clip_area,
254
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride,
255
+ const lv_draw_img_dsc_t * dsc)
256
+ {
257
+ lv_res_t rv = LV_RES_INV;
258
+
259
+ if(check_src_alignment(src_buf, src_stride) != LV_RES_OK)
260
+ VG_LITE_RETURN_INV("Check src alignment failed.");
261
+
262
+ /* Set src_vgbuf structure. */
263
+ lv_vglite_set_src_buf(src_buf, src_area, src_stride);
264
+
265
+ /* Set scissor */
266
+ lv_vglite_set_scissor(clip_area);
267
+
268
+ /* Set vgmatrix. */
269
+ lv_vglite_set_transformation_matrix(dest_area, dsc);
270
+
271
+ /* Start blit. */
272
+ rv = lv_vglite_blit(src_area, dsc->opa);
273
+
274
+ /* Disable scissor. */
275
+ lv_vglite_disable_scissor();
276
+
277
+ return rv;
278
+ }
279
+ #endif /*VG_LITE_BLIT_SPLIT_ENABLED*/
280
+
281
+ lv_res_t lv_gpu_nxp_vglite_buffer_copy(lv_color_t * dest_buf, const lv_area_t * dest_area, lv_coord_t dest_stride,
282
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride)
283
+ {
284
+ vg_lite_error_t err = VG_LITE_SUCCESS;
285
+
286
+ if(check_src_alignment(src_buf, src_stride) != LV_RES_OK)
287
+ VG_LITE_RETURN_INV("Check src alignment failed.");
288
+
289
+ vg_lite_buffer_t src_vgbuf;
290
+ /* Set src_vgbuf structure. */
291
+ lv_vglite_set_buf(&src_vgbuf, src_buf, src_area, src_stride);
292
+
293
+ vg_lite_buffer_t dest_vgbuf;
294
+ /* Set dest_vgbuf structure. */
295
+ lv_vglite_set_buf(&dest_vgbuf, dest_buf, dest_area, dest_stride);
296
+
297
+ uint32_t rect[] = {
298
+ (uint32_t)src_area->x1, /* start x */
299
+ (uint32_t)src_area->y1, /* start y */
300
+ (uint32_t)lv_area_get_width(src_area), /* width */
301
+ (uint32_t)lv_area_get_height(src_area) /* height */
302
+ };
303
+
304
+ /* Set scissor. */
305
+ lv_vglite_set_scissor(dest_area);
306
+
307
+ /* Set vgmatrix. */
308
+ lv_vglite_set_translation_matrix(dest_area);
309
+
310
+ err = vg_lite_blit_rect(&dest_vgbuf, &src_vgbuf, rect, &vgmatrix,
311
+ VG_LITE_BLEND_NONE, 0xFFFFFFFFU, VG_LITE_FILTER_POINT);
312
+ if(err != VG_LITE_SUCCESS) {
313
+ LV_LOG_ERROR("Blit rectangle failed.");
314
+ /* Disable scissor. */
315
+ lv_vglite_disable_scissor();
316
+
317
+ return LV_RES_INV;
318
+ }
319
+
320
+ if(lv_vglite_run() != LV_RES_OK) {
321
+ LV_LOG_ERROR("Run failed.");
322
+ /* Disable scissor. */
323
+ lv_vglite_disable_scissor();
324
+
325
+ return LV_RES_INV;
326
+ }
327
+
328
+ /* Disable scissor. */
329
+ lv_vglite_disable_scissor();
330
+
331
+ return LV_RES_OK;
332
+ }
333
+
334
+ /**********************
335
+ * STATIC FUNCTIONS
336
+ **********************/
337
+
338
+ #if VG_LITE_BLIT_SPLIT_ENABLED
339
+ static lv_res_t lv_vglite_blit_split(lv_color_t * dest_buf, lv_area_t * dest_area, lv_coord_t dest_stride,
340
+ const lv_color_t * src_buf, lv_area_t * src_area, lv_coord_t src_stride,
341
+ lv_opa_t opa)
342
+ {
343
+ lv_res_t rv = LV_RES_INV;
344
+
345
+ VG_LITE_LOG_TRACE("Blit "
346
+ "Area: ([%d,%d], [%d,%d]) -> ([%d,%d], [%d,%d]) | "
347
+ "Size: ([%dx%d] -> [%dx%d]) | "
348
+ "Addr: (0x%x -> 0x%x)",
349
+ src_area->x1, src_area->y1, src_area->x2, src_area->y2,
350
+ dest_area->x1, dest_area->y1, dest_area->x2, dest_area->y2,
351
+ lv_area_get_width(src_area), lv_area_get_height(src_area),
352
+ lv_area_get_width(dest_area), lv_area_get_height(dest_area),
353
+ (uintptr_t)src_buf, (uintptr_t)dest_buf);
354
+
355
+ /* Stage 1: Move starting pointers as close as possible to [x1, y1], so coordinates are as small as possible. */
356
+ align_x(src_area, (lv_color_t **)&src_buf);
357
+ align_y(src_area, (lv_color_t **)&src_buf, src_stride);
358
+ align_x(dest_area, (lv_color_t **)&dest_buf);
359
+ align_y(dest_area, (lv_color_t **)&dest_buf, dest_stride);
360
+
361
+ /* Stage 2: If we're in limit, do a single BLIT */
362
+ if((src_area->x2 < LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR) &&
363
+ (src_area->y2 < LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR)) {
364
+ if(check_src_alignment(src_buf, src_stride) != LV_RES_OK)
365
+ VG_LITE_RETURN_INV("Check src alignment failed.");
366
+
367
+ /* Set new dest_vgbuf and src_vgbuf memory addresses. */
368
+ lv_vglite_set_dest_buf_ptr(dest_buf);
369
+ lv_vglite_set_src_buf_ptr(src_buf);
370
+
371
+ /* Set scissor */
372
+ lv_vglite_set_scissor(dest_area);
373
+
374
+ /* Set vgmatrix. */
375
+ lv_vglite_set_translation_matrix(dest_area);
376
+
377
+ /* Start blit. */
378
+ rv = lv_vglite_blit(src_area, opa);
379
+
380
+ /* Disable scissor. */
381
+ lv_vglite_disable_scissor();
382
+
383
+ VG_LITE_LOG_TRACE("Single "
384
+ "Area: ([%d,%d], [%d,%d]) -> ([%d,%d], [%d,%d]) | "
385
+ "Size: ([%dx%d] -> [%dx%d]) | "
386
+ "Addr: (0x%x -> 0x%x) %s",
387
+ src_area->x1, src_area->y1, src_area->x2, src_area->y2,
388
+ dest_area->x1, dest_area->y1, dest_area->x2, dest_area->y2,
389
+ lv_area_get_width(src_area), lv_area_get_height(src_area),
390
+ lv_area_get_width(dest_area), lv_area_get_height(dest_area),
391
+ (uintptr_t)src_buf, (uintptr_t)dest_buf,
392
+ rv == LV_RES_OK ? "OK!" : "FAILED!");
393
+
394
+ return rv;
395
+ };
396
+
397
+ /* Stage 3: Split the BLIT into multiple tiles */
398
+ VG_LITE_LOG_TRACE("Split "
399
+ "Area: ([%d,%d], [%d,%d]) -> ([%d,%d], [%d,%d]) | "
400
+ "Size: ([%dx%d] -> [%dx%d]) | "
401
+ "Addr: (0x%x -> 0x%x)",
402
+ src_area->x1, src_area->y1, src_area->x2, src_area->y2,
403
+ dest_area->x1, dest_area->y1, dest_area->x2, dest_area->y2,
404
+ lv_area_get_width(src_area), lv_area_get_height(src_area),
405
+ lv_area_get_width(dest_area), lv_area_get_height(dest_area),
406
+ (uintptr_t)src_buf, (uintptr_t)dest_buf);
407
+
408
+
409
+ lv_coord_t width = lv_area_get_width(src_area);
410
+ lv_coord_t height = lv_area_get_height(src_area);
411
+
412
+ /* Number of tiles needed */
413
+ int total_tiles_x = (src_area->x1 + width + LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR - 1) /
414
+ LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR;
415
+ int total_tiles_y = (src_area->y1 + height + LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR - 1) /
416
+ LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR;
417
+
418
+ /* src and dst buffer shift against each other. Src buffer real data [0,0] may start actually at [3,0] in buffer, as
419
+ * the buffer pointer has to be aligned, while dst buffer real data [0,0] may start at [1,0] in buffer. alignment may be
420
+ * different */
421
+ int shift_src_x = (src_area->x1 > dest_area->x1) ? (src_area->x1 - dest_area->x1) : 0;
422
+ int shift_dest_x = (src_area->x1 < dest_area->x1) ? (dest_area->x1 - src_area->x1) : 0;
423
+
424
+ VG_LITE_LOG_TRACE("X shift: src: %d, dst: %d", shift_src_x, shift_dest_x);
425
+
426
+ lv_color_t * tile_dest_buf;
427
+ lv_area_t tile_dest_area;
428
+ const lv_color_t * tile_src_buf;
429
+ lv_area_t tile_src_area;
430
+
431
+ for(int y = 0; y < total_tiles_y; y++) {
432
+
433
+ tile_src_area.y1 = 0; /* no vertical alignment, always start from 0 */
434
+ tile_src_area.y2 = height - y * LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR - 1;
435
+ if(tile_src_area.y2 >= LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR) {
436
+ tile_src_area.y2 = LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR - 1; /* Should never happen */
437
+ }
438
+ tile_src_buf = src_buf + y * LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR * src_stride;
439
+
440
+ tile_dest_area.y1 = tile_src_area.y1; /* y has no alignment, always in sync with src */
441
+ tile_dest_area.y2 = tile_src_area.y2;
442
+
443
+ tile_dest_buf = dest_buf + y * LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR * dest_stride;
444
+
445
+ for(int x = 0; x < total_tiles_x; x++) {
446
+
447
+ if(x == 0) {
448
+ /* 1st tile is special - there may be a gap between buffer start pointer
449
+ * and area.x1 value, as the pointer has to be aligned.
450
+ * tile_src_buf pointer - keep init value from Y-loop.
451
+ * Also, 1st tile start is not shifted! shift is applied from 2nd tile */
452
+ tile_src_area.x1 = src_area->x1;
453
+ tile_dest_area.x1 = dest_area->x1;
454
+ }
455
+ else {
456
+ /* subsequent tiles always starts from 0, but shifted*/
457
+ tile_src_area.x1 = 0 + shift_src_x;
458
+ tile_dest_area.x1 = 0 + shift_dest_x;
459
+ /* and advance start pointer + 1 tile size */
460
+ tile_src_buf += LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR;
461
+ tile_dest_buf += LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR;
462
+ }
463
+
464
+ /* Clip tile end coordinates */
465
+ tile_src_area.x2 = width + src_area->x1 - x * LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR - 1;
466
+ if(tile_src_area.x2 >= LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR) {
467
+ tile_src_area.x2 = LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR - 1;
468
+ }
469
+
470
+ tile_dest_area.x2 = width + dest_area->x1 - x * LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR - 1;
471
+ if(tile_dest_area.x2 >= LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR) {
472
+ tile_dest_area.x2 = LV_GPU_NXP_VG_LITE_BLIT_SPLIT_THR - 1;
473
+ }
474
+
475
+ if(x < (total_tiles_x - 1)) {
476
+ /* And adjust end coords if shifted, but not for last tile! */
477
+ tile_src_area.x2 += shift_src_x;
478
+ tile_dest_area.x2 += shift_dest_x;
479
+ }
480
+
481
+ if(check_src_alignment(tile_src_buf, src_stride) != LV_RES_OK)
482
+ VG_LITE_RETURN_INV("Check src alignment failed.");
483
+
484
+ /* Set new dest_vgbuf and src_vgbuf memory addresses. */
485
+ lv_vglite_set_dest_buf_ptr(tile_dest_buf);
486
+ lv_vglite_set_src_buf_ptr(tile_src_buf);
487
+
488
+ /* Set scissor */
489
+ lv_vglite_set_scissor(&tile_dest_area);
490
+
491
+ /* Set vgmatrix. */
492
+ lv_vglite_set_translation_matrix(&tile_dest_area);
493
+
494
+ /* Start blit. */
495
+ rv = lv_vglite_blit(&tile_src_area, opa);
496
+
497
+ /* Disable scissor. */
498
+ lv_vglite_disable_scissor();
499
+
500
+ VG_LITE_LOG_TRACE("Tile [%d, %d] "
501
+ "Area: ([%d,%d], [%d,%d]) -> ([%d,%d], [%d,%d]) | "
502
+ "Size: ([%dx%d] -> [%dx%d]) | "
503
+ "Addr: (0x%x -> 0x%x) %s",
504
+ x, y,
505
+ tile_src_area.x1, tile_src_area.y1, tile_src_area.x2, tile_src_area.y2,
506
+ tile_dest_area.x1, tile_dest_area.y1, tile_dest_area.x2, tile_dest_area.y2,
507
+ lv_area_get_width(&tile_src_area), lv_area_get_height(&tile_src_area),
508
+ lv_area_get_width(&tile_dest_area), lv_area_get_height(&tile_dest_area),
509
+ (uintptr_t)tile_src_buf, (uintptr_t)tile_dest_buf,
510
+ rv == LV_RES_OK ? "OK!" : "FAILED!");
511
+
512
+ if(rv != LV_RES_OK) {
513
+ return rv;
514
+ }
515
+ }
516
+ }
517
+
518
+ return rv;
519
+ }
520
+ #endif /*VG_LITE_BLIT_SPLIT_ENABLED*/
521
+
522
+ static lv_res_t lv_vglite_blit(const lv_area_t * src_area, lv_opa_t opa)
523
+ {
524
+ vg_lite_error_t err = VG_LITE_SUCCESS;
525
+ vg_lite_buffer_t * dst_vgbuf = lv_vglite_get_dest_buf();
526
+ vg_lite_buffer_t * src_vgbuf = lv_vglite_get_src_buf();
527
+
528
+ uint32_t rect[] = {
529
+ (uint32_t)src_area->x1, /* start x */
530
+ (uint32_t)src_area->y1, /* start y */
531
+ (uint32_t)lv_area_get_width(src_area), /* width */
532
+ (uint32_t)lv_area_get_height(src_area) /* height */
533
+ };
534
+
535
+ uint32_t color;
536
+ vg_lite_blend_t blend;
537
+ if(opa >= (lv_opa_t)LV_OPA_MAX) {
538
+ color = 0xFFFFFFFFU;
539
+ blend = VG_LITE_BLEND_SRC_OVER;
540
+ src_vgbuf->transparency_mode = VG_LITE_IMAGE_TRANSPARENT;
541
+ }
542
+ else {
543
+ if(vg_lite_query_feature(gcFEATURE_BIT_VG_PE_PREMULTIPLY)) {
544
+ color = (opa << 24) | 0x00FFFFFFU;
545
+ }
546
+ else {
547
+ color = (opa << 24) | (opa << 16) | (opa << 8) | opa;
548
+ }
549
+ blend = VG_LITE_BLEND_SRC_OVER;
550
+ src_vgbuf->image_mode = VG_LITE_MULTIPLY_IMAGE_MODE;
551
+ src_vgbuf->transparency_mode = VG_LITE_IMAGE_TRANSPARENT;
552
+ }
553
+
554
+ err = vg_lite_blit_rect(dst_vgbuf, src_vgbuf, rect, &vgmatrix, blend, color, VG_LITE_FILTER_POINT);
555
+ VG_LITE_ERR_RETURN_INV(err, "Blit rectangle failed.");
556
+
557
+ if(lv_vglite_run() != LV_RES_OK)
558
+ VG_LITE_RETURN_INV("Run failed.");
559
+
560
+ return LV_RES_OK;
561
+ }
562
+
563
+ static lv_res_t check_src_alignment(const lv_color_t * src_buf, lv_coord_t src_stride)
564
+ {
565
+ /* No alignment requirement for destination pixel buffer when using mode VG_LITE_LINEAR */
566
+
567
+ /* Test for pointer alignment */
568
+ if((((uintptr_t)src_buf) % (uintptr_t)LV_ATTRIBUTE_MEM_ALIGN_SIZE) != (uintptr_t)0x0U)
569
+ VG_LITE_RETURN_INV("Src buffer ptr (0x%x) not aligned to 0x%x bytes.",
570
+ (size_t)src_buf, LV_ATTRIBUTE_MEM_ALIGN_SIZE);
571
+
572
+ /* Test for stride alignment */
573
+ if((src_stride % (lv_coord_t)LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX) != 0x0U)
574
+ VG_LITE_RETURN_INV("Src buffer stride (%d px) not aligned to %d px.",
575
+ src_stride, LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX);
576
+ return LV_RES_OK;
577
+ }
578
+
579
+ static inline void lv_vglite_set_translation_matrix(const lv_area_t * dest_area)
580
+ {
581
+ vg_lite_identity(&vgmatrix);
582
+ vg_lite_translate((vg_lite_float_t)dest_area->x1, (vg_lite_float_t)dest_area->y1, &vgmatrix);
583
+ }
584
+
585
+ static inline void lv_vglite_set_transformation_matrix(const lv_area_t * dest_area, const lv_draw_img_dsc_t * dsc)
586
+ {
587
+ lv_vglite_set_translation_matrix(dest_area);
588
+
589
+ bool has_scale = (dsc->zoom != LV_IMG_ZOOM_NONE);
590
+ bool has_rotation = (dsc->angle != 0);
591
+
592
+ vg_lite_translate(dsc->pivot.x, dsc->pivot.y, &vgmatrix);
593
+ if(has_rotation)
594
+ vg_lite_rotate(dsc->angle / 10.0f, &vgmatrix); /* angle is 1/10 degree */
595
+ if(has_scale) {
596
+ vg_lite_float_t scale = 1.0f * dsc->zoom / LV_IMG_ZOOM_NONE;
597
+ vg_lite_scale(scale, scale, &vgmatrix);
598
+ }
599
+ vg_lite_translate(0.0f - dsc->pivot.x, 0.0f - dsc->pivot.y, &vgmatrix);
600
+ }
601
+
602
+ #if VG_LITE_BLIT_SPLIT_ENABLED
603
+ static void align_x(lv_area_t * area, lv_color_t ** buf)
604
+ {
605
+ int alignedAreaStartPx = area->x1 - (area->x1 % (LV_ATTRIBUTE_MEM_ALIGN_SIZE / sizeof(lv_color_t)));
606
+ VG_LITE_COND_STOP(alignedAreaStartPx < 0, "Negative X alignment.");
607
+
608
+ area->x1 -= alignedAreaStartPx;
609
+ area->x2 -= alignedAreaStartPx;
610
+ *buf += alignedAreaStartPx;
611
+ }
612
+
613
+ static void align_y(lv_area_t * area, lv_color_t ** buf, lv_coord_t stride)
614
+ {
615
+ int LineToAlignMem;
616
+ int alignedAreaStartPy;
617
+ /* find how many lines of pixels will respect memory alignment requirement */
618
+ if((stride % (lv_coord_t)LV_ATTRIBUTE_MEM_ALIGN_SIZE) == 0x0U) {
619
+ alignedAreaStartPy = area->y1;
620
+ }
621
+ else {
622
+ LineToAlignMem = LV_ATTRIBUTE_MEM_ALIGN_SIZE / (LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX * sizeof(lv_color_t));
623
+ VG_LITE_COND_STOP(LV_ATTRIBUTE_MEM_ALIGN_SIZE % (LV_GPU_NXP_VG_LITE_STRIDE_ALIGN_PX * sizeof(lv_color_t)),
624
+ "Complex case: need gcd function.");
625
+ alignedAreaStartPy = area->y1 - (area->y1 % LineToAlignMem);
626
+ VG_LITE_COND_STOP(alignedAreaStartPy < 0, "Negative Y alignment.");
627
+ }
628
+
629
+ area->y1 -= alignedAreaStartPy;
630
+ area->y2 -= alignedAreaStartPy;
631
+ *buf += (uint32_t)(alignedAreaStartPy * stride);
632
+ }
633
+ #endif /*VG_LITE_BLIT_SPLIT_ENABLED*/
634
+
635
+ #endif /*LV_USE_GPU_NXP_VG_LITE*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite_blend.h ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_vglite_blend.h
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2020-2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ #ifndef LV_DRAW_VGLITE_BLEND_H
31
+ #define LV_DRAW_VGLITE_BLEND_H
32
+
33
+ #ifdef __cplusplus
34
+ extern "C" {
35
+ #endif
36
+
37
+ /*********************
38
+ * INCLUDES
39
+ *********************/
40
+
41
+ #include "../../../lv_conf_internal.h"
42
+
43
+ #if LV_USE_GPU_NXP_VG_LITE
44
+ #include "lv_vglite_utils.h"
45
+
46
+ /*********************
47
+ * DEFINES
48
+ *********************/
49
+
50
+ /**
51
+ * Enable BLIT quality degradation workaround for RT595,
52
+ * recommended for screen's dimension > 352 pixels.
53
+ */
54
+ #define RT595_BLIT_WRKRND_ENABLED 1
55
+
56
+ /* Internal compound symbol */
57
+ #if (defined(CPU_MIMXRT595SFFOB) || defined(CPU_MIMXRT595SFFOB_cm33) || \
58
+ defined(CPU_MIMXRT595SFFOC) || defined(CPU_MIMXRT595SFFOC_cm33)) && \
59
+ RT595_BLIT_WRKRND_ENABLED
60
+ #define VG_LITE_BLIT_SPLIT_ENABLED 1
61
+ #else
62
+ #define VG_LITE_BLIT_SPLIT_ENABLED 0
63
+ #endif
64
+
65
+ /**********************
66
+ * TYPEDEFS
67
+ **********************/
68
+
69
+ /**********************
70
+ * GLOBAL PROTOTYPES
71
+ **********************/
72
+
73
+ /**
74
+ * Fill area, with optional opacity.
75
+ *
76
+ * @param[in] dest_area Area with relative coordinates of destination buffer
77
+ * @param[in] color Color
78
+ * @param[in] opa Opacity (255 = full, 128 = 50% background/50% color, 0 = no fill)
79
+ *
80
+ * @retval LV_RES_OK Fill completed
81
+ * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
82
+ */
83
+ lv_res_t lv_gpu_nxp_vglite_fill(const lv_area_t * dest_area, lv_color_t color, lv_opa_t opa);
84
+
85
+ #if VG_LITE_BLIT_SPLIT_ENABLED
86
+ /**
87
+ * BLock Image Transfer - copy rectangular image from src_buf to dst_buf with effects.
88
+ * By default, image is copied directly, with optional opacity.
89
+ *
90
+ * @param[in/out] dest_buf Destination buffer
91
+ * @param[in] dest_area Area with relative coordinates of destination buffer
92
+ * @param[in] dest_stride Stride of destination buffer in pixels
93
+ * @param[in] src_buf Source buffer
94
+ * @param[in] src_area Source area with relative coordinates of source buffer
95
+ * @param[in] src_stride Stride of source buffer in pixels
96
+ * @param[in] opa Opacity
97
+ *
98
+ * @retval LV_RES_OK Transfer complete
99
+ * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
100
+ */
101
+ lv_res_t lv_gpu_nxp_vglite_blit_split(lv_color_t * dest_buf, lv_area_t * dest_area, lv_coord_t dest_stride,
102
+ const lv_color_t * src_buf, lv_area_t * src_area, lv_coord_t src_stride,
103
+ lv_opa_t opa);
104
+ #else
105
+ /**
106
+ * BLock Image Transfer - copy rectangular image from src_buf to dst_buf with effects.
107
+ * By default, image is copied directly, with optional opacity.
108
+ *
109
+ * @param[in] dest_stride Stride of destination buffer in pixels
110
+ * @param[in] src_buf Source buffer
111
+ * @param[in] src_area Source area with relative coordinates of source buffer
112
+ * @param[in] src_stride Stride of source buffer in pixels
113
+ * @param[in] opa Opacity
114
+ *
115
+ * @retval LV_RES_OK Transfer complete
116
+ * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
117
+ */
118
+ lv_res_t lv_gpu_nxp_vglite_blit(const lv_area_t * dest_area,
119
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride,
120
+ lv_opa_t opa);
121
+
122
+ /**
123
+ * BLock Image Transfer - copy rectangular image from src_buf to dst_buf with transformation.
124
+ * By default, image is copied directly, with optional opacity.
125
+ *
126
+ * @param[in] dest_area Area with relative coordinates of destination buffer
127
+ * @param[in] clip_area Clip area with relative coordinates of destination buffer
128
+ * @param[in] src_buf Source buffer
129
+ * @param[in] src_area Source area with relative coordinates of source buffer
130
+ * @param[in] src_stride Stride of source buffer in pixels
131
+ * @param[in] dsc Image descriptor
132
+ *
133
+ * @retval LV_RES_OK Transfer complete
134
+ * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
135
+ */
136
+ lv_res_t lv_gpu_nxp_vglite_blit_transform(const lv_area_t * dest_area, const lv_area_t * clip_area,
137
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride,
138
+ const lv_draw_img_dsc_t * dsc);
139
+
140
+ #endif /*VG_LITE_BLIT_SPLIT_ENABLED*/
141
+
142
+ /**
143
+ * BLock Image Transfer - simple copy of rectangular image from source to destination.
144
+ *
145
+ * @param[in] dest_buf Destination buffer
146
+ * @param[in] dest_area Area with relative coordinates of destination buffer
147
+ * @param[in] dest_stride Stride of destination buffer in pixels
148
+ * @param[in] src_buf Source buffer
149
+ * @param[in] src_area Source area with relative coordinates of source buffer
150
+ * @param[in] src_stride Stride of source buffer in pixels
151
+ *
152
+ * @retval LV_RES_OK Transfer complete
153
+ * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
154
+ */
155
+ lv_res_t lv_gpu_nxp_vglite_buffer_copy(lv_color_t * dest_buf, const lv_area_t * dest_area, lv_coord_t dest_stride,
156
+ const lv_color_t * src_buf, const lv_area_t * src_area, lv_coord_t src_stride);
157
+
158
+ /**********************
159
+ * MACROS
160
+ **********************/
161
+
162
+ #endif /*LV_USE_GPU_NXP_VG_LITE*/
163
+
164
+ #ifdef __cplusplus
165
+ } /*extern "C"*/
166
+ #endif
167
+
168
+ #endif /*LV_DRAW_VGLITE_BLEND_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite_line.c ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_vglite_line.c
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2022, 2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ /*********************
31
+ * INCLUDES
32
+ *********************/
33
+
34
+ #include "lv_draw_vglite_line.h"
35
+
36
+ #if LV_USE_GPU_NXP_VG_LITE
37
+ #include "lv_vglite_buf.h"
38
+ #include <math.h>
39
+
40
+ /*********************
41
+ * DEFINES
42
+ *********************/
43
+
44
+ /**********************
45
+ * TYPEDEFS
46
+ **********************/
47
+
48
+ /**********************
49
+ * STATIC PROTOTYPES
50
+ **********************/
51
+
52
+ /**********************
53
+ * STATIC VARIABLES
54
+ **********************/
55
+
56
+ /**********************
57
+ * MACROS
58
+ **********************/
59
+
60
+ /**********************
61
+ * GLOBAL FUNCTIONS
62
+ **********************/
63
+
64
+ lv_res_t lv_gpu_nxp_vglite_draw_line(const lv_point_t * point1, const lv_point_t * point2,
65
+ const lv_area_t * clip_area, const lv_draw_line_dsc_t * dsc)
66
+ {
67
+ vg_lite_error_t err = VG_LITE_SUCCESS;
68
+ vg_lite_path_t path;
69
+ vg_lite_color_t vgcol; /* vglite takes ABGR */
70
+ vg_lite_buffer_t * vgbuf = lv_vglite_get_dest_buf();
71
+ vg_lite_cap_style_t cap_style = (dsc->round_start || dsc->round_end) ? VG_LITE_CAP_ROUND : VG_LITE_CAP_BUTT;
72
+ vg_lite_join_style_t join_style = (dsc->round_start || dsc->round_end) ? VG_LITE_JOIN_ROUND : VG_LITE_JOIN_MITER;
73
+
74
+ bool is_dashed = (dsc->dash_width && dsc->dash_gap);
75
+
76
+ vg_lite_float_t stroke_dash_pattern[2] = {0, 0};
77
+ uint32_t stroke_dash_count = 0;
78
+ vg_lite_float_t stroke_dash_phase = 0;
79
+ if(is_dashed) {
80
+ stroke_dash_pattern[0] = (vg_lite_float_t)dsc->dash_width;
81
+ stroke_dash_pattern[1] = (vg_lite_float_t)dsc->dash_gap;
82
+ stroke_dash_count = sizeof(stroke_dash_pattern) / sizeof(vg_lite_float_t);
83
+ stroke_dash_phase = (vg_lite_float_t)dsc->dash_width / 2;
84
+ }
85
+
86
+ /* Choose vglite blend mode based on given lvgl blend mode */
87
+ vg_lite_blend_t vglite_blend_mode = lv_vglite_get_blend_mode(dsc->blend_mode);
88
+
89
+ /*** Init path ***/
90
+ lv_coord_t width = dsc->width;
91
+
92
+ int32_t line_path[] = { /*VG line path*/
93
+ VLC_OP_MOVE, point1->x, point1->y,
94
+ VLC_OP_LINE, point2->x, point2->y,
95
+ VLC_OP_END
96
+ };
97
+
98
+ err = vg_lite_init_path(&path, VG_LITE_S32, VG_LITE_HIGH, sizeof(line_path), line_path,
99
+ (vg_lite_float_t)clip_area->x1, (vg_lite_float_t)clip_area->y1,
100
+ ((vg_lite_float_t)clip_area->x2) + 1.0f, ((vg_lite_float_t)clip_area->y2) + 1.0f);
101
+ VG_LITE_ERR_RETURN_INV(err, "Init path failed.");
102
+
103
+ vg_lite_matrix_t matrix;
104
+ vg_lite_identity(&matrix);
105
+
106
+ lv_color32_t col32 = { .full = lv_color_to32(dsc->color) }; /*Convert color to RGBA8888*/
107
+ vg_lite_buffer_format_t color_format = LV_COLOR_DEPTH == 16 ? VG_LITE_BGRA8888 : VG_LITE_ABGR8888;
108
+ if(lv_vglite_premult_and_swizzle(&vgcol, col32, dsc->opa, color_format) != LV_RES_OK)
109
+ VG_LITE_RETURN_INV("Premultiplication and swizzle failed.");
110
+
111
+ /*** Draw line ***/
112
+ err = vg_lite_set_draw_path_type(&path, VG_LITE_DRAW_STROKE_PATH);
113
+ VG_LITE_ERR_RETURN_INV(err, "Set draw path type failed.");
114
+
115
+ err = vg_lite_set_stroke(&path, cap_style, join_style, width, 8, stroke_dash_pattern, stroke_dash_count,
116
+ stroke_dash_phase, vgcol);
117
+ VG_LITE_ERR_RETURN_INV(err, "Set stroke failed.");
118
+
119
+ err = vg_lite_update_stroke(&path);
120
+ VG_LITE_ERR_RETURN_INV(err, "Update stroke failed.");
121
+
122
+ lv_vglite_set_scissor(clip_area);
123
+
124
+ err = vg_lite_draw(vgbuf, &path, VG_LITE_FILL_NON_ZERO, &matrix, vglite_blend_mode, vgcol);
125
+ VG_LITE_ERR_RETURN_INV(err, "Draw line failed.");
126
+
127
+ if(lv_vglite_run() != LV_RES_OK)
128
+ VG_LITE_RETURN_INV("Run failed.");
129
+
130
+ lv_vglite_disable_scissor();
131
+
132
+ err = vg_lite_clear_path(&path);
133
+ VG_LITE_ERR_RETURN_INV(err, "Clear path failed.");
134
+
135
+ return LV_RES_OK;
136
+ }
137
+
138
+ /**********************
139
+ * STATIC FUNCTIONS
140
+ **********************/
141
+
142
+ #endif /*LV_USE_GPU_NXP_VG_LITE*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite_line.h ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_vglite_line.h
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2022, 2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ #ifndef LV_DRAW_VGLITE_LINE_H
31
+ #define LV_DRAW_VGLITE_LINE_H
32
+
33
+ #ifdef __cplusplus
34
+ extern "C"
35
+ {
36
+ #endif
37
+
38
+ /*********************
39
+ * INCLUDES
40
+ *********************/
41
+ #include "../../../lv_conf_internal.h"
42
+
43
+ #if LV_USE_GPU_NXP_VG_LITE
44
+ #include "lv_vglite_utils.h"
45
+ #include "../../lv_draw_line.h"
46
+
47
+ /*********************
48
+ * DEFINES
49
+ *********************/
50
+
51
+ /**********************
52
+ * TYPEDEFS
53
+ **********************/
54
+
55
+ /**********************
56
+ * GLOBAL PROTOTYPES
57
+ **********************/
58
+
59
+ /**
60
+ * Draw line shape with effects
61
+ *
62
+ * @param[in] point1 Starting point with relative coordinates
63
+ * @param[in] point2 Ending point with relative coordinates
64
+ * @param[in] clip_area Clipping area with relative coordinates to dest buff
65
+ * @param[in] dsc Line description structure (width, rounded ending, opacity, ...)
66
+ *
67
+ * @retval LV_RES_OK Draw completed
68
+ * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
69
+ */
70
+ lv_res_t lv_gpu_nxp_vglite_draw_line(const lv_point_t * point1, const lv_point_t * point2,
71
+ const lv_area_t * clip_area, const lv_draw_line_dsc_t * dsc);
72
+
73
+ /**********************
74
+ * MACROS
75
+ **********************/
76
+
77
+ #endif /*LV_USE_GPU_NXP_VG_LITE*/
78
+
79
+ #ifdef __cplusplus
80
+ } /*extern "C"*/
81
+ #endif
82
+
83
+ #endif /*LV_DRAW_VGLITE_RECT_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite_rect.c ADDED
@@ -0,0 +1,459 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_vglite_rect.c
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2021-2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ /*********************
31
+ * INCLUDES
32
+ *********************/
33
+
34
+ #include "lv_draw_vglite_rect.h"
35
+
36
+ #if LV_USE_GPU_NXP_VG_LITE
37
+ #include "lv_vglite_buf.h"
38
+ #include <math.h>
39
+
40
+ /*********************
41
+ * DEFINES
42
+ *********************/
43
+ /*********************
44
+ * DEFINES
45
+ *********************/
46
+
47
+ /* Path data sizes for different elements */
48
+ #define CUBIC_PATH_DATA_SIZE 7 /* 1 opcode, 6 arguments */
49
+ #define LINE_PATH_DATA_SIZE 3 /* 1 opcode, 2 arguments */
50
+ #define MOVE_PATH_DATA_SIZE 3 /* 1 opcode, 2 arguments */
51
+ #define END_PATH_DATA_SIZE 1 /* 1 opcode, 0 arguments */
52
+ /* Maximum possible rectangle path size
53
+ * is in the rounded rectangle case:
54
+ * - 1 move for the path start
55
+ * - 4 cubics for the corners
56
+ * - 4 lines for the sides
57
+ * - 1 end for the path end */
58
+ #define RECT_PATH_DATA_MAX_SIZE 1 * MOVE_PATH_DATA_SIZE + 4 * CUBIC_PATH_DATA_SIZE + 4 * LINE_PATH_DATA_SIZE + 1 * END_PATH_DATA_SIZE
59
+
60
+ /**********************
61
+ * TYPEDEFS
62
+ **********************/
63
+
64
+ /**********************
65
+ * STATIC PROTOTYPES
66
+ **********************/
67
+
68
+ /**
69
+ * Generates path data for rectangle drawing.
70
+ *
71
+ * @param[in/out] path The path data to initialize
72
+ * @param[in/out] path_size The resulting size of the created path data
73
+ * @param[in] dsc The style descriptor for the rectangle to be drawn
74
+ * @param[in] coords The coordinates of the rectangle to be drawn
75
+ */
76
+ static void lv_vglite_create_rect_path_data(int32_t * path_data, uint32_t * path_data_size,
77
+ lv_coord_t radius,
78
+ const lv_area_t * coords);
79
+
80
+ /**********************
81
+ * STATIC VARIABLES
82
+ **********************/
83
+
84
+ /**********************
85
+ * MACROS
86
+ **********************/
87
+
88
+ /**********************
89
+ * GLOBAL FUNCTIONS
90
+ **********************/
91
+
92
+ lv_res_t lv_gpu_nxp_vglite_draw_bg(const lv_area_t * coords, const lv_area_t * clip_area,
93
+ const lv_draw_rect_dsc_t * dsc)
94
+ {
95
+ vg_lite_error_t err = VG_LITE_SUCCESS;
96
+ lv_coord_t width = lv_area_get_width(coords);
97
+ lv_coord_t height = lv_area_get_height(coords);
98
+ vg_lite_color_t vgcol;
99
+ lv_coord_t radius = dsc->radius;
100
+ vg_lite_buffer_t * vgbuf = lv_vglite_get_dest_buf();
101
+
102
+ if(dsc->radius < 0)
103
+ return LV_RES_INV;
104
+
105
+ /*** Init path ***/
106
+ int32_t path_data[RECT_PATH_DATA_MAX_SIZE];
107
+ uint32_t path_data_size;
108
+ lv_vglite_create_rect_path_data(path_data, &path_data_size, radius, coords);
109
+ vg_lite_quality_t path_quality = dsc->radius > 0 ? VG_LITE_HIGH : VG_LITE_LOW;
110
+
111
+ vg_lite_path_t path;
112
+ err = vg_lite_init_path(&path, VG_LITE_S32, path_quality, path_data_size, path_data,
113
+ (vg_lite_float_t)clip_area->x1, (vg_lite_float_t)clip_area->y1,
114
+ ((vg_lite_float_t)clip_area->x2) + 1.0f, ((vg_lite_float_t)clip_area->y2) + 1.0f);
115
+ VG_LITE_ERR_RETURN_INV(err, "Init path failed.");
116
+
117
+ vg_lite_matrix_t matrix;
118
+ vg_lite_identity(&matrix);
119
+
120
+ vg_lite_matrix_t * grad_matrix;
121
+ vg_lite_linear_gradient_t gradient;
122
+
123
+ /*** Init Color/Gradient ***/
124
+ if(dsc->bg_grad.dir != (lv_grad_dir_t)LV_GRAD_DIR_NONE) {
125
+ uint32_t colors[2];
126
+ uint32_t stops[2];
127
+ lv_color32_t col32[2];
128
+
129
+ /* Gradient setup */
130
+ uint8_t cnt = LV_MAX(dsc->bg_grad.stops_count, 2);
131
+ for(uint8_t i = 0; i < cnt; i++) {
132
+ col32[i].full = lv_color_to32(dsc->bg_grad.stops[i].color); /*Convert color to RGBA8888*/
133
+ stops[i] = dsc->bg_grad.stops[i].frac;
134
+
135
+ vg_lite_buffer_format_t color_format = LV_COLOR_DEPTH == 16 ? VG_LITE_ABGR8888 : VG_LITE_ARGB8888;
136
+ if(lv_vglite_premult_and_swizzle(&colors[i], col32[i], dsc->bg_opa, color_format) != LV_RES_OK)
137
+ VG_LITE_RETURN_INV("Premultiplication and swizzle failed.");
138
+ }
139
+
140
+ lv_memset_00(&gradient, sizeof(vg_lite_linear_gradient_t));
141
+
142
+ err = vg_lite_init_grad(&gradient);
143
+ VG_LITE_ERR_RETURN_INV(err, "Init gradient failed");
144
+
145
+ err = vg_lite_set_grad(&gradient, cnt, colors, stops);
146
+ VG_LITE_ERR_RETURN_INV(err, "Set gradient failed.");
147
+
148
+ err = vg_lite_update_grad(&gradient);
149
+ VG_LITE_ERR_RETURN_INV(err, "Update gradient failed.");
150
+
151
+ grad_matrix = vg_lite_get_grad_matrix(&gradient);
152
+ vg_lite_identity(grad_matrix);
153
+ vg_lite_translate((float)coords->x1, (float)coords->y1, grad_matrix);
154
+
155
+ if(dsc->bg_grad.dir == (lv_grad_dir_t)LV_GRAD_DIR_VER) {
156
+ vg_lite_scale(1.0f, (float)height / 256.0f, grad_matrix);
157
+ vg_lite_rotate(90.0f, grad_matrix);
158
+ }
159
+ else { /*LV_GRAD_DIR_HOR*/
160
+ vg_lite_scale((float)width / 256.0f, 1.0f, grad_matrix);
161
+ }
162
+ }
163
+
164
+ lv_color32_t bg_col32 = {.full = lv_color_to32(dsc->bg_color)}; /*Convert color to RGBA8888*/
165
+ vg_lite_buffer_format_t color_format = LV_COLOR_DEPTH == 16 ? VG_LITE_BGRA8888 : VG_LITE_ABGR8888;
166
+ if(lv_vglite_premult_and_swizzle(&vgcol, bg_col32, dsc->bg_opa, color_format) != LV_RES_OK)
167
+ VG_LITE_RETURN_INV("Premultiplication and swizzle failed.");
168
+
169
+ lv_vglite_set_scissor(clip_area);
170
+
171
+ /*** Draw rectangle ***/
172
+ if(dsc->bg_grad.dir == (lv_grad_dir_t)LV_GRAD_DIR_NONE) {
173
+ err = vg_lite_draw(vgbuf, &path, VG_LITE_FILL_EVEN_ODD, &matrix, VG_LITE_BLEND_SRC_OVER, vgcol);
174
+ }
175
+ else {
176
+ err = vg_lite_draw_gradient(vgbuf, &path, VG_LITE_FILL_EVEN_ODD, &matrix, &gradient, VG_LITE_BLEND_SRC_OVER);
177
+ }
178
+ VG_LITE_ERR_RETURN_INV(err, "Draw gradient failed.");
179
+
180
+ if(lv_vglite_run() != LV_RES_OK)
181
+ VG_LITE_RETURN_INV("Run failed.");
182
+
183
+ lv_vglite_disable_scissor();
184
+
185
+ err = vg_lite_clear_path(&path);
186
+ VG_LITE_ERR_RETURN_INV(err, "Clear path failed.");
187
+
188
+ if(dsc->bg_grad.dir != (lv_grad_dir_t)LV_GRAD_DIR_NONE) {
189
+ err = vg_lite_clear_grad(&gradient);
190
+ VG_LITE_ERR_RETURN_INV(err, "Clear gradient failed.");
191
+ }
192
+
193
+ return LV_RES_OK;
194
+ }
195
+
196
+ lv_res_t lv_gpu_nxp_vglite_draw_border_generic(const lv_area_t * coords, const lv_area_t * clip_area,
197
+ const lv_draw_rect_dsc_t * dsc, bool border)
198
+ {
199
+ vg_lite_error_t err = VG_LITE_SUCCESS;
200
+ vg_lite_color_t vgcol; /* vglite takes ABGR */
201
+ lv_coord_t radius = dsc->radius;
202
+ vg_lite_buffer_t * vgbuf = lv_vglite_get_dest_buf();
203
+
204
+ if(radius < 0)
205
+ return LV_RES_INV;
206
+
207
+ if(border) {
208
+ /* Draw border - only has radius if object has radius*/
209
+ lv_coord_t border_half = (lv_coord_t)floor(dsc->border_width / 2.0f);
210
+ if(radius > border_half)
211
+ radius = radius - border_half;
212
+ }
213
+ else {
214
+ /* Draw outline - always has radius, leave the same radius in the circle case */
215
+ lv_coord_t outline_half = (lv_coord_t)ceil(dsc->outline_width / 2.0f);
216
+ if(radius < (lv_coord_t)LV_RADIUS_CIRCLE - outline_half)
217
+ radius = radius + outline_half;
218
+ }
219
+
220
+ vg_lite_cap_style_t cap_style = (radius) ? VG_LITE_CAP_ROUND : VG_LITE_CAP_BUTT;
221
+ vg_lite_join_style_t join_style = (radius) ? VG_LITE_JOIN_ROUND : VG_LITE_JOIN_MITER;
222
+
223
+ /* Choose vglite blend mode based on given lvgl blend mode */
224
+ vg_lite_blend_t vglite_blend_mode = lv_vglite_get_blend_mode(dsc->blend_mode);
225
+
226
+ /*** Init path ***/
227
+ int32_t path_data[RECT_PATH_DATA_MAX_SIZE];
228
+ uint32_t path_data_size;
229
+ lv_vglite_create_rect_path_data(path_data, &path_data_size, radius, coords);
230
+ vg_lite_quality_t path_quality = dsc->radius > 0 ? VG_LITE_HIGH : VG_LITE_LOW;
231
+
232
+ vg_lite_path_t path;
233
+ err = vg_lite_init_path(&path, VG_LITE_S32, path_quality, path_data_size, path_data,
234
+ (vg_lite_float_t)clip_area->x1, (vg_lite_float_t)clip_area->y1,
235
+ ((vg_lite_float_t)clip_area->x2) + 1.0f, ((vg_lite_float_t)clip_area->y2) + 1.0f);
236
+ VG_LITE_ERR_RETURN_INV(err, "Init path failed.");
237
+
238
+ vg_lite_matrix_t matrix;
239
+ vg_lite_identity(&matrix);
240
+
241
+ lv_opa_t opa;
242
+ lv_color32_t col32;
243
+ lv_coord_t line_width;
244
+
245
+ if(border) {
246
+ opa = dsc->border_opa;
247
+ col32.full = lv_color_to32(dsc->border_color); /*Convert color to RGBA8888*/
248
+ line_width = dsc->border_width;
249
+ }
250
+ else {
251
+ opa = dsc->outline_opa;
252
+ col32.full = lv_color_to32(dsc->outline_color); /*Convert color to RGBA8888*/
253
+ line_width = dsc->outline_width;
254
+ }
255
+
256
+ vg_lite_buffer_format_t color_format = LV_COLOR_DEPTH == 16 ? VG_LITE_BGRA8888 : VG_LITE_ABGR8888;
257
+ if(lv_vglite_premult_and_swizzle(&vgcol, col32, opa, color_format) != LV_RES_OK)
258
+ VG_LITE_RETURN_INV("Premultiplication and swizzle failed.");
259
+
260
+ /*** Draw border ***/
261
+ err = vg_lite_set_draw_path_type(&path, VG_LITE_DRAW_STROKE_PATH);
262
+ VG_LITE_ERR_RETURN_INV(err, "Set draw path type failed.");
263
+
264
+ err = vg_lite_set_stroke(&path, cap_style, join_style, line_width, 8, NULL, 0, 0, vgcol);
265
+ VG_LITE_ERR_RETURN_INV(err, "Set stroke failed.");
266
+
267
+ err = vg_lite_update_stroke(&path);
268
+ VG_LITE_ERR_RETURN_INV(err, "Update stroke failed.");
269
+
270
+ lv_vglite_set_scissor(clip_area);
271
+
272
+ err = vg_lite_draw(vgbuf, &path, VG_LITE_FILL_NON_ZERO, &matrix, vglite_blend_mode, vgcol);
273
+ VG_LITE_ERR_RETURN_INV(err, "Draw border failed.");
274
+
275
+ if(lv_vglite_run() != LV_RES_OK)
276
+ VG_LITE_RETURN_INV("Run failed.");
277
+
278
+ lv_vglite_disable_scissor();
279
+
280
+ err = vg_lite_clear_path(&path);
281
+ VG_LITE_ERR_RETURN_INV(err, "Clear path failed.");
282
+
283
+ return LV_RES_OK;
284
+
285
+ }
286
+
287
+ /**********************
288
+ * STATIC FUNCTIONS
289
+ **********************/
290
+
291
+ static void lv_vglite_create_rect_path_data(int32_t * path_data, uint32_t * path_data_size,
292
+ lv_coord_t radius,
293
+ const lv_area_t * coords)
294
+ {
295
+ lv_coord_t rect_width = lv_area_get_width(coords);
296
+ lv_coord_t rect_height = lv_area_get_height(coords);
297
+
298
+ /* Get the final radius. Can't be larger than the half of the shortest side */
299
+ int32_t shortest_side = LV_MIN(rect_width, rect_height);
300
+ int32_t final_radius = LV_MIN(radius, shortest_side / 2);
301
+
302
+ /* Path data element index */
303
+ uint8_t pidx = 0;
304
+
305
+ if((radius == (lv_coord_t)LV_RADIUS_CIRCLE) && (rect_width == rect_height)) {
306
+
307
+ /* Get the control point offset for rounded cases */
308
+ int32_t cpoff = (int32_t)((float)final_radius * BEZIER_OPTIM_CIRCLE);
309
+
310
+ /* Circle case */
311
+ /* Starting point */
312
+ path_data[pidx++] = VLC_OP_MOVE;
313
+ path_data[pidx++] = coords->x1 + final_radius;
314
+ path_data[pidx++] = coords->y1;
315
+
316
+ /* Top-right arc */
317
+ path_data[pidx++] = VLC_OP_CUBIC_REL;
318
+ path_data[pidx++] = cpoff;
319
+ path_data[pidx++] = 0;
320
+ path_data[pidx++] = final_radius;
321
+ path_data[pidx++] = final_radius - cpoff;
322
+ path_data[pidx++] = final_radius;
323
+ path_data[pidx++] = final_radius;
324
+
325
+ /* Bottom-right arc*/
326
+ path_data[pidx++] = VLC_OP_CUBIC_REL;
327
+ path_data[pidx++] = 0;
328
+ path_data[pidx++] = cpoff;
329
+ path_data[pidx++] = cpoff - final_radius;
330
+ path_data[pidx++] = final_radius;
331
+ path_data[pidx++] = 0 - final_radius;
332
+ path_data[pidx++] = final_radius;
333
+
334
+ /* Bottom-left arc */
335
+ path_data[pidx++] = VLC_OP_CUBIC_REL;
336
+ path_data[pidx++] = 0 - cpoff;
337
+ path_data[pidx++] = 0;
338
+ path_data[pidx++] = 0 - final_radius;
339
+ path_data[pidx++] = cpoff - final_radius;
340
+ path_data[pidx++] = 0 - final_radius;
341
+ path_data[pidx++] = 0 - final_radius;
342
+
343
+ /* Top-left arc*/
344
+ path_data[pidx++] = VLC_OP_CUBIC_REL;
345
+ path_data[pidx++] = 0;
346
+ path_data[pidx++] = 0 - cpoff;
347
+ path_data[pidx++] = final_radius - cpoff;
348
+ path_data[pidx++] = 0 - final_radius;
349
+ path_data[pidx++] = final_radius;
350
+ path_data[pidx++] = 0 - final_radius;
351
+
352
+ /* Ending point */
353
+ path_data[pidx++] = VLC_OP_END;
354
+ }
355
+ else if(radius > 0) {
356
+ /* Get the control point offset for rounded cases */
357
+ int32_t cpoff = (int32_t)((float)final_radius * BEZIER_OPTIM_CIRCLE);
358
+
359
+ /* Rounded rectangle case */
360
+ /* Starting point */
361
+ path_data[pidx++] = VLC_OP_MOVE;
362
+ path_data[pidx++] = coords->x1 + final_radius;
363
+ path_data[pidx++] = coords->y1;
364
+
365
+ /* Top side */
366
+ path_data[pidx++] = VLC_OP_LINE;
367
+ path_data[pidx++] = coords->x2 - final_radius + 1; // Extended for VGLite
368
+ path_data[pidx++] = coords->y1;
369
+
370
+ /* Top-right corner */
371
+ path_data[pidx++] = VLC_OP_CUBIC_REL;
372
+ path_data[pidx++] = cpoff;
373
+ path_data[pidx++] = 0;
374
+ path_data[pidx++] = final_radius;
375
+ path_data[pidx++] = final_radius - cpoff;
376
+ path_data[pidx++] = final_radius;
377
+ path_data[pidx++] = final_radius;
378
+
379
+ /* Right side */
380
+ path_data[pidx++] = VLC_OP_LINE;
381
+ path_data[pidx++] = coords->x2 + 1; // Extended for VGLite
382
+ path_data[pidx++] = coords->y2 - final_radius + 1; // Extended for VGLite
383
+
384
+ /* Bottom-right corner*/
385
+ path_data[pidx++] = VLC_OP_CUBIC_REL;
386
+ path_data[pidx++] = 0;
387
+ path_data[pidx++] = cpoff;
388
+ path_data[pidx++] = cpoff - final_radius;
389
+ path_data[pidx++] = final_radius;
390
+ path_data[pidx++] = 0 - final_radius;
391
+ path_data[pidx++] = final_radius;
392
+
393
+ /* Bottom side */
394
+ path_data[pidx++] = VLC_OP_LINE;
395
+ path_data[pidx++] = coords->x1 + final_radius;
396
+ path_data[pidx++] = coords->y2 + 1; // Extended for VGLite
397
+
398
+ /* Bottom-left corner */
399
+ path_data[pidx++] = VLC_OP_CUBIC_REL;
400
+ path_data[pidx++] = 0 - cpoff;
401
+ path_data[pidx++] = 0;
402
+ path_data[pidx++] = 0 - final_radius;
403
+ path_data[pidx++] = cpoff - final_radius;
404
+ path_data[pidx++] = 0 - final_radius;
405
+ path_data[pidx++] = 0 - final_radius;
406
+
407
+ /* Left side*/
408
+ path_data[pidx++] = VLC_OP_LINE;
409
+ path_data[pidx++] = coords->x1;
410
+ path_data[pidx++] = coords->y1 + final_radius;
411
+
412
+ /* Top-left corner */
413
+ path_data[pidx++] = VLC_OP_CUBIC_REL;
414
+ path_data[pidx++] = 0;
415
+ path_data[pidx++] = 0 - cpoff;
416
+ path_data[pidx++] = final_radius - cpoff;
417
+ path_data[pidx++] = 0 - final_radius;
418
+ path_data[pidx++] = final_radius;
419
+ path_data[pidx++] = 0 - final_radius;
420
+
421
+ /* Ending point */
422
+ path_data[pidx++] = VLC_OP_END;
423
+ }
424
+ else {
425
+ /* Non-rounded rectangle case */
426
+ /* Starting point */
427
+ path_data[pidx++] = VLC_OP_MOVE;
428
+ path_data[pidx++] = coords->x1;
429
+ path_data[pidx++] = coords->y1;
430
+
431
+ /* Top side */
432
+ path_data[pidx++] = VLC_OP_LINE;
433
+ path_data[pidx++] = coords->x2 + 1; // Extended for VGLite
434
+ path_data[pidx++] = coords->y1;
435
+
436
+ /* Right side */
437
+ path_data[pidx++] = VLC_OP_LINE;
438
+ path_data[pidx++] = coords->x2 + 1; // Extended for VGLite
439
+ path_data[pidx++] = coords->y2 + 1; // Extended for VGLite
440
+
441
+ /* Bottom side */
442
+ path_data[pidx++] = VLC_OP_LINE;
443
+ path_data[pidx++] = coords->x1;
444
+ path_data[pidx++] = coords->y2 + 1; // Extended for VGLite
445
+
446
+ /* Left side*/
447
+ path_data[pidx++] = VLC_OP_LINE;
448
+ path_data[pidx++] = coords->x1;
449
+ path_data[pidx++] = coords->y1;
450
+
451
+ /* Ending point */
452
+ path_data[pidx++] = VLC_OP_END;
453
+ }
454
+
455
+ /* Resulting path size */
456
+ *path_data_size = pidx * sizeof(int32_t);
457
+ }
458
+
459
+ #endif /*LV_USE_GPU_NXP_VG_LITE*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_draw_vglite_rect.h ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_vglite_rect.h
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2021-2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ #ifndef LV_DRAW_VGLITE_RECT_H
31
+ #define LV_DRAW_VGLITE_RECT_H
32
+
33
+ #ifdef __cplusplus
34
+ extern "C" {
35
+ #endif
36
+
37
+ /*********************
38
+ * INCLUDES
39
+ *********************/
40
+ #include "../../../lv_conf_internal.h"
41
+
42
+ #if LV_USE_GPU_NXP_VG_LITE
43
+ #include "lv_vglite_utils.h"
44
+ #include "../../lv_draw_rect.h"
45
+
46
+ /*********************
47
+ * DEFINES
48
+ *********************/
49
+
50
+ /**********************
51
+ * TYPEDEFS
52
+ **********************/
53
+
54
+ /**********************
55
+ * GLOBAL PROTOTYPES
56
+ **********************/
57
+
58
+ /**
59
+ * Draw rectangle background with effects (rounded corners, gradient)
60
+ *
61
+ * @param[in] coords Coordinates of the rectangle background (relative to dest buff)
62
+ * @param[in] clip_area Clipping area with relative coordinates to dest buff
63
+ * @param[in] dsc Description of the rectangle background
64
+ *
65
+ * @retval LV_RES_OK Draw completed
66
+ * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
67
+ *
68
+ */
69
+ lv_res_t lv_gpu_nxp_vglite_draw_bg(const lv_area_t * coords, const lv_area_t * clip_area,
70
+ const lv_draw_rect_dsc_t * dsc);
71
+
72
+ /**
73
+ * Draw rectangle border/outline shape with effects (rounded corners, opacity)
74
+ *
75
+ * @param[in] coords Coordinates of the rectangle border/outline (relative to dest buff)
76
+ * @param[in] clip_area Clipping area with relative coordinates to dest buff
77
+ * @param[in] dsc Description of the rectangle border/outline
78
+ * @param[in] border True for border, False for outline
79
+ *
80
+ * @retval LV_RES_OK Draw completed
81
+ * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
82
+ *
83
+ */
84
+ lv_res_t lv_gpu_nxp_vglite_draw_border_generic(const lv_area_t * coords, const lv_area_t * clip_area,
85
+ const lv_draw_rect_dsc_t * dsc, bool border);
86
+
87
+ /**********************
88
+ * MACROS
89
+ **********************/
90
+
91
+ #endif /*LV_USE_GPU_NXP_VG_LITE*/
92
+
93
+ #ifdef __cplusplus
94
+ } /*extern "C"*/
95
+ #endif
96
+
97
+ #endif /*LV_DRAW_VGLITE_RECT_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_vglite_buf.c ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_vglite_buf.c
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ /*********************
31
+ * INCLUDES
32
+ *********************/
33
+
34
+ #include "lv_vglite_buf.h"
35
+
36
+ #if LV_USE_GPU_NXP_VG_LITE
37
+
38
+ /*********************
39
+ * DEFINES
40
+ *********************/
41
+
42
+ #if LV_COLOR_DEPTH == 16
43
+ #define VG_LITE_PX_FMT VG_LITE_RGB565
44
+ #elif LV_COLOR_DEPTH == 32
45
+ #define VG_LITE_PX_FMT VG_LITE_BGRA8888
46
+ #else
47
+ #error Only 16bit and 32bit color depth are supported. Set LV_COLOR_DEPTH to 16 or 32.
48
+ #endif
49
+
50
+ /**********************
51
+ * TYPEDEFS
52
+ **********************/
53
+
54
+ /**********************
55
+ * STATIC PROTOTYPES
56
+ **********************/
57
+
58
+ static inline void lv_vglite_set_dest_buf(const lv_color_t * buf, const lv_area_t * area, lv_coord_t stride);
59
+ static inline void lv_vglite_set_buf_ptr(vg_lite_buffer_t * vgbuf, const lv_color_t * buf);
60
+
61
+ /**********************
62
+ * STATIC VARIABLES
63
+ **********************/
64
+
65
+ static vg_lite_buffer_t dest_vgbuf;
66
+ static vg_lite_buffer_t src_vgbuf;
67
+
68
+ /**********************
69
+ * MACROS
70
+ **********************/
71
+
72
+ /**********************
73
+ * GLOBAL FUNCTIONS
74
+ **********************/
75
+
76
+ void lv_gpu_nxp_vglite_init_buf(const lv_color_t * buf, const lv_area_t * area, lv_coord_t stride)
77
+ {
78
+ lv_vglite_set_dest_buf(buf, area, stride);
79
+ }
80
+
81
+ vg_lite_buffer_t * lv_vglite_get_dest_buf(void)
82
+ {
83
+ return &dest_vgbuf;
84
+ }
85
+
86
+ vg_lite_buffer_t * lv_vglite_get_src_buf(void)
87
+ {
88
+ return &src_vgbuf;
89
+ }
90
+
91
+ void lv_vglite_set_dest_buf_ptr(const lv_color_t * buf)
92
+ {
93
+ lv_vglite_set_buf_ptr(&dest_vgbuf, buf);
94
+ }
95
+
96
+ void lv_vglite_set_src_buf_ptr(const lv_color_t * buf)
97
+ {
98
+ lv_vglite_set_buf_ptr(&src_vgbuf, buf);
99
+ }
100
+
101
+ void lv_vglite_set_src_buf(const lv_color_t * buf, const lv_area_t * area, lv_coord_t stride)
102
+ {
103
+ if(src_vgbuf.memory != (void *)buf)
104
+ lv_vglite_set_buf(&src_vgbuf, buf, area, stride);
105
+ }
106
+
107
+ void lv_vglite_set_buf(vg_lite_buffer_t * vgbuf, const lv_color_t * buf,
108
+ const lv_area_t * area, lv_coord_t stride)
109
+ {
110
+ vgbuf->format = VG_LITE_PX_FMT;
111
+ vgbuf->tiled = VG_LITE_LINEAR;
112
+ vgbuf->image_mode = VG_LITE_NORMAL_IMAGE_MODE;
113
+ vgbuf->transparency_mode = VG_LITE_IMAGE_OPAQUE;
114
+
115
+ vgbuf->width = (int32_t)lv_area_get_width(area);
116
+ vgbuf->height = (int32_t)lv_area_get_height(area);
117
+ vgbuf->stride = (int32_t)(stride) * sizeof(lv_color_t);
118
+
119
+ lv_memset_00(&vgbuf->yuv, sizeof(vgbuf->yuv));
120
+
121
+ vgbuf->memory = (void *)buf;
122
+ vgbuf->address = (uint32_t)vgbuf->memory;
123
+ vgbuf->handle = NULL;
124
+ }
125
+
126
+ /**********************
127
+ * STATIC FUNCTIONS
128
+ **********************/
129
+
130
+ static inline void lv_vglite_set_dest_buf(const lv_color_t * buf, const lv_area_t * area, lv_coord_t stride)
131
+ {
132
+ lv_vglite_set_buf(&dest_vgbuf, buf, area, stride);
133
+ }
134
+
135
+ static inline void lv_vglite_set_buf_ptr(vg_lite_buffer_t * vgbuf, const lv_color_t * buf)
136
+ {
137
+ vgbuf->memory = (void *)buf;
138
+ vgbuf->address = (uint32_t)vgbuf->memory;
139
+ }
140
+
141
+ #endif /*LV_USE_GPU_NXP_VG_LITE*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_vglite_buf.h ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_vglite_buf.h
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ #ifndef LV_VGLITE_BUF_H
31
+ #define LV_VGLITE_BUF_H
32
+
33
+ #ifdef __cplusplus
34
+ extern "C" {
35
+ #endif
36
+
37
+ /*********************
38
+ * INCLUDES
39
+ *********************/
40
+ #include "../../../lv_conf_internal.h"
41
+
42
+ #if LV_USE_GPU_NXP_VG_LITE
43
+ #include "vg_lite.h"
44
+ #include "../../sw/lv_draw_sw.h"
45
+
46
+ /*********************
47
+ * DEFINES
48
+ *********************/
49
+
50
+ /**********************
51
+ * TYPEDEFS
52
+ **********************/
53
+
54
+ /**********************
55
+ * GLOBAL PROTOTYPES
56
+ **********************/
57
+ /**
58
+ * Init vglite destination buffer. It will be done once per frame.
59
+ *
60
+ * @param[in] buf Destination buffer address (does not require alignment for VG_LITE_LINEAR mode)
61
+ * @param[in] area Destination buffer area (for width and height)
62
+ * @param[in] stride Stride of destination buffer
63
+ */
64
+ void lv_gpu_nxp_vglite_init_buf(const lv_color_t * buf, const lv_area_t * area, lv_coord_t stride);
65
+
66
+ /**
67
+ * Get vglite destination buffer pointer.
68
+ *
69
+ * @retval The vglite destination buffer
70
+ */
71
+ vg_lite_buffer_t * lv_vglite_get_dest_buf(void);
72
+
73
+ /**
74
+ * Get vglite source buffer pointer.
75
+ *
76
+ * @retval The vglite source buffer
77
+ */
78
+ vg_lite_buffer_t * lv_vglite_get_src_buf(void);
79
+
80
+ /**
81
+ * Set vglite destination buffer address only.
82
+ *
83
+ * @param[in] buf Destination buffer address (does not require alignment for VG_LITE_LINEAR mode)
84
+ */
85
+ void lv_vglite_set_dest_buf_ptr(const lv_color_t * buf);
86
+
87
+ /**
88
+ * Set vglite source buffer address only.
89
+ *
90
+ * @param[in] buf Source buffer address
91
+ */
92
+ void lv_vglite_set_src_buf_ptr(const lv_color_t * buf);
93
+
94
+ /**
95
+ * Set vglite source buffer. It will be done only if buffer addreess is different.
96
+ *
97
+ * @param[in] buf Source buffer address
98
+ * @param[in] area Source buffer area (for width and height)
99
+ * @param[in] stride Stride of source buffer
100
+ */
101
+ void lv_vglite_set_src_buf(const lv_color_t * buf, const lv_area_t * area, lv_coord_t stride);
102
+
103
+ /**
104
+ * Set vglite buffer.
105
+ *
106
+ * @param[in] vgbuf Address of the VGLite buffer object
107
+ * @param[in] buf Address of the memory for the VGLite buffer
108
+ * @param[in] area buffer area (for width and height)
109
+ * @param[in] stride buffer stride
110
+ */
111
+ void lv_vglite_set_buf(vg_lite_buffer_t * vgbuf, const lv_color_t * buf,
112
+ const lv_area_t * area, lv_coord_t stride);
113
+
114
+ /**********************
115
+ * MACROS
116
+ **********************/
117
+
118
+ #endif /*LV_USE_GPU_NXP_VG_LITE*/
119
+
120
+ #ifdef __cplusplus
121
+ } /*extern "C"*/
122
+ #endif
123
+
124
+ #endif /*LV_VGLITE_BUF_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_vglite_utils.c ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_vglite_utils.c
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2022, 2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ /*********************
31
+ * INCLUDES
32
+ *********************/
33
+
34
+ #include "lv_vglite_utils.h"
35
+
36
+ #if LV_USE_GPU_NXP_VG_LITE
37
+ #include "../../../core/lv_refr.h"
38
+
39
+ /*********************
40
+ * DEFINES
41
+ *********************/
42
+
43
+ /**********************
44
+ * TYPEDEFS
45
+ **********************/
46
+
47
+ /**********************
48
+ * STATIC PROTOTYPES
49
+ **********************/
50
+
51
+ /**
52
+ * Clean and invalidate cache.
53
+ */
54
+ static inline void invalidate_cache(void);
55
+
56
+ /**********************
57
+ * STATIC VARIABLES
58
+ **********************/
59
+
60
+ /**********************
61
+ * MACROS
62
+ **********************/
63
+
64
+ /**********************
65
+ * GLOBAL FUNCTIONS
66
+ **********************/
67
+
68
+ lv_res_t lv_vglite_run(void)
69
+ {
70
+ invalidate_cache();
71
+
72
+ VG_LITE_ERR_RETURN_INV(vg_lite_flush(), "Flush failed.");
73
+
74
+ return LV_RES_OK;
75
+ }
76
+
77
+ lv_res_t lv_vglite_premult_and_swizzle(vg_lite_color_t * vg_col32, lv_color32_t lv_col32, lv_opa_t opa,
78
+ vg_lite_buffer_format_t vg_col_format)
79
+ {
80
+
81
+ lv_color32_t lv_col32_premul = lv_col32;
82
+ if(opa <= (lv_opa_t)LV_OPA_MAX) {
83
+ /* Only pre-multiply color if hardware pre-multiplication is not present */
84
+ if(!vg_lite_query_feature(gcFEATURE_BIT_VG_PE_PREMULTIPLY)) {
85
+ lv_col32_premul.ch.red = (uint8_t)(((uint16_t)lv_col32.ch.red * opa) >> 8);
86
+ lv_col32_premul.ch.green = (uint8_t)(((uint16_t)lv_col32.ch.green * opa) >> 8);
87
+ lv_col32_premul.ch.blue = (uint8_t)(((uint16_t)lv_col32.ch.blue * opa) >> 8);
88
+ }
89
+ lv_col32_premul.ch.alpha = opa;
90
+ }
91
+
92
+ switch(vg_col_format) {
93
+ case VG_LITE_BGRA8888:
94
+ *vg_col32 = lv_col32_premul.full;
95
+ break;
96
+ case VG_LITE_RGBA8888:
97
+ *vg_col32 = ((uint32_t)lv_col32_premul.ch.red << 24) | ((uint32_t)lv_col32_premul.ch.green << 16) |
98
+ ((uint32_t)lv_col32_premul.ch.blue << 8) | (uint32_t)lv_col32_premul.ch.alpha;
99
+ break;
100
+ case VG_LITE_ABGR8888:
101
+ *vg_col32 = ((uint32_t)lv_col32_premul.ch.alpha << 24) | ((uint32_t)lv_col32_premul.ch.blue << 16) |
102
+ ((uint32_t)lv_col32_premul.ch.green << 8) | (uint32_t)lv_col32_premul.ch.red;
103
+ break;
104
+ case VG_LITE_ARGB8888:
105
+ *vg_col32 = ((uint32_t)lv_col32_premul.ch.alpha << 24) | ((uint32_t)lv_col32_premul.ch.red << 16) |
106
+ ((uint32_t)lv_col32_premul.ch.green << 8) | (uint32_t)lv_col32_premul.ch.blue;
107
+ break;
108
+ default:
109
+ return LV_RES_INV;
110
+ }
111
+
112
+ return LV_RES_OK;
113
+ }
114
+
115
+ vg_lite_blend_t lv_vglite_get_blend_mode(lv_blend_mode_t lv_blend_mode)
116
+ {
117
+ vg_lite_blend_t vg_blend_mode;
118
+ switch(lv_blend_mode) {
119
+ case LV_BLEND_MODE_ADDITIVE:
120
+ vg_blend_mode = VG_LITE_BLEND_ADDITIVE;
121
+ break;
122
+ case LV_BLEND_MODE_SUBTRACTIVE:
123
+ vg_blend_mode = VG_LITE_BLEND_SUBTRACT;
124
+ break;
125
+ case LV_BLEND_MODE_MULTIPLY:
126
+ vg_blend_mode = VG_LITE_BLEND_MULTIPLY;
127
+ break;
128
+ case LV_BLEND_MODE_REPLACE:
129
+ vg_blend_mode = VG_LITE_BLEND_NONE;
130
+ break;
131
+ default:
132
+ vg_blend_mode = VG_LITE_BLEND_SRC_OVER;
133
+ break;
134
+ }
135
+ return vg_blend_mode;
136
+ }
137
+
138
+ /**********************
139
+ * STATIC FUNCTIONS
140
+ **********************/
141
+
142
+ static inline void invalidate_cache(void)
143
+ {
144
+ lv_disp_t * disp = _lv_refr_get_disp_refreshing();
145
+ if(disp->driver->clean_dcache_cb)
146
+ disp->driver->clean_dcache_cb(disp->driver);
147
+ }
148
+
149
+ #endif /*LV_USE_GPU_NXP_VG_LITE*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/nxp/vglite/lv_vglite_utils.h ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_vglite_utils.h
3
+ *
4
+ */
5
+
6
+ /**
7
+ * MIT License
8
+ *
9
+ * Copyright 2022, 2023 NXP
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ * of this software and associated documentation files (the "Software"), to deal
13
+ * in the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice (including the next paragraph)
19
+ * shall be included in all copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ *
28
+ */
29
+
30
+ #ifndef LV_VGLITE_UTILS_H
31
+ #define LV_VGLITE_UTILS_H
32
+
33
+ #ifdef __cplusplus
34
+ extern "C" {
35
+ #endif
36
+
37
+ /*********************
38
+ * INCLUDES
39
+ *********************/
40
+ #include "../../../lv_conf_internal.h"
41
+
42
+ #if LV_USE_GPU_NXP_VG_LITE
43
+ #include "vg_lite.h"
44
+ #include "../../sw/lv_draw_sw.h"
45
+ #include "../../../misc/lv_log.h"
46
+
47
+ /*********************
48
+ * DEFINES
49
+ *********************/
50
+
51
+ #ifndef LV_GPU_NXP_VG_LITE_LOG_ERRORS
52
+ /** Enable logging of VG-Lite errors (\see LV_LOG_ERROR)*/
53
+ #define LV_GPU_NXP_VG_LITE_LOG_ERRORS 1
54
+ #endif
55
+
56
+ #ifndef LV_GPU_NXP_VG_LITE_LOG_TRACES
57
+ /** Enable logging of VG-Lite traces (\see LV_LOG_ERROR)*/
58
+ #define LV_GPU_NXP_VG_LITE_LOG_TRACES 0
59
+ #endif
60
+
61
+
62
+ /* The optimal Bezier control point offset for radial unit
63
+ * see: https://spencermortensen.com/articles/bezier-circle/
64
+ **/
65
+ #define BEZIER_OPTIM_CIRCLE 0.551915024494f
66
+
67
+ /* Draw lines for control points of Bezier curves */
68
+ #define BEZIER_DBG_CONTROL_POINTS 0
69
+
70
+ /**********************
71
+ * TYPEDEFS
72
+ **********************/
73
+
74
+ /**********************
75
+ * STATIC PROTOTYPES
76
+ **********************/
77
+
78
+ /**
79
+ * Enable scissor and set the clipping box.
80
+ *
81
+ * @param[in] clip_area Clip area with relative coordinates of destination buffer
82
+ */
83
+ static inline void lv_vglite_set_scissor(const lv_area_t * clip_area);
84
+
85
+ /**
86
+ * Disable scissor.
87
+ */
88
+ static inline void lv_vglite_disable_scissor(void);
89
+
90
+
91
+ /**********************
92
+ * GLOBAL PROTOTYPES
93
+ **********************/
94
+
95
+ /**
96
+ * Premultiplies and swizzles given LVGL 32bit color to obtain vglite color.
97
+ *
98
+ * @param[in/out] vg_col32 The obtained vglite color
99
+ * @param[in] lv_col32 The initial LVGL 32bit color
100
+ * @param[in] opa The opacity to premultiply with
101
+ * @param[in] vg_col_format The format of the resulting vglite color
102
+ *
103
+ * @retval LV_RES_OK Operation completed
104
+ * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
105
+ */
106
+ lv_res_t lv_vglite_premult_and_swizzle(vg_lite_color_t * vg_col32, lv_color32_t lv_col32, lv_opa_t opa,
107
+ vg_lite_buffer_format_t vg_col_format);
108
+
109
+ /**
110
+ * Get vglite blend mode.
111
+ *
112
+ * @param[in] lv_blend_mode The LVGL blend mode
113
+ *
114
+ * @retval The vglite blend mode
115
+ */
116
+ vg_lite_blend_t lv_vglite_get_blend_mode(lv_blend_mode_t lv_blend_mode);
117
+
118
+ /**
119
+ * Clear cache and flush command to VG-Lite.
120
+ *
121
+ * @retval LV_RES_OK Run completed
122
+ * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_VG_LITE_LOG_ERRORS)
123
+ */
124
+ lv_res_t lv_vglite_run(void);
125
+
126
+ /**********************
127
+ * MACROS
128
+ **********************/
129
+
130
+ #define VG_LITE_COND_STOP(cond, txt) \
131
+ do { \
132
+ if (cond) { \
133
+ LV_LOG_ERROR("%s. STOP!", txt); \
134
+ for ( ; ; ); \
135
+ } \
136
+ } while(0)
137
+
138
+ #if LV_GPU_NXP_VG_LITE_LOG_ERRORS
139
+ #define VG_LITE_ERR_RETURN_INV(err, fmt, ...) \
140
+ do { \
141
+ if(err != VG_LITE_SUCCESS) { \
142
+ LV_LOG_ERROR(fmt" (err = %d)", \
143
+ err, ##__VA_ARGS__); \
144
+ return LV_RES_INV; \
145
+ } \
146
+ } while (0)
147
+ #else
148
+ #define VG_LITE_ERR_RETURN_INV(err, fmt, ...) \
149
+ do { \
150
+ if(err != VG_LITE_SUCCESS) { \
151
+ return LV_RES_INV; \
152
+ } \
153
+ }while(0)
154
+ #endif /*LV_GPU_NXP_VG_LITE_LOG_ERRORS*/
155
+
156
+ #if LV_GPU_NXP_VG_LITE_LOG_TRACES
157
+ #define VG_LITE_LOG_TRACE(fmt, ...) \
158
+ do { \
159
+ LV_LOG(fmt, ##__VA_ARGS__); \
160
+ } while (0)
161
+
162
+ #define VG_LITE_RETURN_INV(fmt, ...) \
163
+ do { \
164
+ LV_LOG_ERROR(fmt, ##__VA_ARGS__); \
165
+ return LV_RES_INV; \
166
+ } while (0)
167
+ #else
168
+ #define VG_LITE_LOG_TRACE(fmt, ...) \
169
+ do { \
170
+ } while (0)
171
+ #define VG_LITE_RETURN_INV(fmt, ...) \
172
+ do { \
173
+ return LV_RES_INV; \
174
+ }while(0)
175
+ #endif /*LV_GPU_NXP_VG_LITE_LOG_TRACES*/
176
+
177
+ /**********************
178
+ * STATIC FUNCTIONS
179
+ **********************/
180
+
181
+ static inline void lv_vglite_set_scissor(const lv_area_t * clip_area)
182
+ {
183
+ vg_lite_enable_scissor();
184
+ vg_lite_set_scissor((int32_t)clip_area->x1, (int32_t)clip_area->y1,
185
+ (int32_t)lv_area_get_width(clip_area),
186
+ (int32_t)lv_area_get_height(clip_area));
187
+ }
188
+
189
+ static inline void lv_vglite_disable_scissor(void)
190
+ {
191
+ vg_lite_disable_scissor();
192
+ }
193
+
194
+ #endif /*LV_USE_GPU_NXP_VG_LITE*/
195
+
196
+ #ifdef __cplusplus
197
+ } /*extern "C"*/
198
+ #endif
199
+
200
+ #endif /*LV_VGLITE_UTILS_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/renesas/lv_gpu_d2_draw_label.c ADDED
@@ -0,0 +1,292 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_gpu_d2_draw_label.c
3
+ *
4
+ * @description HAL layer for display driver
5
+ *
6
+ */
7
+
8
+ /*********************
9
+ * INCLUDES
10
+ *********************/
11
+ #include "../../draw/lv_draw_label.h"
12
+ #include "../../misc/lv_assert.h"
13
+ #include "../../core/lv_refr.h"
14
+ #include "lv_gpu_d2_ra6m3.h"
15
+
16
+ #if LV_USE_GPU_RA6M3_G2D
17
+ #include LV_GPU_RA6M3_G2D_INCLUDE
18
+
19
+ /**********************
20
+ * STATIC VARIABLES
21
+ **********************/
22
+
23
+ /**********************
24
+ * GLOBAL VARIABLES
25
+ **********************/
26
+ extern const uint8_t _lv_bpp1_opa_table[2];
27
+ extern const uint8_t _lv_bpp2_opa_table[4];
28
+ extern const uint8_t _lv_bpp4_opa_table[16];
29
+ extern const uint8_t _lv_bpp8_opa_table[256];
30
+
31
+ /**********************
32
+ * MACROS
33
+ **********************/
34
+
35
+ /**********************
36
+ * GLOBAL FUNCTIONS
37
+ **********************/
38
+
39
+ /**********************
40
+ * STATIC FUNCTIONS
41
+ **********************/
42
+
43
+ static void LV_ATTRIBUTE_FAST_MEM draw_letter_normal(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc,
44
+ const lv_point_t * pos, lv_font_glyph_dsc_t * g, const uint8_t * map_p)
45
+ {
46
+
47
+ const uint8_t * bpp_opa_table_p;
48
+ uint32_t bitmask_init;
49
+ uint32_t bitmask;
50
+ uint32_t bpp = g->bpp;
51
+ lv_opa_t opa = dsc->opa;
52
+ uint32_t shades;
53
+ if(bpp == 3) bpp = 4;
54
+
55
+ #if LV_USE_IMGFONT
56
+ if(bpp == LV_IMGFONT_BPP) { //is imgfont
57
+ lv_area_t fill_area;
58
+ fill_area.x1 = pos->x;
59
+ fill_area.y1 = pos->y;
60
+ fill_area.x2 = pos->x + g->box_w - 1;
61
+ fill_area.y2 = pos->y + g->box_h - 1;
62
+ lv_draw_img_dsc_t img_dsc;
63
+ lv_draw_img_dsc_init(&img_dsc);
64
+ img_dsc.angle = 0;
65
+ img_dsc.zoom = LV_IMG_ZOOM_NONE;
66
+ img_dsc.opa = dsc->opa;
67
+ img_dsc.blend_mode = dsc->blend_mode;
68
+ lv_draw_img(draw_ctx, &img_dsc, &fill_area, map_p);
69
+ return;
70
+ }
71
+ #endif
72
+
73
+ switch(bpp) {
74
+ case 1:
75
+ bpp_opa_table_p = _lv_bpp1_opa_table;
76
+ bitmask_init = 0x80;
77
+ shades = 2;
78
+ break;
79
+ case 2:
80
+ bpp_opa_table_p = _lv_bpp2_opa_table;
81
+ bitmask_init = 0xC0;
82
+ shades = 4;
83
+ break;
84
+ case 4:
85
+ bpp_opa_table_p = _lv_bpp4_opa_table;
86
+ bitmask_init = 0xF0;
87
+ shades = 16;
88
+ break;
89
+ case 8:
90
+ bpp_opa_table_p = _lv_bpp8_opa_table;
91
+ bitmask_init = 0xFF;
92
+ shades = 256;
93
+ break; /*No opa table, pixel value will be used directly*/
94
+ default:
95
+ LV_LOG_WARN("lv_draw_letter: invalid bpp");
96
+ return; /*Invalid bpp. Can't render the letter*/
97
+ }
98
+
99
+ static lv_opa_t opa_table[256];
100
+ static lv_opa_t prev_opa = LV_OPA_TRANSP;
101
+ static uint32_t prev_bpp = 0;
102
+ if(opa < LV_OPA_MAX) {
103
+ if(prev_opa != opa || prev_bpp != bpp) {
104
+ uint32_t i;
105
+ for(i = 0; i < shades; i++) {
106
+ opa_table[i] = bpp_opa_table_p[i] == LV_OPA_COVER ? opa : ((bpp_opa_table_p[i] * opa) >> 8);
107
+ }
108
+ }
109
+ bpp_opa_table_p = opa_table;
110
+ prev_opa = opa;
111
+ prev_bpp = bpp;
112
+ }
113
+
114
+ int32_t col, row;
115
+ int32_t box_w = g->box_w;
116
+ int32_t box_h = g->box_h;
117
+ int32_t width_bit = box_w * bpp; /*Letter width in bits*/
118
+
119
+ /*Calculate the col/row start/end on the map*/
120
+ int32_t col_start = pos->x >= draw_ctx->clip_area->x1 ? 0 : draw_ctx->clip_area->x1 - pos->x;
121
+ int32_t col_end = pos->x + box_w <= draw_ctx->clip_area->x2 ? box_w : draw_ctx->clip_area->x2 - pos->x + 1;
122
+ int32_t row_start = pos->y >= draw_ctx->clip_area->y1 ? 0 : draw_ctx->clip_area->y1 - pos->y;
123
+ int32_t row_end = pos->y + box_h <= draw_ctx->clip_area->y2 ? box_h : draw_ctx->clip_area->y2 - pos->y + 1;
124
+
125
+ /*Move on the map too*/
126
+ uint32_t bit_ofs = (row_start * width_bit) + (col_start * bpp);
127
+ map_p += bit_ofs >> 3;
128
+
129
+ uint8_t letter_px;
130
+ uint32_t col_bit;
131
+ col_bit = bit_ofs & 0x7; /*"& 0x7" equals to "% 8" just faster*/
132
+
133
+ lv_draw_sw_blend_dsc_t blend_dsc;
134
+ lv_memset_00(&blend_dsc, sizeof(blend_dsc));
135
+ blend_dsc.color = dsc->color;
136
+ blend_dsc.opa = LV_OPA_COVER;
137
+ blend_dsc.blend_mode = dsc->blend_mode;
138
+
139
+ lv_coord_t hor_res = lv_disp_get_hor_res(_lv_refr_get_disp_refreshing());
140
+ uint32_t mask_buf_size = box_w * box_h > hor_res ? hor_res : box_w * box_h;
141
+ lv_opa_t * mask_buf = lv_mem_buf_get(mask_buf_size);
142
+ blend_dsc.mask_buf = mask_buf;
143
+ int32_t mask_p = 0;
144
+
145
+ lv_area_t fill_area;
146
+ fill_area.x1 = col_start + pos->x;
147
+ fill_area.x2 = col_end + pos->x - 1;
148
+ fill_area.y1 = row_start + pos->y;
149
+ fill_area.y2 = fill_area.y1;
150
+ #if LV_DRAW_COMPLEX
151
+ lv_coord_t fill_w = lv_area_get_width(&fill_area);
152
+ lv_area_t mask_area;
153
+ lv_area_copy(&mask_area, &fill_area);
154
+ mask_area.y2 = mask_area.y1 + row_end;
155
+ bool mask_any = lv_draw_mask_is_any(&mask_area);
156
+ #endif
157
+ blend_dsc.blend_area = &fill_area;
158
+ blend_dsc.mask_area = &fill_area;
159
+
160
+ uint32_t col_bit_max = 8 - bpp;
161
+ uint32_t col_bit_row_ofs = (box_w + col_start - col_end) * bpp;
162
+
163
+ for(row = row_start ; row < row_end; row++) {
164
+ #if LV_DRAW_COMPLEX
165
+ int32_t mask_p_start = mask_p;
166
+ #endif
167
+ bitmask = bitmask_init >> col_bit;
168
+ for(col = col_start; col < col_end; col++) {
169
+ /*Load the pixel's opacity into the mask*/
170
+ letter_px = (*map_p & bitmask) >> (col_bit_max - col_bit);
171
+ if(letter_px) {
172
+ mask_buf[mask_p] = bpp_opa_table_p[letter_px];
173
+ }
174
+ else {
175
+ mask_buf[mask_p] = 0;
176
+ }
177
+
178
+ /*Go to the next column*/
179
+ if(col_bit < col_bit_max) {
180
+ col_bit += bpp;
181
+ bitmask = bitmask >> bpp;
182
+ }
183
+ else {
184
+ col_bit = 0;
185
+ bitmask = bitmask_init;
186
+ map_p++;
187
+ }
188
+
189
+ /*Next mask byte*/
190
+ mask_p++;
191
+ }
192
+
193
+ #if LV_DRAW_COMPLEX
194
+ /*Apply masks if any*/
195
+ if(mask_any) {
196
+ blend_dsc.mask_res = lv_draw_mask_apply(mask_buf + mask_p_start, fill_area.x1, fill_area.y2,
197
+ fill_w);
198
+ if(blend_dsc.mask_res == LV_DRAW_MASK_RES_TRANSP) {
199
+ lv_memset_00(mask_buf + mask_p_start, fill_w);
200
+ }
201
+ }
202
+ #endif
203
+
204
+ if((uint32_t) mask_p + (col_end - col_start) < mask_buf_size) {
205
+ fill_area.y2 ++;
206
+ }
207
+ else {
208
+ blend_dsc.mask_res = LV_DRAW_MASK_RES_CHANGED;
209
+ lv_draw_ra6m3_2d_blend(draw_ctx, &blend_dsc);
210
+
211
+ fill_area.y1 = fill_area.y2 + 1;
212
+ fill_area.y2 = fill_area.y1;
213
+ mask_p = 0;
214
+ }
215
+
216
+ col_bit += col_bit_row_ofs;
217
+ map_p += (col_bit >> 3);
218
+ col_bit = col_bit & 0x7;
219
+ }
220
+
221
+ /*Flush the last part*/
222
+ if(fill_area.y1 != fill_area.y2) {
223
+ fill_area.y2--;
224
+ blend_dsc.mask_res = LV_DRAW_MASK_RES_CHANGED;
225
+ lv_draw_ra6m3_2d_blend(draw_ctx, &blend_dsc);
226
+ mask_p = 0;
227
+ }
228
+
229
+ lv_mem_buf_release(mask_buf);
230
+ }
231
+
232
+ void lv_draw_gpu_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, const lv_point_t * pos_p,
233
+ uint32_t letter)
234
+ {
235
+ const lv_font_t * font_p = dsc->font;
236
+
237
+ lv_opa_t opa = dsc->opa;
238
+ if(opa < LV_OPA_MIN) return;
239
+ if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;
240
+
241
+ if(font_p == NULL) {
242
+ LV_LOG_WARN("lv_draw_letter: font is NULL");
243
+ return;
244
+ }
245
+
246
+ lv_font_glyph_dsc_t g;
247
+ bool g_ret = lv_font_get_glyph_dsc(font_p, &g, letter, '\0');
248
+ if(g_ret == false) {
249
+ /*Add warning if the dsc is not found
250
+ *but do not print warning for non printable ASCII chars (e.g. '\n')*/
251
+ if(letter >= 0x20 &&
252
+ letter != 0xf8ff && /*LV_SYMBOL_DUMMY*/
253
+ letter != 0x200c) { /*ZERO WIDTH NON-JOINER*/
254
+ LV_LOG_WARN("lv_draw_letter: glyph dsc. not found for U+%X", letter);
255
+ }
256
+ return;
257
+ }
258
+
259
+ /*Don't draw anything if the character is empty. E.g. space*/
260
+ if((g.box_h == 0) || (g.box_w == 0)) return;
261
+
262
+ lv_point_t gpos;
263
+ gpos.x = pos_p->x + g.ofs_x;
264
+ gpos.y = pos_p->y + (dsc->font->line_height - dsc->font->base_line) - g.box_h - g.ofs_y;
265
+
266
+ /*If the letter is completely out of mask don't draw it*/
267
+ if(gpos.x + g.box_w < draw_ctx->clip_area->x1 ||
268
+ gpos.x > draw_ctx->clip_area->x2 ||
269
+ gpos.y + g.box_h < draw_ctx->clip_area->y1 ||
270
+ gpos.y > draw_ctx->clip_area->y2) {
271
+ return;
272
+ }
273
+
274
+ const uint8_t * map_p = lv_font_get_glyph_bitmap(font_p, letter);
275
+ if(map_p == NULL) {
276
+ LV_LOG_WARN("lv_draw_letter: character's bitmap not found");
277
+ return;
278
+ }
279
+
280
+ if(font_p->subpx) {
281
+ #if LV_DRAW_COMPLEX && LV_USE_FONT_SUBPX
282
+ draw_letter_subpx(pos_x, pos_y, &g, clip_area, map_p, color, opa, blend_mode);
283
+ #else
284
+ LV_LOG_WARN("Can't draw sub-pixel rendered letter because LV_USE_FONT_SUBPX == 0 in lv_conf.h");
285
+ #endif
286
+ }
287
+ else {
288
+ draw_letter_normal(draw_ctx, dsc, &gpos, &g, map_p);
289
+ }
290
+ }
291
+
292
+ #endif
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/renesas/lv_gpu_d2_ra6m3.c ADDED
@@ -0,0 +1,742 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_gpu_d2_ra6m3.c
3
+ *
4
+ */
5
+
6
+ /*********************
7
+ * INCLUDES
8
+ *********************/
9
+ #include "lv_gpu_d2_ra6m3.h"
10
+ #include "../../core/lv_refr.h"
11
+ #include <math.h>
12
+
13
+ #if LV_USE_GPU_RA6M3_G2D
14
+
15
+ #include LV_GPU_RA6M3_G2D_INCLUDE
16
+
17
+ /*********************
18
+ * DEFINES
19
+ *********************/
20
+ #define LOG_ERRORS
21
+ #ifdef LOG_ERRORS
22
+ #define STRINGIFY(x) #x
23
+ #define TOSTRING(x) STRINGIFY(x)
24
+
25
+ #define ERROR_LIST_SIZE (4)
26
+ #define D2_EXEC(a) lv_port_gpu_log_error(a, __func__, __LINE__)
27
+ #else
28
+ /* here is error logging not enabled */
29
+ #define D2_EXEC(a) a;
30
+ #endif
31
+
32
+ /**********************
33
+ * TYPEDEFS
34
+ **********************/
35
+ typedef struct {
36
+ d2_s32 error;
37
+ const char * func;
38
+ int line;
39
+ } log_error_entry;
40
+
41
+ /**********************
42
+ * STATIC PROTOTYPES
43
+ **********************/
44
+ #ifdef LOG_ERRORS
45
+ static void lv_port_gpu_log_error(d2_s32 status, const char * func, int line);
46
+ #endif
47
+ static void invalidate_cache(void);
48
+
49
+ void lv_draw_gpu_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, const lv_point_t * pos_p,
50
+ uint32_t letter);
51
+
52
+ /**********************
53
+ * STATIC VARIABLES
54
+ **********************/
55
+ #ifdef LOG_ERRORS
56
+ static log_error_entry log_error_list[ERROR_LIST_SIZE];
57
+ static int error_list_index;
58
+ static int error_count;
59
+ #endif
60
+
61
+ static d2_device * _d2_handle;
62
+ static d2_renderbuffer * renderbuffer;
63
+
64
+ static d2_s32 src_cf_val, dst_cf_val;
65
+ static lv_draw_img_dsc_t img_dsc;
66
+ static bool color_key_enabled, alpha_enabled, blend_enabled, colorize_enabled;
67
+
68
+ /**********************
69
+ * STATIC FUNCTIONS
70
+ **********************/
71
+ static d2_s32 lv_port_gpu_cf_lv_to_d2(lv_img_cf_t cf)
72
+ {
73
+ d2_s32 d2_cf;
74
+
75
+ #if (DLG_LVGL_CF == 1)
76
+ switch(cf & ~(1 << 5)) {
77
+ #else
78
+ switch(cf) {
79
+ #endif /* (DLG_LVGL_CF == 1) */
80
+ case LV_IMG_CF_TRUE_COLOR:
81
+ d2_cf = d2_mode_rgb565;
82
+ break;
83
+ case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED:
84
+ d2_cf = d2_mode_rgb565;
85
+ break;
86
+ case LV_IMG_CF_ALPHA_1BIT:
87
+ d2_cf = d2_mode_alpha1;
88
+ break;
89
+ case LV_IMG_CF_ALPHA_2BIT:
90
+ d2_cf = d2_mode_alpha2;
91
+ break;
92
+ case LV_IMG_CF_ALPHA_4BIT:
93
+ d2_cf = d2_mode_alpha4;
94
+ break;
95
+ case LV_IMG_CF_ALPHA_8BIT:
96
+ d2_cf = d2_mode_alpha8;
97
+ break;
98
+ case LV_IMG_CF_INDEXED_1BIT:
99
+ d2_cf = d2_mode_i1 | d2_mode_clut;
100
+ break;
101
+ case LV_IMG_CF_INDEXED_2BIT:
102
+ d2_cf = d2_mode_i2 | d2_mode_clut;
103
+ break;
104
+ case LV_IMG_CF_INDEXED_4BIT:
105
+ d2_cf = d2_mode_i4 | d2_mode_clut;
106
+ break;
107
+ case LV_IMG_CF_INDEXED_8BIT:
108
+ d2_cf = d2_mode_i8 | d2_mode_clut;
109
+ break;
110
+ #if (DLG_LVGL_CF == 1)
111
+ case LV_IMG_CF_RGB565:
112
+ d2_cf = d2_mode_rgb565;
113
+ break;
114
+ case LV_IMG_CF_RGB888:
115
+ d2_cf = d2_mode_rgb888;
116
+ break;
117
+ case LV_IMG_CF_RGBA8888:
118
+ d2_cf = d2_mode_rgba8888;
119
+ break;
120
+ #endif /* DLG_LVGL_CF */
121
+ default:
122
+ return -1;
123
+ }
124
+
125
+ #if (DLG_LVGL_CF == 1)
126
+ return d2_cf | (cf & (1 << 5) ? d2_mode_rle : 0);
127
+ #else
128
+ return d2_cf;
129
+ #endif /* (DLG_LVGL_CF == 1) */
130
+ }
131
+
132
+ static bool lv_port_gpu_cf_fb_valid(d2_s32 cf)
133
+ {
134
+ if((cf & (d2_mode_rle | d2_mode_clut)) || cf < 0) {
135
+ return false;
136
+ }
137
+
138
+ switch(cf) {
139
+ case d2_mode_alpha8:
140
+ case d2_mode_rgb565:
141
+ case d2_mode_argb8888:
142
+ case d2_mode_argb4444:
143
+ case d2_mode_rgba8888:
144
+ case d2_mode_rgba4444:
145
+ return true;
146
+ default:
147
+ return false;
148
+ }
149
+ }
150
+
151
+ static bool lv_port_gpu_cf_has_alpha(d2_s32 cf)
152
+ {
153
+ switch(cf & ~(d2_mode_clut | d2_mode_rle)) {
154
+ case d2_mode_argb8888:
155
+ case d2_mode_rgba8888:
156
+ case d2_mode_argb4444:
157
+ case d2_mode_rgba4444:
158
+ case d2_mode_argb1555:
159
+ case d2_mode_rgba5551:
160
+ case d2_mode_ai44:
161
+ case d2_mode_i8:
162
+ case d2_mode_i4:
163
+ case d2_mode_i2:
164
+ case d2_mode_i1:
165
+ case d2_mode_alpha8:
166
+ case d2_mode_alpha4:
167
+ case d2_mode_alpha2:
168
+ case d2_mode_alpha1:
169
+ return true;
170
+ default:
171
+ return false;
172
+ }
173
+ }
174
+
175
+ static bool lv_port_gpu_cf_is_alpha(d2_s32 cf)
176
+ {
177
+ switch(cf & ~d2_mode_rle) {
178
+ case d2_mode_alpha8:
179
+ case d2_mode_alpha4:
180
+ case d2_mode_alpha2:
181
+ case d2_mode_alpha1:
182
+ return true;
183
+ default:
184
+ return false;
185
+ }
186
+ }
187
+
188
+ static d2_color lv_port_gpu_color_lv_to_d2(lv_color_t color)
189
+ {
190
+ uint8_t alpha, red, green, blue;
191
+
192
+ alpha = 0xFF;
193
+ red = color.ch.red << 3 | color.ch.red >> 2;
194
+ green = color.ch.green << 2 | color.ch.green >> 4;
195
+ blue = color.ch.blue << 3 | color.ch.blue >> 2;
196
+
197
+ return (alpha) << 24UL
198
+ | (red) << 16UL
199
+ | (green) << 8UL
200
+ | (blue) << 0UL;
201
+ }
202
+
203
+ static void lv_port_gpu_get_recolor_consts(d2_color * cl, d2_color * ch)
204
+ {
205
+ d2_color c = lv_port_gpu_color_lv_to_d2(img_dsc.recolor);
206
+ d2_alpha r, g, b, opa = img_dsc.recolor_opa > LV_OPA_MAX ? LV_OPA_COVER : img_dsc.recolor_opa;
207
+
208
+ r = ((uint32_t)((uint8_t)(c >> 16UL)) * opa) / 255;
209
+ g = ((uint32_t)((uint8_t)(c >> 8UL)) * opa) / 255;
210
+ b = ((uint32_t)((uint8_t)(c >> 0UL)) * opa) / 255;
211
+ *cl = r << 16UL | g << 8UL | b << 0UL;
212
+
213
+ r += 255 - opa;
214
+ g += 255 - opa;
215
+ b += 255 - opa;
216
+ *ch = r << 16UL | g << 8UL | b << 0UL;
217
+ }
218
+
219
+ static int lv_port_gpu_handle_indexed_color(const lv_color_t ** src, const d2_color ** clut, d2_s32 cf)
220
+ {
221
+ int clut_len = 0;
222
+
223
+ if(cf & d2_mode_clut) {
224
+ /* Calculate CLUT length in entries */
225
+ switch(cf & ~(d2_mode_clut | d2_mode_rle)) {
226
+ case d2_mode_i1:
227
+ clut_len = 2;
228
+ break;
229
+ case d2_mode_i2:
230
+ clut_len = 4;
231
+ break;
232
+ case d2_mode_i4:
233
+ clut_len = 16;
234
+ break;
235
+ case d2_mode_i8:
236
+ clut_len = 256;
237
+ break;
238
+ case d2_mode_ai44:
239
+ clut_len = 16;
240
+ break;
241
+ default:
242
+ return 0;
243
+ }
244
+
245
+ *clut = (const d2_color *)*src;
246
+ *src = (const lv_color_t *)((const uint32_t *)*src + clut_len);
247
+ }
248
+ return clut_len;
249
+ }
250
+
251
+ static int lv_port_gpu_cf_bpp(d2_s32 cf)
252
+ {
253
+ switch(cf & ~(d2_mode_clut | d2_mode_rle)) {
254
+ case d2_mode_argb8888:
255
+ return 32;
256
+ case d2_mode_rgba8888:
257
+ return 32;
258
+ case d2_mode_rgb888:
259
+ return 32;
260
+ case d2_mode_argb4444:
261
+ return 16;
262
+ case d2_mode_rgba4444:
263
+ return 16;
264
+ case d2_mode_argb1555:
265
+ return 16;
266
+ case d2_mode_rgba5551:
267
+ return 16;
268
+ case d2_mode_rgb565:
269
+ return 16;
270
+ case d2_mode_ai44:
271
+ return 8;
272
+ case d2_mode_i8:
273
+ return 8;
274
+ case d2_mode_i4:
275
+ return 4;
276
+ case d2_mode_i2:
277
+ return 2;
278
+ case d2_mode_i1:
279
+ return 1;
280
+ case d2_mode_alpha8:
281
+ return 8;
282
+ case d2_mode_alpha4:
283
+ return 4;
284
+ case d2_mode_alpha2:
285
+ return 2;
286
+ case d2_mode_alpha1:
287
+ return 1;
288
+ default:
289
+ return 0;
290
+ }
291
+ }
292
+
293
+ static d2_s32 lv_port_gpu_cf_get_default(void)
294
+ {
295
+ return d2_mode_rgb565;
296
+ }
297
+
298
+ static void lv_port_gpu_config_blit_clear(void)
299
+ {
300
+ alpha_enabled = false;
301
+ color_key_enabled = false;
302
+ blend_enabled = true;
303
+ colorize_enabled = false;
304
+
305
+ lv_draw_img_dsc_init(&img_dsc);
306
+
307
+ src_cf_val = lv_port_gpu_cf_get_default();
308
+ dst_cf_val = lv_port_gpu_cf_get_default();
309
+ }
310
+
311
+ void lv_port_gpu_init(void)
312
+ {
313
+ lv_port_gpu_config_blit_clear();
314
+ }
315
+
316
+ static void lv_port_gpu_rotate_point(int * x, int * y, float cos_angle, float sin_angle, int pivot_x, int pivot_y)
317
+ {
318
+ float fx, fy;
319
+
320
+ *x -= pivot_x;
321
+ *y -= pivot_y;
322
+
323
+ fx = ((float) * x) / 16.0f;
324
+ fy = ((float) * y) / 16.0f;
325
+
326
+ *x = (int)(((fx * cos_angle) - (fy * sin_angle)) * 16.0f);
327
+ *y = (int)(((fx * sin_angle) + (fy * cos_angle)) * 16.0f);
328
+
329
+ *x += pivot_x;
330
+ *y += pivot_y;
331
+ }
332
+
333
+ void lv_draw_ra6m3_g2d_init(void)
334
+ {
335
+ if(_d2_handle != NULL) {
336
+ return;
337
+ }
338
+
339
+ _d2_handle = d2_opendevice(0);
340
+
341
+ if(_d2_handle == NULL)
342
+ return;
343
+
344
+ /* set blocksize for default displaylist */
345
+ if(d2_setdlistblocksize(_d2_handle, 25) != D2_OK) {
346
+ LV_LOG_ERROR("Could NOT d2_setdlistblocksize\n");
347
+ d2_closedevice(_d2_handle);
348
+
349
+ return;
350
+ }
351
+
352
+ /* bind the hardware */
353
+ if(d2_inithw(_d2_handle, 0) != D2_OK) {
354
+ LV_LOG_ERROR("Could NOT d2_inithw\n");
355
+ d2_closedevice(_d2_handle);
356
+
357
+ return;
358
+ }
359
+
360
+ renderbuffer = d2_newrenderbuffer(_d2_handle, 20, 20);
361
+ if(!renderbuffer) {
362
+ LV_LOG_ERROR("NO renderbuffer\n");
363
+ d2_closedevice(_d2_handle);
364
+
365
+ return;
366
+ }
367
+ }
368
+
369
+ static void lv_port_gpu_hw_deinit(void)
370
+ {
371
+ if(_d2_handle == NULL)
372
+ return;
373
+
374
+ D2_EXEC(d2_freerenderbuffer(_d2_handle, renderbuffer));
375
+ D2_EXEC(d2_closedevice(_d2_handle));
376
+
377
+ renderbuffer = NULL;
378
+ _d2_handle = NULL;
379
+ }
380
+
381
+ void lv_port_gpu_flush(void)
382
+ {
383
+ lv_port_gpu_hw_deinit();
384
+ }
385
+
386
+ static void lv_port_gpu_start_render(void)
387
+ {
388
+ D2_EXEC(d2_selectrenderbuffer(_d2_handle, renderbuffer));
389
+ }
390
+
391
+ static void lv_port_gpu_complete_render(void)
392
+ {
393
+ D2_EXEC(d2_flushframe(_d2_handle));
394
+ }
395
+
396
+ void lv_port_gpu_wait(lv_draw_ctx_t * draw_ctx)
397
+ {
398
+ lv_port_gpu_complete_render();
399
+
400
+ lv_draw_sw_wait_for_finish(draw_ctx);
401
+ }
402
+
403
+ static void lv_port_gpu_execute_render(void)
404
+ {
405
+ if(_d2_handle) {
406
+ D2_EXEC(d2_executerenderbuffer(_d2_handle, renderbuffer, 0));
407
+ }
408
+ }
409
+
410
+ void lv_port_gpu_blit(int32_t x, int32_t y, lv_color_t * dst, const lv_area_t * fill_area)
411
+ {
412
+ uint32_t ModeSrc;
413
+
414
+ ModeSrc = d2_mode_rgb565;
415
+
416
+ lv_coord_t dst_width, dst_hight;
417
+ dst_width = lv_area_get_width(fill_area);
418
+ dst_hight = lv_area_get_height(fill_area);
419
+
420
+ d2_selectrenderbuffer(_d2_handle, renderbuffer);
421
+
422
+ // Generate render operations
423
+ d2_framebuffer(_d2_handle, (uint16_t *)&fb_background[0], LV_HOR_RES_MAX, LV_HOR_RES_MAX,
424
+ MAX(fill_area->y2 + 1, 2), lv_port_gpu_cf_get_default());
425
+
426
+ d2_cliprect(_d2_handle, 0, 0, LV_HOR_RES_MAX - 1, fill_area->y2);
427
+ d2_setblitsrc(_d2_handle, (void *) dst, dst_width, dst_width, dst_hight, ModeSrc);
428
+ d2_blitcopy(_d2_handle, dst_width, dst_hight, 0, 0, D2_FIX4(dst_width), D2_FIX4(dst_hight),
429
+ D2_FIX4(fill_area->x1), D2_FIX4(fill_area->y1), 0);
430
+
431
+ // Execute render operations
432
+ d2_executerenderbuffer(_d2_handle, renderbuffer, 0);
433
+ }
434
+
435
+ void lv_port_gpu_fill(lv_color_t * dest_buf, const lv_area_t * fill_area, lv_coord_t dst_width,
436
+ lv_color_t color, lv_opa_t opa)
437
+ {
438
+ invalidate_cache();
439
+
440
+ lv_port_gpu_start_render();
441
+
442
+ D2_EXEC(d2_framebuffer(_d2_handle, d1_maptovidmem(_d2_handle, dest_buf), MAX(dst_width, 2), MAX(dst_width, 2),
443
+ MAX(fill_area->y2 + 1, 2), lv_port_gpu_cf_get_default()));
444
+
445
+ D2_EXEC(d2_cliprect(_d2_handle, 0, 0, dst_width - 1, fill_area->y2));
446
+ D2_EXEC(d2_setalpha(_d2_handle, opa > LV_OPA_MAX ? 0xFF : opa));
447
+ D2_EXEC(d2_setcolor(_d2_handle, 0, lv_port_gpu_color_lv_to_d2(color)));
448
+ D2_EXEC(d2_renderbox(_d2_handle, D2_FIX4(fill_area->x1), D2_FIX4(fill_area->y1),
449
+ D2_FIX4(lv_area_get_width(fill_area)), D2_FIX4(lv_area_get_height(fill_area))));
450
+
451
+ lv_port_gpu_execute_render();
452
+ }
453
+
454
+ bool lv_port_gpu_config_blit(const lv_draw_img_dsc_t * draw_dsc, lv_img_cf_t dst_cf,
455
+ lv_img_cf_t src_cf, bool alpha_en, bool color_key_en, bool blend_en, bool colorize_en)
456
+ {
457
+ d2_s32 d2_src_cf, d2_dst_cf;
458
+
459
+ if(blend_en && draw_dsc->blend_mode != LV_BLEND_MODE_NORMAL
460
+ && draw_dsc->blend_mode != LV_BLEND_MODE_ADDITIVE) {
461
+ return false;
462
+ }
463
+
464
+ d2_src_cf = lv_port_gpu_cf_lv_to_d2(src_cf);
465
+ d2_dst_cf = lv_port_gpu_cf_lv_to_d2(dst_cf);
466
+ if(d2_src_cf < 0 || !lv_port_gpu_cf_fb_valid(d2_dst_cf)) {
467
+ return false;
468
+ }
469
+ src_cf_val = d2_src_cf;
470
+ dst_cf_val = d2_dst_cf;
471
+
472
+ img_dsc = *draw_dsc;
473
+
474
+ /* Disable alpha if alpha channel does not exist */
475
+ alpha_enabled = lv_port_gpu_cf_has_alpha(src_cf_val) ? alpha_en : 0;
476
+ color_key_enabled = color_key_en;
477
+ blend_enabled = blend_en;
478
+ colorize_enabled = colorize_en | lv_port_gpu_cf_is_alpha(src_cf_val);
479
+
480
+ return true;
481
+ }
482
+
483
+ static void lv_port_gpu_blit_internal(const lv_area_t * dest_area, const lv_color_t * src_buf,
484
+ const lv_area_t * src_area, d2_u32 flags)
485
+ {
486
+ const lv_area_t * img_area = src_area;
487
+ lv_area_t img_area_scaled;
488
+ lv_coord_t w, h, img_w, img_h;
489
+ d2_s32 pitch;
490
+ int bpp = lv_port_gpu_cf_bpp(src_cf_val);
491
+
492
+ D2_EXEC(d2_cliprect(_d2_handle, dest_area->x1, dest_area->y1, dest_area->x2, dest_area->y2));
493
+
494
+ pitch = w = lv_area_get_width(src_area);
495
+ h = lv_area_get_height(src_area);
496
+
497
+ if(img_dsc.zoom != LV_IMG_ZOOM_NONE) {
498
+ img_area_scaled.x1 = src_area->x1 + ((((int32_t)0 - img_dsc.pivot.x) * img_dsc.zoom) >> 8) + img_dsc.pivot.x;
499
+ img_area_scaled.x2 = src_area->x1 + ((((int32_t)w - img_dsc.pivot.x) * img_dsc.zoom) >> 8) + img_dsc.pivot.x;
500
+ img_area_scaled.y1 = src_area->y1 + ((((int32_t)0 - img_dsc.pivot.y) * img_dsc.zoom) >> 8) + img_dsc.pivot.y;
501
+ img_area_scaled.y2 = src_area->y1 + ((((int32_t)h - img_dsc.pivot.y) * img_dsc.zoom) >> 8) + img_dsc.pivot.y;
502
+ img_area = &img_area_scaled;
503
+ }
504
+
505
+ img_w = lv_area_get_width(img_area);
506
+ img_h = lv_area_get_height(img_area);
507
+
508
+ if(0 < bpp && bpp < 8) {
509
+ pitch = (w + (8 - bpp)) & (~(8 - bpp));
510
+ }
511
+
512
+ if(img_dsc.angle == 0) {
513
+ D2_EXEC(d2_setblitsrc(_d2_handle, (void *) src_buf, pitch, w, h, src_cf_val));
514
+
515
+ D2_EXEC(d2_blitcopy(_d2_handle, w, h, 0, 0,
516
+ D2_FIX4(img_w), D2_FIX4(img_h), D2_FIX4(img_area->x1), D2_FIX4(img_area->y1), flags));
517
+ }
518
+ else {
519
+ int x, y, x1, y1, x2, y2, x3, y3, x4, y4, dxu, dxv, dyu, dyv, xx, xy, yx, yy;
520
+ int pivot_scaled_x, pivot_scaled_y;
521
+ int tex_offset = (flags & d2_bf_filter) ? -32767 : 0;
522
+ d2_u8 amode, cmode = d2_to_copy;
523
+ float angle = ((float)img_dsc.angle / 10) * M_PI / 180;
524
+ float cos_angle = cosf(angle);
525
+ float sin_angle = sinf(angle);
526
+ d2_u8 fillmode_backup;
527
+
528
+ /* setup texture params */
529
+ fillmode_backup = d2_getfillmode(_d2_handle);
530
+ D2_EXEC(d2_setfillmode(_d2_handle, d2_fm_texture));
531
+ D2_EXEC(d2_settexture(_d2_handle, (void *) src_buf, pitch, w, h, src_cf_val));
532
+ D2_EXEC(d2_settexturemode(_d2_handle, flags & (d2_bf_filter | d2_bf_wrap)));
533
+ amode = flags & d2_bf_usealpha ? d2_to_copy : d2_to_one;
534
+ cmode = flags & d2_bf_colorize2 ? d2_to_blend : d2_to_copy;
535
+ D2_EXEC(d2_settextureoperation(_d2_handle, amode, cmode, cmode, cmode));
536
+ if(flags & d2_bf_colorize2) {
537
+ d2_color cl = d2_getcolor(_d2_handle, 0), ch = d2_getcolor(_d2_handle, 1);
538
+ D2_EXEC(d2_settexopparam(_d2_handle, d2_cc_red, (uint8_t)(cl >> 16UL),
539
+ (uint8_t)(ch >> 16UL)));
540
+ D2_EXEC(d2_settexopparam(_d2_handle, d2_cc_green, (uint8_t)(cl >> 8UL),
541
+ (uint8_t)(ch >> 8UL)));
542
+ D2_EXEC(d2_settexopparam(_d2_handle, d2_cc_blue, (uint8_t)(cl >> 0UL),
543
+ (uint8_t)(ch >> 0UL)));
544
+ }
545
+
546
+ x = D2_FIX4(img_area->x1);
547
+ y = D2_FIX4(img_area->y1);
548
+
549
+ /* define quad points */
550
+ x1 = D2_FIX4(0);
551
+ y1 = D2_FIX4(0);
552
+ x2 = D2_FIX4(img_w);
553
+ y2 = D2_FIX4(0);
554
+ x3 = D2_FIX4(img_w);
555
+ y3 = D2_FIX4(img_h);
556
+ x4 = D2_FIX4(0);
557
+ y4 = D2_FIX4(img_h);
558
+
559
+ /* rotate points for quad */
560
+ pivot_scaled_x = (img_dsc.pivot.x * img_dsc.zoom) >> 4;
561
+ pivot_scaled_y = (img_dsc.pivot.y * img_dsc.zoom) >> 4;
562
+
563
+ lv_port_gpu_rotate_point(&x1, &y1, cos_angle, sin_angle, pivot_scaled_x, pivot_scaled_y);
564
+ lv_port_gpu_rotate_point(&x2, &y2, cos_angle, sin_angle, pivot_scaled_x, pivot_scaled_y);
565
+ lv_port_gpu_rotate_point(&x3, &y3, cos_angle, sin_angle, pivot_scaled_x, pivot_scaled_y);
566
+ lv_port_gpu_rotate_point(&x4, &y4, cos_angle, sin_angle, pivot_scaled_x, pivot_scaled_y);
567
+
568
+ /* compute texture increments */
569
+ xx = (int)(cos_angle * 65536.0f);
570
+ xy = (int)(sin_angle * 65536.0f);
571
+ yx = (int)(-sin_angle * 65536.0f);
572
+ yy = (int)(cos_angle * 65536.0f);
573
+ dxu = ((D2_FIX16(w) / D2_FIX4(img_w)) * xx) >> 12;
574
+ dxv = ((D2_FIX16(w) / D2_FIX4(img_w)) * xy) >> 12;
575
+ dyu = ((D2_FIX16(h) / D2_FIX4(img_h)) * yx) >> 12;
576
+ dyv = ((D2_FIX16(h) / D2_FIX4(img_h)) * yy) >> 12;
577
+
578
+ /* map texture exactly to rotated quad, so texel center is always (0/0) top-left */
579
+ D2_EXEC(d2_settexelcenter(_d2_handle, 0, 0));
580
+ D2_EXEC(d2_settexturemapping(_d2_handle, (d2_point)(x + x1), (d2_point)(y + y1),
581
+ tex_offset, tex_offset, dxu, dxv, dyu, dyv));
582
+
583
+ int minx = MAX(dest_area->x1, D2_INT4(x + MIN(x1, MIN(x2, MIN(x3, x4)))));
584
+ int maxx = MIN(dest_area->x2, D2_INT4(x + MAX(x1, MAX(x2, MAX(x3, x4)))));
585
+ int slice = (flags & d2_bf_filter) ? 6 : 8;
586
+
587
+ /* Perform render operation in slices to acheive better performance */
588
+ for(int posx = minx; posx < maxx; posx += slice) {
589
+ D2_EXEC(d2_cliprect(_d2_handle, posx, dest_area->y1, MIN(posx + slice - 1, maxx), dest_area->y2));
590
+ D2_EXEC(d2_renderquad(_d2_handle, (d2_point)(x + x1), (d2_point)(y + y1),
591
+ (d2_point)(x + x2), (d2_point)(y + y2),
592
+ (d2_point)(x + x3), (d2_point)(y + y3),
593
+ (d2_point)(x + x4), (d2_point)(y + y4), 0));
594
+ }
595
+ D2_EXEC(d2_setfillmode(_d2_handle, fillmode_backup));
596
+ }
597
+ }
598
+
599
+ void lv_port_ra_gpu_blit(lv_color_t * dst, const lv_area_t * dst_area, lv_coord_t dest_stride,
600
+ const lv_color_t * src, const lv_area_t * src_area, lv_opa_t opa)
601
+ {
602
+ d2_u32 flags = 0;
603
+ const d2_color * clut = NULL;
604
+ int clut_len = 0;
605
+
606
+ invalidate_cache();
607
+
608
+ clut_len = lv_port_gpu_handle_indexed_color(&src, &clut, src_cf_val);
609
+
610
+ lv_port_gpu_start_render();
611
+
612
+ D2_EXEC(d2_framebuffer(_d2_handle, d1_maptovidmem(_d2_handle, dst), MAX(dest_stride, 2),
613
+ MAX(dst_area->x2 + 1, 2), MAX(dst_area->y2 + 1, 2), dst_cf_val));
614
+
615
+ flags |= alpha_enabled ? d2_bf_usealpha : 0;
616
+
617
+ D2_EXEC(d2_setalpha(_d2_handle, opa > LV_OPA_MAX ? LV_OPA_COVER : opa));
618
+
619
+ if(clut) {
620
+ D2_EXEC(d2_writetexclut_direct(_d2_handle, clut, 0, clut_len));
621
+ }
622
+
623
+ flags |= color_key_enabled ? d2_bf_usealpha : 0;
624
+ flags |= (colorize_enabled || img_dsc.recolor_opa != LV_OPA_TRANSP) ? d2_bf_colorize2 : 0;
625
+ if(colorize_enabled) {
626
+ D2_EXEC(d2_setcolor(_d2_handle, 0, lv_port_gpu_color_lv_to_d2(img_dsc.recolor)));
627
+ D2_EXEC(d2_setcolor(_d2_handle, 1, lv_port_gpu_color_lv_to_d2(img_dsc.recolor)));
628
+ }
629
+ else if(img_dsc.recolor_opa != LV_OPA_TRANSP) {
630
+ d2_color cl = 0, ch = 0;
631
+ lv_port_gpu_get_recolor_consts(&cl, &ch);
632
+ D2_EXEC(d2_setcolor(_d2_handle, 0, cl));
633
+ D2_EXEC(d2_setcolor(_d2_handle, 1, ch));
634
+ }
635
+
636
+ flags |= ((img_dsc.angle || img_dsc.zoom != LV_IMG_ZOOM_NONE) && img_dsc.antialias) ? d2_bf_filter : 0;
637
+
638
+ if(blend_enabled) {
639
+ D2_EXEC(d2_setblendmode(_d2_handle, d2_bm_alpha,
640
+ img_dsc.blend_mode != LV_BLEND_MODE_NORMAL ? d2_bm_one : d2_bm_one_minus_alpha));
641
+ D2_EXEC(d2_setalphablendmode(_d2_handle, d2_bm_one, d2_bm_one_minus_alpha));
642
+ }
643
+ else {
644
+ D2_EXEC(d2_setblendmode(_d2_handle, d2_bm_one, d2_bm_zero));
645
+ D2_EXEC(d2_setalphablendmode(_d2_handle, d2_bm_one, d2_bm_zero));
646
+ }
647
+
648
+ lv_port_gpu_blit_internal(dst_area, src, src_area, flags);
649
+
650
+ lv_port_gpu_execute_render();
651
+ }
652
+
653
+ void lv_draw_ra6m3_2d_blend(lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc)
654
+ {
655
+ lv_area_t blend_area;
656
+ if(!_lv_area_intersect(&blend_area, dsc->blend_area, draw_ctx->clip_area)) return;
657
+
658
+ bool done = false;
659
+
660
+ if(dsc->mask_buf == NULL && dsc->blend_mode == LV_BLEND_MODE_NORMAL && lv_area_get_size(&blend_area) > 100) {
661
+ lv_coord_t dest_stride = lv_area_get_width(draw_ctx->buf_area);
662
+
663
+ lv_color_t * dest_buf = draw_ctx->buf;
664
+
665
+ const lv_color_t * src_buf = dsc->src_buf;
666
+ if(src_buf) {
667
+ lv_draw_sw_blend_basic(draw_ctx, dsc);
668
+
669
+ lv_area_t src_area;
670
+ src_area.x1 = blend_area.x1 - (dsc->blend_area->x1 - draw_ctx->buf_area->x1);
671
+ src_area.y1 = blend_area.y1 - (dsc->blend_area->y1 - draw_ctx->buf_area->y1);
672
+ src_area.x2 = src_area.x1 + lv_area_get_width(dsc->blend_area) - 1;
673
+ src_area.y2 = src_area.y1 + lv_area_get_height(dsc->blend_area) - 1;
674
+
675
+ lv_port_ra_gpu_blit(dest_buf, &blend_area, dest_stride, src_buf, &src_area, dsc->opa);
676
+ done = true;
677
+ }
678
+ else if(dsc->opa >= LV_OPA_MAX) {
679
+ lv_area_move(&blend_area, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
680
+ lv_port_gpu_fill(dest_buf, &blend_area, dest_stride, dsc->color, dsc->opa);
681
+ done = true;
682
+ }
683
+ }
684
+
685
+ if(!done) lv_draw_sw_blend_basic(draw_ctx, dsc);
686
+ }
687
+
688
+ static void lv_port_gpu_img_decoded(lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * dsc,
689
+ const lv_area_t * coords, const uint8_t * map_p, lv_img_cf_t color_format)
690
+ {
691
+ /*TODO basic ARGB8888 image can be handles here*/
692
+
693
+ lv_draw_sw_img_decoded(draw_ctx, dsc, coords, map_p, color_format);
694
+ }
695
+
696
+ void lv_draw_ra6m3_2d_ctx_init(lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx)
697
+ {
698
+ lv_draw_sw_init_ctx(drv, draw_ctx);
699
+
700
+ lv_draw_ra6m3_dma2d_ctx_t * ra_2d_draw_ctx = (lv_draw_sw_ctx_t *)draw_ctx;
701
+
702
+ ra_2d_draw_ctx->blend = lv_draw_ra6m3_2d_blend;
703
+ ra_2d_draw_ctx->base_draw.draw_img_decoded = lv_port_gpu_img_decoded;
704
+ ra_2d_draw_ctx->base_draw.wait_for_finish = lv_port_gpu_wait;
705
+ ra_2d_draw_ctx->base_draw.draw_letter = lv_draw_gpu_letter;
706
+ //ra_2d_draw_ctx->base_draw.buffer_copy = lv_draw_ra6m3_2d_buffer_copy;
707
+ }
708
+
709
+ void lv_draw_stm32_dma2d_ctx_deinit(lv_disp_t * disp, lv_draw_ctx_t * draw_ctx)
710
+ {
711
+ LV_UNUSED(disp);
712
+ LV_UNUSED(draw_ctx);
713
+ }
714
+
715
+ static void invalidate_cache(void)
716
+ {
717
+ lv_disp_t * disp = _lv_refr_get_disp_refreshing();
718
+ if(disp->driver->clean_dcache_cb) disp->driver->clean_dcache_cb(disp->driver);
719
+ }
720
+
721
+ #ifdef LOG_ERRORS
722
+ static void lv_port_gpu_log_error(d2_s32 status, const char * func, int line)
723
+ {
724
+ if(status) {
725
+ log_error_list[error_list_index].error = status;
726
+ log_error_list[error_list_index].func = func;
727
+ log_error_list[error_list_index].line = line;
728
+ LV_LOG_ERROR("%s\r\n", d2_geterrorstring(_d2_handle));
729
+ LV_LOG_ERROR("%d:\t%d - %s : %d\r\n", error_count,
730
+ log_error_list[error_list_index].error,
731
+ log_error_list[error_list_index].func,
732
+ log_error_list[error_list_index].line);
733
+
734
+ error_count++;
735
+ error_list_index++;
736
+ if(error_list_index >= ERROR_LIST_SIZE) {
737
+ error_list_index = 0;
738
+ }
739
+ }
740
+ }
741
+ #endif
742
+ #endif /* LV_USE_GPU_RA6M3_G2D */
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/renesas/lv_gpu_d2_ra6m3.h ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_gpu_d2_ra6m3.h
3
+ *
4
+ */
5
+ #ifndef LV_GPU_D2_RA6M3_H
6
+ #define LV_GPU_D2_RA6M3_H
7
+
8
+ #ifdef __cplusplus
9
+ extern "C" {
10
+ #endif
11
+
12
+ /*********************
13
+ * INCLUDES
14
+ *********************/
15
+ #include "../../misc/lv_color.h"
16
+
17
+ #if LV_USE_GPU_RA6M3_G2D
18
+ #include "../../core/lv_disp.h"
19
+ #include "../sw/lv_draw_sw.h"
20
+
21
+ /**********************
22
+ * DEFINE
23
+ **********************/
24
+ #define MIN(A, B) ((A) < (B) ? (A) : (B))
25
+ #define MAX(A, B) ((A) > (B) ? (A) : (B))
26
+ #define M_PI 3.1415926
27
+
28
+ /**********************
29
+ * TYPEDEFS
30
+ **********************/
31
+ typedef lv_draw_sw_ctx_t lv_draw_ra6m3_dma2d_ctx_t;
32
+
33
+ /**********************
34
+ * GLOBAL PROTOTYPES
35
+ **********************/
36
+ void lv_draw_ra6m3_g2d_init(void);
37
+
38
+ void lv_port_gpu_init(void);
39
+
40
+ void lv_port_gpu_flush(void);
41
+
42
+ void lv_port_gpu_blit(int32_t x, int32_t y, lv_color_t * dst, const lv_area_t * fill_area);
43
+
44
+ void lv_draw_ra6m3_2d_blend(lv_draw_ctx_t * draw_ctx, const lv_draw_sw_blend_dsc_t * dsc);
45
+
46
+ void lv_draw_ra6m3_2d_ctx_init(lv_disp_drv_t * drv, lv_draw_ctx_t * draw_ctx);
47
+
48
+ void lv_draw_ra6m3_2d_ctx_deinit(lv_disp_drv_t * disp, lv_draw_ctx_t * draw_ctx);
49
+
50
+ #endif /*LV_USE_GPU_GD32_IPA*/
51
+
52
+ #ifdef __cplusplus
53
+ } /*extern "C"*/
54
+ #endif
55
+
56
+ #endif
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/README.md ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SDL_Renderer Based Drawing Functions
2
+
3
+ In LVGL, drawing was performed by CPU. To improve drawing performance on platforms with GPU,
4
+ we should perform drawing operations on GPU if possible.
5
+
6
+ This implementation has moved most bitmap blending and drawing procedures to utilize SDL_Renderer,
7
+ which takes advantages of hardware acceleration APIs like DirectX or OpenGL.
8
+
9
+ This implementation can be also considered as a reference implementation, for contributors wants to
10
+ develop accelerated drawing functions with other APIs such as OpenGL/OpenGL ES.
11
+
12
+ ## Caveats
13
+ `lv_draw_arc`, `lv_draw_line` is not enabled, due to incomplete implementation. So lines and arcs will
14
+ have significant impact to drawing performances.
15
+
16
+ Performance of this implementation still has room to improve. Or we should use more powerful APIs
17
+ such as OpenGL.
18
+
19
+ ## Notices for files
20
+
21
+ ### `lv_draw_sdl_stack_blur.c`
22
+
23
+ Contains modified code from [android-stackblur](https://github.com/kikoso/android-stackblur) project.
24
+ Apache License 2.0
25
+
26
+ ### `lv_draw_sdl_lru.c`/`lv_draw_sdl_lru.h`
27
+
28
+ Contains modified code from [C-LRU-Cache](https://github.com/willcannings/C-LRU-Cache) project. No license defined.
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl.c ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_sdl.c
3
+ *
4
+ */
5
+
6
+ /*********************
7
+ * INCLUDES
8
+ *********************/
9
+
10
+
11
+ #include "../../lv_conf_internal.h"
12
+
13
+ #if LV_USE_GPU_SDL
14
+
15
+ #include "lv_draw_sdl.h"
16
+ #include "lv_draw_sdl_utils.h"
17
+ #include "lv_draw_sdl_texture_cache.h"
18
+ #include "lv_draw_sdl_layer.h"
19
+
20
+ /*********************
21
+ * DEFINES
22
+ *********************/
23
+ void lv_draw_sdl_draw_rect(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords);
24
+
25
+ lv_res_t lv_draw_sdl_img_core(lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * draw_dsc,
26
+ const lv_area_t * coords, const void * src);
27
+
28
+ void lv_draw_sdl_draw_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, const lv_point_t * pos_p,
29
+ uint32_t letter);
30
+
31
+ void lv_draw_sdl_draw_line(lv_draw_ctx_t * draw_ctx, const lv_draw_line_dsc_t * dsc, const lv_point_t * point1,
32
+ const lv_point_t * point2);
33
+
34
+ void lv_draw_sdl_draw_arc(lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * dsc, const lv_point_t * center,
35
+ uint16_t radius, uint16_t start_angle, uint16_t end_angle);
36
+
37
+ void lv_draw_sdl_polygon(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, const lv_point_t * points,
38
+ uint16_t point_cnt);
39
+
40
+ void lv_draw_sdl_draw_bg(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords);
41
+
42
+ /**********************
43
+ * TYPEDEFS
44
+ **********************/
45
+
46
+ /**********************
47
+ * STATIC PROTOTYPES
48
+ **********************/
49
+
50
+ /**********************
51
+ * STATIC VARIABLES
52
+ **********************/
53
+
54
+ /**********************
55
+ * MACROS
56
+ **********************/
57
+
58
+ /**********************
59
+ * GLOBAL FUNCTIONS
60
+ **********************/
61
+
62
+ void lv_draw_sdl_init_ctx(lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx)
63
+ {
64
+ _lv_draw_sdl_utils_init();
65
+ lv_memset_00(draw_ctx, sizeof(lv_draw_sdl_ctx_t));
66
+ draw_ctx->draw_rect = lv_draw_sdl_draw_rect;
67
+ draw_ctx->draw_img = lv_draw_sdl_img_core;
68
+ draw_ctx->draw_letter = lv_draw_sdl_draw_letter;
69
+ draw_ctx->draw_line = lv_draw_sdl_draw_line;
70
+ draw_ctx->draw_arc = lv_draw_sdl_draw_arc;
71
+ draw_ctx->draw_polygon = lv_draw_sdl_polygon;
72
+ draw_ctx->draw_bg = lv_draw_sdl_draw_bg;
73
+ draw_ctx->layer_init = lv_draw_sdl_layer_init;
74
+ draw_ctx->layer_blend = lv_draw_sdl_layer_blend;
75
+ draw_ctx->layer_destroy = lv_draw_sdl_layer_destroy;
76
+ draw_ctx->layer_instance_size = sizeof(lv_draw_sdl_layer_ctx_t);
77
+ lv_draw_sdl_ctx_t * draw_ctx_sdl = (lv_draw_sdl_ctx_t *) draw_ctx;
78
+ draw_ctx_sdl->renderer = ((lv_draw_sdl_drv_param_t *) disp_drv->user_data)->renderer;
79
+ draw_ctx_sdl->internals = lv_mem_alloc(sizeof(lv_draw_sdl_context_internals_t));
80
+ lv_memset_00(draw_ctx_sdl->internals, sizeof(lv_draw_sdl_context_internals_t));
81
+ lv_draw_sdl_texture_cache_init(draw_ctx_sdl);
82
+ }
83
+
84
+ void lv_draw_sdl_deinit_ctx(lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx)
85
+ {
86
+ lv_draw_sdl_ctx_t * draw_ctx_sdl = (lv_draw_sdl_ctx_t *) draw_ctx;
87
+ lv_draw_sdl_texture_cache_deinit(draw_ctx_sdl);
88
+ lv_mem_free(draw_ctx_sdl->internals);
89
+ _lv_draw_sdl_utils_deinit();
90
+ }
91
+
92
+ SDL_Texture * lv_draw_sdl_create_screen_texture(SDL_Renderer * renderer, lv_coord_t hor, lv_coord_t ver)
93
+ {
94
+ SDL_Texture * texture = SDL_CreateTexture(renderer, LV_DRAW_SDL_TEXTURE_FORMAT, SDL_TEXTUREACCESS_TARGET, hor, ver);
95
+ SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
96
+ return texture;
97
+ }
98
+
99
+ /**********************
100
+ * STATIC FUNCTIONS
101
+ **********************/
102
+
103
+ #endif /*LV_USE_GPU_SDL*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl.h ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_sdl.h
3
+ *
4
+ */
5
+
6
+ #ifndef LV_DRAW_SDL_H
7
+ #define LV_DRAW_SDL_H
8
+
9
+
10
+ #ifdef __cplusplus
11
+ extern "C" {
12
+ #endif
13
+
14
+ /*********************
15
+ * INCLUDES
16
+ *********************/
17
+ #include "../../lv_conf_internal.h"
18
+
19
+ #if LV_USE_GPU_SDL
20
+
21
+ #include LV_GPU_SDL_INCLUDE_PATH
22
+
23
+ #include "../lv_draw.h"
24
+ #include "../../core/lv_disp.h"
25
+
26
+ /*********************
27
+ * DEFINES
28
+ *********************/
29
+
30
+ #if SDL_BYTEORDER == SDL_BIG_ENDIAN
31
+ #define LV_DRAW_SDL_TEXTURE_FORMAT SDL_PIXELFORMAT_ARGB8888
32
+ #else
33
+ #define LV_DRAW_SDL_TEXTURE_FORMAT SDL_PIXELFORMAT_RGBA8888
34
+ #endif
35
+
36
+ /**********************
37
+ * TYPEDEFS
38
+ **********************/
39
+
40
+ struct lv_draw_sdl_context_internals_t;
41
+
42
+ typedef struct {
43
+ /**
44
+ * Render for display driver
45
+ */
46
+ SDL_Renderer * renderer;
47
+ void * user_data;
48
+ } lv_draw_sdl_drv_param_t;
49
+
50
+ typedef struct {
51
+ lv_draw_ctx_t base_draw;
52
+ SDL_Renderer * renderer;
53
+ struct lv_draw_sdl_context_internals_t * internals;
54
+ } lv_draw_sdl_ctx_t;
55
+
56
+ /**********************
57
+ * GLOBAL PROTOTYPES
58
+ **********************/
59
+
60
+ void lv_draw_sdl_init_ctx(lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx);
61
+
62
+ /**
63
+ * @brief Free caches
64
+ *
65
+ */
66
+ void lv_draw_sdl_deinit_ctx(lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx);
67
+
68
+ SDL_Texture * lv_draw_sdl_create_screen_texture(SDL_Renderer * renderer, lv_coord_t hor, lv_coord_t ver);
69
+
70
+ /*======================
71
+ * Add/remove functions
72
+ *=====================*/
73
+
74
+ /*=====================
75
+ * Setter functions
76
+ *====================*/
77
+
78
+ /*=====================
79
+ * Getter functions
80
+ *====================*/
81
+
82
+ /*=====================
83
+ * Other functions
84
+ *====================*/
85
+
86
+ /**********************
87
+ * MACROS
88
+ **********************/
89
+
90
+ #endif /*LV_USE_GPU_SDL*/
91
+
92
+ #ifdef __cplusplus
93
+ } /*extern "C"*/
94
+ #endif
95
+
96
+ #endif /*LV_DRAW_SDL_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_arc.c ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_sdl_arc.c
3
+ *
4
+ */
5
+
6
+ /*********************
7
+ * INCLUDES
8
+ *********************/
9
+ #include "../../lv_conf_internal.h"
10
+
11
+ #if LV_USE_GPU_SDL
12
+
13
+ #include "lv_draw_sdl.h"
14
+ #include "lv_draw_sdl_utils.h"
15
+ #include "lv_draw_sdl_texture_cache.h"
16
+ #include "lv_draw_sdl_composite.h"
17
+
18
+ /*********************
19
+ * DEFINES
20
+ *********************/
21
+
22
+ /**********************
23
+ * TYPEDEFS
24
+ **********************/
25
+
26
+ /**********************
27
+ * STATIC PROTOTYPES
28
+ **********************/
29
+
30
+ /**********************
31
+ * STATIC VARIABLES
32
+ **********************/
33
+
34
+ /**********************
35
+ * MACROS
36
+ **********************/
37
+
38
+ static void dump_masks(SDL_Texture * texture, const lv_area_t * coords, const int16_t * ids, int16_t ids_count,
39
+ const int16_t * caps);
40
+
41
+ static void get_cap_area(int16_t angle, lv_coord_t thickness, uint16_t radius, const lv_point_t * center,
42
+ lv_area_t * out);
43
+
44
+ /**********************
45
+ * GLOBAL FUNCTIONS
46
+ **********************/
47
+ void lv_draw_sdl_draw_arc(lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * dsc, const lv_point_t * center,
48
+ uint16_t radius, uint16_t start_angle, uint16_t end_angle)
49
+ {
50
+ lv_draw_sdl_ctx_t * ctx = (lv_draw_sdl_ctx_t *) draw_ctx;
51
+
52
+ lv_area_t area_out;
53
+ area_out.x1 = center->x - radius;
54
+ area_out.y1 = center->y - radius;
55
+ area_out.x2 = center->x + radius - 1; /*-1 because the center already belongs to the left/bottom part*/
56
+ area_out.y2 = center->y + radius - 1;
57
+
58
+ lv_area_t draw_area;
59
+ if(!_lv_area_intersect(&draw_area, &area_out, draw_ctx->clip_area)) {
60
+ return;
61
+ }
62
+
63
+ lv_area_t area_in;
64
+ lv_area_copy(&area_in, &area_out);
65
+ area_in.x1 += dsc->width;
66
+ area_in.y1 += dsc->width;
67
+ area_in.x2 -= dsc->width;
68
+ area_in.y2 -= dsc->width;
69
+
70
+
71
+ while(start_angle >= 360) start_angle -= 360;
72
+ while(end_angle >= 360) end_angle -= 360;
73
+
74
+ int16_t mask_ids[3] = {LV_MASK_ID_INV, LV_MASK_ID_INV, LV_MASK_ID_INV}, mask_ids_count = 1;
75
+ int16_t cap_ids[2] = {LV_MASK_ID_INV, LV_MASK_ID_INV};
76
+
77
+ lv_draw_mask_radius_param_t mask_out_param;
78
+ lv_draw_mask_radius_init(&mask_out_param, &area_out, LV_RADIUS_CIRCLE, false);
79
+ mask_ids[0] = lv_draw_mask_add(&mask_out_param, NULL);
80
+
81
+ lv_draw_mask_radius_param_t mask_in_param;
82
+ if(lv_area_get_width(&area_in) > 0 && lv_area_get_height(&area_in) > 0) {
83
+ lv_draw_mask_radius_init(&mask_in_param, &area_in, LV_RADIUS_CIRCLE, true);
84
+ mask_ids[1] = lv_draw_mask_add(&mask_in_param, NULL);
85
+ mask_ids_count++;
86
+ }
87
+
88
+ lv_draw_mask_angle_param_t mask_angle_param;
89
+ if((start_angle - end_angle) % 360) {
90
+ lv_draw_mask_angle_init(&mask_angle_param, center->x, center->y, start_angle, end_angle);
91
+ mask_ids[2] = lv_draw_mask_add(&mask_angle_param, NULL);
92
+ mask_ids_count++;
93
+ }
94
+
95
+ lv_draw_mask_radius_param_t cap_start_param, cap_end_param;
96
+ if(mask_ids_count == 3 && dsc->rounded) {
97
+ lv_area_t start_area, end_area;
98
+ get_cap_area((int16_t) start_angle, dsc->width, radius, center, &start_area);
99
+ get_cap_area((int16_t) end_angle, dsc->width, radius, center, &end_area);
100
+ lv_draw_mask_radius_init(&cap_start_param, &start_area, dsc->width / 2, false);
101
+ cap_ids[0] = lv_draw_mask_add(&cap_start_param, NULL);
102
+ lv_draw_mask_radius_init(&cap_end_param, &end_area, dsc->width / 2, false);
103
+ cap_ids[1] = lv_draw_mask_add(&cap_end_param, NULL);
104
+ }
105
+
106
+ lv_coord_t w = lv_area_get_width(&draw_area), h = lv_area_get_height(&draw_area);
107
+ bool texture_cached = false;
108
+ SDL_Texture * texture = lv_draw_sdl_composite_texture_obtain(ctx, LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_STREAM1, w, h,
109
+ &texture_cached);
110
+ SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
111
+ dump_masks(texture, &draw_area, mask_ids, mask_ids_count, cap_ids[0] != LV_MASK_ID_INV ? cap_ids : NULL);
112
+
113
+ lv_draw_mask_remove_id(mask_ids[0]);
114
+ lv_draw_mask_free_param(&mask_out_param);
115
+
116
+ if(mask_ids_count > 1) {
117
+ lv_draw_mask_remove_id(mask_ids[1]);
118
+ lv_draw_mask_free_param(&mask_in_param);
119
+ }
120
+
121
+ if(mask_ids_count > 2) {
122
+ lv_draw_mask_remove_id(mask_ids[2]);
123
+ lv_draw_mask_free_param(&mask_angle_param);
124
+ }
125
+
126
+ if(cap_ids[0] != LV_MASK_ID_INV) {
127
+ lv_draw_mask_remove_id(cap_ids[0]);
128
+ lv_draw_mask_remove_id(cap_ids[1]);
129
+ lv_draw_mask_free_param(&cap_start_param);
130
+ lv_draw_mask_free_param(&cap_end_param);
131
+ }
132
+
133
+ SDL_Rect srcrect = {0, 0, w, h}, dstrect;
134
+ lv_area_to_sdl_rect(&draw_area, &dstrect);
135
+ SDL_Color color;
136
+ lv_color_to_sdl_color(&dsc->color, &color);
137
+ SDL_SetTextureColorMod(texture, color.r, color.g, color.b);
138
+ SDL_SetTextureAlphaMod(texture, dsc->opa);
139
+ SDL_RenderCopy(ctx->renderer, texture, &srcrect, &dstrect);
140
+
141
+ if(!texture_cached) {
142
+ LV_LOG_WARN("Texture is not cached, this will impact performance.");
143
+ SDL_DestroyTexture(texture);
144
+ }
145
+ }
146
+
147
+ /**********************
148
+ * STATIC FUNCTIONS
149
+ **********************/
150
+
151
+ static void dump_masks(SDL_Texture * texture, const lv_area_t * coords, const int16_t * ids, int16_t ids_count,
152
+ const int16_t * caps)
153
+ {
154
+ lv_coord_t w = lv_area_get_width(coords), h = lv_area_get_height(coords);
155
+ SDL_assert(w > 0 && h > 0);
156
+ SDL_Rect rect = {0, 0, w, h};
157
+ uint8_t * pixels;
158
+ int pitch;
159
+ if(SDL_LockTexture(texture, &rect, (void **) &pixels, &pitch) != 0) return;
160
+
161
+ lv_opa_t * line_buf = lv_mem_buf_get(rect.w);
162
+ for(lv_coord_t y = 0; y < rect.h; y++) {
163
+ lv_memset_ff(line_buf, rect.w);
164
+ lv_coord_t abs_x = (lv_coord_t) coords->x1, abs_y = (lv_coord_t)(y + coords->y1), len = (lv_coord_t) rect.w;
165
+ lv_draw_mask_res_t res;
166
+ res = lv_draw_mask_apply_ids(line_buf, abs_x, abs_y, len, ids, ids_count);
167
+ if(res == LV_DRAW_MASK_RES_TRANSP) {
168
+ lv_memset_00(&pixels[y * pitch], 4 * rect.w);
169
+ }
170
+ else if(res == LV_DRAW_MASK_RES_FULL_COVER) {
171
+ lv_memset_ff(&pixels[y * pitch], 4 * rect.w);
172
+ }
173
+ else {
174
+ for(int x = 0; x < rect.w; x++) {
175
+ uint8_t * pixel = &pixels[y * pitch + x * 4];
176
+ *pixel = line_buf[x];
177
+ pixel[1] = pixel[2] = pixel[3] = 0xFF;
178
+ }
179
+ }
180
+ if(caps) {
181
+ for(int i = 0; i < 2; i++) {
182
+ lv_memset_ff(line_buf, rect.w);
183
+ res = lv_draw_mask_apply_ids(line_buf, abs_x, abs_y, len, &caps[i], 1);
184
+ if(res == LV_DRAW_MASK_RES_TRANSP) {
185
+ /* Ignore */
186
+ }
187
+ else if(res == LV_DRAW_MASK_RES_FULL_COVER) {
188
+ lv_memset_ff(&pixels[y * pitch], 4 * rect.w);
189
+ }
190
+ else {
191
+ for(int x = 0; x < rect.w; x++) {
192
+ uint8_t * pixel = &pixels[y * pitch + x * 4];
193
+ uint16_t old_opa = line_buf[x] + *pixel;
194
+ *pixel = LV_MIN(old_opa, 0xFF);
195
+ pixel[1] = pixel[2] = pixel[3] = 0xFF;
196
+ }
197
+ }
198
+ }
199
+ }
200
+ }
201
+ lv_mem_buf_release(line_buf);
202
+ SDL_UnlockTexture(texture);
203
+ }
204
+
205
+ static void get_cap_area(int16_t angle, lv_coord_t thickness, uint16_t radius, const lv_point_t * center,
206
+ lv_area_t * out)
207
+ {
208
+ const uint8_t ps = 8;
209
+ const uint8_t pa = 127;
210
+
211
+ int32_t thick_half = thickness / 2;
212
+ uint8_t thick_corr = (thickness & 0x01) ? 0 : 1;
213
+
214
+ int32_t cir_x;
215
+ int32_t cir_y;
216
+
217
+ cir_x = ((radius - thick_half) * lv_trigo_sin((int16_t)(90 - angle))) >> (LV_TRIGO_SHIFT - ps);
218
+ cir_y = ((radius - thick_half) * lv_trigo_sin(angle)) >> (LV_TRIGO_SHIFT - ps);
219
+
220
+ /*Actually the center of the pixel need to be calculated so apply 1/2 px offset*/
221
+ if(cir_x > 0) {
222
+ cir_x = (cir_x - pa) >> ps;
223
+ out->x1 = cir_x - thick_half + thick_corr;
224
+ out->x2 = cir_x + thick_half;
225
+ }
226
+ else {
227
+ cir_x = (cir_x + pa) >> ps;
228
+ out->x1 = cir_x - thick_half;
229
+ out->x2 = cir_x + thick_half - thick_corr;
230
+ }
231
+
232
+ if(cir_y > 0) {
233
+ cir_y = (cir_y - pa) >> ps;
234
+ out->y1 = cir_y - thick_half + thick_corr;
235
+ out->y2 = cir_y + thick_half;
236
+ }
237
+ else {
238
+ cir_y = (cir_y + pa) >> ps;
239
+ out->y1 = cir_y - thick_half;
240
+ out->y2 = cir_y + thick_half - thick_corr;
241
+ }
242
+ lv_area_move(out, center->x, center->y);
243
+ }
244
+
245
+ #endif /*LV_USE_GPU_SDL*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_bg.c ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_sdl_bg.c
3
+ *
4
+ */
5
+
6
+ /*********************
7
+ * INCLUDES
8
+ *********************/
9
+
10
+ #include "../../lv_conf_internal.h"
11
+
12
+ #if LV_USE_GPU_SDL
13
+
14
+ #include "../lv_draw_rect.h"
15
+ #include "../lv_draw_img.h"
16
+ #include "../lv_draw_label.h"
17
+ #include "../lv_draw_mask.h"
18
+ #include "../../core/lv_refr.h"
19
+ #include "lv_draw_sdl_utils.h"
20
+ #include "lv_draw_sdl_texture_cache.h"
21
+ #include "lv_draw_sdl_composite.h"
22
+
23
+ /*********************
24
+ * DEFINES
25
+ *********************/
26
+
27
+ /**********************
28
+ * TYPEDEFS
29
+ **********************/
30
+
31
+ /**********************
32
+ * STATIC PROTOTYPES
33
+ **********************/
34
+
35
+ static void draw_bg_color(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const lv_area_t * draw_area,
36
+ const lv_draw_rect_dsc_t * dsc);
37
+
38
+ static void draw_bg_img(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const lv_area_t * draw_area,
39
+ const lv_draw_rect_dsc_t * dsc);
40
+
41
+ /**********************
42
+ * STATIC VARIABLES
43
+ **********************/
44
+
45
+ /**********************
46
+ * MACROS
47
+ **********************/
48
+
49
+ /**********************
50
+ * GLOBAL FUNCTIONS
51
+ **********************/
52
+
53
+ void lv_draw_sdl_draw_bg(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords)
54
+ {
55
+ const lv_area_t * clip = draw_ctx->clip_area;
56
+ lv_draw_sdl_ctx_t * ctx = (lv_draw_sdl_ctx_t *) draw_ctx;
57
+ /* Coords will be translated so coords will start at (0,0) */
58
+ lv_area_t t_area;
59
+ bool has_content = _lv_area_intersect(&t_area, coords, clip);
60
+
61
+ /* Shadows and outlines will also draw in extended area */
62
+ if(has_content) {
63
+ if(dsc->bg_img_src) {
64
+ draw_bg_img(ctx, coords, &t_area, dsc);
65
+ }
66
+ else {
67
+ draw_bg_color(ctx, coords, &t_area, dsc);
68
+ }
69
+ }
70
+
71
+ }
72
+
73
+ /**********************
74
+ * STATIC FUNCTIONS
75
+ **********************/
76
+
77
+ static void draw_bg_color(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const lv_area_t * draw_area,
78
+ const lv_draw_rect_dsc_t * dsc)
79
+ {
80
+ SDL_Color bg_color;
81
+ lv_color_to_sdl_color(&dsc->bg_color, &bg_color);
82
+ SDL_SetRenderDrawBlendMode(ctx->renderer, SDL_BLENDMODE_NONE);
83
+ SDL_SetRenderDrawColor(ctx->renderer, bg_color.r, bg_color.g, bg_color.b, dsc->bg_opa);
84
+
85
+ SDL_Rect rect;
86
+ lv_area_to_sdl_rect(draw_area, &rect);
87
+ SDL_RenderFillRect(ctx->renderer, &rect);
88
+
89
+ SDL_SetRenderDrawBlendMode(ctx->renderer, SDL_BLENDMODE_BLEND);
90
+ }
91
+
92
+ static void draw_bg_img(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const lv_area_t * draw_area,
93
+ const lv_draw_rect_dsc_t * dsc)
94
+ {
95
+ SDL_SetRenderDrawBlendMode(ctx->renderer, SDL_BLENDMODE_NONE);
96
+ SDL_SetRenderDrawColor(ctx->renderer, 0, 0, 0, 0);
97
+
98
+ SDL_Rect rect;
99
+ lv_area_to_sdl_rect(draw_area, &rect);
100
+ SDL_RenderFillRect(ctx->renderer, &rect);
101
+
102
+ SDL_SetRenderDrawBlendMode(ctx->renderer, SDL_BLENDMODE_BLEND);
103
+ lv_draw_rect((lv_draw_ctx_t *) ctx, dsc, coords);
104
+ }
105
+
106
+ #endif /*LV_USE_GPU_SDL*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_composite.c ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_sdl_composite.c
3
+ *
4
+ */
5
+
6
+ /*********************
7
+ * INCLUDES
8
+ *********************/
9
+ #include "../../lv_conf_internal.h"
10
+
11
+ #if LV_USE_GPU_SDL
12
+
13
+ #include "../../misc/lv_gc.h"
14
+ #include "../../core/lv_refr.h"
15
+ #include "lv_draw_sdl_composite.h"
16
+ #include "lv_draw_sdl_utils.h"
17
+ #include "lv_draw_sdl_priv.h"
18
+ #include "lv_draw_sdl_texture_cache.h"
19
+
20
+ /*********************
21
+ * DEFINES
22
+ *********************/
23
+
24
+ /**********************
25
+ * TYPEDEFS
26
+ **********************/
27
+
28
+ typedef struct {
29
+ lv_sdl_cache_key_magic_t magic;
30
+ lv_draw_sdl_composite_texture_id_t type;
31
+ } composite_key_t;
32
+
33
+ /**********************
34
+ * STATIC PROTOTYPES
35
+ **********************/
36
+
37
+ static composite_key_t mask_key_create(lv_draw_sdl_composite_texture_id_t type);
38
+
39
+ static lv_coord_t next_pow_of_2(lv_coord_t num);
40
+
41
+ static void dump_masks(SDL_Texture * texture, const lv_area_t * coords);
42
+ /**********************
43
+ * STATIC VARIABLES
44
+ **********************/
45
+
46
+ /**********************
47
+ * MACROS
48
+ **********************/
49
+
50
+ /**********************
51
+ * GLOBAL FUNCTIONS
52
+ **********************/
53
+
54
+ bool lv_draw_sdl_composite_begin(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords_in, const lv_area_t * clip_in,
55
+ const lv_area_t * extension, lv_blend_mode_t blend_mode, lv_area_t * coords_out,
56
+ lv_area_t * clip_out, lv_area_t * apply_area)
57
+ {
58
+ lv_area_t full_coords = *coords_in;
59
+
60
+ /* Normalize full_coords */
61
+ if(full_coords.x1 > full_coords.x2) {
62
+ lv_coord_t x2 = full_coords.x2;
63
+ full_coords.x2 = full_coords.x1;
64
+ full_coords.x1 = x2;
65
+ }
66
+ if(full_coords.y1 > full_coords.y2) {
67
+ lv_coord_t y2 = full_coords.y2;
68
+ full_coords.y2 = full_coords.y1;
69
+ full_coords.y1 = y2;
70
+ }
71
+
72
+ if(extension) {
73
+ full_coords.x1 -= extension->x1;
74
+ full_coords.x2 += extension->x2;
75
+ full_coords.y1 -= extension->y1;
76
+ full_coords.y2 += extension->y2;
77
+ }
78
+
79
+ if(!_lv_area_intersect(apply_area, &full_coords, clip_in)) return false;
80
+ bool has_mask = lv_draw_mask_is_any(apply_area);
81
+
82
+ const bool draw_mask = has_mask && LV_GPU_SDL_CUSTOM_BLEND_MODE;
83
+ const bool draw_blend = blend_mode != LV_BLEND_MODE_NORMAL;
84
+ if(draw_mask || draw_blend) {
85
+ lv_draw_sdl_context_internals_t * internals = ctx->internals;
86
+ LV_ASSERT(internals->mask == NULL && internals->composition == NULL && internals->target_backup == NULL);
87
+
88
+ lv_coord_t w = lv_area_get_width(apply_area), h = lv_area_get_height(apply_area);
89
+ internals->composition = lv_draw_sdl_composite_texture_obtain(ctx, LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TARGET0, w, h,
90
+ &internals->composition_cached);
91
+ /* Don't need to worry about integral overflow */
92
+ lv_coord_t ofs_x = (lv_coord_t) - apply_area->x1, ofs_y = (lv_coord_t) - apply_area->y1;
93
+ /* Offset draw area to start with (0,0) of coords */
94
+ lv_area_move(coords_out, ofs_x, ofs_y);
95
+ lv_area_move(clip_out, ofs_x, ofs_y);
96
+ internals->target_backup = SDL_GetRenderTarget(ctx->renderer);
97
+ SDL_SetRenderTarget(ctx->renderer, internals->composition);
98
+ SDL_SetRenderDrawColor(ctx->renderer, 255, 255, 255, 0);
99
+ /* SDL_RenderClear is not working properly, so we overwrite the target with solid color */
100
+ SDL_SetRenderDrawBlendMode(ctx->renderer, SDL_BLENDMODE_NONE);
101
+ SDL_RenderFillRect(ctx->renderer, NULL);
102
+ SDL_SetRenderDrawBlendMode(ctx->renderer, SDL_BLENDMODE_BLEND);
103
+ #if LV_GPU_SDL_CUSTOM_BLEND_MODE
104
+ internals->mask = lv_draw_sdl_composite_texture_obtain(ctx, LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_STREAM0, w, h,
105
+ &internals->composition_cached);
106
+ dump_masks(internals->mask, apply_area);
107
+ #endif
108
+ }
109
+ else if(has_mask) {
110
+ /* Fallback mask handling. This will at least make bars looks less bad */
111
+ for(uint8_t i = 0; i < _LV_MASK_MAX_NUM; i++) {
112
+ _lv_draw_mask_common_dsc_t * comm_param = LV_GC_ROOT(_lv_draw_mask_list[i]).param;
113
+ if(comm_param == NULL) continue;
114
+ switch(comm_param->type) {
115
+ case LV_DRAW_MASK_TYPE_RADIUS: {
116
+ const lv_draw_mask_radius_param_t * param = (const lv_draw_mask_radius_param_t *) comm_param;
117
+ if(param->cfg.outer) break;
118
+ _lv_area_intersect(clip_out, apply_area, &param->cfg.rect);
119
+ break;
120
+ }
121
+ default:
122
+ break;
123
+ }
124
+ }
125
+ }
126
+ return has_mask;
127
+ }
128
+
129
+ void lv_draw_sdl_composite_end(lv_draw_sdl_ctx_t * ctx, const lv_area_t * apply_area, lv_blend_mode_t blend_mode)
130
+ {
131
+ lv_draw_sdl_context_internals_t * internals = ctx->internals;
132
+ SDL_Rect src_rect = {0, 0, lv_area_get_width(apply_area), lv_area_get_height(apply_area)};
133
+ #if LV_GPU_SDL_CUSTOM_BLEND_MODE
134
+ if(internals->mask) {
135
+ SDL_BlendMode mode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE,
136
+ SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ZERO,
137
+ SDL_BLENDFACTOR_SRC_ALPHA, SDL_BLENDOPERATION_ADD);
138
+ SDL_SetTextureBlendMode(internals->mask, mode);
139
+ SDL_RenderCopy(ctx->renderer, internals->mask, &src_rect, &src_rect);
140
+ }
141
+ #endif
142
+
143
+ /* Shapes are drawn on composite layer when mask or blend mode is present */
144
+ if(internals->composition) {
145
+ SDL_Rect dst_rect;
146
+ lv_area_to_sdl_rect(apply_area, &dst_rect);
147
+
148
+ SDL_SetRenderTarget(ctx->renderer, internals->target_backup);
149
+ switch(blend_mode) {
150
+ case LV_BLEND_MODE_NORMAL:
151
+ SDL_SetTextureBlendMode(internals->composition, SDL_BLENDMODE_BLEND);
152
+ break;
153
+ case LV_BLEND_MODE_ADDITIVE:
154
+ SDL_SetTextureBlendMode(internals->composition, SDL_BLENDMODE_ADD);
155
+ break;
156
+ #if LV_GPU_SDL_CUSTOM_BLEND_MODE
157
+ case LV_BLEND_MODE_SUBTRACTIVE: {
158
+ SDL_BlendMode mode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE,
159
+ SDL_BLENDOPERATION_SUBTRACT, SDL_BLENDFACTOR_ONE,
160
+ SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_SUBTRACT);
161
+ SDL_SetTextureBlendMode(internals->composition, mode);
162
+ break;
163
+ }
164
+ case LV_BLEND_MODE_MULTIPLY: {
165
+ SDL_BlendMode mode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_SRC_COLOR,
166
+ SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ZERO,
167
+ SDL_BLENDFACTOR_DST_ALPHA, SDL_BLENDOPERATION_ADD);
168
+ SDL_SetTextureBlendMode(internals->composition, mode);
169
+ break;
170
+ }
171
+ #endif
172
+ default:
173
+ LV_LOG_WARN("Doesn't support blend mode %d", blend_mode);
174
+ SDL_SetTextureBlendMode(internals->composition, SDL_BLENDMODE_BLEND);
175
+ /* Unsupported yet */
176
+ break;
177
+ }
178
+ SDL_RenderCopy(ctx->renderer, internals->composition, &src_rect, &dst_rect);
179
+ if(!internals->composition_cached) {
180
+ LV_LOG_WARN("Texture is not cached, this will impact performance.");
181
+ SDL_DestroyTexture(internals->composition);
182
+ }
183
+ }
184
+
185
+ internals->mask = internals->composition = internals->target_backup = NULL;
186
+ }
187
+
188
+ SDL_Texture * lv_draw_sdl_composite_texture_obtain(lv_draw_sdl_ctx_t * ctx, lv_draw_sdl_composite_texture_id_t id,
189
+ lv_coord_t w, lv_coord_t h, bool * texture_in_cache)
190
+ {
191
+ lv_point_t * tex_size = NULL;
192
+ composite_key_t mask_key = mask_key_create(id);
193
+ SDL_Texture * result = lv_draw_sdl_texture_cache_get_with_userdata(ctx, &mask_key, sizeof(composite_key_t), NULL,
194
+ (void **) &tex_size);
195
+ if(result == NULL || tex_size->x < w || tex_size->y < h) {
196
+ lv_coord_t size = next_pow_of_2(LV_MAX(w, h));
197
+ int access = SDL_TEXTUREACCESS_STREAMING;
198
+ if(id >= LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TRANSFORM0) {
199
+ access = SDL_TEXTUREACCESS_TARGET;
200
+ }
201
+ else if(id >= LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TARGET0) {
202
+ access = SDL_TEXTUREACCESS_TARGET;
203
+ }
204
+ result = SDL_CreateTexture(ctx->renderer, LV_DRAW_SDL_TEXTURE_FORMAT, access, size, size);
205
+ tex_size = lv_mem_alloc(sizeof(lv_point_t));
206
+ tex_size->x = tex_size->y = size;
207
+ bool in_cache = lv_draw_sdl_texture_cache_put_advanced(ctx, &mask_key, sizeof(composite_key_t), result,
208
+ tex_size, lv_mem_free, 0);
209
+ if(!in_cache) {
210
+ lv_mem_free(tex_size);
211
+ }
212
+ if(texture_in_cache != NULL) {
213
+ *texture_in_cache = in_cache;
214
+ }
215
+ }
216
+ else if(texture_in_cache != NULL) {
217
+ *texture_in_cache = true;
218
+ }
219
+
220
+ return result;
221
+ }
222
+
223
+ /**********************
224
+ * STATIC FUNCTIONS
225
+ **********************/
226
+
227
+ static composite_key_t mask_key_create(lv_draw_sdl_composite_texture_id_t type)
228
+ {
229
+ composite_key_t key;
230
+ /* VERY IMPORTANT! Padding between members is uninitialized, so we have to wipe them manually */
231
+ SDL_memset(&key, 0, sizeof(key));
232
+ key.magic = LV_GPU_CACHE_KEY_MAGIC_MASK;
233
+ key.type = type;
234
+ return key;
235
+ }
236
+
237
+ static lv_coord_t next_pow_of_2(lv_coord_t num)
238
+ {
239
+ lv_coord_t n = 128;
240
+ while(n < num && n < 16384) {
241
+ n = n << 1;
242
+ }
243
+ return n;
244
+ }
245
+
246
+ static void dump_masks(SDL_Texture * texture, const lv_area_t * coords)
247
+ {
248
+ lv_coord_t w = lv_area_get_width(coords), h = lv_area_get_height(coords);
249
+ SDL_assert(w > 0 && h > 0);
250
+ SDL_Rect rect = {0, 0, w, h};
251
+ uint8_t * pixels;
252
+ int pitch;
253
+ if(SDL_LockTexture(texture, &rect, (void **) &pixels, &pitch) != 0) return;
254
+
255
+ lv_opa_t * line_buf = lv_mem_buf_get(rect.w);
256
+ for(lv_coord_t y = 0; y < rect.h; y++) {
257
+ lv_memset_ff(line_buf, rect.w);
258
+ lv_coord_t abs_x = (lv_coord_t) coords->x1, abs_y = (lv_coord_t)(y + coords->y1), len = (lv_coord_t) rect.w;
259
+ lv_draw_mask_res_t res;
260
+ res = lv_draw_mask_apply(line_buf, abs_x, abs_y, len);
261
+ if(res == LV_DRAW_MASK_RES_TRANSP) {
262
+ lv_memset_00(&pixels[y * pitch], 4 * rect.w);
263
+ }
264
+ else if(res == LV_DRAW_MASK_RES_FULL_COVER) {
265
+ lv_memset_ff(&pixels[y * pitch], 4 * rect.w);
266
+ }
267
+ else {
268
+ for(int x = 0; x < rect.w; x++) {
269
+ const size_t idx = y * pitch + x * 4;
270
+ pixels[idx] = line_buf[x];
271
+ pixels[idx + 1] = pixels[idx + 2] = pixels[idx + 3] = 0xFF;
272
+ }
273
+ }
274
+ }
275
+ lv_mem_buf_release(line_buf);
276
+ SDL_UnlockTexture(texture);
277
+ }
278
+
279
+ #endif /*LV_USE_GPU_SDL*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_composite.h ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_sdl_composite.h
3
+ *
4
+ */
5
+
6
+ #ifndef LV_DRAW_SDL_COMPOSITE_H
7
+ #define LV_DRAW_SDL_COMPOSITE_H
8
+
9
+ #ifdef __cplusplus
10
+ extern "C" {
11
+ #endif
12
+
13
+ /*********************
14
+ * INCLUDES
15
+ *********************/
16
+
17
+ #include "../../lv_conf_internal.h"
18
+
19
+ #include LV_GPU_SDL_INCLUDE_PATH
20
+
21
+ #include "lv_draw_sdl.h"
22
+ #include "../../misc/lv_area.h"
23
+ #include "../../misc/lv_color.h"
24
+
25
+ /*********************
26
+ * DEFINES
27
+ *********************/
28
+
29
+ /**********************
30
+ * TYPEDEFS
31
+ **********************/
32
+
33
+ typedef enum lv_draw_sdl_composite_texture_id_t {
34
+ LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_STREAM0,
35
+ LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_STREAM1,
36
+ LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TARGET0,
37
+ LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TARGET1,
38
+ LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TRANSFORM0,
39
+ } lv_draw_sdl_composite_texture_id_t;
40
+
41
+ /**********************
42
+ * GLOBAL PROTOTYPES
43
+ **********************/
44
+
45
+ /**
46
+ * Begin drawing with mask. Render target will be switched to a temporary texture,
47
+ * and drawing coordinates may get clipped or translated
48
+ * @param ctx Drawing context
49
+ * @param coords_in Original coordinates
50
+ * @param clip_in Original clip area
51
+ * @param extension Useful for shadows or outlines, can be NULL
52
+ * @param coords_out Translated coords
53
+ * @param clip_out Translated clip area
54
+ * @param apply_area Area of actual composited texture will be drawn
55
+ * @return true if there are any mask needs to be drawn, false otherwise
56
+ */
57
+ bool lv_draw_sdl_composite_begin(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords_in, const lv_area_t * clip_in,
58
+ const lv_area_t * extension, lv_blend_mode_t blend_mode, lv_area_t * coords_out,
59
+ lv_area_t * clip_out, lv_area_t * apply_area);
60
+
61
+ void lv_draw_sdl_composite_end(lv_draw_sdl_ctx_t * ctx, const lv_area_t * apply_area, lv_blend_mode_t blend_mode);
62
+
63
+ /**
64
+ *
65
+ * @param ctx Drawing context
66
+ * @param id Texture ID
67
+ * @param w Maximum width needed
68
+ * @param h Maximum height needed
69
+ * @param texture_in_cache output to query if the texture is in cache. If it's not in cache, you'll need to destroy it
70
+ * by yourself
71
+ * @return Obtained texture
72
+ */
73
+ SDL_Texture * lv_draw_sdl_composite_texture_obtain(lv_draw_sdl_ctx_t * ctx, lv_draw_sdl_composite_texture_id_t id,
74
+ lv_coord_t w, lv_coord_t h, bool * texture_in_cache);
75
+
76
+ /**********************
77
+ * MACROS
78
+ **********************/
79
+
80
+ #ifdef __cplusplus
81
+ } /*extern "C"*/
82
+ #endif
83
+
84
+ #endif /*LV_DRAW_SDL_COMPOSITE_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_img.c ADDED
@@ -0,0 +1,499 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_sdl_img.c
3
+ *
4
+ */
5
+
6
+ /*********************
7
+ * INCLUDES
8
+ *********************/
9
+
10
+ #include "../../lv_conf_internal.h"
11
+
12
+ #if LV_USE_GPU_SDL
13
+
14
+ #include "../lv_draw_img.h"
15
+ #include "../lv_img_cache.h"
16
+ #include "../lv_draw_mask.h"
17
+ #include "../../misc/lv_lru.h"
18
+ #include "../../misc/lv_gc.h"
19
+
20
+ #include "lv_draw_sdl_img.h"
21
+ #include "lv_draw_sdl_utils.h"
22
+ #include "lv_draw_sdl_texture_cache.h"
23
+ #include "lv_draw_sdl_composite.h"
24
+ #include "lv_draw_sdl_rect.h"
25
+ #include "lv_draw_sdl_layer.h"
26
+
27
+ /*********************
28
+ * DEFINES
29
+ *********************/
30
+
31
+ /**********************
32
+ * TYPEDEFS
33
+ **********************/
34
+
35
+ typedef struct {
36
+ lv_sdl_cache_key_magic_t magic;
37
+ const SDL_Texture * texture;
38
+ lv_coord_t w, h, radius;
39
+ } lv_draw_img_rounded_key_t;
40
+
41
+ enum {
42
+ ROUNDED_IMG_PART_LEFT = 0,
43
+ ROUNDED_IMG_PART_HCENTER = 1,
44
+ ROUNDED_IMG_PART_RIGHT = 2,
45
+ ROUNDED_IMG_PART_TOP = 3,
46
+ ROUNDED_IMG_PART_VCENTER = 4,
47
+ ROUNDED_IMG_PART_BOTTOM = 5,
48
+ };
49
+
50
+ enum {
51
+ ROUNDED_IMG_CORNER_TOP_LEFT = 0,
52
+ ROUNDED_IMG_CORNER_TOP_RIGHT = 1,
53
+ ROUNDED_IMG_CORNER_BOTTOM_RIGHT = 2,
54
+ ROUNDED_IMG_CORNER_BOTTOM_LEFT = 3,
55
+ };
56
+
57
+ /**********************
58
+ * STATIC PROTOTYPES
59
+ **********************/
60
+
61
+ static SDL_Texture * upload_img_texture(SDL_Renderer * renderer, lv_img_decoder_dsc_t * dsc);
62
+
63
+ static SDL_Texture * upload_img_texture_fallback(SDL_Renderer * renderer, lv_img_decoder_dsc_t * dsc);
64
+
65
+ static bool check_mask_simple_radius(const lv_area_t * coords, lv_coord_t * radius);
66
+
67
+ static void draw_img_simple(lv_draw_sdl_ctx_t * ctx, SDL_Texture * texture, const lv_draw_sdl_img_header_t * header,
68
+ const lv_draw_img_dsc_t * draw_dsc, const lv_area_t * coords, const lv_area_t * clip);
69
+
70
+ static void draw_img_rounded(lv_draw_sdl_ctx_t * ctx, SDL_Texture * texture, const lv_draw_sdl_img_header_t * header,
71
+ const lv_draw_img_dsc_t * draw_dsc, const lv_area_t * coords, const lv_area_t * clip,
72
+ lv_coord_t radius);
73
+
74
+ static SDL_Texture * img_rounded_frag_obtain(lv_draw_sdl_ctx_t * ctx, SDL_Texture * texture,
75
+ const lv_draw_sdl_img_header_t * header, int w, int h, lv_coord_t radius,
76
+ bool * in_cache);
77
+
78
+ static lv_draw_img_rounded_key_t rounded_key_create(const SDL_Texture * texture, lv_coord_t w, lv_coord_t h,
79
+ lv_coord_t radius);
80
+
81
+ static void calc_draw_part(SDL_Texture * texture, const lv_draw_sdl_img_header_t * header, const lv_area_t * coords,
82
+ const lv_area_t * clip, SDL_Rect * clipped_src, SDL_Rect * clipped_dst);
83
+ /**********************
84
+ * STATIC VARIABLES
85
+ **********************/
86
+
87
+ /**********************
88
+ * MACROS
89
+ **********************/
90
+
91
+
92
+ static void apply_recolor_opa(SDL_Texture * texture, const lv_draw_img_dsc_t * draw_dsc);
93
+
94
+ /**********************
95
+ * GLOBAL FUNCTIONS
96
+ **********************/
97
+
98
+ lv_res_t lv_draw_sdl_img_core(lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * draw_dsc,
99
+ const lv_area_t * coords, const void * src)
100
+ {
101
+ const lv_area_t * clip = draw_ctx->clip_area;
102
+ lv_draw_sdl_ctx_t * ctx = (lv_draw_sdl_ctx_t *) draw_ctx;
103
+
104
+ size_t key_size;
105
+ lv_draw_sdl_cache_key_head_img_t * key = lv_draw_sdl_texture_img_key_create(src, draw_dsc->frame_id, &key_size);
106
+ bool texture_found = false;
107
+ lv_draw_sdl_img_header_t * header = NULL;
108
+ SDL_Texture * texture = lv_draw_sdl_texture_cache_get_with_userdata(ctx, key, key_size, &texture_found,
109
+ (void **) &header);
110
+ bool texture_in_cache = false;
111
+ if(!texture_found) {
112
+ lv_draw_sdl_img_load_texture(ctx, key, key_size, src, draw_dsc->frame_id, &texture, &header,
113
+ &texture_in_cache);
114
+ }
115
+ else {
116
+ texture_in_cache = true;
117
+ }
118
+ SDL_free(key);
119
+ if(!texture || !header) {
120
+ return LV_RES_INV;
121
+ }
122
+
123
+ lv_area_t zoomed_cords;
124
+ _lv_img_buf_get_transformed_area(&zoomed_cords, lv_area_get_width(coords), lv_area_get_height(coords), 0,
125
+ draw_dsc->zoom, &draw_dsc->pivot);
126
+ lv_area_move(&zoomed_cords, coords->x1, coords->y1);
127
+
128
+ /* When in > 0, draw simple radius */
129
+ lv_coord_t radius = 0;
130
+ /* Coords will be translated so coords will start at (0,0) */
131
+ lv_area_t t_coords = zoomed_cords, t_clip = *clip, apply_area;
132
+
133
+ bool has_composite = false;
134
+
135
+ if(!check_mask_simple_radius(&t_coords, &radius)) {
136
+ has_composite = lv_draw_sdl_composite_begin(ctx, &zoomed_cords, clip, NULL, draw_dsc->blend_mode,
137
+ &t_coords, &t_clip, &apply_area);
138
+ }
139
+
140
+ lv_draw_sdl_transform_areas_offset(ctx, has_composite, &apply_area, &t_coords, &t_clip);
141
+
142
+ SDL_Rect clip_rect, coords_rect;
143
+ lv_area_to_sdl_rect(&t_clip, &clip_rect);
144
+ lv_area_to_sdl_rect(&t_coords, &coords_rect);
145
+
146
+ SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
147
+
148
+ if(radius > 0) {
149
+ draw_img_rounded(ctx, texture, header, draw_dsc, &t_coords, &t_clip, radius);
150
+ }
151
+ else {
152
+ draw_img_simple(ctx, texture, header, draw_dsc, &t_coords, &t_clip);
153
+ }
154
+
155
+ lv_draw_sdl_composite_end(ctx, &apply_area, draw_dsc->blend_mode);
156
+
157
+ if(!texture_in_cache) {
158
+ LV_LOG_WARN("Texture is not cached, this will impact performance.");
159
+ if(!header->managed) {
160
+ SDL_DestroyTexture(texture);
161
+ }
162
+ lv_mem_free(header);
163
+ }
164
+
165
+ return LV_RES_OK;
166
+ }
167
+
168
+ static void calc_draw_part(SDL_Texture * texture, const lv_draw_sdl_img_header_t * header, const lv_area_t * coords,
169
+ const lv_area_t * clip, SDL_Rect * clipped_src, SDL_Rect * clipped_dst)
170
+ {
171
+ double x = 0, y = 0, w, h;
172
+ if(SDL_RectEmpty(&header->rect)) {
173
+ Uint32 format = 0;
174
+ int access = 0, tw, th;
175
+ SDL_QueryTexture(texture, &format, &access, &tw, &th);
176
+ w = tw;
177
+ h = th;
178
+ }
179
+ else {
180
+ x = header->rect.x;
181
+ y = header->rect.y;
182
+ w = header->rect.w;
183
+ h = header->rect.h;
184
+ }
185
+ if(clip) {
186
+ lv_area_t clipped_area;
187
+ _lv_area_intersect(&clipped_area, coords, clip);
188
+ lv_area_to_sdl_rect(&clipped_area, clipped_dst);
189
+ }
190
+ else {
191
+ lv_area_to_sdl_rect(coords, clipped_dst);
192
+ }
193
+ lv_coord_t coords_w = lv_area_get_width(coords), coords_h = lv_area_get_height(coords);
194
+ clipped_src->x = (int)(x + (clipped_dst->x - coords->x1) * w / coords_w);
195
+ clipped_src->y = (int)(y + (clipped_dst->y - coords->y1) * h / coords_h);
196
+ clipped_src->w = (int)(w - (coords_w - clipped_dst->w) * w / coords_w);
197
+ clipped_src->h = (int)(h - (coords_h - clipped_dst->h) * h / coords_h);
198
+ }
199
+
200
+ bool lv_draw_sdl_img_load_texture(lv_draw_sdl_ctx_t * ctx, lv_draw_sdl_cache_key_head_img_t * key, size_t key_size,
201
+ const void * src, int32_t frame_id, SDL_Texture ** texture,
202
+ lv_draw_sdl_img_header_t ** header, bool * texture_in_cache)
203
+ {
204
+ _lv_img_cache_entry_t * cdsc = _lv_img_cache_open(src, lv_color_white(), frame_id);
205
+ lv_draw_sdl_cache_flag_t tex_flags = 0;
206
+ SDL_Rect rect;
207
+ SDL_memset(&rect, 0, sizeof(SDL_Rect));
208
+ if(cdsc) {
209
+ lv_img_decoder_dsc_t * dsc = &cdsc->dec_dsc;
210
+ if(dsc->user_data && SDL_memcmp(dsc->user_data, LV_DRAW_SDL_DEC_DSC_TEXTURE_HEAD, 8) == 0) {
211
+ lv_draw_sdl_dec_dsc_userdata_t * ptr = (lv_draw_sdl_dec_dsc_userdata_t *) dsc->user_data;
212
+ *texture = ptr->texture;
213
+ rect = ptr->rect;
214
+ if(ptr->texture_managed) {
215
+ tex_flags |= LV_DRAW_SDL_CACHE_FLAG_MANAGED;
216
+ }
217
+ ptr->texture_referenced = true;
218
+ }
219
+ else {
220
+ *texture = upload_img_texture(ctx->renderer, dsc);
221
+ }
222
+ #if LV_IMG_CACHE_DEF_SIZE == 0
223
+ lv_img_decoder_close(dsc);
224
+ #endif
225
+ }
226
+ if(texture && cdsc) {
227
+ *header = lv_mem_alloc(sizeof(lv_draw_sdl_img_header_t));
228
+ SDL_memcpy(&(*header)->base, &cdsc->dec_dsc.header, sizeof(lv_img_header_t));
229
+ (*header)->rect = rect;
230
+ (*header)->managed = (tex_flags & LV_DRAW_SDL_CACHE_FLAG_MANAGED) != 0;
231
+ *texture_in_cache = lv_draw_sdl_texture_cache_put_advanced(ctx, key, key_size, *texture, *header, SDL_free,
232
+ tex_flags);
233
+ return true;
234
+ }
235
+ else {
236
+ *texture_in_cache = lv_draw_sdl_texture_cache_put(ctx, key, key_size, NULL);
237
+ return false;
238
+ }
239
+ }
240
+
241
+ /**********************
242
+ * STATIC FUNCTIONS
243
+ **********************/
244
+
245
+ static SDL_Texture * upload_img_texture(SDL_Renderer * renderer, lv_img_decoder_dsc_t * dsc)
246
+ {
247
+ if(!dsc->img_data) {
248
+ return upload_img_texture_fallback(renderer, dsc);
249
+ }
250
+ bool chroma_keyed = dsc->header.cf == (uint32_t) LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED;
251
+ int h = (int) dsc->header.h;
252
+ int w = (int) dsc->header.w;
253
+ void * data = (void *) dsc->img_data;
254
+ Uint32 rmask = 0x00FF0000;
255
+ Uint32 gmask = 0x0000FF00;
256
+ Uint32 bmask = 0x000000FF;
257
+ Uint32 amask = 0xFF000000;
258
+ if(chroma_keyed) {
259
+ amask = 0x00;
260
+ }
261
+ SDL_Surface * surface = SDL_CreateRGBSurfaceFrom(data, w, h, LV_COLOR_DEPTH, w * LV_COLOR_DEPTH / 8,
262
+ rmask, gmask, bmask, amask);
263
+ SDL_SetColorKey(surface, chroma_keyed, lv_color_to32(LV_COLOR_CHROMA_KEY));
264
+ SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
265
+ SDL_FreeSurface(surface);
266
+ return texture;
267
+ }
268
+
269
+ static SDL_Texture * upload_img_texture_fallback(SDL_Renderer * renderer, lv_img_decoder_dsc_t * dsc)
270
+ {
271
+ lv_coord_t h = (lv_coord_t) dsc->header.h;
272
+ lv_coord_t w = (lv_coord_t) dsc->header.w;
273
+ uint8_t * data = lv_mem_buf_get(w * h * sizeof(lv_color_t));
274
+ for(lv_coord_t y = 0; y < h; y++) {
275
+ lv_img_decoder_read_line(dsc, 0, y, w, &data[y * w * sizeof(lv_color_t)]);
276
+ }
277
+ Uint32 rmask = 0x00FF0000;
278
+ Uint32 gmask = 0x0000FF00;
279
+ Uint32 bmask = 0x000000FF;
280
+ Uint32 amask = 0xFF000000;
281
+ SDL_Surface * surface = SDL_CreateRGBSurfaceFrom(data, w, h, LV_COLOR_DEPTH, w * LV_COLOR_DEPTH / 8,
282
+ rmask, gmask, bmask, amask);
283
+ SDL_SetColorKey(surface, SDL_TRUE, lv_color_to32(LV_COLOR_CHROMA_KEY));
284
+ SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
285
+ SDL_FreeSurface(surface);
286
+ lv_mem_buf_release(data);
287
+ return texture;
288
+ }
289
+
290
+ /**
291
+ * Check if there is only one radius mask
292
+ * @param radius Set to radius value if the only mask is a radius mask
293
+ * @return true if the only mask is a radius mask
294
+ */
295
+ static bool check_mask_simple_radius(const lv_area_t * coords, lv_coord_t * radius)
296
+ {
297
+ if(lv_draw_mask_get_cnt() != 1) return false;
298
+ for(uint8_t i = 0; i < _LV_MASK_MAX_NUM; i++) {
299
+ _lv_draw_mask_common_dsc_t * param = LV_GC_ROOT(_lv_draw_mask_list[i]).param;
300
+ if(param->type == LV_DRAW_MASK_TYPE_RADIUS) {
301
+ lv_draw_mask_radius_param_t * rparam = (lv_draw_mask_radius_param_t *) param;
302
+ if(rparam->cfg.outer) return false;
303
+ if(!_lv_area_is_equal(&rparam->cfg.rect, coords)) return false;
304
+ *radius = rparam->cfg.radius;
305
+ return true;
306
+ }
307
+ }
308
+ return false;
309
+ }
310
+
311
+ static void draw_img_simple(lv_draw_sdl_ctx_t * ctx, SDL_Texture * texture, const lv_draw_sdl_img_header_t * header,
312
+ const lv_draw_img_dsc_t * draw_dsc, const lv_area_t * coords, const lv_area_t * clip)
313
+ {
314
+ apply_recolor_opa(texture, draw_dsc);
315
+ SDL_Point pivot = {.x = draw_dsc->pivot.x, .y = draw_dsc->pivot.y};
316
+
317
+ /*Image needs to be rotated, so we have to use clip rect which is slower*/
318
+ if(draw_dsc->angle != 0) {
319
+ /* No radius, set clip here */
320
+ SDL_Rect clip_rect;
321
+ lv_area_to_sdl_rect(clip, &clip_rect);
322
+ SDL_RenderSetClipRect(ctx->renderer, &clip_rect);
323
+ }
324
+ SDL_Rect src_rect, dst_rect;
325
+ calc_draw_part(texture, header, coords, clip, &src_rect, &dst_rect);
326
+ SDL_RenderCopyEx(ctx->renderer, texture, &src_rect, &dst_rect, draw_dsc->angle, &pivot, SDL_FLIP_NONE);
327
+ if(draw_dsc->angle != 0) {
328
+ SDL_RenderSetClipRect(ctx->renderer, NULL);
329
+ }
330
+ }
331
+
332
+
333
+ static void draw_img_rounded(lv_draw_sdl_ctx_t * ctx, SDL_Texture * texture, const lv_draw_sdl_img_header_t * header,
334
+ const lv_draw_img_dsc_t * draw_dsc, const lv_area_t * coords, const lv_area_t * clip,
335
+ lv_coord_t radius)
336
+ {
337
+ const int w = lv_area_get_width(coords), h = lv_area_get_height(coords);
338
+ lv_coord_t real_radius = LV_MIN3(radius, w, h);
339
+ bool frag_in_cache = false;
340
+ SDL_Texture * frag = img_rounded_frag_obtain(ctx, texture, header, w, h, real_radius, &frag_in_cache);
341
+ apply_recolor_opa(frag, draw_dsc);
342
+ lv_draw_sdl_rect_bg_frag_draw_corners(ctx, frag, real_radius, coords, clip, true);
343
+
344
+ apply_recolor_opa(texture, draw_dsc);
345
+
346
+ SDL_Rect src_rect, dst_rect;
347
+ /* Draw 3 parts */
348
+ lv_area_t clip_tmp, part;
349
+ calc_draw_part(texture, header, coords, NULL, &src_rect, &dst_rect);
350
+ for(int i = w > h ? ROUNDED_IMG_PART_LEFT : ROUNDED_IMG_PART_TOP, j = i + 3; i <= j; i++) {
351
+ switch(i) {
352
+ case ROUNDED_IMG_PART_LEFT:
353
+ lv_area_set(&part, coords->x1, coords->y1 + radius, coords->x1 + radius - 1, coords->y2 - radius);
354
+ break;
355
+ case ROUNDED_IMG_PART_HCENTER:
356
+ lv_area_set(&part, coords->x1 + radius, coords->y1, coords->x2 - radius, coords->y2);
357
+ break;
358
+ case ROUNDED_IMG_PART_RIGHT:
359
+ lv_area_set(&part, coords->x2 - radius + 1, coords->y1 + radius, coords->x2, coords->y2 - radius);
360
+ break;
361
+ case ROUNDED_IMG_PART_TOP:
362
+ lv_area_set(&part, coords->x1 + radius, coords->y1, coords->x2 - radius, coords->y1 + radius - 1);
363
+ break;
364
+ case ROUNDED_IMG_PART_VCENTER:
365
+ lv_area_set(&part, coords->x1 + radius, coords->y2 - radius + 1, coords->x2 - radius, coords->y2);
366
+ break;
367
+ case ROUNDED_IMG_PART_BOTTOM:
368
+ lv_area_set(&part, coords->x1, coords->y1 + radius, coords->x2, coords->y2 - radius);
369
+ break;
370
+ default:
371
+ break;
372
+ }
373
+ if(!_lv_area_intersect(&clip_tmp, &part, clip)) continue;
374
+ SDL_Rect clip_rect;
375
+ lv_area_to_sdl_rect(&clip_tmp, &clip_rect);
376
+ SDL_RenderSetClipRect(ctx->renderer, &clip_rect);
377
+ SDL_RenderCopy(ctx->renderer, texture, &src_rect, &dst_rect);
378
+ }
379
+ SDL_RenderSetClipRect(ctx->renderer, NULL);
380
+
381
+ if(!frag_in_cache) {
382
+ LV_LOG_WARN("Texture is not cached, this will impact performance.");
383
+ SDL_DestroyTexture(frag);
384
+ }
385
+ }
386
+
387
+ static void apply_recolor_opa(SDL_Texture * texture, const lv_draw_img_dsc_t * draw_dsc)
388
+ {
389
+ if(draw_dsc->recolor_opa > LV_OPA_TRANSP) {
390
+ /* Draw with mixed recolor */
391
+ lv_color_t recolor = lv_color_mix(draw_dsc->recolor, lv_color_white(), draw_dsc->recolor_opa);
392
+ SDL_SetTextureColorMod(texture, recolor.ch.red, recolor.ch.green, recolor.ch.blue);
393
+ }
394
+ else {
395
+ /* Draw with no recolor */
396
+ SDL_SetTextureColorMod(texture, 0xFF, 0xFF, 0xFF);
397
+ }
398
+ SDL_SetTextureAlphaMod(texture, draw_dsc->opa);
399
+ }
400
+
401
+ static SDL_Texture * img_rounded_frag_obtain(lv_draw_sdl_ctx_t * ctx, SDL_Texture * texture,
402
+ const lv_draw_sdl_img_header_t * header, int w, int h, lv_coord_t radius,
403
+ bool * in_cache)
404
+ {
405
+ lv_draw_img_rounded_key_t key = rounded_key_create(texture, w, h, radius);
406
+ bool mask_frag_in_cache = false;
407
+ SDL_Texture * mask_frag = lv_draw_sdl_rect_bg_frag_obtain(ctx, radius, &mask_frag_in_cache);
408
+ SDL_Texture * img_frag = lv_draw_sdl_texture_cache_get(ctx, &key, sizeof(key), NULL);
409
+ if(img_frag == NULL) {
410
+ const lv_coord_t full_frag_size = radius * 2 + 3;
411
+ img_frag = SDL_CreateTexture(ctx->renderer, LV_DRAW_SDL_TEXTURE_FORMAT, SDL_TEXTUREACCESS_TARGET,
412
+ full_frag_size, full_frag_size);
413
+ SDL_assert(img_frag);
414
+ SDL_SetTextureBlendMode(img_frag, SDL_BLENDMODE_BLEND);
415
+ SDL_Texture * old_target = SDL_GetRenderTarget(ctx->renderer);
416
+ SDL_SetRenderTarget(ctx->renderer, img_frag);
417
+ SDL_SetRenderDrawColor(ctx->renderer, 0, 0, 0, 0);
418
+ /* SDL_RenderClear is not working properly, so we overwrite the target with solid color */
419
+ SDL_SetRenderDrawBlendMode(ctx->renderer, SDL_BLENDMODE_NONE);
420
+ SDL_RenderFillRect(ctx->renderer, NULL);
421
+ SDL_SetRenderDrawBlendMode(ctx->renderer, SDL_BLENDMODE_BLEND);
422
+
423
+ lv_area_t coords = {0, 0, w - 1, h - 1};
424
+ lv_area_t frag_coords = {0, 0, full_frag_size - 1, full_frag_size - 1};
425
+ lv_draw_sdl_rect_bg_frag_draw_corners(ctx, mask_frag, radius, &frag_coords, NULL, false);
426
+
427
+ SDL_SetTextureAlphaMod(texture, 0xFF);
428
+ SDL_SetTextureColorMod(texture, 0xFF, 0xFF, 0xFF);
429
+ #if LV_GPU_SDL_CUSTOM_BLEND_MODE
430
+ SDL_BlendMode blend_mode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ZERO,
431
+ SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_DST_ALPHA,
432
+ SDL_BLENDFACTOR_ZERO, SDL_BLENDOPERATION_ADD);
433
+ SDL_SetTextureBlendMode(texture, blend_mode);
434
+ #else
435
+ SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_MOD);
436
+ #endif
437
+ SDL_Rect srcrect, cliprect, dstrect = {0, 0, radius, radius};
438
+
439
+ cliprect.w = cliprect.h = radius;
440
+ for(int i = 0; i <= ROUNDED_IMG_CORNER_BOTTOM_LEFT; i++) {
441
+ switch(i) {
442
+ case ROUNDED_IMG_CORNER_TOP_LEFT:
443
+ cliprect.x = 0;
444
+ cliprect.y = 0;
445
+ lv_area_align(&frag_coords, &coords, LV_ALIGN_TOP_LEFT, 0, 0);
446
+ break;
447
+ case ROUNDED_IMG_CORNER_TOP_RIGHT:
448
+ cliprect.x = full_frag_size - radius;
449
+ cliprect.y = 0;
450
+ lv_area_align(&frag_coords, &coords, LV_ALIGN_TOP_RIGHT, 0, 0);
451
+ break;
452
+ case ROUNDED_IMG_CORNER_BOTTOM_RIGHT:
453
+ cliprect.x = full_frag_size - radius;
454
+ cliprect.y = full_frag_size - radius;
455
+ lv_area_align(&frag_coords, &coords, LV_ALIGN_BOTTOM_RIGHT, 0, 0);
456
+ break;
457
+ case ROUNDED_IMG_CORNER_BOTTOM_LEFT:
458
+ cliprect.x = 0;
459
+ cliprect.y = full_frag_size - radius;
460
+ lv_area_align(&frag_coords, &coords, LV_ALIGN_BOTTOM_LEFT, 0, 0);
461
+ break;
462
+ default:
463
+ break;
464
+ }
465
+ calc_draw_part(texture, header, &coords, NULL, &srcrect, &dstrect);
466
+ SDL_RenderSetClipRect(ctx->renderer, &cliprect);
467
+ SDL_RenderCopy(ctx->renderer, texture, &srcrect, &dstrect);
468
+ }
469
+ SDL_RenderSetClipRect(ctx->renderer, NULL);
470
+
471
+ SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
472
+
473
+ SDL_SetRenderTarget(ctx->renderer, old_target);
474
+ *in_cache = lv_draw_sdl_texture_cache_put(ctx, &key, sizeof(key), img_frag);
475
+ }
476
+ else {
477
+ *in_cache = true;
478
+ }
479
+ if(!mask_frag_in_cache) {
480
+ LV_LOG_WARN("Texture is not cached, this will impact performance.");
481
+ SDL_DestroyTexture(mask_frag);
482
+ }
483
+ return img_frag;
484
+ }
485
+
486
+ static lv_draw_img_rounded_key_t rounded_key_create(const SDL_Texture * texture, lv_coord_t w, lv_coord_t h,
487
+ lv_coord_t radius)
488
+ {
489
+ lv_draw_img_rounded_key_t key;
490
+ SDL_memset(&key, 0, sizeof(key));
491
+ key.magic = LV_GPU_CACHE_KEY_MAGIC_IMG_ROUNDED_CORNERS;
492
+ key.texture = texture;
493
+ key.w = w;
494
+ key.h = h;
495
+ key.radius = radius;
496
+ return key;
497
+ }
498
+
499
+ #endif /*LV_USE_GPU_SDL*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_img.h ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_sdl_img.h
3
+ *
4
+ */
5
+
6
+ #ifndef LV_DRAW_SDL_IMG_H
7
+ #define LV_DRAW_SDL_IMG_H
8
+
9
+
10
+ #ifdef __cplusplus
11
+ extern "C" {
12
+ #endif
13
+
14
+ /*********************
15
+ * INCLUDES
16
+ *********************/
17
+ #include "../../lv_conf_internal.h"
18
+
19
+ #if LV_USE_GPU_SDL
20
+
21
+ #include LV_GPU_SDL_INCLUDE_PATH
22
+
23
+ #include "../lv_draw.h"
24
+
25
+ #include "lv_draw_sdl_texture_cache.h"
26
+
27
+ /*********************
28
+ * DEFINES
29
+ *********************/
30
+
31
+ /**********************
32
+ * TYPEDEFS
33
+ **********************/
34
+
35
+ typedef struct lv_draw_sdl_img_header_t {
36
+ lv_img_header_t base;
37
+ SDL_Rect rect;
38
+ bool managed;
39
+ } lv_draw_sdl_img_header_t;
40
+
41
+ /**********************
42
+ * GLOBAL PROTOTYPES
43
+ **********************/
44
+
45
+ /*======================
46
+ * Add/remove functions
47
+ *=====================*/
48
+
49
+ /*=====================
50
+ * Setter functions
51
+ *====================*/
52
+
53
+ /*=====================
54
+ * Getter functions
55
+ *====================*/
56
+
57
+ /*=====================
58
+ * Other functions
59
+ *====================*/
60
+ /**
61
+ *
62
+ * @param ctx Drawing context
63
+ * @param key Texture cache key
64
+ * @param key_size Size of texture cache key
65
+ * @param src Image source pointer
66
+ * @param frame_id Frame ID for animated image
67
+ * @param texture Texture for render
68
+ * @param header Header also holds sdl image info
69
+ * @param texture_in_cache Whether the texture has been put in the cache. Please note for managed texture,
70
+ * this will be false too. So you'll need to check header.managed too.
71
+ * @return Whether the image has been loaded successfully
72
+ */
73
+ bool lv_draw_sdl_img_load_texture(lv_draw_sdl_ctx_t * ctx, lv_draw_sdl_cache_key_head_img_t * key, size_t key_size,
74
+ const void * src, int32_t frame_id, SDL_Texture ** texture,
75
+ lv_draw_sdl_img_header_t ** header, bool * texture_in_cache);
76
+ /**********************
77
+ * MACROS
78
+ **********************/
79
+
80
+ #endif /*LV_USE_GPU_SDL*/
81
+
82
+ #ifdef __cplusplus
83
+ } /*extern "C"*/
84
+ #endif
85
+
86
+ #endif /*LV_DRAW_SDL_IMG_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_label.c ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_sdl_label.c
3
+ *
4
+ */
5
+
6
+ /*********************
7
+ * INCLUDES
8
+ *********************/
9
+
10
+ #include "../../lv_conf_internal.h"
11
+
12
+ #if LV_USE_GPU_SDL
13
+
14
+ #include LV_GPU_SDL_INCLUDE_PATH
15
+
16
+ #include "../lv_draw_label.h"
17
+ #include "../../misc/lv_utils.h"
18
+
19
+ #include "lv_draw_sdl_utils.h"
20
+ #include "lv_draw_sdl_texture_cache.h"
21
+ #include "lv_draw_sdl_composite.h"
22
+ #include "lv_draw_sdl_layer.h"
23
+
24
+ /*********************
25
+ * DEFINES
26
+ *********************/
27
+
28
+ /**********************
29
+ * TYPEDEFS
30
+ **********************/
31
+
32
+ typedef struct {
33
+ lv_sdl_cache_key_magic_t magic;
34
+ const lv_font_t * font_p;
35
+ uint32_t letter;
36
+ } lv_font_glyph_key_t;
37
+
38
+ /**********************
39
+ * STATIC PROTOTYPES
40
+ **********************/
41
+
42
+ static lv_font_glyph_key_t font_key_glyph_create(const lv_font_t * font_p, uint32_t letter);
43
+
44
+
45
+ /**********************
46
+ * STATIC VARIABLES
47
+ **********************/
48
+
49
+ /**********************
50
+ * MACROS
51
+ **********************/
52
+
53
+ /**********************
54
+ * GLOBAL FUNCTIONS
55
+ **********************/
56
+
57
+ void lv_draw_sdl_draw_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, const lv_point_t * pos_p,
58
+ uint32_t letter)
59
+ {
60
+ const lv_area_t * clip_area = draw_ctx->clip_area;
61
+ const lv_font_t * font_p = dsc->font;
62
+ lv_opa_t opa = dsc->opa;
63
+ lv_color_t color = dsc->color;
64
+ if(opa < LV_OPA_MIN) return;
65
+ if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;
66
+
67
+ if(font_p == NULL) {
68
+ LV_LOG_WARN("lv_draw_letter: font is NULL");
69
+ return;
70
+ }
71
+
72
+ lv_font_glyph_dsc_t g;
73
+ bool g_ret = lv_font_get_glyph_dsc(font_p, &g, letter, '\0');
74
+ if(g_ret == false) {
75
+ /*Add warning if the dsc is not found
76
+ *but do not print warning for non printable ASCII chars (e.g. '\n')*/
77
+ if(letter >= 0x20 &&
78
+ letter != 0xf8ff && /*LV_SYMBOL_DUMMY*/
79
+ letter != 0x200c) { /*ZERO WIDTH NON-JOINER*/
80
+ LV_LOG_WARN("lv_draw_letter: glyph dsc. not found for U+%X", letter);
81
+
82
+ /* draw placeholder */
83
+ lv_area_t glyph_coords;
84
+ lv_draw_rect_dsc_t glyph_dsc;
85
+ lv_coord_t begin_x = pos_p->x + g.ofs_x;
86
+ lv_coord_t begin_y = pos_p->y + g.ofs_y;
87
+ lv_area_set(&glyph_coords, begin_x, begin_y, begin_x + g.box_w, begin_y + g.box_h);
88
+ lv_draw_rect_dsc_init(&glyph_dsc);
89
+ glyph_dsc.bg_opa = LV_OPA_MIN;
90
+ glyph_dsc.outline_opa = LV_OPA_MIN;
91
+ glyph_dsc.shadow_opa = LV_OPA_MIN;
92
+ glyph_dsc.bg_img_opa = LV_OPA_MIN;
93
+ glyph_dsc.border_color = dsc->color;
94
+ glyph_dsc.border_width = 1;
95
+ draw_ctx->draw_rect(draw_ctx, &glyph_dsc, &glyph_coords);
96
+ }
97
+ return;
98
+ }
99
+
100
+ /*Don't draw anything if the character is empty. E.g. space*/
101
+ if((g.box_h == 0) || (g.box_w == 0)) return;
102
+
103
+ int32_t pos_x = pos_p->x + g.ofs_x;
104
+ int32_t pos_y = pos_p->y + (font_p->line_height - font_p->base_line) - g.box_h - g.ofs_y;
105
+
106
+ const lv_area_t letter_area = {pos_x, pos_y, pos_x + g.box_w - 1, pos_y + g.box_h - 1};
107
+ lv_area_t draw_area;
108
+
109
+ /*If the letter is completely out of mask don't draw it*/
110
+ if(!_lv_area_intersect(&draw_area, &letter_area, clip_area)) {
111
+ return;
112
+ }
113
+
114
+ lv_draw_sdl_ctx_t * ctx = (lv_draw_sdl_ctx_t *) draw_ctx;
115
+ SDL_Renderer * renderer = ctx->renderer;
116
+
117
+ lv_font_glyph_key_t glyph_key = font_key_glyph_create(font_p, letter);
118
+ bool glyph_found = false;
119
+ SDL_Texture * texture = lv_draw_sdl_texture_cache_get(ctx, &glyph_key, sizeof(glyph_key), &glyph_found);
120
+ bool in_cache = false;
121
+ if(!glyph_found) {
122
+ if(g.resolved_font) {
123
+ font_p = g.resolved_font;
124
+ }
125
+ const uint8_t * bmp = lv_font_get_glyph_bitmap(font_p, letter);
126
+ uint8_t * buf = lv_mem_alloc(g.box_w * g.box_h);
127
+ lv_sdl_to_8bpp(buf, bmp, g.box_w, g.box_h, g.box_w, g.bpp);
128
+ SDL_Surface * mask = lv_sdl_create_opa_surface(buf, g.box_w, g.box_h, g.box_w);
129
+ texture = SDL_CreateTextureFromSurface(renderer, mask);
130
+ SDL_FreeSurface(mask);
131
+ lv_mem_free(buf);
132
+ in_cache = lv_draw_sdl_texture_cache_put(ctx, &glyph_key, sizeof(glyph_key), texture);
133
+ }
134
+ else {
135
+ in_cache = true;
136
+ }
137
+ if(!texture) {
138
+ return;
139
+ }
140
+
141
+ lv_area_t t_letter = letter_area, t_clip = *clip_area, apply_area;
142
+ bool has_composite = lv_draw_sdl_composite_begin(ctx, &letter_area, clip_area, NULL, dsc->blend_mode, &t_letter,
143
+ &t_clip, &apply_area);
144
+
145
+ lv_draw_sdl_transform_areas_offset(ctx, has_composite, &apply_area, &t_letter, &t_clip);
146
+
147
+ /*If the letter is completely out of mask don't draw it*/
148
+ if(!_lv_area_intersect(&draw_area, &t_letter, &t_clip)) {
149
+ if(!in_cache) {
150
+ LV_LOG_WARN("Texture is not cached, this will impact performance.");
151
+ SDL_DestroyTexture(texture);
152
+ }
153
+ return;
154
+ }
155
+ SDL_Rect srcrect, dstrect;
156
+ lv_area_to_sdl_rect(&draw_area, &dstrect);
157
+ srcrect.x = draw_area.x1 - t_letter.x1;
158
+ srcrect.y = draw_area.y1 - t_letter.y1;
159
+ srcrect.w = dstrect.w;
160
+ srcrect.h = dstrect.h;
161
+ SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
162
+ SDL_SetTextureAlphaMod(texture, opa);
163
+ SDL_SetTextureColorMod(texture, color.ch.red, color.ch.green, color.ch.blue);
164
+ SDL_RenderCopy(renderer, texture, &srcrect, &dstrect);
165
+
166
+ lv_draw_sdl_composite_end(ctx, &apply_area, dsc->blend_mode);
167
+
168
+ if(!in_cache) {
169
+ LV_LOG_WARN("Texture is not cached, this will impact performance.");
170
+ SDL_DestroyTexture(texture);
171
+ }
172
+ }
173
+
174
+ /**********************
175
+ * STATIC FUNCTIONS
176
+ **********************/
177
+
178
+ static lv_font_glyph_key_t font_key_glyph_create(const lv_font_t * font_p, uint32_t letter)
179
+ {
180
+ lv_font_glyph_key_t key;
181
+ /* VERY IMPORTANT! Padding between members is uninitialized, so we have to wipe them manually */
182
+ SDL_memset(&key, 0, sizeof(key));
183
+ key.magic = LV_GPU_CACHE_KEY_MAGIC_FONT_GLYPH;
184
+ key.font_p = font_p;
185
+ key.letter = letter;
186
+ return key;
187
+ }
188
+
189
+ #endif /*LV_USE_GPU_SDL*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_layer.c ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_sdl_refr.c
3
+ *
4
+ */
5
+
6
+ /*********************
7
+ * INCLUDES
8
+ *********************/
9
+ #include "../../lv_conf_internal.h"
10
+
11
+ #if LV_USE_GPU_SDL
12
+
13
+ #include "../../core/lv_refr.h"
14
+
15
+ #include "lv_draw_sdl.h"
16
+ #include "lv_draw_sdl_priv.h"
17
+ #include "lv_draw_sdl_composite.h"
18
+ #include "lv_draw_sdl_utils.h"
19
+ #include "lv_draw_sdl_layer.h"
20
+
21
+ /*********************
22
+ * DEFINES
23
+ *********************/
24
+
25
+ /**********************
26
+ * TYPEDEFS
27
+ **********************/
28
+
29
+ /**********************
30
+ * STATIC PROTOTYPES
31
+ **********************/
32
+
33
+ /**********************
34
+ * STATIC VARIABLES
35
+ **********************/
36
+
37
+ /**********************
38
+ * MACROS
39
+ **********************/
40
+
41
+ /**********************
42
+ * GLOBAL FUNCTIONS
43
+ **********************/
44
+
45
+ lv_draw_layer_ctx_t * lv_draw_sdl_layer_init(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx,
46
+ lv_draw_layer_flags_t flags)
47
+ {
48
+ lv_draw_sdl_ctx_t * ctx = (lv_draw_sdl_ctx_t *) draw_ctx;
49
+ SDL_Renderer * renderer = ctx->renderer;
50
+
51
+ lv_draw_sdl_layer_ctx_t * transform_ctx = (lv_draw_sdl_layer_ctx_t *) layer_ctx;
52
+
53
+ transform_ctx->flags = flags;
54
+ transform_ctx->orig_target = SDL_GetRenderTarget(renderer);
55
+
56
+ lv_coord_t target_w = lv_area_get_width(&layer_ctx->area_full);
57
+ lv_coord_t target_h = lv_area_get_height(&layer_ctx->area_full);
58
+
59
+ enum lv_draw_sdl_composite_texture_id_t texture_id = LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TRANSFORM0 +
60
+ ctx->internals->transform_count;
61
+ transform_ctx->target = lv_draw_sdl_composite_texture_obtain(ctx, texture_id, target_w, target_h,
62
+ &transform_ctx->target_in_cache);
63
+ transform_ctx->target_rect.x = 0;
64
+ transform_ctx->target_rect.y = 0;
65
+ transform_ctx->target_rect.w = target_w;
66
+ transform_ctx->target_rect.h = target_h;
67
+
68
+ layer_ctx->max_row_with_alpha = target_h;
69
+ layer_ctx->max_row_with_no_alpha = target_h;
70
+
71
+ SDL_SetTextureBlendMode(transform_ctx->target, SDL_BLENDMODE_BLEND);
72
+ SDL_SetRenderTarget(renderer, transform_ctx->target);
73
+
74
+ /* SDL_RenderClear is not working properly, so we overwrite the target with solid color */
75
+ SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
76
+ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
77
+ SDL_RenderFillRect(renderer, NULL);
78
+ SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
79
+
80
+ /* Set proper drawing context for transform layer */
81
+ ctx->internals->transform_count += 1;
82
+ draw_ctx->buf_area = &layer_ctx->area_full;
83
+ draw_ctx->clip_area = &layer_ctx->area_full;
84
+
85
+ return layer_ctx;
86
+ }
87
+
88
+ void lv_draw_sdl_layer_blend(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx,
89
+ const lv_draw_img_dsc_t * draw_dsc)
90
+ {
91
+ lv_draw_sdl_ctx_t * ctx = (lv_draw_sdl_ctx_t *) draw_ctx;
92
+ lv_draw_sdl_layer_ctx_t * transform_ctx = (lv_draw_sdl_layer_ctx_t *) layer_ctx;
93
+
94
+ SDL_Renderer * renderer = ctx->renderer;
95
+
96
+ SDL_Rect trans_rect;
97
+
98
+ if(transform_ctx->flags & LV_DRAW_LAYER_FLAG_CAN_SUBDIVIDE) {
99
+ lv_area_zoom_to_sdl_rect(&layer_ctx->area_act, &trans_rect, draw_dsc->zoom, &draw_dsc->pivot);
100
+ }
101
+ else {
102
+ lv_area_zoom_to_sdl_rect(&layer_ctx->area_full, &trans_rect, draw_dsc->zoom, &draw_dsc->pivot);
103
+ }
104
+
105
+ SDL_SetRenderTarget(renderer, transform_ctx->orig_target);
106
+
107
+ /*Render off-screen texture, transformed*/
108
+ SDL_Rect clip_rect;
109
+ lv_area_to_sdl_rect(layer_ctx->original.clip_area, &clip_rect);
110
+ SDL_Point center = {.x = draw_dsc->pivot.x, .y = draw_dsc->pivot.y};
111
+ SDL_RenderSetClipRect(renderer, &clip_rect);
112
+ SDL_SetTextureAlphaMod(transform_ctx->target, draw_dsc->opa);
113
+ SDL_RenderCopyEx(renderer, transform_ctx->target, &transform_ctx->target_rect, &trans_rect,
114
+ draw_dsc->angle, &center, SDL_FLIP_NONE);
115
+ SDL_RenderSetClipRect(renderer, NULL);
116
+ }
117
+
118
+ void lv_draw_sdl_layer_destroy(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx)
119
+ {
120
+ lv_draw_sdl_ctx_t * ctx = (lv_draw_sdl_ctx_t *) draw_ctx;
121
+ lv_draw_sdl_layer_ctx_t * transform_ctx = (lv_draw_sdl_layer_ctx_t *) layer_ctx;
122
+ if(!transform_ctx->target_in_cache && transform_ctx->target != NULL) {
123
+ LV_LOG_WARN("Texture is not cached, this will impact performance.");
124
+ SDL_DestroyTexture(transform_ctx->target);
125
+ }
126
+ ctx->internals->transform_count -= 1;
127
+ }
128
+
129
+ void lv_draw_sdl_transform_areas_offset(lv_draw_sdl_ctx_t * ctx, bool has_composite, lv_area_t * apply_area,
130
+ lv_area_t * coords, lv_area_t * clip)
131
+ {
132
+ if(ctx->internals->transform_count == 0) {
133
+ return;
134
+ }
135
+ lv_area_t * area = ctx->base_draw.buf_area;
136
+ lv_area_move(coords, -area->x1, -area->y1);
137
+ lv_area_move(clip, -area->x1, -area->y1);
138
+ if(has_composite) {
139
+ lv_area_move(apply_area, -area->x1, -area->y1);
140
+ }
141
+ }
142
+
143
+ /**********************
144
+ * STATIC FUNCTIONS
145
+ **********************/
146
+
147
+ #endif /*LV_USE_GPU_SDL*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_layer.h ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_sdl_refr.h
3
+ *
4
+ */
5
+
6
+ #ifndef LV_TEMPL_H
7
+ #define LV_TEMPL_H
8
+
9
+ #ifdef __cplusplus
10
+ extern "C" {
11
+ #endif
12
+
13
+ /*********************
14
+ * INCLUDES
15
+ *********************/
16
+ #include "lv_draw_sdl.h"
17
+
18
+ /*********************
19
+ * DEFINES
20
+ *********************/
21
+
22
+ /**********************
23
+ * TYPEDEFS
24
+ **********************/
25
+ typedef struct _lv_draw_sdl_layer_ctx_t {
26
+ lv_draw_layer_ctx_t base;
27
+
28
+ SDL_Texture * orig_target;
29
+ SDL_Texture * target;
30
+ SDL_Rect target_rect;
31
+ bool target_in_cache;
32
+ lv_draw_layer_flags_t flags;
33
+ } lv_draw_sdl_layer_ctx_t;
34
+ /**********************
35
+ * GLOBAL PROTOTYPES
36
+ **********************/
37
+
38
+ lv_draw_layer_ctx_t * lv_draw_sdl_layer_init(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx,
39
+ lv_draw_layer_flags_t flags);
40
+
41
+ void lv_draw_sdl_layer_blend(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * transform_ctx,
42
+ const lv_draw_img_dsc_t * draw_dsc);
43
+
44
+ void lv_draw_sdl_layer_destroy(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx);
45
+
46
+ void lv_draw_sdl_transform_areas_offset(lv_draw_sdl_ctx_t * ctx, bool has_composite, lv_area_t * apply_area,
47
+ lv_area_t * coords, lv_area_t * clip);
48
+ /**********************
49
+ * MACROS
50
+ **********************/
51
+
52
+ #ifdef __cplusplus
53
+ } /*extern "C"*/
54
+ #endif
55
+
56
+ #endif /*LV_TEMPL_H*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_line.c ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_sdl_line.c
3
+ *
4
+ */
5
+
6
+ /*********************
7
+ * INCLUDES
8
+ *********************/
9
+ #include "../../lv_conf_internal.h"
10
+
11
+ #if LV_USE_GPU_SDL
12
+
13
+ #include "lv_draw_sdl.h"
14
+ #include "lv_draw_sdl_utils.h"
15
+ #include "lv_draw_sdl_texture_cache.h"
16
+ #include "lv_draw_sdl_composite.h"
17
+ #include "lv_draw_sdl_mask.h"
18
+
19
+ /*********************
20
+ * DEFINES
21
+ *********************/
22
+ #define ROUND_START 0x01
23
+ #define ROUND_END 0x02
24
+ /**********************
25
+ * TYPEDEFS
26
+ **********************/
27
+
28
+ typedef struct {
29
+ lv_sdl_cache_key_magic_t magic;
30
+ lv_coord_t length;
31
+ lv_coord_t width;
32
+ uint8_t round;
33
+ } lv_draw_line_key_t;
34
+
35
+ /**********************
36
+ * STATIC PROTOTYPES
37
+ **********************/
38
+
39
+ /**********************
40
+ * STATIC VARIABLES
41
+ **********************/
42
+
43
+ /**********************
44
+ * MACROS
45
+ **********************/
46
+
47
+ static lv_draw_line_key_t line_key_create(const lv_draw_line_dsc_t * dsc, lv_coord_t length);
48
+
49
+ static SDL_Texture * line_texture_create(lv_draw_sdl_ctx_t * sdl_ctx, const lv_draw_line_dsc_t * dsc,
50
+ lv_coord_t length);
51
+
52
+ /**********************
53
+ * GLOBAL FUNCTIONS
54
+ **********************/
55
+ void lv_draw_sdl_draw_line(lv_draw_ctx_t * draw_ctx, const lv_draw_line_dsc_t * dsc, const lv_point_t * point1,
56
+ const lv_point_t * point2, bool * in_cache)
57
+ {
58
+ lv_draw_sdl_ctx_t * sdl_ctx = (lv_draw_sdl_ctx_t *) draw_ctx;
59
+ SDL_Renderer * renderer = sdl_ctx->renderer;
60
+ lv_coord_t x1 = point1->x, x2 = point2->x, y1 = point1->y, y2 = point2->y;
61
+ double length = SDL_sqrt(SDL_pow(x2 - x1, 2) + SDL_pow(y2 - y1, 2));
62
+ if(length - (long) length > 0.5) {
63
+ length = (long) length + 1;
64
+ }
65
+
66
+ double angle = SDL_atan2(y2 - y1, x2 - x1) * 180 / M_PI;
67
+ lv_draw_line_key_t key = line_key_create(dsc, (lv_coord_t) length);
68
+ SDL_Texture * texture = lv_draw_sdl_texture_cache_get(sdl_ctx, &key, sizeof(key), NULL);
69
+ if(!texture) {
70
+ texture = line_texture_create(sdl_ctx, dsc, (lv_coord_t) length);
71
+ *in_cache = lv_draw_sdl_texture_cache_put(sdl_ctx, &key, sizeof(key), texture);
72
+ }
73
+
74
+ lv_area_t coords = {x1, y1, x2, y2};
75
+ const lv_area_t * clip = draw_ctx->clip_area;
76
+
77
+ SDL_Rect coords_r, clip_r;
78
+ lv_area_to_sdl_rect(&coords, &coords_r);
79
+ lv_area_to_sdl_rect(clip, &clip_r);
80
+
81
+ lv_area_t t_coords = coords, t_clip = *clip, apply_area;
82
+ lv_area_t extension = {dsc->width / 2, dsc->width / 2, dsc->width / 2, dsc->width / 2};
83
+ lv_draw_sdl_composite_begin(sdl_ctx, &coords, clip, &extension, dsc->blend_mode, &t_coords, &t_clip,
84
+ &apply_area);
85
+
86
+ SDL_Color color;
87
+ lv_color_to_sdl_color(&dsc->color, &color);
88
+
89
+ SDL_SetTextureColorMod(texture, color.r, color.g, color.b);
90
+ SDL_SetTextureAlphaMod(texture, dsc->opa);
91
+ SDL_Rect srcrect = {0, 0, (int) length + dsc->width + 2, dsc->width + 2},
92
+ dstrect = {t_coords.x1 - 1 - dsc->width / 2, t_coords.y1 - 1, srcrect.w, srcrect.h};
93
+ SDL_Point center = {1 + dsc->width / 2, 1 + dsc->width / 2};
94
+
95
+ SDL_Rect clip_rect;
96
+ lv_area_to_sdl_rect(&t_clip, &clip_rect);
97
+ if(!SDL_RectEquals(&clip_rect, &dstrect) || angle != 0) {
98
+ SDL_RenderSetClipRect(renderer, &clip_rect);
99
+ }
100
+ SDL_RenderCopyEx(renderer, texture, &srcrect, &dstrect, angle, &center, 0);
101
+ SDL_RenderSetClipRect(renderer, NULL);
102
+
103
+ lv_draw_sdl_composite_end(sdl_ctx, &apply_area, dsc->blend_mode);
104
+ }
105
+
106
+ /**********************
107
+ * STATIC FUNCTIONS
108
+ **********************/
109
+
110
+ static lv_draw_line_key_t line_key_create(const lv_draw_line_dsc_t * dsc, lv_coord_t length)
111
+ {
112
+ lv_draw_line_key_t key;
113
+ lv_memset_00(&key, sizeof(lv_draw_line_key_t));
114
+ key.magic = LV_GPU_CACHE_KEY_MAGIC_LINE;
115
+ key.length = length;
116
+ key.width = dsc->width;
117
+ key.round = (dsc->round_start ? ROUND_START : 0) | (dsc->round_end ? ROUND_END : 0);
118
+ return key;
119
+ }
120
+
121
+ static SDL_Texture * line_texture_create(lv_draw_sdl_ctx_t * sdl_ctx, const lv_draw_line_dsc_t * dsc, lv_coord_t length)
122
+ {
123
+ SDL_Texture * texture = SDL_CreateTexture(sdl_ctx->renderer, LV_DRAW_SDL_TEXTURE_FORMAT, SDL_TEXTUREACCESS_TARGET,
124
+ length + dsc->width + 2, dsc->width + 2);
125
+ SDL_Texture * target = SDL_GetRenderTarget(sdl_ctx->renderer);
126
+ SDL_SetRenderTarget(sdl_ctx->renderer, texture);
127
+ SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
128
+ SDL_SetRenderDrawColor(sdl_ctx->renderer, 0xFF, 0xFF, 0xFF, 0x0);
129
+ /* SDL_RenderClear is not working properly, so we overwrite the target with solid color */
130
+ SDL_SetRenderDrawBlendMode(sdl_ctx->renderer, SDL_BLENDMODE_NONE);
131
+ SDL_RenderFillRect(sdl_ctx->renderer, NULL);
132
+ SDL_SetRenderDrawBlendMode(sdl_ctx->renderer, SDL_BLENDMODE_BLEND);
133
+ SDL_SetRenderDrawColor(sdl_ctx->renderer, 0xFF, 0xFF, 0xFF, 0xFF);
134
+ SDL_Rect line_rect = {1 + dsc->width / 2, 1, length, dsc->width};
135
+ SDL_RenderFillRect(sdl_ctx->renderer, &line_rect);
136
+ if(dsc->round_start || dsc->round_end) {
137
+ lv_draw_mask_radius_param_t param;
138
+ lv_area_t round_area = {0, 0, dsc->width - 1, dsc->width - 1};
139
+ lv_draw_mask_radius_init(&param, &round_area, LV_RADIUS_CIRCLE, false);
140
+
141
+ int16_t mask_id = lv_draw_mask_add(&param, NULL);
142
+ SDL_Texture * round_texture = lv_draw_sdl_mask_dump_texture(sdl_ctx->renderer, &round_area, &mask_id, 1);
143
+ lv_draw_mask_remove_id(mask_id);
144
+
145
+ SDL_Rect round_src = {0, 0, dsc->width, dsc->width};
146
+ SDL_Rect round_dst = {line_rect.x - dsc->width / 2, 1, dsc->width, dsc->width};
147
+ SDL_RenderCopy(sdl_ctx->renderer, round_texture, &round_src, &round_dst);
148
+ round_dst.x = line_rect.w + dsc->width / 2;
149
+ SDL_RenderCopy(sdl_ctx->renderer, round_texture, &round_src, &round_dst);
150
+ SDL_DestroyTexture(round_texture);
151
+ }
152
+
153
+ SDL_SetRenderTarget(sdl_ctx->renderer, target);
154
+ return texture;
155
+ }
156
+
157
+ #endif /*LV_USE_GPU_SDL*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_mask.c ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_sdl_mask.c
3
+ *
4
+ */
5
+
6
+ /*********************
7
+ * INCLUDES
8
+ *********************/
9
+ #include "../../lv_conf_internal.h"
10
+
11
+ #if LV_USE_GPU_SDL
12
+
13
+ #include "../../misc/lv_gc.h"
14
+ #include "lv_draw_sdl_mask.h"
15
+ #include "lv_draw_sdl_utils.h"
16
+
17
+ /*********************
18
+ * DEFINES
19
+ *********************/
20
+ #ifndef HAVE_SDL_CUSTOM_BLEND_MODE
21
+ #define HAVE_SDL_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6))
22
+ #endif
23
+
24
+ /**********************
25
+ * TYPEDEFS
26
+ **********************/
27
+
28
+ /**********************
29
+ * STATIC PROTOTYPES
30
+ **********************/
31
+
32
+ /**********************
33
+ * STATIC VARIABLES
34
+ **********************/
35
+
36
+ /**********************
37
+ * MACROS
38
+ **********************/
39
+
40
+ /**********************
41
+ * GLOBAL FUNCTIONS
42
+ **********************/
43
+
44
+ lv_opa_t * lv_draw_sdl_mask_dump_opa(const lv_area_t * coords, const int16_t * ids, int16_t ids_count)
45
+ {
46
+ SDL_assert(coords->x2 >= coords->x1);
47
+ SDL_assert(coords->y2 >= coords->y1);
48
+ lv_coord_t w = lv_area_get_width(coords), h = lv_area_get_height(coords);
49
+ lv_opa_t * mask_buf = lv_mem_buf_get(w * h);
50
+ for(lv_coord_t y = 0; y < h; y++) {
51
+ lv_opa_t * line_buf = &mask_buf[y * w];
52
+ lv_memset_ff(line_buf, w);
53
+ lv_coord_t abs_x = (lv_coord_t) coords->x1, abs_y = (lv_coord_t)(y + coords->y1), len = (lv_coord_t) w;
54
+ lv_draw_mask_res_t res;
55
+ if(ids) {
56
+ res = lv_draw_mask_apply_ids(line_buf, abs_x, abs_y, len, ids, ids_count);
57
+ }
58
+ else {
59
+ res = lv_draw_mask_apply(line_buf, abs_x, abs_y, len);
60
+ }
61
+ if(res == LV_DRAW_MASK_RES_TRANSP) {
62
+ lv_memset_00(line_buf, w);
63
+ }
64
+ }
65
+ return mask_buf;
66
+ }
67
+
68
+ SDL_Texture * lv_draw_sdl_mask_dump_texture(SDL_Renderer * renderer, const lv_area_t * coords, const int16_t * ids,
69
+ int16_t ids_count)
70
+ {
71
+ lv_coord_t w = lv_area_get_width(coords), h = lv_area_get_height(coords);
72
+ lv_opa_t * mask_buf = lv_draw_sdl_mask_dump_opa(coords, ids, ids_count);
73
+ SDL_Surface * surface = lv_sdl_create_opa_surface(mask_buf, w, h, w);
74
+ lv_mem_buf_release(mask_buf);
75
+ SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
76
+ SDL_FreeSurface(surface);
77
+ return texture;
78
+ }
79
+
80
+ /**********************
81
+ * STATIC FUNCTIONS
82
+ **********************/
83
+
84
+ #endif /*LV_USE_GPU_SDL*/
Floatkyun_Ultra-Vision/GUI/STM32_Keil_Project/LVGL/LVGL_SRC/lvgl/src/draw/sdl/lv_draw_sdl_mask.h ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @file lv_draw_sdl_mask.h
3
+ *
4
+ */
5
+
6
+ #ifndef LV_DRAW_SDL_MASK_H
7
+ #define LV_DRAW_SDL_MASK_H
8
+
9
+ #ifdef __cplusplus
10
+ extern "C" {
11
+ #endif
12
+
13
+ /*********************
14
+ * INCLUDES
15
+ *********************/
16
+
17
+ #include "../../lv_conf_internal.h"
18
+
19
+ #include LV_GPU_SDL_INCLUDE_PATH
20
+
21
+ #include "lv_draw_sdl.h"
22
+ #include "../../misc/lv_area.h"
23
+ #include "../../misc/lv_color.h"
24
+
25
+ /*********************
26
+ * DEFINES
27
+ *********************/
28
+
29
+ /**********************
30
+ * TYPEDEFS
31
+ **********************/
32
+
33
+ /**********************
34
+ * GLOBAL PROTOTYPES
35
+ **********************/
36
+
37
+ lv_opa_t * lv_draw_sdl_mask_dump_opa(const lv_area_t * coords, const int16_t * ids, int16_t ids_count);
38
+
39
+ SDL_Texture * lv_draw_sdl_mask_dump_texture(SDL_Renderer * renderer, const lv_area_t * coords, const int16_t * ids,
40
+ int16_t ids_count);
41
+
42
+
43
+ /**********************
44
+ * MACROS
45
+ **********************/
46
+
47
+ #ifdef __cplusplus
48
+ } /*extern "C"*/
49
+ #endif
50
+
51
+ #endif /*LV_DRAW_SDL_MASK_H*/