From 7586520973a84543e933c15f0a76c08054105389 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Thu, 13 Oct 2022 11:58:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=AE=9A=E4=B9=89GA?= =?UTF-8?q?MMA=E6=95=B0=E6=8D=AE=E4=B8=8D=E8=83=BD=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=EF=BC=9B=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8C=BA=E5=9F=9F=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=8B=96=E6=9B=B3=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sane/DlgArea.cpp | 4 ++-- sane/DlgPage.cpp | 4 ++++ sane/gb_json.cpp | 39 ++++++++++++++++++++++++++++++++++----- sane/gb_json.h | 4 +++- sane/scanner.cpp | 27 ++++++++++++++++++++++++--- 5 files changed, 67 insertions(+), 11 deletions(-) diff --git a/sane/DlgArea.cpp b/sane/DlgArea.cpp index c3814c2..a5938b9 100644 --- a/sane/DlgArea.cpp +++ b/sane/DlgArea.cpp @@ -306,8 +306,8 @@ void dlg_area::drag_blocks(std::vector& blocks) r.left = user_sel_.left; r.top = user_sel_.top; - r.right = r.left + 1; - r.bottom = r.top + 1; + r.right = r.left + l; + r.bottom = r.top + l; r.pos = DRAG_POS_LT; blocks.clear(); diff --git a/sane/DlgPage.cpp b/sane/DlgPage.cpp index eaf0f9d..acf2e9f 100644 --- a/sane/DlgPage.cpp +++ b/sane/DlgPage.cpp @@ -832,6 +832,10 @@ void dlg_page::handle_command(WORD code, WORD id, HANDLE ctrl) len = sizeof(gamma); dlg.get_gamma(&gamma); sane_.sane_io_control_api(dev_, IO_CTRL_CODE_SET_CUSTOM_GAMMA, &gamma, &len); + + gb::sane_config* cfg = get_config(); + if (cfg) + cfg->config_changed(id_custom_gamma_, (char*)&gamma, sizeof(gamma), true); } return; diff --git a/sane/gb_json.cpp b/sane/gb_json.cpp index b3ee341..28da594 100644 --- a/sane/gb_json.cpp +++ b/sane/gb_json.cpp @@ -831,6 +831,8 @@ namespace gb namespace gb { + std::string sane_config::opt_data_appendix_("_data"); + sane_config::sane_config() : jsn_(NULL), bkp_(NULL), in_setting_(false) { def_val_ = new gb::json(); @@ -881,6 +883,22 @@ namespace gb return ret; } + bool sane_config::is_option_data(std::string& name) + { + size_t pos = name.find(sane_config::opt_data_appendix_); + + if (pos != std::string::npos) + { + if (pos + sane_config::opt_data_appendix_.length() == name.length()) + { + name.erase(pos); + + return true; + } + } + + return false; + } void sane_config::clear() { @@ -1053,7 +1071,7 @@ namespace gb else jsn_->set_value(name, hex_v.c_str()); } - void sane_config::config_changed(int sn, const char* val, size_t bytes) + void sane_config::config_changed(int sn, const char* val, size_t bytes, bool extra) { std::string name(""), hex_v(to_hex_letter(val, bytes)), @@ -1062,11 +1080,22 @@ namespace gb if (id_name_.count(sn)) { name = id_name_[sn]; - def = default_value(name.c_str()); - if (hex_v == def) - jsn_->remove(name.c_str()); - else + if (extra) + { + name += sane_config::opt_data_appendix_; jsn_->set_value(name.c_str(), hex_v.c_str()); + } + else + { + def = default_value(name.c_str()); + if (hex_v == def) + { + jsn_->remove(name.c_str()); + jsn_->remove((name + sane_config::opt_data_appendix_).c_str()); + } + else + jsn_->set_value(name.c_str(), hex_v.c_str()); + } } } void sane_config::remove_config(const char* name) diff --git a/sane/gb_json.h b/sane/gb_json.h index 565df29..4a24ef1 100644 --- a/sane/gb_json.h +++ b/sane/gb_json.h @@ -100,8 +100,10 @@ namespace gb sane_config(); ~sane_config(); + static std::string opt_data_appendix_; static bool hex(unsigned char ch, unsigned char* val); static bool hex_char(const char* data, unsigned char* val); + static bool is_option_data(std::string& name); // reset baase option name into 'name' if name was option data, and return true public: bool load_from_file(const wchar_t* file); @@ -112,7 +114,7 @@ namespace gb bool next_config(std::string& name, std::string& val); void begin_setting(bool restore = false); void config_changed(const char* name, const char* val, size_t bytes); - void config_changed(int sn, const char* val, size_t bytes); + void config_changed(int sn, const char* val, size_t bytes, bool extra = false); void remove_config(const char* name); void end_setting(bool cancel); int id_from_name(const char* name); diff --git a/sane/scanner.cpp b/sane/scanner.cpp index 5afe6cd..30a2e7b 100644 --- a/sane/scanner.cpp +++ b/sane/scanner.cpp @@ -478,13 +478,34 @@ void scanner::save_config(const wchar_t* file) void scanner::apply_config(void) { std::string n(""), v(""), ver(cfg_->get_version()); - std::wstring notice(L""); + if (cfg_->first_config(n, v)) { do { - int id = cfg_->id_from_name(n.c_str()); - if (id != -1) + int id = cfg_->id_from_name(n.c_str()); + if (id == -1) + { + if (gb::sane_config::is_option_data(n)) + { + id = cfg_->id_from_name(n.c_str()); + if (id == is_custom_gamma_id_) + { + if (v.length() == sizeof(SANE_Gamma)) + { + unsigned int l = v.length(); + hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_SET_CUSTOM_GAMMA, &v[0], &l); + } + else + { + wchar_t info[128] = { 0 }; + swprintf_s(info, _countof(info) - 1, L"ERROR: custom gamma data length is %u, but we expect %u.\r\n", v.length(), sizeof(SANE_Gamma)); + log_info(info, 0); + } + } + } + } + else { void* data = &v[0]; SANE_Fixed fixed = 0;