Debian Codegraph @

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

raw symbols SCIP
1 /**
2 * @file lv_draw_sw_blend_to_rgb565.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9 #include "lv_draw_sw_blend_to_rgb565.h"
10 #if LV_USE_DRAW_SW
11
12 #if LV_DRAW_SW_SUPPORT_RGB565
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 /**********************
38 * STATIC PROTOTYPES
39 **********************/
40
41 #if LV_DRAW_SW_SUPPORT_AL88
42 static void /* LV_ATTRIBUTE_FAST_MEM */ al88_image_blend(lv_draw_sw_blend_image_dsc_t * dsc);
43 #endif
44
45 #if LV_DRAW_SW_SUPPORT_I1
46 static void /* LV_ATTRIBUTE_FAST_MEM */ i1_image_blend(lv_draw_sw_blend_image_dsc_t * dsc);
47
48 static inline uint8_t /* LV_ATTRIBUTE_FAST_MEM */ get_bit(const uint8_t * buf, int32_t bit_idx);
49 #endif
50
51 #if LV_DRAW_SW_SUPPORT_L8
52 static void /* LV_ATTRIBUTE_FAST_MEM */ l8_image_blend(lv_draw_sw_blend_image_dsc_t * dsc);
53 #endif
54
55 static void /* LV_ATTRIBUTE_FAST_MEM */ rgb565_image_blend(lv_draw_sw_blend_image_dsc_t * dsc);
56
57 #if LV_DRAW_SW_SUPPORT_RGB565_SWAPPED
58 static void /* LV_ATTRIBUTE_FAST_MEM */ rgb565_swapped_image_blend(lv_draw_sw_blend_image_dsc_t * dsc);
59 #endif
60
61 #if LV_DRAW_SW_SUPPORT_RGB888 || LV_DRAW_SW_SUPPORT_XRGB8888
62 static void /* LV_ATTRIBUTE_FAST_MEM */ rgb888_image_blend(lv_draw_sw_blend_image_dsc_t * dsc,
63 const uint8_t src_px_size);
64 #endif
65
66 #if LV_DRAW_SW_SUPPORT_ARGB8888
67 static void /* LV_ATTRIBUTE_FAST_MEM */ argb8888_image_blend(lv_draw_sw_blend_image_dsc_t * dsc);
68 #endif
69
70 #if LV_DRAW_SW_SUPPORT_ARGB8888_PREMULTIPLIED
71 static void /* LV_ATTRIBUTE_FAST_MEM */ argb8888_premultiplied_image_blend(lv_draw_sw_blend_image_dsc_t * dsc);
72 #endif
73
74 static inline uint16_t /* LV_ATTRIBUTE_FAST_MEM */ l8_to_rgb565(const uint8_t c1);
75
76 static inline uint16_t /* LV_ATTRIBUTE_FAST_MEM */ lv_color_8_16_mix(const uint8_t c1, uint16_t c2, uint8_t mix);
77
78 static inline uint16_t /* LV_ATTRIBUTE_FAST_MEM */ lv_color_24_16_mix(const uint8_t * c1, uint16_t c2, uint8_t mix);
79
80 static inline void * /* LV_ATTRIBUTE_FAST_MEM */ drawbuf_next_row(const void * buf, uint32_t stride);
81
82 #if LV_DRAW_SW_SUPPORT_RGB565_SWAPPED
83 static inline lv_color16_t /* LV_ATTRIBUTE_FAST_MEM */ lv_color16_from_u16(uint16_t raw);
84 #endif
85
86 /**********************
87 * STATIC VARIABLES
88 **********************/
89
90 /**********************
91 * MACROS
92 **********************/
93
94 #ifndef LV_DRAW_SW_COLOR_BLEND_TO_RGB565
95 #define LV_DRAW_SW_COLOR_BLEND_TO_RGB565(...) LV_RESULT_INVALID
96 #endif
97
98 #ifndef LV_DRAW_SW_COLOR_BLEND_TO_RGB565_WITH_OPA
99 #define LV_DRAW_SW_COLOR_BLEND_TO_RGB565_WITH_OPA(...) LV_RESULT_INVALID
100 #endif
101
102 #ifndef LV_DRAW_SW_COLOR_BLEND_TO_RGB565_WITH_MASK
103 #define LV_DRAW_SW_COLOR_BLEND_TO_RGB565_WITH_MASK(...) LV_RESULT_INVALID
104 #endif
105
106 #ifndef LV_DRAW_SW_COLOR_BLEND_TO_RGB565_MIX_MASK_OPA
107 #define LV_DRAW_SW_COLOR_BLEND_TO_RGB565_MIX_MASK_OPA(...) LV_RESULT_INVALID
108 #endif
109
110 #ifndef LV_DRAW_SW_L8_BLEND_NORMAL_TO_RGB565
111 #define LV_DRAW_SW_L8_BLEND_NORMAL_TO_RGB565(...) LV_RESULT_INVALID
112 #endif
113
114 #ifndef LV_DRAW_SW_L8_BLEND_NORMAL_TO_RGB565_WITH_OPA
115 #define LV_DRAW_SW_L8_BLEND_NORMAL_TO_RGB565_WITH_OPA(...) LV_RESULT_INVALID
116 #endif
117
118 #ifndef LV_DRAW_SW_L8_BLEND_NORMAL_TO_RGB565_WITH_MASK
119 #define LV_DRAW_SW_L8_BLEND_NORMAL_TO_RGB565_WITH_MASK(...) LV_RESULT_INVALID
120 #endif
121
122 #ifndef LV_DRAW_SW_L8_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA
123 #define LV_DRAW_SW_L8_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA(...) LV_RESULT_INVALID
124 #endif
125
126 #ifndef LV_DRAW_SW_AL88_BLEND_NORMAL_TO_RGB565
127 #define LV_DRAW_SW_AL88_BLEND_NORMAL_TO_RGB565(...) LV_RESULT_INVALID
128 #endif
129
130 #ifndef LV_DRAW_SW_AL88_BLEND_NORMAL_TO_RGB565_WITH_OPA
131 #define LV_DRAW_SW_AL88_BLEND_NORMAL_TO_RGB565_WITH_OPA(...) LV_RESULT_INVALID
132 #endif
133
134 #ifndef LV_DRAW_SW_AL88_BLEND_NORMAL_TO_RGB565_WITH_MASK
135 #define LV_DRAW_SW_AL88_BLEND_NORMAL_TO_RGB565_WITH_MASK(...) LV_RESULT_INVALID
136 #endif
137
138 #ifndef LV_DRAW_SW_AL88_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA
139 #define LV_DRAW_SW_AL88_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA(...) LV_RESULT_INVALID
140 #endif
141
142 #ifndef LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_RGB565
143 #define LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_RGB565(...) LV_RESULT_INVALID
144 #endif
145
146 #ifndef LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_RGB565_WITH_OPA
147 #define LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_RGB565_WITH_OPA(...) LV_RESULT_INVALID
148 #endif
149
150 #ifndef LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_RGB565_WITH_MASK
151 #define LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_RGB565_WITH_MASK(...) LV_RESULT_INVALID
152 #endif
153
154 #ifndef LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA
155 #define LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA(...) LV_RESULT_INVALID
156 #endif
157
158 #ifndef LV_DRAW_SW_RGB565_SWAPPED_BLEND_NORMAL_TO_RGB565
159 #define LV_DRAW_SW_RGB565_SWAPPED_BLEND_NORMAL_TO_RGB565(...) LV_RESULT_INVALID
160 #endif
161
162 #ifndef LV_DRAW_SW_RGB565_SWAPPED_BLEND_NORMAL_TO_RGB565_WITH_OPA
163 #define LV_DRAW_SW_RGB565_SWAPPED_BLEND_NORMAL_TO_RGB565_WITH_OPA(...) LV_RESULT_INVALID
164 #endif
165
166 #ifndef LV_DRAW_SW_RGB565_SWAPPED_BLEND_NORMAL_TO_RGB565_WITH_MASK
167 #define LV_DRAW_SW_RGB565_SWAPPED_BLEND_NORMAL_TO_RGB565_WITH_MASK(...) LV_RESULT_INVALID
168 #endif
169
170 #ifndef LV_DRAW_SW_RGB565_SWAPPED_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA
171 #define LV_DRAW_SW_RGB565_SWAPPED_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA(...) LV_RESULT_INVALID
172 #endif
173
174 #ifndef LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_RGB565
175 #define LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_RGB565(...) LV_RESULT_INVALID
176 #endif
177
178 #ifndef LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_RGB565_WITH_OPA
179 #define LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_RGB565_WITH_OPA(...) LV_RESULT_INVALID
180 #endif
181
182 #ifndef LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_RGB565_WITH_MASK
183 #define LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_RGB565_WITH_MASK(...) LV_RESULT_INVALID
184 #endif
185
186 #ifndef LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA
187 #define LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA(...) LV_RESULT_INVALID
188 #endif
189
190 #ifndef LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB565
191 #define LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB565(...) LV_RESULT_INVALID
192 #endif
193
194 #ifndef LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB565_WITH_OPA
195 #define LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB565_WITH_OPA(...) LV_RESULT_INVALID
196 #endif
197
198 #ifndef LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB565_WITH_MASK
199 #define LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB565_WITH_MASK(...) LV_RESULT_INVALID
200 #endif
201
202 #ifndef LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA
203 #define LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA(...) LV_RESULT_INVALID
204 #endif
205
206 #ifndef LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_RGB565
207 #define LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_RGB565(...) LV_RESULT_INVALID
208 #endif
209
210 #ifndef LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_RGB565_WITH_OPA
211 #define LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_RGB565_WITH_OPA(...) LV_RESULT_INVALID
212 #endif
213
214 #ifndef LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_RGB565_WITH_MASK
215 #define LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_RGB565_WITH_MASK(...) LV_RESULT_INVALID
216 #endif
217
218 #ifndef LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA
219 #define LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA(...) LV_RESULT_INVALID
220 #endif
221
222 #ifndef LV_DRAW_SW_I1_BLEND_NORMAL_TO_RGB565
223 #define LV_DRAW_SW_I1_BLEND_NORMAL_TO_RGB565(...) LV_RESULT_INVALID
224 #endif
225
226 #ifndef LV_DRAW_SW_I1_BLEND_NORMAL_TO_RGB565_WITH_OPA
227 #define LV_DRAW_SW_I1_BLEND_NORMAL_TO_RGB565_WITH_OPA(...) LV_RESULT_INVALID
228 #endif
229
230 #ifndef LV_DRAW_SW_I1_BLEND_NORMAL_TO_RGB565_WITH_MASK
231 #define LV_DRAW_SW_I1_BLEND_NORMAL_TO_RGB565_WITH_MASK(...) LV_RESULT_INVALID
232 #endif
233
234 #ifndef LV_DRAW_SW_I1_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA
235 #define LV_DRAW_SW_I1_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA(...) LV_RESULT_INVALID
236 #endif
237
238 /**********************
239 * GLOBAL FUNCTIONS
240 **********************/
241
242 /**
243 * Fill an area with a color.
244 * Supports normal fill, fill with opacity, fill with mask, and fill with mask and opacity.
245 * dest_buf and color have native color depth. (RGB565, RGB888, XRGB8888)
246 * The background (dest_buf) cannot have alpha channel
247 * @param dest_buf
248 * @param dest_area
249 * @param dest_stride
250 * @param color
251 * @param opa
252 * @param mask
253 * @param mask_stride
254 */
255 void LV_ATTRIBUTE_FAST_MEM lv_draw_sw_blend_color_to_rgb565(lv_draw_sw_blend_fill_dsc_t * dsc)
256 {
257 int32_t w = dsc->dest_w;
258 int32_t h = dsc->dest_h;
259 uint16_t color16 = lv_color_to_u16(dsc->color);
260 lv_opa_t opa = dsc->opa;
261 const lv_opa_t * mask = dsc->mask_buf;
262 int32_t mask_stride = dsc->mask_stride;
263 uint16_t * dest_buf_u16 = dsc->dest_buf;
264 int32_t dest_stride = dsc->dest_stride;
265
266 int32_t x;
267 int32_t y;
268
269 LV_UNUSED(w);
270 LV_UNUSED(h);
271 LV_UNUSED(x);
272 LV_UNUSED(y);
273 LV_UNUSED(opa);
274 LV_UNUSED(mask);
275 LV_UNUSED(color16);
276 LV_UNUSED(mask_stride);
277 LV_UNUSED(dest_stride);
278 LV_UNUSED(dest_buf_u16);
279
280 /*Simple fill*/
281 if(mask == NULL && opa >= LV_OPA_MAX) {
282 if(LV_RESULT_INVALID == LV_DRAW_SW_COLOR_BLEND_TO_RGB565(dsc)) {
283 for(y = 0; y < h; y++) {
284 uint16_t * dest_end_final = dest_buf_u16 + w;
285 uint32_t * dest_end_mid = (uint32_t *)((uint16_t *) dest_buf_u16 + ((w - 1) & ~(0xF)));
286 if((lv_uintptr_t)&dest_buf_u16[0] & 0x3) {
287 dest_buf_u16[0] = color16;
288 dest_buf_u16++;
289 }
290
291 uint32_t c32 = (uint32_t)color16 + ((uint32_t)color16 << 16);
292 uint32_t * dest32 = (uint32_t *)dest_buf_u16;
293 while(dest32 < dest_end_mid) {
294 dest32[0] = c32;
295 dest32[1] = c32;
296 dest32[2] = c32;
297 dest32[3] = c32;
298 dest32[4] = c32;
299 dest32[5] = c32;
300 dest32[6] = c32;
301 dest32[7] = c32;
302 dest32 += 8;
303 }
304
305 dest_buf_u16 = (uint16_t *)dest32;
306
307 while(dest_buf_u16 < dest_end_final) {
308 *dest_buf_u16 = color16;
309 dest_buf_u16++;
310 }
311
312 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
313 dest_buf_u16 -= w;
314 }
315 }
316
317 }
318 /*Opacity only*/
319 else if(mask == NULL && opa < LV_OPA_MAX) {
320 if(LV_RESULT_INVALID == LV_DRAW_SW_COLOR_BLEND_TO_RGB565_WITH_OPA(dsc)) {
321 uint32_t last_dest32_color = dest_buf_u16[0] + 1; /*Set to value which is not equal to the first pixel*/
322 uint32_t last_res32_color = 0;
323
324 for(y = 0; y < h; y++) {
325 x = 0;
326 if((lv_uintptr_t)&dest_buf_u16[0] & 0x3) {
327 dest_buf_u16[0] = lv_color_16_16_mix(color16, dest_buf_u16[0], opa);
328 x = 1;
329 }
330
331 for(; x < w - 2; x += 2) {
332 if(dest_buf_u16[x] != dest_buf_u16[x + 1]) {
333 dest_buf_u16[x + 0] = lv_color_16_16_mix(color16, dest_buf_u16[x + 0], opa);
334 dest_buf_u16[x + 1] = lv_color_16_16_mix(color16, dest_buf_u16[x + 1], opa);
335 }
336 else {
337 volatile uint32_t * dest32 = (uint32_t *)&dest_buf_u16[x];
338 if(last_dest32_color == *dest32) {
339 *dest32 = last_res32_color;
340 }
341 else {
342 last_dest32_color = *dest32;
343
344 dest_buf_u16[x] = lv_color_16_16_mix(color16, dest_buf_u16[x + 0], opa);
345 dest_buf_u16[x + 1] = dest_buf_u16[x];
346
347 last_res32_color = *dest32;
348 }
349 }
350 }
351
352 for(; x < w ; x++) {
353 dest_buf_u16[x] = lv_color_16_16_mix(color16, dest_buf_u16[x], opa);
354 }
355 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
356 }
357 }
358 }
359 /*Masked with full opacity*/
360 else if(mask && opa >= LV_OPA_MAX) {
361 if(LV_RESULT_INVALID == LV_DRAW_SW_COLOR_BLEND_TO_RGB565_WITH_MASK(dsc)) {
362 for(y = 0; y < h; y++) {
363 x = 0;
364 if((lv_uintptr_t)(mask) & 0x1) {
365 dest_buf_u16[x] = lv_color_16_16_mix(color16, dest_buf_u16[x], mask[x]);
366 x++;
367 }
368
369 for(; x <= w - 2; x += 2) {
370 uint16_t mask16 = *((uint16_t *)&mask[x]);
371 if(mask16 == 0xFFFF) {
372 dest_buf_u16[x + 0] = color16;
373 dest_buf_u16[x + 1] = color16;
374 }
375 else if(mask16 != 0) {
376 dest_buf_u16[x + 0] = lv_color_16_16_mix(color16, dest_buf_u16[x + 0], mask[x + 0]);
377 dest_buf_u16[x + 1] = lv_color_16_16_mix(color16, dest_buf_u16[x + 1], mask[x + 1]);
378 }
379 }
380
381 for(; x < w ; x++) {
382 dest_buf_u16[x] = lv_color_16_16_mix(color16, dest_buf_u16[x], mask[x]);
383 }
384 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
385 mask += mask_stride;
386 }
387 }
388 }
389 /*Masked with opacity*/
390 else if(mask && opa < LV_OPA_MAX) {
391 if(LV_RESULT_INVALID == LV_DRAW_SW_COLOR_BLEND_TO_RGB565_MIX_MASK_OPA(dsc)) {
392 for(y = 0; y < h; y++) {
393 for(x = 0; x < w; x++) {
394 dest_buf_u16[x] = lv_color_16_16_mix(color16, dest_buf_u16[x], LV_OPA_MIX2(mask[x], opa));
395 }
396 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
397 mask += mask_stride;
398 }
399 }
400 }
401 }
402
403 void LV_ATTRIBUTE_FAST_MEM lv_draw_sw_blend_image_to_rgb565(lv_draw_sw_blend_image_dsc_t * dsc)
404 {
405 switch(dsc->src_color_format) {
406 case LV_COLOR_FORMAT_RGB565:
407 rgb565_image_blend(dsc);
408 break;
409 #if LV_DRAW_SW_SUPPORT_RGB565_SWAPPED
410 case LV_COLOR_FORMAT_RGB565_SWAPPED:
411 rgb565_swapped_image_blend(dsc);
412 break;
413 #endif
414 #if LV_DRAW_SW_SUPPORT_RGB888
415 case LV_COLOR_FORMAT_RGB888:
416 rgb888_image_blend(dsc, 3);
417 break;
418 #endif
419 #if LV_DRAW_SW_SUPPORT_XRGB8888
420 case LV_COLOR_FORMAT_XRGB8888:
421 rgb888_image_blend(dsc, 4);
422 break;
423 #endif
424 #if LV_DRAW_SW_SUPPORT_ARGB8888
425 case LV_COLOR_FORMAT_ARGB8888:
426 argb8888_image_blend(dsc);
427 break;
428 #endif
429 #if LV_DRAW_SW_SUPPORT_ARGB8888_PREMULTIPLIED
430 case LV_COLOR_FORMAT_ARGB8888_PREMULTIPLIED:
431 argb8888_premultiplied_image_blend(dsc);
432 break;
433 #endif
434 #if LV_DRAW_SW_SUPPORT_L8
435 case LV_COLOR_FORMAT_L8:
436 l8_image_blend(dsc);
437 break;
438 #endif
439 #if LV_DRAW_SW_SUPPORT_AL88
440 case LV_COLOR_FORMAT_AL88:
441 al88_image_blend(dsc);
442 break;
443 #endif
444 #if LV_DRAW_SW_SUPPORT_I1
445 case LV_COLOR_FORMAT_I1:
446 i1_image_blend(dsc);
447 break;
448 #endif
449 default:
450 LV_LOG_WARN("Not supported source color format");
451 break;
452 }
453 }
454
455 /**********************
456 * STATIC FUNCTIONS
457 **********************/
458
459 #if LV_DRAW_SW_SUPPORT_I1
460 static void LV_ATTRIBUTE_FAST_MEM i1_image_blend(lv_draw_sw_blend_image_dsc_t * dsc)
461 {
462 int32_t w = dsc->dest_w;
463 int32_t h = dsc->dest_h;
464 lv_opa_t opa = dsc->opa;
465 uint16_t * dest_buf_u16 = dsc->dest_buf;
466 int32_t dest_stride = dsc->dest_stride;
467 const uint8_t * src_buf_i1 = dsc->src_buf;
468 int32_t src_stride = dsc->src_stride;
469 const lv_opa_t * mask_buf = dsc->mask_buf;
470 int32_t mask_stride = dsc->mask_stride;
471
472 int32_t dest_x;
473 int32_t src_x;
474 int32_t y;
475
476 if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
477 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
478 if(LV_RESULT_INVALID == LV_DRAW_SW_I1_BLEND_NORMAL_TO_RGB565(dsc)) {
479 for(y = 0; y < h; y++) {
480 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x++) {
481 uint8_t chan_val = get_bit(src_buf_i1, src_x) * 255;
482 dest_buf_u16[dest_x] = l8_to_rgb565(chan_val);
483 }
484 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
485 src_buf_i1 = drawbuf_next_row(src_buf_i1, src_stride);
486 }
487 }
488 }
489 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
490 if(LV_RESULT_INVALID == LV_DRAW_SW_I1_BLEND_NORMAL_TO_RGB565_WITH_OPA(dsc)) {
491 for(y = 0; y < h; y++) {
492 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x++) {
493 uint8_t chan_val = get_bit(src_buf_i1, src_x) * 255;
494 dest_buf_u16[dest_x] = lv_color_8_16_mix(chan_val, dest_buf_u16[dest_x], opa);
495 }
496 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
497 src_buf_i1 = drawbuf_next_row(src_buf_i1, src_stride);
498 }
499 }
500 }
501 else if(mask_buf && opa >= LV_OPA_MAX) {
502 if(LV_RESULT_INVALID == LV_DRAW_SW_I1_BLEND_NORMAL_TO_RGB565_WITH_MASK(dsc)) {
503 for(y = 0; y < h; y++) {
504 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x++) {
505 uint8_t chan_val = get_bit(src_buf_i1, src_x) * 255;
506 dest_buf_u16[dest_x] = lv_color_8_16_mix(chan_val, dest_buf_u16[dest_x], mask_buf[dest_x]);
507 }
508 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
509 src_buf_i1 = drawbuf_next_row(src_buf_i1, src_stride);
510 mask_buf += mask_stride;
511 }
512 }
513 }
514 else if(mask_buf && opa < LV_OPA_MAX) {
515 if(LV_RESULT_INVALID == LV_DRAW_SW_I1_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA(dsc)) {
516 for(y = 0; y < h; y++) {
517 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x++) {
518 uint8_t chan_val = get_bit(src_buf_i1, src_x) * 255;
519 dest_buf_u16[dest_x] = lv_color_8_16_mix(chan_val, dest_buf_u16[dest_x], LV_OPA_MIX2(mask_buf[dest_x], opa));
520 }
521 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
522 src_buf_i1 = drawbuf_next_row(src_buf_i1, src_stride);
523 mask_buf += mask_stride;
524 }
525 }
526 }
527 }
528 else {
529 for(y = 0; y < h; y++) {
530 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += 4) {
531 uint16_t res = 0;
532 uint8_t chan_val = get_bit(src_buf_i1, src_x) * 255;
533 switch(dsc->blend_mode) {
534 case LV_BLEND_MODE_ADDITIVE:
535 // Additive blending mode
536 res = (LV_MIN(dest_buf_u16[dest_x] + l8_to_rgb565(chan_val), 0xFFFF));
537 break;
538 case LV_BLEND_MODE_SUBTRACTIVE:
539 // Subtractive blending mode
540 res = (LV_MAX(dest_buf_u16[dest_x] - l8_to_rgb565(chan_val), 0));
541 break;
542 case LV_BLEND_MODE_MULTIPLY:
543 // Multiply blending mode
544 res = ((((dest_buf_u16[dest_x] >> 11) * (l8_to_rgb565(chan_val) >> 3)) & 0x1F) << 11) |
545 ((((dest_buf_u16[dest_x] >> 5) & 0x3F) * ((l8_to_rgb565(chan_val) >> 2) & 0x3F) >> 6) << 5) |
546 (((dest_buf_u16[dest_x] & 0x1F) * (l8_to_rgb565(chan_val) & 0x1F)) >> 5);
547 break;
548 case LV_BLEND_MODE_DIFFERENCE:
549 /*Difference blending mode*/
550 res = (LV_ABS(dest_buf_u16[dest_x] - l8_to_rgb565(chan_val)));
551 break;
552 default:
553 LV_LOG_WARN("Not supported blend mode: %d", dsc->blend_mode);
554 return;
555 }
556
557 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
558 dest_buf_u16[dest_x] = res;
559 }
560 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
561 dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], opa);
562 }
563 else {
564 if(opa >= LV_OPA_MAX)
565 dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], mask_buf[dest_x]);
566 else
567 dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], LV_OPA_MIX2(mask_buf[dest_x], opa));
568 }
569 }
570
571 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
572 src_buf_i1 = drawbuf_next_row(src_buf_i1, src_stride);
573 if(mask_buf) mask_buf += mask_stride;
574 }
575 }
576 }
577 #endif
578
579 #if LV_DRAW_SW_SUPPORT_AL88
580 static void LV_ATTRIBUTE_FAST_MEM al88_image_blend(lv_draw_sw_blend_image_dsc_t * dsc)
581 {
582 int32_t w = dsc->dest_w;
583 int32_t h = dsc->dest_h;
584 lv_opa_t opa = dsc->opa;
585 uint16_t * dest_buf_u16 = dsc->dest_buf;
586 int32_t dest_stride = dsc->dest_stride;
587 const lv_color16a_t * src_buf_al88 = dsc->src_buf;
588 int32_t src_stride = dsc->src_stride;
589 const lv_opa_t * mask_buf = dsc->mask_buf;
590 int32_t mask_stride = dsc->mask_stride;
591
592 int32_t dest_x;
593 int32_t src_x;
594 int32_t y;
595
596 if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
597 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
598 if(LV_RESULT_INVALID == LV_DRAW_SW_AL88_BLEND_NORMAL_TO_RGB565(dsc)) {
599 for(y = 0; y < h; y++) {
600 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x++) {
601 dest_buf_u16[dest_x] = lv_color_8_16_mix(src_buf_al88[src_x].lumi, dest_buf_u16[dest_x], src_buf_al88[src_x].alpha);
602 }
603 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
604 src_buf_al88 = drawbuf_next_row(src_buf_al88, src_stride);
605 }
606 }
607 }
608 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
609 if(LV_RESULT_INVALID == LV_DRAW_SW_AL88_BLEND_NORMAL_TO_RGB565_WITH_OPA(dsc)) {
610 for(y = 0; y < h; y++) {
611 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x++) {
612 dest_buf_u16[dest_x] = lv_color_8_16_mix(src_buf_al88[src_x].lumi, dest_buf_u16[dest_x],
613 LV_OPA_MIX2(src_buf_al88[src_x].alpha, opa));
614 }
615 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
616 src_buf_al88 = drawbuf_next_row(src_buf_al88, src_stride);
617 }
618 }
619 }
620 else if(mask_buf && opa >= LV_OPA_MAX) {
621 if(LV_RESULT_INVALID == LV_DRAW_SW_AL88_BLEND_NORMAL_TO_RGB565_WITH_MASK(dsc)) {
622 for(y = 0; y < h; y++) {
623 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x++) {
624 dest_buf_u16[dest_x] = lv_color_8_16_mix(src_buf_al88[src_x].lumi, dest_buf_u16[dest_x],
625 LV_OPA_MIX2(src_buf_al88[src_x].alpha, mask_buf[dest_x]));
626 }
627 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
628 src_buf_al88 = drawbuf_next_row(src_buf_al88, src_stride);
629 mask_buf += mask_stride;
630 }
631 }
632 }
633 else if(mask_buf && opa < LV_OPA_MAX) {
634 if(LV_RESULT_INVALID == LV_DRAW_SW_AL88_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA(dsc)) {
635 for(y = 0; y < h; y++) {
636 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x++) {
637 dest_buf_u16[dest_x] = lv_color_8_16_mix(src_buf_al88[src_x].lumi, dest_buf_u16[dest_x],
638 LV_OPA_MIX3(src_buf_al88[src_x].alpha, mask_buf[dest_x], opa));
639 }
640 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
641 src_buf_al88 = drawbuf_next_row(src_buf_al88, src_stride);
642 mask_buf += mask_stride;
643 }
644 }
645 }
646 }
647 else {
648 uint16_t res = 0;
649 for(y = 0; y < h; y++) {
650 lv_color16_t * dest_buf_c16 = (lv_color16_t *)dest_buf_u16;
651 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += 4) {
652 uint8_t rb = src_buf_al88[src_x].lumi >> 3;
653 uint8_t g = src_buf_al88[src_x].lumi >> 2;
654 switch(dsc->blend_mode) {
655 case LV_BLEND_MODE_ADDITIVE:
656 res = (LV_MIN(dest_buf_c16[dest_x].red + rb, 31)) << 11;
657 res += (LV_MIN(dest_buf_c16[dest_x].green + g, 63)) << 5;
658 res += LV_MIN(dest_buf_c16[dest_x].blue + rb, 31);
659 break;
660 case LV_BLEND_MODE_SUBTRACTIVE:
661 res = (LV_MAX(dest_buf_c16[dest_x].red - rb, 0)) << 11;
662 res += (LV_MAX(dest_buf_c16[dest_x].green - g, 0)) << 5;
663 res += LV_MAX(dest_buf_c16[dest_x].blue - rb, 0);
664 break;
665 case LV_BLEND_MODE_MULTIPLY:
666 res = ((dest_buf_c16[dest_x].red * rb) >> 5) << 11;
667 res += ((dest_buf_c16[dest_x].green * g) >> 6) << 5;
668 res += (dest_buf_c16[dest_x].blue * rb) >> 5;
669 break;
670 case LV_BLEND_MODE_DIFFERENCE:
671 res = (LV_ABS(dest_buf_c16[dest_x].red - rb)) << 11;
672 res += (LV_ABS(dest_buf_c16[dest_x].green - g)) << 5;
673 res += LV_ABS(dest_buf_c16[dest_x].blue - rb);
674 break;
675 default:
676 LV_LOG_WARN("Not supported blend mode: %d", dsc->blend_mode);
677 return;
678 }
679 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
680 dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], src_buf_al88[src_x].alpha);
681 }
682 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
683 dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], LV_OPA_MIX2(opa, src_buf_al88[src_x].alpha));
684 }
685 else {
686 if(opa >= LV_OPA_MAX) dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], mask_buf[dest_x]);
687 else dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], LV_OPA_MIX3(mask_buf[dest_x], opa,
688 src_buf_al88[src_x].alpha));
689 }
690 }
691
692 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
693 src_buf_al88 = drawbuf_next_row(src_buf_al88, src_stride);
694 if(mask_buf) mask_buf += mask_stride;
695 }
696 }
697 }
698
699 #endif
700
701 #if LV_DRAW_SW_SUPPORT_L8
702
703 static void LV_ATTRIBUTE_FAST_MEM l8_image_blend(lv_draw_sw_blend_image_dsc_t * dsc)
704 {
705 int32_t w = dsc->dest_w;
706 int32_t h = dsc->dest_h;
707 lv_opa_t opa = dsc->opa;
708 uint16_t * dest_buf_u16 = dsc->dest_buf;
709 int32_t dest_stride = dsc->dest_stride;
710 const uint8_t * src_buf_l8 = dsc->src_buf;
711 int32_t src_stride = dsc->src_stride;
712 const lv_opa_t * mask_buf = dsc->mask_buf;
713 int32_t mask_stride = dsc->mask_stride;
714
715 int32_t dest_x;
716 int32_t src_x;
717 int32_t y;
718
719 if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
720 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
721 if(LV_RESULT_INVALID == LV_DRAW_SW_L8_BLEND_NORMAL_TO_RGB565(dsc)) {
722 for(y = 0; y < h; y++) {
723 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x++) {
724 dest_buf_u16[dest_x] = l8_to_rgb565(src_buf_l8[src_x]);
725 }
726 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
727 src_buf_l8 += src_stride;
728 }
729 }
730 }
731 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
732 if(LV_RESULT_INVALID == LV_DRAW_SW_L8_BLEND_NORMAL_TO_RGB565_WITH_OPA(dsc)) {
733 for(y = 0; y < h; y++) {
734 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x++) {
735 dest_buf_u16[dest_x] = lv_color_8_16_mix(src_buf_l8[src_x], dest_buf_u16[dest_x], opa);
736 }
737 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
738 src_buf_l8 += src_stride;
739 }
740 }
741 }
742 else if(mask_buf && opa >= LV_OPA_MAX) {
743 if(LV_RESULT_INVALID == LV_DRAW_SW_L8_BLEND_NORMAL_TO_RGB565_WITH_MASK(dsc)) {
744 for(y = 0; y < h; y++) {
745 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x++) {
746 dest_buf_u16[dest_x] = lv_color_8_16_mix(src_buf_l8[src_x], dest_buf_u16[dest_x], mask_buf[dest_x]);
747 }
748 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
749 src_buf_l8 += src_stride;
750 mask_buf += mask_stride;
751 }
752 }
753 }
754 else if(mask_buf && opa < LV_OPA_MAX) {
755 if(LV_RESULT_INVALID == LV_DRAW_SW_L8_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA(dsc)) {
756 for(y = 0; y < h; y++) {
757 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x++) {
758 dest_buf_u16[dest_x] = lv_color_8_16_mix(src_buf_l8[src_x], dest_buf_u16[dest_x], LV_OPA_MIX2(mask_buf[dest_x], opa));
759 }
760 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
761 src_buf_l8 += src_stride;
762 mask_buf += mask_stride;
763 }
764 }
765 }
766 }
767 else {
768 uint16_t res = 0;
769 for(y = 0; y < h; y++) {
770 lv_color16_t * dest_buf_c16 = (lv_color16_t *)dest_buf_u16;
771 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += 4) {
772 uint8_t rb = src_buf_l8[src_x] >> 3;
773 uint8_t g = src_buf_l8[src_x] >> 2;
774 switch(dsc->blend_mode) {
775 case LV_BLEND_MODE_ADDITIVE:
776 res = (LV_MIN(dest_buf_c16[dest_x].red + rb, 31)) << 11;
777 res += (LV_MIN(dest_buf_c16[dest_x].green + g, 63)) << 5;
778 res += LV_MIN(dest_buf_c16[dest_x].blue + rb, 31);
779 break;
780 case LV_BLEND_MODE_SUBTRACTIVE:
781 res = (LV_MAX(dest_buf_c16[dest_x].red - rb, 0)) << 11;
782 res += (LV_MAX(dest_buf_c16[dest_x].green - g, 0)) << 5;
783 res += LV_MAX(dest_buf_c16[dest_x].blue - rb, 0);
784 break;
785 case LV_BLEND_MODE_MULTIPLY:
786 res = ((dest_buf_c16[dest_x].red * rb) >> 5) << 11;
787 res += ((dest_buf_c16[dest_x].green * g) >> 6) << 5;
788 res += (dest_buf_c16[dest_x].blue * rb) >> 5;
789 break;
790 case LV_BLEND_MODE_DIFFERENCE:
791 res = (LV_ABS(dest_buf_c16[dest_x].red - rb)) << 11;
792 res += (LV_ABS(dest_buf_c16[dest_x].green - g)) << 5;
793 res += LV_ABS(dest_buf_c16[dest_x].blue - rb);
794 break;
795 default:
796 LV_LOG_WARN("Not supported blend mode: %d", dsc->blend_mode);
797 return;
798 }
799
800 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
801 dest_buf_u16[dest_x] = res;
802 }
803 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
804 dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], opa);
805 }
806 else {
807 if(opa >= LV_OPA_MAX) dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], mask_buf[dest_x]);
808 else dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], LV_OPA_MIX2(mask_buf[dest_x], opa));
809 }
810 }
811
812 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
813 src_buf_l8 += src_stride;
814 if(mask_buf) mask_buf += mask_stride;
815 }
816 }
817 }
818
819 #endif
820
821 static void LV_ATTRIBUTE_FAST_MEM rgb565_image_blend(lv_draw_sw_blend_image_dsc_t * dsc)
822 {
823 int32_t w = dsc->dest_w;
824 int32_t h = dsc->dest_h;
825 lv_opa_t opa = dsc->opa;
826 uint16_t * dest_buf_u16 = dsc->dest_buf;
827 int32_t dest_stride = dsc->dest_stride;
828 const uint16_t * src_buf_u16 = dsc->src_buf;
829 int32_t src_stride = dsc->src_stride;
830 const lv_opa_t * mask_buf = dsc->mask_buf;
831 int32_t mask_stride = dsc->mask_stride;
832
833 int32_t x;
834 int32_t y;
835
836 if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
837 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
838 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_RGB565(dsc)) {
839 uint32_t line_in_bytes = w * 2;
840 for(y = 0; y < h; y++) {
841 lv_memcpy(dest_buf_u16, src_buf_u16, line_in_bytes);
842 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
843 src_buf_u16 = drawbuf_next_row(src_buf_u16, src_stride);
844 }
845 }
846 }
847 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
848 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_RGB565_WITH_OPA(dsc)) {
849 for(y = 0; y < h; y++) {
850 for(x = 0; x < w; x++) {
851 dest_buf_u16[x] = lv_color_16_16_mix(src_buf_u16[x], dest_buf_u16[x], opa);
852 }
853 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
854 src_buf_u16 = drawbuf_next_row(src_buf_u16, src_stride);
855 }
856 }
857 }
858 else if(mask_buf && opa >= LV_OPA_MAX) {
859 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_RGB565_WITH_MASK(dsc)) {
860 for(y = 0; y < h; y++) {
861 for(x = 0; x < w; x++) {
862 dest_buf_u16[x] = lv_color_16_16_mix(src_buf_u16[x], dest_buf_u16[x], mask_buf[x]);
863 }
864 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
865 src_buf_u16 = drawbuf_next_row(src_buf_u16, src_stride);
866 mask_buf += mask_stride;
867 }
868 }
869 }
870 else {
871 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB565_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA(dsc)) {
872 for(y = 0; y < h; y++) {
873 for(x = 0; x < w; x++) {
874 dest_buf_u16[x] = lv_color_16_16_mix(src_buf_u16[x], dest_buf_u16[x], LV_OPA_MIX2(mask_buf[x], opa));
875 }
876 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
877 src_buf_u16 = drawbuf_next_row(src_buf_u16, src_stride);
878 mask_buf += mask_stride;
879 }
880 }
881 }
882 }
883 else {
884 uint16_t res = 0;
885 for(y = 0; y < h; y++) {
886 lv_color16_t * dest_buf_c16 = (lv_color16_t *) dest_buf_u16;
887 lv_color16_t * src_buf_c16 = (lv_color16_t *) src_buf_u16;
888 for(x = 0; x < w; x++) {
889 switch(dsc->blend_mode) {
890 case LV_BLEND_MODE_ADDITIVE:
891 if(src_buf_u16[x] == 0x0000) continue; /*Do not add pure black*/
892 res = (LV_MIN(dest_buf_c16[x].red + src_buf_c16[x].red, 31)) << 11;
893 res += (LV_MIN(dest_buf_c16[x].green + src_buf_c16[x].green, 63)) << 5;
894 res += LV_MIN(dest_buf_c16[x].blue + src_buf_c16[x].blue, 31);
895 break;
896 case LV_BLEND_MODE_SUBTRACTIVE:
897 if(src_buf_u16[x] == 0x0000) continue; /*Do not subtract pure black*/
898 res = (LV_MAX(dest_buf_c16[x].red - src_buf_c16[x].red, 0)) << 11;
899 res += (LV_MAX(dest_buf_c16[x].green - src_buf_c16[x].green, 0)) << 5;
900 res += LV_MAX(dest_buf_c16[x].blue - src_buf_c16[x].blue, 0);
901 break;
902 case LV_BLEND_MODE_MULTIPLY:
903 if(src_buf_u16[x] == 0xffff) continue; /*Do not multiply with pure white (considered as 1)*/
904 res = ((dest_buf_c16[x].red * src_buf_c16[x].red) >> 5) << 11;
905 res += ((dest_buf_c16[x].green * src_buf_c16[x].green) >> 6) << 5;
906 res += (dest_buf_c16[x].blue * src_buf_c16[x].blue) >> 5;
907 break;
908 case LV_BLEND_MODE_DIFFERENCE:
909 res = (LV_ABS(dest_buf_c16[x].red - src_buf_c16[x].red)) << 11;
910 res += (LV_ABS(dest_buf_c16[x].green - src_buf_c16[x].green)) << 5;
911 res += LV_ABS(dest_buf_c16[x].blue - src_buf_c16[x].blue);
912 break;
913 default:
914 LV_LOG_WARN("Not supported blend mode: %d", dsc->blend_mode);
915 return;
916 }
917
918 if(mask_buf == NULL) {
919 dest_buf_u16[x] = lv_color_16_16_mix(res, dest_buf_u16[x], opa);
920 }
921 else {
922 if(opa >= LV_OPA_MAX) dest_buf_u16[x] = lv_color_16_16_mix(res, dest_buf_u16[x], mask_buf[x]);
923 else dest_buf_u16[x] = lv_color_16_16_mix(res, dest_buf_u16[x], LV_OPA_MIX2(mask_buf[x], opa));
924 }
925 }
926
927 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
928 src_buf_u16 = drawbuf_next_row(src_buf_u16, src_stride);
929 if(mask_buf) mask_buf += mask_stride;
930 }
931 }
932 }
933
934 #if LV_DRAW_SW_SUPPORT_RGB565_SWAPPED
935 static void LV_ATTRIBUTE_FAST_MEM rgb565_swapped_image_blend(lv_draw_sw_blend_image_dsc_t * dsc)
936 {
937 int32_t w = dsc->dest_w;
938 int32_t h = dsc->dest_h;
939 lv_opa_t opa = dsc->opa;
940 uint16_t * dest_buf_u16 = dsc->dest_buf;
941 int32_t dest_stride = dsc->dest_stride;
942 const uint16_t * src_buf_u16 = dsc->src_buf;
943 int32_t src_stride = dsc->src_stride;
944 const lv_opa_t * mask_buf = dsc->mask_buf;
945 int32_t mask_stride = dsc->mask_stride;
946
947 int32_t x;
948 int32_t y;
949
950 if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
951 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
952 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB565_SWAPPED_BLEND_NORMAL_TO_RGB565(dsc)) {
953 uint32_t line_in_bytes = w * 2;
954 for(y = 0; y < h; y++) {
955 lv_memcpy(dest_buf_u16, src_buf_u16, line_in_bytes);
956 lv_draw_sw_rgb565_swap((uint8_t *) dest_buf_u16, w);
957 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
958 src_buf_u16 = drawbuf_next_row(src_buf_u16, src_stride);
959 }
960 }
961 }
962 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
963 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB565_SWAPPED_BLEND_NORMAL_TO_RGB565_WITH_OPA(dsc)) {
964 for(y = 0; y < h; y++) {
965 for(x = 0; x < w; x++) {
966 dest_buf_u16[x] = lv_color_16_16_mix(lv_color_swap_16(src_buf_u16[x]), dest_buf_u16[x], opa);
967 }
968 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
969 src_buf_u16 = drawbuf_next_row(src_buf_u16, src_stride);
970 }
971 }
972 }
973 else if(mask_buf && opa >= LV_OPA_MAX) {
974 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB565_SWAPPED_BLEND_NORMAL_TO_RGB565_WITH_MASK(dsc)) {
975 for(y = 0; y < h; y++) {
976 for(x = 0; x < w; x++) {
977 dest_buf_u16[x] = lv_color_16_16_mix(lv_color_swap_16(src_buf_u16[x]), dest_buf_u16[x], mask_buf[x]);
978 }
979 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
980 src_buf_u16 = drawbuf_next_row(src_buf_u16, src_stride);
981 mask_buf += mask_stride;
982 }
983 }
984 }
985 else {
986 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB565_SWAPPED_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA(dsc)) {
987 for(y = 0; y < h; y++) {
988 for(x = 0; x < w; x++) {
989 dest_buf_u16[x] = lv_color_16_16_mix(lv_color_swap_16(src_buf_u16[x]), dest_buf_u16[x], LV_OPA_MIX2(mask_buf[x], opa));
990 }
991 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
992 src_buf_u16 = drawbuf_next_row(src_buf_u16, src_stride);
993 mask_buf += mask_stride;
994 }
995 }
996 }
997 }
998 else {
999 uint16_t res = 0;
1000 for(y = 0; y < h; y++) {
1001 lv_color16_t * dest_buf_c16 = (lv_color16_t *) dest_buf_u16;
1002
1003 for(x = 0; x < w; x++) {
1004 uint16_t raw;
1005 lv_color16_t px;
1006 raw = lv_color_swap_16(src_buf_u16[x]); /* swap byte order */
1007 px = lv_color16_from_u16(raw);
1008
1009 switch(dsc->blend_mode) {
1010 case LV_BLEND_MODE_ADDITIVE:
1011 if(src_buf_u16[x] == 0x0000) continue; /*Do not add pure black*/
1012 res = (LV_MIN(dest_buf_c16[x].red + px.red, 31)) << 11;
1013 res += (LV_MIN(dest_buf_c16[x].green + px.green, 63)) << 5;
1014 res += LV_MIN(dest_buf_c16[x].blue + px.blue, 31);
1015 break;
1016 case LV_BLEND_MODE_SUBTRACTIVE:
1017 if(src_buf_u16[x] == 0x0000) continue; /*Do not subtract pure black*/
1018 res = (LV_MAX(dest_buf_c16[x].red - px.red, 0)) << 11;
1019 res += (LV_MAX(dest_buf_c16[x].green - px.green, 0)) << 5;
1020 res += LV_MAX(dest_buf_c16[x].blue - px.blue, 0);
1021 break;
1022 case LV_BLEND_MODE_MULTIPLY:
1023 if(src_buf_u16[x] == 0xffff) continue; /*Do not multiply with pure white (considered as 1)*/
1024 res = ((dest_buf_c16[x].red * px.red) >> 5) << 11;
1025 res += ((dest_buf_c16[x].green * px.green) >> 6) << 5;
1026 res += (dest_buf_c16[x].blue * px.blue) >> 5;
1027 break;
1028 case LV_BLEND_MODE_DIFFERENCE:
1029 res = (LV_ABS(dest_buf_c16[x].red - px.red)) << 11;
1030 res += (LV_ABS(dest_buf_c16[x].green - px.green)) << 5;
1031 res += LV_ABS(dest_buf_c16[x].blue - px.blue);
1032 break;
1033 default:
1034 LV_LOG_WARN("Not supported blend mode: %d", dsc->blend_mode);
1035 return;
1036 }
1037
1038 if(mask_buf == NULL) {
1039 dest_buf_u16[x] = lv_color_16_16_mix(res, dest_buf_u16[x], opa);
1040 }
1041 else {
1042 if(opa >= LV_OPA_MAX) dest_buf_u16[x] = lv_color_16_16_mix(res, dest_buf_u16[x], mask_buf[x]);
1043 else dest_buf_u16[x] = lv_color_16_16_mix(res, dest_buf_u16[x], LV_OPA_MIX2(mask_buf[x], opa));
1044 }
1045 }
1046
1047 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
1048 src_buf_u16 = drawbuf_next_row(src_buf_u16, src_stride);
1049 if(mask_buf) mask_buf += mask_stride;
1050 }
1051 }
1052 }
1053
1054 #endif
1055
1056 #if LV_DRAW_SW_SUPPORT_RGB888 || LV_DRAW_SW_SUPPORT_XRGB8888
1057
1058 static void LV_ATTRIBUTE_FAST_MEM rgb888_image_blend(lv_draw_sw_blend_image_dsc_t * dsc, const uint8_t src_px_size)
1059 {
1060 int32_t w = dsc->dest_w;
1061 int32_t h = dsc->dest_h;
1062 lv_opa_t opa = dsc->opa;
1063 uint16_t * dest_buf_u16 = dsc->dest_buf;
1064 int32_t dest_stride = dsc->dest_stride;
1065 const uint8_t * src_buf_u8 = dsc->src_buf;
1066 int32_t src_stride = dsc->src_stride;
1067 const lv_opa_t * mask_buf = dsc->mask_buf;
1068 int32_t mask_stride = dsc->mask_stride;
1069
1070 int32_t dest_x;
1071 int32_t src_x;
1072 int32_t y;
1073
1074 if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
1075 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
1076 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_RGB565(dsc, src_px_size)) {
1077 for(y = 0; y < h; y++) {
1078 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += src_px_size) {
1079 dest_buf_u16[dest_x] = ((src_buf_u8[src_x + 2] & 0xF8) << 8) +
1080 ((src_buf_u8[src_x + 1] & 0xFC) << 3) +
1081 ((src_buf_u8[src_x + 0] & 0xF8) >> 3);
1082 }
1083 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
1084 src_buf_u8 += src_stride;
1085 }
1086 }
1087 }
1088 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
1089 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_RGB565_WITH_OPA(dsc, src_px_size)) {
1090 for(y = 0; y < h; y++) {
1091 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += src_px_size) {
1092 dest_buf_u16[dest_x] = lv_color_24_16_mix(&src_buf_u8[src_x], dest_buf_u16[dest_x], opa);
1093 }
1094 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
1095 src_buf_u8 += src_stride;
1096 }
1097 }
1098 }
1099 if(mask_buf && opa >= LV_OPA_MAX) {
1100 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_RGB565_WITH_MASK(dsc, src_px_size)) {
1101 for(y = 0; y < h; y++) {
1102 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += src_px_size) {
1103 dest_buf_u16[dest_x] = lv_color_24_16_mix(&src_buf_u8[src_x], dest_buf_u16[dest_x], mask_buf[dest_x]);
1104 }
1105 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
1106 src_buf_u8 += src_stride;
1107 mask_buf += mask_stride;
1108 }
1109 }
1110 }
1111 if(mask_buf && opa < LV_OPA_MAX) {
1112 if(LV_RESULT_INVALID == LV_DRAW_SW_RGB888_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA(dsc, src_px_size)) {
1113 for(y = 0; y < h; y++) {
1114 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += src_px_size) {
1115 dest_buf_u16[dest_x] = lv_color_24_16_mix(&src_buf_u8[src_x], dest_buf_u16[dest_x], LV_OPA_MIX2(mask_buf[dest_x], opa));
1116 }
1117 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
1118 src_buf_u8 += src_stride;
1119 mask_buf += mask_stride;
1120 }
1121 }
1122 }
1123 }
1124 else {
1125 uint16_t res = 0;
1126 for(y = 0; y < h; y++) {
1127 lv_color16_t * dest_buf_c16 = (lv_color16_t *) dest_buf_u16;
1128 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += src_px_size) {
1129 switch(dsc->blend_mode) {
1130 case LV_BLEND_MODE_ADDITIVE:
1131 res = (LV_MIN(dest_buf_c16[dest_x].red + (src_buf_u8[src_x + 2] >> 3), 31)) << 11;
1132 res += (LV_MIN(dest_buf_c16[dest_x].green + (src_buf_u8[src_x + 1] >> 2), 63)) << 5;
1133 res += LV_MIN(dest_buf_c16[dest_x].blue + (src_buf_u8[src_x + 0] >> 3), 31);
1134 break;
1135 case LV_BLEND_MODE_SUBTRACTIVE:
1136 res = (LV_MAX(dest_buf_c16[dest_x].red - (src_buf_u8[src_x + 2] >> 3), 0)) << 11;
1137 res += (LV_MAX(dest_buf_c16[dest_x].green - (src_buf_u8[src_x + 1] >> 2), 0)) << 5;
1138 res += LV_MAX(dest_buf_c16[dest_x].blue - (src_buf_u8[src_x + 0] >> 3), 0);
1139 break;
1140 case LV_BLEND_MODE_MULTIPLY:
1141 res = ((dest_buf_c16[dest_x].red * (src_buf_u8[src_x + 2] >> 3)) >> 5) << 11;
1142 res += ((dest_buf_c16[dest_x].green * (src_buf_u8[src_x + 1] >> 2)) >> 6) << 5;
1143 res += (dest_buf_c16[dest_x].blue * (src_buf_u8[src_x + 0] >> 3)) >> 5;
1144 break;
1145 case LV_BLEND_MODE_DIFFERENCE:
1146 res = (LV_ABS(dest_buf_c16[dest_x].red - (src_buf_u8[src_x + 2] >> 3))) << 11;
1147 res += (LV_ABS(dest_buf_c16[dest_x].green - (src_buf_u8[src_x + 1] >> 2))) << 5;
1148 res += LV_ABS(dest_buf_c16[dest_x].blue - (src_buf_u8[src_x + 0] >> 3));
1149 break;
1150 default:
1151 LV_LOG_WARN("Not supported blend mode: %d", dsc->blend_mode);
1152 return;
1153 }
1154
1155 if(mask_buf == NULL) {
1156 dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], opa);
1157 }
1158 else {
1159 if(opa >= LV_OPA_MAX) dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], mask_buf[dest_x]);
1160 else dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], LV_OPA_MIX2(mask_buf[dest_x], opa));
1161 }
1162 }
1163 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
1164 src_buf_u8 += src_stride;
1165 if(mask_buf) mask_buf += mask_stride;
1166 }
1167
1168 }
1169 }
1170
1171 #endif
1172
1173 #if LV_DRAW_SW_SUPPORT_ARGB8888
1174
1175 static void LV_ATTRIBUTE_FAST_MEM argb8888_image_blend(lv_draw_sw_blend_image_dsc_t * dsc)
1176 {
1177 int32_t w = dsc->dest_w;
1178 int32_t h = dsc->dest_h;
1179 lv_opa_t opa = dsc->opa;
1180 uint16_t * dest_buf_u16 = dsc->dest_buf;
1181 int32_t dest_stride = dsc->dest_stride;
1182 const uint8_t * src_buf_u8 = dsc->src_buf;
1183 int32_t src_stride = dsc->src_stride;
1184 const lv_opa_t * mask_buf = dsc->mask_buf;
1185 int32_t mask_stride = dsc->mask_stride;
1186
1187 int32_t dest_x;
1188 int32_t src_x;
1189 int32_t y;
1190
1191 if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
1192 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
1193 if(LV_RESULT_INVALID == LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB565(dsc)) {
1194 for(y = 0; y < h; y++) {
1195 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += 4) {
1196 dest_buf_u16[dest_x] = lv_color_24_16_mix(&src_buf_u8[src_x], dest_buf_u16[dest_x], src_buf_u8[src_x + 3]);
1197 }
1198 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
1199 src_buf_u8 += src_stride;
1200 }
1201 }
1202 }
1203 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
1204 if(LV_RESULT_INVALID == LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB565_WITH_OPA(dsc)) {
1205 for(y = 0; y < h; y++) {
1206 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += 4) {
1207 dest_buf_u16[dest_x] = lv_color_24_16_mix(&src_buf_u8[src_x], dest_buf_u16[dest_x], LV_OPA_MIX2(src_buf_u8[src_x + 3],
1208 opa));
1209 }
1210 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
1211 src_buf_u8 += src_stride;
1212 }
1213 }
1214 }
1215 else if(mask_buf && opa >= LV_OPA_MAX) {
1216 if(LV_RESULT_INVALID == LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB565_WITH_MASK(dsc)) {
1217 for(y = 0; y < h; y++) {
1218 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += 4) {
1219 dest_buf_u16[dest_x] = lv_color_24_16_mix(&src_buf_u8[src_x], dest_buf_u16[dest_x],
1220 LV_OPA_MIX2(src_buf_u8[src_x + 3], mask_buf[dest_x]));
1221 }
1222 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
1223 src_buf_u8 += src_stride;
1224 mask_buf += mask_stride;
1225 }
1226 }
1227 }
1228 else if(mask_buf && opa < LV_OPA_MAX) {
1229 if(LV_RESULT_INVALID == LV_DRAW_SW_ARGB8888_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA(dsc)) {
1230 for(y = 0; y < h; y++) {
1231 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += 4) {
1232 dest_buf_u16[dest_x] = lv_color_24_16_mix(&src_buf_u8[src_x], dest_buf_u16[dest_x],
1233 LV_OPA_MIX3(src_buf_u8[src_x + 3], mask_buf[dest_x], opa));
1234 }
1235 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
1236 src_buf_u8 += src_stride;
1237 mask_buf += mask_stride;
1238 }
1239 }
1240 }
1241 }
1242 else {
1243 uint16_t res = 0;
1244 for(y = 0; y < h; y++) {
1245 lv_color16_t * dest_buf_c16 = (lv_color16_t *) dest_buf_u16;
1246 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += 4) {
1247 switch(dsc->blend_mode) {
1248 case LV_BLEND_MODE_ADDITIVE:
1249 res = (LV_MIN(dest_buf_c16[dest_x].red + (src_buf_u8[src_x + 2] >> 3), 31)) << 11;
1250 res += (LV_MIN(dest_buf_c16[dest_x].green + (src_buf_u8[src_x + 1] >> 2), 63)) << 5;
1251 res += LV_MIN(dest_buf_c16[dest_x].blue + (src_buf_u8[src_x + 0] >> 3), 31);
1252 break;
1253 case LV_BLEND_MODE_SUBTRACTIVE:
1254 res = (LV_MAX(dest_buf_c16[dest_x].red - (src_buf_u8[src_x + 2] >> 3), 0)) << 11;
1255 res += (LV_MAX(dest_buf_c16[dest_x].green - (src_buf_u8[src_x + 1] >> 2), 0)) << 5;
1256 res += LV_MAX(dest_buf_c16[dest_x].blue - (src_buf_u8[src_x + 0] >> 3), 0);
1257 break;
1258 case LV_BLEND_MODE_MULTIPLY:
1259 res = ((dest_buf_c16[dest_x].red * (src_buf_u8[src_x + 2] >> 3)) >> 5) << 11;
1260 res += ((dest_buf_c16[dest_x].green * (src_buf_u8[src_x + 1] >> 2)) >> 6) << 5;
1261 res += (dest_buf_c16[dest_x].blue * (src_buf_u8[src_x + 0] >> 3)) >> 5;
1262 break;
1263 case LV_BLEND_MODE_DIFFERENCE:
1264 res = (LV_ABS(dest_buf_c16[dest_x].red - (src_buf_u8[src_x + 2] >> 3))) << 11;
1265 res += (LV_ABS(dest_buf_c16[dest_x].green - (src_buf_u8[src_x + 1] >> 2))) << 5;
1266 res += LV_ABS(dest_buf_c16[dest_x].blue - (src_buf_u8[src_x + 0] >> 3));
1267 break;
1268 default:
1269 LV_LOG_WARN("Not supported blend mode: %d", dsc->blend_mode);
1270 return;
1271 }
1272
1273 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
1274 dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], src_buf_u8[src_x + 3]);
1275 }
1276 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
1277 dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], LV_OPA_MIX2(opa, src_buf_u8[src_x + 3]));
1278 }
1279 else {
1280 if(opa >= LV_OPA_MAX) dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], mask_buf[dest_x]);
1281 else dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], LV_OPA_MIX3(mask_buf[dest_x], opa,
1282 src_buf_u8[src_x + 3]));
1283 }
1284 }
1285
1286 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
1287 src_buf_u8 += src_stride;
1288 if(mask_buf) mask_buf += mask_stride;
1289 }
1290 }
1291 }
1292
1293 #endif
1294
1295 #if LV_DRAW_SW_SUPPORT_ARGB8888_PREMULTIPLIED
1296
1297 static inline uint16_t LV_ATTRIBUTE_FAST_MEM lv_color_24_16_mix_premult(const uint8_t * c1, uint16_t c2, uint8_t mix)
1298 {
1299 if(mix == 0) {
1300 return c2;
1301 }
1302 else if(mix == 255) {
1303 return ((c1[2] & 0xF8) << 8) + ((c1[1] & 0xFC) << 3) + ((c1[0] & 0xF8) >> 3);
1304 }
1305 else {
1306 lv_opa_t mix_inv = 255 - mix;
1307
1308 uint8_t r = (c1[2] >> 3) + ((((c2 >> 11) & 0x1F) * mix_inv) >> 8);
1309 uint8_t g = (c1[1] >> 2) + ((((c2 >> 5) & 0x3F) * mix_inv) >> 8);
1310 uint8_t b = (c1[0] >> 3) + ((((c2 >> 0) & 0x1F) * mix_inv) >> 8);
1311
1312 return (r << 11) + (g << 5) + (b);
1313 }
1314 }
1315
1316 static void LV_ATTRIBUTE_FAST_MEM argb8888_premultiplied_image_blend(lv_draw_sw_blend_image_dsc_t * dsc)
1317 {
1318 int32_t w = dsc->dest_w;
1319 int32_t h = dsc->dest_h;
1320 lv_opa_t opa = dsc->opa;
1321 uint16_t * dest_buf_u16 = dsc->dest_buf;
1322 int32_t dest_stride = dsc->dest_stride;
1323 const uint8_t * src_buf_u8 = dsc->src_buf;
1324 int32_t src_stride = dsc->src_stride;
1325 const lv_opa_t * mask_buf = dsc->mask_buf;
1326 int32_t mask_stride = dsc->mask_stride;
1327
1328 int32_t dest_x;
1329 int32_t src_x;
1330 int32_t y;
1331
1332 if(dsc->blend_mode == LV_BLEND_MODE_NORMAL) {
1333 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
1334 if(LV_RESULT_INVALID == LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_RGB565(dsc)) {
1335 for(y = 0; y < h; y++) {
1336 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += 4) {
1337 /*For the trivial case use the premultiplied image as it is.
1338 *For the other cases unpremultiply as another alpha also needs to be applied.*/
1339 dest_buf_u16[dest_x] = lv_color_24_16_mix_premult(&src_buf_u8[src_x], dest_buf_u16[dest_x], src_buf_u8[src_x + 3]);
1340 }
1341 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
1342 src_buf_u8 += src_stride;
1343 }
1344 }
1345 }
1346 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
1347 if(LV_RESULT_INVALID == LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_RGB565_WITH_OPA(dsc)) {
1348 for(y = 0; y < h; y++) {
1349 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += 4) {
1350 if(src_buf_u8[src_x + 3] > 0) {
1351 uint8_t src_buf_u8_unpremult[3];
1352 uint16_t reciprocal = (255 * 256) / src_buf_u8[src_x + 3];
1353 src_buf_u8_unpremult[0] = (src_buf_u8[src_x + 0] * reciprocal) >> 8;
1354 src_buf_u8_unpremult[1] = (src_buf_u8[src_x + 1] * reciprocal) >> 8;
1355 src_buf_u8_unpremult[2] = (src_buf_u8[src_x + 2] * reciprocal) >> 8;
1356 dest_buf_u16[dest_x] = lv_color_24_16_mix(src_buf_u8_unpremult, dest_buf_u16[dest_x],
1357 LV_OPA_MIX2(src_buf_u8[src_x + 3], opa));
1358 }
1359 }
1360 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
1361 src_buf_u8 += src_stride;
1362 }
1363 }
1364 }
1365 else if(mask_buf && opa >= LV_OPA_MAX) {
1366 if(LV_RESULT_INVALID == LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_RGB565_WITH_MASK(dsc)) {
1367 for(y = 0; y < h; y++) {
1368 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += 4) {
1369 if(src_buf_u8[src_x + 3] > 0) {
1370 uint8_t src_buf_u8_unpremult[3];
1371 uint16_t reciprocal = (255 * 256) / src_buf_u8[src_x + 3];
1372 src_buf_u8_unpremult[0] = (src_buf_u8[src_x + 0] * reciprocal) >> 8;
1373 src_buf_u8_unpremult[1] = (src_buf_u8[src_x + 1] * reciprocal) >> 8;
1374 src_buf_u8_unpremult[2] = (src_buf_u8[src_x + 2] * reciprocal) >> 8;
1375 dest_buf_u16[dest_x] = lv_color_24_16_mix(src_buf_u8_unpremult, dest_buf_u16[dest_x],
1376 LV_OPA_MIX2(src_buf_u8[src_x + 3], mask_buf[dest_x]));
1377 }
1378
1379 }
1380 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
1381 src_buf_u8 += src_stride;
1382 mask_buf += mask_stride;
1383 }
1384 }
1385 }
1386 else if(mask_buf && opa < LV_OPA_MAX) {
1387 if(LV_RESULT_INVALID == LV_DRAW_SW_ARGB8888_PREMULTIPLIED_BLEND_NORMAL_TO_RGB565_MIX_MASK_OPA(dsc)) {
1388 for(y = 0; y < h; y++) {
1389 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += 4) {
1390 if(src_buf_u8[src_x + 3] > 0) {
1391 uint8_t src_buf_u8_unpremult[3];
1392 uint16_t reciprocal = (255 * 256) / src_buf_u8[src_x + 3];
1393 src_buf_u8_unpremult[0] = (src_buf_u8[src_x + 0] * reciprocal) >> 8;
1394 src_buf_u8_unpremult[1] = (src_buf_u8[src_x + 1] * reciprocal) >> 8;
1395 src_buf_u8_unpremult[2] = (src_buf_u8[src_x + 2] * reciprocal) >> 8;
1396 dest_buf_u16[dest_x] = lv_color_24_16_mix(src_buf_u8_unpremult, dest_buf_u16[dest_x],
1397 LV_OPA_MIX3(src_buf_u8[src_x + 3], mask_buf[dest_x], opa));
1398 }
1399 }
1400 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
1401 src_buf_u8 += src_stride;
1402 mask_buf += mask_stride;
1403 }
1404 }
1405 }
1406 }
1407 else {
1408 uint16_t res = 0;
1409 for(y = 0; y < h; y++) {
1410 lv_color16_t * dest_buf_c16 = (lv_color16_t *) dest_buf_u16;
1411 for(dest_x = 0, src_x = 0; dest_x < w; dest_x++, src_x += 4) {
1412 switch(dsc->blend_mode) {
1413 case LV_BLEND_MODE_ADDITIVE:
1414 res = (LV_MIN(dest_buf_c16[dest_x].red + (src_buf_u8[src_x + 2] >> 3), 31)) << 11;
1415 res += (LV_MIN(dest_buf_c16[dest_x].green + (src_buf_u8[src_x + 1] >> 2), 63)) << 5;
1416 res += LV_MIN(dest_buf_c16[dest_x].blue + (src_buf_u8[src_x + 0] >> 3), 31);
1417 break;
1418 case LV_BLEND_MODE_SUBTRACTIVE:
1419 res = (LV_MAX(dest_buf_c16[dest_x].red - (src_buf_u8[src_x + 2] >> 3), 0)) << 11;
1420 res += (LV_MAX(dest_buf_c16[dest_x].green - (src_buf_u8[src_x + 1] >> 2), 0)) << 5;
1421 res += LV_MAX(dest_buf_c16[dest_x].blue - (src_buf_u8[src_x + 0] >> 3), 0);
1422 break;
1423 case LV_BLEND_MODE_MULTIPLY:
1424 res = ((dest_buf_c16[dest_x].red * (src_buf_u8[src_x + 2] >> 3)) >> 5) << 11;
1425 res += ((dest_buf_c16[dest_x].green * (src_buf_u8[src_x + 1] >> 2)) >> 6) << 5;
1426 res += (dest_buf_c16[dest_x].blue * (src_buf_u8[src_x + 0] >> 3)) >> 5;
1427 break;
1428 case LV_BLEND_MODE_DIFFERENCE:
1429 res = (LV_ABS(dest_buf_c16[dest_x].red - (src_buf_u8[src_x + 2] >> 3))) << 11;
1430 res += (LV_ABS(dest_buf_c16[dest_x].green - (src_buf_u8[src_x + 1] >> 2))) << 5;
1431 res += LV_ABS(dest_buf_c16[dest_x].blue - (src_buf_u8[src_x + 0] >> 3));
1432 break;
1433 default:
1434 LV_LOG_WARN("Not supported blend mode: %d", dsc->blend_mode);
1435 return;
1436 }
1437
1438 if(mask_buf == NULL && opa >= LV_OPA_MAX) {
1439 /* Blending premultiplied ARGB8888 to RGB565 with no mask and full opacity */
1440 dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], src_buf_u8[src_x + 3]);
1441 }
1442 else if(mask_buf == NULL && opa < LV_OPA_MAX) {
1443 /* Blending premultiplied ARGB8888 to RGB565 with no mask and partial opacity */
1444 dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], LV_OPA_MIX2(opa, src_buf_u8[src_x + 3]));
1445 }
1446 else {
1447 if(opa >= LV_OPA_MAX)
1448 dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], mask_buf[dest_x]);
1449 else
1450 dest_buf_u16[dest_x] = lv_color_16_16_mix(res, dest_buf_u16[dest_x], LV_OPA_MIX3(mask_buf[dest_x], opa,
1451 src_buf_u8[src_x + 3]));
1452 }
1453 }
1454
1455 dest_buf_u16 = drawbuf_next_row(dest_buf_u16, dest_stride);
1456 src_buf_u8 += src_stride;
1457 if(mask_buf) mask_buf += mask_stride;
1458 }
1459 }
1460 }
1461
1462 #endif
1463
1464 static inline uint16_t LV_ATTRIBUTE_FAST_MEM l8_to_rgb565(const uint8_t c1)
1465 {
1466 return ((c1 & 0xF8) << 8) + ((c1 & 0xFC) << 3) + ((c1 & 0xF8) >> 3);
1467 }
1468
1469 static inline uint16_t LV_ATTRIBUTE_FAST_MEM lv_color_8_16_mix(const uint8_t c1, uint16_t c2, uint8_t mix)
1470 {
1471
1472 if(mix == 0) {
1473 return c2;
1474 }
1475 else if(mix == 255) {
1476 return ((c1 & 0xF8) << 8) + ((c1 & 0xFC) << 3) + ((c1 & 0xF8) >> 3);
1477 }
1478 else {
1479 lv_opa_t mix_inv = 255 - mix;
1480
1481 return ((((c1 >> 3) * mix + ((c2 >> 11) & 0x1F) * mix_inv) << 3) & 0xF800) +
1482 ((((c1 >> 2) * mix + ((c2 >> 5) & 0x3F) * mix_inv) >> 3) & 0x07E0) +
1483 (((c1 >> 3) * mix + (c2 & 0x1F) * mix_inv) >> 8);
1484 }
1485 }
1486
1487 static inline uint16_t LV_ATTRIBUTE_FAST_MEM lv_color_24_16_mix(const uint8_t * c1, uint16_t c2, uint8_t mix)
1488 {
1489 if(mix == 0) {
1490 return c2;
1491 }
1492 else if(mix == 255) {
1493 return ((c1[2] & 0xF8) << 8) + ((c1[1] & 0xFC) << 3) + ((c1[0] & 0xF8) >> 3);
1494 }
1495 else {
1496 lv_opa_t mix_inv = 255 - mix;
1497
1498 return ((((c1[2] >> 3) * mix + ((c2 >> 11) & 0x1F) * mix_inv) << 3) & 0xF800) +
1499 ((((c1[1] >> 2) * mix + ((c2 >> 5) & 0x3F) * mix_inv) >> 3) & 0x07E0) +
1500 (((c1[0] >> 3) * mix + (c2 & 0x1F) * mix_inv) >> 8);
1501 }
1502 }
1503
1504 #if LV_DRAW_SW_SUPPORT_I1
1505
1506 static inline uint8_t LV_ATTRIBUTE_FAST_MEM get_bit(const uint8_t * buf, int32_t bit_idx)
1507 {
1508 return (buf[bit_idx / 8] >> (7 - (bit_idx % 8))) & 1;
1509 }
1510
1511 #endif
1512
1513 static inline void * LV_ATTRIBUTE_FAST_MEM drawbuf_next_row(const void * buf, uint32_t stride)
1514 {
1515 return (void *)((uint8_t *)buf + stride);
1516 }
1517
1518 #if LV_DRAW_SW_SUPPORT_RGB565_SWAPPED
1519 static inline lv_color16_t LV_ATTRIBUTE_FAST_MEM lv_color16_from_u16(uint16_t raw)
1520 {
1521 lv_color16_t c;
1522 c.red = (raw >> 11) & 0x1F;
1523 c.green = (raw >> 5) & 0x3F;
1524 c.blue = raw & 0x1F;
1525 return c;
1526 }
1527 #endif
1528
1529 #endif /*LV_DRAW_SW_SUPPORT_RGB565*/
1530
1531 #endif /*LV_USE_DRAW_SW*/