diff --git a/demos/music/lv_demo_music_main.c b/demos/music/lv_demo_music_main.c index f699b45116..84d4179c6a 100644 --- a/demos/music/lv_demo_music_main.c +++ b/demos/music/lv_demo_music_main.c @@ -13,6 +13,7 @@ #include "assets/spectrum_1.h" #include "assets/spectrum_2.h" #include "assets/spectrum_3.h" +#include "../../src/lvgl_private.h" /********************* * DEFINES diff --git a/demos/widgets/lv_demo_widgets.c b/demos/widgets/lv_demo_widgets.c index dd2fb34ba6..33ba10fc3e 100644 --- a/demos/widgets/lv_demo_widgets.c +++ b/demos/widgets/lv_demo_widgets.c @@ -7,6 +7,7 @@ * INCLUDES *********************/ #include "lv_demo_widgets.h" +#include "../../src/lvgl_private.h" #if LV_USE_DEMO_WIDGETS diff --git a/examples/porting/osal/lv_example_osal.c b/examples/porting/osal/lv_example_osal.c index 6e8e07e83b..83ca557c45 100644 --- a/examples/porting/osal/lv_example_osal.c +++ b/examples/porting/osal/lv_example_osal.c @@ -9,6 +9,7 @@ #include "../../lv_examples.h" #if LV_BUILD_EXAMPLES +#include "../../../src/osal/lv_os.h" /********************* * DEFINES diff --git a/examples/widgets/chart/lv_example_chart_5.c b/examples/widgets/chart/lv_example_chart_5.c index 723b3f1105..402f4cec9d 100644 --- a/examples/widgets/chart/lv_example_chart_5.c +++ b/examples/widgets/chart/lv_example_chart_5.c @@ -1,4 +1,5 @@ #include "../../lv_examples.h" +#include "../../../src/lvgl_private.h" #if LV_USE_CHART && LV_DRAW_SW_COMPLEX && LV_BUILD_EXAMPLES diff --git a/lvgl.h b/lvgl.h index 4cf9efbbd7..5cea1e283a 100644 --- a/lvgl.h +++ b/lvgl.h @@ -36,7 +36,8 @@ extern "C" { #include "src/misc/lv_iter.h" #include "src/misc/lv_circle_buf.h" #include "src/misc/lv_tree.h" - +#include "src/misc/cache/lv_image_cache.h" + #include "src/tick/lv_tick.h" #include "src/core/lv_obj.h" @@ -113,10 +114,9 @@ extern "C" { #include "src/layouts/lv_layout.h" -#include "src/draw/lv_draw.h" #include "src/draw/lv_draw_buf.h" #include "src/draw/lv_draw_vector.h" -#include "src/draw/sw/lv_draw_sw.h" +#include "src/draw/sw/lv_draw_sw_utils.h" #include "src/themes/lv_theme.h" diff --git a/src/display/lv_display.h b/src/display/lv_display.h index 2887ab691d..a1c7c7da97 100644 --- a/src/display/lv_display.h +++ b/src/display/lv_display.h @@ -17,7 +17,7 @@ extern "C" { #include "../misc/lv_timer.h" #include "../misc/lv_event.h" #include "../misc/lv_color.h" -#include "../draw/lv_draw.h" +#include "../misc/lv_area.h" /********************* * DEFINES diff --git a/src/draw/lv_draw.h b/src/draw/lv_draw.h index 6f69f69d18..6caf0cfd85 100644 --- a/src/draw/lv_draw.h +++ b/src/draw/lv_draw.h @@ -25,7 +25,6 @@ extern "C" { #include "../misc/lv_profiler.h" #include "../misc/lv_matrix.h" #include "lv_image_decoder.h" -#include "../osal/lv_os.h" #include "lv_draw_buf.h" /********************* diff --git a/src/draw/lv_draw_private.h b/src/draw/lv_draw_private.h index 8145cf7f23..2619632ecf 100644 --- a/src/draw/lv_draw_private.h +++ b/src/draw/lv_draw_private.h @@ -19,6 +19,8 @@ extern "C" { *********************/ #include "lv_draw.h" +#include "../osal/lv_os.h" +#include "../misc/cache/lv_cache.h" /********************* * DEFINES diff --git a/src/draw/lv_image_decoder.h b/src/draw/lv_image_decoder.h index e898edc9dd..0747881be6 100644 --- a/src/draw/lv_image_decoder.h +++ b/src/draw/lv_image_decoder.h @@ -19,7 +19,6 @@ extern "C" { #include "../misc/lv_fs.h" #include "../misc/lv_types.h" #include "../misc/lv_area.h" -#include "../misc/cache/lv_cache.h" /********************* * DEFINES diff --git a/src/draw/lv_image_decoder_private.h b/src/draw/lv_image_decoder_private.h index c5bcb0d6d9..a0013a8424 100644 --- a/src/draw/lv_image_decoder_private.h +++ b/src/draw/lv_image_decoder_private.h @@ -13,8 +13,8 @@ extern "C" { /********************* * INCLUDES *********************/ - #include "lv_image_decoder.h" +#include "../misc/cache/lv_cache.h" /********************* * DEFINES diff --git a/src/draw/sw/lv_draw_sw.c b/src/draw/sw/lv_draw_sw.c index 01fae648ac..a5a2e1cc99 100644 --- a/src/draw/sw/lv_draw_sw.c +++ b/src/draw/sw/lv_draw_sw.c @@ -38,58 +38,6 @@ *********************/ #define DRAW_UNIT_ID_SW 1 -#ifndef LV_DRAW_SW_RGB565_SWAP - #define LV_DRAW_SW_RGB565_SWAP(...) LV_RESULT_INVALID -#endif - -#ifndef LV_DRAW_SW_ROTATE90_ARGB8888 - #define LV_DRAW_SW_ROTATE90_ARGB8888(...) LV_RESULT_INVALID -#endif - -#ifndef LV_DRAW_SW_ROTATE180_ARGB8888 - #define LV_DRAW_SW_ROTATE180_ARGB8888(...) LV_RESULT_INVALID -#endif - -#ifndef LV_DRAW_SW_ROTATE270_ARGB8888 - #define LV_DRAW_SW_ROTATE270_ARGB8888(...) LV_RESULT_INVALID -#endif - -#ifndef LV_DRAW_SW_ROTATE90_RGB888 - #define LV_DRAW_SW_ROTATE90_RGB888(...) LV_RESULT_INVALID -#endif - -#ifndef LV_DRAW_SW_ROTATE180_RGB888 - #define LV_DRAW_SW_ROTATE180_RGB888(...) LV_RESULT_INVALID -#endif - -#ifndef LV_DRAW_SW_ROTATE270_RGB888 - #define LV_DRAW_SW_ROTATE270_RGB888(...) LV_RESULT_INVALID -#endif - -#ifndef LV_DRAW_SW_ROTATE90_RGB565 - #define LV_DRAW_SW_ROTATE90_RGB565(...) LV_RESULT_INVALID -#endif - -#ifndef LV_DRAW_SW_ROTATE180_RGB565 - #define LV_DRAW_SW_ROTATE180_RGB565(...) LV_RESULT_INVALID -#endif - -#ifndef LV_DRAW_SW_ROTATE270_RGB565 - #define LV_DRAW_SW_ROTATE270_RGB565(...) LV_RESULT_INVALID -#endif - -#ifndef LV_DRAW_SW_ROTATE90_L8 - #define LV_DRAW_SW_ROTATE90_L8(...) LV_RESULT_INVALID -#endif - -#ifndef LV_DRAW_SW_ROTATE180_L8 - #define LV_DRAW_SW_ROTATE180_L8(...) LV_RESULT_INVALID -#endif - -#ifndef LV_DRAW_SW_ROTATE270_L8 - #define LV_DRAW_SW_ROTATE270_L8(...) LV_RESULT_INVALID -#endif - /********************** * TYPEDEFS **********************/ @@ -107,47 +55,6 @@ static int32_t dispatch(lv_draw_unit_t * draw_unit, lv_layer_t * layer); static int32_t evaluate(lv_draw_unit_t * draw_unit, lv_draw_task_t * task); static int32_t lv_draw_sw_delete(lv_draw_unit_t * draw_unit); -#if LV_DRAW_SW_SUPPORT_ARGB8888 -static void rotate90_argb8888(const uint32_t * src, uint32_t * dst, int32_t src_width, int32_t src_height, - int32_t src_stride, - int32_t dst_stride); -static void rotate180_argb8888(const uint32_t * src, uint32_t * dst, int32_t width, int32_t height, int32_t src_stride, - int32_t dest_stride); -static void rotate270_argb8888(const uint32_t * src, uint32_t * dst, int32_t src_width, int32_t src_height, - int32_t src_stride, - int32_t dst_stride); -#endif -#if LV_DRAW_SW_SUPPORT_RGB888 -static void rotate90_rgb888(const uint8_t * src, uint8_t * dst, int32_t src_width, int32_t src_height, - int32_t src_stride, - int32_t dst_stride); -static void rotate180_rgb888(const uint8_t * src, uint8_t * dst, int32_t width, int32_t height, int32_t src_stride, - int32_t dest_stride); -static void rotate270_rgb888(const uint8_t * src, uint8_t * dst, int32_t width, int32_t height, int32_t src_stride, - int32_t dst_stride); -#endif -#if LV_DRAW_SW_SUPPORT_RGB565 -static void rotate90_rgb565(const uint16_t * src, uint16_t * dst, int32_t src_width, int32_t src_height, - int32_t src_stride, - int32_t dst_stride); -static void rotate180_rgb565(const uint16_t * src, uint16_t * dst, int32_t width, int32_t height, int32_t src_stride, - int32_t dest_stride); -static void rotate270_rgb565(const uint16_t * src, uint16_t * dst, int32_t src_width, int32_t src_height, - int32_t src_stride, - int32_t dst_stride); -#endif - -#if LV_DRAW_SW_SUPPORT_L8 - -static void rotate90_l8(const uint8_t * src, uint8_t * dst, int32_t src_width, int32_t src_height, - int32_t src_stride, - int32_t dst_stride); -static void rotate180_l8(const uint8_t * src, uint8_t * dst, int32_t width, int32_t height, int32_t src_stride, - int32_t dest_stride); -static void rotate270_l8(const uint8_t * src, uint8_t * dst, int32_t src_width, int32_t src_height, - int32_t src_stride, - int32_t dst_stride); -#endif /********************** * STATIC VARIABLES **********************/ @@ -217,194 +124,6 @@ static int32_t lv_draw_sw_delete(lv_draw_unit_t * draw_unit) #endif } -void lv_draw_sw_rgb565_swap(void * buf, uint32_t buf_size_px) -{ - if(LV_DRAW_SW_RGB565_SWAP(buf, buf_size_px) == LV_RESULT_OK) return; - - uint32_t u32_cnt = buf_size_px / 2; - uint16_t * buf16 = buf; - uint32_t * buf32 = buf; - - while(u32_cnt >= 8) { - buf32[0] = ((buf32[0] & 0xff00ff00) >> 8) | ((buf32[0] & 0x00ff00ff) << 8); - buf32[1] = ((buf32[1] & 0xff00ff00) >> 8) | ((buf32[1] & 0x00ff00ff) << 8); - buf32[2] = ((buf32[2] & 0xff00ff00) >> 8) | ((buf32[2] & 0x00ff00ff) << 8); - buf32[3] = ((buf32[3] & 0xff00ff00) >> 8) | ((buf32[3] & 0x00ff00ff) << 8); - buf32[4] = ((buf32[4] & 0xff00ff00) >> 8) | ((buf32[4] & 0x00ff00ff) << 8); - buf32[5] = ((buf32[5] & 0xff00ff00) >> 8) | ((buf32[5] & 0x00ff00ff) << 8); - buf32[6] = ((buf32[6] & 0xff00ff00) >> 8) | ((buf32[6] & 0x00ff00ff) << 8); - buf32[7] = ((buf32[7] & 0xff00ff00) >> 8) | ((buf32[7] & 0x00ff00ff) << 8); - buf32 += 8; - u32_cnt -= 8; - } - - while(u32_cnt) { - *buf32 = ((*buf32 & 0xff00ff00) >> 8) | ((*buf32 & 0x00ff00ff) << 8); - buf32++; - u32_cnt--; - } - - if(buf_size_px & 0x1) { - uint32_t e = buf_size_px - 1; - buf16[e] = ((buf16[e] & 0xff00) >> 8) | ((buf16[e] & 0x00ff) << 8); - } - -} - -void lv_draw_sw_i1_invert(void * buf, uint32_t buf_size) -{ - if(buf == NULL) return; - - uint8_t * byte_buf = (uint8_t *)buf; - uint32_t i; - - /*Make the buffer aligned*/ - while(((uintptr_t)(byte_buf) & (sizeof(int) - 1)) && buf_size > 0) { - *byte_buf = ~(*byte_buf); - byte_buf++; - buf_size--; - } - - if(buf_size >= sizeof(uint32_t)) { - uint32_t * aligned_addr = (uint32_t *)byte_buf; - uint32_t word_count = buf_size / 4; - - for(i = 0; i < word_count; ++i) { - aligned_addr[i] = ~aligned_addr[i]; - } - - byte_buf = (uint8_t *)(aligned_addr + word_count); - buf_size = buf_size % sizeof(uint32_t); - } - - for(i = 0; i < buf_size; ++i) { - byte_buf[i] = ~byte_buf[i]; - } -} - -void lv_draw_sw_i1_convert_to_vtiled(const void * buf, uint32_t buf_size, uint32_t width, uint32_t height, - void * out_buf, - uint32_t out_buf_size, bool bit_order_lsb) -{ - LV_ASSERT(buf && out_buf); - LV_ASSERT(width % 8 == 0 && height % 8 == 0); - LV_ASSERT(buf_size == (width / 8) * height); - LV_ASSERT(out_buf_size >= buf_size); - - lv_memset(out_buf, 0, out_buf_size); - - const uint8_t * src_buf = (uint8_t *)buf; - uint8_t * dst_buf = (uint8_t *)out_buf; - - for(uint32_t y = 0; y < height; y++) { - for(uint32_t x = 0; x < width; x++) { - uint32_t src_index = y * width + x; - uint32_t dst_index = x * height + y; - uint8_t bit = (src_buf[src_index / 8] >> (7 - (src_index % 8))) & 0x01; - if(bit_order_lsb) { - dst_buf[dst_index / 8] |= (bit << (dst_index % 8)); - } - else { - dst_buf[dst_index / 8] |= (bit << (7 - (dst_index % 8))); - } - } - } -} - -void lv_draw_sw_rotate(const void * src, void * dest, int32_t src_width, int32_t src_height, int32_t src_stride, - int32_t dest_stride, lv_display_rotation_t rotation, lv_color_format_t color_format) -{ - if(rotation == LV_DISPLAY_ROTATION_90) { - switch(color_format) { -#if LV_DRAW_SW_SUPPORT_L8 - case LV_COLOR_FORMAT_L8: - rotate90_l8(src, dest, src_width, src_height, src_stride, dest_stride); - break; -#endif -#if LV_DRAW_SW_SUPPORT_RGB565 - case LV_COLOR_FORMAT_RGB565: - rotate90_rgb565(src, dest, src_width, src_height, src_stride, dest_stride); - break; -#endif -#if LV_DRAW_SW_SUPPORT_RGB888 - case LV_COLOR_FORMAT_RGB888: - rotate90_rgb888(src, dest, src_width, src_height, src_stride, dest_stride); - break; -#endif -#if LV_DRAW_SW_SUPPORT_ARGB8888 || LV_DRAW_SW_SUPPORT_XRGB8888 - case LV_COLOR_FORMAT_XRGB8888: - case LV_COLOR_FORMAT_ARGB8888: - rotate90_argb8888(src, dest, src_width, src_height, src_stride, dest_stride); - break; -#endif - default: - break; - } - - return; - } - - if(rotation == LV_DISPLAY_ROTATION_180) { - switch(color_format) { -#if LV_DRAW_SW_SUPPORT_L8 - case LV_COLOR_FORMAT_L8: - rotate180_l8(src, dest, src_width, src_height, src_stride, dest_stride); - break; -#endif -#if LV_DRAW_SW_SUPPORT_RGB565 - case LV_COLOR_FORMAT_RGB565: - rotate180_rgb565(src, dest, src_width, src_height, src_stride, dest_stride); - break; -#endif -#if LV_DRAW_SW_SUPPORT_RGB888 - case LV_COLOR_FORMAT_RGB888: - rotate180_rgb888(src, dest, src_width, src_height, src_stride, dest_stride); - break; -#endif -#if LV_DRAW_SW_SUPPORT_ARGB8888 || LV_DRAW_SW_SUPPORT_XRGB8888 - case LV_COLOR_FORMAT_XRGB8888: - case LV_COLOR_FORMAT_ARGB8888: - rotate180_argb8888(src, dest, src_width, src_height, src_stride, dest_stride); - break; -#endif - default: - break; - } - - return; - } - - if(rotation == LV_DISPLAY_ROTATION_270) { - switch(color_format) { -#if LV_DRAW_SW_SUPPORT_L8 - case LV_COLOR_FORMAT_L8: - rotate270_l8(src, dest, src_width, src_height, src_stride, dest_stride); - break; -#endif -#if LV_DRAW_SW_SUPPORT_RGB565 - case LV_COLOR_FORMAT_RGB565: - rotate270_rgb565(src, dest, src_width, src_height, src_stride, dest_stride); - break; -#endif -#if LV_DRAW_SW_SUPPORT_RGB888 - case LV_COLOR_FORMAT_RGB888: - rotate270_rgb888(src, dest, src_width, src_height, src_stride, dest_stride); - break; -#endif -#if LV_DRAW_SW_SUPPORT_ARGB8888 || LV_DRAW_SW_SUPPORT_XRGB8888 - case LV_COLOR_FORMAT_XRGB8888: - case LV_COLOR_FORMAT_ARGB8888: - rotate270_argb8888(src, dest, src_width, src_height, src_stride, dest_stride); - break; -#endif - default: - break; - } - - return; - } -} - /********************** * STATIC FUNCTIONS **********************/ @@ -625,250 +344,4 @@ static void execute_drawing(lv_draw_sw_unit_t * u) LV_PROFILER_DRAW_END; } -#if LV_DRAW_SW_SUPPORT_ARGB8888 - -static void rotate270_argb8888(const uint32_t * src, uint32_t * dst, int32_t src_width, int32_t src_height, - int32_t src_stride, - int32_t dst_stride) -{ - if(LV_RESULT_OK == LV_DRAW_SW_ROTATE90_ARGB8888(src, dst, src_width, src_height, src_stride, dst_stride)) { - return ; - } - - src_stride /= sizeof(uint32_t); - dst_stride /= sizeof(uint32_t); - - for(int32_t x = 0; x < src_width; ++x) { - int32_t dstIndex = x * dst_stride; - int32_t srcIndex = x; - for(int32_t y = 0; y < src_height; ++y) { - dst[dstIndex + (src_height - y - 1)] = src[srcIndex]; - srcIndex += src_stride; - } - } -} - -static void rotate180_argb8888(const uint32_t * src, uint32_t * dst, int32_t width, int32_t height, int32_t src_stride, - int32_t dest_stride) -{ - LV_UNUSED(dest_stride); - if(LV_RESULT_OK == LV_DRAW_SW_ROTATE180_ARGB8888(src, dst, src_width, src_height, src_stride, dst_stride)) { - return ; - } - - src_stride /= sizeof(uint32_t); - dest_stride /= sizeof(uint32_t); - - for(int32_t y = 0; y < height; ++y) { - int32_t dstIndex = (height - y - 1) * dest_stride; - int32_t srcIndex = y * src_stride; - for(int32_t x = 0; x < width; ++x) { - dst[dstIndex + width - x - 1] = src[srcIndex + x]; - } - } -} - -static void rotate90_argb8888(const uint32_t * src, uint32_t * dst, int32_t src_width, int32_t src_height, - int32_t src_stride, int32_t dst_stride) -{ - if(LV_RESULT_OK == LV_DRAW_SW_ROTATE270_ARGB8888(src, dst, src_width, src_height, src_stride, dst_stride)) { - return ; - } - - src_stride /= sizeof(uint32_t); - dst_stride /= sizeof(uint32_t); - - for(int32_t x = 0; x < src_width; ++x) { - int32_t dstIndex = (src_width - x - 1); - int32_t srcIndex = x; - for(int32_t y = 0; y < src_height; ++y) { - dst[dstIndex * dst_stride + y] = src[srcIndex]; - srcIndex += src_stride; - } - } -} - -#endif - -#if LV_DRAW_SW_SUPPORT_RGB888 - -static void rotate90_rgb888(const uint8_t * src, uint8_t * dst, int32_t src_width, int32_t src_height, - int32_t src_stride, - int32_t dst_stride) -{ - if(LV_RESULT_OK == LV_DRAW_SW_ROTATE90_RGB888(src, dst, src_width, src_height, src_stride, dst_stride)) { - return ; - } - - for(int32_t x = 0; x < src_width; ++x) { - for(int32_t y = 0; y < src_height; ++y) { - int32_t srcIndex = y * src_stride + x * 3; - int32_t dstIndex = (src_width - x - 1) * dst_stride + y * 3; - dst[dstIndex] = src[srcIndex]; /*Red*/ - dst[dstIndex + 1] = src[srcIndex + 1]; /*Green*/ - dst[dstIndex + 2] = src[srcIndex + 2]; /*Blue*/ - } - } -} - -static void rotate180_rgb888(const uint8_t * src, uint8_t * dst, int32_t width, int32_t height, int32_t src_stride, - int32_t dest_stride) -{ - if(LV_RESULT_OK == LV_DRAW_SW_ROTATE180_RGB888(src, dst, src_width, src_height, src_stride, dst_stride)) { - return ; - } - - for(int32_t y = 0; y < height; ++y) { - for(int32_t x = 0; x < width; ++x) { - int32_t srcIndex = y * src_stride + x * 3; - int32_t dstIndex = (height - y - 1) * dest_stride + (width - x - 1) * 3; - dst[dstIndex] = src[srcIndex]; - dst[dstIndex + 1] = src[srcIndex + 1]; - dst[dstIndex + 2] = src[srcIndex + 2]; - } - } -} - -static void rotate270_rgb888(const uint8_t * src, uint8_t * dst, int32_t width, int32_t height, int32_t src_stride, - int32_t dst_stride) -{ - if(LV_RESULT_OK == LV_DRAW_SW_ROTATE270_RGB888(src, dst, src_width, src_height, src_stride, dst_stride)) { - return ; - } - - for(int32_t x = 0; x < width; ++x) { - for(int32_t y = 0; y < height; ++y) { - int32_t srcIndex = y * src_stride + x * 3; - int32_t dstIndex = x * dst_stride + (height - y - 1) * 3; - dst[dstIndex] = src[srcIndex]; /*Red*/ - dst[dstIndex + 1] = src[srcIndex + 1]; /*Green*/ - dst[dstIndex + 2] = src[srcIndex + 2]; /*Blue*/ - } - } -} - -#endif - -#if LV_DRAW_SW_SUPPORT_RGB565 - -static void rotate270_rgb565(const uint16_t * src, uint16_t * dst, int32_t src_width, int32_t src_height, - int32_t src_stride, - int32_t dst_stride) -{ - if(LV_RESULT_OK == LV_DRAW_SW_ROTATE90_RGB565(src, dst, src_width, src_height, src_stride, dst_stride)) { - return ; - } - - src_stride /= sizeof(uint16_t); - dst_stride /= sizeof(uint16_t); - - for(int32_t x = 0; x < src_width; ++x) { - int32_t dstIndex = x * dst_stride; - int32_t srcIndex = x; - for(int32_t y = 0; y < src_height; ++y) { - dst[dstIndex + (src_height - y - 1)] = src[srcIndex]; - srcIndex += src_stride; - } - } -} - -static void rotate180_rgb565(const uint16_t * src, uint16_t * dst, int32_t width, int32_t height, int32_t src_stride, - int32_t dest_stride) -{ - if(LV_RESULT_OK == LV_DRAW_SW_ROTATE180_RGB565(src, dst, width, height, src_stride)) { - return ; - } - - src_stride /= sizeof(uint16_t); - dest_stride /= sizeof(uint16_t); - - for(int32_t y = 0; y < height; ++y) { - int32_t dstIndex = (height - y - 1) * dest_stride; - int32_t srcIndex = y * src_stride; - for(int32_t x = 0; x < width; ++x) { - dst[dstIndex + width - x - 1] = src[srcIndex + x]; - } - } -} - -static void rotate90_rgb565(const uint16_t * src, uint16_t * dst, int32_t src_width, int32_t src_height, - int32_t src_stride, - int32_t dst_stride) -{ - if(LV_RESULT_OK == LV_DRAW_SW_ROTATE270_RGB565(src, dst, src_width, src_height, src_stride, dst_stride)) { - return ; - } - - src_stride /= sizeof(uint16_t); - dst_stride /= sizeof(uint16_t); - - for(int32_t x = 0; x < src_width; ++x) { - int32_t dstIndex = (src_width - x - 1); - int32_t srcIndex = x; - for(int32_t y = 0; y < src_height; ++y) { - dst[dstIndex * dst_stride + y] = src[srcIndex]; - srcIndex += src_stride; - } - } -} - -#endif - - -#if LV_DRAW_SW_SUPPORT_L8 - -static void rotate90_l8(const uint8_t * src, uint8_t * dst, int32_t src_width, int32_t src_height, - int32_t src_stride, - int32_t dst_stride) -{ - if(LV_RESULT_OK == LV_DRAW_SW_ROTATE270_L8(src, dst, src_width, src_height, src_stride, dst_stride)) { - return ; - } - - for(int32_t x = 0; x < src_width; ++x) { - int32_t dstIndex = (src_width - x - 1); - int32_t srcIndex = x; - for(int32_t y = 0; y < src_height; ++y) { - dst[dstIndex * dst_stride + y] = src[srcIndex]; - srcIndex += src_stride; - } - } -} - -static void rotate180_l8(const uint8_t * src, uint8_t * dst, int32_t width, int32_t height, int32_t src_stride, - int32_t dest_stride) -{ - if(LV_RESULT_OK == LV_DRAW_SW_ROTATE180_L8(src, dst, width, height, src_stride)) { - return ; - } - - for(int32_t y = 0; y < height; ++y) { - int32_t dstIndex = (height - y - 1) * dest_stride; - int32_t srcIndex = y * src_stride; - for(int32_t x = 0; x < width; ++x) { - dst[dstIndex + width - x - 1] = src[srcIndex + x]; - } - } -} - -static void rotate270_l8(const uint8_t * src, uint8_t * dst, int32_t src_width, int32_t src_height, - int32_t src_stride, - int32_t dst_stride) -{ - if(LV_RESULT_OK == LV_DRAW_SW_ROTATE90_L8(src, dst, src_width, src_height, src_stride, dst_stride)) { - return ; - } - - for(int32_t x = 0; x < src_width; ++x) { - int32_t dstIndex = x * dst_stride; - int32_t srcIndex = x; - for(int32_t y = 0; y < src_height; ++y) { - dst[dstIndex + (src_height - y - 1)] = src[srcIndex]; - srcIndex += src_stride; - } - } -} - -#endif - #endif /*LV_USE_DRAW_SW*/ diff --git a/src/draw/sw/lv_draw_sw.h b/src/draw/sw/lv_draw_sw.h index 48b2393716..959a2572b3 100644 --- a/src/draw/sw/lv_draw_sw.h +++ b/src/draw/sw/lv_draw_sw.h @@ -27,6 +27,7 @@ extern "C" { #include "../lv_draw_image.h" #include "../lv_draw_line.h" #include "../lv_draw_arc.h" +#include "lv_draw_sw_utils.h" /********************* * DEFINES @@ -152,56 +153,6 @@ void lv_draw_sw_transform(lv_draw_unit_t * draw_unit, const lv_area_t * dest_are void lv_draw_sw_vector(lv_draw_unit_t * draw_unit, const lv_draw_vector_task_dsc_t * dsc); #endif -/** - * Swap the upper and lower byte of an RGB565 buffer. - * Might be required if a 8bit parallel port or an SPI port send the bytes in the wrong order. - * The bytes will be swapped in place. - * @param buf pointer to buffer - * @param buf_size_px number of pixels in the buffer - */ -void lv_draw_sw_rgb565_swap(void * buf, uint32_t buf_size_px); - -/** - * Invert a draw buffer in the I1 color format. - * Conventionally, a bit is set to 1 during blending if the luminance is greater than 127. - * Depending on the display controller used, you might want to have different behavior. - * The inversion will be performed in place. - * @param buf pointer to the buffer to be inverted - * @param buf_size size of the buffer in bytes - */ -void lv_draw_sw_i1_invert(void * buf, uint32_t buf_size); - - -/** - * Convert a draw buffer in I1 color format from htiled (row-wise) - * to vtiled (column-wise) buffer layout. The conversion assumes that the buffer width - * and height is rounded to a multiple of 8. - * @param buf pointer to the buffer to be converted - * @param buf_size size of the buffer in bytes - * @param width width of the buffer - * @param height height of the buffer - * @param out_buf pointer to the output buffer - * @param out_buf_size size of the output buffer in bytes - * @param bit_order_lsb bit order of the resulting vtiled buffer - */ -void lv_draw_sw_i1_convert_to_vtiled(const void * buf, uint32_t buf_size, uint32_t width, uint32_t height, - void * out_buf, - uint32_t out_buf_size, bool bit_order_lsb); - -/** - * Rotate a buffer into another buffer - * @param src the source buffer - * @param dest the destination buffer - * @param src_width source width in pixels - * @param src_height source height in pixels - * @param src_stride source stride in bytes (number of bytes in a row) - * @param dest_stride destination stride in bytes (number of bytes in a row) - * @param rotation LV_DISPLAY_ROTATION_0/90/180/270 - * @param color_format LV_COLOR_FORMAT_RGB565/RGB888/XRGB8888/ARGB8888 - */ -void lv_draw_sw_rotate(const void * src, void * dest, int32_t src_width, int32_t src_height, int32_t src_stride, - int32_t dest_stride, lv_display_rotation_t rotation, lv_color_format_t color_format); - /*********************** * GLOBAL VARIABLES ***********************/ diff --git a/src/draw/sw/lv_draw_sw_utils.c b/src/draw/sw/lv_draw_sw_utils.c new file mode 100644 index 0000000000..8e88a1fb53 --- /dev/null +++ b/src/draw/sw/lv_draw_sw_utils.c @@ -0,0 +1,567 @@ +/** + * @file lv_draw_sw_utils.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_draw_sw_utils.h" +#if LV_USE_DRAW_SW + +/********************* + * DEFINES + *********************/ +#ifndef LV_DRAW_SW_RGB565_SWAP + #define LV_DRAW_SW_RGB565_SWAP(...) LV_RESULT_INVALID +#endif + +#ifndef LV_DRAW_SW_ROTATE90_ARGB8888 + #define LV_DRAW_SW_ROTATE90_ARGB8888(...) LV_RESULT_INVALID +#endif + +#ifndef LV_DRAW_SW_ROTATE180_ARGB8888 + #define LV_DRAW_SW_ROTATE180_ARGB8888(...) LV_RESULT_INVALID +#endif + +#ifndef LV_DRAW_SW_ROTATE270_ARGB8888 + #define LV_DRAW_SW_ROTATE270_ARGB8888(...) LV_RESULT_INVALID +#endif + +#ifndef LV_DRAW_SW_ROTATE90_RGB888 + #define LV_DRAW_SW_ROTATE90_RGB888(...) LV_RESULT_INVALID +#endif + +#ifndef LV_DRAW_SW_ROTATE180_RGB888 + #define LV_DRAW_SW_ROTATE180_RGB888(...) LV_RESULT_INVALID +#endif + +#ifndef LV_DRAW_SW_ROTATE270_RGB888 + #define LV_DRAW_SW_ROTATE270_RGB888(...) LV_RESULT_INVALID +#endif + +#ifndef LV_DRAW_SW_ROTATE90_RGB565 + #define LV_DRAW_SW_ROTATE90_RGB565(...) LV_RESULT_INVALID +#endif + +#ifndef LV_DRAW_SW_ROTATE180_RGB565 + #define LV_DRAW_SW_ROTATE180_RGB565(...) LV_RESULT_INVALID +#endif + +#ifndef LV_DRAW_SW_ROTATE270_RGB565 + #define LV_DRAW_SW_ROTATE270_RGB565(...) LV_RESULT_INVALID +#endif + +#ifndef LV_DRAW_SW_ROTATE90_L8 + #define LV_DRAW_SW_ROTATE90_L8(...) LV_RESULT_INVALID +#endif + +#ifndef LV_DRAW_SW_ROTATE180_L8 + #define LV_DRAW_SW_ROTATE180_L8(...) LV_RESULT_INVALID +#endif + +#ifndef LV_DRAW_SW_ROTATE270_L8 + #define LV_DRAW_SW_ROTATE270_L8(...) LV_RESULT_INVALID +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +#if LV_DRAW_SW_SUPPORT_ARGB8888 +static void rotate90_argb8888(const uint32_t * src, uint32_t * dst, int32_t src_width, int32_t src_height, + int32_t src_stride, + int32_t dst_stride); +static void rotate180_argb8888(const uint32_t * src, uint32_t * dst, int32_t width, int32_t height, int32_t src_stride, + int32_t dest_stride); +static void rotate270_argb8888(const uint32_t * src, uint32_t * dst, int32_t src_width, int32_t src_height, + int32_t src_stride, + int32_t dst_stride); +#endif +#if LV_DRAW_SW_SUPPORT_RGB888 +static void rotate90_rgb888(const uint8_t * src, uint8_t * dst, int32_t src_width, int32_t src_height, + int32_t src_stride, + int32_t dst_stride); +static void rotate180_rgb888(const uint8_t * src, uint8_t * dst, int32_t width, int32_t height, int32_t src_stride, + int32_t dest_stride); +static void rotate270_rgb888(const uint8_t * src, uint8_t * dst, int32_t width, int32_t height, int32_t src_stride, + int32_t dst_stride); +#endif +#if LV_DRAW_SW_SUPPORT_RGB565 +static void rotate90_rgb565(const uint16_t * src, uint16_t * dst, int32_t src_width, int32_t src_height, + int32_t src_stride, + int32_t dst_stride); +static void rotate180_rgb565(const uint16_t * src, uint16_t * dst, int32_t width, int32_t height, int32_t src_stride, + int32_t dest_stride); +static void rotate270_rgb565(const uint16_t * src, uint16_t * dst, int32_t src_width, int32_t src_height, + int32_t src_stride, + int32_t dst_stride); +#endif + +#if LV_DRAW_SW_SUPPORT_L8 + +static void rotate90_l8(const uint8_t * src, uint8_t * dst, int32_t src_width, int32_t src_height, + int32_t src_stride, + int32_t dst_stride); +static void rotate180_l8(const uint8_t * src, uint8_t * dst, int32_t width, int32_t height, int32_t src_stride, + int32_t dest_stride); +static void rotate270_l8(const uint8_t * src, uint8_t * dst, int32_t src_width, int32_t src_height, + int32_t src_stride, + int32_t dst_stride); +#endif + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +void lv_draw_sw_rgb565_swap(void * buf, uint32_t buf_size_px) +{ + if(LV_DRAW_SW_RGB565_SWAP(buf, buf_size_px) == LV_RESULT_OK) return; + + uint32_t u32_cnt = buf_size_px / 2; + uint16_t * buf16 = buf; + uint32_t * buf32 = buf; + + while(u32_cnt >= 8) { + buf32[0] = ((buf32[0] & 0xff00ff00) >> 8) | ((buf32[0] & 0x00ff00ff) << 8); + buf32[1] = ((buf32[1] & 0xff00ff00) >> 8) | ((buf32[1] & 0x00ff00ff) << 8); + buf32[2] = ((buf32[2] & 0xff00ff00) >> 8) | ((buf32[2] & 0x00ff00ff) << 8); + buf32[3] = ((buf32[3] & 0xff00ff00) >> 8) | ((buf32[3] & 0x00ff00ff) << 8); + buf32[4] = ((buf32[4] & 0xff00ff00) >> 8) | ((buf32[4] & 0x00ff00ff) << 8); + buf32[5] = ((buf32[5] & 0xff00ff00) >> 8) | ((buf32[5] & 0x00ff00ff) << 8); + buf32[6] = ((buf32[6] & 0xff00ff00) >> 8) | ((buf32[6] & 0x00ff00ff) << 8); + buf32[7] = ((buf32[7] & 0xff00ff00) >> 8) | ((buf32[7] & 0x00ff00ff) << 8); + buf32 += 8; + u32_cnt -= 8; + } + + while(u32_cnt) { + *buf32 = ((*buf32 & 0xff00ff00) >> 8) | ((*buf32 & 0x00ff00ff) << 8); + buf32++; + u32_cnt--; + } + + if(buf_size_px & 0x1) { + uint32_t e = buf_size_px - 1; + buf16[e] = ((buf16[e] & 0xff00) >> 8) | ((buf16[e] & 0x00ff) << 8); + } + +} + +void lv_draw_sw_i1_invert(void * buf, uint32_t buf_size) +{ + if(buf == NULL) return; + + uint8_t * byte_buf = (uint8_t *)buf; + uint32_t i; + + /*Make the buffer aligned*/ + while(((uintptr_t)(byte_buf) & (sizeof(int) - 1)) && buf_size > 0) { + *byte_buf = ~(*byte_buf); + byte_buf++; + buf_size--; + } + + if(buf_size >= sizeof(uint32_t)) { + uint32_t * aligned_addr = (uint32_t *)byte_buf; + uint32_t word_count = buf_size / 4; + + for(i = 0; i < word_count; ++i) { + aligned_addr[i] = ~aligned_addr[i]; + } + + byte_buf = (uint8_t *)(aligned_addr + word_count); + buf_size = buf_size % sizeof(uint32_t); + } + + for(i = 0; i < buf_size; ++i) { + byte_buf[i] = ~byte_buf[i]; + } +} + +void lv_draw_sw_i1_convert_to_vtiled(const void * buf, uint32_t buf_size, uint32_t width, uint32_t height, + void * out_buf, + uint32_t out_buf_size, bool bit_order_lsb) +{ + LV_ASSERT(buf && out_buf); + LV_ASSERT(width % 8 == 0 && height % 8 == 0); + LV_ASSERT(buf_size == (width / 8) * height); + LV_ASSERT(out_buf_size >= buf_size); + + lv_memset(out_buf, 0, out_buf_size); + + const uint8_t * src_buf = (uint8_t *)buf; + uint8_t * dst_buf = (uint8_t *)out_buf; + + for(uint32_t y = 0; y < height; y++) { + for(uint32_t x = 0; x < width; x++) { + uint32_t src_index = y * width + x; + uint32_t dst_index = x * height + y; + uint8_t bit = (src_buf[src_index / 8] >> (7 - (src_index % 8))) & 0x01; + if(bit_order_lsb) { + dst_buf[dst_index / 8] |= (bit << (dst_index % 8)); + } + else { + dst_buf[dst_index / 8] |= (bit << (7 - (dst_index % 8))); + } + } + } +} + +void lv_draw_sw_rotate(const void * src, void * dest, int32_t src_width, int32_t src_height, int32_t src_stride, + int32_t dest_stride, lv_display_rotation_t rotation, lv_color_format_t color_format) +{ + if(rotation == LV_DISPLAY_ROTATION_90) { + switch(color_format) { +#if LV_DRAW_SW_SUPPORT_L8 + case LV_COLOR_FORMAT_L8: + rotate90_l8(src, dest, src_width, src_height, src_stride, dest_stride); + break; +#endif +#if LV_DRAW_SW_SUPPORT_RGB565 + case LV_COLOR_FORMAT_RGB565: + rotate90_rgb565(src, dest, src_width, src_height, src_stride, dest_stride); + break; +#endif +#if LV_DRAW_SW_SUPPORT_RGB888 + case LV_COLOR_FORMAT_RGB888: + rotate90_rgb888(src, dest, src_width, src_height, src_stride, dest_stride); + break; +#endif +#if LV_DRAW_SW_SUPPORT_ARGB8888 || LV_DRAW_SW_SUPPORT_XRGB8888 + case LV_COLOR_FORMAT_XRGB8888: + case LV_COLOR_FORMAT_ARGB8888: + rotate90_argb8888(src, dest, src_width, src_height, src_stride, dest_stride); + break; +#endif + default: + break; + } + + return; + } + + if(rotation == LV_DISPLAY_ROTATION_180) { + switch(color_format) { +#if LV_DRAW_SW_SUPPORT_L8 + case LV_COLOR_FORMAT_L8: + rotate180_l8(src, dest, src_width, src_height, src_stride, dest_stride); + break; +#endif +#if LV_DRAW_SW_SUPPORT_RGB565 + case LV_COLOR_FORMAT_RGB565: + rotate180_rgb565(src, dest, src_width, src_height, src_stride, dest_stride); + break; +#endif +#if LV_DRAW_SW_SUPPORT_RGB888 + case LV_COLOR_FORMAT_RGB888: + rotate180_rgb888(src, dest, src_width, src_height, src_stride, dest_stride); + break; +#endif +#if LV_DRAW_SW_SUPPORT_ARGB8888 || LV_DRAW_SW_SUPPORT_XRGB8888 + case LV_COLOR_FORMAT_XRGB8888: + case LV_COLOR_FORMAT_ARGB8888: + rotate180_argb8888(src, dest, src_width, src_height, src_stride, dest_stride); + break; +#endif + default: + break; + } + + return; + } + + if(rotation == LV_DISPLAY_ROTATION_270) { + switch(color_format) { +#if LV_DRAW_SW_SUPPORT_L8 + case LV_COLOR_FORMAT_L8: + rotate270_l8(src, dest, src_width, src_height, src_stride, dest_stride); + break; +#endif +#if LV_DRAW_SW_SUPPORT_RGB565 + case LV_COLOR_FORMAT_RGB565: + rotate270_rgb565(src, dest, src_width, src_height, src_stride, dest_stride); + break; +#endif +#if LV_DRAW_SW_SUPPORT_RGB888 + case LV_COLOR_FORMAT_RGB888: + rotate270_rgb888(src, dest, src_width, src_height, src_stride, dest_stride); + break; +#endif +#if LV_DRAW_SW_SUPPORT_ARGB8888 || LV_DRAW_SW_SUPPORT_XRGB8888 + case LV_COLOR_FORMAT_XRGB8888: + case LV_COLOR_FORMAT_ARGB8888: + rotate270_argb8888(src, dest, src_width, src_height, src_stride, dest_stride); + break; +#endif + default: + break; + } + + return; + } +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +#if LV_DRAW_SW_SUPPORT_ARGB8888 + +static void rotate270_argb8888(const uint32_t * src, uint32_t * dst, int32_t src_width, int32_t src_height, + int32_t src_stride, + int32_t dst_stride) +{ + if(LV_RESULT_OK == LV_DRAW_SW_ROTATE90_ARGB8888(src, dst, src_width, src_height, src_stride, dst_stride)) { + return ; + } + + src_stride /= sizeof(uint32_t); + dst_stride /= sizeof(uint32_t); + + for(int32_t x = 0; x < src_width; ++x) { + int32_t dstIndex = x * dst_stride; + int32_t srcIndex = x; + for(int32_t y = 0; y < src_height; ++y) { + dst[dstIndex + (src_height - y - 1)] = src[srcIndex]; + srcIndex += src_stride; + } + } +} + +static void rotate180_argb8888(const uint32_t * src, uint32_t * dst, int32_t width, int32_t height, int32_t src_stride, + int32_t dest_stride) +{ + LV_UNUSED(dest_stride); + if(LV_RESULT_OK == LV_DRAW_SW_ROTATE180_ARGB8888(src, dst, src_width, src_height, src_stride, dst_stride)) { + return ; + } + + src_stride /= sizeof(uint32_t); + dest_stride /= sizeof(uint32_t); + + for(int32_t y = 0; y < height; ++y) { + int32_t dstIndex = (height - y - 1) * dest_stride; + int32_t srcIndex = y * src_stride; + for(int32_t x = 0; x < width; ++x) { + dst[dstIndex + width - x - 1] = src[srcIndex + x]; + } + } +} + +static void rotate90_argb8888(const uint32_t * src, uint32_t * dst, int32_t src_width, int32_t src_height, + int32_t src_stride, int32_t dst_stride) +{ + if(LV_RESULT_OK == LV_DRAW_SW_ROTATE270_ARGB8888(src, dst, src_width, src_height, src_stride, dst_stride)) { + return ; + } + + src_stride /= sizeof(uint32_t); + dst_stride /= sizeof(uint32_t); + + for(int32_t x = 0; x < src_width; ++x) { + int32_t dstIndex = (src_width - x - 1); + int32_t srcIndex = x; + for(int32_t y = 0; y < src_height; ++y) { + dst[dstIndex * dst_stride + y] = src[srcIndex]; + srcIndex += src_stride; + } + } +} + +#endif + +#if LV_DRAW_SW_SUPPORT_RGB888 + +static void rotate90_rgb888(const uint8_t * src, uint8_t * dst, int32_t src_width, int32_t src_height, + int32_t src_stride, + int32_t dst_stride) +{ + if(LV_RESULT_OK == LV_DRAW_SW_ROTATE90_RGB888(src, dst, src_width, src_height, src_stride, dst_stride)) { + return ; + } + + for(int32_t x = 0; x < src_width; ++x) { + for(int32_t y = 0; y < src_height; ++y) { + int32_t srcIndex = y * src_stride + x * 3; + int32_t dstIndex = (src_width - x - 1) * dst_stride + y * 3; + dst[dstIndex] = src[srcIndex]; /*Red*/ + dst[dstIndex + 1] = src[srcIndex + 1]; /*Green*/ + dst[dstIndex + 2] = src[srcIndex + 2]; /*Blue*/ + } + } +} + +static void rotate180_rgb888(const uint8_t * src, uint8_t * dst, int32_t width, int32_t height, int32_t src_stride, + int32_t dest_stride) +{ + if(LV_RESULT_OK == LV_DRAW_SW_ROTATE180_RGB888(src, dst, src_width, src_height, src_stride, dst_stride)) { + return ; + } + + for(int32_t y = 0; y < height; ++y) { + for(int32_t x = 0; x < width; ++x) { + int32_t srcIndex = y * src_stride + x * 3; + int32_t dstIndex = (height - y - 1) * dest_stride + (width - x - 1) * 3; + dst[dstIndex] = src[srcIndex]; + dst[dstIndex + 1] = src[srcIndex + 1]; + dst[dstIndex + 2] = src[srcIndex + 2]; + } + } +} + +static void rotate270_rgb888(const uint8_t * src, uint8_t * dst, int32_t width, int32_t height, int32_t src_stride, + int32_t dst_stride) +{ + if(LV_RESULT_OK == LV_DRAW_SW_ROTATE270_RGB888(src, dst, src_width, src_height, src_stride, dst_stride)) { + return ; + } + + for(int32_t x = 0; x < width; ++x) { + for(int32_t y = 0; y < height; ++y) { + int32_t srcIndex = y * src_stride + x * 3; + int32_t dstIndex = x * dst_stride + (height - y - 1) * 3; + dst[dstIndex] = src[srcIndex]; /*Red*/ + dst[dstIndex + 1] = src[srcIndex + 1]; /*Green*/ + dst[dstIndex + 2] = src[srcIndex + 2]; /*Blue*/ + } + } +} + +#endif + +#if LV_DRAW_SW_SUPPORT_RGB565 + +static void rotate270_rgb565(const uint16_t * src, uint16_t * dst, int32_t src_width, int32_t src_height, + int32_t src_stride, + int32_t dst_stride) +{ + if(LV_RESULT_OK == LV_DRAW_SW_ROTATE90_RGB565(src, dst, src_width, src_height, src_stride, dst_stride)) { + return ; + } + + src_stride /= sizeof(uint16_t); + dst_stride /= sizeof(uint16_t); + + for(int32_t x = 0; x < src_width; ++x) { + int32_t dstIndex = x * dst_stride; + int32_t srcIndex = x; + for(int32_t y = 0; y < src_height; ++y) { + dst[dstIndex + (src_height - y - 1)] = src[srcIndex]; + srcIndex += src_stride; + } + } +} + +static void rotate180_rgb565(const uint16_t * src, uint16_t * dst, int32_t width, int32_t height, int32_t src_stride, + int32_t dest_stride) +{ + if(LV_RESULT_OK == LV_DRAW_SW_ROTATE180_RGB565(src, dst, width, height, src_stride)) { + return ; + } + + src_stride /= sizeof(uint16_t); + dest_stride /= sizeof(uint16_t); + + for(int32_t y = 0; y < height; ++y) { + int32_t dstIndex = (height - y - 1) * dest_stride; + int32_t srcIndex = y * src_stride; + for(int32_t x = 0; x < width; ++x) { + dst[dstIndex + width - x - 1] = src[srcIndex + x]; + } + } +} + +static void rotate90_rgb565(const uint16_t * src, uint16_t * dst, int32_t src_width, int32_t src_height, + int32_t src_stride, + int32_t dst_stride) +{ + if(LV_RESULT_OK == LV_DRAW_SW_ROTATE270_RGB565(src, dst, src_width, src_height, src_stride, dst_stride)) { + return ; + } + + src_stride /= sizeof(uint16_t); + dst_stride /= sizeof(uint16_t); + + for(int32_t x = 0; x < src_width; ++x) { + int32_t dstIndex = (src_width - x - 1); + int32_t srcIndex = x; + for(int32_t y = 0; y < src_height; ++y) { + dst[dstIndex * dst_stride + y] = src[srcIndex]; + srcIndex += src_stride; + } + } +} + +#endif + + +#if LV_DRAW_SW_SUPPORT_L8 + +static void rotate90_l8(const uint8_t * src, uint8_t * dst, int32_t src_width, int32_t src_height, + int32_t src_stride, + int32_t dst_stride) +{ + if(LV_RESULT_OK == LV_DRAW_SW_ROTATE270_L8(src, dst, src_width, src_height, src_stride, dst_stride)) { + return ; + } + + for(int32_t x = 0; x < src_width; ++x) { + int32_t dstIndex = (src_width - x - 1); + int32_t srcIndex = x; + for(int32_t y = 0; y < src_height; ++y) { + dst[dstIndex * dst_stride + y] = src[srcIndex]; + srcIndex += src_stride; + } + } +} + +static void rotate180_l8(const uint8_t * src, uint8_t * dst, int32_t width, int32_t height, int32_t src_stride, + int32_t dest_stride) +{ + if(LV_RESULT_OK == LV_DRAW_SW_ROTATE180_L8(src, dst, width, height, src_stride)) { + return ; + } + + for(int32_t y = 0; y < height; ++y) { + int32_t dstIndex = (height - y - 1) * dest_stride; + int32_t srcIndex = y * src_stride; + for(int32_t x = 0; x < width; ++x) { + dst[dstIndex + width - x - 1] = src[srcIndex + x]; + } + } +} + +static void rotate270_l8(const uint8_t * src, uint8_t * dst, int32_t src_width, int32_t src_height, + int32_t src_stride, + int32_t dst_stride) +{ + if(LV_RESULT_OK == LV_DRAW_SW_ROTATE90_L8(src, dst, src_width, src_height, src_stride, dst_stride)) { + return ; + } + + for(int32_t x = 0; x < src_width; ++x) { + int32_t dstIndex = x * dst_stride; + int32_t srcIndex = x; + for(int32_t y = 0; y < src_height; ++y) { + dst[dstIndex + (src_height - y - 1)] = src[srcIndex]; + srcIndex += src_stride; + } + } +} + +#endif + +#endif /*LV_USE_DRAW_SW*/ diff --git a/src/draw/sw/lv_draw_sw_utils.h b/src/draw/sw/lv_draw_sw_utils.h new file mode 100644 index 0000000000..293155efb2 --- /dev/null +++ b/src/draw/sw/lv_draw_sw_utils.h @@ -0,0 +1,96 @@ +/** + * @file lv_draw_sw_utils.h + * + */ + +#ifndef LV_DRAW_SW_UTILS_H +#define LV_DRAW_SW_UTILS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "../../lv_conf_internal.h" +#if LV_USE_DRAW_SW + +#include "../../misc/lv_area.h" +#include "../../misc/lv_color.h" +#include "../../display/lv_display.h" + + +/********************* + * DEFINES + *********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Swap the upper and lower byte of an RGB565 buffer. + * Might be required if a 8bit parallel port or an SPI port send the bytes in the wrong order. + * The bytes will be swapped in place. + * @param buf pointer to buffer + * @param buf_size_px number of pixels in the buffer + */ +void lv_draw_sw_rgb565_swap(void * buf, uint32_t buf_size_px); + +/** + * Invert a draw buffer in the I1 color format. + * Conventionally, a bit is set to 1 during blending if the luminance is greater than 127. + * Depending on the display controller used, you might want to have different behavior. + * The inversion will be performed in place. + * @param buf pointer to the buffer to be inverted + * @param buf_size size of the buffer in bytes + */ +void lv_draw_sw_i1_invert(void * buf, uint32_t buf_size); + + +/** + * Convert a draw buffer in I1 color format from htiled (row-wise) + * to vtiled (column-wise) buffer layout. The conversion assumes that the buffer width + * and height is rounded to a multiple of 8. + * @param buf pointer to the buffer to be converted + * @param buf_size size of the buffer in bytes + * @param width width of the buffer + * @param height height of the buffer + * @param out_buf pointer to the output buffer + * @param out_buf_size size of the output buffer in bytes + * @param bit_order_lsb bit order of the resulting vtiled buffer + */ +void lv_draw_sw_i1_convert_to_vtiled(const void * buf, uint32_t buf_size, uint32_t width, uint32_t height, + void * out_buf, + uint32_t out_buf_size, bool bit_order_lsb); + +/** + * Rotate a buffer into another buffer + * @param src the source buffer + * @param dest the destination buffer + * @param src_width source width in pixels + * @param src_height source height in pixels + * @param src_stride source stride in bytes (number of bytes in a row) + * @param dest_stride destination stride in bytes (number of bytes in a row) + * @param rotation LV_DISPLAY_ROTATION_0/90/180/270 + * @param color_format LV_COLOR_FORMAT_RGB565/RGB888/XRGB8888/ARGB8888 + */ +void lv_draw_sw_rotate(const void * src, void * dest, int32_t src_width, int32_t src_height, int32_t src_stride, + int32_t dest_stride, lv_display_rotation_t rotation, lv_color_format_t color_format); + +/*********************** + * GLOBAL VARIABLES + ***********************/ + +/********************** + * MACROS + **********************/ + +#endif /*LV_USE_DRAW_SW*/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_DRAW_SW_UTILS_H*/ diff --git a/src/drivers/display/drm/lv_linux_drm.c b/src/drivers/display/drm/lv_linux_drm.c index 29e0168d9e..2c04786453 100644 --- a/src/drivers/display/drm/lv_linux_drm.c +++ b/src/drivers/display/drm/lv_linux_drm.c @@ -22,6 +22,8 @@ #include #include +#include "../../../stdlib/lv_sprintf.h" + /********************* * DEFINES *********************/ diff --git a/src/drivers/windows/lv_windows_context.c b/src/drivers/windows/lv_windows_context.c index 191333abd7..a79b7852fd 100644 --- a/src/drivers/windows/lv_windows_context.c +++ b/src/drivers/windows/lv_windows_context.c @@ -16,6 +16,7 @@ #include "lv_windows_display.h" #include "lv_windows_input_private.h" +#include "../../osal/lv_os.h" /********************* * DEFINES diff --git a/src/font/lv_font.h b/src/font/lv_font.h index 6b0dff0ff1..7c869378d4 100644 --- a/src/font/lv_font.h +++ b/src/font/lv_font.h @@ -19,7 +19,6 @@ extern "C" { #include "lv_symbol_def.h" #include "../draw/lv_draw_buf.h" #include "../misc/lv_area.h" -#include "../misc/cache/lv_cache.h" /********************* * DEFINES diff --git a/src/libs/gif/lv_gif.c b/src/libs/gif/lv_gif.c index 920f77689b..901a758012 100644 --- a/src/libs/gif/lv_gif.c +++ b/src/libs/gif/lv_gif.c @@ -6,10 +6,11 @@ /********************* * INCLUDES *********************/ -#include "../../misc/lv_timer_private.h" -#include "../../core/lv_obj_class_private.h" #include "lv_gif_private.h" #if LV_USE_GIF +#include "../../misc/lv_timer_private.h" +#include "../../misc/cache/lv_image_cache.h" +#include "../../core/lv_obj_class_private.h" #include "gifdec.h" diff --git a/src/misc/cache/lv_cache.c b/src/misc/cache/lv_cache.c index b89ac8e1f9..1ab6c9fc6f 100644 --- a/src/misc/cache/lv_cache.c +++ b/src/misc/cache/lv_cache.c @@ -10,6 +10,7 @@ #include "../../stdlib/lv_sprintf.h" #include "../lv_assert.h" #include "lv_cache_entry_private.h" +#include "lv_cache_private.h" /********************* * DEFINES @@ -25,6 +26,7 @@ static void cache_drop_internal_no_lock(lv_cache_t * cache, const void * key, void * user_data); static bool cache_evict_one_internal_no_lock(lv_cache_t * cache, void * user_data); static lv_cache_entry_t * cache_add_internal_no_lock(lv_cache_t * cache, const void * key, void * user_data); + /********************** * GLOBAL VARIABLES **********************/ diff --git a/src/misc/cache/lv_cache.h b/src/misc/cache/lv_cache.h index 0271c87f3d..8469c43775 100644 --- a/src/misc/cache/lv_cache.h +++ b/src/misc/cache/lv_cache.h @@ -14,13 +14,13 @@ extern "C" { * INCLUDES *********************/ #include "lv_cache_entry.h" -#include "lv_cache_private.h" #include "../lv_types.h" #include "lv_cache_lru_rb.h" #include "lv_image_cache.h" #include "lv_image_header_cache.h" + /********************* * DEFINES *********************/ diff --git a/src/misc/cache/lv_cache_entry.c b/src/misc/cache/lv_cache_entry.c index 242e1a0f26..4f280e66e3 100644 --- a/src/misc/cache/lv_cache_entry.c +++ b/src/misc/cache/lv_cache_entry.c @@ -12,6 +12,7 @@ #include "lv_cache.h" #include "lv_cache_entry_private.h" #include "lv_cache_private.h" + /********************* * DEFINES *********************/ @@ -51,11 +52,13 @@ void lv_cache_entry_reset_ref(lv_cache_entry_t * entry) LV_ASSERT_NULL(entry); entry->ref_cnt = 0; } + void lv_cache_entry_inc_ref(lv_cache_entry_t * entry) { LV_ASSERT_NULL(entry); entry->ref_cnt++; } + void lv_cache_entry_dec_ref(lv_cache_entry_t * entry) { LV_ASSERT_NULL(entry); @@ -65,35 +68,42 @@ void lv_cache_entry_dec_ref(lv_cache_entry_t * entry) entry->ref_cnt = 0; } } + int32_t lv_cache_entry_get_ref(lv_cache_entry_t * entry) { LV_ASSERT_NULL(entry); return entry->ref_cnt; } + uint32_t lv_cache_entry_get_node_size(lv_cache_entry_t * entry) { return entry->node_size; } + void lv_cache_entry_set_node_size(lv_cache_entry_t * entry, uint32_t node_size) { LV_ASSERT_NULL(entry); entry->node_size = node_size; } + void lv_cache_entry_set_invalid(lv_cache_entry_t * entry, bool is_invalid) { LV_ASSERT_NULL(entry); entry->is_invalid = is_invalid; } + bool lv_cache_entry_is_invalid(lv_cache_entry_t * entry) { LV_ASSERT_NULL(entry); return entry->is_invalid; } + void * lv_cache_entry_get_data(lv_cache_entry_t * entry) { LV_ASSERT_NULL(entry); return (uint8_t *)entry - entry->node_size; } + void * lv_cache_entry_acquire_data(lv_cache_entry_t * entry) { LV_ASSERT_NULL(entry); @@ -101,6 +111,7 @@ void * lv_cache_entry_acquire_data(lv_cache_entry_t * entry) lv_cache_entry_inc_ref(entry); return lv_cache_entry_get_data(entry); } + void lv_cache_entry_release_data(lv_cache_entry_t * entry, void * user_data) { LV_UNUSED(user_data); @@ -113,16 +124,19 @@ void lv_cache_entry_release_data(lv_cache_entry_t * entry, void * user_data) lv_cache_entry_dec_ref(entry); } + lv_cache_entry_t * lv_cache_entry_get_entry(void * data, const uint32_t node_size) { LV_ASSERT_NULL(data); return (lv_cache_entry_t *)((uint8_t *)data + node_size); } + void lv_cache_entry_set_cache(lv_cache_entry_t * entry, const lv_cache_t * cache) { LV_ASSERT_NULL(entry); entry->cache = cache; } + const lv_cache_t * lv_cache_entry_get_cache(const lv_cache_entry_t * entry) { LV_ASSERT_NULL(entry); @@ -133,6 +147,7 @@ uint32_t lv_cache_entry_get_size(const uint32_t node_size) { return node_size + sizeof(lv_cache_entry_t); } + lv_cache_entry_t * lv_cache_entry_alloc(const uint32_t node_size, const lv_cache_t * cache) { void * res = lv_malloc_zeroed(lv_cache_entry_get_size(node_size)); @@ -145,6 +160,7 @@ lv_cache_entry_t * lv_cache_entry_alloc(const uint32_t node_size, const lv_cache lv_cache_entry_init(entry, cache, node_size); return (lv_cache_entry_t *)((uint8_t *)entry + node_size); } + void lv_cache_entry_init(lv_cache_entry_t * entry, const lv_cache_t * cache, const uint32_t node_size) { LV_ASSERT_NULL(entry); @@ -155,6 +171,7 @@ void lv_cache_entry_init(lv_cache_entry_t * entry, const lv_cache_t * cache, con entry->ref_cnt = 0; entry->is_invalid = false; } + void lv_cache_entry_delete(lv_cache_entry_t * entry) { LV_ASSERT_NULL(entry); @@ -162,6 +179,7 @@ void lv_cache_entry_delete(lv_cache_entry_t * entry) void * data = lv_cache_entry_get_data(entry); lv_free(data); } + /********************** * STATIC FUNCTIONS **********************/ diff --git a/src/misc/cache/lv_cache_entry.h b/src/misc/cache/lv_cache_entry.h index 947f71d723..3c28f2d929 100644 --- a/src/misc/cache/lv_cache_entry.h +++ b/src/misc/cache/lv_cache_entry.h @@ -13,9 +13,8 @@ extern "C" { /********************* * INCLUDES *********************/ -#include "../../osal/lv_os.h" #include "../lv_types.h" -#include "lv_cache_private.h" + /********************* * DEFINES *********************/ diff --git a/src/misc/cache/lv_cache_entry_private.h b/src/misc/cache/lv_cache_entry_private.h index f8d41bb9f9..7fc2794cb8 100644 --- a/src/misc/cache/lv_cache_entry_private.h +++ b/src/misc/cache/lv_cache_entry_private.h @@ -16,6 +16,7 @@ extern "C" { #include "../lv_types.h" #include "../../osal/lv_os.h" #include "../lv_profiler.h" + /********************* * DEFINES *********************/ @@ -35,6 +36,7 @@ void lv_cache_entry_set_invalid(lv_cache_entry_t * entry, bool is_invalid); void lv_cache_entry_set_cache(lv_cache_entry_t * entry, const lv_cache_t * cache); void * lv_cache_entry_acquire_data(lv_cache_entry_t * entry); void lv_cache_entry_release_data(lv_cache_entry_t * entry, void * user_data); + /************************* * GLOBAL VARIABLES *************************/ diff --git a/src/misc/cache/lv_cache_private.h b/src/misc/cache/lv_cache_private.h index d197fbf630..80bd0b9895 100644 --- a/src/misc/cache/lv_cache_private.h +++ b/src/misc/cache/lv_cache_private.h @@ -40,9 +40,7 @@ struct _lv_cache_class_t; struct _lv_cache_entry_t; typedef struct _lv_cache_ops_t lv_cache_ops_t; -typedef struct _lv_cache_t lv_cache_t; typedef struct _lv_cache_class_t lv_cache_class_t; -typedef struct _lv_cache_entry_t lv_cache_entry_t; typedef int8_t lv_cache_compare_res_t; typedef bool (*lv_cache_create_cb_t)(void * node, void * user_data); diff --git a/src/misc/lv_types.h b/src/misc/lv_types.h index d86284a7c1..91612f882d 100644 --- a/src/misc/lv_types.h +++ b/src/misc/lv_types.h @@ -135,6 +135,10 @@ typedef struct _lv_color_filter_dsc_t lv_color_filter_dsc_t; typedef struct _lv_event_dsc_t lv_event_dsc_t; +typedef struct _lv_cache_t lv_cache_t; + +typedef struct _lv_cache_entry_t lv_cache_entry_t; + typedef struct _lv_fs_file_cache_t lv_fs_file_cache_t; typedef struct _lv_fs_path_ex_t lv_fs_path_ex_t; diff --git a/src/stdlib/builtin/lv_tlsf.h b/src/stdlib/builtin/lv_tlsf.h index bfaf08435b..d56327274d 100644 --- a/src/stdlib/builtin/lv_tlsf.h +++ b/src/stdlib/builtin/lv_tlsf.h @@ -41,7 +41,6 @@ ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "../../osal/lv_os.h" #include "../../misc/lv_ll.h" #include "../../misc/lv_types.h" diff --git a/src/stdlib/builtin/lv_tlsf_private.h b/src/stdlib/builtin/lv_tlsf_private.h index 036e9d73eb..abba9573df 100644 --- a/src/stdlib/builtin/lv_tlsf_private.h +++ b/src/stdlib/builtin/lv_tlsf_private.h @@ -17,6 +17,7 @@ extern "C" { *********************/ #include "lv_tlsf.h" +#include "../../osal/lv_os.h" /********************* * DEFINES diff --git a/src/widgets/lottie/lv_lottie.c b/src/widgets/lottie/lv_lottie.c index 48ae258146..455b1be6b4 100644 --- a/src/widgets/lottie/lv_lottie.c +++ b/src/widgets/lottie/lv_lottie.c @@ -18,6 +18,7 @@ #include "../../misc/lv_timer.h" #include "../../core/lv_obj_class_private.h" +#include "../../misc/cache/lv_image_cache.h" /********************* * DEFINES