优化校正数据转换;修复区间值逻辑解析BUG

This commit is contained in:
gb 2024-02-22 10:31:24 +08:00
parent af6c187bac
commit e7c79e24fc
3 changed files with 108 additions and 61 deletions

View File

@ -2,6 +2,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <algorithm>
#include <base/utils.h> #include <base/utils.h>
#include <json/gb_json.h> #include <json/gb_json.h>
#include <sane/sane_name.h> #include <sane/sane_name.h>
@ -185,12 +186,22 @@ namespace correct
if(root->get_value("Sp", data.val)) if(root->get_value("Sp", data.val))
add_data(que, SANE_OPT_NAME(CIS_SP), data); 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<CORDATA> load_old_correct_data(const char* file) std::vector<CORDATA> load_old_correct_data(const char* file, std::vector<int>* dpis = nullptr)
{ {
std::vector<CORDATA> old; std::vector<CORDATA> old;
std::string cont(utils::load_mini_file(file, nullptr)); std::string cont(utils::load_mini_file(file, nullptr));
gb_json *root = new gb_json(); gb_json *root = new gb_json();
std::vector<int> res;
for(auto& v: names) for(auto& v: names)
{ {
@ -231,6 +242,8 @@ namespace correct
data.dpi = 0; data.dpi = 0;
if(data.dpi) if(data.dpi)
{ {
if(std::find(res.begin(), res.end(), data.dpi) == res.end())
res.push_back(data.dpi);
parse_mode(child, old, data); parse_mode(child, old, data);
} }
} }
@ -249,14 +262,96 @@ namespace correct
old.erase(old.begin() + i); old.erase(old.begin() + i);
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); return std::move(old);
} }
int save_correct_data(CORDATA& data, std::vector<int>& 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 namespace cis
{ {
std::vector<int> get_fixed_resolution(void)
{
std::vector<int> res;
res.push_back(300);
res.push_back(600);
return std::move(res);
}
int get_sector_pixels(int sec_num, int dpi, bool side) int get_sector_pixels(int sec_num, int dpi, bool side)
{ {
// both side and all sectors has the same pixel // 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) 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); root(CIS_CORRECT_DATA_PATH);
uint64_t src_m = 0, uint64_t src_m = 0,
dst_m = 0; dst_m = 0;
std::vector<correct::CORDATA> old(correct::load_old_correct_data(src.c_str())); std::vector<int> fixed_res; // (get_fixed_resolution());
std::vector<correct::CORDATA> old(correct::load_old_correct_data(src.c_str(), &fixed_res));
if(utils::get_file_time(src.c_str(), nullptr, &src_m, nullptr) && !force) if(utils::get_file_time(src.c_str(), nullptr, &src_m, nullptr) && !force)
return; return;
std::sort(fixed_res.begin(), fixed_res.end());
for(auto& v: correct::names) for(auto& v: correct::names)
{ {
std::string fn(root + v + ".json"); std::string fn(root + v + ".json");
@ -301,35 +398,8 @@ namespace cis
{ {
if(n.name == v) if(n.name == v)
{ {
gb_json *init = new gb_json(); correct::save_correct_data(n, fixed_res, init_dpi, init_clr);
correct::CONDDATA def; break;
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;
} }
} }
} }
@ -350,35 +420,8 @@ namespace cis
{ {
if(n.name == fn) if(n.name == fn)
{ {
gb_json *init = new gb_json(); correct::save_correct_data(n, fixed_res, init_dpi, init_clr);
correct::CONDDATA def; break;
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;
} }
} }
} }

View File

@ -2,6 +2,7 @@
// //
// Date: 2024-01-19 // Date: 2024-01-19
#pragma once #pragma once
#include <vector>
#define CIS_SECTOR_COUNT 6 // how many sectors of ONE CIS #define CIS_SECTOR_COUNT 6 // how many sectors of ONE CIS
#define CIS_CORRECT_DATA_PATH "/usr/local/huago2/" #define CIS_CORRECT_DATA_PATH "/usr/local/huago2/"
@ -11,6 +12,8 @@ class gb_json;
namespace cis namespace cis
{ {
std::vector<int> get_fixed_resolution(void);
// Function: how many pixels one sector generated // Function: how many pixels one sector generated
// //
// Parameter: sec_num - sector index, from Zero to CIS_SECTOR_COUNT - 1 // Parameter: sec_num - sector index, from Zero to CIS_SECTOR_COUNT - 1

View File

@ -794,6 +794,7 @@ bool device_option::parse_simple_logic_expression(gb_json* root, const char* exp
{ {
v = std::string(next, tag - next); v = std::string(next, tag - next);
calc.val2 = device_option::from_text_value(n.c_str(), v.c_str()); calc.val2 = device_option::from_text_value(n.c_str(), v.c_str());
ret = device_option::get_between(n.c_str(), &calc.compare);
} }
} }
} }