From f9057909f94aaf1f308b43618fcfa6d05cf59af9 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Tue, 5 Jul 2022 17:00:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E5=8F=8AGAMMA=E7=95=8C=E9=9D=A2=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=8F=82=E6=95=B0=E4=BC=A0=E9=80=92=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sane/DlgArea.cpp | 31 +++++++++++++++++++-------- sane/DlgArea.h | 11 +++++----- sane/DlgGamma.cpp | 54 +++++++++++++++++++++++------------------------ sane/DlgGamma.h | 2 +- sane/DlgPage.cpp | 40 +++++++++++++++++++++++------------ 5 files changed, 81 insertions(+), 57 deletions(-) diff --git a/sane/DlgArea.cpp b/sane/DlgArea.cpp index 681ffb4..d800d0a 100644 --- a/sane/DlgArea.cpp +++ b/sane/DlgArea.cpp @@ -205,6 +205,15 @@ float dlg_area::as_mm(float v) else return v; } +float dlg_area::from_mm(float v) +{ + if (unit_ == PAPER_UNIT_INCH) + return dlg_area::mm_2_inches(v); + else if (unit_ == PAPER_UNIT_PIXEL) + return dlg_area::mm_2_pixel(v, dpi_); + else + return v; +} float dlg_area::as_inches(float v) { if (unit_ == PAPER_UNIT_MM) @@ -650,12 +659,12 @@ void dlg_area::set_paper(const wchar_t* name, float width_mm, float height_mm, f clear_area(); } -void dlg_area::set_area(int x, int y, int w, int h) +void dlg_area::set_area(float x, float y, float w, float h) { - x_ = x; - y_ = y; - w_ = w; - h_ = h; + x_ = from_mm(x); + y_ = from_mm(y); + w_ = from_mm(w); + h_ = from_mm(h); if (x_ > paper_w_) { @@ -675,6 +684,10 @@ void dlg_area::set_area(int x, int y, int w, int h) } if (h_ + y_ > paper_h_) h_ = paper_h_ - y_; + user_sel_.left = whole_.left + x_ / ratio_; + user_sel_.top = whole_.top + y_ / ratio_; + user_sel_.right = user_sel_.left + w_ / ratio_; + user_sel_.bottom = user_sel_.top + h_ / ratio_; refresh_paper_info(); } @@ -715,19 +728,19 @@ int dlg_area::do_modal(HWND parent) return exit_code_; } -int dlg_area::x_in_mm(void) +float dlg_area::x_in_mm(void) { return as_mm(x_); } -int dlg_area::y_in_mm(void) +float dlg_area::y_in_mm(void) { return as_mm(y_); } -int dlg_area::w_in_mm(void) +float dlg_area::w_in_mm(void) { return as_mm(w_); } -int dlg_area::h_in_mm(void) +float dlg_area::h_in_mm(void) { return as_mm(h_); } diff --git a/sane/DlgArea.h b/sane/DlgArea.h index 048d6be..83f5006 100644 --- a/sane/DlgArea.h +++ b/sane/DlgArea.h @@ -59,6 +59,7 @@ class dlg_area: public dlg_base void handle_command(WORD code, WORD id, HANDLE ctrl); float as_mm(float v); + float from_mm(float v); float as_inches(float v); float as_pixels(float v); std::wstring format_number(float v); @@ -89,10 +90,10 @@ public: public: void set_paper(const wchar_t* name, float width_mm, float height_mm, float dpi); - void set_area(int x, int y, int w, int h); + void set_area(float x, float y, float w, float h); int do_modal(HWND parent); // return IDOK or IDCANCEL - int x_in_mm(void); - int y_in_mm(void); - int w_in_mm(void); - int h_in_mm(void); + float x_in_mm(void); + float y_in_mm(void); + float w_in_mm(void); + float h_in_mm(void); }; diff --git a/sane/DlgGamma.cpp b/sane/DlgGamma.cpp index 729e6da..25941cd 100644 --- a/sane/DlgGamma.cpp +++ b/sane/DlgGamma.cpp @@ -650,27 +650,27 @@ int dlg_gamma::do_modal(HWND parent) void dlg_gamma::get_gamma(SANE_Gamma* gamma) { gamma->apply_to_back = SANE_FALSE; - if (cur_ == &rgb_gray_) + //if (cur_ == &rgb_gray_) { + cur_ = &rgb_gray_; gamma->pt_count = cur_->points.size() - 2; - gamma->pt_count_r = gamma->pt_count_g = gamma->pt_count_b = 0; - for (int i = 2; i < gamma->pt_count; ++i) + // gamma->pt_count_r = gamma->pt_count_g = gamma->pt_count_b = 0; + for (int i = 2; i < cur_->points.size(); ++i) { gamma->keypoint[i - 2].x = cur_->points[i].x; gamma->keypoint[i - 2].y = cur_->points[i].y; } - cur_ = &rgb_gray_; for (int i = 0; i < 256; ++i) gamma->table[i] = calc_value(i); } - else + //else { - gamma->pt_count = 0; + // gamma->pt_count = 0; cur_ = &red_; - gamma->pt_count_r = cur_->points.size(); - for (int i = 2; i < gamma->pt_count; ++i) + gamma->pt_count_r = cur_->points.size() - 2; + for (int i = 2; i < cur_->points.size(); ++i) { gamma->keypoint_r[i - 2].x = cur_->points[i].x; gamma->keypoint_r[i - 2].y = cur_->points[i].y; @@ -679,8 +679,8 @@ void dlg_gamma::get_gamma(SANE_Gamma* gamma) gamma->table[i] = calc_value(i); cur_ = &green_; - gamma->pt_count_g = cur_->points.size(); - for (int i = 2; i < gamma->pt_count; ++i) + gamma->pt_count_g = cur_->points.size() - 2; + for (int i = 2; i < cur_->points.size(); ++i) { gamma->keypoint_g[i - 2].x = cur_->points[i].x; gamma->keypoint_g[i - 2].y = cur_->points[i].y; @@ -689,8 +689,8 @@ void dlg_gamma::get_gamma(SANE_Gamma* gamma) gamma->table[256 + i] = calc_value(i); cur_ = &blue_; - gamma->pt_count_b = cur_->points.size(); - for (int i = 2; i < gamma->pt_count; ++i) + gamma->pt_count_b = cur_->points.size() - 2; + for (int i = 2; i < cur_->points.size(); ++i) { gamma->keypoint_b[i - 2].x = cur_->points[i].x; gamma->keypoint_b[i - 2].y = cur_->points[i].y; @@ -699,24 +699,22 @@ void dlg_gamma::get_gamma(SANE_Gamma* gamma) gamma->table[512 + i] = calc_value(i); } } -void dlg_gamma::set_gamma(const SANE_Gamma* gamma) +void dlg_gamma::set_gamma(const SANE_Gamma* gamma, bool gray) { int sel = 0; SendMessage(get_item(IDC_CHANNEL), CB_RESETCONTENT, 0, 0); - if (gamma->pt_count) + is_color_ = !gray; + cur_ = &rgb_gray_; + init_curve(cur_); + for (int i = 0; i < gamma->pt_count; ++i) { - is_color_ = false; - cur_ = &rgb_gray_; - init_curve(cur_); - for (int i = 0; i < gamma->pt_count; ++i) - { - POINT pt = { gamma->keypoint[i].x, gamma->keypoint[i].y }; - cur_->points.push_back(pt); - } - cur_->coefs = calc::coefs_from_points(cur_->points); - SendMessageW(get_item(IDC_CHANNEL), CB_ADDSTRING, 0, (LPARAM)L"\u7070"); + POINT pt = { gamma->keypoint[i].x, gamma->keypoint[i].y }; + cur_->points.push_back(pt); } - else + cur_->coefs = calc::coefs_from_points(cur_->points); + SendMessageW(get_item(IDC_CHANNEL), CB_ADDSTRING, 0, is_color_ ? (LPARAM)L"RGB" : (LPARAM)L"\u7070"); + + if(!gray) { is_color_ = true; cur_ = &red_; @@ -746,13 +744,13 @@ void dlg_gamma::set_gamma(const SANE_Gamma* gamma) } cur_->coefs = calc::coefs_from_points(cur_->points); - SendMessageW(get_item(IDC_CHANNEL), CB_ADDSTRING, 0, (LPARAM)L"RGB"); + // SendMessageW(get_item(IDC_CHANNEL), CB_ADDSTRING, 0, (LPARAM)L"RGB"); SendMessageW(get_item(IDC_CHANNEL), CB_ADDSTRING, 0, (LPARAM)L"\u7ea2"); SendMessageW(get_item(IDC_CHANNEL), CB_ADDSTRING, 0, (LPARAM)L"\u7eff"); SendMessageW(get_item(IDC_CHANNEL), CB_ADDSTRING, 0, (LPARAM)L"\u84dd"); - cur_ = &red_; - sel = 1; } + cur_ = &rgb_gray_; + sel = 0; SendMessage(get_item(IDC_CHANNEL), CB_SETCURSEL, sel, 0); SendMessage(get_item(IDC_SCHEME), CB_SETCURSEL, 0, 0); } diff --git a/sane/DlgGamma.h b/sane/DlgGamma.h index c0665ae..cbb7e40 100644 --- a/sane/DlgGamma.h +++ b/sane/DlgGamma.h @@ -55,5 +55,5 @@ public: public: int do_modal(HWND parent); void get_gamma(SANE_Gamma* gamma); - void set_gamma(const SANE_Gamma* gamma); + void set_gamma(const SANE_Gamma* gamma, bool gray); }; diff --git a/sane/DlgPage.cpp b/sane/DlgPage.cpp index 7d2376e..7c500ea 100644 --- a/sane/DlgPage.cpp +++ b/sane/DlgPage.cpp @@ -140,13 +140,12 @@ HWND dlg_base::hwnd(void) } void dlg_base::show(bool visible) { - UINT cmd = SW_HIDE; - if (visible) - { - DWORD style = GetWindowLong(hwnd_, GWL_STYLE); + UINT cmd = visible ? SW_SHOW : SW_HIDE; + DWORD style = GetWindowLong(hwnd_, GWL_STYLE); - cmd = SW_SHOW; - if (!(style & WS_CHILD)) + if (!(style & WS_CHILD)) + { + if (visible) { RECT r0 = { 0 }, rp = { 0 }, rme = { 0 }; POINT pt = { 0 }; @@ -180,9 +179,9 @@ void dlg_base::show(bool visible) SetWindowPos(hwnd_, HWND_TOP, pt.x, pt.y, RECT_W(rme), RECT_H(rme), SWP_NOSIZE); UpdateWindow(hwnd_); } + EnableWindow(parent_, !visible); } ShowWindow(hwnd_, cmd); - EnableWindow(parent_, !visible); } void dlg_base::enable(bool enable) { @@ -597,11 +596,22 @@ void dlg_page::handle_command(WORD code, WORD id, HANDLE ctrl) { unsigned int size = 0; std::string utf8(local_trans::u2a(paper_.c_str(), CP_UTF8)); - dlg_area dlg(hwnd()); + dlg_area dlg(parent_); + float x = .0f, y = .0f, w = .0f, h = .0f; + SANE_Fixed sf; sane_.sane_io_control_api(dev_, IO_CTRL_CODE_GET_PAPER_SIZE, &utf8[0], &size); dlg.set_paper(paper_.c_str(), (float)(size & 0x0ffff), float(size >> 16), dpi_); - if (dlg.do_modal(hwnd()) == IDOK) + sane_.sane_control_option_api(dev_, id_custom_left_, SANE_ACTION_GET_VALUE, &sf, NULL); + x = SANE_UNFIX(sf); + sane_.sane_control_option_api(dev_, id_custom_top_, SANE_ACTION_GET_VALUE, &sf, NULL); + y = SANE_UNFIX(sf); + sane_.sane_control_option_api(dev_, id_custom_right_, SANE_ACTION_GET_VALUE, &sf, NULL); + w = SANE_UNFIX(sf) - x; + sane_.sane_control_option_api(dev_, id_custom_bottom_, SANE_ACTION_GET_VALUE, &sf, NULL); + h = SANE_UNFIX(sf) - y; + dlg.set_area(x, y, w, h); + if (dlg.do_modal(parent_) == IDOK) { SANE_Fixed val = SANE_FIX(dlg.x_in_mm()); SANE_Int after = 0; @@ -630,13 +640,15 @@ void dlg_page::handle_command(WORD code, WORD id, HANDLE ctrl) } else if (id == dlg_page::dyn_id_base + id_custom_gamma_) { - dlg_gamma dlg(hwnd(), true); + dlg_gamma dlg(parent_, true); + SANE_Gamma gamma = { 0 }; + unsigned int len = sizeof(gamma); - if (dlg.do_modal(hwnd()) == IDOK) + sane_.sane_io_control_api(dev_, IO_CTRL_CODE_GET_CUSTOM_GAMMA, &gamma, &len); + dlg.set_gamma(&gamma, len < 2); + if (dlg.do_modal(parent_) == IDOK) { - SANE_Gamma gamma = { 0 }; - unsigned int len = sizeof(gamma); - + len = sizeof(gamma); dlg.get_gamma(&gamma); sane_.sane_io_control_api(dev_, IO_CTRL_CODE_SET_CUSTOM_GAMMA, &gamma, &len); }