修复自定义区域及GAMMA界面初始化参数传递问题
This commit is contained in:
parent
96f6b45893
commit
f9057909f9
|
@ -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_);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue