Debian Codegraph @

lvgl/src/draw/sw/blend/lv_draw_sw_blend_to_argb8888.c

raw symbols SCIP
1 /**
2 * @file lv_draw_sw_blend_to_argb8888.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9 #include "lv_draw_sw_blend_to_argb8888.h"
10 #if LV_USE_DRAW_SW
11
12 #if LV_DRAW_SW_SUPPORT_ARGB8888
13
14 #include "lv_draw_sw_blend_private.h"
15 #include "../../../misc/lv_math.h"
16 #include "../../../display/lv_display.h"
17 #include "../../../core/lv_refr.h"
18 #include "../../../misc/lv_color.h"
19 #include "../../../stdlib/lv_string.h"
20
21 #if LV_USE_DRAW_SW_ASM == LV_DRAW_SW_ASM_NEON
22 #include "neon/lv_blend_neon.h"
23 #elif LV_USE_DRAW_SW_ASM == LV_DRAW_SW_ASM_HELIUM
24 #include "helium/lv_blend_helium.h"
25 #elif LV_USE_DRAW_SW_ASM == LV_DRAW_SW_ASM_CUSTOM
26 #include LV_DRAW_SW_ASM_CUSTOM_INCLUDE
27 #endif
28
29 /*********************
30 * DEFINES
31 *********************/
32
33 /**********************
34 * TYPEDEFS
35 **********************/
36
37 typedef struct {
38 lv_color32_t fg_saved;
39 lv_color32_t bg_saved;
40 lv_color32_t res_saved;
41 lv_opa_t res_alpha_saved;
42 lv_opa_t ratio_saved;
43 } lv_color_mix_alpha_cache_t;
44
45 /**********************
46 * STATIC PROTOTYPES
47 **********************/
48
49 #if LV_DRAW_SW_SUPPORT_AL88
50 static void /* LV_ATTRIBUTE_FAST_MEM */ al88_image_blend(lv_draw_sw_blend_image_dsc_t * dsc);
51 #endif
52
53 #if LV_DRAW_SW_SUPPORT_I1
54 static void /* LV_ATTRIBUTE_FAST_MEM */ i1_image_blend(lv_draw_sw_blend_image_dsc_t * dsc);
55
56 static inline uint8_t /* LV_ATTRIBUTE_FAST_MEM */ get_bit(const uint8_t * buf, int32_t bit_idx);
57 #endif
58
59 #if LV_DRAW_SW_SUPPORT_L8
60 static void /* LV_ATTRIBUTE_FAST_MEM */ l8_image_blend(lv_draw_sw_blend_image_dsc_t * dsc);
61 #endif
62
63 #if LV_DRAW_SW_SUPPORT_RGB565
64 static void /* LV_ATTRIBUTE_FAST_MEM */ rgb565_image_blend(lv_draw_sw_blend_image_dsc_t * dsc);
65 #endif
66
67 #if LV_DRAW_SW_SUPPORT_RGB565_SWAPPED
68 static void /* LV_ATTRIBUTE_FAST_MEM */ rgb565_swapped_image_blend(lv_draw_sw_blend_image_dsc_t * dsc);
69 #endif
70
71 #if LV_DRAW_SW_SUPPORT_RGB888 || LV_DRAW_SW_SUPPORT_XRGB8888
72 static void /* LV_ATTRIBUTE_FAST_MEM */ rgb888_image_blend(lv_draw_sw_blend_image_dsc_t * dsc,
73 const uint8_t src_px_size);
74 #endif
75
76 #if LV_DRAW_SW_SUPPORT_ARGB8888_PREMULTIPLIED
77 static void /* LV_ATTRIBUTE_FAST_MEM */ argb8888_premultiplied_image_blend(lv_draw_sw_blend_image_dsc_t * dsc);
78 #endif
79
80 static void /* LV_ATTRIBUTE_FAST_MEM */ argb8888_image_blend(lv_draw_sw_blend_image_dsc_t * dsc);
81
82 static inline void /* LV_ATTRIBUTE_FAST_MEM */ lv_color_8_32_mix(const uint8_t src, lv_color32_t * dest, uint8_t mix);
83
84 static inline lv_color32_t /* LV_ATTRIBUTE_FAST_MEM */ lv_color_32_32_mix(lv_color32_t fg, lv_color32_t bg,
85 lv_color_mix_alpha_cache_t * cache);
86
87 static void lv_color_mix_with_alpha_cache_init(lv_color_mix_alpha_cache_t * cache);
88
89 static inline void /* LV_ATTRIBUTE_FAST_MEM */ blend_non_normal_pixel(lv_color32_t * dest, lv_color32_t src,
90 lv_blend_mode_t mode, lv_color_mix_alpha_cache_t * cache);
91
92 static inline void * /* LV_ATTRIBUTE_FAST_MEM */ drawbuf_next_row(const void * buf, uint32_t stride);
93
94 #if LV_DRAW_SW_SUPPORT_RGB565_SWAPPED
95 static inline lv_color16_t /* LV_ATTRIBUTE_FAST_MEM */ lv_color16_from_u16(uint16_t raw);
96 #endif
97
98 /**********************
99 * STATIC VARIABLES
100 **********************/
101
102 /**********************
103 * MACROS
104 **********************/
105
106 #ifndef LV_DRAW_SW_COLOR_BLEND_TO_ARGB8888
107 #define LV_DRAW_SW_COLOR_BLEND_TO_ARGB8888(...) LV_RESULT_INVALID
108 #endif
109
110 #ifndef LV_DRAW_SW_COLOR_BLEND_TO_ARGB8888_WITH_OPA
111 #define LV_DRAW_SW_COLOR_BLEND_TO_ARGB8888_WITH_OPA(...) LV_RESULT_INVALID
112 #endif
113
114 #ifndef LV_DRAW_SW_COLOR_BLEND_TO_ARGB8888_WITH_MASK
115 #define LV_DRAW_SW_COLOR_BLEND_TO_ARGB8888_WITH_MASK(...) LV_RESULT_INVALID
116 #endif
117
118 #ifndef LV_DRAW_SW_COLOR_BLEND_TO_ARGB8888_MIX_MASK_OPA
119 #define LV_DRAW_SW_COLOR_BLEND_TO_ARGB8888_MIX_MASK_OPA(...) LV_RESULT_INVALID
120 #endif
121
122 #ifndef LV_DRAW_SW_L8_BLEND_NORMAL_TO_ARGB8888
123 #define LV_DRAW_SW_L8_BLEND_NORMAL_TO_ARGB8888(...) LV_RESULT_INVALID
124 #endif
125
126 #ifndef LV_DRAW_SW_L8_BLEND_NORMAL_TO_ARGB8888_WITH_OPA
127 #define LV_DRAW_SW_L8_BLEND_NORMAL_TO_ARGB8888_WITH_OPA(...) LV_RESULT_INVALID
128 #endif
129
130 #ifndef LV_DRAW_SW_L8_BLEND_NORMAL_TO_ARGB8888_WITH_MASK
131 #define LV_DRAW_SW_L8_BLEND_NORMAL_TO_ARGB8888_WITH_MASK(...) LV_RESULT_INVALID
132 #endif
133
134 #ifndef LV_DRAW_SW_L8_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA
135 #define LV_DRAW_SW_L8_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA(...) LV_RESULT_INVALID
136 #endif
137
138 #ifndef LV_DRAW_SW_AL88_BLEND_NORMAL_TO_ARGB8888
139 #define LV_DRAW_SW_AL88_BLEND_NORMAL_TO_ARGB8888(...) LV_RESULT_INVALID
140 #endif
141
142 #ifndef LV_DRAW_SW_AL88_BLEND_NORMAL_TO_ARGB8888_WITH_OPA
143 #define LV_DRAW_SW_AL88_BLEND_NORMAL_TO_ARGB8888_WITH_OPA(...) LV_RESULT_INVALID
144 #endif
145
146 #ifndef LV_DRAW_SW_AL88_BLEND_NORMAL_TO_ARGB8888_WITH_MASK
147 #define LV_DRAW_SW_AL88_BLEND_NORMAL_TO_ARGB8888_WITH_MASK(...) LV_RESULT_INVALID
148 #endif
149
150 #ifndef LV_DRAW_SW_AL88_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA
151 #define LV_DRAW_SW_AL88_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA(...) LV_RESULT_INVALID
152 #endif
153
154 #ifndef LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_ARGB8888
155 #define LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_ARGB8888(...) LV_RESULT_INVALID
156 #endif
157
158 #ifndef LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_ARGB8888_WITH_OPA
159 #define LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_ARGB8888_WITH_OPA(...) LV_RESULT_INVALID
160 #endif
161
162 #ifndef LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_ARGB8888_WITH_MASK
163 #define LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_ARGB8888_WITH_MASK(...) LV_RESULT_INVALID
164 #endif
165
166 #ifndef LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA
167 #define LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA(...) LV_RESULT_INVALID
168 #endif
169
170 #ifndef LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_ARGB8888
171 #define LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_ARGB8888(...) LV_RESULT_INVALID
172 #endif
173
174 #ifndef LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_ARGB8888_WITH_OPA
175 #define LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_ARGB8888_WITH_OPA(...) LV_RESULT_INVALID
176 #endif
177
178 #ifndef LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_ARGB8888_WITH_MASK
179 #define LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_ARGB8888_WITH_MASK(...) LV_RESULT_INVALID
180 #endif
181
182 #ifndef LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA
183 #define LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA(...) LV_RESULT_INVALID
184 #endif
185
186 #ifndef LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_ARGB8888
187 #define LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_ARGB8888(...) LV_RESULT_INVALID
188 #endif
189
190 #ifndef LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_ARGB8888_WITH_OPA
191 #define LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_ARGB8888_WITH_OPA(...) LV_RESULT_INVALID
192 #endif
193
194 #ifndef LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_ARGB8888_WITH_MASK
195 #define LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_ARGB8888_WITH_MASK(...) LV_RESULT_INVALID
196 #endif
197
198 #ifndef LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA
199 #define LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA(...) LV_RESULT_INVALID
200 #endif
201
202 #ifndef LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_ARGB8888
203 #define LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_ARGB8888(...) LV_RESULT_INVALID
204 #endif
205
206 #ifndef LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_ARGB8888_WITH_OPA
207 #define LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_ARGB8888_WITH_OPA(...) LV_RESULT_INVALID
208 #endif
209
210 #ifndef LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_ARGB8888_WITH_MASK
211 #define LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_ARGB8888_WITH_MASK(...) LV_RESULT_INVALID
212 #endif
213
214 #ifndef LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA
215 #define LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA(...) LV_RESULT_INVALID
216 #endif
217
218 #ifndef LV_DRAW_SW_I1_BLEND_NORMAL_TO_ARGB8888
219 #define LV_DRAW_SW_I1_BLEND_NORMAL_TO_ARGB8888(...) LV_RESULT_INVALID
220 #endif
221
222 #ifndef LV_DRAW_SW_I1_BLEND_NORMAL_TO_ARGB8888_WITH_OPA
223 #define LV_DRAW_SW_I1_BLEND_NORMAL_TO_ARGB8888_WITH_OPA(...) LV_RESULT_INVALID
224 #endif
225
226 #ifndef LV_DRAW_SW_I1_BLEND_NORMAL_TO_ARGB8888_WITH_MASK
227 #define LV_DRAW_SW_I1_BLEND_NORMAL_TO_ARGB8888_WITH_MASK(...) LV_RESULT_INVALID
228 #endif
229
230 #ifndef LV_DRAW_SW_I1_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA
231 #define LV_DRAW_SW_I1_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA(...) LV_RESULT_INVALID
232 #endif
233
234 /**********************
235 * GLOBAL FUNCTIONS
236 **********************/
237
238 void LV_ATTRIBUTE_FAST_MEM lv_draw_sw_blend_color_to_argb8888(lv_draw_sw_blend_fill_dsc_t * dsc)
239 {
240 int32_t w = dsc->dest_w;
241 int32_t h = dsc->dest_h;
242 lv_opa_t opa = dsc->opa;
243 const lv_opa_t * mask = dsc->mask_buf;
244 int32_t mask_stride = dsc->mask_stride;
245 int32_t dest_stride = dsc->dest_stride;
246
247 lv_color_mix_alpha_cache_t cache;
248 lv_color_mix_with_alpha_cache_init(&cache);
249
250 int32_t x;
251 int32_t y;
252
253 LV_UNUSED(w);
254 LV_UNUSED(h);
255 LV_UNUSED(x);
256 LV_UNUSED(y);
257 LV_UNUSED(opa);
258 LV_UNUSED(mask);
259 LV_UNUSED(mask_stride);
260 LV_UNUSED(dest_stride);
261
262 /*Simple fill*/
263 if(mask == NULL && opa >= LV_OPA_MAX) {
264 if(LV_RESULT_INVALID == LV_DRAW_SW_COLOR_BLEND_TO_ARGB8888(dsc)) {
265 uint32_t color32 = lv_color_to_u32(dsc->color);
266 uint32_t * dest_buf = dsc->dest_buf;
267 for(y = 0; y < h; y++) {
268 for(x = 0; x < w - 15; x += 16) {
269 dest_buf[x + 0] = color32;
270 dest_buf[x + 1] = color32;
271 dest_buf[x + 2] = color32;
272 dest_buf[x + 3] = color32;
273
274 dest_buf[x + 4] = color32;
275 dest_buf[x + 5] = color32;
276 dest_buf[x + 6] = color32;
277 dest_buf[x + 7] = color32;
278
279 dest_buf[x + 8] = color32;
280 dest_buf[x + 9] = color32;
281 dest_buf[x + 10] = color32;
282 dest_buf[x + 11] = color32;
283
284 dest_buf[x + 12] = color32;
285 dest_buf[x + 13] = color32;
286 dest_buf[x + 14] = color32;
287 dest_buf[x + 15] = color32;
288 }
289 for(; x < w; x ++) {
290 dest_buf[x] = color32;
291 }
292
293 dest_buf = drawbuf_next_row(dest_buf, dest_stride);
294 }
295 }
296 }
297 /*Opacity only*/
298 else if(mask == NULL && opa < LV_OPA_MAX) {
299 if(LV_RESULT_INVALID == LV_DRAW_SW_COLOR_BLEND_TO_ARGB8888_WITH_OPA(dsc)) {
300 lv_color32_t color_argb = lv_color_to_32(dsc->color, opa);
301 lv_color32_t * dest_buf = dsc->dest_buf;
302
303 for(y = 0; y < h; y++) {
304 for(x = 0; x < w; x++) {
305 dest_buf[x] = lv_color_32_32_mix(color_argb, dest_buf[x], &cache);
306 }
307
308 dest_buf = drawbuf_next_row(dest_buf, dest_stride);
309 }
310 }
311 }
312 /*Masked with full opacity*/
313 else if(mask && opa >= LV_OPA_MAX) {
314 if(LV_RESULT_INVALID == LV_DRAW_SW_COLOR_BLEND_TO_ARGB8888_WITH_MASK(dsc)) {
315 lv_color32_t color_argb = lv_color_to_32(dsc->color, 0xff);
316 lv_color32_t * dest_buf = dsc->dest_buf;
317 for(y = 0; y < h; y++) {
318 for(x = 0; x < w; x++) {
319 color_argb.alpha = mask[x];
320 dest_buf[x] = lv_color_32_32_mix(color_argb, dest_buf[x], &cache);
321 }
322
323 dest_buf = drawbuf_next_row(dest_buf, dest_stride);
324 mask += mask_stride;
325 }
326 }
327 }
328 /*Masked with opacity*/
329 else {
330 if(LV_RESULT_INVALID == LV_DRAW_SW_COLOR_BLEND_TO_ARGB8888_MIX_MASK_OPA(dsc)) {
331 lv_color32_t color_argb = lv_color_to_32(dsc->color, opa);
332 lv_color32_t * dest_buf = dsc->dest_buf;
333 for(y = 0; y < h; y++) {
334 for(x = 0; x < w; x++) {
335 color_argb.alpha = LV_OPA_MIX2(mask[x], opa);
336 dest_buf[x] = lv_color_32_32_mix(color_argb, dest_buf[x], &cache);
337 }
338 dest_buf = drawbuf_next_row(dest_buf, dest_stride);
339 mask += mask_stride;
340 }
341 }
342 }
343 }
344
345 void LV_ATTRIBUTE_FAST_MEM lv_draw_sw_blend_image_to_argb8888(lv_draw_sw_blend_image_dsc_t * dsc)
346 {
347 switch(dsc->src_color_format) {
348 #if LV_DRAW_SW_SUPPORT_RGB565
349 case LV_COLOR_FORMAT_RGB565:
350 rgb565_image_blend(dsc);
351 break;
352 #endif
353 #if LV_DRAW_SW_SUPPORT_RGB565_SWAPPED
354 case LV_COLOR_FORMAT_RGB565_SWAPPED:
355 rgb565_swapped_image_blend(dsc);
356 break;
357 #endif
358 #if LV_DRAW_SW_SUPPORT_RGB888
359 case LV_COLOR_FORMAT_RGB888:
360 rgb888_image_blend(dsc, 3);
361 break;
362 #endif
363 #if LV_DRAW_SW_SUPPORT_XRGB8888
364 case LV_COLOR_FORMAT_XRGB8888:
365 rgb888_image_blend(dsc, 4);
366 break;
367 #endif
368 #if LV_DRAW_SW_SUPPORT_ARGB8888_PREMULTIPLIED
369 case LV_COLOR_FORMAT_ARGB8888_PREMULTIPLIED:
370 argb8888_premultiplied_image_blend(dsc);
371 break;
372 #endif
373 case LV_COLOR_FORMAT_ARGB8888:
374 argb8888_image_blend(dsc);
375 break;
376 #if LV_DRAW_SW_SUPPORT_L8
377 case LV_COLOR_FORMAT_L8:
378 l8_image_blend(dsc);
379 break;
380 #endif
381 #if LV_DRAW_SW_SUPPORT_AL88
382 case LV_COLOR_FORMAT_AL88:
383 al88_image_blend(dsc);
384 break;
385 #endif
386 #if LV_DRAW_SW_SUPPORT_I1
387 case LV_COLOR_FORMAT_I1:
388 i1_image_blend(dsc);
389 break;
390 #endif
391 default:
392 LV_LOG_WARN("Not supported source color format");
393 break;
394 }
395 }
396
397 /**********************
398 * STATIC FUNCTIONS
399 **********************/
400
401 #if LV_DRAW_SW_SUPPORT_I1
402 static void LV_ATTRIBUTE_FAST_MEM i1_image_blend(lv_draw_sw_blend_image_dsc_t * dsc)
403 {
404 int32_t w = dsc->dest_w;
405 int32_t h = dsc->dest_h;
406 lv_opa_t opa = dsc->opa;
407 lv_color32_t * dest_buf_c32 = dsc->dest_buf;
408 int32_t dest_stride = dsc->dest_stride;
409 const uint8_t * src_buf_i1 = dsc->src_buf;
410 int32_t src_stride = dsc->src_stride;
411 const lv_opa_t * mask_buf = dsc->mask_buf;
412 int32_t mask_stride = dsc->mask_stride;
413
414 int32_t dest_x;
415 int32_t src_x;
416 int32_t y;
417
418 if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
419 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
420 if(LV_RESULT_INVALID == LV_DRAW_SW_I1_BLEND_NORMAL_TO_ARGB8888(dsc)) {
421 for(y = 0; y < h; y++) {
422 for(dest_x = 0, src_x = 0; src_x < w; dest_x++, src_x++) {
423 uint8_t chan_val = get_bit(src_buf_i1, src_x) * 255;
424 dest_buf_c32[dest_x].alpha = chan_val;
425 dest_buf_c32[dest_x].red = chan_val;
426 dest_buf_c32[dest_x].green = chan_val;
427 dest_buf_c32[dest_x].blue = chan_val;
428 }
429 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
430 src_buf_i1 = drawbuf_next_row(src_buf_i1, src_stride);
431 }
432 }
433 }
434 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
435 if(LV_RESULT_INVALID == LV_DRAW_SW_I1_BLEND_NORMAL_TO_ARGB8888_WITH_OPA(dsc)) {
436 for(y = 0; y < h; y++) {
437 for(dest_x = 0, src_x = 0; src_x < w; dest_x++, src_x++) {
438 uint8_t chan_val = get_bit(src_buf_i1, src_x) * 255;
439 lv_color_8_32_mix(chan_val, &dest_buf_c32[dest_x], opa);
440 }
441 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
442 src_buf_i1 = drawbuf_next_row(src_buf_i1, src_stride);
443 }
444 }
445 }
446 else if(mask_buf && opa >= LV_OPA_MAX) {
447 if(LV_RESULT_INVALID == LV_DRAW_SW_I1_BLEND_NORMAL_TO_ARGB8888_WITH_MASK(dsc)) {
448 for(y = 0; y < h; y++) {
449 for(dest_x = 0, src_x = 0; src_x < w; dest_x++, src_x++) {
450 uint8_t chan_val = get_bit(src_buf_i1, src_x) * 255;
451 lv_color_8_32_mix(chan_val, &dest_buf_c32[dest_x], mask_buf[src_x]);
452 }
453 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
454 src_buf_i1 = drawbuf_next_row(src_buf_i1, src_stride);
455 mask_buf += mask_stride;
456 }
457 }
458 }
459 else if(mask_buf && opa < LV_OPA_MAX) {
460 if(LV_RESULT_INVALID == LV_DRAW_SW_I1_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA(dsc)) {
461 for(y = 0; y < h; y++) {
462 for(dest_x = 0, src_x = 0; src_x < w; dest_x++, src_x++) {
463 uint8_t chan_val = get_bit(src_buf_i1, src_x) * 255;
464 lv_color_8_32_mix(chan_val, &dest_buf_c32[dest_x], LV_OPA_MIX2(mask_buf[src_x], opa));
465 }
466 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
467 src_buf_i1 = drawbuf_next_row(src_buf_i1, src_stride);
468 mask_buf += mask_stride;
469 }
470 }
471 }
472 }
473 else {
474 lv_color32_t src_argb;
475 lv_color_mix_alpha_cache_t cache;
476 lv_color_mix_with_alpha_cache_init(&cache);
477 for(y = 0; y < h; y++) {
478 for(dest_x = 0, src_x = 0; src_x < w; dest_x++, src_x++) {
479 src_argb.red = get_bit(src_buf_i1, src_x) * 255;
480 src_argb.green = src_argb.red;
481 src_argb.blue = src_argb.red;
482 if(mask_buf == NULL) src_argb.alpha = opa;
483 else src_argb.alpha = LV_OPA_MIX2(mask_buf[dest_x], opa);
484 blend_non_normal_pixel(&dest_buf_c32[dest_x], src_argb, dsc->blend_mode, &cache);
485 }
486 if(mask_buf) mask_buf += mask_stride;
487 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
488 src_buf_i1 = drawbuf_next_row(src_buf_i1, src_stride);
489 }
490 }
491 }
492 #endif
493
494 #if LV_DRAW_SW_SUPPORT_AL88
495 static void LV_ATTRIBUTE_FAST_MEM al88_image_blend(lv_draw_sw_blend_image_dsc_t * dsc)
496 {
497 int32_t w = dsc->dest_w;
498 int32_t h = dsc->dest_h;
499 lv_opa_t opa = dsc->opa;
500 lv_color32_t * dest_buf_c32 = dsc->dest_buf;
501 int32_t dest_stride = dsc->dest_stride;
502 const lv_color16a_t * src_buf_al88 = dsc->src_buf;
503 int32_t src_stride = dsc->src_stride;
504 const lv_opa_t * mask_buf = dsc->mask_buf;
505 int32_t mask_stride = dsc->mask_stride;
506
507 int32_t dest_x;
508 int32_t src_x;
509 int32_t y;
510
511 if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
512 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
513 if(LV_RESULT_INVALID == LV_DRAW_SW_AL88_BLEND_NORMAL_TO_ARGB8888(dsc)) {
514 for(y = 0; y < h; y++) {
515 for(dest_x = 0, src_x = 0; src_x < w; dest_x++, src_x++) {
516 /*
517 dest_buf_c32[dest_x].alpha = src_buf_al88[src_x].alpha;
518 dest_buf_c32[dest_x].red = src_buf_al88[src_x].lumi;
519 dest_buf_c32[dest_x].green = src_buf_al88[src_x].lumi;
520 dest_buf_c32[dest_x].blue = src_buf_al88[src_x].lumi;
521 */
522 lv_color_8_32_mix(src_buf_al88[src_x].lumi, &dest_buf_c32[dest_x], src_buf_al88[src_x].alpha);
523 }
524 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
525 src_buf_al88 = drawbuf_next_row(src_buf_al88, src_stride);
526 }
527 }
528 }
529 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
530 if(LV_RESULT_INVALID == LV_DRAW_SW_AL88_BLEND_NORMAL_TO_ARGB8888_WITH_OPA(dsc)) {
531 for(y = 0; y < h; y++) {
532 for(dest_x = 0, src_x = 0; src_x < w; dest_x++, src_x++) {
533 lv_color_8_32_mix(src_buf_al88[src_x].lumi, &dest_buf_c32[dest_x], LV_OPA_MIX2(src_buf_al88[src_x].alpha, opa));
534 }
535 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
536 src_buf_al88 = drawbuf_next_row(src_buf_al88, src_stride);
537 }
538 }
539 }
540 else if(mask_buf && opa >= LV_OPA_MAX) {
541 if(LV_RESULT_INVALID == LV_DRAW_SW_AL88_BLEND_NORMAL_TO_ARGB8888_WITH_MASK(dsc)) {
542 for(y = 0; y < h; y++) {
543 for(dest_x = 0, src_x = 0; src_x < w; dest_x++, src_x++) {
544 lv_color_8_32_mix(src_buf_al88[src_x].lumi, &dest_buf_c32[dest_x], LV_OPA_MIX2(src_buf_al88[src_x].alpha,
545 mask_buf[src_x]));
546 }
547 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
548 src_buf_al88 = drawbuf_next_row(src_buf_al88, src_stride);
549 mask_buf += mask_stride;
550 }
551 }
552 }
553 else if(mask_buf && opa < LV_OPA_MAX) {
554 if(LV_RESULT_INVALID == LV_DRAW_SW_AL88_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA(dsc)) {
555 for(y = 0; y < h; y++) {
556 for(dest_x = 0, src_x = 0; src_x < w; dest_x++, src_x++) {
557 lv_color_8_32_mix(src_buf_al88[src_x].lumi, &dest_buf_c32[dest_x], LV_OPA_MIX3(src_buf_al88[src_x].alpha,
558 mask_buf[src_x], opa));
559 }
560 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
561 src_buf_al88 = drawbuf_next_row(src_buf_al88, src_stride);
562 mask_buf += mask_stride;
563 }
564 }
565 }
566 }
567 else {
568 lv_color32_t src_argb;
569 lv_color_mix_alpha_cache_t cache;
570 lv_color_mix_with_alpha_cache_init(&cache);
571 for(y = 0; y < h; y++) {
572 for(dest_x = 0, src_x = 0; src_x < w; dest_x++, src_x++) {
573 src_argb.red = src_buf_al88[src_x].lumi;
574 src_argb.green = src_buf_al88[src_x].lumi;
575 src_argb.blue = src_buf_al88[src_x].lumi;
576 if(mask_buf == NULL) src_argb.alpha = LV_OPA_MIX2(src_buf_al88[src_x].alpha, opa);
577 else src_argb.alpha = LV_OPA_MIX3(src_buf_al88[src_x].alpha, mask_buf[dest_x], opa);
578 blend_non_normal_pixel(&dest_buf_c32[dest_x], src_argb, dsc->blend_mode, &cache);
579 }
580 if(mask_buf) mask_buf += mask_stride;
581 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
582 src_buf_al88 = drawbuf_next_row(src_buf_al88, src_stride);
583 }
584 }
585 }
586
587 #endif
588
589 #if LV_DRAW_SW_SUPPORT_L8
590
591 static void LV_ATTRIBUTE_FAST_MEM l8_image_blend(lv_draw_sw_blend_image_dsc_t * dsc)
592 {
593 int32_t w = dsc->dest_w;
594 int32_t h = dsc->dest_h;
595 lv_opa_t opa = dsc->opa;
596 lv_color32_t * dest_buf_c32 = dsc->dest_buf;
597 int32_t dest_stride = dsc->dest_stride;
598 const uint8_t * src_buf_l8 = dsc->src_buf;
599 int32_t src_stride = dsc->src_stride;
600 const lv_opa_t * mask_buf = dsc->mask_buf;
601 int32_t mask_stride = dsc->mask_stride;
602
603 int32_t dest_x;
604 int32_t src_x;
605 int32_t y;
606
607 if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
608 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
609 if(LV_RESULT_INVALID == LV_DRAW_SW_L8_BLEND_NORMAL_TO_ARGB8888(dsc)) {
610 for(y = 0; y < h; y++) {
611 for(dest_x = 0, src_x = 0; src_x < w; dest_x++, src_x++) {
612 dest_buf_c32[dest_x].alpha = 0xff;
613 dest_buf_c32[dest_x].red = src_buf_l8[src_x];
614 dest_buf_c32[dest_x].green = src_buf_l8[src_x];
615 dest_buf_c32[dest_x].blue = src_buf_l8[src_x];
616 }
617 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
618 src_buf_l8 = drawbuf_next_row(src_buf_l8, src_stride);
619 }
620 }
621 }
622 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
623 if(LV_RESULT_INVALID == LV_DRAW_SW_L8_BLEND_NORMAL_TO_ARGB8888_WITH_OPA(dsc)) {
624 for(y = 0; y < h; y++) {
625 for(dest_x = 0, src_x = 0; src_x < w; dest_x++, src_x++) {
626 lv_color_8_32_mix(src_buf_l8[src_x], &dest_buf_c32[dest_x], opa);
627 }
628 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
629 src_buf_l8 = drawbuf_next_row(src_buf_l8, src_stride);
630 }
631 }
632 }
633 else if(mask_buf && opa >= LV_OPA_MAX) {
634 if(LV_RESULT_INVALID == LV_DRAW_SW_L8_BLEND_NORMAL_TO_ARGB8888_WITH_MASK(dsc)) {
635 for(y = 0; y < h; y++) {
636 for(dest_x = 0, src_x = 0; src_x < w; dest_x++, src_x++) {
637 lv_color_8_32_mix(src_buf_l8[src_x], &dest_buf_c32[dest_x], mask_buf[src_x]);
638 }
639 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
640 src_buf_l8 = drawbuf_next_row(src_buf_l8, src_stride);
641 mask_buf += mask_stride;
642 }
643 }
644 }
645 else if(mask_buf && opa < LV_OPA_MAX) {
646 if(LV_RESULT_INVALID == LV_DRAW_SW_L8_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA(dsc)) {
647 for(y = 0; y < h; y++) {
648 for(dest_x = 0, src_x = 0; src_x < w; dest_x++, src_x++) {
649 lv_color_8_32_mix(src_buf_l8[src_x], &dest_buf_c32[dest_x], LV_OPA_MIX2(mask_buf[src_x], opa));
650 }
651 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
652 src_buf_l8 = drawbuf_next_row(src_buf_l8, src_stride);
653 mask_buf += mask_stride;
654 }
655 }
656 }
657 }
658 else {
659 lv_color32_t src_argb;
660 lv_color_mix_alpha_cache_t cache;
661 lv_color_mix_with_alpha_cache_init(&cache);
662 for(y = 0; y < h; y++) {
663 for(dest_x = 0, src_x = 0; src_x < w; dest_x++, src_x++) {
664 src_argb.red = src_buf_l8[src_x];
665 src_argb.green = src_buf_l8[src_x];
666 src_argb.blue = src_buf_l8[src_x];
667 if(mask_buf == NULL) src_argb.alpha = opa;
668 else src_argb.alpha = LV_OPA_MIX2(mask_buf[dest_x], opa);
669 blend_non_normal_pixel(&dest_buf_c32[dest_x], src_argb, dsc->blend_mode, &cache);
670 }
671 if(mask_buf) mask_buf += mask_stride;
672 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
673 src_buf_l8 = drawbuf_next_row(src_buf_l8, src_stride);
674 }
675 }
676 }
677
678 #endif
679
680 #if LV_DRAW_SW_SUPPORT_RGB565
681
682 static void LV_ATTRIBUTE_FAST_MEM rgb565_image_blend(lv_draw_sw_blend_image_dsc_t * dsc)
683 {
684 int32_t w = dsc->dest_w;
685 int32_t h = dsc->dest_h;
686 lv_opa_t opa = dsc->opa;
687 lv_color32_t * dest_buf_c32 = dsc->dest_buf;
688 int32_t dest_stride = dsc->dest_stride;
689 const lv_color16_t * src_buf_c16 = (const lv_color16_t *) dsc->src_buf;
690 int32_t src_stride = dsc->src_stride;
691 const lv_opa_t * mask_buf = dsc->mask_buf;
692 int32_t mask_stride = dsc->mask_stride;
693
694 lv_color32_t color_argb;
695 lv_color_mix_alpha_cache_t cache;
696 lv_color_mix_with_alpha_cache_init(&cache);
697
698
699 int32_t x;
700 int32_t y;
701
702 LV_UNUSED(color_argb);
703
704 if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
705 if(mask_buf == NULL) {
706 lv_result_t accelerated;
707 if(opa >= LV_OPA_MAX) {
708 accelerated = LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_ARGB8888(dsc);
709 }
710 else {
711 accelerated = LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_ARGB8888_WITH_OPA(dsc);
712 }
713 if(LV_RESULT_INVALID == accelerated) {
714 color_argb.alpha = opa;
715 for(y = 0; y < h; y++) {
716 for(x = 0; x < w; x++) {
717 color_argb.red = (src_buf_c16[x].red * 2106) >> 8; /*To make it rounded*/
718 color_argb.green = (src_buf_c16[x].green * 1037) >> 8;
719 color_argb.blue = (src_buf_c16[x].blue * 2106) >> 8;
720 dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
721 }
722 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
723 src_buf_c16 = drawbuf_next_row(src_buf_c16, src_stride);
724 }
725 }
726 }
727 else if(mask_buf && opa >= LV_OPA_MAX) {
728 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_ARGB8888_WITH_MASK(dsc)) {
729 for(y = 0; y < h; y++) {
730 for(x = 0; x < w; x++) {
731 color_argb.alpha = mask_buf[x];
732 color_argb.red = (src_buf_c16[x].red * 2106) >> 8; /*To make it rounded*/
733 color_argb.green = (src_buf_c16[x].green * 1037) >> 8;
734 color_argb.blue = (src_buf_c16[x].blue * 2106) >> 8;
735 dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
736 }
737 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
738 src_buf_c16 = drawbuf_next_row(src_buf_c16, src_stride);
739 mask_buf += mask_stride;
740 }
741 }
742 }
743 else {
744 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA(dsc)) {
745 for(y = 0; y < h; y++) {
746 for(x = 0; x < w; x++) {
747 color_argb.alpha = LV_OPA_MIX2(mask_buf[x], opa);
748 color_argb.red = (src_buf_c16[x].red * 2106) >> 8; /*To make it rounded*/
749 color_argb.green = (src_buf_c16[x].green * 1037) >> 8;
750 color_argb.blue = (src_buf_c16[x].blue * 2106) >> 8;
751 dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
752 }
753 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
754 src_buf_c16 = drawbuf_next_row(src_buf_c16, src_stride);
755 mask_buf += mask_stride;
756 }
757 }
758 }
759 }
760 else {
761 lv_color32_t src_argb;
762 for(y = 0; y < h; y++) {
763 for(x = 0; x < w; x++) {
764 src_argb.red = (src_buf_c16[x].red * 2106) >> 8;
765 src_argb.green = (src_buf_c16[x].green * 1037) >> 8;
766 src_argb.blue = (src_buf_c16[x].blue * 2106) >> 8;
767 if(mask_buf == NULL) src_argb.alpha = opa;
768 else src_argb.alpha = LV_OPA_MIX2(mask_buf[x], opa);
769 blend_non_normal_pixel(&dest_buf_c32[x], src_argb, dsc->blend_mode, &cache);
770 }
771 if(mask_buf) mask_buf += mask_stride;
772 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
773 src_buf_c16 = drawbuf_next_row(src_buf_c16, src_stride);
774 }
775 }
776 }
777
778 #endif
779
780 #if LV_DRAW_SW_SUPPORT_RGB565_SWAPPED
781
782 static void LV_ATTRIBUTE_FAST_MEM rgb565_swapped_image_blend(lv_draw_sw_blend_image_dsc_t * dsc)
783 {
784 int32_t w = dsc->dest_w;
785 int32_t h = dsc->dest_h;
786 lv_opa_t opa = dsc->opa;
787 lv_color32_t * dest_buf_c32 = dsc->dest_buf;
788 int32_t dest_stride = dsc->dest_stride;
789 const uint16_t * src_buf_u16 = dsc->src_buf;
790 int32_t src_stride = dsc->src_stride;
791 const lv_opa_t * mask_buf = dsc->mask_buf;
792 int32_t mask_stride = dsc->mask_stride;
793
794 lv_color32_t color_argb;
795 lv_color_mix_alpha_cache_t cache;
796 lv_color_mix_with_alpha_cache_init(&cache);
797
798 int32_t x;
799 int32_t y;
800
801 LV_UNUSED(color_argb);
802
803 uint16_t raw;
804 lv_color16_t px;
805
806 if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
807 if(mask_buf == NULL) {
808 lv_result_t accelerated;
809 if(opa >= LV_OPA_MAX) {
810 accelerated = LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_ARGB8888(dsc);
811 }
812 else {
813 accelerated = LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_ARGB8888_WITH_OPA(dsc);
814 }
815 if(LV_RESULT_INVALID == accelerated) {
816 color_argb.alpha = opa;
817 for(y = 0; y < h; y++) {
818 for(x = 0; x < w; x++) {
819 raw = lv_color_swap_16(src_buf_u16[x]); /* swap byte order */
820 px = lv_color16_from_u16(raw);
821 color_argb.red = (px.red * 2106) >> 8; /*To make it rounded*/
822 color_argb.green = (px.green * 1037) >> 8;
823 color_argb.blue = (px.blue * 2106) >> 8;
824 dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
825 }
826 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
827 src_buf_u16 = drawbuf_next_row(src_buf_u16, src_stride);
828 }
829 }
830 }
831 else if(mask_buf && opa >= LV_OPA_MAX) {
832 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_ARGB8888_WITH_MASK(dsc)) {
833 for(y = 0; y < h; y++) {
834 for(x = 0; x < w; x++) {
835 color_argb.alpha = mask_buf[x];
836 raw = lv_color_swap_16(src_buf_u16[x]); /* swap byte order */
837 px = lv_color16_from_u16(raw);
838 color_argb.red = (px.red * 2106) >> 8; /*To make it rounded*/
839 color_argb.green = (px.green * 1037) >> 8;
840 color_argb.blue = (px.blue * 2106) >> 8;
841 dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
842 }
843 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
844 src_buf_u16 = drawbuf_next_row(src_buf_u16, src_stride);
845 mask_buf += mask_stride;
846 }
847 }
848 }
849 else {
850 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA(dsc)) {
851 for(y = 0; y < h; y++) {
852 for(x = 0; x < w; x++) {
853 color_argb.alpha = LV_OPA_MIX2(mask_buf[x], opa);
854 raw = lv_color_swap_16(src_buf_u16[x]); /* swap byte order */
855 px = lv_color16_from_u16(raw);
856 color_argb.red = (px.red * 2106) >> 8; /*To make it rounded*/
857 color_argb.green = (px.green * 1037) >> 8;
858 color_argb.blue = (px.blue * 2106) >> 8;
859 dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
860 }
861 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
862 src_buf_u16 = drawbuf_next_row(src_buf_u16, src_stride);
863 mask_buf += mask_stride;
864 }
865 }
866 }
867 }
868 else {
869 lv_color32_t src_argb;
870 for(y = 0; y < h; y++) {
871 for(x = 0; x < w; x++) {
872 raw = lv_color_swap_16(src_buf_u16[x]); /* swap byte order */
873 px = lv_color16_from_u16(raw);
874 src_argb.red = (px.red * 2106) >> 8;
875 src_argb.green = (px.green * 1037) >> 8;
876 src_argb.blue = (px.blue * 2106) >> 8;
877 if(mask_buf == NULL) src_argb.alpha = opa;
878 else src_argb.alpha = LV_OPA_MIX2(mask_buf[x], opa);
879 blend_non_normal_pixel(&dest_buf_c32[x], src_argb, dsc->blend_mode, &cache);
880 }
881 if(mask_buf) mask_buf += mask_stride;
882 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
883 src_buf_u16 = drawbuf_next_row(src_buf_u16, src_stride);
884 }
885 }
886 }
887
888 #endif
889
890 #if LV_DRAW_SW_SUPPORT_RGB888 || LV_DRAW_SW_SUPPORT_XRGB8888
891
892 static void LV_ATTRIBUTE_FAST_MEM rgb888_image_blend(lv_draw_sw_blend_image_dsc_t * dsc, const uint8_t src_px_size)
893 {
894 int32_t w = dsc->dest_w;
895 int32_t h = dsc->dest_h;
896 lv_opa_t opa = dsc->opa;
897 lv_color32_t * dest_buf_c32 = dsc->dest_buf;
898 int32_t dest_stride = dsc->dest_stride;
899 const uint8_t * src_buf = dsc->src_buf;
900 int32_t src_stride = dsc->src_stride;
901 const lv_opa_t * mask_buf = dsc->mask_buf;
902 int32_t mask_stride = dsc->mask_stride;
903
904 lv_color32_t color_argb;
905 lv_color_mix_alpha_cache_t cache;
906 lv_color_mix_with_alpha_cache_init(&cache);
907
908 int32_t dest_x;
909 int32_t src_x;
910 int32_t y;
911
912 LV_UNUSED(color_argb);
913
914 if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
915 /*Special case*/
916 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
917 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_ARGB8888(dsc, src_px_size)) {
918 if(src_px_size == 4) {
919 uint32_t line_in_bytes = w * 4;
920 for(y = 0; y < h; y++) {
921 lv_memcpy(dest_buf_c32, src_buf, line_in_bytes);
922 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
923 src_buf = drawbuf_next_row(src_buf, src_stride);
924 }
925 }
926 else if(src_px_size == 3) {
927 for(y = 0; y < h; y++) {
928 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += 3) {
929 dest_buf_c32[dest_x].red = src_buf[src_x + 2];
930 dest_buf_c32[dest_x].green = src_buf[src_x + 1];
931 dest_buf_c32[dest_x].blue = src_buf[src_x + 0];
932 dest_buf_c32[dest_x].alpha = 0xff;
933 }
934 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
935 src_buf = drawbuf_next_row(src_buf, src_stride);
936 }
937 }
938 }
939 }
940 if(mask_buf == NULL && opa < LV_OPA_MAX) {
941 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_ARGB8888_WITH_OPA(dsc, src_px_size)) {
942 color_argb.alpha = opa;
943 for(y = 0; y < h; y++) {
944 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += src_px_size) {
945 color_argb.red = src_buf[src_x + 2];
946 color_argb.green = src_buf[src_x + 1];
947 color_argb.blue = src_buf[src_x + 0];
948 dest_buf_c32[dest_x] = lv_color_32_32_mix(color_argb, dest_buf_c32[dest_x], &cache);
949 }
950 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
951 src_buf = drawbuf_next_row(src_buf, src_stride);
952 }
953 }
954 }
955 if(mask_buf && opa >= LV_OPA_MAX) {
956 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_ARGB8888_WITH_MASK(dsc, src_px_size)) {
957 for(y = 0; y < h; y++) {
958 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += src_px_size) {
959 color_argb.alpha = mask_buf[dest_x];
960 color_argb.red = src_buf[src_x + 2];
961 color_argb.green = src_buf[src_x + 1];
962 color_argb.blue = src_buf[src_x + 0];
963 dest_buf_c32[dest_x] = lv_color_32_32_mix(color_argb, dest_buf_c32[dest_x], &cache);
964 }
965 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
966 src_buf = drawbuf_next_row(src_buf, src_stride);
967 mask_buf += mask_stride;
968 }
969 }
970 }
971 if(mask_buf && opa < LV_OPA_MAX) {
972 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA(dsc, src_px_size)) {
973 for(y = 0; y < h; y++) {
974 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += src_px_size) {
975 color_argb.alpha = (opa * mask_buf[dest_x]) >> 8;
976 color_argb.red = src_buf[src_x + 2];
977 color_argb.green = src_buf[src_x + 1];
978 color_argb.blue = src_buf[src_x + 0];
979 dest_buf_c32[dest_x] = lv_color_32_32_mix(color_argb, dest_buf_c32[dest_x], &cache);
980 }
981 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
982 src_buf = drawbuf_next_row(src_buf, src_stride);
983 mask_buf += mask_stride;
984 }
985 }
986 }
987 }
988 else {
989 lv_color32_t src_argb;
990 for(y = 0; y < h; y++) {
991 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += src_px_size) {
992 src_argb.red = src_buf[src_x + 2];
993 src_argb.green = src_buf[src_x + 1];
994 src_argb.blue = src_buf[src_x + 0];
995 if(mask_buf == NULL) src_argb.alpha = opa;
996 else src_argb.alpha = LV_OPA_MIX2(mask_buf[dest_x], opa);
997
998 blend_non_normal_pixel(&dest_buf_c32[dest_x], src_argb, dsc->blend_mode, &cache);
999 }
1000 if(mask_buf) mask_buf += mask_stride;
1001 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
1002 src_buf = drawbuf_next_row(src_buf, src_stride);
1003 }
1004 }
1005 }
1006
1007 #endif
1008
1009 static void LV_ATTRIBUTE_FAST_MEM argb8888_image_blend(lv_draw_sw_blend_image_dsc_t * dsc)
1010 {
1011 int32_t w = dsc->dest_w;
1012 int32_t h = dsc->dest_h;
1013 lv_opa_t opa = dsc->opa;
1014 lv_color32_t * dest_buf_c32 = dsc->dest_buf;
1015 int32_t dest_stride = dsc->dest_stride;
1016 const lv_color32_t * src_buf_c32 = dsc->src_buf;
1017 int32_t src_stride = dsc->src_stride;
1018 const lv_opa_t * mask_buf = dsc->mask_buf;
1019 int32_t mask_stride = dsc->mask_stride;
1020
1021 lv_color32_t color_argb;
1022 lv_color_mix_alpha_cache_t cache;
1023 lv_color_mix_with_alpha_cache_init(&cache);
1024
1025 int32_t x;
1026 int32_t y;
1027
1028 if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
1029 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
1030 if(LV_RESULT_INVALID == LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_ARGB8888(dsc)) {
1031 for(y = 0; y < h; y++) {
1032 for(x = 0; x < w; x++) {
1033 dest_buf_c32[x] = lv_color_32_32_mix(src_buf_c32[x], dest_buf_c32[x], &cache);
1034 }
1035 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
1036 src_buf_c32 = drawbuf_next_row(src_buf_c32, src_stride);
1037 }
1038 }
1039 }
1040 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
1041 if(LV_RESULT_INVALID == LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_ARGB8888_WITH_OPA(dsc)) {
1042 for(y = 0; y < h; y++) {
1043 for(x = 0; x < w; x++) {
1044 color_argb = src_buf_c32[x];
1045 color_argb.alpha = LV_OPA_MIX2(color_argb.alpha, opa);
1046 dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
1047 }
1048 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
1049 src_buf_c32 = drawbuf_next_row(src_buf_c32, src_stride);
1050 }
1051 }
1052 }
1053 else if(mask_buf && opa >= LV_OPA_MAX) {
1054 if(LV_RESULT_INVALID == LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_ARGB8888_WITH_MASK(dsc)) {
1055 for(y = 0; y < h; y++) {
1056 for(x = 0; x < w; x++) {
1057 color_argb = src_buf_c32[x];
1058 color_argb.alpha = LV_OPA_MIX2(color_argb.alpha, mask_buf[x]);
1059 dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
1060 }
1061 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
1062 src_buf_c32 = drawbuf_next_row(src_buf_c32, src_stride);
1063 mask_buf += mask_stride;
1064 }
1065 }
1066 }
1067 else if(mask_buf && opa < LV_OPA_MAX) {
1068 if(LV_RESULT_INVALID == LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA(dsc)) {
1069 for(y = 0; y < h; y++) {
1070 for(x = 0; x < w; x++) {
1071 color_argb = src_buf_c32[x];
1072 color_argb.alpha = LV_OPA_MIX3(color_argb.alpha, opa, mask_buf[x]);
1073 dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
1074 }
1075 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
1076 src_buf_c32 = drawbuf_next_row(src_buf_c32, src_stride);
1077 mask_buf += mask_stride;
1078 }
1079 }
1080 }
1081 }
1082 else {
1083 for(y = 0; y < h; y++) {
1084 for(x = 0; x < w; x++) {
1085 color_argb = src_buf_c32[x];
1086 if(mask_buf == NULL) color_argb.alpha = LV_OPA_MIX2(color_argb.alpha, opa);
1087 else color_argb.alpha = LV_OPA_MIX3(color_argb.alpha, mask_buf[x], opa);
1088 blend_non_normal_pixel(&dest_buf_c32[x], color_argb, dsc->blend_mode, &cache);
1089 }
1090 if(mask_buf) mask_buf += mask_stride;
1091 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
1092 src_buf_c32 = drawbuf_next_row(src_buf_c32, src_stride);
1093 }
1094 }
1095 }
1096
1097 #if LV_DRAW_SW_SUPPORT_ARGB8888_PREMULTIPLIED
1098
1099 static void LV_ATTRIBUTE_FAST_MEM argb8888_premultiplied_image_blend(lv_draw_sw_blend_image_dsc_t * dsc)
1100 {
1101 int32_t w = dsc->dest_w;
1102 int32_t h = dsc->dest_h;
1103 lv_opa_t opa = dsc->opa;
1104 lv_color32_t * dest_buf_c32 = dsc->dest_buf;
1105 int32_t dest_stride = dsc->dest_stride;
1106 const lv_color32_t * src_buf_c32 = dsc->src_buf;
1107 int32_t src_stride = dsc->src_stride;
1108 const lv_opa_t * mask_buf = dsc->mask_buf;
1109 int32_t mask_stride = dsc->mask_stride;
1110
1111 lv_color32_t color_argb;
1112 lv_color_mix_alpha_cache_t cache;
1113 lv_color_mix_with_alpha_cache_init(&cache);
1114
1115 int32_t x;
1116 int32_t y;
1117
1118 /* Process the normal blend mode (for premultiplied alpha) */
1119 if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
1120 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
1121 if(LV_RESULT_INVALID == LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_ARGB8888(dsc)) {
1122 for(y = 0; y < h; y++) {
1123 for(x = 0; x < w; x++) {
1124 /* Unpremultiply the source color by using the reciprocal of the alpha */
1125 color_argb = src_buf_c32[x];
1126 if(color_argb.alpha != 0) {
1127 uint16_t reciprocal_alpha = (255 * 256) / color_argb.alpha;
1128 color_argb.red = (color_argb.red * reciprocal_alpha) >> 8;
1129 color_argb.green = (color_argb.green * reciprocal_alpha) >> 8;
1130 color_argb.blue = (color_argb.blue * reciprocal_alpha) >> 8;
1131
1132 /* Blend with destination */
1133 dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
1134 }
1135 }
1136 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
1137 src_buf_c32 = drawbuf_next_row(src_buf_c32, src_stride);
1138 }
1139 }
1140 }
1141 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
1142 if(LV_RESULT_INVALID == LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_ARGB8888_WITH_OPA(dsc)) {
1143 for(y = 0; y < h; y++) {
1144 for(x = 0; x < w; x++) {
1145 /* Unpremultiply the source color by using the reciprocal of the alpha */
1146 color_argb = src_buf_c32[x];
1147 if(color_argb.alpha != 0) {
1148 uint16_t reciprocal_alpha = (255 * 256) / color_argb.alpha;
1149 color_argb.red = (color_argb.red * reciprocal_alpha) >> 8;
1150 color_argb.green = (color_argb.green * reciprocal_alpha) >> 8;
1151 color_argb.blue = (color_argb.blue * reciprocal_alpha) >> 8;
1152 color_argb.alpha = LV_OPA_MIX2(color_argb.alpha, opa);
1153 }
1154
1155 /* Blend with destination */
1156 dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
1157 }
1158 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
1159 src_buf_c32 = drawbuf_next_row(src_buf_c32, src_stride);
1160 }
1161 }
1162 }
1163 else if(mask_buf && opa >= LV_OPA_MAX) {
1164 if(LV_RESULT_INVALID == LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_ARGB8888_WITH_MASK(dsc)) {
1165 for(y = 0; y < h; y++) {
1166 for(x = 0; x < w; x++) {
1167 /* Unpremultiply the source color by using the reciprocal of the alpha */
1168 color_argb = src_buf_c32[x];
1169 if(color_argb.alpha != 0) {
1170 uint16_t reciprocal_alpha = (255 * 256) / color_argb.alpha;
1171 color_argb.red = (color_argb.red * reciprocal_alpha) >> 8;
1172 color_argb.green = (color_argb.green * reciprocal_alpha) >> 8;
1173 color_argb.blue = (color_argb.blue * reciprocal_alpha) >> 8;
1174 color_argb.alpha = LV_OPA_MIX2(color_argb.alpha, mask_buf[x]);
1175 }
1176
1177 /* Blend with destination */
1178 dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
1179 }
1180 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
1181 src_buf_c32 = drawbuf_next_row(src_buf_c32, src_stride);
1182 mask_buf += mask_stride;
1183 }
1184 }
1185 }
1186 else if(mask_buf && opa < LV_OPA_MAX) {
1187 if(LV_RESULT_INVALID == LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_ARGB8888_MIX_MASK_OPA(dsc)) {
1188 for(y = 0; y < h; y++) {
1189 for(x = 0; x < w; x++) {
1190 /* Unpremultiply the source color by using the reciprocal of the alpha */
1191 color_argb = src_buf_c32[x];
1192 if(color_argb.alpha != 0) {
1193 uint16_t reciprocal_alpha = (255 * 256) / color_argb.alpha;
1194 color_argb.red = (color_argb.red * reciprocal_alpha) >> 8;
1195 color_argb.green = (color_argb.green * reciprocal_alpha) >> 8;
1196 color_argb.blue = (color_argb.blue * reciprocal_alpha) >> 8;
1197 color_argb.alpha = LV_OPA_MIX3(color_argb.alpha, opa, mask_buf[x]);
1198 }
1199
1200 /* Blend with destination */
1201 dest_buf_c32[x] = lv_color_32_32_mix(color_argb, dest_buf_c32[x], &cache);
1202 }
1203 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
1204 src_buf_c32 = drawbuf_next_row(src_buf_c32, src_stride);
1205 mask_buf += mask_stride;
1206 }
1207 }
1208 }
1209 }
1210 else {
1211 for(y = 0; y < h; y++) {
1212 for(x = 0; x < w; x++) {
1213 /* Unpremultiply the source color by using the reciprocal of the alpha */
1214 color_argb = src_buf_c32[x];
1215 if(color_argb.alpha != 0) {
1216 uint16_t reciprocal_alpha = (255 * 256) / color_argb.alpha;
1217 color_argb.red = (color_argb.red * reciprocal_alpha) >> 8;
1218 color_argb.green = (color_argb.green * reciprocal_alpha) >> 8;
1219 color_argb.blue = (color_argb.blue * reciprocal_alpha) >> 8;
1220 }
1221 if(mask_buf == NULL) {
1222 color_argb.alpha = LV_OPA_MIX2(color_argb.alpha, opa);
1223 }
1224 else {
1225 color_argb.alpha = LV_OPA_MIX3(color_argb.alpha, mask_buf[x], opa);
1226 }
1227
1228 /* Blend with destination using non-normal blend mode */
1229 blend_non_normal_pixel(&dest_buf_c32[x], color_argb, dsc->blend_mode, &cache);
1230 }
1231 if(mask_buf) mask_buf += mask_stride;
1232 dest_buf_c32 = drawbuf_next_row(dest_buf_c32, dest_stride);
1233 src_buf_c32 = drawbuf_next_row(src_buf_c32, src_stride);
1234 }
1235 }
1236 }
1237
1238 #endif
1239
1240 static inline void LV_ATTRIBUTE_FAST_MEM lv_color_8_32_mix(const uint8_t src, lv_color32_t * dest, uint8_t mix)
1241 {
1242
1243 if(mix == 0) return;
1244
1245 dest->alpha = 255;
1246 if(mix >= LV_OPA_MAX) {
1247 dest->red = src;
1248 dest->green = src;
1249 dest->blue = src;
1250 }
1251 else {
1252 lv_opa_t mix_inv = 255 - mix;
1253 dest->red = (uint32_t)((uint32_t)src * mix + dest->red * mix_inv) >> 8;
1254 dest->green = (uint32_t)((uint32_t)src * mix + dest->green * mix_inv) >> 8;
1255 dest->blue = (uint32_t)((uint32_t)src * mix + dest->blue * mix_inv) >> 8;
1256 }
1257 }
1258
1259 static inline lv_color32_t LV_ATTRIBUTE_FAST_MEM lv_color_32_32_mix(lv_color32_t fg, lv_color32_t bg,
1260 lv_color_mix_alpha_cache_t * cache)
1261 {
1262 /*Pick the foreground if it's fully opaque or the Background is fully transparent*/
1263 if(fg.alpha >= LV_OPA_MAX || bg.alpha <= LV_OPA_MIN) {
1264 return fg;
1265 }
1266 /*Transparent foreground: use the Background*/
1267 else if(fg.alpha <= LV_OPA_MIN) {
1268 return bg;
1269 }
1270 /*Opaque background: use simple mix*/
1271 else if(bg.alpha == 255) {
1272 return lv_color_mix32(fg, bg);
1273 }
1274 /*Both colors have alpha. Expensive calculation need to be applied*/
1275 else {
1276 /*Save the parameters and the result. If they will be asked again don't compute again*/
1277
1278 /*Update the ratio and the result alpha value if the input alpha values change*/
1279 if(bg.alpha != cache->bg_saved.alpha || fg.alpha != cache->fg_saved.alpha) {
1280 /*Info:
1281 * https://en.wikipedia.org/wiki/Alpha_compositing#Analytical_derivation_of_the_over_operator*/
1282 cache->res_alpha_saved = 255 - LV_OPA_MIX2(255 - fg.alpha, 255 - bg.alpha);
1283 LV_ASSERT(cache->res_alpha_saved != 0);
1284 cache->ratio_saved = (uint32_t)((uint32_t)fg.alpha * 255) / cache->res_alpha_saved;
1285 }
1286
1287 if(!lv_color32_eq(bg, cache->bg_saved) || !lv_color32_eq(fg, cache->fg_saved)) {
1288 cache->fg_saved = fg;
1289 cache->bg_saved = bg;
1290 fg.alpha = cache->ratio_saved;
1291 cache->res_saved = lv_color_mix32(fg, bg);
1292 cache->res_saved.alpha = cache->res_alpha_saved;
1293 }
1294
1295 return cache->res_saved;
1296 }
1297 }
1298
1299 void lv_color_mix_with_alpha_cache_init(lv_color_mix_alpha_cache_t * cache)
1300 {
1301 lv_memzero(&cache->fg_saved, sizeof(lv_color32_t));
1302 lv_memzero(&cache->bg_saved, sizeof(lv_color32_t));
1303 lv_memzero(&cache->res_saved, sizeof(lv_color32_t));
1304 cache->res_alpha_saved = 255;
1305 cache->ratio_saved = 255;
1306 }
1307
1308 #if LV_DRAW_SW_SUPPORT_I1
1309
1310 static inline uint8_t LV_ATTRIBUTE_FAST_MEM get_bit(const uint8_t * buf, int32_t bit_idx)
1311 {
1312 return (buf[bit_idx / 8] >> (7 - (bit_idx % 8))) & 1;
1313 }
1314
1315 #endif
1316
1317 static inline void LV_ATTRIBUTE_FAST_MEM blend_non_normal_pixel(lv_color32_t * dest, lv_color32_t src,
1318 lv_blend_mode_t mode, lv_color_mix_alpha_cache_t * cache)
1319 {
1320 lv_color32_t res;
1321 switch(mode) {
1322 case LV_BLEND_MODE_ADDITIVE:
1323 res.red = LV_MIN(dest->red + src.red, 255);
1324 res.green = LV_MIN(dest->green + src.green, 255);
1325 res.blue = LV_MIN(dest->blue + src.blue, 255);
1326 break;
1327 case LV_BLEND_MODE_SUBTRACTIVE:
1328 res.red = LV_MAX(dest->red - src.red, 0);
1329 res.green = LV_MAX(dest->green - src.green, 0);
1330 res.blue = LV_MAX(dest->blue - src.blue, 0);
1331 break;
1332 case LV_BLEND_MODE_MULTIPLY:
1333 res.red = (dest->red * src.red) >> 8;
1334 res.green = (dest->green * src.green) >> 8;
1335 res.blue = (dest->blue * src.blue) >> 8;
1336 break;
1337 case LV_BLEND_MODE_DIFFERENCE:
1338 res.red = LV_ABS(dest->red - src.red);
1339 res.green = LV_ABS(dest->green - src.green);
1340 res.blue = LV_ABS(dest->blue - src.blue);
1341 break;
1342 default:
1343 LV_LOG_WARN("Not supported blend mode: %d", mode);
1344 return;
1345 }
1346 res.alpha = src.alpha;
1347 *dest = lv_color_32_32_mix(res, *dest, cache);
1348 }
1349
1350 static inline void * LV_ATTRIBUTE_FAST_MEM drawbuf_next_row(const void * buf, uint32_t stride)
1351 {
1352 return (void *)((uint8_t *)buf + stride);
1353 }
1354
1355 #if LV_DRAW_SW_SUPPORT_RGB565_SWAPPED
1356 static inline lv_color16_t LV_ATTRIBUTE_FAST_MEM lv_color16_from_u16(uint16_t raw)
1357 {
1358 lv_color16_t c;
1359 c.red = (raw >> 11) & 0x1F;
1360 c.green = (raw >> 5) & 0x3F;
1361 c.blue = raw & 0x1F;
1362 return c;
1363 }
1364 #endif
1365
1366 #endif /* LV_DRAW_SW_SUPPORT_ARGB8888 */
1367
1368 #endif /* LV_USE_DRAW_SW */