diff --git a/docs/sane-opts/imgprc_mgr.txt b/docs/sane-opts/imgprc_mgr.txt index 3916ef3..9c4f9bb 100644 --- a/docs/sane-opts/imgprc_mgr.txt +++ b/docs/sane-opts/imgprc_mgr.txt @@ -55,5 +55,31 @@ "size": 4, "cur": false, "default": false + }, + "cis-rebuild": { + "cat": "advanced", + "group": "高级设置", + "title": "图像拼接", + "desc": "从CIS数据流重建图像", + "type": "bool", + "ui-pos": 20, + "auth": 0, + "affect": 2, + "size": 4, + "cur": true, + "default": true + }, + "stretch": { + "cat": "advanced", + "group": "高级设置", + "title": "图像拉伸", + "desc": "将硬件分辨率拉伸到用户指定的分辨率", + "type": "bool", + "ui-pos": 30, + "auth": 0, + "affect": 2, + "size": 4, + "cur": true, + "default": true } } \ No newline at end of file diff --git a/hardware/hardware.cpp b/hardware/hardware.cpp index bcaca34..158f54a 100644 --- a/hardware/hardware.cpp +++ b/hardware/hardware.cpp @@ -25,6 +25,7 @@ static std::string device_opt_json[] = { }; #endif + ///////////////////////////////////////////////////////////////////////////////////////////////////////// // scanner_hw scanner_hw::scanner_hw() : mb_events_("motorboard-event") diff --git a/imgproc/imgprc_mgr.cpp b/imgproc/imgprc_mgr.cpp index 2fcd1f0..ead2da2 100644 --- a/imgproc/imgprc_mgr.cpp +++ b/imgproc/imgprc_mgr.cpp @@ -23,9 +23,10 @@ } static std::string device_opt_json[] = { - "{\"is-multiout\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\",\"desc\":\"\\u540c\\u65f6\\u8f93\\u51fa\\u591a\\u79cd\\u989c\\u8272\\u6a21\\u5f0f\\u7684\\u56fe\\u50cf\",\"type\":\"bool\",\"fix-id\":34817,\"ui-pos\":10,\"auth\":0,\"size\":4,\"cur\":false,\"default\":false},\"multiout-type\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\\u7c7b\\u578b\",\"desc\":\"\\u9009\\u62e9\\u591a\\u6d41\\u8f93\\u51fa\\u7684\\u7c7b\\u578b\",\"type\":\"string\",\"fix-id\":34818,\"ui-pos\":11,\"auth\":0,\"enabled\":false,\"size\":66,\"cur\":\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"default\":\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"range\":[\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"\\u5f69\\u8272+\\u7070\\u5ea6\",\"\\u5f69\\u8272+\\u9ed1\\u767d\",\"\\u7070\\u5ea6+\\u9ed1\\u767d\"],\"depend\":\"is-multiout==true\"},\"mode\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u989c\\u8272\\u6a21\\u5f0f\",\"desc\":\"\\u9009\\u62e9\\u8272\\u5f69\\u6a21\\u5f0f\",\"type\":\"string\",\"fix-id\":34819,\"ui-pos\":15,\"auth\":0,\"size\":24,\"cur\":\"24\\u4f4d\\u5f69\\u8272\",\"default\":\"24\\u4f4d\\u5f69\\u8272\",\"range\":[\"24\\u4f4d\\u5f69\\u8272\",\"256\\u7ea7\\u7070\\u5ea6\",\"\\u9ed1\\u767d\",\"\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"],\"depend\":\"is-multiout!=true\"},\"dump-img\":{\"cat\":\"base\",\"group\":\"\\u9ad8\\u7ea7\\u8bbe\\u7f6e\",\"title\":\"\\u8f93\\u51fa\\u4e2d\\u95f4\\u56fe\\u50cf\",\"desc\":\"\\u8f93\\u51fa\\u5404\\u7b97\\u6cd5\\u4e2d\\u95f4\\u7ed3\\u679c\\u56fe\\u50cf\",\"type\":\"bool\",\"ui-pos\":10,\"auth\":0,\"affect\":2,\"size\":4,\"cur\":false,\"default\":false}}" + "{\"is-multiout\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\",\"desc\":\"\\u540c\\u65f6\\u8f93\\u51fa\\u591a\\u79cd\\u989c\\u8272\\u6a21\\u5f0f\\u7684\\u56fe\\u50cf\",\"type\":\"bool\",\"fix-id\":34817,\"ui-pos\":10,\"auth\":0,\"size\":4,\"cur\":false,\"default\":false},\"multiout-type\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u591a\\u6d41\\u8f93\\u51fa\\u7c7b\\u578b\",\"desc\":\"\\u9009\\u62e9\\u591a\\u6d41\\u8f93\\u51fa\\u7684\\u7c7b\\u578b\",\"type\":\"string\",\"fix-id\":34818,\"ui-pos\":11,\"auth\":0,\"enabled\":false,\"size\":66,\"cur\":\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"default\":\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"range\":[\"\\u5f69\\u8272+\\u7070\\u5ea6+\\u9ed1\\u767d\",\"\\u5f69\\u8272+\\u7070\\u5ea6\",\"\\u5f69\\u8272+\\u9ed1\\u767d\",\"\\u7070\\u5ea6+\\u9ed1\\u767d\"],\"depend\":\"is-multiout==true\"},\"mode\":{\"cat\":\"base\",\"group\":\"base\",\"title\":\"\\u989c\\u8272\\u6a21\\u5f0f\",\"desc\":\"\\u9009\\u62e9\\u8272\\u5f69\\u6a21\\u5f0f\",\"type\":\"string\",\"fix-id\":34819,\"ui-pos\":15,\"auth\":0,\"size\":24,\"cur\":\"24\\u4f4d\\u5f69\\u8272\",\"default\":\"24\\u4f4d\\u5f69\\u8272\",\"range\":[\"24\\u4f4d\\u5f69\\u8272\",\"256\\u7ea7\\u7070\\u5ea6\",\"\\u9ed1\\u767d\",\"\\u989c\\u8272\\u81ea\\u52a8\\u8bc6\\u522b\"],\"depend\":\"is-multiout!=true\"},\"dump-img\":{\"cat\":\"base\",\"group\":\"\\u9ad8\\u7ea7\\u8bbe\\u7f6e\",\"title\":\"\\u8f93\\u51fa\\u4e2d\\u95f4\\u56fe\\u50cf\",\"desc\":\"\\u8f93\\u51fa\\u5404\\u7b97\\u6cd5\\u4e2d\\u95f4\\u7ed3\\u679c\\u56fe\\u50cf\",\"type\":\"bool\",\"ui-pos\":10,\"auth\":0,\"affect\":2,\"size\":4,\"cur\":false,\"default\":false},\"cis-rebuild\":{\"cat\":\"advanced\",\"group\":\"\\u9ad8\\u7ea7\\u8bbe\\u7f6e\",\"title\":\"\\u56fe\\u50cf\\u62fc\\u63a5\",\"desc\":\"\\u4eceCIS\\u6570\\u636e\\u6d41\\u91cd\\u5efa\\u56fe\\u50cf\",\"type\":\"bool\",\"ui-pos\":20,\"auth\":0,\"affect\":2,\"size\":4,\"cur\":true,\"default\":true},\"stretch\":{\"cat\":\"advanced\",\"group\":\"\\u9ad8\\u7ea7\\u8bbe\\u7f6e\",\"title\":\"\\u56fe\\u50cf\\u62c9\\u4f38\",\"desc\":\"\\u5c06\\u786c\\u4ef6\\u5206\\u8fa8\\u7387\\u62c9\\u4f38\\u5230\\u7528\\u6237\\u6307\\u5b9a\\u7684\\u5206\\u8fa8\\u7387\",\"type\":\"bool\",\"ui-pos\":30,\"auth\":0,\"affect\":2,\"size\":4,\"cur\":true,\"default\":true}}" }; + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // imgproc_mgr @@ -126,8 +127,18 @@ void imgproc_mgr::process(RAWIMG* img) std::vector in, out, *src = &in, *dst = &out, *swp = nullptr; chronograph watch; - rebuild_->do_rebuild(&img->info, img->data->ptr(), in); - utils::to_log(LOG_LEVEL_ALL, "Rebuild paper %d spend %llu milliseconds.\n", img->info.pos.paper_ind, watch.elapse_ms()); + if(do_rebuild_) + { + rebuild_->do_rebuild(&img->info, img->data->ptr(), in); + utils::to_log(LOG_LEVEL_ALL, "Rebuild paper %d spend %llu milliseconds.\n", img->info.pos.paper_ind, watch.elapse_ms()); + } + else + { + PROCIMGINFO i; + i.info = img->info; + i.img = cv::Mat(img->info.width, img->info.height, CV_8UC1, img->data->ptr()); + in.push_back(i); + } if(dump_img_) { @@ -165,7 +176,7 @@ void imgproc_mgr::process(RAWIMG* img) for(auto& v: in) v.info.prc_time = t; } - + send_image(*src, true); } else @@ -228,6 +239,32 @@ int imgproc_mgr::set_value(const char* name, void* val) if(strcmp(name, SANE_FULL_NAME(DUMP_IMG)) == 0) dump_img_ = *(bool*)val; + else if(strcmp(name, SANE_FULL_NAME(CIS_REBUILD)) == 0) + do_rebuild_ = *(bool*)val; + else if(strcmp(name, SANE_FULL_NAME(CIS_STRETCH)) == 0) + { + if(*(bool*)val) + { + if(stretcher_) + { + processors_.push_back(stretcher_); + stretcher_ = nullptr; + std::sort(processors_.begin(), processors_.end(), &imgproc_mgr::sort_processor_by_pos); + } + } + else + { + for(size_t i = 0; i < processors_.size(); ++i) + { + if(strcmp(processors_[i]->from(), "stretch") == 0) + { + stretcher_ = processors_[i]; + processors_.erase(processors_.begin() + i); + break; + } + } + } + } else ret = SCANNER_ERR_DEVICE_NOT_SUPPORT; @@ -253,6 +290,9 @@ int imgproc_mgr::clear(void) for (auto& v : processors_) v->release(); processors_.clear(); + if(stretcher_) + stretcher_->release(); + stretcher_ = nullptr; return 0; } @@ -264,7 +304,7 @@ int imgproc_mgr::process(LPPACKIMAGE info, dyn_mem_ptr data, bool img) ri.data = data; if(img) - data->add_ref(); + return ret; // data->add_ref(); if(img) ri.info = *info; else diff --git a/imgproc/imgprc_mgr.h b/imgproc/imgprc_mgr.h index 3945511..51d1040 100644 --- a/imgproc/imgprc_mgr.h +++ b/imgproc/imgprc_mgr.h @@ -28,6 +28,8 @@ class imgproc_mgr : public sane_opt_provider }RAWIMG; refer_guard rebuild_; + image_processor* stretcher_ = nullptr; + bool do_rebuild_ = true; volatile bool run_ = true; bool dump_img_ = false; uint32_t scan_id_ = 0; diff --git a/scanner/main.cpp b/scanner/main.cpp index 3106e74..e3031a8 100644 --- a/scanner/main.cpp +++ b/scanner/main.cpp @@ -30,16 +30,6 @@ static void sigHandler(int sig) _exit(0); } -static std::string get_command(void) -{ - std::string cmd(""); - char in[2] = {0}; - - while((in[0] = getchar()) != 0x0a) - cmd += in; - - return std::move(cmd); -} namespace test_cmd { @@ -48,6 +38,29 @@ namespace test_cmd while(*ptr == ' ') ptr++; } + static void print_help(void) + { + console_color clr = console_color::COLOR_CHAR_RED; + + printf("usage: "); + utils::printf_with_color("clear", clr); + printf(" - to clear screen\n "); + + utils::printf_with_color("exit", clr); + printf(" - to quit this app\n "); + + utils::printf_with_color("free", clr); + printf(" - : to free memory\n "); + + utils::printf_with_color("mem", clr); + printf(" - to print memory usage\n "); + + utils::printf_with_color("rdmem", clr); + printf(" - [len]: to read memory\n "); + + utils::printf_with_color("sys", clr); + printf(" - to invoke system call\n"); + } static const char* free_cmd = "free "; static void free_memory(const char* cmd) @@ -127,6 +140,16 @@ namespace test_cmd } } + static const char* sys_cmd = "sys "; + static void invoke_sys_command(const char* cmd) + { + cmd = strstr(cmd, sys_cmd); + if(cmd) + { + cmd += strlen(sys_cmd); + system(cmd); + } + } }; int main() @@ -149,17 +172,24 @@ int main() scanner = new async_scanner(); int err = scanner->last_error(); + test_cmd::print_help(); while(err == 0) { - std::string cmd(get_command()); + std::string cmd(utils::from_console("cmd>")); if(cmd == "exit") break; if(cmd == "mem") utils::print_memory_usage(" Memory usage", false); - if(cmd.find(test_cmd::free_cmd) == 0) + else if(cmd.find(test_cmd::free_cmd) == 0) test_cmd::free_memory(cmd.c_str()); - if(cmd.find(test_cmd::rdm_cmd) == 0) + else if(cmd.find(test_cmd::rdm_cmd) == 0) test_cmd::read_memory(cmd.c_str()); + else if(cmd == "clear") + system("clear"); + else if(cmd.find(test_cmd::sys_cmd) == 0) + test_cmd::invoke_sys_command(cmd.c_str()); + else + test_cmd::print_help(); } async_scanner* tmp = scanner; @@ -168,5 +198,8 @@ int main() tmp->stop(); tmp->release(); + std::this_thread::sleep_for(std::chrono::microseconds(500)); + utils::print_memory_usage("Memory usage", false); + return 0; } \ No newline at end of file diff --git a/sdk/base/plat_types.h b/sdk/base/plat_types.h index b475182..844b122 100644 --- a/sdk/base/plat_types.h +++ b/sdk/base/plat_types.h @@ -26,6 +26,43 @@ return #e; +//////////////////////////////////////////////////////////////////////////// +// console definitions +enum console_color +{ + COLOR_CHAR_BLACK = 0x30, + COLOR_CHAR_RED, + COLOR_CHAR_GREEN, + COLOR_CHAR_YELLOW, + COLOR_CHAR_BLUE, + COLOR_CHAR_MAGENTA, + COLOR_CHAR_CYAN, + COLOR_CHAR_WHITE, + + COLOR_BKG_NONE = 0x3f, + COLOR_BKG_BLACK = 0x40, + COLOR_BKG_RED, + COLOR_BKG_GREEN, + COLOR_BKG_YELLOW, + COLOR_BKG_BLUE, + COLOR_BKG_MAGENTA, + COLOR_BKG_CYAN, + COLOR_BKG_WHITE, +}; +enum console_display_mode +{ + MODE_DEFAULT = 0, + MODE_HILIGHT, + MODE_DIM, + MODE_UNDER_LINE = 4, + MODE_BLINK, + MODE_REVERSE = 7, + MODE_HIDDEN, + MODE_NON_BOLD = 22, + MODE_NON_BLINK = 25, + MODE_NON_REVERSE = 27, +}; + #if !OS_WIN // migrate codes from windows to linux ... #include #include diff --git a/sdk/base/utils.cpp b/sdk/base/utils.cpp index b5e7fa5..b7e9420 100644 --- a/sdk/base/utils.cpp +++ b/sdk/base/utils.cpp @@ -723,6 +723,18 @@ namespace utils return len > 0 ? path : lnk_file; #endif } + std::string from_console(const char* tips, console_color clr) + { + std::string cmd(""); + char in[2] = {0}; + + if(tips && tips[0]) + printf_with_color(tips, clr); + while((in[0] = getchar()) != 0x0a) + cmd += in; + + return std::move(cmd); + } std::string get_ini_value(const char* seg, const char* key, const char* cfg_file) { char buf[512] = { 0 }; @@ -788,6 +800,29 @@ namespace utils return err; } + void printf_with_color(const char* msg, console_color text_clr, console_color bkg_clr, console_display_mode mode) + { + char buf[80] = {0}; + + // sprintf(buf, "\033[%xm %%s \033[0m", text_clr); + if(mode != console_display_mode::MODE_DEFAULT) + { + if(bkg_clr != console_color::COLOR_BKG_NONE) + sprintf(buf, "\033[%d;%x;%xm%%s\033[0m", mode, text_clr, bkg_clr); + else + sprintf(buf, "\033[%d;%xm%%s\033[0m", mode, text_clr); + } + else if(bkg_clr != console_color::COLOR_BKG_NONE) + { + sprintf(buf, "\033[%x;%xm%%s\033[0m", text_clr, bkg_clr); + } + else + { + sprintf(buf, "\033[%xm%%s\033[0m", text_clr); + } + + printf(buf, msg); + } bool is_match_pattern(const char* text, const char* pattern) { diff --git a/sdk/base/utils.h b/sdk/base/utils.h index a56974e..6353505 100644 --- a/sdk/base/utils.h +++ b/sdk/base/utils.h @@ -44,9 +44,11 @@ namespace utils std::string get_module_full_path(const char* part_name = nullptr/*nullptr to get main-pe/first module's full path*/); std::string find_file(const char* root_dir, const char* part_name, bool recursive = false); std::string target_file_from_link(const char* lnk_file); + std::string from_console(const char* tips = nullptr, console_color clr = console_color::COLOR_CHAR_GREEN); std::string get_ini_value(const char* seg, const char* key, const char* cfg_file); // return "" if not found std::string load_mini_file(const char* file, int* err); // <= 1MB int save_2_file(void* data, size_t len, const char* file, bool append = false/*append or new*/, size_t max_size = -1/*in append mode, truncate file if size is exceeded this value if was not -1*/); + void printf_with_color(const char* msg, console_color text_clr, console_color bkg_clr = COLOR_BKG_NONE, console_display_mode mode = console_display_mode::MODE_DEFAULT); bool is_match_pattern(const char* text, const char* pattern); const char* to_lower(std::string& str); // return str.c_str() diff --git a/sdk/sane/sane_ex.h b/sdk/sane/sane_ex.h index e6cd697..2e8e238 100644 --- a/sdk/sane/sane_ex.h +++ b/sdk/sane/sane_ex.h @@ -254,6 +254,8 @@ enum opt_visible_level // "visible" field #define SANE_STD_OPT_NAME_CIS_SAMPLE "sample" #define SANE_STD_OPT_NAME_CIS_SP "cis-sp" #define SANE_STD_OPT_NAME_CIS_LED "cis-led" +#define SANE_STD_OPT_NAME_CIS_REBUILD "cis-rebuild" +#define SANE_STD_OPT_NAME_CIS_STRETCH "stretch" #define SANE_STD_OPT_NAME_CIS_EXPO_FB "expo-fb" #define SANE_STD_OPT_NAME_CIS_EXPO_FG "expo-fg" #define SANE_STD_OPT_NAME_CIS_EXPO_FR "expo-fr" diff --git a/xmake.lua b/xmake.lua index fa30e19..006cad8 100644 --- a/xmake.lua +++ b/xmake.lua @@ -60,8 +60,8 @@ add_packagedirs("sdk") add_defines("BUILD_AS_DEVICE") add_defines("VER_MAIN=2") add_defines("VER_FAMILY=200") -add_defines("VER_DATE=20240129") -add_defines("VER_BUILD=8") +add_defines("VER_DATE=20240130") +add_defines("VER_BUILD=20") target("conf") set_kind("phony")