diff --git a/hardware/cis/cis_param.cpp b/hardware/cis/cis_param.cpp index fea04df..5fad2aa 100644 --- a/hardware/cis/cis_param.cpp +++ b/hardware/cis/cis_param.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -185,12 +186,22 @@ namespace correct if(root->get_value("Sp", data.val)) add_data(que, SANE_OPT_NAME(CIS_SP), data); } + static bool sort_cd(const CONDDATA& l, const CONDDATA& r) + { + if(l.dpi < r.dpi) + return true; + else if(l.dpi > r.dpi) + return false; + else + return l.clr > r.clr; + } - std::vector load_old_correct_data(const char* file) + std::vector load_old_correct_data(const char* file, std::vector* dpis = nullptr) { std::vector old; std::string cont(utils::load_mini_file(file, nullptr)); gb_json *root = new gb_json(); + std::vector res; for(auto& v: names) { @@ -231,6 +242,8 @@ namespace correct data.dpi = 0; if(data.dpi) { + if(std::find(res.begin(), res.end(), data.dpi) == res.end()) + res.push_back(data.dpi); parse_mode(child, old, data); } } @@ -249,14 +262,96 @@ namespace correct old.erase(old.begin() + i); i--; } + else + { + std::sort(old[i].data.begin(), old[i].data.end(), sort_cd); + } + } + + if(dpis) + { + std::sort(res.begin(), res.end()); + *dpis = std::move(res); } return std::move(old); } + int save_correct_data(CORDATA& data, std::vector& fixed_dpi, int init_dpi, bool init_clr) + { + correct::CONDDATA def; + int err = 0; + std::string root(CIS_CORRECT_DATA_PATH), cont(""); + gb_json *init = new gb_json(); + + for(auto& item: data.data) + { + if(item.clr == init_clr && item.dpi == init_dpi) + def = item; + else + { + std::string key(SANE_OPT_NAME(CIS_MODE)); + + key += "=="; + if(item.clr) + key += WORDS_COLOR_COLOR; + else + key += WORDS_COLOR_GRAY; + key += "&&"; + if(fixed_dpi.size()) + { + key += SANE_OPT_NAME(RESOLUTION); + for(size_t i = 0; i < fixed_dpi.size(); ++i) + { + if(item.dpi <= fixed_dpi[i]) + { + if(i + 1 < fixed_dpi.size()) + { + if(i == 0) + key += "<=" + std::to_string((fixed_dpi[i] + fixed_dpi[i + 1]) / 2); + else + // key += ">" + std::to_string((fixed_dpi[i] + fixed_dpi[i - 1]) / 2) + // + "&&" + SANE_OPT_NAME(RESOLUTION) + // + "<=" + std::to_string((fixed_dpi[i] + fixed_dpi[i + 1]) / 2); + key += "==[" + std::to_string((fixed_dpi[i] + fixed_dpi[i - 1]) / 2) + + "," + std::to_string((fixed_dpi[i] + fixed_dpi[i + 1]) / 2) + "]"; + } + else + key += ">" + std::to_string(i > 0 ? (fixed_dpi[i] + fixed_dpi[i - 1]) / 2 : fixed_dpi[i]); + break; + } + else if(i == fixed_dpi.size() - 1) + key += ">=" + std::to_string(fixed_dpi[i]); + } + } + else + { + key += SANE_OPT_NAME(CIS_DPI); + key += "==" + std::to_string(item.dpi); + } + init->set_value(key.c_str(), item.val); + } + } + init->set_value("default", def.val); + cont = init->to_string(); + init->release(); + utils::save_2_file(&cont[0], cont.length(), (root + data.name + ".json").c_str()); + + return err; + } }; namespace cis { + std::vector get_fixed_resolution(void) + { + std::vector res; + + res.push_back(300); + res.push_back(600); + + return std::move(res); + } + int get_sector_pixels(int sec_num, int dpi, bool side) { // both side and all sectors has the same pixel @@ -278,15 +373,17 @@ namespace cis void update_correct_data(int init_dpi, bool init_clr, bool force) { - std::string src("/usr/local/huago/cameraparam.json"), + std::string src("/usr/local/huago/cameraparam.json"), root(CIS_CORRECT_DATA_PATH); uint64_t src_m = 0, dst_m = 0; - std::vector old(correct::load_old_correct_data(src.c_str())); + std::vector fixed_res; // (get_fixed_resolution()); + std::vector old(correct::load_old_correct_data(src.c_str(), &fixed_res)); if(utils::get_file_time(src.c_str(), nullptr, &src_m, nullptr) && !force) return; + std::sort(fixed_res.begin(), fixed_res.end()); for(auto& v: correct::names) { std::string fn(root + v + ".json"); @@ -301,35 +398,8 @@ namespace cis { if(n.name == v) { - gb_json *init = new gb_json(); - correct::CONDDATA def; - - for(auto& item: n.data) - { - if(item.clr == init_clr && item.dpi == init_dpi) - def = item; - else - { - std::string key(SANE_OPT_NAME(CIS_MODE)); - - key += "=="; - if(item.clr) - key += WORDS_COLOR_COLOR; - else - key += WORDS_COLOR_GRAY; - key += "&&"; - key += SANE_OPT_NAME(CIS_DPI); - key += "==" + std::to_string(item.dpi); - init->set_value(key.c_str(), item.val); - } - } - init->set_value("default", def.val); - - std::string cont(init->to_string()); - - init->release(); - utils::save_2_file(&cont[0], cont.length(), fn.c_str()); - break; + correct::save_correct_data(n, fixed_res, init_dpi, init_clr); + break; } } } @@ -350,35 +420,8 @@ namespace cis { if(n.name == fn) { - gb_json *init = new gb_json(); - correct::CONDDATA def; - - for(auto& item: n.data) - { - if(item.clr == init_clr && item.dpi == init_dpi) - def = item; - else - { - std::string key(SANE_OPT_NAME(CIS_MODE)); - - key += "=="; - if(item.clr) - key += WORDS_COLOR_COLOR; - else - key += WORDS_COLOR_GRAY; - key += "&&"; - key += SANE_OPT_NAME(CIS_DPI); - key += "==" + std::to_string(item.dpi); - init->set_value(key.c_str(), item.val); - } - } - init->set_value("default", def.val); - - std::string cont(init->to_string()); - - init->release(); - utils::save_2_file(&cont[0], cont.length(), (root + fn + ".json").c_str()); - break; + correct::save_correct_data(n, fixed_res, init_dpi, init_clr); + break; } } } diff --git a/hardware/cis/cis_param.h b/hardware/cis/cis_param.h index e95d3a4..a0a61f8 100644 --- a/hardware/cis/cis_param.h +++ b/hardware/cis/cis_param.h @@ -2,6 +2,7 @@ // // Date: 2024-01-19 #pragma once +#include #define CIS_SECTOR_COUNT 6 // how many sectors of ONE CIS #define CIS_CORRECT_DATA_PATH "/usr/local/huago2/" @@ -11,6 +12,8 @@ class gb_json; namespace cis { + std::vector get_fixed_resolution(void); + // Function: how many pixels one sector generated // // Parameter: sec_num - sector index, from Zero to CIS_SECTOR_COUNT - 1 diff --git a/sdk/sane_opt_json/device_opt.cpp b/sdk/sane_opt_json/device_opt.cpp index dc59f78..02180d2 100644 --- a/sdk/sane_opt_json/device_opt.cpp +++ b/sdk/sane_opt_json/device_opt.cpp @@ -794,6 +794,7 @@ bool device_option::parse_simple_logic_expression(gb_json* root, const char* exp { v = std::string(next, tag - next); calc.val2 = device_option::from_text_value(n.c_str(), v.c_str()); + ret = device_option::get_between(n.c_str(), &calc.compare); } } }