From d5986601b1b544c7605ba77bdec90c623068d1f7 Mon Sep 17 00:00:00 2001 From: Neucrack Date: Mon, 13 May 2024 14:35:40 +0800 Subject: [PATCH] optimize image.compress func and fix lvgl build error --- components/3rd_party/lvgl/CMakeLists.txt | 2 +- components/3rd_party/lvgl/component.py | 2 +- components/vision/include/maix_image.hpp | 2 +- components/vision/src/maix_image_ops.cpp | 18 +----------------- tools/cmake/build.py | 2 ++ 5 files changed, 6 insertions(+), 20 deletions(-) diff --git a/components/3rd_party/lvgl/CMakeLists.txt b/components/3rd_party/lvgl/CMakeLists.txt index f9da3912..420e882c 100644 --- a/components/3rd_party/lvgl/CMakeLists.txt +++ b/components/3rd_party/lvgl/CMakeLists.txt @@ -1,5 +1,5 @@ -set(version_str "${CONFIG_LVGL_VERSION_MAJOR}.${CONFIG_LVGL_VERSION_MAJOR}.${CONFIG_LVGL_VERSION_MAJOR}") +set(version_str "${CONFIG_LVGL_VERSION_MAJOR}.${CONFIG_LVGL_VERSION_MINOR}.${CONFIG_LVGL_VERSION_PATCH}") set(unzip_dir_name "lvgl-${version_str}") set(unzip_path "${DL_EXTRACTED_PATH}/lvgl_srcs/${unzip_dir_name}") diff --git a/components/3rd_party/lvgl/component.py b/components/3rd_party/lvgl/component.py index cb552507..9cb08e40 100644 --- a/components/3rd_party/lvgl/component.py +++ b/components/3rd_party/lvgl/component.py @@ -15,7 +15,7 @@ def add_file_downloads(confs : dict) -> list: path = f"lvgl_srcs/lvgl-{version}" check_file = 'lvgl' rename = { - 'lvgl-{version}': 'lvgl' + f'lvgl-{version}': 'lvgl' } return [ diff --git a/components/vision/include/maix_image.hpp b/components/vision/include/maix_image.hpp index ee17e215..f0f4d6f5 100644 --- a/components/vision/include/maix_image.hpp +++ b/components/vision/include/maix_image.hpp @@ -531,7 +531,7 @@ namespace maix::image image::Image *midpoint_pool(int x_div, int y_div, double bias = 0.5, bool copy = false); /** - * @brief JPEG compresses the image in place. + * @brief JPEG compresses the image in place, the same as to_jpeg functioin, it's recommend to use to_jpeg instead. * @param quality The quality of the compressed image. default is 95. * @return Returns the compressed JPEG image * @maixpy maix.image.Image.compress diff --git a/components/vision/src/maix_image_ops.cpp b/components/vision/src/maix_image_ops.cpp index de39e197..dd3eb179 100644 --- a/components/vision/src/maix_image_ops.cpp +++ b/components/vision/src/maix_image_ops.cpp @@ -154,23 +154,7 @@ namespace maix::image { } image::Image *Image::compress(int quality) { - if (quality < 0) { - log::warn("compress invalid quality: %d", quality); - return nullptr; - } - - quality = quality > 100 ? 100 : quality; - - cv::Mat img(_height, _width, CV_8UC((int)image::fmt_size[_format]), _data); - std::vector compressed; - std::vector params; - params.push_back(cv::IMWRITE_JPEG_QUALITY); - params.push_back(quality); - cv::imencode(".jpg", img, compressed, params); - - int dst_data_size = compressed.size(); - image::Image *dst = new image::Image(_width, _height, Format::FMT_JPEG, compressed.data(), dst_data_size, true); - return dst; + return to_jpeg(quality); } err::Err image_zero(image::Image &src, image::Image &mask, bool invert) { diff --git a/tools/cmake/build.py b/tools/cmake/build.py index c77f11b9..13ab3d51 100644 --- a/tools/cmake/build.py +++ b/tools/cmake/build.py @@ -90,6 +90,8 @@ def find_valid_components(components): depends[name] = [] for r in match: if r in components: + if name == r: + continue depends[name].append(r) # find main depends def get_depend_recursive(name):