1 /**
2 * MIT License
3 *
4 * -----------------------------------------------------------------------------
5 * Copyright (c) 2008-24 Think Silicon Single Member PC
6 * -----------------------------------------------------------------------------
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights to
11 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12 * the Software, and to permit persons to whom the Software is furnished to do so,
13 * subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next paragraph)
16 * shall be included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
19 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
20 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
22 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
23 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27 /**
28 * @file lv_draw_nema_gfx_utils.c
29 *
30 */
31
32 /*********************
33 * INCLUDES
34 *********************/
35 #include "lv_draw_nema_gfx.h"
36
37 #if LV_USE_NEMA_GFX
38
39 /**********************
40 * GLOBAL FUNCTIONS
41 **********************/
42
lv_nemagfx_cf_to_nema(lv_color_format_t cf)43 uint32_t lv_nemagfx_cf_to_nema(lv_color_format_t cf)
44 {
45 switch(cf) {
46 case LV_COLOR_FORMAT_A1:
47 return NEMA_A1;
48 case LV_COLOR_FORMAT_A2:
49 return NEMA_A2;
50 case LV_COLOR_FORMAT_A4:
51 return NEMA_A4;
52 case LV_COLOR_FORMAT_A8:
53 return NEMA_A8;
54 case LV_COLOR_FORMAT_I1:
55 return NEMA_L1;
56 case LV_COLOR_FORMAT_I2:
57 return NEMA_L2;
58 case LV_COLOR_FORMAT_I4:
59 return NEMA_L4;
60 case LV_COLOR_FORMAT_L8:
61 case LV_COLOR_FORMAT_I8:
62 return NEMA_L8;
63 case LV_COLOR_FORMAT_RGB565:
64 return NEMA_RGB565;
65 case LV_COLOR_FORMAT_RGB888:
66 return NEMA_BGR24;
67 case LV_COLOR_FORMAT_ARGB8888:
68 return NEMA_BGRA8888;
69 case LV_COLOR_FORMAT_XRGB8888:
70 return NEMA_BGRX8888;
71 case LV_COLOR_FORMAT_NEMA_TSC4:
72 return NEMA_TSC4;
73 case LV_COLOR_FORMAT_NEMA_TSC6:
74 return NEMA_TSC6;
75 case LV_COLOR_FORMAT_NEMA_TSC6A:
76 return NEMA_TSC6A;
77 case LV_COLOR_FORMAT_NEMA_TSC12:
78 return NEMA_TSC12;
79 case LV_COLOR_FORMAT_NEMA_TSC12A:
80 return NEMA_TSC12A;
81 /*Guard for previous NemaGFX Version*/
82 #ifdef NEMA_TSC6AP
83 case LV_COLOR_FORMAT_NEMA_TSC6AP:
84 return NEMA_TSC6AP;
85 #endif
86 default:
87 return LV_NEMA_GFX_COLOR_FORMAT;
88 }
89 }
90
lv_nemagfx_blending_mode(lv_blend_mode_t lv_blend_mode)91 uint32_t lv_nemagfx_blending_mode(lv_blend_mode_t lv_blend_mode)
92 {
93 uint32_t blending_mode;
94 switch(lv_blend_mode) {
95 case LV_BLEND_MODE_NORMAL:
96 blending_mode = NEMA_BL_SIMPLE;
97 break;
98 case LV_BLEND_MODE_ADDITIVE:
99 blending_mode = NEMA_BL_ADD;
100 break;
101 case LV_BLEND_MODE_MULTIPLY:
102 blending_mode = nema_blending_mode(NEMA_BF_DESTCOLOR, NEMA_BF_INVSRCALPHA, NEMA_BLOP_SRC_PREMULT);
103 break;
104 default:
105 blending_mode = NEMA_BL_SIMPLE;
106 break;
107 }
108 return blending_mode;
109 }
110
lv_nemagfx_grad_set(NEMA_VG_GRAD_HANDLE gradient,lv_grad_dsc_t lv_grad,lv_opa_t opa)111 void lv_nemagfx_grad_set(NEMA_VG_GRAD_HANDLE gradient, lv_grad_dsc_t lv_grad, lv_opa_t opa)
112 {
113
114 float stops[LV_GRADIENT_MAX_STOPS];
115 color_var_t colors[LV_GRADIENT_MAX_STOPS];
116
117 uint32_t cnt = LV_MAX(lv_grad.stops_count, LV_GRADIENT_MAX_STOPS);
118
119 for(uint8_t i = 0; i < cnt; i++) {
120 stops[i] = (float)(lv_grad.stops[i].frac) / 255.f;
121 colors[i].a = LV_OPA_MIX2(lv_grad.stops[i].opa, opa);
122 colors[i].r = lv_grad.stops[i].color.red;
123 colors[i].g = lv_grad.stops[i].color.green;
124 colors[i].b = lv_grad.stops[i].color.blue;
125 }
126
127 nema_vg_grad_set(gradient, cnt, stops, colors);
128 }
129
lv_nemagfx_is_cf_supported(lv_color_format_t cf)130 bool lv_nemagfx_is_cf_supported(lv_color_format_t cf)
131 {
132
133 switch(cf) {
134 case LV_COLOR_FORMAT_ARGB8565:
135 case LV_COLOR_FORMAT_RGB565A8:
136 return false;
137 default:
138 break;
139 }
140 return true;
141 }
142
143 #endif /*LV_USE_NEMA_GFX*/
144