diff --git a/device/scanner.vcxproj b/device/scanner.vcxproj
index 0d68a59..a9d9f25 100644
--- a/device/scanner.vcxproj
+++ b/device/scanner.vcxproj
@@ -76,6 +76,7 @@
$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\oem\huagao;$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration);$(LibraryPath)
$(SolutionDir)..\..\tmp\$(PlatformTarget)\huagao\$(Configuration)\$(ProjectName)\
$(SolutionDir)..\..\release\win\$(PlatformTarget)\OEM\huagao\
+ true
false
@@ -83,6 +84,7 @@
$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\oem\huagao;$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration);$(LibraryPath)
$(SolutionDir)..\..\tmp\$(PlatformTarget)\huagao\$(Configuration)\$(ProjectName)\
$(SolutionDir)..\..\release\win\$(PlatformTarget)\OEM\huagao\
+ false
true
@@ -90,6 +92,7 @@
$(SolutionDir)..\..\tmp\$(PlatformTarget)\huagao\$(Configuration)\$(ProjectName)\
$(SolutionDir)..\..\code_device\hgdriver\3rdparty\nick;$(SolutionDir)..\..\sdk\include\opencv\;$(SolutionDir)..\..\code_device\hgdriver\3rdparty\cyusb\inc\;$(SolutionDir)..\..\code_device\hgdriver\3rdparty\libtiff\include\;$(SolutionDir)..\..\code_device\hgdriver\3rdparty\log4cplus\include\;$(SolutionDir)..\..\code_device\sdk\;$(SolutionDir)..\..\code_device\hgdriver\ImageProcess\;$(SolutionDir)..\..\sdk\include\;$(SolutionDir)..\..\code_device\hgdriver\hgdev\;$(SolutionDir)..\..\code_device\hgdriver\wrapper\;$(ProjectDir);$(SolutionDir)..\..\code_device\hgdriver\3rdparty\tiff\include\;$(SolutionDir)..\..\code_device\hgdriver\3rdparty\openssl\include;$(IncludePath)
$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\oem\huagao;$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration);$(LibraryPath)
+ true
false
@@ -97,6 +100,7 @@
$(SolutionDir)..\..\tmp\$(PlatformTarget)\huagao\$(Configuration)\$(ProjectName)\
$(SolutionDir)..\..\code_device\hgdriver\3rdparty\nick;$(SolutionDir)..\..\sdk\include\opencv\;$(SolutionDir)..\..\code_device\hgdriver\3rdparty\cyusb\inc\;$(SolutionDir)..\..\code_device\hgdriver\3rdparty\libtiff\include\;$(SolutionDir)..\..\code_device\hgdriver\3rdparty\log4cplus\include\;$(SolutionDir)..\..\code_device\sdk\;$(SolutionDir)..\..\code_device\hgdriver\ImageProcess\;$(SolutionDir)..\..\sdk\include\;$(SolutionDir)..\..\code_device\hgdriver\hgdev\;$(SolutionDir)..\..\code_device\hgdriver\wrapper\;$(ProjectDir);$(SolutionDir)..\..\code_device\hgdriver\3rdparty\tiff\include\;$(SolutionDir)..\..\code_device\hgdriver\3rdparty\openssl\include;$(IncludePath)
$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\oem\huagao;$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration);$(LibraryPath)
+ false
@@ -118,8 +122,10 @@
-
-
+ move /Y "$(TargetDir)$(ProjectName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+copy /y "$(TargetPath)" "C:\Windows\twain_32\HuaGoTwain"
@@ -147,8 +153,9 @@
-
-
+ move /Y "$(TargetDir)$(ProjectName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
@@ -169,8 +176,10 @@
$(ProjectDir)device.def
-
-
+ move /Y "$(TargetDir)$(ProjectName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+copy /y "$(TargetPath)" "C:\Program Files\HuaGoScan"
@@ -196,8 +205,9 @@
$(ProjectDir)device.def
-
-
+ move /Y "$(TargetDir)$(ProjectName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
diff --git a/device/win_usb/win_usb.cpp b/device/win_usb/win_usb.cpp
index d6e6952..64b5a65 100644
--- a/device/win_usb/win_usb.cpp
+++ b/device/win_usb/win_usb.cpp
@@ -48,9 +48,6 @@ void usb_callback::notify(libusb_context* ctx, usb_device* dev, int ev)
}
std::string u2utf8(const wchar_t* u)
{
-#if defined(OEM_NONE) || defined(OEM_LISCHENG) || defined(OEM_HANWANG) || defined(OEM_ZHONGJING)
- return hg_log::u2utf8(u);
-#else
int len = WideCharToMultiByte(CP_UTF8, 0, u, lstrlenW(u), NULL, 0, NULL, NULL);
char *ansi = new char[len + 4];
@@ -61,7 +58,6 @@ std::string u2utf8(const wchar_t* u)
delete[] ansi;
return utf8;
-#endif
}
std::wstring ansi2unicode(const char* ansi, UINT cp = CP_ACP)
{
diff --git a/lang/lang.def b/lang/lang.def
index 527189b..a53cdd5 100644
--- a/lang/lang.def
+++ b/lang/lang.def
@@ -10,3 +10,5 @@ EXPORTS
to_default_language
from_default_language
lang_refresh_language
+ language_option_descriptor
+
diff --git a/lang/lang.vcxproj b/lang/lang.vcxproj
index 060a9cf..5576933 100644
--- a/lang/lang.vcxproj
+++ b/lang/lang.vcxproj
@@ -29,7 +29,7 @@
DynamicLibrary
true
- v143
+ v142
Unicode
@@ -42,7 +42,7 @@
DynamicLibrary
true
- v143
+ v142
Unicode
@@ -74,27 +74,31 @@
$(SolutionDir)..\..\release\win\$(PlatformTarget)\OEM\huagao\
$(SolutionDir)..\..\tmp\$(PlatformTarget)\huagao\$(Configuration)\$(ProjectName)\
$(SolutionDir)..\..\sdk\include;$(IncludePath)
+ true
$(SolutionDir)..\..\release\win\$(PlatformTarget)\OEM\huagao\
$(SolutionDir)..\..\tmp\$(PlatformTarget)\huagao\$(Configuration)\$(ProjectName)\
$(SolutionDir)..\..\sdk\include;$(IncludePath)
+ false
$(SolutionDir)..\..\release\win\$(PlatformTarget)\OEM\huagao\
$(SolutionDir)..\..\tmp\$(PlatformTarget)\huagao\$(Configuration)\$(ProjectName)\
$(SolutionDir)..\..\sdk\include;$(IncludePath)
+ true
$(SolutionDir)..\..\release\win\$(PlatformTarget)\OEM\huagao\
$(SolutionDir)..\..\tmp\$(PlatformTarget)\huagao\$(Configuration)\$(ProjectName)\
$(SolutionDir)..\..\sdk\include;$(IncludePath)
+ false
Level3
true
- WIN32;_DEBUG;LANG_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);LANG_EXPORT;_CRT_SECURE_NO_WARNINGS
+ WIN32;_DEBUG;LANG_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);LANG_EXPORT;_CRT_SECURE_NO_WARNINGS;VENDOR=huagao
true
Use
pch.h
@@ -106,8 +110,11 @@
lang.def
-
-
+ mkdir "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+copy /y "$(TargetPath)" "C:\Windows\twain_32\HuaGoTwain"
@@ -116,7 +123,7 @@
true
true
true
- WIN32;NDEBUG;LANG_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);LANG_EXPORT;_CRT_SECURE_NO_WARNINGS
+ WIN32;NDEBUG;LANG_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);LANG_EXPORT;_CRT_SECURE_NO_WARNINGS;OEM=huagao
true
Use
pch.h
@@ -131,15 +138,17 @@
lang.def
-
-
+ mkdir "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
Level3
true
- _DEBUG;LANG_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);LANG_EXPORT;_CRT_SECURE_NO_WARNINGS
+ _DEBUG;LANG_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);LANG_EXPORT;_CRT_SECURE_NO_WARNINGS;OEM=huagao
true
Use
pch.h
@@ -151,8 +160,11 @@
lang.def
-
-
+ mkdir "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+copy /y "$(TargetPath)" "C:\Program Files\HuaGoScan"
@@ -161,7 +173,7 @@
true
true
true
- NDEBUG;LANG_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);LANG_EXPORT;_CRT_SECURE_NO_WARNINGS
+ NDEBUG;LANG_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions);LANG_EXPORT;_CRT_SECURE_NO_WARNINGS;OEM=huagao
true
Use
pch.h
@@ -176,8 +188,10 @@
lang.def
-
-
+ mkdir "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
diff --git a/sane/DlgArea.cpp b/sane/DlgArea.cpp
deleted file mode 100644
index 2b7e9fa..0000000
--- a/sane/DlgArea.cpp
+++ /dev/null
@@ -1,814 +0,0 @@
-// DlgIndicator.cpp: 实现文件
-//
-
-#include "DlgArea.h"
-#include "resource.h"
-#include "scanned_img.h" // for local_trans
-#include "mem_dc.h"
-
-// CDlgIndicator 对话框
-#define MM_PER_INCH 25.4f
-
-int dlg_area::area_min_pixel = 50;
-
-dlg_area::dlg_area(HWND parent) : dlg_base(parent, IDD_AREA)
- , unit_(PAPER_UNIT_MM), paper_w_(210), paper_h_(297), dpi_(200)
- , x_(0), y_(0), w_(paper_w_), h_(paper_h_)
- , paper_(L"A4")
- , paper_w_0_(paper_w_), paper_h_0_(paper_h_), cursor_(NULL), drag_(DRAG_POS_NONE)
- , in_set_func_(false)
-{
- std::wstring title(local_trans::lang_trans_between_hz936(CONST_STRING_CUSTOM_AREA));
-
- create();
-
- SetWindowTextW(hwnd(), title.c_str());
- title = local_trans::lang_trans_between_hz936(CONST_STRING_UNIT_MM) + L" (mm)";
- SendMessageW(get_item(IDC_UNIT), CB_ADDSTRING, 0, (LPARAM)&title[0]);
- title = local_trans::lang_trans_between_hz936(CONST_STRING_UNIT_INCH) + L" (inch)";
- SendMessageW(get_item(IDC_UNIT), CB_ADDSTRING, 0, (LPARAM)&title[0]);
- title = local_trans::lang_trans_between_hz936(CONST_STRING_UNIT_PIXEL) + L" (px)";
- SendMessageW(get_item(IDC_UNIT), CB_ADDSTRING, 0, (LPARAM)&title[0]);
- SendMessage(get_item(IDC_UNIT), CB_SETCURSEL, 0, 0);
-
-
- if (!dlg_base::is_language_pack_default_code_page())
- {
- int width_diff = 0, w = 0;
- RECT r = { 0 }, rp = { 0 };
-
- title = local_trans::lang_trans_between_hz936(CONST_STRING_OPT_PAPER) + L":";
- set_item_text(IDC_STATIC_PAPER, title.c_str());
- title = local_trans::lang_trans_between_hz936(CONST_STRING_UNIT) + L":";
- set_item_text(IDC_STATIC_UNIT, title.c_str());
- title = L"DPI (" + local_trans::lang_trans_between_hz936(CONST_STRING_UNIT_PIXEL) + L"/" + local_trans::lang_trans_between_hz936(CONST_STRING_UNIT_INCH) + L"):";
- set_item_text(IDC_STATIC_DPI, title.c_str());
- title = local_trans::lang_trans_between_hz936(CONST_STRING_AREA_SET) + L":";
- set_item_text(IDC_STATIC_AREA, title.c_str());
- title = local_trans::lang_trans_between_hz936(CONST_STRING_LEFT) + L":";
- set_item_text(IDC_STATIC_LEFT, title.c_str());
- title = local_trans::lang_trans_between_hz936(CONST_STRING_TOP) + L":";
- set_item_text(IDC_STATIC_TOP, title.c_str());
- title = local_trans::lang_trans_between_hz936(CONST_STRING_WIDTH) + L":";
- set_item_text(IDC_STATIC_W, title.c_str());
- title = local_trans::lang_trans_between_hz936(CONST_STRING_HEIGHT) + L":";
- set_item_text(IDC_STATIC_H, title.c_str());
-
- title = local_trans::lang_trans_between_hz936(CONST_STRING_RESTORE_AREA);
- set_item_text(IDC_BUTTON_RESET, title.c_str());
- title = local_trans::lang_trans_between_hz936(CONST_STRING_CANCEL);
- set_item_text(IDCANCEL, title.c_str());
- title = local_trans::lang_trans_between_hz936(CONST_STRING_OK);
- set_item_text(IDOK, title.c_str());
-
- layout();
- }
-}
-dlg_area::~dlg_area()
-{
-}
-
-float dlg_area::mm_2_pixel(float mm, float dpi)
-{
- return inches_2_pixel(mm_2_inches(mm), dpi);
-}
-float dlg_area::mm_2_inches(float mm)
-{
- return mm / MM_PER_INCH;
-}
-float dlg_area::inches_2_pixel(float inch, float dpi)
-{
- return inch * dpi;
-}
-float dlg_area::inches_2_mm(float inch)
-{
- return inch * MM_PER_INCH;
-}
-float dlg_area::pixel_2_mm(float px, float dpi)
-{
- return inches_2_mm(pixel_2_inches(px, dpi));
-}
-float dlg_area::pixel_2_inches(float px, float dpi)
-{
- return px / dpi;
-}
-
-BOOL dlg_area::handle_message(UINT msg, WPARAM wp, LPARAM lp)
-{
- wchar_t text[40] = { 0 };
- BOOL ret = TRUE;
-
- switch (msg)
- {
- case WM_INITDIALOG:
- UpdateWindow(hwnd());
- break;
- case WM_COMMAND:
- handle_command(HIWORD(wp), LOWORD(wp), (HWND)lp);
- break;
- case WM_PAINT:
- {
- PAINTSTRUCT ps = { 0 };
- HDC hdc = BeginPaint(hwnd(), &ps);
- {
- compatible_dc dc(hdc);
- on_paint(dc.get_dc());
- }
- EndPaint(hwnd(), &ps);
- }
- break;
- case WM_MOUSEMOVE:
- on_mouse_move(wp, LOWORD(lp), HIWORD(lp));
- break;
- case WM_LBUTTONDOWN:
- on_lbutton_down(LOWORD(lp), HIWORD(lp));
- break;
- case WM_LBUTTONUP:
- on_lbutton_up(LOWORD(lp), HIWORD(lp));
- break;
- default:
- ret = FALSE;
- }
- return ret;
-}
-void dlg_area::handle_command(WORD code, WORD id, HANDLE ctrl)
-{
- if (id == IDC_UNIT)
- {
- if (code == CBN_SELCHANGE)
- {
- on_unit_changed((HWND)ctrl);
- }
- }
- else if (id == IDCANCEL)
- {
- quit_modal(id);
- }
- else if (id == IDOK)
- {
- quit_modal(id);
- }
- else if (id == IDC_BUTTON_RESET)
- {
- clear_area();
- }
- else if (id == IDC_EDIT_x ||
- id == IDC_EDIT_y ||
- id == IDC_EDIT_W ||
- id == IDC_EDIT_H)
- {
- if (code == EN_CHANGE && !in_set_func_)
- {
- wchar_t val[80] = { 0 };
- float num = .0f;
-
- GetWindowTextW((HWND)ctrl, val, _countof(val) - 1);
- num = (float)_wtof(val);
- if (id == IDC_EDIT_x)
- {
- if (num < .0f)
- num = .0f;
- if (num > paper_w_ - dlg_area::area_min_pixel)
- num = paper_w_ - dlg_area::area_min_pixel;
- x_ = num;
- user_sel_.left = whole_.left + (LONG)(x_ / ratio_);
- if (x_ + w_ > paper_w_)
- w_ = paper_w_ - x_;
- user_sel_.right = user_sel_.left + (LONG)(w_ / ratio_);
- refresh_paper_info();
- InvalidateRect(hwnd(), &whole_, FALSE);
- }
- else if (id == IDC_EDIT_y)
- {
- if (num < .0f)
- num = .0f;
- if (num > paper_h_ - dlg_area::area_min_pixel)
- num = paper_h_ - dlg_area::area_min_pixel;
- y_ = num;
- user_sel_.top = whole_.top + (LONG)(y_ / ratio_);
- if (y_ + h_ > paper_h_)
- h_ = paper_h_ - y_;
- user_sel_.bottom = user_sel_.top + (LONG)(h_ / ratio_);
- refresh_paper_info();
- InvalidateRect(hwnd(), &whole_, FALSE);
- }
- else if (id == IDC_EDIT_W)
- {
- if (num < dlg_area::area_min_pixel)
- num = (float)dlg_area::area_min_pixel;
- if (num > paper_w_)
- num = paper_w_;
- w_ = num;
- user_sel_.right = user_sel_.left + (LONG)(w_ / ratio_);
- if (user_sel_.right > whole_.right)
- {
- OffsetRect(&user_sel_, whole_.right - user_sel_.right, 0);
- if (user_sel_.left < whole_.left)
- {
- user_sel_.left = whole_.left;
- x_ = 0;
- }
- }
- refresh_paper_info();
- InvalidateRect(hwnd(), &whole_, FALSE);
- }
- else if (id == IDC_EDIT_H)
- {
- if (num < dlg_area::area_min_pixel)
- num = (float)dlg_area::area_min_pixel;
- if (num > paper_h_)
- num = paper_h_;
- h_ = num;
- user_sel_.bottom = user_sel_.top + (LONG)(h_ / ratio_);
- if (user_sel_.bottom > whole_.bottom)
- {
- OffsetRect(&user_sel_, 0, whole_.bottom - user_sel_.bottom);
- if (user_sel_.top < whole_.top)
- {
- user_sel_.top = whole_.top;
- y_ = 0;
- }
- }
- refresh_paper_info();
- InvalidateRect(hwnd(), &whole_, FALSE);
- }
- }
- }
-}
-void dlg_area::layout(void)
-{
- RECT r = { 0 };
- int w_dif = get_width_diff_as_text_length(IDC_STATIC_LEFT),
- top1 = get_width_diff_as_text_length(IDC_STATIC_PAPER),
- top21 = get_width_diff_as_text_length(IDC_STATIC_UNIT),
- top22 = get_width_diff_as_text_length(IDC_STATIC_DPI);
-
-#define CHECK_CTRL_W(id) \
- if(w_dif < get_width_diff_as_text_length(id)) \
- w_dif = get_width_diff_as_text_length(id);
-
- CHECK_CTRL_W(IDC_STATIC_TOP);
- CHECK_CTRL_W(IDC_STATIC_W);
- CHECK_CTRL_W(IDC_STATIC_H);
- CHECK_CTRL_W(IDC_BUTTON_RESET);
- if (w_dif < top21 + top22)
- w_dif = top21 + top22;
-
- // layout ...
- if (w_dif > 0)
- {
- GetWindowRect(hwnd(), &r);
- r.right += w_dif;
- MoveWindow(hwnd(), r.left, r.top, RECT_W(r), RECT_H(r), FALSE);
-
- expand_item(IDC_STATIC_PAPER, top1, 0);
- offset_item(IDC_EDIT_PAPER, top1, 0);
- expand_item(IDC_EDIT_PAPER, w_dif - top1, 0);
-
- expand_item(IDC_STATIC_UNIT, top21, 0);
- offset_item(IDC_UNIT, top21, 0);
-
- offset_item(IDC_STATIC_DPI, w_dif - top22, 0);
- expand_item(IDC_STATIC_DPI, top22, 0);
- offset_item(IDC_EDIT_DPI, top21 + top22, 0);
-
- expand_item(IDC_STATIC_AREA, w_dif, 0);
-
- expand_item(IDC_STATIC_LEFT, w_dif, 0);
- offset_item(IDC_EDIT_x, w_dif, 0);
-
- expand_item(IDC_STATIC_TOP, w_dif, 0);
- offset_item(IDC_EDIT_y, w_dif, 0);
-
- expand_item(IDC_STATIC_W, w_dif, 0);
- offset_item(IDC_EDIT_W, w_dif, 0);
-
- expand_item(IDC_STATIC_H, w_dif, 0);
- offset_item(IDC_EDIT_H, w_dif, 0);
-
- top1 = get_width_diff_as_text_length(IDC_BUTTON_RESET);
- expand_item(IDC_BUTTON_RESET, top1, 0);
- offset_item(IDC_BUTTON_RESET, (w_dif - top1) / 2, 0);
-
- offset_item(IDOK, w_dif, 0);
- offset_item(IDCANCEL, w_dif, 0);
- }
-}
-
-float dlg_area::as_mm(float v)
-{
- if (unit_ == PAPER_UNIT_INCH)
- return dlg_area::inches_2_mm(v);
- else if (unit_ == PAPER_UNIT_PIXEL)
- return dlg_area::pixel_2_mm(v, dpi_);
- 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)
- return dlg_area::mm_2_inches(v);
- else if (unit_ == PAPER_UNIT_PIXEL)
- return dlg_area::pixel_2_inches(v, dpi_);
- else
- return v;
-}
-float dlg_area::as_pixels(float v)
-{
- if (unit_ == PAPER_UNIT_MM)
- return dlg_area::mm_2_pixel(v, dpi_);
- else if (unit_ == PAPER_UNIT_INCH)
- return dlg_area::inches_2_pixel(v, dpi_);
- else
- return v;
-}
-std::wstring dlg_area::format_number(float v)
-{
- wchar_t str[40] = { 0 };
-
- if (unit_ == PAPER_UNIT_PIXEL)
- swprintf_s(str, _countof(str) - 1, L"%d", (int)(v + .5f));
- else
- swprintf_s(str, _countof(str) - 1, L"%.2f", v);
-
- return str;
-}
-void dlg_area::refresh_paper_info(void)
-{
- SetWindowTextW(get_item(IDC_EDIT_PAPER), (paper_ + L"(" + format_number(paper_w_) + local_trans::lang_trans_between_hz936(CONST_STRING_MULTIPLE) + format_number(paper_h_) + L")").c_str());
- SetDlgItemInt(hwnd(), IDC_EDIT_DPI, UINT(dpi_), FALSE);
-
- in_set_func_ = true;
- SetWindowTextW(get_item(IDC_EDIT_x), format_number(x_).c_str());
- SetWindowTextW(get_item(IDC_EDIT_y), format_number(y_).c_str());
- SetWindowTextW(get_item(IDC_EDIT_W), format_number(w_).c_str());
- SetWindowTextW(get_item(IDC_EDIT_H), format_number(h_).c_str());
- in_set_func_ = false;
-
- InvalidateRect(hwnd(), &whole_, FALSE);
-}
-void dlg_area::to_unit(paper_unit unit)
-{
- float(dlg_area:: * conv)(float) = NULL;
-
- if (unit == PAPER_UNIT_INCH)
- {
- conv = &dlg_area::as_inches;
- paper_w_ = dlg_area::mm_2_inches(paper_w_0_);
- paper_h_ = dlg_area::mm_2_inches(paper_h_0_);
- }
- else if (unit == PAPER_UNIT_PIXEL)
- {
- conv = &dlg_area::as_pixels;
- paper_w_ = dlg_area::mm_2_pixel(paper_w_0_, dpi_);
- paper_h_ = dlg_area::mm_2_pixel(paper_h_0_, dpi_);
- }
- else // if (unit == PAPER_UNIT_MM)
- {
- conv = &dlg_area::as_mm;
- paper_w_ = paper_w_0_;
- paper_h_ = paper_h_0_;
- }
-
-#define CONV_UNIT(v) \
- v = (this->*conv)(v);
-
- CONV_UNIT(x_);
- CONV_UNIT(y_);
- CONV_UNIT(w_);
- CONV_UNIT(h_);
- unit_ = unit;
- refresh_paper_info();
-}
-void dlg_area::clear_area(void)
-{
- x_ = y_ = 0;
- w_ = paper_w_;
- h_ = paper_h_;
- user_sel_ = whole_;
-
- refresh_paper_info();
-}
-void dlg_area::drag_blocks(std::vector& blocks)
-{
- int l = 5;
- DRAGRECT r;
-
- r.left = user_sel_.left;
- r.top = user_sel_.top;
- r.right = r.left + l;
- r.bottom = r.top + l;
- r.pos = DRAG_POS_LT;
-
- blocks.clear();
- blocks.push_back(r);
- OffsetRect(&r, (user_sel_.right - user_sel_.left) / 2 - l / 2, 0); r.pos = DRAG_POS_MT;
- blocks.push_back(r);
- OffsetRect(&r, (user_sel_.right - r.right), 0); r.pos = DRAG_POS_RT;
- blocks.push_back(r);
- OffsetRect(&r, 0, (user_sel_.bottom - user_sel_.top) / 2 - l / 2); r.pos = DRAG_POS_RM;
- blocks.push_back(r);
- OffsetRect(&r, 0, (user_sel_.bottom - r.bottom)); r.pos = DRAG_POS_RB;
- blocks.push_back(r);
- OffsetRect(&r, -((user_sel_.right - user_sel_.left) / 2 - l / 2), 0); r.pos = DRAG_POS_MB;
- blocks.push_back(r);
- OffsetRect(&r, user_sel_.left - r.left, 0); r.pos = DRAG_POS_LB;
- blocks.push_back(r);
- OffsetRect(&r, 0, -((user_sel_.bottom - user_sel_.top) / 2 - l / 2)); r.pos = DRAG_POS_LM;
- blocks.push_back(r);
-}
-float dlg_area::pos_2_area(int val, bool x)
-{
- float r = x ? (float)(val - whole_.left) : (float)(val - whole_.top);
-
- r *= ratio_;
- if (unit_ == PAPER_UNIT_INCH)
- r = dlg_area::mm_2_inches(r);
- else if (unit_ == PAPER_UNIT_PIXEL)
- r = dlg_area::mm_2_pixel(r, dpi_);
-
- return r;
-}
-void dlg_area::valid_x(int& x, bool left)
-{
- if (left)
- {
- if (x < whole_.left)
- x = whole_.left;
- if (x > user_sel_.right - dlg_area::area_min_pixel)
- x = user_sel_.right - dlg_area::area_min_pixel;
- }
- else
- {
- if (x > whole_.right)
- x = whole_.right;
- if (x < user_sel_.left + dlg_area::area_min_pixel)
- x = user_sel_.left + dlg_area::area_min_pixel;
- }
-}
-void dlg_area::valid_y(int& y, bool top)
-{
- if (top)
- {
- if (y < whole_.top)
- y = whole_.top;
- if (y > user_sel_.bottom - dlg_area::area_min_pixel)
- y = user_sel_.bottom - dlg_area::area_min_pixel;
- }
- else
- {
- if (y > whole_.bottom)
- y = whole_.bottom;
- if (y < user_sel_.top + dlg_area::area_min_pixel)
- y = user_sel_.top + dlg_area::area_min_pixel;
- }
-}
-
-void dlg_area::on_unit_changed(HWND wnd)
-{
- wchar_t text[80] = { 0 };
-
- GetWindowTextW(wnd, text, _countof(text) - 1);
- if (wcsstr(text, L"mm"))
- {
- if (unit_ != PAPER_UNIT_MM)
- {
- to_unit(PAPER_UNIT_MM);
- }
- }
- else if (wcsstr(text, L"inch"))
- {
- if (unit_ != PAPER_UNIT_INCH)
- {
- to_unit(PAPER_UNIT_INCH);
- }
- }
- else
- {
- if (unit_ != PAPER_UNIT_PIXEL)
- {
- to_unit(PAPER_UNIT_PIXEL);
- }
- }
-}
-void dlg_area::on_paint(HDC hdc)
-{
- HBRUSH brsh_all = CreateSolidBrush(RGB(192, 192, 192)),
- brsh_drag = CreateSolidBrush(RGB(255, 0, 0)),
- brsh_sel = CreateSolidBrush(RGB(255, 255, 255));
- HPEN pen_border = CreatePen(PS_SOLID, 1, RGB(0, 255, 0)),
- pen_ruler = CreatePen(PS_SOLID, 1, RGB(0, 0, 0)),
- pen_old = (HPEN)SelectObject(hdc, pen_border);
- int step = 3, minor = 3, major = 5, count = 1, len = 0;
-
- FillRect(hdc, &whole_, brsh_all);
- FillRect(hdc, &user_sel_, brsh_sel);
- Rectangle(hdc, user_sel_.left, user_sel_.top, user_sel_.right, user_sel_.bottom);
- SelectObject(hdc, pen_ruler);
- for (int i = whole_.left + step; i < whole_.right; i += step)
- {
- ++count;
- len = (count % 5) == 0 ? major : minor;
- MoveToEx(hdc, i, whole_.top, NULL);
- LineTo(hdc, i, whole_.top + len);
- MoveToEx(hdc, i, whole_.bottom, NULL);
- LineTo(hdc, i, whole_.bottom - len);
- }
- count = 1;
- for (int i = whole_.top + step; i < whole_.bottom; i += step)
- {
- ++count;
- len = (count % 5) == 0 ? major : minor;
- MoveToEx(hdc, whole_.left, i, NULL);
- LineTo(hdc, whole_.left + len, i);
- MoveToEx(hdc, whole_.right, i, NULL);
- LineTo(hdc, whole_.right - len, i);
- }
-
- std::vector r;
- drag_blocks(r);
- for(size_t i = 0; i < r.size(); ++i)
- FillRect(hdc, &r[i], brsh_drag);
-
- SelectObject(hdc, pen_old);
- DeleteObject(pen_border);
- DeleteObject(pen_ruler);
- DeleteObject(brsh_all);
- DeleteObject(brsh_sel);
- DeleteObject(brsh_drag);
-}
-void dlg_area::on_mouse_move(DWORD key, int x, int y)
-{
- if (key == MK_LBUTTON)
- {
- if (drag_ == DRAG_POS_NONE)
- return;
-
- float dif = .0f;
-
- SetCursor(LoadCursorW(NULL, cursor_));
- if (drag_ == DRAG_POS_LT)
- {
- valid_x(x, true);
- valid_y(y, true);
- user_sel_.left = x;
- user_sel_.top = y;
- dif = x_;
- x_ = pos_2_area(x, true);
- w_ -= x_ - dif;
- dif = y_;
- y_ = pos_2_area(y, false);
- h_ -= y_ - dif;
- }
- else if (drag_ == DRAG_POS_MT)
- {
- valid_y(y, true);
- user_sel_.top = y;
- dif = y_;
- y_ = pos_2_area(y, false);
- h_ -= y_ - dif;
- }
- else if(drag_ == DRAG_POS_RT)
- {
- valid_x(x, false);
- valid_y(y, true);
- user_sel_.right = x;
- user_sel_.top = y;
- w_ = pos_2_area(x, true) - x_;
- if (x_ + w_ > paper_w_)
- w_ = paper_w_ - x_;
- dif = y_;
- y_ = pos_2_area(y, false);
- h_ -= y_ - dif;
- }
- else if (drag_ == DRAG_POS_LM)
- {
- valid_x(x, true);
- user_sel_.left = x;
- dif = x_;
- x_ = pos_2_area(x, true);
- w_ -= x_ - dif;
- }
- else if (drag_ == DRAG_POS_RM)
- {
- valid_x(x, false);
- user_sel_.right = x;
- w_ = pos_2_area(x, true) - x_;
- if (x_ + w_ > paper_w_)
- w_ = paper_w_ - x_;
- }
- else if (drag_ == DRAG_POS_LB)
- {
- valid_x(x, true);
- valid_y(y, false);
- user_sel_.left = x;
- user_sel_.bottom = y;
- dif = x_;
- x_ = pos_2_area(x, true);
- w_ -= x_ - dif;
- h_ = pos_2_area(y, false) - y_;
- }
- else if (drag_ == DRAG_POS_MB)
- {
- valid_y(y, false);
- user_sel_.bottom = y;
- h_ = pos_2_area(y, false) - y_;
- if (y_ + h_ > paper_h_)
- h_ = paper_h_ - y_;
- }
- else if (drag_ == DRAG_POS_RB)
- {
- valid_x(x, false);
- valid_y(y, false);
- user_sel_.right = x;
- user_sel_.bottom = y;
- w_ = pos_2_area(x, true) - x_;
- if (x_ + w_ > paper_w_)
- w_ = paper_w_ - x_;
- h_ = pos_2_area(y, false) - y_;
- if (y_ + h_ > paper_h_)
- h_ = paper_h_ - y_;
- }
- else if (drag_ == DRAG_POS_MOVE)
- {
- x += move_.x;
- y += move_.y;
- OffsetRect(&user_sel_, x - user_sel_.left, y - user_sel_.top);
- if (user_sel_.left < whole_.left)
- OffsetRect(&user_sel_, whole_.left - user_sel_.left, 0);
- if (user_sel_.right > whole_.right)
- OffsetRect(&user_sel_, whole_.right - user_sel_.right, 0);
- if (user_sel_.top < whole_.top)
- OffsetRect(&user_sel_, 0, whole_.top - user_sel_.top);
- if (user_sel_.bottom > whole_.bottom)
- OffsetRect(&user_sel_, 0, whole_.bottom - user_sel_.bottom);
- x_ = pos_2_area(user_sel_.left, true);
- if (x_ + w_ > paper_w_)
- x_ = paper_w_ - w_;
- y_ = pos_2_area(user_sel_.top, false);
- if (y_ + h_ > paper_h_)
- y_ = paper_h_ - h_;
- }
-
- refresh_paper_info();
- InvalidateRect(hwnd(), &whole_, FALSE);
- return;
- }
-
- POINT pt = { x, y };
- std::vector r;
- bool handled = false;
-
- drag_blocks(r);
- for (size_t i = 0; i < r.size(); ++i)
- {
- if (PtInRect(&r[i], pt))
- {
- handled = true;
- if (r[i].pos == DRAG_POS_LT || r[i].pos == DRAG_POS_RB)
- cursor_ = IDC_SIZENWSE;
- else if(r[i].pos == DRAG_POS_RT || r[i].pos == DRAG_POS_LB)
- cursor_ = IDC_SIZENESW;
- else if(r[i].pos == DRAG_POS_MT || r[i].pos == DRAG_POS_MB)
- cursor_ = IDC_SIZENS;
- else
- cursor_ = IDC_SIZEWE;
-
- drag_ = r[i].pos;
- SetCursor(LoadCursor(NULL, cursor_));
- break;
- }
- }
- if (!handled)
- {
- if (PtInRect(&user_sel_, pt))
- {
- drag_ = DRAG_POS_MOVE;
- cursor_ = IDC_SIZEALL;
- SetCursor(LoadCursor(NULL, cursor_));
- }
- else
- {
- drag_ = DRAG_POS_NONE;
- cursor_ = NULL;
- }
- }
-}
-void dlg_area::on_lbutton_down(int x, int y)
-{
- move_.x = user_sel_.left - x;
- move_.y = user_sel_.top - y;
- if (cursor_)
- SetCursor(LoadCursorW(NULL, cursor_));
- SetCapture(hwnd());
-}
-void dlg_area::on_lbutton_up(int x, int y)
-{
- drag_ = DRAG_POS_NONE;
- cursor_ = NULL;
- ReleaseCapture();
-}
-
-
-void dlg_area::set_paper(const wchar_t* name, float width_mm, float height_mm, float dpi)
-{
- wchar_t paper[40] = { 0 };
-
- dpi_ = dpi;
- paper_ = name;
-
- paper_w_0_ = width_mm;
- paper_h_0_ = height_mm;
-
- if (unit_ == PAPER_UNIT_INCH)
- {
- paper_w_ = dlg_area::mm_2_inches(width_mm);
- paper_h_ = dlg_area::mm_2_inches(height_mm);
- }
- else if (unit_ == PAPER_UNIT_PIXEL)
- {
- paper_w_ = dlg_area::mm_2_pixel(width_mm, dpi_);
- paper_h_ = dlg_area::mm_2_pixel(height_mm, dpi_);
- }
- else
- {
- paper_w_ = width_mm;
- paper_h_ = height_mm;
- }
-
- RECT r = { 0 };
- float xr = 1.0f,
- yr = 1.0f;
-
- GetWindowRect(get_item(IDC_STATIC_PAINT), &r);
- screen_2_client(&r);
- xr = paper_w_0_ / (r.right - r.left);
- yr = paper_h_0_ / (r.bottom - r.top);
- ratio_ = xr >= yr ? xr : yr;
-
- xr = paper_w_0_ / ratio_;
- xr = (r.right - r.left - xr) / 2;
- yr = paper_h_0_ / ratio_;
- yr = (r.bottom - r.top - yr) / 2;
- whole_.left = r.left + (LONG)xr; whole_.right = r.right - (LONG)xr;
- whole_.top = r.top + (LONG)yr; whole_.bottom = r.bottom - (LONG)yr;
-
- clear_area();
-}
-void dlg_area::set_area(float x, float y, float w, float h)
-{
- x_ = from_mm(x);
- y_ = from_mm(y);
- w_ = from_mm(w);
- h_ = from_mm(h);
-
- if (x_ > paper_w_)
- {
- if (w_ < paper_w_)
- x_ = paper_w_ - w_;
- else
- x_ = 0;
- }
- if (w_ + x_ > paper_w_)
- w_ = paper_w_ - x_;
- if (y_ > paper_h_)
- {
- if (h_ < paper_h_)
- y_ = paper_h_ - h_;
- else
- y_ = 0;
- }
- if (h_ + y_ > paper_h_)
- h_ = paper_h_ - y_;
- user_sel_.left = whole_.left + (LONG)(x_ / ratio_);
- user_sel_.top = whole_.top + (LONG)(y_ / ratio_);
- user_sel_.right = user_sel_.left + (LONG)(w_ / ratio_);
- user_sel_.bottom = user_sel_.top + (LONG)(h_ / ratio_);
-
- refresh_paper_info();
-}
-float dlg_area::x_in_mm(void)
-{
- return as_mm(x_);
-}
-float dlg_area::y_in_mm(void)
-{
- return as_mm(y_);
-}
-float dlg_area::w_in_mm(void)
-{
- return as_mm(w_);
-}
-float dlg_area::h_in_mm(void)
-{
- return as_mm(h_);
-}
diff --git a/sane/DlgArea.h b/sane/DlgArea.h
deleted file mode 100644
index 1067cad..0000000
--- a/sane/DlgArea.h
+++ /dev/null
@@ -1,98 +0,0 @@
-#pragma once
-
-#include
-#include
-
-#include "DlgPage.h"
-
-// CDlgIndicator 对话框
-
-class dlg_area: public dlg_base
-{
- enum paper_unit
- {
- PAPER_UNIT_MM = 0,
- PAPER_UNIT_INCH,
- PAPER_UNIT_PIXEL,
- };
- enum drag_pos
- {
- DRAG_POS_NONE = 0,
- DRAG_POS_LT,
- DRAG_POS_MT,
- DRAG_POS_RT,
- DRAG_POS_LM,
- DRAG_POS_RM,
- DRAG_POS_LB,
- DRAG_POS_MB,
- DRAG_POS_RB,
- DRAG_POS_MOVE,
- };
- typedef struct _drag_block : RECT
- {
- drag_pos pos;
- }DRAGRECT;
- std::wstring paper_;
- paper_unit unit_;
- float paper_w_0_;
- float paper_h_0_;
- float paper_w_;
- float paper_h_;
- float dpi_;
- float x_;
- float y_;
- float w_;
- float h_;
-
- RECT whole_;
- RECT user_sel_;
- float ratio_; // mm / pixel
- drag_pos drag_;
- POINT move_;
- bool in_set_func_;
- const wchar_t* cursor_;
-
- static int area_min_pixel;
-
- BOOL handle_message(UINT msg, WPARAM wp, LPARAM lp) override;
- void handle_command(WORD code, WORD id, HANDLE ctrl);
- void layout(void);
-
- 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);
- void refresh_paper_info(void);
- void to_unit(paper_unit unit);
- void clear_area(void);
- void drag_blocks(std::vector& blocks);
- float pos_2_area(int val, bool x);
- void valid_x(int& x, bool left);
- void valid_y(int& y, bool top);
-
- void on_unit_changed(HWND wnd);
- void on_paint(HDC hdc);
- void on_mouse_move(DWORD key, int x, int y);
- void on_lbutton_down(int x, int y);
- void on_lbutton_up(int x, int y);
-
-public:
- dlg_area(HWND parent);
- ~dlg_area();
-
- static float mm_2_pixel(float mm, float dpi);
- static float mm_2_inches(float mm);
- static float inches_2_pixel(float inch, float dpi);
- static float inches_2_mm(float inch);
- static float pixel_2_mm(float px, float dpi);
- static float pixel_2_inches(float px, float dpi);
-
-public:
- void set_paper(const wchar_t* name, float width_mm, float height_mm, float dpi);
- void set_area(float x, float y, float w, float h);
- float x_in_mm(void);
- float y_in_mm(void);
- float w_in_mm(void);
- float h_in_mm(void);
-};
diff --git a/sane/DlgCfgMgr.cpp b/sane/DlgCfgMgr.cpp
deleted file mode 100644
index 5ff5cd0..0000000
--- a/sane/DlgCfgMgr.cpp
+++ /dev/null
@@ -1,216 +0,0 @@
-// DlgIndicator.cpp: 实现文件
-//
-
-#include "DlgCfgMgr.h"
-#include "resource.h"
-#include "scanned_img.h" // for local_trans
-#include "mem_dc.h"
-#include "gb_json.h"
-
-// CDlgIndicator 对话框
-
-dlg_cfg_mgr::dlg_cfg_mgr(gb::scanner_cfg* cfg, HWND parent) : cfg_(cfg), dlg_base(parent, IDD_CFG_MGR), schm_changed_(false)
-{
- create();
-
- std::wstring title(local_trans::lang_trans_between_hz936(CONST_STRING_CFG_MANAGER));
- int dif = 0;
-
- SetWindowTextW(hwnd(), title.c_str());
-
- title = local_trans::lang_trans_between_hz936(CONST_STRING_CFG_SCHEME);
- set_item_text(IDC_STATIC_PAPER, title.c_str());
- set_item_fit_to_text(IDC_STATIC_PAPER);
-
- title = local_trans::lang_trans_between_hz936(CONST_STRING_DEL_SELECTED);
- set_item_text(IDC_BUTTON_DEL_SEL, title.c_str());
- dif = set_item_fit_to_text(IDC_BUTTON_DEL_SEL);
- if (dif)
- offset_item(IDC_BUTTON_DEL_SEL, -dif, 0);
-
- title = local_trans::lang_trans_between_hz936(CONST_STRING_DEL_ALL);
- set_item_text(IDC_BUTTON_DEL_ALL, title.c_str());
- set_item_fit_to_text(IDC_BUTTON_DEL_ALL);
-
- title = local_trans::lang_trans_between_hz936(CONST_STRING_CFG_CONTENT);
- set_item_text(IDC_STATIC_SKETCH, title.c_str());
-
- title = local_trans::lang_trans_between_hz936(CONST_STRING_OK);
- set_item_text(IDOK, title.c_str());
-}
-dlg_cfg_mgr::~dlg_cfg_mgr()
-{
-}
-
-
-BOOL dlg_cfg_mgr::handle_message(UINT msg, WPARAM wp, LPARAM lp)
-{
- wchar_t text[40] = { 0 };
- BOOL ret = TRUE;
-
- switch (msg)
- {
- case WM_INITDIALOG:
- on_init_dlg();
- UpdateWindow(hwnd());
- break;
- case WM_COMMAND:
- handle_command(HIWORD(wp), LOWORD(wp), (HWND)lp);
- break;
- case WM_NOTIFY:
- handle_notify(wp, (LPNMHDR)lp);
- break;
- case WM_PAINT:
- {
- PAINTSTRUCT ps = { 0 };
- HDC hdc = BeginPaint(hwnd(), &ps);
- {
- compatible_dc dc(hdc);
- on_paint(dc.get_dc());
- }
- EndPaint(hwnd(), &ps);
- }
- break;
- default:
- ret = FALSE;
- }
- return ret;
-}
-void dlg_cfg_mgr::handle_command(WORD code, WORD id, HANDLE ctrl)
-{
- wchar_t cls[128] = { 0 };
-
- GetClassNameW((HWND)ctrl, cls, _countof(cls) - 1);
- if (IS_BUTTON(cls))
- {
- if (code == BN_CLICKED)
- {
- if (id == IDOK || id == IDCANCEL)
- quit_modal(id);
- else if (id == IDC_BUTTON_DEL_SEL)
- on_del_selected();
- else if (id == IDC_BUTTON_DEL_ALL)
- on_del_all();
- }
- }
- else if (IS_EDIT(cls))
- {
- //if (code == EN_SETFOCUS)
- // label_edit_ = (HWND)ctrl;
- }
-}
-void dlg_cfg_mgr::handle_notify(UINT id, LPNMHDR pnhdr)
-{
- if (id == IDC_LIST1)
- {
- if (pnhdr->code == LVN_BEGINLABELEDITW)
- {
- LPNMLVDISPINFOW pdisp = (LPNMLVDISPINFOW)pnhdr;
-
- label_ = pdisp->item.pszText ? pdisp->item.pszText : L"";
- }
- else if (pnhdr->code == LVN_ENDLABELEDITW)
- {
- LPNMLVDISPINFOW pdisp = (LPNMLVDISPINFOW)pnhdr;
-
- if (pdisp->item.pszText && label_ != pdisp->item.pszText)
- {
- ListView_SetItemText(get_item(IDC_LIST1), pdisp->item.iItem, pdisp->item.iSubItem, pdisp->item.pszText);
-
- if (cfg_)
- {
- if (!cfg_->rename_scheme(local_trans::u2a(label_.c_str(), CP_UTF8).c_str(), local_trans::u2a(pdisp->item.pszText, CP_UTF8).c_str()))
- {
- std::wstring input(pdisp->item.pszText);
-
- input += L" " + local_trans::lang_trans_between_hz936(CONST_STRING_ALREADY_EXISTS);
- ::MessageBoxW(hwnd(), input.c_str(), local_trans::lang_trans_between_hz936(CONST_STRING_RE_INPUT).c_str(), MB_OK | MB_ICONINFORMATION);
- dlg_base::list_set_item_text(get_item(IDC_LIST1), pdisp->item.iItem, 0, label_.c_str());
- }
- }
- }
- }
- else if (pnhdr->code == LVN_ITEMCHANGED)
- {
- LPNMLISTVIEW pv = (LPNMLISTVIEW)pnhdr;
- if ((pv->uNewState & LVIS_SELECTED) && (pv->uOldState & LVIS_SELECTED) == 0)
- on_sel_changed(pv->iItem);
- }
- }
-}
-void dlg_cfg_mgr::layout(void)
-{
-}
-
-
-void dlg_cfg_mgr::on_init_dlg(void)
-{
- HWND lstwnd = get_item(IDC_LIST1);
- std::vector schemes;
-
- cfg_->get_all_schemes(schemes);
- dlg_base::list_insert_column(lstwnd, local_trans::lang_trans_between_hz936(CONST_STRING_CFG_NAME).c_str(), 270);
- for (size_t i = 1; i < schemes.size(); ++i) // 0 is default scheme
- {
- dlg_base::list_insert_item(lstwnd, local_trans::a2u(schemes[i].c_str(), CP_UTF8).c_str());
- }
-}
-void dlg_cfg_mgr::on_paint(HDC hdc)
-{
-}
-void dlg_cfg_mgr::on_sel_changed(int sel)
-{
- std::wstring name(dlg_base::list_get_text(get_item(IDC_LIST1), sel));
- gb::sane_config_schm* schm = cfg_->get_scheme(local_trans::u2a(name.c_str(), CP_UTF8).c_str());
-
- name = L"";
- if (schm)
- {
- std::string key(""), val("");
- int cnt = 1;
-
- if (schm->first_config(key, val))
- {
- do
- {
- std::string v(gb::sane_config_schm::sane_option_value_2_string(&val[0], val.length(), (SANE_Value_Type)cfg_->option_value_type(key.c_str())));
-
- name += std::to_wstring(cnt++) + L" - " + local_trans::a2u(cfg_->option_title(key.c_str()).c_str(), CP_UTF8) + L"\r\n ";
- if (cfg_->option_value_type(key.c_str()) == SANE_TYPE_STRING)
- v = local_trans::u2a(local_trans::lang_trans_between_hz936(local_trans::a2u(v.c_str(), CP_UTF8).c_str()).c_str(), CP_UTF8);
- name += local_trans::a2u(v.c_str(), CP_UTF8) + L"\r\n\r\n";
- } while (schm->next_config(key, val));
- }
- schm->release();
- }
- dlg_base::set_item_text(IDC_EDIT1, name.c_str());
-}
-void dlg_cfg_mgr::on_del_selected(void)
-{
- std::vector sels;
- HWND lwnd = get_item(IDC_LIST1);
- bool changed = false;
-
- dlg_base::list_get_selected_items(lwnd, sels);
- for(int i = sels.size() - 1; i >= 0; i--)
- {
- std::string name(local_trans::u2a(dlg_base::list_get_text(lwnd, sels[i]).c_str(), CP_UTF8));
- if (cfg_->remove_scheme(name.c_str()))
- {
- changed = true;
- ListView_DeleteItem(lwnd, sels[i]);
- schm_changed_ = true;
- }
- }
-}
-void dlg_cfg_mgr::on_del_all(void)
-{
- cfg_->remove_all_schemes();
- ListView_DeleteAllItems(get_item(IDC_LIST1)); // clear list
- schm_changed_ = true;
- dlg_base::set_item_text(IDC_EDIT1, L"");
-}
-bool dlg_cfg_mgr::is_scheme_changed(void)
-{
- return schm_changed_;
-}
diff --git a/sane/DlgCfgMgr.h b/sane/DlgCfgMgr.h
deleted file mode 100644
index ef66783..0000000
--- a/sane/DlgCfgMgr.h
+++ /dev/null
@@ -1,37 +0,0 @@
-#pragma once
-
-#include
-#include
-
-#include "DlgPage.h"
-
-// CDlgIndicator 对话框
-namespace gb
-{
- class scanner_cfg;
-}
-
-class dlg_cfg_mgr: public dlg_base
-{
- gb::scanner_cfg* cfg_;
- std::wstring label_;
- bool schm_changed_; // to notify parent refreshing UI and settings
-
- BOOL handle_message(UINT msg, WPARAM wp, LPARAM lp) override;
- void handle_command(WORD code, WORD id, HANDLE ctrl);
- void handle_notify(UINT id, LPNMHDR pnhdr);
- void layout(void);
-
- void on_init_dlg(void);
- void on_paint(HDC hdc);
- void on_sel_changed(int sel);
- void on_del_selected(void);
- void on_del_all(void);
-
-public:
- dlg_cfg_mgr(gb::scanner_cfg* cfg, HWND parent);
- ~dlg_cfg_mgr();
-
-public:
- bool is_scheme_changed(void);
-};
diff --git a/sane/DlgGamma.cpp b/sane/DlgGamma.cpp
deleted file mode 100644
index 6019e20..0000000
--- a/sane/DlgGamma.cpp
+++ /dev/null
@@ -1,825 +0,0 @@
-// DlgIndicator.cpp: 实现文件
-//
-
-#include "DlgGamma.h"
-#include "resource.h"
-#include "mem_dc.h"
-
-#include "scanned_img.h"
-
-#define MAX_KEY_POINTS 4 // not include (0, 0) and (255, 255)
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// calculator
-#include
-namespace calc
-{
- void solve_matrix(double** a, int n, std::vector& coef)
- {
- int m = 0;
- int i, j;
-
- coef.clear();
- for (j = 0; j < n; j++) {
- double max = 0;
- double imax = 0;
- for (i = j; i < n; i++) {
- if (imax < fabs(a[i][j])) {
- imax = fabs(a[i][j]);
- max = a[i][j];//得到各行中所在列最大元素
- m = i;
- }
- }
- if (fabs(a[j][j]) != max) {
- double b = 0;
- for (int k = j; k < n + 1; k++) {
- b = a[j][k];
- a[j][k] = a[m][k];
- a[m][k] = b;
- }
- }
- for (int r = j; r < n + 1; r++) {
- a[j][r] = a[j][r] / max;//让该行的所在列除以所在列的第一个元素,目的是让首元素为1
- }
- for (i = j + 1; i < n; i++) {
- double c = a[i][j];
- if (c == 0) continue;
- for (int s = j; s < n + 1; s++) {
- //double tempdata = a[i][s];
- a[i][s] = a[i][s] - a[j][s] * c;//前后行数相减,使下一行或者上一行的首元素为0
- }
- }
- }
- for (i = n - 2; i >= 0; i--) {
- for (j = i + 1; j < n; j++) {
- a[i][n] = a[i][n] - a[j][n] * a[i][j];
- }
- }
-
- for (int k = 0; k < n; k++) {
- coef.push_back(a[k][n]);
- }
- }
- int power(int m, int exp)
- {
- int val = 1;
- for (int i = 0; i < exp; ++i)
- val *= m;
-
- return val;
- }
- std::vector coefs_from_points(const std::vector& pt)
- {
- std::vector coef;
- double** a = new double* [pt.size()];
-
- for (int i = 0; i < (int)pt.size(); ++i)
- a[i] = new double[pt.size() + 1];
-
- for (int i = 0; i < (int)pt.size(); ++i)
- {
- for (int j = 0; j < (int)pt.size(); ++j)
- a[i][j] = power(pt[i].x, pt.size() - j - 1);
- a[i][pt.size()] = pt[i].y;
- }
- solve_matrix(a, pt.size(), coef);
- for (int i = 0; i < (int)pt.size(); ++i)
- delete[] a[i];
- delete[] a;
-
- return coef;
- }
-}
-
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// dlg_gamma
-dlg_gamma::dlg_gamma(HWND parent, bool color) : dlg_base(parent, IDD_GAMMA), is_color_(color), bkgnd_(NULL)
- , show_all_(false)
-{
- std::wstring title(local_trans::lang_trans_between_hz936(CONST_STRING_CUSTOM_TONE));
-
- create();
- SetWindowTextW(hwnd(), title.c_str());
-
- if (!dlg_base::is_language_pack_default_code_page())
- {
- title = local_trans::lang_trans_between_hz936(CONST_STRING_TONE_SCHEME);
- set_item_text(IDC_STATIC_SCHEME, title.c_str());
-
- title = local_trans::lang_trans_between_hz936(CONST_STRING_COLOR_CHANNEL);
- set_item_text(IDC_STATIC_COLOR, title.c_str());
-
- title = local_trans::lang_trans_between_hz936(CONST_STRING_INITIALIZE);
- set_item_text(IDC_BUTTON_RESET, title.c_str());
-
- title = local_trans::lang_trans_between_hz936(CONST_STRING_INPUT);
- set_item_text(IDC_STATIC_INPUT, title.c_str());
-
- title = local_trans::lang_trans_between_hz936(CONST_STRING_OUTPUT);
- set_item_text(IDC_STATIC_OUTPUT, title.c_str());
-
- title = local_trans::lang_trans_between_hz936(CONST_STRING_CANCEL);
- set_item_text(IDCANCEL, title.c_str());
-
- title = local_trans::lang_trans_between_hz936(CONST_STRING_OK);
- set_item_text(IDOK, title.c_str());
-
- layout();
- }
-}
-dlg_gamma::~dlg_gamma()
-{
- DeleteObject(bkgnd_);
-}
-
-
-BOOL dlg_gamma::handle_message(UINT msg, WPARAM wp, LPARAM lp)
-{
- wchar_t text[40] = { 0 };
- BOOL ret = TRUE;
-
- switch (msg)
- {
- case WM_INITDIALOG:
- on_init_dlg();
- UpdateWindow(hwnd());
- break;
- case WM_COMMAND:
- handle_command(HIWORD(wp), LOWORD(wp), (HWND)lp);
- break;
- case WM_PAINT:
- {
- PAINTSTRUCT ps = { 0 };
- HDC hdc = BeginPaint(hwnd(), &ps);
- {
- compatible_dc dc(hdc);
- on_paint(dc.get_dc());
- }
- EndPaint(hwnd(), &ps);
- }
- break;
- case WM_MOUSEMOVE:
- on_mouse_move(wp, LOWORD(lp), HIWORD(lp));
- break;
- case WM_LBUTTONDOWN:
- on_lbutton_down(LOWORD(lp), HIWORD(lp));
- break;
- case WM_LBUTTONUP:
- on_lbutton_up(LOWORD(lp), HIWORD(lp));
- break;
- default:
- ret = FALSE;
- }
- return ret;
-}
-void dlg_gamma::handle_command(WORD code, WORD id, HANDLE ctrl)
-{
- if (code == BN_CLICKED)
- {
- if (id == IDC_BUTTON_RESET)
- {
- init_curve(cur_, cur_->clr);
- InvalidateRect(hwnd(), NULL, FALSE);
- }
- else
- {
- quit_modal(id);
- }
- }
- else if (code == EN_CHANGE)
- {
- if (id == IDC_EDIT_INPUT)
- {
- wchar_t val[40] = { 0 };
- int y = 0;
-
- GetDlgItemTextW(hwnd(), id, val, _countof(val) - 1);
- y = _wtoi(val);
- if (y < cur_->points[0].x)
- SetDlgItemInt(hwnd(), IDC_EDIT_INPUT, cur_->points[0].x, FALSE);
- if (y > cur_->points[1].x)
- SetDlgItemInt(hwnd(), IDC_EDIT_INPUT, cur_->points[1].x, FALSE);
- else
- {
- y = calc_value(y);
- SetDlgItemInt(hwnd(), IDC_EDIT_OUTPUT, y, FALSE);
- }
- }
- }
- else if (code == CBN_SELCHANGE)
- {
- on_combo_sel_changed(id, SendMessage((HWND)ctrl, CB_GETCURSEL, 0, 0));
- }
-}
-void dlg_gamma::layout(void)
-{
- int r1 = get_width_diff_as_text_length(IDC_STATIC_SCHEME),
- r21 = get_width_diff_as_text_length(IDC_STATIC_COLOR),
- r22 = get_width_diff_as_text_length(IDC_BUTTON_RESET),
- r31 = get_width_diff_as_text_length(IDC_STATIC_INPUT),
- r32 = get_width_diff_as_text_length(IDC_STATIC_OUTPUT),
- r33 = get_width_diff_as_text_length(IDCANCEL),
- r34 = get_width_diff_as_text_length(IDOK),
- diff = 0;
-
- if (diff < r1)
- diff = r1;
- if (diff < r21 + r22)
- diff = r21 + r22;
- if (diff < r31 + r32 + r33 + r34)
- diff = r31 + r32 + r33 + r34;
-
- if (diff > 0)
- {
- RECT r = { 0 };
-
- GetWindowRect(hwnd(), &r);
- r.right += diff;
- MoveWindow(hwnd(), r.left, r.top, RECT_W(r), RECT_H(r), FALSE);
-
- expand_item(IDC_STATIC_SCHEME, r1, 0);
- offset_item(IDC_SCHEME, r1, 0);
- expand_item(IDC_SCHEME, diff - r1, 0);
-
- expand_item(IDC_STATIC_COLOR, r21, 0);
- offset_item(IDC_CHANNEL, r21, 0);
-
- expand_item(IDC_BUTTON_RESET, r22, 0);
- offset_item(IDC_BUTTON_RESET, diff - r22, 0);
-
- expand_item(IDC_STATIC_INPUT, r31, 0);
- offset_item(IDC_EDIT_INPUT, r31, 0);
-
- offset_item(IDC_STATIC_OUTPUT, r31, 0);
- expand_item(IDC_STATIC_OUTPUT, r32, 0);
- offset_item(IDC_EDIT_OUTPUT, r31 + r32, 0);
-
- offset_item(IDCANCEL, diff - r33, 0);
- expand_item(IDCANCEL, r33, 0);
-
- offset_item(IDOK, diff - r34, 0);
- expand_item(IDOK, r34, 0);
-
- expand_item(IDC_STATIC_PAINT, diff, 0);
- }
-}
-void dlg_gamma::create_background(void)
-{
- COLORREF bclr = RGB(128, 128, 128);
- HDC hdc = GetWindowDC(hwnd()),
- cdc = CreateCompatibleDC(hdc);
- HBRUSH bkg = CreateSolidBrush(bclr);
- HPEN grid = CreatePen(PS_SOLID, 1, RGB(0, 0, 0)),
- old = (HPEN)SelectObject(cdc, grid);
- HBITMAP ob = NULL;
- int w = paint_area_.right - paint_area_.left + 2,
- h = paint_area_.bottom - paint_area_.top + 2;
- RECT r = { 1, 1, w - 1, h - 1};
-
- if (bkgnd_)
- DeleteObject(bkgnd_);
-
- // create bitmap and select into DC
- bkgnd_ = CreateCompatibleBitmap(hdc, w, h);
- ob = (HBITMAP)SelectObject(cdc, bkgnd_);
- SetBkColor(cdc, bclr);
-
- // background and grid
- FillRect(cdc, &r, bkg);
- MoveToEx(cdc, r.left, r.top, NULL);
- LineTo(cdc, r.right, r.top);
- LineTo(cdc, r.right, r.bottom);
- LineTo(cdc, r.left, r.bottom);
- LineTo(cdc, r.left, r.top);
- SelectObject(cdc, old);
- DeleteObject(grid);
- grid = CreatePen(PS_DASH, 1, RGB(0, 0, 0));
- SelectObject(cdc, grid);
- for (int i = 1; i < 6; ++i)
- {
- MoveToEx(cdc, r.left + i * 50, r.bottom, NULL);
- LineTo(cdc, r.left + i * 50, r.top);
-
- MoveToEx(cdc, r.left, r.bottom - i * 50, NULL);
- LineTo(cdc, r.right, r.bottom - i * 50);
- }
-
- // default curve
- MoveToEx(cdc, r.left, r.bottom, NULL);
- LineTo(cdc, r.right, r.top);
-
- // free resource
- SelectObject(cdc, old);
- SelectObject(cdc, ob);
- DeleteDC(cdc);
- ReleaseDC(hwnd(), hdc);
-
- DeleteObject(bkg);
- DeleteObject(grid);
-}
-void dlg_gamma::init_curve(GAMMACURVE* curv, COLORREF clr)
-{
- curv->points.clear();
- curv->points.push_back({ 0, 0 });
- curv->points.push_back({ 255, 255 });
- curv->coefs = calc::coefs_from_points(curv->points);
- curv->drag = -1;
- curv->left = 0;
- curv->right = 1;
- curv->clr = clr;
-}
-int dlg_gamma::add_drag_point(int x, int y)
-{
- int ind = -1;
-
- if (cur_->points.size() < MAX_KEY_POINTS + 2)
- {
- for (int i = 2; i < (int)cur_->points.size(); ++i)
- {
- if (x < cur_->points[i].x)
- {
- cur_->points.insert(cur_->points.begin() + i, { x, calc_value(x) });
- ind = i;
- cur_->coefs = calc::coefs_from_points(cur_->points);
- break;
- }
- else if (x == cur_->points[i].x)
- {
- ind = i;
- break;
- }
- }
- if (ind == -1)
- {
- ind = cur_->points.size();
- cur_->points.push_back({ x, calc_value(x) });
- cur_->coefs = calc::coefs_from_points(cur_->points);
- }
- cur_->left = ind - 1;
- cur_->right = ind + 1;
- if (cur_->left == 1)
- cur_->left = 0;
- if (cur_->right >= (int)cur_->points.size())
- cur_->right = 1;
- }
- else
- {
- for (int i = 2; i < (int)cur_->points.size(); ++i)
- {
- if (x == cur_->points[i].x)
- {
- ind = i;
- cur_->left = ind - 1;
- cur_->right = ind + 1;
- if (cur_->left == 1)
- cur_->left = 0;
- if (cur_->right >= (int)cur_->points.size())
- cur_->right = 1;
- break;
- }
- }
- }
- cur_->drag = ind;
-
- return ind;
-}
-BYTE dlg_gamma::calc_value(BYTE x)
-{
- double y = .0f;
- for(int j = 0; j < (int)cur_->points.size(); ++j)
- y += cur_->coefs[j] * calc::power(x, cur_->points.size() - j - 1);
-
- if (y > 255.0f)
- y = 255.0f;
- if (y < .0f)
- y = .0f;
-
- bool upper = cur_->points[1].y > cur_->points[0].y;
- if (y < cur_->points[!upper].y)
- y = cur_->points[!upper].y;
- if (y > cur_->points[upper].y)
- y = cur_->points[upper].y;
-
- return (BYTE)(y + .5f);
-}
-bool dlg_gamma::is_adjacent(POINT p1, POINT p2)
-{
- bool neighbour = abs(p1.x - p2.x) <= 3 && abs(p1.y - p2.y) <= 3;
-
- return neighbour;
-}
-bool dlg_gamma::hit_test(int* x, int* y)
-{
- for (int i = 2; i < (int)cur_->points.size(); ++i)
- {
- POINT pt = { *x, *y };
- if (is_adjacent(pt, cur_->points[i]))
- {
- *x = cur_->points[i].x;
- *y = cur_->points[i].y;
- return true;
- }
- }
-
-
- int val = calc_value(*x), tolerant = 3;
- bool hit = false;
-
- if (abs(val - *y) < tolerant)
- {
- *y = val;
- hit = true;
- }
- else
- {
- int l = *x - tolerant,
- u = *x + tolerant;
- if (l < 0)
- l = 0;
- if (u > 255)
- u = 255;
- for (; l <= u; ++l)
- {
- val = calc_value(l);
- if (abs(val - *y) < tolerant)
- {
- hit = true;
- *x = l;
- *y = val;
- break;
- }
- }
- }
-
- return hit;
-}
-void dlg_gamma::draw_ellipse(HDC hdc, POINT center, int xl, int yl)
-{
- center.x += paint_area_.left;
- center.y = paint_area_.bottom - center.y;
-
- HRGN rgn = CreateEllipticRgn(center.x - xl, center.y - yl, center.x + xl, center.y + yl);
- HBRUSH brsh = CreateSolidBrush(RGB(255, 0, 255));
- FillRgn(hdc, rgn, brsh);
- DeleteObject(brsh);
- DeleteObject(rgn);
-}
-void dlg_gamma::draw_current_curve(HDC hdc)
-{
- MoveToEx(hdc, paint_area_.left + cur_->points[0].x, paint_area_.bottom - cur_->points[0].y, NULL);
- for (int i = 0; i < 256; ++i)
- {
- int y = calc_value(i);
- LineTo(hdc, paint_area_.left + i, paint_area_.bottom - y);
- }
-}
-
-void dlg_gamma::on_init_dlg(void)
-{
- HWND combo = get_item(IDC_SCHEME);
-
- GetWindowRect(get_item(IDC_STATIC_PAINT), &paint_area_);
- screen_2_client(&paint_area_);
- paint_area_.right = paint_area_.left + 255;
- paint_area_.bottom = paint_area_.top + 255;
- create_background();
-
- init_curve(&rgb_gray_);
- init_curve(&red_, RGB(255, 0, 0));
- init_curve(&green_, RGB(0, 255, 0));
- init_curve(&blue_, RGB(0, 0, 255));
-
- std::wstring lang(local_trans::lang_trans_between_hz936(CONST_STRING_CUSTOM));
- SendMessageW(combo, CB_ADDSTRING, 0, (LPARAM)&lang[0]);
- lang = local_trans::lang_trans_between_hz936(CONST_STRING_NEG_PHOTO) + L" (RGB)";
- SendMessageW(combo, CB_ADDSTRING, 0, (LPARAM)&lang[0]);
- lang = local_trans::lang_trans_between_hz936(CONST_STRING_COLOR_NEG_PHOTO) + L" (RGB)";
- SendMessageW(combo, CB_ADDSTRING, 0, (LPARAM)&lang[0]);
- lang = local_trans::lang_trans_between_hz936(CONST_STRING_DARKER) + L" (RGB)";
- SendMessageW(combo, CB_ADDSTRING, 0, (LPARAM)&lang[0]);
- lang = local_trans::lang_trans_between_hz936(CONST_STRING_BRIGHTER) + L" (RGB)";
- SendMessageW(combo, CB_ADDSTRING, 0, (LPARAM)&lang[0]);
- SendMessage(combo, CB_SETCURSEL, 0, 0);
-
- combo = get_item(IDC_CHANNEL);
- if (is_color_)
- {
- SendMessageW(combo, CB_ADDSTRING, 0, (LPARAM)L"RGB");
- lang = local_trans::lang_trans_between_hz936(CONST_STRING_RED);
- SendMessageW(combo, CB_ADDSTRING, 0, (LPARAM)&lang[0]);
- lang = local_trans::lang_trans_between_hz936(CONST_STRING_GREEN);
- SendMessageW(combo, CB_ADDSTRING, 0, (LPARAM)&lang[0]);
- lang = local_trans::lang_trans_between_hz936(CONST_STRING_BLUE);
- SendMessageW(combo, CB_ADDSTRING, 0, (LPARAM)&lang[0]);
- }
- else
- {
- lang = local_trans::lang_trans_between_hz936(CONST_STRING_GRAY);
- SendMessageW(combo, CB_ADDSTRING, 0, (LPARAM)&lang[0]);
- }
- SendMessage(combo, CB_SETCURSEL, 0, 0);
- cur_ = &rgb_gray_;
-
- SetDlgItemInt(hwnd(), IDC_EDIT_INPUT, 0, FALSE);
- SetDlgItemInt(hwnd(), IDC_EDIT_OUTPUT, 0, FALSE);
-}
-void dlg_gamma::on_paint(HDC hdc)
-{
- HPEN pen = CreatePen(PS_SOLID, 1, cur_->clr),
- drag = CreatePen(PS_SOLID, 1, RGB(255, 0, 255)),
- old = (HPEN)SelectObject(hdc, pen);
- HDC cdc = CreateCompatibleDC(hdc);
- HBITMAP ob = (HBITMAP)SelectObject(cdc, bkgnd_);
-
- BitBlt(hdc, paint_area_.left - 1, paint_area_.top - 1, paint_area_.right - paint_area_.left + 2, paint_area_.bottom - paint_area_.top + 2,
- cdc, 0, 0, SRCCOPY);
- SelectObject(cdc, ob);
- DeleteDC(cdc);
-
- if (show_all_)
- {
- GAMMACURVE* prev = cur_;
- HPEN now = NULL;
-
- cur_ = &red_;
- now = CreatePen(PS_SOLID, 1, cur_->clr);
- SelectObject(hdc, now);
- draw_current_curve(hdc);
-
- cur_ = &green_;
- SelectObject(hdc, old);
- DeleteObject(now);
- now = CreatePen(PS_SOLID, 1, cur_->clr);
- SelectObject(hdc, now);
- draw_current_curve(hdc);
-
- cur_ = &blue_;
- SelectObject(hdc, old);
- DeleteObject(now);
- now = CreatePen(PS_SOLID, 1, cur_->clr);
- SelectObject(hdc, now);
- draw_current_curve(hdc);
-
- SelectObject(hdc, pen);
- DeleteObject(now);
- cur_ = prev;
- }
- else
- draw_current_curve(hdc);
- SelectObject(hdc, drag);
-
- for (int i = 0; i < (int)cur_->points.size(); ++i)
- {
- draw_ellipse(hdc, cur_->points[i], 3, 3);
- }
- SelectObject(hdc, old);
-
- DeleteObject(pen);
-}
-void dlg_gamma::on_mouse_move(DWORD key, int x, int y)
-{
- POINT pt = { x, y };
-
- if (PtInRect(&paint_area_, pt))
- {
- x -= paint_area_.left;
- y = paint_area_.bottom - y;
- if (key == MK_LBUTTON && cur_->drag != -1)
- {
- if (x <= cur_->points[cur_->left].x)
- x = cur_->points[cur_->left].x + 1;
- else if (x >= cur_->points[cur_->right].x)
- x = cur_->points[cur_->right].x - 1;
- cur_->points[cur_->drag].x = x;
- cur_->points[cur_->drag].y = y;
- cur_->coefs = calc::coefs_from_points(cur_->points);
- InvalidateRect(hwnd(), NULL, FALSE);
- }
- else if (key == MK_CONTROL)
- {
- y = calc_value(x);
- pt.y = paint_area_.bottom - y;
- ClientToScreen(hwnd(), &pt);
- SetCursorPos(pt.x, pt.y);
- }
- SetDlgItemInt(hwnd(), IDC_EDIT_INPUT, x, FALSE);
- SetDlgItemInt(hwnd(), IDC_EDIT_OUTPUT, y, FALSE);
- }
-}
-void dlg_gamma::on_lbutton_down(int x, int y)
-{
- x -= paint_area_.left;
- y = paint_area_.bottom - y;
- if (hit_test(&x, &y))
- {
- if(add_drag_point(x, y) != -1)
- SetCapture(hwnd());
- }
-}
-void dlg_gamma::on_lbutton_up(int x, int y)
-{
- cur_->drag = -1;
- cur_->left = 0;
- cur_->right = 1;
- ReleaseCapture();
-}
-void dlg_gamma::on_combo_sel_changed(int id, int sel)
-{
- show_all_ = false;
- if (id == IDC_SCHEME)
- {
- if (sel == 1)
- {
- cur_ = &rgb_gray_;
- init_curve(cur_);
- cur_->points.clear();
- cur_->points.push_back({ 0, 255 });
- cur_->points.push_back({ 255, 0 });
- cur_->coefs = calc::coefs_from_points(cur_->points);
- }
- else if (sel == 2)
- {
- show_all_ = true;
- cur_ = &red_;
- init_curve(cur_, cur_->clr);
- cur_->points.clear();
- cur_->points.push_back({ 33, 255 });
- cur_->points.push_back({ 185, 0 });
- cur_->points.push_back({ 119, 127 });
- cur_->coefs = calc::coefs_from_points(cur_->points);
-
- cur_ = &green_;
- init_curve(cur_, cur_->clr);
- cur_->points.clear();
- cur_->points.push_back({ 28, 255 });
- cur_->points.push_back({ 132, 0 });
- cur_->points.push_back({ 77, 127 });
- cur_->coefs = calc::coefs_from_points(cur_->points);
-
- cur_ = &blue_;
- init_curve(cur_, cur_->clr);
- cur_->points.clear();
- cur_->points.push_back({ 25, 255 });
- cur_->points.push_back({ 108, 0 });
- cur_->points.push_back({ 60, 127 });
- cur_->coefs = calc::coefs_from_points(cur_->points);
-
- cur_ = &red_;
- }
- else if (sel == 3)
- {
- cur_ = &rgb_gray_;
- init_curve(cur_);
- cur_->points.push_back({ 130, 101 });
- cur_->coefs = calc::coefs_from_points(cur_->points);
- }
- else if (sel == 4)
- {
- cur_ = &rgb_gray_;
- init_curve(cur_);
- cur_->points.push_back({ 103, 125 });
- cur_->coefs = calc::coefs_from_points(cur_->points);
- }
- InvalidateRect(hwnd(), NULL, FALSE);
- }
- else if (id == IDC_CHANNEL)
- {
- GAMMACURVE* prev = cur_, * all[] = { &rgb_gray_, &red_, &green_, &blue_ };
-
- cur_ = all[sel];
- if (prev != cur_)
- {
- if (cur_->points.size() == 2)
- {
- COLORREF clr = cur_->clr;
-
- *cur_ = *prev;
- cur_->clr = clr;
- }
- InvalidateRect(hwnd(), NULL, FALSE);
- }
- }
-}
-
-void dlg_gamma::get_gamma(SANE_Gamma* gamma)
-{
- gamma->apply_to_back = SANE_FALSE;
- //if (cur_ == &rgb_gray_)
- {
- cur_ = &rgb_gray_;
- gamma->pt_count = (SANE_Byte)(cur_->points.size() - 2);
- // gamma->pt_count_r = gamma->pt_count_g = gamma->pt_count_b = 0;
- for (int i = 2; i < (int)cur_->points.size(); ++i)
- {
- gamma->keypoint[i - 2].x = (SANE_Byte)cur_->points[i].x;
- gamma->keypoint[i - 2].y = (SANE_Byte)cur_->points[i].y;
- }
-
- for (int i = 0; i < 256; ++i)
- gamma->table[i] = calc_value(i);
- }
- //else
- {
- // gamma->pt_count = 0;
-
- cur_ = &red_;
- gamma->pt_count_r = (SANE_Byte)(cur_->points.size() - 2);
- for (int i = 2; i < (int)cur_->points.size(); ++i)
- {
- gamma->keypoint_r[i - 2].x = (SANE_Byte)cur_->points[i].x;
- gamma->keypoint_r[i - 2].y = (SANE_Byte)cur_->points[i].y;
- }
- for (int i = 0; i < 256; ++i)
- gamma->table[i] = calc_value(i);
-
- cur_ = &green_;
- gamma->pt_count_g = (SANE_Byte)(cur_->points.size() - 2);
- for (int i = 2; i < (int)cur_->points.size(); ++i)
- {
- gamma->keypoint_g[i - 2].x = (SANE_Byte)cur_->points[i].x;
- gamma->keypoint_g[i - 2].y = (SANE_Byte)cur_->points[i].y;
- }
- for (int i = 0; i < 256; ++i)
- gamma->table[256 + i] = calc_value(i);
-
- cur_ = &blue_;
- gamma->pt_count_b = (SANE_Byte)(cur_->points.size() - 2);
- for (int i = 2; i < (int)cur_->points.size(); ++i)
- {
- gamma->keypoint_b[i - 2].x = (SANE_Byte)cur_->points[i].x;
- gamma->keypoint_b[i - 2].y = (SANE_Byte)cur_->points[i].y;
- }
- for (int i = 0; i < 256; ++i)
- gamma->table[512 + i] = calc_value(i);
- }
-}
-void dlg_gamma::set_gamma(const SANE_Gamma* gamma, bool gray)
-{
- int sel = 0;
- std::wstring text(L"");
-
- SendMessage(get_item(IDC_CHANNEL), CB_RESETCONTENT, 0, 0);
- is_color_ = !gray;
- 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);
- if (is_color_)
- {
- SendMessageW(get_item(IDC_CHANNEL), CB_ADDSTRING, 0, (LPARAM)L"RGB");
- }
- else
- {
- text = local_trans::lang_trans_between_hz936(CONST_STRING_GRAY);
- SendMessageW(get_item(IDC_CHANNEL), CB_ADDSTRING, 0, (LPARAM)&text[0]);
- }
-
- if(!gray)
- {
- is_color_ = true;
- cur_ = &red_;
- init_curve(cur_);
- for (int i = 0; i < gamma->pt_count_r; ++i)
- {
- POINT pt = { gamma->keypoint_r[i].x, gamma->keypoint_r[i].y };
- cur_->points.push_back(pt);
- }
- cur_->coefs = calc::coefs_from_points(cur_->points);
-
- cur_ = &green_;
- init_curve(cur_);
- for (int i = 0; i < gamma->pt_count_g; ++i)
- {
- POINT pt = { gamma->keypoint_g[i].x, gamma->keypoint_g[i].y };
- cur_->points.push_back(pt);
- }
- cur_->coefs = calc::coefs_from_points(cur_->points);
-
- cur_ = &blue_;
- init_curve(cur_);
- for (int i = 0; i < gamma->pt_count_b; ++i)
- {
- POINT pt = { gamma->keypoint_b[i].x, gamma->keypoint_b[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"RGB");
- text = local_trans::lang_trans_between_hz936(CONST_STRING_RED);
- SendMessageW(get_item(IDC_CHANNEL), CB_ADDSTRING, 0, (LPARAM)&text[0]);
- text = local_trans::lang_trans_between_hz936(CONST_STRING_GREEN);
- SendMessageW(get_item(IDC_CHANNEL), CB_ADDSTRING, 0, (LPARAM)&text[0]);
- text = local_trans::lang_trans_between_hz936(CONST_STRING_BLUE);
- SendMessageW(get_item(IDC_CHANNEL), CB_ADDSTRING, 0, (LPARAM)&text[0]);
- }
- 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
deleted file mode 100644
index e18ba4d..0000000
--- a/sane/DlgGamma.h
+++ /dev/null
@@ -1,58 +0,0 @@
-#pragma once
-
-#include
-#include
-
-#include "DlgPage.h"
-
-// CDlgIndicator 对话框
-
-class dlg_gamma: public dlg_base
-{
- bool is_color_;
- bool show_all_;
- RECT paint_area_;
- HBITMAP bkgnd_;
-
- typedef struct _gamma_curve
- {
- std::vector points;
- std::vector coefs;
- int drag;
- int left;
- int right;
- COLORREF clr;
- }GAMMACURVE;
- GAMMACURVE rgb_gray_;
- GAMMACURVE red_;
- GAMMACURVE green_;
- GAMMACURVE blue_;
- GAMMACURVE* cur_;
-
- BOOL handle_message(UINT msg, WPARAM wp, LPARAM lp) override;
- void handle_command(WORD code, WORD id, HANDLE ctrl);
- void layout(void);
- void create_background(void);
- void init_curve(GAMMACURVE* curv, COLORREF clr = RGB(255, 255, 255));
- int add_drag_point(int x, int y);
- BYTE calc_value(BYTE x);
- bool is_adjacent(POINT p1, POINT p2);
- bool hit_test(int* x, int* y);
- void draw_ellipse(HDC hdc, POINT center, int xl, int yl);
- void draw_current_curve(HDC hdc);
-
- void on_init_dlg(void);
- void on_paint(HDC hdc);
- void on_mouse_move(DWORD key, int x, int y);
- void on_lbutton_down(int x, int y);
- void on_lbutton_up(int x, int y);
- void on_combo_sel_changed(int id, int sel);
-
-public:
- dlg_gamma(HWND parent, bool color);
- ~dlg_gamma();
-
-public:
- void get_gamma(SANE_Gamma* gamma);
- void set_gamma(const SANE_Gamma* gamma, bool gray);
-};
diff --git a/sane/DlgIndicator.cpp b/sane/DlgIndicator.cpp
deleted file mode 100644
index 560305a..0000000
--- a/sane/DlgIndicator.cpp
+++ /dev/null
@@ -1,315 +0,0 @@
-// DlgIndicator.cpp: 实现文件
-//
-
-#include "DlgIndicator.h"
-#include "resource.h"
-#include "scanned_img.h" // for local_trans
-
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-/// dlg_choose_dev
-// CDlgIndicator 对话框
-
-
-dlg_indicator::dlg_indicator(HWND parent) : dlg_base(parent, IDD_INDICATOR)
- , papers_(0), images_(0), err_(false)
-{
- create();
- SetWindowLongW(GetDlgItem(hwnd_, IDC_STATIC_ERR), GWL_STYLE, GetWindowLong(GetDlgItem(hwnd_, IDC_STATIC_ERR), GWL_STYLE) | SS_OWNERDRAW);
-
- if (!dlg_base::is_language_pack_default_code_page())
- {
- std::wstring text(local_trans::lang_trans_between_hz936(CONST_STRING_SCANNING));
-
- SetWindowTextW(hwnd(), text.c_str());
-
- text = local_trans::lang_trans_between_hz936(CONST_STRING_PAPER);
- set_item_text(IDC_STATIC_PAPER, text.c_str());
-
- text = local_trans::lang_trans_between_hz936(CONST_STRING_IMAGE);
- set_item_text(IDC_STATIC_IMAGE, text.c_str());
-
- text = local_trans::lang_trans_between_hz936(CONST_STRING_CANCEL);
- set_item_text(IDCANCEL, text.c_str());
-
- int paper = get_width_diff_as_text_length(IDC_STATIC_PAPER),
- img = get_width_diff_as_text_length(IDC_STATIC_IMAGE),
- btn = get_width_diff_as_text_length(IDCANCEL),
- diff = paper >= img + btn ? paper : img + btn;
-
- if (diff > 0)
- {
- RECT r = { 0 };
-
- GetWindowRect(hwnd(), &r);
- r.right += diff;
- MoveWindow(hwnd(), r.left, r.top, RECT_W(r), RECT_H(r), FALSE);
-
- expand_item(IDC_STATIC_PAPER, paper, 0);
- offset_item(IDC_EDIT_PAPER, paper, 0);
-
- expand_item(IDC_STATIC_IMAGE, img, 0);
- offset_item(IDC_EDIT_IMAGE, img, 0);
-
- offset_item(IDCANCEL, diff - btn, 0);
- expand_item(IDCANCEL, btn, 0);
- }
- }
-}
-dlg_indicator::~dlg_indicator()
-{
-}
-
-
-BOOL dlg_indicator::handle_message(UINT msg, WPARAM wp, LPARAM lp)
-{
- wchar_t text[40] = { 0 };
- BOOL ret = TRUE;
-
- switch (msg)
- {
- case WM_INITDIALOG:
- swprintf_s(text, _countof(text) - 1, L"%u", papers_);
- SetDlgItemTextW(hwnd_, IDC_EDIT_IMAGE, text);
- SetDlgItemTextW(hwnd_, IDC_EDIT_PAPER, text);
- UpdateWindow(hwnd_);
- break;
- case WM_USB_PACKET_RECEIVED:
- papers_++;
- swprintf_s(text, _countof(text) - 1, L"%u", papers_);
- SetDlgItemTextW(hwnd_, IDC_EDIT_PAPER, text);
- UpdateWindow(hwnd_);
- break;
- case WM_IMAGE_RECEIVED:
- images_++;
- swprintf_s(text, _countof(text) - 1, L"%u", images_);
- SetDlgItemTextW(hwnd_, IDC_EDIT_IMAGE, text);
- UpdateWindow(hwnd_);
- break;
- case WM_COMMAND:
- handle_command(HIWORD(wp), LOWORD(wp), (HWND)lp);
- break;
- case WM_DRAWITEM:
- if (wp == IDC_STATIC_ERR)
- {
- DRAWITEMSTRUCT* ds = (DRAWITEMSTRUCT*)lp;
- wchar_t text[128] = { 0 };
- HBRUSH brsh = CreateSolidBrush(GetBkColor(ds->hDC));
-
- FillRect(ds->hDC, &ds->rcItem, brsh);
- DeleteObject(brsh);
-
- GetWindowTextW(ds->hwndItem, text, _countof(text) - 1);
- SetBkMode(ds->hDC, TRANSPARENT);
- SetTextColor(ds->hDC, err_ ? RGB(255, 0, 0) : RGB(0, 0, 0));
- TextOutW(ds->hDC, 0, 0, text, lstrlenW(text));
- }
- ret = FALSE;
- break;
- case WM_SCAN_WORKING:
- notify_ui_event(SANE_EVENT_WORKING);
- break;
- case WM_SCAN_FINISHED:
- if (lp)
- {
- std::string* str = (std::string*)wp;
- std::wstring err(local_trans::a2u(str->c_str(), CP_UTF8));
-
- SetDlgItemTextW(hwnd_, IDC_STATIC_ERR, err.c_str());
- delete str;
- }
- else
- {
- std::string* str = (std::string*)wp;
- std::wstring txt(local_trans::lang_trans_between_hz936(CONST_STRING_TOTAL_SCANNED));
-
- txt += L": " + std::to_wstring(images_);
- SetDlgItemTextW(hwnd_, IDC_STATIC_ERR, txt.c_str());
- delete str;
- SetTimer(hwnd_, 1, 3000, NULL);
- }
- SetDlgItemTextW(hwnd_, IDCANCEL, local_trans::lang_trans_between_hz936(CONST_STRING_CLOSE).c_str());
- ShowWindow(GetDlgItem(hwnd_, IDC_STATIC_PAPER), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd_, IDC_STATIC_IMAGE), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd_, IDC_EDIT_PAPER), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd_, IDC_EDIT_IMAGE), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd_, IDC_STATIC_ERR), SW_SHOW);
- SetWindowTextW(hwnd_, local_trans::lang_trans_between_hz936(CONST_STRING_SCAN_OVER).c_str());
- UpdateWindow(hwnd_);
- break;
- case WM_TIMER:
- if (wp == 1)
- {
- KillTimer(hwnd_, wp);
- notify_over(false);
- break;
- }
- default:
- ret = FALSE;
- break;
- }
-
- return ret;
-}
-void dlg_indicator::handle_command(WORD code, WORD id, HANDLE ctrl)
-{
- if (id == IDCANCEL)
- {
- notify_over(true);
- }
-}
-void dlg_indicator::notify_over(bool cancel)
-{
- notify_ui_event(cancel ? SANE_EVENT_UI_CLOSE_CANCEL : SANE_EVENT_UI_CLOSE_NORMAL);
-}
-
-HWND dlg_indicator::window(void)
-{
- return hwnd_;
-}
-HWND dlg_indicator::parent(void)
-{
- return parent_;
-}
-void dlg_indicator::notify_data_arrived(bool image)
-{
- SendMessage(hwnd_, image ? WM_IMAGE_RECEIVED : WM_USB_PACKET_RECEIVED, 0, 0); // PostMessage 存在消息合并/遗漏的现象,改用Send
-}
-void dlg_indicator::notify_scan_over(const char* msg, bool err)
-{
- std::string* mstr(new std::string(msg ? msg : ""));
-
- err_ = err;
- if (!PostMessage(hwnd_, WM_SCAN_FINISHED, (WPARAM)mstr, (LPARAM)err))
- {
- delete mstr;
- notify_over(false);
- }
-}
-void dlg_indicator::notify_working(void)
-{
- PostMessage(hwnd_, WM_SCAN_WORKING, 0, 0);
-}
-// CDlgIndicator 消息处理程序
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-/// dlg_choose_dev
-///
-dlg_choose_dev::dlg_choose_dev(HWND parent, const std::vector& devs) : dlg_base(parent, IDD_CHOOSE_DEV), item_(-1)
-{
- create();
-
- HWND lst = GetDlgItem(hwnd_, IDC_LIST1);
- LV_COLUMNW col = { 0 };
- int ind = 0;
- std::wstring text(local_trans::lang_trans_between_hz936(CONST_STRING_CHOOSE_DEVICE));
-
- SetWindowTextW(hwnd(), text.c_str());
- ListView_SetExtendedListViewStyle(lst, ListView_GetExtendedListViewStyle(lst) | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
- SetWindowLong(lst, GWL_STYLE, GetWindowLong(lst, GWL_STYLE) | LVS_SINGLESEL);
- col.mask = LVCF_TEXT | LVCF_WIDTH;
- col.cx = 180;
- text = local_trans::lang_trans_between_hz936(CONST_STRING_DEVICE_NAME);
- col.pszText = &text[0];
- SendMessageW(lst, LVM_INSERTCOLUMN, ind++, (LPARAM)&col);
- text = local_trans::lang_trans_between_hz936(CONST_STRING_SERIAL_NUM);
- col.pszText = &text[0];
- SendMessageW(lst, LVM_INSERTCOLUMN, ind++, (LPARAM)&col);
-
- ind = 0;
- for (const auto& v: devs)
- {
- std::wstring n(local_trans::a2u(v.name.c_str(), CP_UTF8)),
- s(local_trans::a2u(v.sn.c_str(), CP_UTF8));
- LV_ITEM item = { 0 };
- int ind = 0;
-
- item.mask = LVIF_TEXT;
- item.pszText = &n[0];
- item.iItem = ListView_GetItemCount(lst);
- ind = SendMessageW(lst, LVM_INSERTITEMW, 0, (LPARAM)&item);
-
- item.pszText = &s[0];
- item.iSubItem = 1;
- item.iItem = ind;
- SendMessageW(lst, LVM_SETITEMTEXTW, ind, (LPARAM)&item);
- if (ind++ == 0)
- {
- item_ = 0;
- ListView_SetItemState(lst, ind, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
- SetFocus(lst);
- }
- }
-
- text = local_trans::lang_trans_between_hz936(CONST_STRING_CANCEL);
- set_item_text(IDCANCEL, text.c_str());
-
- text = local_trans::lang_trans_between_hz936(CONST_STRING_OK);
- set_item_text(IDOK, text.c_str());
-}
-dlg_choose_dev::~dlg_choose_dev()
-{}
-
-BOOL dlg_choose_dev::handle_message(UINT msg, WPARAM wp, LPARAM lp)
-{
- wchar_t text[40] = { 0 };
- BOOL ret = TRUE;
-
- switch (msg)
- {
- case WM_COMMAND:
- handle_command(HIWORD(wp), LOWORD(wp), (HWND)lp);
- break;
- case WM_NOTIFY:
- handle_notify(wp, (LPNMHDR)lp);
- break;
- default:
- ret = FALSE;
- break;
- }
-
- return ret;
-}
-void dlg_choose_dev::handle_command(WORD code, WORD id, HANDLE ctrl)
-{
- if (id == IDOK)
- {
- HWND lst = GetDlgItem(hwnd_, IDC_LIST1);
- if (item_ >= 0 && item_ < ListView_GetItemCount(lst))
- {
- wchar_t buf[128] = { 0 };
-
- ListView_GetItemText(lst, item_, 0, buf, _countof(buf) - 1);
- sel_ = local_trans::u2a(buf, CP_UTF8);
- }
- id = IDCANCEL;
- }
-
- if (id == IDCANCEL)
- {
- abandon_hold_ = true;
- PostMessage(hwnd_, 0, 0, 0);
- }
-}
-void dlg_choose_dev::handle_notify(UINT id, LPNMHDR pnhdr)
-{
- if (pnhdr->hwndFrom == GetDlgItem(hwnd_, IDC_LIST1))
- {
- if (pnhdr->code == LVN_ITEMCHANGED)
- {
- LPNMHEADER h = (LPNMHEADER)pnhdr;
- item_ = h->iItem;
- }
- else if (pnhdr->code == NM_DBLCLK)
- {
- handle_command(0, IDOK, NULL);
- }
- }
-}
-
-std::string dlg_choose_dev::get_selected_device(void)
-{
- return sel_;
-}
\ No newline at end of file
diff --git a/sane/DlgIndicator.h b/sane/DlgIndicator.h
deleted file mode 100644
index 6c64d00..0000000
--- a/sane/DlgIndicator.h
+++ /dev/null
@@ -1,55 +0,0 @@
-#pragma once
-
-#include
-#include
-#include
false
@@ -84,6 +85,7 @@
$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration);$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\oem\huagao;$(LibraryPath)
$(SolutionDir)..\..\tmp\$(PlatformTarget)\huagao\$(Configuration)\$(ProjectName)\
$(SolutionDir)..\..\release\win\$(PlatformTarget)\OEM\huagao\
+ false
true
@@ -91,6 +93,7 @@
$(SolutionDir)..\..\tmp\$(PlatformTarget)\huagao\$(Configuration)\$(ProjectName)\
$(SolutionDir)..\..\sdk\include;$(SolutionDir)..\..\code_device\include\;$(IncludePath)
$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration);$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\oem\huagao;$(LibraryPath)
+ true
false
@@ -98,6 +101,7 @@
$(SolutionDir)..\..\tmp\$(PlatformTarget)\huagao\$(Configuration)\$(ProjectName)\
$(SolutionDir)..\..\sdk\include;$(SolutionDir)..\..\code_device\include\;$(IncludePath)
$(SolutionDir)..\..\sdk\lib\win\$(PlatformTarget)\$(Configuration);$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\oem\huagao;$(LibraryPath)
+ false
@@ -118,8 +122,10 @@
-
-
+ move /Y "$(TargetDir)$(ProjectName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+copy /y "$(TargetPath)" "C:\Windows\twain_32\HuaGoTwain"
@@ -144,8 +150,9 @@
UseLinkTimeCodeGeneration
-
-
+ move /Y "$(TargetDir)$(ProjectName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
@@ -164,8 +171,10 @@
$(ProjectDir)sane.def
-
-
+ move /Y "$(TargetDir)$(ProjectName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+copy /y "$(TargetPath)" "C:\Program Files\HuaGoScan"
@@ -189,8 +198,9 @@
UseLinkTimeCodeGeneration
-
-
+ move /Y "$(TargetDir)$(ProjectName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(ProjectName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
@@ -199,19 +209,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -226,22 +223,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/sane/sane.vcxproj.filters b/sane/sane.vcxproj.filters
index 73d0df0..febe37d 100644
--- a/sane/sane.vcxproj.filters
+++ b/sane/sane.vcxproj.filters
@@ -13,12 +13,6 @@
{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
-
- {8ae15a45-410d-4611-b852-f82b64bb1fcc}
-
-
- {5c86255e-570e-4921-9c62-c98d05edcab4}
-
@@ -36,45 +30,6 @@
源文件
-
- sane2twain
-
-
- sane2twain
-
-
- sane2twain
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
@@ -113,54 +68,9 @@
头文件
-
- sane2twain
-
-
- sane2twain
-
-
- sane2twain
-
-
- sane2twain
-
头文件
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
-
- sane2twain\UI
-
diff --git a/sane/sane_option_trans.cpp b/sane/sane_option_trans.cpp
deleted file mode 100644
index 6e723c2..0000000
--- a/sane/sane_option_trans.cpp
+++ /dev/null
@@ -1,300 +0,0 @@
-#include "sane_option_trans.h"
-#include
-#include
-
-#include "../../sdk/include/lang/app_language.h"
-
-namespace sane_opt_trans
-{
- static struct
- {
- int twain_id;
- const char* opt_val;
- }
- g_color_mode_map[] = {{COLOR_BW, OPTION_VALUE_YSMS_HB}
- , {COLOR_GRAY, OPTION_VALUE_YSMS_256JHD}
- , {COLOR_RGB, OPTION_VALUE_YSMS_24WCS}
- , {COLOR_AUTO_MATCH, OPTION_VALUE_YSMS_YSZDSB}
- },
- g_multiout_map[] = { {MULTI_OUT_NONE, "\346\227\240"}
- , {MULTI_OUT_ALL, OPTION_VALUE_DLSCLX_CS_HD_HB}
- , {MULTI_OUT_COLOR_GRAY, OPTION_VALUE_DLSCLX_CS_HD}
- , {MULTI_OUT_COLOR_BW, OPTION_VALUE_DLSCLX_CS_HB}
- , {MULTI_OUT_GRAY_BW, OPTION_VALUE_DLSCLX_HD_HB}
- },
- g_enhance_map[] = { {ENHANCE_NONE, OPTION_VALUE_HDHHBTX_CSYZQ_BCS}
- , {ENHANCE_RED, OPTION_VALUE_HDHHBTX_CSYZQ_HSZQ}
- , {ENHANCE_GREEN, OPTION_VALUE_HDHHBTX_CSYZQ_LSZQ}
- , {ENHANCE_BLUE, OPTION_VALUE_HDHHBTX_CSYZQ_LANSEZENGQIANG}
- },
- g_filter_map[] = { {FILTER_NONE, OPTION_VALUE_HDHHBTX_CSYZQ_BCS}
- , {FILTER_RED, OPTION_VALUE_HDHHBTX_CSYZQ_CHS}
- , {FILTER_GREEN, OPTION_VALUE_HDHHBTX_CSYZQ_CLS}
- , {FILTER_BLUE, OPTION_VALUE_HDHHBTX_CSYZQ_CHULANSE}
- },
- g_auto_color_map[] = { {0, OPTION_VALUE_YSMS_HB}
- , {1, OPTION_VALUE_YSMS_256JHD}
- },
- g_sharpen_map[] = { {SHARPEN_NONE, OPTION_VALUE_RHYMH_W}
- , {SHARPEN_SHARPEN, OPTION_VALUE_RHYMH_RH}
- , {SHARPEN_SHARPEN_MORE, OPTION_VALUE_RHYMH_JYBRH}
- , {SHARPEN_BLUR, OPTION_VALUE_RHYMH_MH}
- , {SHARPEN_BLUR_MORE, OPTION_VALUE_RHYMH_JYBMH}
- },
- g_paper_map[] = { {PAPER_LETTER, OPTION_VALUE_ZZCC_Letter}
- , {PAPER_LEGAL, OPTION_VALUE_ZZCC_LEGAL}
- //, {PAPER_8K, OPTION_VALUE_ZZCC_8K}
- //, {PAPER_16K, OPTION_VALUE_ZZCC_16K}
- , {PAPER_A3, OPTION_VALUE_ZZCC_A3}
- , {PAPER_A4, OPTION_VALUE_ZZCC_A4}
- , {PAPER_A5, OPTION_VALUE_ZZCC_A5}
- , {PAPER_A6, OPTION_VALUE_ZZCC_A6}
- , {PAPER_B4, OPTION_VALUE_ZZCC_B4}
- , {PAPER_B5, OPTION_VALUE_ZZCC_B5}
- , {PAPER_B6, OPTION_VALUE_ZZCC_B6}
- , {PAPER_STATEMENT, OPTION_VALUE_ZZCC_PPYSCC}
- , {PAPER_MAXSIZE, OPTION_VALUE_ZZCC_ZDSMCC}
- , {PAPER_MAXSIZE_CROP, OPTION_VALUE_ZZCC_ZDSMCCZDCQ}
- , {PAPER_DOUBLE_LETTER, OPTION_VALUE_ZZCC_DoubleLetter}
- , {PAPER_TRIPPLE, OPTION_VALUE_ZZCC_SLSJ}
- }
- ;
-#define VALUE_FROM_TWAIN(arr, val) \
- for (int i = 0; i < _countof(arr); ++i) \
- { \
- if (arr[i].twain_id == val) \
- return from_default_language(arr[i].opt_val, NULL); \
- }
-#define VALUE_TO_TWAIN(arr, val) \
- for (int i = 0; i < _countof(arr); ++i) \
- { \
- if (strcmp(from_default_language(arr[i].opt_val, NULL), val) == 0) \
- return arr[i].twain_id; \
- }
-
- const char* color_mode_from_twain(int val)
- {
- VALUE_FROM_TWAIN(g_color_mode_map, val);
-
- return OPTION_VALUE_YSMS_YSZDSB;
- }
- int color_mode_to_twain(const char* val)
- {
- VALUE_TO_TWAIN(g_color_mode_map, val);
-
- return COLOR_AUTO_MATCH;
- }
-
- const char* multiout_value_from_twain(int val)
- {
- VALUE_FROM_TWAIN(g_multiout_map, val);
-
- return NULL;
- }
- int multiout_value_to_twain(const char* val)
- {
- VALUE_TO_TWAIN(g_multiout_map, val);
-
- return -1;
- }
-
- const char* filter_enhance_value_from_twain(int val, bool filter)
- {
- if (filter)
- {
- for (int i = 0; i < _countof(g_filter_map); ++i)
- {
- if (g_filter_map[i].twain_id == val)
- return from_default_language(g_filter_map[i].opt_val, NULL);
- }
- }
- else
- {
- for (int i = 0; i < _countof(g_enhance_map); ++i)
- {
- if (g_enhance_map[i].twain_id == val)
- return from_default_language(g_enhance_map[i].opt_val, NULL);
- }
- }
-
- return from_default_language(OPTION_VALUE_HDHHBTX_CSYZQ_BCS, NULL);
- }
- int filter_enhance_value_to_twain(const char* val, bool* is_filter)
- {
- bool type = false;
- const char* hz = to_default_language(val, NULL);
-
- if (!is_filter)
- is_filter = &type;
-
- *is_filter = true;
- for (int i = 0; i < _countof(g_filter_map); ++i)
- {
- if (strcmp(g_filter_map[i].opt_val, hz) == 0)
- return g_filter_map[i].twain_id;
- }
- *is_filter = false;
- for (int i = 0; i < _countof(g_enhance_map); ++i)
- {
- if (strcmp(g_enhance_map[i].opt_val, hz) == 0)
- return g_enhance_map[i].twain_id;
- }
-
- return ENHANCE_NONE;
- }
-
- const char* text_direction_from_twain(float val)
- {
- while (val < .0f)
- val += 360.0f;
- while (val > 360.0f)
- val -= 360.0f;
-
- if (60.0f < val && val < 120.0f)
- return from_default_language(OPTION_VALUE_WGFX_90, NULL);
- else if (150.0f < val && val < 210.0f)
- return from_default_language(OPTION_VALUE_WGFX_180, NULL);
- else if (240.0f < val && val < 300.0f)
- return from_default_language(OPTION_VALUE_WGFX__90, NULL);
- else if (330.0f < val || val < 30.0f)
- return from_default_language(OPTION_VALUE_WGFX_0, NULL);
- else
- return from_default_language(OPTION_VALUE_WGFX_ZDWBFXSB, NULL);
- }
- float text_direction_to_twain(const char* val)
- {
- const char* hz = to_default_language(val, NULL);
- if (strcmp(hz, OPTION_VALUE_WGFX_90) == 0)
- return 90.0f;
- else if (strcmp(hz, OPTION_VALUE_WGFX_180) == 0)
- return 180.0f;
- else if (strcmp(hz, OPTION_VALUE_WGFX__90) == 0)
- return 270.0f;
- else if (strcmp(hz, OPTION_VALUE_WGFX_0) == 0)
- return .0f;
- else
- return AUTO_MATIC_ROTATE;
- }
-
- struct
- {
- const char* normal;
- const char* lateral;
- }g_lateral_map[] =
- { {OPTION_VALUE_ZZCC_A4, OPTION_VALUE_ZZCC_A4HX}
- , {OPTION_VALUE_ZZCC_16K, OPTION_VALUE_ZZCC_16KHX}
- , {OPTION_VALUE_ZZCC_A5, OPTION_VALUE_ZZCC_A5HX}
- , {OPTION_VALUE_ZZCC_A6, OPTION_VALUE_ZZCC_A6HX}
- , {OPTION_VALUE_ZZCC_B5, OPTION_VALUE_ZZCC_B5HX}
- , {OPTION_VALUE_ZZCC_B6, OPTION_VALUE_ZZCC_B6HX}
- , {OPTION_VALUE_ZZCC_Letter, OPTION_VALUE_ZZCC_LetterHX}
- };
-
- const char* paper_from_twain(int val)
- {
- VALUE_FROM_TWAIN(g_paper_map, val);
-
- return NULL;
- }
- int paper_to_twain(const char* val)
- {
- VALUE_TO_TWAIN(g_paper_map, val);
-
- return -1;
- }
- const char* switch_paper_lateral(const char* val)
- {
- const char* hz = to_default_language(val, NULL);
- for (int i = 0; i < _countof(g_lateral_map); ++i)
- {
- if (strcmp(g_lateral_map[i].normal, hz) == 0)
- return from_default_language(g_lateral_map[i].lateral, NULL);
- else if (strcmp(g_lateral_map[i].lateral, hz) == 0)
- return from_default_language(g_lateral_map[i].normal, NULL);
- }
-
- return NULL;
- }
- bool is_paper_lateral(const char* val)
- {
- const char* hz = to_default_language(val, NULL);
- for (int i = 0; i < _countof(g_lateral_map); ++i)
- {
- if (strcmp(g_lateral_map[i].lateral, hz) == 0)
- return true;
- }
-
- return false;
- }
-
- const char* auto_color_type_from_twain(int val)
- {
- VALUE_FROM_TWAIN(g_color_mode_map, val);
-
- return from_default_language(OPTION_VALUE_YSMS_24WCS, NULL);
- }
- int auto_color_type_to_twain(const char* val)
- {
- VALUE_TO_TWAIN(g_color_mode_map, val);
-
- return -1;
- }
-
- const char* sharpen_from_twain(int val)
- {
- VALUE_FROM_TWAIN(g_sharpen_map, val);
-
- return from_default_language(OPTION_VALUE_RHYMH_W, NULL);
- }
- int sharpen_to_twain(const char* val)
- {
- VALUE_TO_TWAIN(g_sharpen_map, val);
-
- return SHARPEN_NONE;
- }
-
- struct {
- int twain;
- int sane;
- }
- g_compression_map[] = { {0, SANE_COMPRESSION_NONE}
- , {5, SANE_COMPRESSION_GROUP4}
- }
- ;
-#define INT_FROM_TWAIN(arr, val) \
- for (int i = 0; i < _countof(arr); ++i) \
- { \
- if (arr[i].twain == val) \
- return arr[i].sane; \
- }
-#define INT_TO_TWAIN(arr, val) \
- for (int i = 0; i < _countof(arr); ++i) \
- { \
- if (arr[i].sane == val) \
- return arr[i].twain; \
- }
-
- int compression_from_twain(int val)
- {
- INT_FROM_TWAIN(g_compression_map, val);
-
- return SANE_COMPRESSION_NONE;
- }
- int compression_to_twain(int val)
- {
- INT_TO_TWAIN(g_compression_map, val);
-
- return 0;
- }
- std::vector support_image_types(void)
- {
- std::vector it;
-
- it.push_back(SANE_IMAGE_TYPE_BMP);
- it.push_back(SANE_IMAGE_TYPE_TIFF);
- it.push_back(SANE_IMAGE_TYPE_JFIF);
-
- return it;
- }
-}
-
diff --git a/sane/sane_option_trans.h b/sane/sane_option_trans.h
deleted file mode 100644
index 72dbac2..0000000
--- a/sane/sane_option_trans.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// utilities for transfroming options between TWAIN and sane ...
-//
-// Date: 2022-04-14
-//
-
-#pragma once
-
-#include "s2t_api.h"
-
-namespace sane_opt_trans
-{
- const char* color_mode_from_twain(int val);
- int color_mode_to_twain(const char* val);
-
- const char* multiout_value_from_twain(int val);
- int multiout_value_to_twain(const char* val);
-
- const char* filter_enhance_value_from_twain(int val, bool filter);
- int filter_enhance_value_to_twain(const char* val, bool* is_filter);
-
- const char* text_direction_from_twain(float val);
- float text_direction_to_twain(const char* val);
-
- const char* paper_from_twain(int val);
- int paper_to_twain(const char* val);
-
- const char* switch_paper_lateral(const char* val);
- bool is_paper_lateral(const char* val);
-
- const char* auto_color_type_from_twain(int val);
- int auto_color_type_to_twain(const char* val);
-
- const char* sharpen_from_twain(int val);
- int sharpen_to_twain(const char* val);
-
- int compression_from_twain(int val);
- int compression_to_twain(int val);
-
- std::vector support_image_types(void);
-}
-
diff --git a/sane/scanned_img.cpp b/sane/scanned_img.cpp
deleted file mode 100644
index e46c3f3..0000000
--- a/sane/scanned_img.cpp
+++ /dev/null
@@ -1,795 +0,0 @@
-#include "scanned_img.h"
-
-#include
-#include
-#pragma comment(lib, "Shlwapi.lib")
-
-#include "../../code_device/hgsane/sane_hg_mdw.h"
-#include "../../sdk/include/lang/app_language.h"
-
-
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//
-namespace local_trans
-{
- std::string u2a(const wchar_t* u, UINT cp)
- {
- std::string a("");
-
- if (u)
- {
- char * ansi = NULL;
- int len = 0;
-
- len = WideCharToMultiByte(cp, 0, u, lstrlenW(u), NULL, 0, NULL, NULL);
- ansi = new char[len + 2];
- len = WideCharToMultiByte(cp, 0, u, lstrlenW(u), ansi, len, NULL, NULL);
- ansi[len--] = 0;
- a = ansi;
- delete[] ansi;
- }
-
- return std::move(a);
- }
- std::wstring a2u(const char* asc, UINT cp)
- {
- std::wstring u(L"");
-
- if (asc)
- {
- wchar_t *buf = NULL;
- int len = 0;
-
- len = MultiByteToWideChar(cp, 0, asc, lstrlenA(asc), NULL, 0);
- buf = new wchar_t[len + 2];
- len = MultiByteToWideChar(cp, 0, asc, lstrlenA(asc), buf, len);
- buf[len--] = 0;
- u = buf;
- delete[] buf;
- }
-
- return std::move(u);
- }
-
- std::wstring lang_trans_between_hz936(const wchar_t* in, bool from_hz)
- {
- std::string a(u2a(in, CP_UTF8));
-
- if (from_hz)
- a = from_default_language(a.c_str(), nullptr);
- else
- a = to_default_language(a.c_str(), nullptr);
-
- return std::move(a2u(a.c_str(), CP_UTF8));
- }
- const char* __stdcall lang_trans_between_hz936(const char* in, bool from_hz, void* param)
- {
- return from_hz ? from_default_language(in, nullptr) : to_default_language(in, nullptr);
- }
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// class refer
-refer::refer() : ref_(1)
-{}
-refer::~refer()
-{}
-
-COM_API_IMPLEMENT(refer, long, add_ref(void))
-{
- return InterlockedIncrement(&ref_);
-}
-COM_API_IMPLEMENT(refer, long, release(void))
-{
- long ref = InterlockedDecrement(&ref_);
-
- if (ref == 0)
- delete this;
-
- return ref;
-}
-
-
-
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// class mapping_buf
-const unsigned int max_mem_block = 2 * 1024 * 1024;
-extern void __stdcall log_info(const wchar_t* info, int level);
-
-mapping_buf::mapping_buf() : bytes_(0), offset_(0), mapped_bytes_(0), map_(NULL), buf_(NULL), file_(""), rmv_file_(true), page_size_(0), is_mem_(false)
-{
- SYSTEM_INFO si = { 0 };
-
- GetSystemInfo(&si);
- page_size_ = si.dwPageSize;
- map_unit_ = si.dwAllocationGranularity;
-}
-mapping_buf::~mapping_buf()
-{
- close();
-}
-
-void mapping_buf::init_map(const char* file, unsigned long long size)
-{
- HANDLE f = INVALID_HANDLE_VALUE;
-
- if (size)
- {
- f = CreateFileA(file, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
- if (f != INVALID_HANDLE_VALUE)
- {
- unsigned long long total = size - 1;
- LONG* p32 = (LONG*)&total;
- *p32 = SetFilePointer(f, *p32, p32 + 1, FILE_BEGIN);
- total++;
- if (total == size)
- {
- DWORD wrote = 1;
- WriteFile(f, "\0", 1, &wrote, NULL);
- map_ = CreateFileMapping(f, NULL, PAGE_READWRITE, p32[1], p32[0], NULL);
- }
- CloseHandle(f);
- if (!map_)
- DeleteFileA(file);
- }
-
- {
- std::wstring info(local_trans::a2u(file));
- wchar_t buf[80] = { 0 };
-
- swprintf_s(buf, _countof(buf) - 1, L"Mapping %u bytes to file: ", size);
- log_info((buf + info + L"\r\n").c_str(), 0);
- }
- }
- else
- {
- f = CreateFileA(file, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if (f != INVALID_HANDLE_VALUE)
- {
- DWORD* p32 = (DWORD*)&size;
- *p32 = GetFileSize(f, p32 + 1);
- map_ = CreateFileMapping(f, NULL, PAGE_READWRITE, p32[1], p32[0], NULL);
- CloseHandle(f);
- }
- }
-
- if (map_)
- {
- bytes_ = size;
- file_ = file;
- buffer(0, NULL);
- if (!map_)
- close();
- }
-}
-void mapping_buf::close(void)
-{
- if (buf_)
- {
- if (is_mem_)
- delete[] buf_;
- else
- UnmapViewOfFile(buf_);
- }
- buf_ = NULL;
- if (map_)
- CloseHandle(map_);
- map_ = NULL;
- if (rmv_file_ && file_.length())
- DeleteFileA(file_.c_str());
- file_ = "";
- bytes_ = offset_ = 0;
- mapped_bytes_ = 0;
- rmv_file_ = true;
- is_mem_ = false;
-}
-void mapping_buf::map(void)
-{
- DWORD* off = (DWORD*)&offset_;
-
- buf_ = (unsigned char*)MapViewOfFile(map_, FILE_MAP_READ | FILE_MAP_WRITE, off[1], off[0], mapped_bytes_);
- if (!buf_)
- {
- DWORD err = GetLastError();
- mapped_bytes_ /= map_unit_;
- mapped_bytes_ *= map_unit_;
- while (mapped_bytes_ > map_unit_)
- {
- buf_ = (unsigned char*)MapViewOfFile(map_, FILE_MAP_READ | FILE_MAP_WRITE, off[1], off[0], mapped_bytes_);
- if (buf_)
- break;
- mapped_bytes_ /= 2;
- }
- if (!buf_)
- mapped_bytes_ = 0;
- }
-}
-void mapping_buf::set_buffer(unsigned char*& buf, unsigned long long off, unsigned int* bytes)
-{
- buf = buf_ + (off - offset_);
- if (bytes)
- *bytes = mapped_bytes_ - (unsigned int)(off - offset_);
-}
-
-unsigned char* mapping_buf::allocate(const wchar_t* file, unsigned long long size, bool force_file)
-{
- close();
-
- std::string ansi(local_trans::u2a(file));
- if (force_file || size >= 100 * 1024 * 1024 || PathFileExistsW(file))
- {
- init_map(ansi.c_str(), size);
- }
- else
- {
- try
- {
- buf_ = new unsigned char[(unsigned int)size];
- is_mem_ = true;
- bytes_ = size;
- mapped_bytes_ = (unsigned int)size;
- }
- catch (...)
- {
- is_mem_ = false;
- init_map(ansi.c_str(), size);
- }
- }
-
- return buf_;
-}
-unsigned char* mapping_buf::buffer(unsigned long long off, unsigned int* bytes)
-{
- unsigned int size = bytes ? *bytes : 1 * 1024 * 1024 * 1024;
- unsigned char* buf = NULL;
-
- if (size > bytes_ - offset_)
- size = (unsigned int)(bytes_ - offset_);
-
- if (buf_ && off >= offset_ && size + (off - offset_) <= mapped_bytes_)
- {
- set_buffer(buf, off, bytes);
- }
- else if (!is_mem_)
- {
- if (off < bytes_)
- {
- if (buf_)
- UnmapViewOfFile(buf_);
-
- offset_ = off / map_unit_ * map_unit_;
- mapped_bytes_ = (unsigned int)(bytes_ - offset_);
- map();
- if (buf_)
- set_buffer(buf, off, bytes);
- }
- }
-
- return buf;
-}
-bool mapping_buf::save(const void* data, size_t* bytes, unsigned long long off)
-{
- unsigned int len = *bytes, total = 0;
- unsigned char* buf = buffer(off, &len);
- bool ret = false;
- const char* src = (const char*)data;
-
- while (buf)
- {
- if (len >= *bytes - total)
- {
- memcpy(buf, src, *bytes - total);
- total = *bytes;
- ret = true;
- break;
- }
- memcpy(buf, src, len);
- total += len;
- off += len;
- src += len;
- len = *bytes - total;
- buf = buffer(off, &len);
- }
- *bytes = total;
-
- return ret;
-}
-bool mapping_buf::save(unsigned long long off, mapping_buf* mbuf, unsigned long long src_off)
-{
- size_t len = (unsigned int)(mbuf->bytes() - src_off);
- unsigned char* buf = mbuf->buffer(src_off, (unsigned int*)&len);
- bool ret = false;
-
- while (buf && save(buf, &len, off))
- {
- off += len;
- src_off += len;
- if (src_off >= mbuf->bytes())
- {
- ret = true;
- break;
- }
- len = (unsigned int)(mbuf->bytes() - src_off);
- buf = mbuf->buffer(src_off, (unsigned int*)&len);
- }
-
- return ret;
-}
-int mapping_buf::read(void* buf, size_t* bytes, unsigned long long off)
-{
- if (!bytes)
- return SCANNER_ERR_INVALID_PARAMETER;
-
- unsigned int len = *bytes, total = 0;
- unsigned char *src = buffer(off, &len),
- *dst = (unsigned char*)buf;
- int ret = SCANNER_ERR_OUT_OF_RANGE;
-
- while (src)
- {
- if (len >= *bytes - total)
- {
- memcpy(dst, src, *bytes - total);
- total = *bytes;
- ret = SCANNER_ERR_OK;
- break;
- }
-
- memcpy(dst, src, len);
- total += len;
- off += len;
- len = *bytes - total;
- src = buffer(off, &len);
- }
- *bytes = total;
-
- return ret;
-}
-void mapping_buf::unmap()
-{
- if (!is_mem_)
- {
- if (buf_)
- UnmapViewOfFile(buf_);
- buf_ = NULL;
- offset_ = 0;
- mapped_bytes_ = 0;
- }
-}
-void mapping_buf::set_remove_file_when_destroyed(bool rmv)
-{
- rmv_file_ = rmv;
-}
-const char* mapping_buf::file(void)
-{
- return is_mem_ ? "" : file_.c_str();
-}
-unsigned long long mapping_buf::bytes(void)
-{
- return bytes_;
-}
-unsigned long long mapping_buf::offset(void)
-{
- return offset_;
-}
-unsigned int mapping_buf::mapped_bytes(void)
-{
- return mapped_bytes_;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// class scanned_img
-scanned_img::scanned_img(SANE_Handle dev, SANE_Parameters head, int dpi
- , const wchar_t* tmp_file, twain_xfer xfer
- , SANE_FinalImgFormat *fmt) : head_(head), dpi_(dpi), header_size_(0), file_(tmp_file ? tmp_file : L"")
- , dev_(dev), status_(SANE_Image_Statu_OK)
-{
- if (fmt)
- fmt_ = *fmt;
- else
- {
- fmt_.img_format = SANE_IMAGE_TYPE_BMP;
- fmt_.detail = 0;
- }
-
- size_t bytes = line_bytes() * height();
- std::string h(file_header(fmt_.img_format, (float)dpi, xfer));
- unsigned char* dst = NULL;
- bool ok = false;
-
- data_ = new mapping_buf();
- header_size_ = h.length();
- dst = data_->allocate(tmp_file, bytes + h.length());
- if (dst)
- {
- unsigned long long off = 0, total = 0;
- bytes = h.length();
- if (data_->save(h.c_str(), &bytes, off))
- {
- unsigned int len = line_bytes();
- unsigned long long line = line_bytes();
-
- if (xfer == TWAIN_XFER_Memory)
- line *= -1;
- else
- off = data_->bytes() - line;
- dst = data_->buffer(off, &len);
-
- int want_to_read = head_.bytes_per_line, rcv = 0, dif = line_bytes() - head_.bytes_per_line;
- while (dst)
- {
- int r = want_to_read > (int)(len) - rcv ? (int)(len)- rcv : want_to_read;
- int ret = hg_sane_middleware::instance()->read(dev, dst + rcv, &r);
- total += r;
- if (ret != SANE_STATUS_GOOD)
- break;
-
- want_to_read -= r;
- rcv += r;
- if (want_to_read == 0)
- {
- want_to_read = head_.bytes_per_line;
- off -= line;
- len = line_bytes();
- rcv = 0;
- dst = data_->buffer(off, &len);
- total += dif;
- }
- else
- {
- len = want_to_read;
- dst = data_->buffer(off + rcv, &len);
- }
- }
- ok = total + h.length() + dif == data_->bytes();
- }
- }
- do_result(ok, xfer);
-}
-scanned_img::scanned_img(SANE_Handle dev, SANE_Parameters head, void* data, unsigned int len, int dpi, const wchar_t* tmp_file
- , twain_xfer xfer, SANE_FinalImgFormat* fmt) : head_(head), dpi_(dpi), header_size_(0)
- , file_(tmp_file ? tmp_file : L""), dev_(dev), status_(SANE_Image_Statu_OK)
-{
- if (fmt)
- fmt_ = *fmt;
- else
- {
- fmt_.img_format = SANE_IMAGE_TYPE_BMP;
- fmt_.detail = 0;
- }
-
- size_t bytes = line_bytes() * head.lines;
- std::string h(file_header(fmt_.img_format, (float)dpi, xfer));
- unsigned char* dst = NULL, *src = (unsigned char*)data;
- bool ok = false;
-
- header_size_ = h.length();
- data_ = new mapping_buf();
- bytes += header_size_;
- dst = data_->allocate(tmp_file, bytes);
- bytes = h.length();
- if (dst && data_->save(h.c_str(), &bytes, 0))
- {
- unsigned long long off = bytes, line_l = line_bytes();
- unsigned int buf_len = line_bytes(), row = 0;
- if (xfer == TWAIN_XFER_Memory)
- line_l *= -1;
- else
- off = data_->bytes() - line_l;
- for (; row < (unsigned int)head.lines; ++row)
- {
- bytes = head.bytes_per_line;
- if (!data_->save(src, &bytes, off))
- break;
- off -= line_l;
- src += head.bytes_per_line;
- }
- ok = row == head.lines;
- }
- do_result(ok, xfer);
-}
-scanned_img::~scanned_img()
-{
- if (data_)
- delete data_;
-}
-
-void scanned_img::set_image_status(SANE_Image_Statu status)
-{
- status_ = status;
-}
-
-std::string scanned_img::file_header(SANE_ImageType type, float resolution, twain_xfer xfer)
-{
- std::string h("");
-
- if (type == SANE_IMAGE_TYPE_BMP && xfer != TWAIN_XFER_Memory)
- {
- BITMAPINFOHEADER bih = { 0 };
- int pal_size = 0;
-
- bih.biSize = sizeof(bih);
- bih.biWidth = width();
- bih.biBitCount = depth();
- bih.biSizeImage = line_bytes() * height();
- bih.biPlanes = 1;
- bih.biHeight = height();
- bih.biCompression = BI_RGB;
- bih.biXPelsPerMeter = bih.biYPelsPerMeter = (LONG)(resolution * 39.37f + .5f);
-
- if (bih.biBitCount == 1)
- pal_size = 2 * sizeof(int);
- else if (bih.biBitCount == 8)
- pal_size = 256 * sizeof(int);
-
- if (xfer == TWAIN_XFER_File)
- {
- BITMAPFILEHEADER fh = { 0 };
- fh.bfType = MAKEWORD('B', 'M');
- fh.bfSize = sizeof(fh) + bih.biSizeImage + sizeof(bih) + pal_size;
- fh.bfOffBits = sizeof(fh) + sizeof(bih) + pal_size;
-
- h = std::string((char*)&fh, sizeof(fh));
- }
-
- h += std::string((char*)&bih, sizeof(bih));
- if (bih.biBitCount == 1)
- {
- int pal[] = { 0, 0x0ffffff };
- h += std::string((char*)pal, pal_size);
- }
- else if (bih.biBitCount == 8)
- {
- static unsigned int g_bmp8_pallete[256] = { 0 };
- if (g_bmp8_pallete[1] == 0)
- {
- for (int i = 1; i < _countof(g_bmp8_pallete); ++i)
- g_bmp8_pallete[i] = MAKELONG(MAKEWORD(i, i), MAKEWORD(i, 0));
- }
- h += std::string((char*)g_bmp8_pallete, pal_size);
- }
- }
-
- return h;
-}
-void scanned_img::do_result(bool ok, twain_xfer xfer)
-{
- if (ok)
- {
- if (fmt_.img_format == SANE_IMAGE_TYPE_BMP &&
- fmt_.compress.compression == SANE_COMPRESSION_GROUP4 &&
- xfer == TWAIN_XFER_Memory)
- {
- // convert to black-white ...
- std::string head(file_header(SANE_IMAGE_TYPE_BMP, (float)dpi_, TWAIN_XFER_File));
- size_t size = head.length();
- mapping_buf* buf = new mapping_buf();
- std::wstring file(file_ + L".tmp");
- unsigned long long off = 0;
-
- if (buf->allocate(file.c_str(), size + data_->bytes(), true) &&
- buf->save(head.c_str(), &size, off))
- {
- if (buf->save(size, data_))
- {
- SANE_ImageFormatConvert conv;
- std::string sf(local_trans::u2a(file.c_str()));
-
- buf->unmap();
- conv.src.data = sf.c_str();
- conv.src.data_len = sf.length();
- conv.src.fmt.img_format = SANE_IMAGE_TYPE_BMP;
- conv.src.fmt.compress.compression = SANE_COMPRESSION_NONE;
- conv.src.is_file = SANE_TRUE;
-
- conv.dst.data = NULL;
- conv.dst.data_len = 0;
- conv.dst.fmt.img_format = SANE_IMAGE_TYPE_BMP;
- conv.dst.fmt.compress.compression = SANE_COMPRESSION_GROUP4;
- conv.dst.fmt.compress.detail = NULL;
- conv.dst.is_file = false;
- if (hg_sane_middleware::instance()->io_control(dev_, IO_CTRL_CODE_CONVERT_IMAGE_FORMAT, &conv, NULL) == SANE_STATUS_GOOD)
- {
- delete data_;
- data_ = new mapping_buf();
- size = conv.dst.data_len;
- data_->allocate(file_.c_str(), conv.dst.data_len);
- data_->save(conv.dst.data, &size, 0);
- hg_sane_middleware::instance()->io_control(dev_, IO_CTRL_CODE_FREE_MEMORY, (void*)conv.dst.data, &conv.dst.data_len);
- head_.format = SANE_FRAME_GRAY;
- head_.depth = 1;
- head_.bytes_per_line = (head_.pixels_per_line + 7) / 8;
- }
- }
- }
- if (buf)
- delete buf;
- }
- else if (fmt_.img_format == SANE_IMAGE_TYPE_BMP
- && channel() == 3
- && xfer != TWAIN_XFER_Memory)
- {
- // swap RGB
- swap_rgb();
- }
- data_->unmap();
- }
- else
- {
- delete data_;
- data_ = NULL;
- header_size_ = 0;
- }
-}
-void scanned_img::swap_rgb(void)
-{
- unsigned long long off = 0;
- unsigned int line = line_bytes(), len = line;
- unsigned char* dst = NULL;
-
- for (int i = 0; i < height(); ++i)
- {
- int l = head_.bytes_per_line, cur = 0;
-
- off = i * line + header_size_;
- while (l > 0)
- {
- len = l;
- dst = data_->buffer(off + cur, &len);
- if (!dst)
- break;
- if (len > (unsigned int)l)
- len = l;
- len /= 3;
- for (int pos = 0; pos < (int)len; ++pos)
- {
- unsigned char uc = dst[pos * 3 + 0];
- dst[pos * 3 + 0] = dst[pos * 3 + 2];
- dst[pos * 3 + 2] = uc;
- }
- l -= len * 3;
- cur += len * 3;
- }
- if (!dst)
- break;
- }
-}
-
-// IRef
-COM_API_IMPLEMENT(scanned_img, long, add_ref(void))
-{
- return refer::add_ref();
-}
-COM_API_IMPLEMENT(scanned_img, long, release(void))
-{
- return refer::release();
-}
-
-// IScanImg
-COM_API_IMPLEMENT(scanned_img, int, width(void))
-{
- return head_.pixels_per_line;
-}
-COM_API_IMPLEMENT(scanned_img, int, line_bytes(void))
-{
- if (fmt_.img_format == SANE_IMAGE_TYPE_BMP && head_.depth >= 8)
- return (head_.bytes_per_line + 3) / 4 * 4;
- else
- return head_.bytes_per_line;
-}
-COM_API_IMPLEMENT(scanned_img, int, height(void))
-{
- return head_.lines;
-}
-COM_API_IMPLEMENT(scanned_img, int, depth(void))
-{
- if (head_.format == SANE_FRAME_RGB)
- return head_.depth * 3;
- else
- return head_.depth;
-
-}
-COM_API_IMPLEMENT(scanned_img, int, channel(void))
-{
- return head_.format == SANE_FRAME_RGB ? 3 : 1;
-}
-COM_API_IMPLEMENT(scanned_img, int, dpi(void))
-{
- return dpi_;
-}
-COM_API_IMPLEMENT(scanned_img, SANE_Frame, type(void))
-{
- return head_.format;
-}
-COM_API_IMPLEMENT(scanned_img, unsigned int, bytes(void))
-{
- return data_ ? (unsigned int)data_->bytes() : 0;
-}
-COM_API_IMPLEMENT(scanned_img, unsigned int, header_size(void))
-{
- return header_size_;
-}
-COM_API_IMPLEMENT(scanned_img, unsigned char*, data(unsigned long long off, unsigned int* bytes))
-{
- return data_ ? data_->buffer(off, bytes) : NULL;
-}
-COM_API_IMPLEMENT(scanned_img, int, read(void* buf, size_t* bytes, unsigned long long off))
-{
- return data_ ? data_->read(buf, bytes, off) : SCANNER_ERR_NO_DATA;
-}
-
-COM_API_IMPLEMENT(scanned_img, const char*, file(void))
-{
- if (data_)
- return data_->file();
- else
- return "";
-}
-COM_API_IMPLEMENT(scanned_img, void, keep_file(bool keep))
-{
- if (data_)
- data_->set_remove_file_when_destroyed(!keep);
-}
-COM_API_IMPLEMENT(scanned_img, void, copy_header(SANE_Parameters* head))
-{
- *head = head_;
-}
-COM_API_IMPLEMENT(scanned_img, int, image_status(void))
-{
- return status_;
-}
-
-
-
-
-
-
-
-
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// class safe_img_queue
-safe_img_queue::safe_img_queue()
-{}
-safe_img_queue::~safe_img_queue()
-{
- clear();
-}
-
-void __stdcall safe_img_queue::access_image(scanned_img* img)
-{
- img->add_ref();
-}
-void __stdcall safe_img_queue::free_image(scanned_img* img)
-{
- img->release();
-}
-
-bool safe_img_queue::get_header(SANE_Parameters* header, size_t* bytes, int* dpi)
-{
- scanned_img *img = take(false, &safe_img_queue::access_image);
- bool ok = false;
-
- if (bytes)
- *bytes = 0;
- if (img)
- {
- if(header)
- img->copy_header(header);
- if(bytes)
- *bytes = img->bytes();
- if (dpi)
- *dpi = img->dpi();
- ok = true;
- img->release();
- }
-
- return ok;
-}
-void safe_img_queue::clear()
-{
- safe_queue::clear(&safe_img_queue::free_image);
-}
-
diff --git a/sane/scanned_img.h b/sane/scanned_img.h
deleted file mode 100644
index 4beb9bd..0000000
--- a/sane/scanned_img.h
+++ /dev/null
@@ -1,201 +0,0 @@
-#pragma once
-#include "s2t_api.h"
-#include
-#include
-
-class refer : public IRef
-{
- volatile long ref_;
-
-protected:
- refer();
- virtual ~refer();
-
- // IRef
-public:
- COM_API_OVERRIDE(long, add_ref(void));
- COM_API_OVERRIDE(long, release(void));
-};
-
-class mapping_buf
-{
- unsigned long long bytes_;
- unsigned long long offset_;
- unsigned int page_size_;
- unsigned int map_unit_;
- unsigned int mapped_bytes_;
- HANDLE map_;
- bool is_mem_;
- unsigned char* buf_;
- std::string file_;
- bool rmv_file_;
-
- void init_map(const char* file, unsigned long long size);
- void close(void);
- void map(void);
- void set_buffer(unsigned char*& buf, unsigned long long off, unsigned int* bytes);
-
-public:
- mapping_buf();
- ~mapping_buf();
-
-public:
- unsigned char* allocate(const wchar_t* file, unsigned long long size = 0, bool force_file = false);
- unsigned char* buffer(unsigned long long off, unsigned int* bytes);
- bool save(const void* data, size_t* bytes, unsigned long long off);
- bool save(unsigned long long off, mapping_buf* mbuf, unsigned long long src_off = 0);
- int read(void* buf, size_t* bytes, unsigned long long off);
- void unmap();
- void set_remove_file_when_destroyed(bool rmv);
- const char* file(void);
- unsigned long long bytes(void);
- unsigned long long offset(void);
- unsigned int mapped_bytes(void);
-};
-class scanned_img : public IScanImg, virtual public refer
-{
- SANE_Parameters head_;
- mapping_buf* data_;
- int dpi_;
- SANE_Handle dev_;
- std::wstring file_;
- unsigned int header_size_;
- SANE_FinalImgFormat fmt_;
-
- SANE_Image_Statu status_;
-
- std::string file_header(SANE_ImageType type, float resolution, twain_xfer xfer);
- void do_result(bool ok, twain_xfer xfer);
- void swap_rgb(void);
-
-public:
- scanned_img(SANE_Handle dev, SANE_Parameters head, int dpi, const wchar_t* tmp_file
- , twain_xfer xfer = TWAIN_XFER_Native, SANE_FinalImgFormat *fmt = NULL);
- scanned_img(SANE_Handle dev, SANE_Parameters head, void* data, unsigned int len, int dpi, const wchar_t* tmp_file
- , twain_xfer xfer = TWAIN_XFER_Native, SANE_FinalImgFormat *fmt = NULL);
-
- void set_image_status(SANE_Image_Statu status);
-
-protected:
- ~scanned_img();
-
- // IRef
-public:
- COM_API_OVERRIDE(long, add_ref(void));
- COM_API_OVERRIDE(long, release(void));
-
- // IScanImg
-public:
- COM_API_OVERRIDE(int, width(void));
- COM_API_OVERRIDE(int, line_bytes(void));
- COM_API_OVERRIDE(int, height(void));
- COM_API_OVERRIDE(int, depth(void));
- COM_API_OVERRIDE(int, channel(void));
- COM_API_OVERRIDE(int, dpi(void));
- COM_API_OVERRIDE(SANE_Frame, type(void));
- COM_API_OVERRIDE(unsigned int, bytes(void));
- COM_API_OVERRIDE(unsigned int, header_size(void));
- COM_API_OVERRIDE(unsigned char*, data(unsigned long long off, unsigned int* bytes));
- COM_API_OVERRIDE(int, read(void* buf, size_t* bytes, unsigned long long off = 0));
- COM_API_OVERRIDE(const char*, file(void));
- COM_API_OVERRIDE(void, keep_file(bool keep));
- COM_API_OVERRIDE(void, copy_header(SANE_Parameters* head));
- COM_API_OVERRIDE(int, image_status(void));
-};
-
-template
-class safe_queue
-{
- typedef struct _t_and_size
- {
- size_t bytes;
- T t;
- }TNS;
- std::mutex lock_;
- std::vector queue_;
- size_t bytes_;
- T empty_;
-
-public:
- safe_queue() : bytes_(0)
- {}
- virtual ~safe_queue()
- {}
-
-public:
- size_t count(size_t* bytes = NULL)
- {
- std::lock_guard lock(lock_);
-
- if (bytes)
- *bytes = bytes_;
-
- return queue_.size();
- }
- bool save(T v, size_t bytes)
- {
- std::lock_guard lock(lock_);
- TNS tns = { bytes, v };
-
- queue_.push_back(tns);
- bytes_ += bytes;
-
- return true;
- }
- T take(bool remove = true, void(__stdcall* first)(T) = NULL)
- {
- std::lock_guard lock(lock_);
- TNS t;
-
- if (queue_.size())
- {
- t = queue_[0];
- if (remove)
- {
- queue_.erase(queue_.begin());
- bytes_ -= t.bytes;
- }
- if (first)
- first(t.t);
- }
- else
- t.t = empty_;
-
- return t.t;
- }
- void clear(void(__stdcall* tfree)(T) = NULL)
- {
- std::lock_guard lock(lock_);
-
- if (tfree)
- {
- for (auto& v : queue_)
- tfree(v.t);
- }
- queue_.clear();
- bytes_ = 0;
- }
-};
-
-class safe_img_queue : public safe_queue
-{
- static void __stdcall access_image(scanned_img* img);
- static void __stdcall free_image(scanned_img* img);
-
-public:
- safe_img_queue();
- ~safe_img_queue();
-
-public:
- bool get_header(SANE_Parameters* header, size_t* bytes = NULL, int *dpi = NULL);
- void clear();
-};
-
-namespace local_trans
-{
- std::string u2a(const wchar_t* unic, UINT cp = CP_ACP);
- std::wstring a2u(const char* asc, UINT cp = CP_ACP);
-
- std::wstring lang_trans_between_hz936(const wchar_t* in, bool from_hz = true);
- const char* __stdcall lang_trans_between_hz936(const char* in, bool from_hz, void* param);
-}
diff --git a/sane/scanner.cpp b/sane/scanner.cpp
deleted file mode 100644
index bbec3c7..0000000
--- a/sane/scanner.cpp
+++ /dev/null
@@ -1,3239 +0,0 @@
-#include "scanner.h"
-
-#include
-#include // for PathFileExistsW
-#include "../sdk/hginclude/huagaoxxx_warraper_ex.h"
-#include
-#include "../../code_device/hgsane/sane_hg_mdw.h"
-#include "sane_option_trans.h"
-#include
-#include
-#include "DlgIndicator.h"
-#include "DlgSetting.h"
-#include "gb_json.h"
-#include "../../sdk/include/lang/app_language.h"
-#include
-
-#pragma comment(lib, "Shlwapi.lib")
-
-
-static IMPLEMENT_OPTION_STRING_COMPARE(compare_sane_opt);
-
-#define SET_SANE_OPT_ID(id, id_name, name, val, extension) \
- if(strcmp(SANE_STD_OPT_NAME_##name, val) == 0) \
- { \
- id_name##_id_ = id; \
- extension(id); \
- }
-
-
-#ifdef EXPORT_SANE_API
-__declspec(dllexport)
-#else
-__declspec(dllimport)
-#endif
-void __stdcall log_info(const wchar_t* info, int level);
-
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// callback
-extern "C"
-{
- extern SANE_Status inner_sane_init(SANE_Int* version_code, SANE_Auth_Callback authorize);
- extern void inner_sane_exit(void);
- extern SANE_Status inner_sane_get_devices(const SANE_Device*** device_list, SANE_Bool local_only);
- extern SANE_Status inner_sane_open(SANE_String_Const devicename, SANE_Handle* handle);
- extern void inner_sane_close(SANE_Handle handle);
- extern const SANE_Option_Descriptor* inner_sane_get_option_descriptor(SANE_Handle handle, SANE_Int option);
- extern SANE_Status inner_sane_control_option(SANE_Handle handle, SANE_Int option, SANE_Action action, void* value, SANE_Int* info);
- extern SANE_Status inner_sane_get_parameters(SANE_Handle handle, SANE_Parameters* params);
- extern SANE_Status inner_sane_start(SANE_Handle handle);
- extern SANE_Status inner_sane_read(SANE_Handle handle, SANE_Byte* data, SANE_Int max_length, SANE_Int* length);
- extern void inner_sane_cancel(SANE_Handle handle);
- extern SANE_Status inner_sane_set_io_mode(SANE_Handle handle, SANE_Bool non_blocking);
- extern SANE_Status inner_sane_get_select_fd(SANE_Handle handle, SANE_Int* fd);
- extern SANE_String_Const inner_sane_strstatus(SANE_Status status);
-
- extern SANE_Status inner_sane_init_ex(SANE_Int* version_code, sane_callback cb, void* param);
- extern SANE_Status inner_sane_io_control(SANE_Handle h, unsigned long code, void* data, unsigned* len);
- extern const char* inner_sane_err_desc(SANE_Status err);
-}
-
-namespace callback
-{
- static std::mutex cb_lock_;
- typedef struct _scanner_inst
- {
- SANE_Handle dev;
- scanner* invoker;
-
- bool operator==(const SANE_Handle& h)
- {
- return dev == h;
- }
- bool operator==(const scanner* obj)
- {
- return invoker == obj;
- }
- }SCNINST;
- std::vector g_scanner_instances;
-
- int sane_event_callback( // 注册回调的对象,需要保证该回调是多线程安全的
- SANE_Handle hdev // 产生事件的设备句柄
- , int code // 回调事件代码
- , void* data // 回调事件数据,根据事件代码有所不同,参照具体事件定义
- , unsigned int* len // 数据长度(字节),或者event_data的缓冲区长度,详细请看相应的事件代码
- , void* param // 用户自定义数据,与调用sane_init_ex传入时的保持一致
- ) // 返回值依不同的事件代码而定,通常为“0”
- {
- std::lock_guard lock(cb_lock_);
- std::vector::iterator it = std::find(g_scanner_instances.begin(), g_scanner_instances.end(), hdev);
-
- if (it != g_scanner_instances.end())
- return it->invoker->handle_device_event(code, data, len);
- else
- {
- wchar_t msg[218] = { 0 };
- swprintf_s(msg, _countof(msg) - 1, L"Lost device(0x%08X) when event(%u) occurs!\r\n", hdev, code);
- log_info(msg, 0);
-
- return 0;
- }
- }
- void reg_callback(SANE_Handle dev, scanner* invoker)
- {
- std::lock_guard lock(cb_lock_);
- std::vector::iterator it = std::find(g_scanner_instances.begin(), g_scanner_instances.end(), dev);
- if (it == g_scanner_instances.end())
- {
- SCNINST inst;
-
- inst.dev = dev;
- inst.invoker = invoker;
- g_scanner_instances.push_back(inst);
- }
- else
- it->invoker = invoker;
- }
- void unreg_callback(scanner* invoker)
- {
- std::lock_guard lock(cb_lock_);
- std::vector::iterator it = std::find(g_scanner_instances.begin(), g_scanner_instances.end(), invoker);
- if (it != g_scanner_instances.end())
- g_scanner_instances.erase(it);
- }
-
- struct
- {
- const char* name;
- const char* title;
- }g_opts[] = { {SANE_STD_OPT_NAME_RESTORE , OPTION_TITLE_HFMRSZ}
- , {SANE_STD_OPT_NAME_HELP , OPTION_TITLE_BZ}
- , {SANE_STD_OPT_NAME_IS_MULTI_OUT , OPTION_TITLE_DLSC}
- , {SANE_STD_OPT_NAME_MULTI_OUT_TYPE , OPTION_TITLE_DLSCLX}
- , {SANE_STD_OPT_NAME_COLOR_MODE , OPTION_TITLE_YSMS}
- , {SANE_STD_OPT_NAME_BINARY_THRESHOLD , OPTION_TITLE_HBTXYZ}
- , {SANE_STD_OPT_NAME_REVERSE_01 , OPTION_TITLE_HBTXFSSC}
- , {SANE_STD_OPT_NAME_FILTER , OPTION_TITLE_HDHHBTX_CSYZQ}
- , {SANE_STD_OPT_NAME_RID_MULTIOUT_RED , OPTION_TITLE_24WCSTX_DLSCCH}
- , {SANE_STD_OPT_NAME_RID_ANSWER_SHEET_RED , OPTION_TITLE_24WCSTX_DTKCH}
- , {SANE_STD_OPT_NAME_ERASE_BACKGROUND , OPTION_TITLE_BJYC}
- , {SANE_STD_OPT_NAME_BKG_COLOR_RANGE , OPTION_TITLE_BJSCFDFW}
- , {SANE_STD_OPT_NAME_SHARPEN , OPTION_TITLE_RHYMH}
- , {SANE_STD_OPT_NAME_RID_MORR , OPTION_TITLE_QCMW}
- , {SANE_STD_OPT_NAME_RID_GRID , OPTION_TITLE_CWW}
- , {SANE_STD_OPT_NAME_ERROR_EXTENSION , OPTION_TITLE_CWKS}
- , {SANE_STD_OPT_NAME_NOISE_OPTIMIZE , OPTION_TITLE_HBTXZDYH}
- , {SANE_STD_OPT_NAME_NOISE_SIZE , OPTION_TITLE_ZDYHCC}
- , {SANE_STD_OPT_NAME_PAPER , OPTION_TITLE_ZZCC}
- , {SANE_STD_OPT_NAME_CUSTOM_AREA , OPTION_TITLE_ZDYSMQY}
- , {SANE_STD_OPT_NAME_CUSTOM_AREA_LEFT , OPTION_TITLE_SMQYZCmm}
- , {SANE_STD_OPT_NAME_CUSTOM_AREA_RIGHT , OPTION_TITLE_SMQYYCmm}
- , {SANE_STD_OPT_NAME_CUSTOM_AREA_TOP , OPTION_TITLE_SMQYSCmm}
- , {SANE_STD_OPT_NAME_CUSTOM_AREA_BOTTOM , OPTION_TITLE_SMQYXCmm}
- , {SANE_STD_OPT_NAME_SIZE_CHECK , OPTION_TITLE_CCJC}
- , {SANE_STD_OPT_NAME_PAGE , OPTION_TITLE_SMYM}
- , {SANE_STD_OPT_NAME_DISCARD_BLANK_SENS , OPTION_TITLE_TGKBYLMD}
- , {SANE_STD_OPT_NAME_RESOLUTION , OPTION_TITLE_FBL}
- , {SANE_STD_OPT_NAME_TIME_TO_SLEEP , OPTION_TITLE_XMSJ}
- , {SANE_STD_OPT_NAME_IMAGE_QUALITY , OPTION_TITLE_HZ}
- , {SANE_STD_OPT_NAME_EXCHANGE ,OPTION_TITLE_JHZFM}
- , {SANE_STD_OPT_NAME_SPLIT ,OPTION_TITLE_TXCF }
- , {SANE_STD_OPT_NAME_ANTI_SKEW , OPTION_TITLE_ZDJP}
- , {SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA , OPTION_TITLE_QYSDQX}
- , {SANE_STD_OPT_NAME_GAMMA , OPTION_TITLE_JMZ}
- , {SANE_STD_OPT_NAME_BRIGHTNESS , OPTION_TITLE_LDZ}
- , {SANE_STD_OPT_NAME_CONTRAST , OPTION_TITLE_DBD}
- , {SANE_STD_OPT_NAME_IS_PHOTO_MODE , OPTION_TITLE_ZPMS}
- , {SANE_STD_OPT_NAME_ERASE_BLACK_FRAME , OPTION_TITLE_XCHK}
- , {SANE_STD_OPT_NAME_DARK_SAMPLE , OPTION_TITLE_SSYZ}
- , {SANE_STD_OPT_NAME_THRESHOLD , OPTION_TITLE_YZ}
- , {SANE_STD_OPT_NAME_ANTI_NOISE_LEVEL , OPTION_TITLE_BJKZDJ}
- , {SANE_STD_OPT_NAME_MARGIN , OPTION_TITLE_BYSJ}
- , {SANE_STD_OPT_NAME_FILL_BKG_MODE , OPTION_TITLE_BJTCFS}
- , {SANE_STD_OPT_NAME_IS_ANTI_PERMEATE , OPTION_TITLE_FZST}
- , {SANE_STD_OPT_NAME_ANTI_PERMEATE_LEVEL , OPTION_TITLE_FZSTDJ}
- , {SANE_STD_OPT_NAME_RID_HOLE_L , OPTION_TITLE_CKYCZC}
- , {SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_L , OPTION_TITLE_ZCCKSSFWZFMBL}
- , {SANE_STD_OPT_NAME_RID_HOLE_R , OPTION_TITLE_CKYCYC}
- , {SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_R , OPTION_TITLE_YCCKSSFWZFMBL}
- , {SANE_STD_OPT_NAME_RID_HOLE_T , OPTION_TITLE_CKYCSC}
- , {SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_T , OPTION_TITLE_SCCKSSFWZFMBL}
- , {SANE_STD_OPT_NAME_RID_HOLE_B , OPTION_TITLE_CKYCXC}
- , {SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_B , OPTION_TITLE_XCCKSSFWZFMBL}
- , {SANE_STD_OPT_NAME_IS_FILL_COLOR , OPTION_TITLE_SCTC}
- , {SANE_STD_OPT_NAME_IS_ULTROSONIC_CHECK , OPTION_TITLE_CSBJC}
- , {SANE_STD_OPT_NAME_DOUBLE_FEED_HANDLE , OPTION_TITLE_SZTPCL}
- , {SANE_STD_OPT_NAME_IS_CHECK_STAPLE , OPTION_TITLE_ZDJC}
- , {SANE_STD_OPT_NAME_SCAN_MODE , OPTION_TITLE_SMZS}
- , {SANE_STD_OPT_NAME_SCAN_COUNT , OPTION_TITLE_SMSL}
- , {SANE_STD_OPT_NAME_TEXT_DIRECTION , OPTION_TITLE_WGFX}
- , {SANE_STD_OPT_NAME_IS_ROTATE_BKG_180 , OPTION_TITLE_BMXZ180}
- , {SANE_STD_OPT_NAME_IS_CHECK_DOG_EAR , OPTION_TITLE_ZJJC}
- , {SANE_STD_OPT_NAME_DOG_EAR_SIZE , OPTION_TITLE_ZJDX}
- , {SANE_STD_OPT_NAME_IS_CHECK_ASKEW , OPTION_TITLE_WXJC}
- , {SANE_STD_OPT_NAME_ASKEW_RANGE , OPTION_TITLE_WXRRD}
- , {SANE_STD_OPT_NAME_FEED_STRENGTH , OPTION_TITLE_FZQD}
- , {SANE_STD_OPT_NAME_IS_AUTO_FEED_STRENGTH , OPTION_TITLE_ZDFZQD}
- , {SANE_STD_OPT_NAME_FEED_STRENGTH_VALUE , OPTION_TITLE_JZSBL}
- , {SANE_STD_OPT_NAME_WAIT_TO_SCAN , OPTION_TITLE_DZSM}
- , {SANE_STD_OPT_NAME_FOLD_TYPE , OPTION_TITLE_DZMS}
- , {SANE_STD_OPT_NAME_COLOR_CORRECTION , OPTION_TITLE_SPJZ}
- },
- g_discard[] = { {SANE_STD_OPT_NAME_REVERSE_01 , "\351\273\221\347\231\275\345\233\276\345\203\217\345\217\215\350\211\262\350\276\223\345\207\272\357\274\210\346\255\243\345\270\270\351\242\234\350\211\262\344\270\272\357\274\2320-\351\273\221\350\211\262\357\274\2331-\347\231\275\350\211\262\357\274\211"} // 黑白图像反色输出(正常颜色为:0-黑色;1-白色)
- , {SANE_STD_OPT_NAME_FILTER , "\347\201\260\345\272\246\346\210\226\351\273\221\347\231\275\345\233\276\345\203\217 - \351\231\244\350\211\262"} // 灰度或黑白图像 - 除色
- , {SANE_STD_OPT_NAME_IS_AUTO_FEED_STRENGTH , "\350\207\252\345\212\250\346\220\223\347\272\270\345\274\272\345\272\246"} // 自动搓纸强度
- , {SANE_STD_OPT_NAME_FEED_STRENGTH_VALUE , "\346\220\223\347\272\270\351\230\210\345\200\274"} // " 搓纸阈值"
- };
- const char* option_title_2_name(const char* title)
- {
- while (*title == ' ')
- title++;
-
- for (size_t i = 0; i < _countof(g_discard); ++i)
- {
- if (strcmp(title, g_discard[i].title) == 0)
- return g_discard[i].name;
- }
- for (size_t i = 0; i < _countof(g_opts); ++i)
- {
- if (strcmp(title, g_opts[i].title) == 0)
- return g_opts[i].name;
- }
-
- return "";
- }
- const char* __stdcall option_name_2_title(const char* name)
- {
- for (size_t i = 0; i < _countof(g_opts); ++i)
- {
- if (strcmp(name, g_opts[i].name) == 0)
- return g_opts[i].title;
- }
-
- return "";
- }
-
- static BOOL CALLBACK main_wnd(HWND hwnd, LPARAM param)
- {
- DWORD pid = 0;
-
- GetWindowThreadProcessId(hwnd, &pid);
- if (pid != GetCurrentProcessId())
- return TRUE;
-
- if (((void**)param)[1] == NULL)
- {
- HWND parent = GetParent(hwnd);
- while (IsWindow(parent))
- {
- hwnd = parent;
- parent = GetParent(hwnd);
- }
- parent = hwnd;
- if (!IsWindowVisible(parent))
- return TRUE;
-
- RECT r = { 0 };
- GetWindowRect(parent, &r);
- if (RECT_H(r) > 50 && RECT_W(r) > 50)
- {
- *(HWND*)param = parent;
-
- return FALSE;
- }
- }
- else
- {
- wchar_t val[128] = { 0 };
- GetClassNameW(hwnd, val, _countof(val) - 1);
- if (wcscmp(val, L"#32770"))
- return TRUE;
-
- GetWindowTextW(hwnd, val, _countof(val) - 1);
- if (*((std::wstring**)param)[1] == val)
- {
- *(HWND*)param = hwnd;
-
- return FALSE;
- }
- }
-
- return TRUE;
- }
- static HWND find_main_wnd(void)
- {
- HWND wnd[2] = { NULL };
-
- EnumWindows(main_wnd, (LPARAM)wnd);
-
- return wnd[0];
- }
- static DWORD WINAPI btm(LPVOID para)
- {
- std::wstring* title[2] = { NULL, (std::wstring*)para };
-
- Sleep(100);
- EnumWindows(main_wnd, (LPARAM)title);
- if (IsWindow((HWND)title[0]))
- {
- RECT r = { 0 };
- GetWindowRect((HWND)title[0], &r);
- SetWindowPos((HWND)title[0], HWND_TOPMOST, r.left, r.top, RECT_W(r), RECT_H(r), SWP_SHOWWINDOW | SWP_NOSENDCHANGING);
- SetFocus((HWND)title[0]);
- }
-
- delete title[1];
-
- return 0;
- }
- static void bring_message_box_topmost(const wchar_t* title)
- {
- DWORD id = 0;
- std::wstring* t(new std::wstring(title));
- HANDLE h = CreateThread(NULL, 0, btm, t, 0, &id);
-
- if (h)
- CloseHandle(h);
- else
- delete t;
- }
-
- static const char* __stdcall language_trans(const char* in, bool from_hz, void* param)
- {
- if (from_hz)
- return from_default_language(in, nullptr);
- else
- return to_default_language(in, nullptr);
- }
-
-
- // UI ...
- //
- // events code, see SANE_Event
- //
- // callback events: SANE_EVENT_UI_CLOSE_CANCEL/SANE_EVENT_UI_CLOSE_NORMAL/SANE_EVENT_UI_SCAN_COMMAND/SANE_EVENT_UI_CLOSE_SETTING
- //
- // notify events: SANE_EVENT_WORKING - void*: unused, be NULL, flag - unused, be 0
- // SANE_EVENT_SCAN_FINISHED - void*: (utf8*)message, flag - error code (0 is success)
- // SANE_EVENT_USB_DATA_RECEIVED- void* unused, be NULL, flag - unused, be 0
- // SANE_EVENT_IMAGE_OK - void* unused, be NULL, flag - unused, be 0
- int (*choose_scanner)(const std::vector& devs) = NULL; // blocked. return selected DEVQUE::id or -1 if user cancelled
- void (*apply_current_config)(const char* dev_name, SANE_Handle device, LPSANEAPI api) = NULL; // 应用设备的当前配置
- void (*show_setting_ui)(SANE_Handle device, HWND parent, LPSANEAPI api, bool with_scan/*是否显示“扫描”按钮*/, std::function callback) = NULL;
- void (*show_progress_ui)(HWND parent, std::function callback, std::function* notify) = NULL;
- static void init_ui(void)
- {
- std::string root(hg_sane_middleware::sane_path());
- HMODULE mod = NULL;
-
- root += "HGTwainUI.dll";
-
- mod = LoadLibraryExA(root.c_str(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
- if (!mod)
- {
- std::wstring info(L"Load '" + local_trans::a2u(root.c_str(), CP_UTF8));
-
- info += L"' failed: " + std::to_wstring(GetLastError()) + L"\r\n";
-
- log_info(info.c_str(), 0);
- }
- else
- {
-#define GET_API(api) \
- proc = (FARPROC*)&api; \
- *proc = GetProcAddress(mod, #api);
-
- FARPROC* proc = NULL;
-
- GET_API(choose_scanner);
- GET_API(apply_current_config);
- GET_API(show_setting_ui);
- GET_API(show_progress_ui);
- }
- }
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// class scanner
-scanner::scanner(SCANNERID id) : handle_(NULL), id_(id), ex_id_(EXTENSION_ID_BASE), prev_start_result_(SCANNER_ERR_NOT_START)
- , dpi_(200), tmp_path_(L""), img_ind_(0)
- , scanner_name_(L""), cfg_(NULL), is_ui_wait_img_(false), is_scanning_(false)
- , scanner_ev_handler_(NULL), evh_param_(NULL), app_wnd_(NULL), user_cancel_(false)
- , max_img_mem_(1 * 1024), twain_set_(false), ev_cnt_(0)
-{
- sane_api_.sane_cancel_api = inner_sane_cancel;
- sane_api_.sane_close_api = inner_sane_close;
- sane_api_.sane_control_option_api = inner_sane_control_option;
- sane_api_.sane_get_devices_api = inner_sane_get_devices;
- sane_api_.sane_get_option_descriptor_api = inner_sane_get_option_descriptor;
- sane_api_.sane_get_parameters_api = inner_sane_get_parameters;
- sane_api_.sane_get_select_fd_api = inner_sane_get_select_fd;
- sane_api_.sane_io_control_api = inner_sane_io_control;
- sane_api_.sane_open_api = inner_sane_open;
- sane_api_.sane_read_api = inner_sane_read;
- sane_api_.sane_set_io_mode_api = inner_sane_set_io_mode;
- sane_api_.sane_start_api = inner_sane_start;
- sane_api_.sane_strstatus_api = inner_sane_strstatus;
-
- if (!callback::show_setting_ui)
- {
- cfg_ = new gb::scanner_cfg();
- cfg_->set_language_transform(&callback::language_trans, NULL);
- }
-
- tmp_path_ = local_trans::a2u(hg_sane_middleware::sane_path().c_str());
- {
- char* tmp = getenv("LOCALAPPDATA");
-
- if (tmp)
- {
- tmp_path_ = local_trans::a2u(tmp) + L"\\";
- tmp_path_ += local_trans::a2u(PRODUCT_VENDOR) + L"Scan\\";
- CreateDirectoryW(tmp_path_.c_str(), NULL);
- }
- }
- cfg_path_ = tmp_path_ + L"config";
- CreateDirectoryW(cfg_path_.c_str(), NULL);
- cfg_path_ += L"\\";
- tmp_path_ += L"imgs";
- CreateDirectoryW(tmp_path_.c_str(), NULL);
- tmp_path_ += L"\\";
- img_fmt_.img_format = SANE_IMAGE_TYPE_BMP;
- img_fmt_.compress.compression = SANE_COMPRESSION_NONE;
-
- int mem_limit = GetPrivateProfileIntW(L"mem", L"max_img", 0, (cfg_path_ + L"debug.cfg").c_str());
- if (mem_limit > 0)
- {
- // this value is same as driver memory limit ...
- max_img_mem_ = mem_limit;
- }
- err_ = open();
-}
-scanner::~scanner()
-{
- close();
- if (cfg_)
- {
- cfg_->release();
- cfg_ = NULL;
- }
-}
-
-bool scanner::is_belong_serial(int vid, int pid, SCANNERID serial)
-{
- if (vid == PRODUCT_VENDOR_HG)
- {
- if (GET_SCANNER_VID(serial) == PRODUCT_VENDOR_HG)
- {
- if (GET_SCANNER_PID(serial) == 0x100)
- {
- return pid == 0x100 || pid == 0x139;
- }
- else if (GET_SCANNER_PID(serial) == 0x200)
- {
- return pid == 0x200 || pid == 0x239;
- }
- else if (GET_SCANNER_PID(serial) == 0x300)
- {
- return pid == 0x300 || pid == 0x302 || pid == 0x339;
- }
- else if (GET_SCANNER_PID(serial) == 0x400)
- {
- return pid == 0x400 || pid == 0x402 || pid == 0x439;
- }
- else if (GET_SCANNER_PID(serial) == 0x138 ||
- GET_SCANNER_PID(serial) == 0x238 ||
- GET_SCANNER_PID(serial) == 0x303 ||
- GET_SCANNER_PID(serial) == 0x404) // OEM_CANGTIAN
- return true;
- }
-
- return false;
- }
- else if (vid == PRODUCT_VENDOR_HG1)
- {
- return pid == 0x7823 && GET_SCANNER_VID(serial) == PRODUCT_VENDOR_HG && GET_SCANNER_PID(serial) == 0x200;
- }
- else if (vid == PRODUCT_VENDOR_HW)
- {
- return GET_SCANNER_VID(serial) == vid && GET_SCANNER_PID(serial) == pid;
- }
- else if (vid == PRODUCT_VENDOR_LSC)
- {
- if (GET_SCANNER_VID(serial) == PRODUCT_VENDOR_LSC)
- {
- if (GET_SCANNER_PID(serial) == 0x8420)
- {
- return pid == 0x8200 || pid == 0x8420 || pid == 0x8429;
- }
- else if (GET_SCANNER_PID(serial) == 0x8520)
- {
- return pid == 0x8520 || pid == 0x8529;
- }
- else if (GET_SCANNER_PID(serial) == 0x8620)
- {
- return pid == 0x8620 || pid == 0x8629;
- }
- else if (GET_SCANNER_PID(serial) == 0x8730)
- {
- return pid == 0x8730 || pid == 0x8739;
- }
- }
- return false;
- }
- return true;
-}
-void scanner::get_scanner_name(SCANNERID id, std::vector& names)
-{
- ScannerInfo* devs = NULL;
- long count = 0;
-
- names.clear();
- if (hg_scanner_enum(devs, &count, true) == SCANNER_ERR_INSUFFICIENT_MEMORY)
- {
- count++;
- devs = new ScannerInfo[count];
- memset(devs, 0, count * sizeof(*devs));
- if (hg_scanner_enum(devs, &count, true) == SCANNER_ERR_OK)
- {
- for (int i = 0; i < count; ++i)
- {
- if (scanner::is_belong_serial(devs[i].vid, devs[i].pid, id))
- {
- names.push_back(devs[i].name);
- }
- }
- }
- delete[] devs;
- }
-}
-value_type scanner::from_sane_type(SANE_Value_Type type)
-{
- if (type == SANE_TYPE_BOOL)
- return VAL_TYPE_BOOL;
- else if (type == SANE_TYPE_INT)
- return VAL_TYPE_INT;
- else if (type == SANE_TYPE_FIXED)
- return VAL_TYPE_FLOAT;
- else if (type == SANE_TYPE_STRING)
- return VAL_TYPE_STR;
- else
- return VAL_TYPE_NONE;
-}
-value_limit scanner::from_sane_constraint(SANE_Constraint_Type type)
-{
- if (type == SANE_CONSTRAINT_RANGE)
- return VAL_LIMIT_RANGE;
- else if (type == SANE_CONSTRAINT_STRING_LIST || type == SANE_CONSTRAINT_WORD_LIST)
- return VAL_LIMIT_ENUM;
- else
- return VAL_LIMIT_NONE;
-}
-int scanner::control_read_string(SANE_Handle hdev, int code, std::string& str)
-{
- char* buf = NULL;
- unsigned len = 0;
- int err = hg_sane_middleware::instance()->io_control(hdev, code, buf, &len);
-
- str = "";
- if (err == SANE_STATUS_NO_MEM)
- {
- len += 4;
- buf = new char[len];
- memset(buf, 0, len);
- err = hg_sane_middleware::instance()->io_control(hdev, code, buf, &len);
- if (err == SANE_STATUS_GOOD)
- str = buf;
- delete[] buf;
- }
-
- return err;
-}
-
-int __stdcall scanner::to_int(SANE_Int v)
-{
- return v;
-}
-float __stdcall scanner::to_float(SANE_Fixed v)
-{
- return (float)SANE_UNFIX(v);
-}
-void __stdcall scanner::ui_callback(int uev, void* sender, void* param)
-{
- ((scanner*)param)->on_ui_event(uev, sender);
-}
-bool scanner::is_option_float(int sn, void* param)
-{
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor((SANE_Handle)param, (const void*)sn);
-
- if (desc)
- return desc->type == SANE_TYPE_FIXED;
- else
- return false;
-}
-void __stdcall scanner::apply_scheme(gb::sane_config_schm* schm, void* param)
-{
- ((scanner*)param)->apply_scheme(schm);
-}
-
-// IRef
-COM_API_IMPLEMENT(scanner, long, add_ref(void))
-{
- return refer::add_ref();
-}
-COM_API_IMPLEMENT(scanner, long, release(void))
-{
- return refer::release();
-}
-
-void scanner::transport_config_file(void)
-{
- size_t pos = scanner_name_.find(L" - ");
- std::wstring pid(L"G"), old(L"");
-
- if (pos == std::wstring::npos)
- return;
-
- pid += scanner_name_.substr(pos + 3);
- if (scanner_name_.find(L"HUAGOSCAN ") != std::wstring::npos)
- {
- old = local_trans::lang_trans_between_hz936(L"\u534E\u9AD8\u626B\u63CF\u4EEA\u2014");
- }
- else if (scanner_name_.find(L"LANXUMSCAN ") != std::wstring::npos)
- {
- old = local_trans::lang_trans_between_hz936(L"\u7ACB\u601D\u8FB0\u626B\u63CF\u4EEA\u2014");
- pid += L"S";
- }
- old += pid;
- if (PathFileExistsW((cfg_path_ + old).c_str()))
- {
- log_info((L"Rename config file '" + old + L"' to '" + scanner_name_.substr(0, pos) + L"'\r\n").c_str(), 0);
- MoveFileW((cfg_path_ + old).c_str(), (cfg_path_ + scanner_name_.substr(0, pos)).c_str());
- }
-}
-void scanner::update_config(void)
-{
- if (!cfg_)
- return;
-
- gb::sane_config_schm* schm = cfg_->get_scheme();
- std::string notice("");
-
- if (schm)
- {
- //schm->update(&scanner::is_option_float, handle_, &callback::option_title_2_name, ¬ice);
- //if (notice.length())
- //{
- // std::wstring msg(local_trans::lang_trans_between_hz936(L"\u4E0B\u5217\u914D\u7F6E\u6570\u636E\u9519\u8BEF\uFF0C\u5DF2\u7ECF\u6062\u590D\u5230\u9ED8\u8BA4\u503C\u3002\u5982\u679C\u9700\u8981\uFF0C\u8BF7\u91CD\u65B0\u8BBE\u7F6E") + L"\r\n\r\n");
- // size_t pos = notice.find("\r\n");
- //
- // while (pos != std::string::npos)
- // {
- // msg += local_trans::a2u(callback::option_name_2_title(notice.substr(0, pos).c_str()), CP_UTF8) + L"\r\n";
- // notice.erase(0, pos + 2);
- // pos = notice.find("\r\n");
- // }
- // if (!IsWindow(app_wnd_))
- // callback::bring_message_box_topmost(local_trans::lang_trans_between_hz936(L"\u52A0\u8F7D\u914D\u7F6E").c_str());
- // MessageBoxW(app_wnd_, msg.c_str(), local_trans::lang_trans_between_hz936(L"\u52A0\u8F7D\u914D\u7F6E").c_str(), MB_OK | MB_ICONINFORMATION);
- //}
- schm->release();
- }
-}
-void scanner::load_config(const wchar_t* file)
-{
- if (cfg_)
- {
- cfg_->load_file(local_trans::u2a(file).c_str());
- update_config();
- }
-}
-void scanner::save_config(const wchar_t* file)
-{
- if(cfg_)
- cfg_->save(local_trans::u2a(file).c_str());
-}
-void scanner::apply_config(void)
-{
- if (callback::apply_current_config)
- callback::apply_current_config(local_trans::u2a(scanner_name_.c_str(), CP_UTF8).c_str(), handle_, &sane_api_);
- else if (cfg_)
- {
- gb::sane_config_schm* schm = cfg_->get_scheme();
-
- if (!schm)
- return;
-
- apply_scheme(schm);
- schm->release();
- }
-}
-void scanner::on_ui_event(int uev, void* sender)
-{
- bool indicator = sender == indicator_.get();
- if (uev == SANE_EVENT_SCAN_FINISHED || uev == SANE_EVENT_UI_CLOSE_NORMAL || uev == SANE_EVENT_UI_CLOSE_CANCEL)
- {
- if (uev == SANE_EVENT_UI_CLOSE_CANCEL)
- user_cancel_ = true;
-
- if (indicator)
- indicator_.reset();
-
- is_scanning_ = false;
- if (err_ && setting_.get())
- {
- return;
- }
- }
-
- //int(__stdcall * h)(int, void*) = scanner_ev_handler_;
- //if (h)
- //{
- // if (SANE_EVENT_UI_CLOSE_SETTING == uev)
- // {
- // is_scanning_ = false;
- // setting_.reset();
- // }
-
- // h(uev, evh_param_);
- // return;
- //}
-
- //if (prev_start_result_ != SANE_STATUS_GOOD && indicator)
- // indicator_.reset();
- //else
- {
- //if (uev == SANE_EVENT_UI_SCAN_COMMAND)
- //{
- // ui_show_progress(NULL);
- // start();
- // return;
- //}
-
- if (/*events_.count() > 5 && !is_ui_wait_img_ &&*/
- (uev == SANE_EVENT_UI_CLOSE_CANCEL || uev == SANE_EVENT_UI_CLOSE_NORMAL || uev == SANE_EVENT_UI_CLOSE_SETTING))
- {
- // events_.clear();
- ui_hide();
- if(indicator || !indicator_.get())
- uev = SANE_EVENT_SCAN_FINISHED;
- else
- uev = SANE_EVENT_UI_CLOSE_SETTING;
- }
-
- events_.save(uev, sizeof(uev));
- ev_cnt_++;
- }
-
- if (ev_cnt_ == events_.count() &&
- (ev_cnt_ >= 5 || (ev_cnt_ > 1 && !is_scanning_)))
- {
- // maybe no event has been handled by APP, triggered by callback
- int(__stdcall * h)(int, void*) = scanner_ev_handler_;
- if (h)
- {
- wchar_t info[128] = { 0 };
- swprintf_s(info, _countof(info) - 1, L"[CRAZY]%d scanner events stored but APP has no action, we try to trigger it ONCE ...\r\n", ev_cnt_);
- ev_cnt_--;
- h(events_.take(), evh_param_);
- }
- }
-}
-std::string scanner::choose_scanner(const std::vector& scanners)
-{
- if (scanners.empty())
- return "";
-
- std::vector devs;
- std::string sel("");
- int id = 1;
-
- for (size_t i = 0; i < scanners.size(); ++i)
- {
- SANE_Handle h = NULL;
- int ret = hg_sane_middleware::instance()->open_device(scanners[i].c_str(), &h);
-
- if (h)
- {
- std::string sn("");
- scanner::control_read_string(h, IO_CTRL_CODE_GET_SERIAL, sn);
- if (sn.length())
- {
- DEVQUE dev;
- dev.id = id++;
- dev.name = scanners[i];
- dev.sn = sn;
- devs.push_back(dev);
- }
- hg_sane_middleware::instance()->close_device(h);
- }
- }
-
- if (devs.size() == 0)
- sel = scanners[0];
- else if (devs.size() == 1)
- sel = devs[0].name;
- else if (callback::choose_scanner)
- {
- id = callback::choose_scanner(devs);
- if (id != -1)
- {
- for (auto& v : devs)
- {
- if (v.id == id)
- {
- sel = v.name;
- break;
- }
- }
- }
- }
- else
- {
- dlg_choose_dev dlg(NULL, devs);
- dlg.show(true, true);
- sel = dlg.get_selected_device();
- }
-
- return sel;
-}
-int scanner::open(void)
-{
- int ret = close();
- std::vector que;
- std::string name("");
-
- scanner::get_scanner_name(id_, que);
-
- scanner_name_ = L"";
- if (que.empty())
- return SCANNER_ERR_DEVICE_NOT_FOUND;
-
- if (que.size() == 1)
- name = que[0];
- else
- {
- name = choose_scanner(que);
- if (name.empty())
- return SCANNER_ERR_USER_CANCELED;
- }
-
- ret = hg_sane_middleware::instance()->open_device(name.c_str(), &handle_);
- if (ret == SANE_STATUS_GOOD)
- {
- size_t pid = -1;
-
- transport_config_file();
- callback::reg_callback(handle_, this);
- scanner_name_ = local_trans::a2u(name.c_str(), CP_UTF8);
- pid = scanner_name_.find(L" - ");
- if (pid == -1)
- pid = scanner_name_.length();
- ret = init_options_id();
- load_config((cfg_path_ + scanner_name_.substr(0, pid) + L".cfg").c_str());
- apply_config();
- }
- else
- {
- std::wstring msg(local_trans::a2u(hg_scanner_err_description(ret), CP_UTF8));
- HWND parent = callback::find_main_wnd();
-
- if (!IsWindow(parent))
- callback::bring_message_box_topmost(local_trans::lang_trans_between_hz936(CONST_STRING_OPEN_FAILED).c_str());
- MessageBoxW(parent, msg.c_str(), local_trans::lang_trans_between_hz936(CONST_STRING_OPEN_FAILED).c_str(), MB_OK | MB_ICONERROR);
- }
-
- return ret;
-}
-int scanner::close(void)
-{
- scanner_ev_handler_ = NULL;
- ui_hide();
- callback::unreg_callback(this);
- if (handle_)
- {
- hg_sane_middleware::instance()->close_device(handle_);
- }
- handle_ = NULL;
- ex_id_ = EXTENSION_ID_BASE;
-
- return SCANNER_ERR_OK;
-}
-int scanner::init_options_id(void)
-{
- SANE_Int op_id = 1;
- const SANE_Option_Descriptor* desc = NULL;
- int ret = SCANNER_ERR_OK;
-
-#define SET_OPT_ID(var, predef, func) \
- SET_SANE_OPT_ID(op_id, var, predef, desc->name, func)
-
- while ((desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (const void*)op_id)))
- {
- void* val = hg_sane_middleware::instance()->get_def_value(handle_, (void*)op_id, NULL, true);
- if (val)
- {
- size_t len = 0;
- switch (desc->type)
- {
- case SANE_TYPE_BOOL:
- len = sizeof(SANE_Bool);
- break;
- case SANE_TYPE_INT:
- len = sizeof(SANE_Int);
- break;
- case SANE_TYPE_FIXED:
- len = sizeof(SANE_Fixed);
- break;
- case SANE_TYPE_STRING:
- len = lstrlenA((char*)val);
- break;
- default:
- break;
- }
- if (len && cfg_)
- {
- if (desc->type == SANE_TYPE_STRING)
- {
- std::string deflan(to_default_language((char*)val, nullptr));
- cfg_->set_default_value(op_id, desc->name, desc->title, &deflan[0], deflan.length(), desc->type);
- }
- else
- cfg_->set_default_value(op_id, desc->name, desc->title, (char*)val, len, desc->type);
- }
- local_utility::free_memory(val);
- }
-
- SET_OPT_ID(is_multiout, IS_MULTI_OUT, extension_none)
- else SET_OPT_ID(multiout_type, MULTI_OUT_TYPE, extension_multiout_type)
- else SET_OPT_ID(color_mode, COLOR_MODE, extension_color_mode)
- else SET_OPT_ID(erase_color, FILTER, extension_erase_color)
- else SET_OPT_ID(erase_multiout_red, RID_MULTIOUT_RED, extension_none)
- else SET_OPT_ID(erase_paper_red, RID_ANSWER_SHEET_RED, extension_none)
- else SET_OPT_ID(is_erase_background, ERASE_BACKGROUND, extension_none)
- else SET_OPT_ID(background_color_range, BKG_COLOR_RANGE, extension_none)
- else SET_OPT_ID(sharpen, SHARPEN, extension_sharpen)
- else SET_OPT_ID(erase_morr, RID_MORR, extension_none)
- else SET_OPT_ID(erase_grids, RID_GRID, extension_none)
- else SET_OPT_ID(error_extend, ERROR_EXTENSION, extension_none)
- else SET_OPT_ID(is_noise_modify, NOISE_OPTIMIZE, extension_none)
- else SET_OPT_ID(noise_threshold, NOISE_SIZE, extension_none)
- else SET_OPT_ID(paper, PAPER, extension_paper)
- else SET_OPT_ID(is_custom_area, CUSTOM_AREA, extension_none)
- else SET_OPT_ID(curstom_area_l, CUSTOM_AREA_LEFT, extension_none)
- else SET_OPT_ID(curstom_area_r, CUSTOM_AREA_RIGHT, extension_none)
- else SET_OPT_ID(curstom_area_t, CUSTOM_AREA_TOP, extension_none)
- else SET_OPT_ID(curstom_area_b, CUSTOM_AREA_BOTTOM, extension_none)
- else SET_OPT_ID(is_size_check, SIZE_CHECK, extension_none)
- else SET_OPT_ID(page, PAGE, extension_page)
- else SET_OPT_ID(blank_page_threshold, DISCARD_BLANK_SENS, extension_none)
- else SET_OPT_ID(resolution, RESOLUTION, extension_none)
- else SET_OPT_ID(image_quality, IMAGE_QUALITY, extension_none)
- else SET_OPT_ID(is_swap, EXCHANGE, extension_none)
- else SET_OPT_ID(is_split, SPLIT, extension_none)
- else SET_OPT_ID(is_auto_deskew, ANTI_SKEW, extension_none)
- else SET_OPT_ID(is_custom_gamma, IS_CUSTOM_GAMMA, extension_none)
- else SET_OPT_ID(bright, BRIGHTNESS, extension_none)
- else SET_OPT_ID(contrast, CONTRAST, extension_none)
- else SET_OPT_ID(gamma, GAMMA, extension_none)
- else SET_OPT_ID(is_erase_black_frame, ERASE_BLACK_FRAME, extension_none)
- else SET_OPT_ID(deep_sample, DARK_SAMPLE, extension_none)
- else SET_OPT_ID(threshold, THRESHOLD, extension_none)
- else SET_OPT_ID(anti_noise, ANTI_NOISE_LEVEL, extension_none)
- else SET_OPT_ID(margin, MARGIN, extension_none)
- else SET_OPT_ID(fill_background, FILL_BKG_MODE, extension_fill_bkg_method)
- else SET_OPT_ID(is_anti_permeate, IS_ANTI_PERMEATE, extension_none)
- else SET_OPT_ID(anti_permeate_level, ANTI_PERMEATE_LEVEL, extension_none)
- else SET_OPT_ID(is_erase_hole, RID_HOLE, extension_none)
- else SET_OPT_ID(search_hole_range, SEARCH_HOLE_RANGE, extension_none)
- else SET_OPT_ID(is_filling_color, IS_FILL_COLOR, extension_none)
- else SET_OPT_ID(is_ultrasonic_check, IS_ULTROSONIC_CHECK, extension_none)
- else SET_OPT_ID(is_check_staple, IS_CHECK_STAPLE, extension_none)
- else SET_OPT_ID(scan_mode, SCAN_MODE, extension_none)
- else SET_OPT_ID(scan_count, SCAN_COUNT, extension_none)
- else SET_OPT_ID(text_direction, TEXT_DIRECTION, extension_text_direction)
- else SET_OPT_ID(is_rotate_bkg180, IS_ROTATE_BKG_180, extension_none)
- else SET_OPT_ID(is_check_dogear, IS_CHECK_DOG_EAR, extension_none)
- else SET_OPT_ID(dogear_size, DOG_EAR_SIZE, extension_none)
- else SET_OPT_ID(is_check_skew, IS_CHECK_ASKEW, extension_none)
- else SET_OPT_ID(skew_range, ASKEW_RANGE, extension_none)
- else SET_OPT_ID(black_white_threshold, BINARY_THRESHOLD, extension_none)
- else SET_OPT_ID(is_photo_mode, IS_PHOTO_MODE, extension_none)
- else SET_OPT_ID(double_feed_handle, DOUBLE_FEED_HANDLE, extension_none)
- else SET_OPT_ID(scan_when_paper_on, WAIT_TO_SCAN, extension_none)
- else SET_OPT_ID(feed_strength, FEED_STRENGTH, extension_none)
- else SET_OPT_ID(power_scheme, TIME_TO_SLEEP, extension_none)
- else SET_OPT_ID(is_auto_strength, IS_AUTO_FEED_STRENGTH, extension_none)
- else SET_OPT_ID(feed_strength_value , FEED_STRENGTH_VALUE, extension_none)
- else SET_OPT_ID(is_reverse_bw, REVERSE_01, extension_none)
- else SET_OPT_ID(is_erase_hole_l, RID_HOLE_L, extension_none)
- else SET_OPT_ID(search_hole_range_l, SEARCH_HOLE_RANGE_L, extension_none)
- else SET_OPT_ID(is_erase_hole_r, RID_HOLE_R, extension_none)
- else SET_OPT_ID(search_hole_range_r, SEARCH_HOLE_RANGE_R, extension_none)
- else SET_OPT_ID(is_erase_hole_t, RID_HOLE_T, extension_none)
- else SET_OPT_ID(search_hole_range_t, SEARCH_HOLE_RANGE_T, extension_none)
- else SET_OPT_ID(is_erase_hole_b, RID_HOLE_B, extension_none)
- else SET_OPT_ID(search_hole_range_b, SEARCH_HOLE_RANGE_B, extension_none)
- else SET_OPT_ID(fold_direction, FOLD_TYPE, extension_none)
- else SET_OPT_ID(fold_type, FOLD_TYPE, extension_none)
- else SET_OPT_ID(color_correction, COLOR_CORRECTION, extension_none)
- op_id++;
- }
-
-#define EX_APPENDIX_API(name) \
- { \
- EXAPI ea; \
- ea.ind = ex_##name##_id_ = ex_id_++; \
- ea.ex_api = &scanner::handle_ex_##name; \
- ea.base_ind = -1; \
- ex_opts_.push_back(ea); \
- }
- EX_APPENDIX_API(final_compression);
- EX_APPENDIX_API(final_format);
- EX_APPENDIX_API(serial);
- EX_APPENDIX_API(to_be_scan);
- EX_APPENDIX_API(scan_with_hole);
- EX_APPENDIX_API(device_code);
- EX_APPENDIX_API(power);
- EX_APPENDIX_API(hardware_version);
- EX_APPENDIX_API(ip);
-
- if (black_white_threshold_id_ == -1)
- black_white_threshold_id_ = 0x8836;
-
- if (is_erase_hole_id_ == -1)
- {
- // 兼容老的除孔算法
- EXAPI ea;
-
- ea.ind = is_erase_hole_id_ = ex_id_++;
- ea.base_ind = is_erase_hole_l_id_;
- ea.ex_api = &scanner::handle_ex_erase_hole;
- ex_opts_.push_back(ea);
-
- ea.ind = search_hole_range_id_ = ex_id_++;
- ea.base_ind = search_hole_range_l_id_;
- ea.ex_api = &scanner::handle_ex_search_hole_range;
- ex_opts_.push_back(ea);
- }
-
- return ret;
-}
-int scanner::control_read_string(int code, std::string& ret)
-{
- return scanner::control_read_string(handle_, code, ret);
-}
-
-void scanner::extension_none(int id)
-{
-}
-void scanner::extension_multiout_type(int id)
-{
- EXAPI ea;
-
- ex_multiout_type_id_ = ex_id_++;
- ea.ind = ex_multiout_type_id_;
- ea.base_ind = id;
- ea.ex_api = &scanner::handle_ex_multiout;
-
- ex_opts_.push_back(ea);
-}
-void scanner::extension_color_mode(int id)
-{
- EXAPI ea;
-
- ea.ind = ex_color_mode_id_ = ex_id_++;
- ea.base_ind = id;
- ea.ex_api = &scanner::handle_ex_color_mode;
- ex_opts_.push_back(ea);
-
- ex_auto_color_type_id_ = ex_id_++;
- ea.base_ind = id;
- ea.ind = ex_auto_color_type_id_;
- ea.ex_api = &scanner::handle_ex_auto_color_type;
- ex_opts_.push_back(ea);
-}
-void scanner::extension_sharpen(int id)
-{
- EXAPI ea;
-
- ex_sharpen_id_ = ex_id_++;
- ea.base_ind = id;
- ea.ind = ex_sharpen_id_;
- ea.ex_api = &scanner::handle_ex_sharpen;
-
- ex_opts_.push_back(ea);
-}
-void scanner::extension_paper(int id)
-{
- EXAPI ea;
-
- ea.ind = ex_paper_id_ = ex_id_++;
- ea.base_ind = id;
- ea.ex_api = &scanner::handle_ex_paper;
- ex_opts_.push_back(ea);
-
- ea.ind = ex_paper_lateral_id_ = ex_id_++;
- ea.base_ind = id;
- ea.ex_api = &scanner::handle_ex_paper_lateral;
- ex_opts_.push_back(ea);
-
- ea.ind = ex_auto_paper_size_id_ = ex_id_++;
- ea.base_ind = id;
- ea.ex_api = &scanner::handle_ex_auto_paper_size;
- ex_opts_.push_back(ea);
-
- ea.ind = ex_is_paper_auto_crop_id_ = ex_id_++;
- ea.base_ind = id;
- ea.ex_api = &scanner::handle_ex_auto_paper_crop;
- ex_opts_.push_back(ea);
-}
-void scanner::extension_fill_bkg_method(int id)
-{
- EXAPI ea;
-
- ea.ind = ex_fill_background_id_ = ex_id_++;
- ea.base_ind = id;
- ea.ex_api = &scanner::handle_ex_fill_background;
- ex_opts_.push_back(ea);
-}
-void scanner::extension_text_direction(int id)
-{
- EXAPI ea;
-
- ea.ind = ex_text_direction_id_ = ex_id_++;
- ea.base_ind = id;
- ea.ex_api = &scanner::handle_ex_text_direction;
- ex_opts_.push_back(ea);
-}
-void scanner::extension_page(int id)
-{
- EXAPI ea;
- wchar_t msg[128] = { 0 };
-
- ea.ind = ex_duplex_id_ = ex_id_++;
- ea.base_ind = id;
- ea.ex_api = &scanner::handle_ex_duplex;
- ex_opts_.push_back(ea);
- {
- swprintf_s(msg, _countof(msg) - 1, L"handle_ex_duplex of id: %d\r\n", ea.ind);
- log_info(msg, 0);
- }
-
- ea.ind = ex_discard_blank_page_id_ = ex_id_++;
- ea.base_ind = id;
- ea.ex_api = &scanner::handle_ex_discard_blank_page;
- ex_opts_.push_back(ea);
- {
- swprintf_s(msg, _countof(msg) - 1, L"handle_ex_discard_blank_page of id: %d\r\n", ea.ind);
- log_info(msg, 0);
- }
-
- ea.ind = ex_discard_blank_receipt_id_ = ex_id_++;
- ea.base_ind = id;
- ea.ex_api = &scanner::handle_ex_discard_blank_receipt;
- ex_opts_.push_back(ea);
- {
- swprintf_s(msg, _countof(msg) - 1, L"handle_ex_discard_blank_receipt of id: %d\r\n", ea.ind);
- log_info(msg, 0);
- }
-
- ea.ind = ex_is_page_fold_id_ = ex_id_++;
- ea.base_ind = id;
- ea.ex_api = &scanner::handle_ex_page_fold;
- ex_opts_.push_back(ea);
- {
- swprintf_s(msg, _countof(msg) - 1, L"handle_ex_page_fold of id: %d\r\n", ea.ind);
- log_info(msg, 0);
- }
-}
-void scanner::extension_erase_color(int id)
-{
- EXAPI ea;
-
- ea.ind = ex_color_filter_id_ = ex_id_++;
- ea.base_ind = id;
- ea.ex_api = &scanner::handle_ex_color_filter;
- ex_opts_.push_back(ea);
-
- ea.ind = ex_color_enhance_id_ = ex_id_++;
- ea.base_ind = id;
- ea.ex_api = &scanner::handle_ex_color_enhance;
- ex_opts_.push_back(ea);
-}
-bool scanner::get_option_value_with_parent(int sn, set_opt_value setv, void* param) // return true if handled
-{
- bool handled = true;
-
- if (sn == scan_count_id_)
- {
- SANE_Option_Descriptor* parent = hg_sane_middleware::instance()->get_option_descriptor(handle_, (const void*)scan_mode_id_);
- char* buf = new char[parent->size + 4];
-
- memset(buf, 0, parent->size);
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)scan_mode_id_, buf);
- handled = compare_sane_opt(local_trans::lang_trans_between_hz936(OPTION_VALUE_SMZS_LXSM, true, nullptr), buf);
- delete[] buf;
- if (handled)
- {
- int count = -1;
- value_role role = VAL_ROLE_CURRENT;
- buf = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)scan_mode_id_);
- if (compare_sane_opt(local_trans::lang_trans_between_hz936(OPTION_VALUE_SMZS_LXSM, true, nullptr), buf))
- role = value_role(role | VAL_ROLE_DEFAULT);
- local_utility::free_memory(buf);
-
- setv(&count, value_role(VAL_ROLE_CURRENT | VAL_ROLE_DEFAULT), VAL_LIMIT_NONE, param);
- }
- }
- else
- handled = false;
-
- return handled;
-}
-bool scanner::set_option_value_with_parent(int sn, void* data, int* err) // return true if handled sn
-{
- bool handled = false;
-
- if (sn == scan_count_id_)
- {
- SANE_Option_Descriptor* parent = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)scan_mode_id_);
- char* val = new char[parent->size + 4];
- SANE_Int after = 0;
-
- memset(val, 0, parent->size + 4);
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)scan_mode_id_, val);
- if (compare_sane_opt(local_trans::lang_trans_between_hz936(OPTION_VALUE_SMZS_LXSM, true, nullptr), val))
- {
- if (*(int*)data != -1)
- {
- strcpy(val, local_trans::lang_trans_between_hz936(OPTION_VALUE_SMZS_SMZDZS, true, nullptr));
- *err = hg_sane_middleware::instance()->set_option(handle_, (void*)scan_mode_id_, SANE_ACTION_SET_VALUE, val, &after);
- }
- }
- else if (*(int*)data == -1)
- {
- strcpy(val, local_trans::lang_trans_between_hz936(OPTION_VALUE_SMZS_LXSM, true, nullptr));
- *err = hg_sane_middleware::instance()->set_option(handle_, (void*)scan_mode_id_, SANE_ACTION_SET_VALUE, val, &after);
- }
- delete[] val;
- }
-
- return handled;
-}
-int scanner::set_option_value(int sn, SANE_Value_Type type, int size, void* data)
-{
- char* buf = NULL;
- SANE_Bool sb = SANE_FALSE;
- SANE_Int si = 0, after = 0;
- SANE_Fixed sf = 0;
- int ret = SCANNER_ERR_OK;
- void* val = data;
-
- if (type == SANE_TYPE_BOOL)
- {
- sb = *(bool*)data ? SANE_TRUE : SANE_FALSE;
- val = &sb;
- }
- else if (type == SANE_TYPE_INT)
- {
- si = *(int*)data;
- val = &si;
- }
- else if (type == SANE_TYPE_FIXED)
- {
- sf = SANE_FIX(*(float*)data);
- val = &sf;
- }
- else
- {
- buf = new char[size + 4];
- memset(buf, 0, size + 4);
- strcpy(buf, ((std::string*)data)->c_str());
- val = buf;
- }
-
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)sn, SANE_ACTION_SET_VALUE, val, &after);
-
- if (type == SANE_TYPE_BOOL)
- {
- *(bool*)data = sb == SANE_TRUE;
- }
- else if (type == SANE_TYPE_INT)
- {
- *(int*)data = si;
- }
- else if (type == SANE_TYPE_FIXED)
- {
- *(float*)data = (float)SANE_UNFIX(sf);
- }
- else if(buf)
- {
- strcpy((char*)val, buf);
- delete[] buf;
- }
-
- return ret;
-}
-int scanner::set_is_multiout(bool enable)
-{
- int ret = SCANNER_ERR_OK;
-
- if (is_multiout_id_ > 0)
- {
- SANE_Bool multi = SANE_FALSE;
- SANE_Int after = 0;
-
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)is_multiout_id_, &multi); // parent item ...
- if (enable ^ (multi == SANE_TRUE))
- {
- multi = enable ? SANE_TRUE : SANE_FALSE;
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)is_multiout_id_, SANE_ACTION_SET_VALUE, &multi, &after);
- after = 0;
- }
- }
-
- return ret;
-}
-
-scanner::EXAPIPOS scanner::find_ex_api(int op_id)
-{
- return std::find(ex_opts_.begin(), ex_opts_.end(), op_id);
-}
-void scanner::apply_scheme(gb::sane_config_schm* schm)
-{
- // restore ...
- hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_RESTORE_SETTINGS, nullptr, nullptr);
-
- if (!schm)
- return;
-
- std::string n(""), v(""), ver(schm->get_version());
-
- if (schm->first_config(n, v))
- {
- do
- {
- int id = schm->id_from_name(n.c_str());
- if (id == -1)
- {
- if (gb::sane_config_schm::is_option_data(n))
- {
- id = schm->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
- {
- v = from_default_language(v.c_str(), nullptr);
- void* data = &v[0];
- SANE_Fixed fixed = 0;
- const SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (const void*)id);
- if (desc)
- {
- char* buf = NULL;
- SANE_Int after = 0;
-
- if (desc->type == SANE_TYPE_STRING)
- {
- buf = new char[desc->size + 4];
- memset(buf, 0, desc->size + 4);
- strcpy(buf, v.c_str());
- data = buf;
- }
- hg_sane_middleware::instance()->set_option(handle_, (const void*)id, SANE_ACTION_SET_VALUE, data, &after);
-
- if (buf)
- delete[] buf;
- }
- }
- } while (schm->next_config(n, v));
- }
-}
-
-EX_OPTION_HANDLER_IMPL(multiout)
-{
- int ret = SCANNER_ERR_OK;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
- SANE_Bool parent = SANE_FALSE;
-
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)is_multiout_id_, &parent);
- if (setv)
- {
- char* cur = (char*)hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id),
- * def = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id);
- int now = sane_opt_trans::multiout_value_to_twain(cur),
- init = sane_opt_trans::multiout_value_to_twain(def),
- val = 0;
-
- local_utility::free_memory(def);
- local_utility::free_memory(cur);
-
- {
- // parent item ...
- if (!parent)
- now = MULTI_OUT_NONE;
- }
-
- do
- {
- if (desc->constraint_type == SANE_CONSTRAINT_STRING_LIST)
- {
- // we have no 'MULTI_OUT_NONE' item in this option, this is used as is_multiout_id_
- val = MULTI_OUT_NONE;
- value_role role = val == now ? VAL_ROLE_CURRENT : VAL_ROLE_NONE;
- if (val == init)
- role = (value_role)(role | VAL_ROLE_DEFAULT);
- if (!setv(&val, role, VAL_LIMIT_ENUM, data))
- break;
- for (int i = 0; desc->constraint.string_list[i]; ++i)
- {
- value_role role = VAL_ROLE_NONE;
- val = sane_opt_trans::multiout_value_to_twain(desc->constraint.string_list[i]);
- if (val == now)
- role = VAL_ROLE_CURRENT;
- if (val == init)
- role = value_role(role | VAL_ROLE_DEFAULT);
- if (!setv(&val, role, VAL_LIMIT_ENUM, data))
- break;
- }
- }
- else
- set_cur_and_def_value(now, init, setv, data);
- } while (0);
- }
- else
- {
- char* val = new char[desc->size];
- const char* in = sane_opt_trans::multiout_value_from_twain(*(int*)data);
- SANE_Int after = 0;
-
- if (in && strcmp(in, "\346\227\240"))
- {
- ret = set_is_multiout(true);
- if (ret == SANE_STATUS_GOOD)
- {
- strcpy(val, in);
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, val, &after);
- }
- }
- else
- {
- // disable multi-out, let multiout type aside
- ret = set_is_multiout(false);
- }
- delete[] val;
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(auto_color_type)
-{
- int ret = SCANNER_ERR_OK;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
- int len = desc->size + 4;
- char* buf = new char[len];
-
- memset(buf, 0, len);
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id, buf);
- if (setv)
- {
- char* def = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id);
- int init = sane_opt_trans::auto_color_type_to_twain(def);
-
- local_utility::free_memory(def);
- len = sane_opt_trans::auto_color_type_to_twain(buf);
- set_cur_and_def_value(len, init, setv, data);
- }
- else
- {
- SANE_Int after = 0;
-
- // ret = set_is_multiout(false);
- if (ret == SCANNER_ERR_OK)
- {
- strcpy(buf, sane_opt_trans::auto_color_type_from_twain(*(int*)data));
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, buf, &after);
- }
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
- delete[] buf;
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(color_mode)
-{
- int ret = SCANNER_ERR_OK;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
-
- if (setv)
- {
- char* cur = (char*)hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id),
- * def = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id);
- int now = sane_opt_trans::color_mode_to_twain(cur), // sane_opt_trans::multiout_value_to_twain(cur)
- init = sane_opt_trans::color_mode_to_twain(def),
- val = 0;
-
- local_utility::free_memory(def);
- local_utility::free_memory(cur);
-
- do
- {
- if (desc->constraint_type == SANE_CONSTRAINT_STRING_LIST)
- {
- for (int i = 0; desc->constraint.string_list[i]; ++i)
- {
- value_role role = VAL_ROLE_NONE;
- val = sane_opt_trans::color_mode_to_twain(desc->constraint.string_list[i]);
- if (val == now)
- role = VAL_ROLE_CURRENT;
- if (val == init)
- role = value_role(role | VAL_ROLE_DEFAULT);
- if (!setv(&val, role, VAL_LIMIT_ENUM, data))
- break;
- }
- }
- else
- set_cur_and_def_value(now, init, setv, data);
- } while (0);
- }
- else
- {
- SANE_Int after = 0;
-
- // ret = set_is_multiout(false);
- if (ret == SCANNER_ERR_OK)
- {
- char* val = new char[desc->size];
- const char* in = sane_opt_trans::color_mode_from_twain(*(int*)data);
-
- strcpy(val, in);
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, val, &after);
- delete[] val;
- }
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(sharpen)
-{
- int ret = SCANNER_ERR_OK;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
-
- if (setv)
- {
- char* cur = (char*)hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id),
- * def = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id);
- int now = sane_opt_trans::multiout_value_to_twain(cur),
- init = sane_opt_trans::sharpen_to_twain(def),
- val = 0;
-
- local_utility::free_memory(def);
- local_utility::free_memory(cur);
-
- do
- {
- if (desc->constraint_type == SANE_CONSTRAINT_STRING_LIST)
- {
- for (int i = 0; desc->constraint.string_list[i]; ++i)
- {
- value_role role = VAL_ROLE_NONE;
- val = sane_opt_trans::sharpen_to_twain(desc->constraint.string_list[i]);
- if (val == now)
- role = VAL_ROLE_CURRENT;
- if (val == init)
- role = value_role(role | VAL_ROLE_DEFAULT);
- if (!setv(&val, role, VAL_LIMIT_ENUM, data))
- break;
- }
- }
- else
- set_cur_and_def_value(now, init, setv, data);
- } while (0);
- }
- else
- {
- char* val = new char[desc->size];
- const char* in = sane_opt_trans::sharpen_from_twain(*(int*)data);
- SANE_Int after = 0;
-
- strcpy(val, in);
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, val, &after);
- delete[] val;
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(paper)
-{
- int ret = SCANNER_ERR_OK;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
- int len = desc->size + 4;
- char* buf = new char[len];
-
- memset(buf, 0, len);
- if (setv)
- {
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id, buf);
- char* def = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id);
- int now = sane_opt_trans::paper_to_twain(buf),
- init = sane_opt_trans::paper_to_twain(def),
- val = 0;
-
- local_utility::free_memory(def);
- do
- {
- if (desc->constraint_type == SANE_CONSTRAINT_STRING_LIST)
- {
- for (int i = 0; desc->constraint.string_list[i]; ++i)
- {
- value_role role = VAL_ROLE_NONE;
- val = sane_opt_trans::paper_to_twain(desc->constraint.string_list[i]);
- if (val == -1)
- continue;
- if (val == now)
- role = VAL_ROLE_CURRENT;
- if (val == init)
- role = value_role(role | VAL_ROLE_DEFAULT);
- if (!setv(&val, role, VAL_LIMIT_ENUM, data))
- break;
- }
- }
- else
- set_cur_and_def_value(now, init, setv, data);
- } while (0);
- }
- else if (sane_opt_trans::paper_from_twain(*(int*)data))
- {
- SANE_Int after = 0;
- strcpy(buf, sane_opt_trans::paper_from_twain(*(int*)data));
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, buf, &after);
- }
- else
- ret = SCANNER_ERR_INVALID_PARAMETER;
-
- delete[] buf;
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(paper_lateral)
-{
- int ret = SCANNER_ERR_OK;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
- int len = desc->size + 4;
- char* buf = new char[len];
- const char* lateral_swap = NULL;
- bool lateral = false;
-
- memset(buf, 0, len);
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id, buf);
- lateral_swap = sane_opt_trans::switch_paper_lateral(buf);
- lateral = sane_opt_trans::is_paper_lateral(buf);
- if (setv)
- {
- set_cur_and_def_value(lateral, false, setv, data);
- }
- else if (lateral_swap)
- {
- SANE_Int after = 0;
- if (lateral != *(bool*)data)
- {
- strcpy(buf, lateral_swap);
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, buf, &after);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
- }
- else
- {
- SANE_Int after = 0;
- if (*(bool*)data)
- {
- // set to A4Lateral ...
- strcpy(buf, local_trans::lang_trans_between_hz936(OPTION_VALUE_ZZCC_A4HX, true, nullptr));
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, buf, &after);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
- //ret = SCANNER_ERR_DEVICE_NOT_SUPPORT;
- }
-
- delete[] buf;
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(auto_paper_size)
-{
- int ret = SCANNER_ERR_OK;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
- int len = desc->size + 4;
- char* buf = new char[len];
-
- memset(buf, 0, len);
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id, buf);
- if (setv)
- {
- char* init = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id);
- bool yes = strcmp(buf, local_trans::lang_trans_between_hz936(OPTION_VALUE_ZZCC_PPYSCC, true, nullptr)) == 0,
- def = strcmp(init, local_trans::lang_trans_between_hz936(OPTION_VALUE_ZZCC_PPYSCC, true, nullptr)) == 0;
-
- local_utility::free_memory(init);
- set_cur_and_def_value(yes, def, setv, data);
- }
- else
- {
- SANE_Int after = 0;
- strcpy(buf, *(bool*)data ? local_trans::lang_trans_between_hz936(OPTION_VALUE_ZZCC_PPYSCC, true, nullptr) : local_trans::lang_trans_between_hz936(OPTION_VALUE_ZZCC_A4, true, nullptr));
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, buf, &after);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
- delete[] buf;
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(auto_paper_crop)
-{
- int ret = SCANNER_ERR_OK;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
- int len = desc->size + 4;
- char* buf = new char[len];
-
- memset(buf, 0, len);
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id, buf);
- if (setv)
- {
- char* init = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id);
- bool yes = strcmp(buf, local_trans::lang_trans_between_hz936(OPTION_VALUE_ZZCC_ZDSMCCZDCQ, true, nullptr)) == 0,
- def = strcmp(init, OPTION_VALUE_ZZCC_ZDSMCCZDCQ) == 0;
-
- local_utility::free_memory(init);
- set_cur_and_def_value(yes, def, setv, data);
- }
- else
- {
- SANE_Int after = 0;
- strcpy(buf, *(bool*)data ? local_trans::lang_trans_between_hz936(OPTION_VALUE_ZZCC_ZDSMCCZDCQ, true, nullptr) : local_trans::lang_trans_between_hz936(OPTION_VALUE_ZZCC_ZDSMCC, true, nullptr));
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, buf, &after);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
- delete[] buf;
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(text_direction)
-{
- int ret = SCANNER_ERR_OK;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
- int len = desc->size + 4;
- char* buf = new char[len];
-
- memset(buf, 0, len);
- if (setv)
- {
- char* def = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id);
- float now = .0f, init = sane_opt_trans::text_direction_to_twain(def), val = .0f;
-
- local_utility::free_memory(def);
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id, buf);
- now = sane_opt_trans::text_direction_to_twain(buf);
- do
- {
- if (desc->constraint_type == SANE_CONSTRAINT_STRING_LIST)
- {
- for (int i = 0; desc->constraint.string_list[i]; ++i)
- {
- value_role role = VAL_ROLE_NONE;
- val = sane_opt_trans::text_direction_to_twain(desc->constraint.string_list[i]);
- if (IS_DOUBLE_EQUAL(val, now))
- role = VAL_ROLE_CURRENT;
- if (IS_DOUBLE_EQUAL(val, init))
- role = value_role(role | VAL_ROLE_DEFAULT);
- if (!setv(&val, role, VAL_LIMIT_ENUM, data))
- break;
- }
- }
- else
- set_cur_and_def_value(now, init, setv, data);
- } while (0);
- }
- else
- {
- SANE_Int after = 0;
-
- strcpy(buf, sane_opt_trans::text_direction_from_twain(*(float*)data));
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, buf, &after);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
- delete[] buf;
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(duplex)
-{
- int ret = SCANNER_ERR_OK;
- bool val = *(bool*)data;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
- unsigned len = desc->size + 4;
- char* buf = new char[len];
-
- memset(buf, 0, len);
- if (setv)
- {
- char* init = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id);
-
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id, buf);
- set_cur_and_def_value(strcmp(buf, local_trans::lang_trans_between_hz936(OPTION_VALUE_SMYM_SM, true, nullptr)) == 0, strcmp(init, local_trans::lang_trans_between_hz936(OPTION_VALUE_SMYM_SM, true, nullptr)) == 0, setv, data);
- local_utility::free_memory(init);
- }
- else
- {
- strcpy(buf, val ? local_trans::lang_trans_between_hz936(OPTION_VALUE_SMYM_SM, true, nullptr) : local_trans::lang_trans_between_hz936(OPTION_VALUE_SMYM_DM, true, nullptr));
- SANE_Int after = 0;
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, buf, &after);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
- delete[] buf;
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(fill_background)
-{
- int ret = SCANNER_ERR_OK;
- bool val = *(bool*)data;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
- unsigned len = desc->size + 4;
- char* buf = new char[len];
-
- memset(buf, 0, len);
- if (setv)
- {
- char* init = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id);
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id, buf);
- val = strcmp(buf, local_trans::lang_trans_between_hz936(OPTION_VALUE_SMYM_SM, true, nullptr)) == 0;
- set_cur_and_def_value(strcmp(buf, local_trans::lang_trans_between_hz936(OPTION_VALUE_BJTCFS_TDBX, true, nullptr)) == 0, strcmp(init, local_trans::lang_trans_between_hz936(OPTION_VALUE_BJTCFS_TDBX, true, nullptr)) == 0, setv, data);
- local_utility::free_memory(init);
- }
- else
- {
- strcpy(buf, val ? local_trans::lang_trans_between_hz936(OPTION_VALUE_BJTCFS_TDBX, true, nullptr) : local_trans::lang_trans_between_hz936(OPTION_VALUE_BJTCFS_ADBX, true, nullptr));
- SANE_Int after = 0;
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, buf, &after);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
- delete[] buf;
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(discard_blank_page)
-{
- int ret = SCANNER_ERR_OK;
- bool val = *(bool*)data;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
- unsigned len = desc->size + 4;
- char* buf = new char[len];
-
- memset(buf, 0, len);
- if (setv)
- {
- char* init = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id);
- bool def = strcmp(init, local_trans::lang_trans_between_hz936(OPTION_VALUE_SMYM_TGKBYTY, true, nullptr)) == 0;
-
- local_utility::free_memory(init);
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id, buf);
- val = strcmp(buf, local_trans::lang_trans_between_hz936(OPTION_VALUE_SMYM_TGKBYTY, true, nullptr)) == 0;
- set_cur_and_def_value(val, def, setv, data);
- }
- else
- {
- if (val)
- strcpy(buf, local_trans::lang_trans_between_hz936(OPTION_VALUE_SMYM_TGKBYTY, true, nullptr));
- else
- {
- char* init = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id);
- strcpy(buf, init);
- local_utility::free_memory(init);
- }
- SANE_Int after = 0;
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, buf, &after);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
- delete[] buf;
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(discard_blank_receipt)
-{
- int ret = SCANNER_ERR_OK;
- bool val = *(bool*)data;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
- unsigned len = desc->size + 4;
- char* buf = new char[len];
-
- memset(buf, 0, len);
- if (setv)
- {
- char* init = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id);
- bool def = strcmp(init, local_trans::lang_trans_between_hz936(OPTION_VALUE_SMYM_TGKBYFPZ, true, nullptr)) == 0;
-
- local_utility::free_memory(init);
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id, buf);
- val = strcmp(buf, local_trans::lang_trans_between_hz936(OPTION_VALUE_SMYM_TGKBYFPZ, true, nullptr)) == 0;
- set_cur_and_def_value(val, def, setv, data);
- }
- else
- {
- if (val)
- strcpy(buf, local_trans::lang_trans_between_hz936(OPTION_VALUE_SMYM_TGKBYFPZ, true, nullptr));
- else
- {
- char* init = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id);
- strcpy(buf, init);
- local_utility::free_memory(init);
- }
- SANE_Int after = 0;
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, buf, &after);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
- delete[] buf;
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(page_fold)
-{
- int ret = SCANNER_ERR_OK;
- bool val = *(bool*)data;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
- unsigned len = desc->size + 4;
- char* buf = new char[len];
-
- memset(buf, 0, len);
- if (setv)
- {
- char* init = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id);
- bool def = strcmp(init, local_trans::lang_trans_between_hz936(OPTION_VALUE_SMYM_DZ, true, nullptr)) == 0;
-
- local_utility::free_memory(init);
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id, buf);
- val = strcmp(buf, local_trans::lang_trans_between_hz936(OPTION_VALUE_SMYM_DZ, true, nullptr)) == 0;
- set_cur_and_def_value(val, def, setv, data);
- }
- else
- {
- if (val)
- strcpy(buf, local_trans::lang_trans_between_hz936(OPTION_VALUE_SMYM_DZ, true, nullptr));
- else
- {
- char* init = (char*)hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id);
- strcpy(buf, init);
- local_utility::free_memory(init);
- }
- SANE_Int after = 0;
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, buf, &after);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
- delete[] buf;
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(color_filter) // int (filter_value)
-{
- int ret = SCANNER_ERR_DEVICE_NOT_SUPPORT;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
- char* buf = NULL;
- unsigned int len = 0;
-
- if (desc)
- {
- len = desc->size + 4;
- buf = new char[len];
- memset(buf, 0, len);
- if (setv)
- {
- bool filter = false;
- int val = FILTER_NONE, now = FILTER_NONE;
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id, buf);
- now = sane_opt_trans::filter_enhance_value_to_twain(buf, &filter);
- if (!filter)
- now = val;
- do
- {
- if (desc->constraint_type == SANE_CONSTRAINT_STRING_LIST)
- {
- for (int i = 0; desc->constraint.string_list[i]; ++i)
- {
- value_role role = VAL_ROLE_NONE;
- int v = sane_opt_trans::filter_enhance_value_to_twain(desc->constraint.string_list[i], &filter);
- if (!filter && v != FILTER_NONE)
- continue;
- if (v == now)
- role = VAL_ROLE_CURRENT;
- if (v == val)
- role = value_role(role | VAL_ROLE_DEFAULT);
- if (!setv(&v, role, VAL_LIMIT_ENUM, data))
- break;
- }
- }
- }while (0);
- }
- else
- {
- const char* val = sane_opt_trans::filter_enhance_value_from_twain(*((int*)data), true);
- SANE_Int after = 0;
-
- strcpy(buf, val);
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, buf, &after);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
- delete[] buf;
- }
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(color_enhance) // int (enhance_value)
-{
- int ret = SCANNER_ERR_DEVICE_NOT_SUPPORT;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
- char* buf = NULL;
- unsigned int len = 0;
-
- if (desc)
- {
- len = desc->size + 4;
- buf = new char[len];
- memset(buf, 0, len);
- if (setv)
- {
- bool filter = false;
- int val = ENHANCE_NONE, now = ENHANCE_NONE;
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id, buf);
- now = sane_opt_trans::filter_enhance_value_to_twain(buf, &filter);
- if (filter)
- now = val;
- do
- {
- if (desc->constraint_type == SANE_CONSTRAINT_STRING_LIST)
- {
- for (int i = 0; desc->constraint.string_list[i]; ++i)
- {
- value_role role = VAL_ROLE_NONE;
- int v = sane_opt_trans::filter_enhance_value_to_twain(desc->constraint.string_list[i], &filter);
- if (filter && v != ENHANCE_NONE)
- continue;
- if (v == now)
- role = VAL_ROLE_CURRENT;
- if (v == val)
- role = value_role(role | VAL_ROLE_DEFAULT);
- if (!setv(&v, role, VAL_LIMIT_ENUM, data))
- break;
- }
- }
- } while (0);
- }
- else
- {
- const char* val = sane_opt_trans::filter_enhance_value_from_twain(*((int*)data), false);
- SANE_Int after = 0;
-
- strcpy(buf, val);
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)base_id, SANE_ACTION_SET_VALUE, buf, &after);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
- delete[] buf;
- }
-
- return ret;
-}
-
-EX_OPTION_HANDLER_IMPL(final_compression)
-{
- int ret = SCANNER_ERR_OK;
- int* compression = (int*)data;
- unsigned int len = sizeof(*compression);
-
- if (setv)
- {
- int val = 0;
- ret = hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_GET_FINAL_COMPRESSION, &val, &len);
- if (ret == SANE_STATUS_GOOD)
- {
- int i = SANE_COMPRESSION_FIRST;
- for (; i < SANE_COMPRESSION_LAST; ++i)
- {
- value_role role = VAL_ROLE_NONE;
- if (i == val)
- role = VAL_ROLE_CURRENT;
- if (i == SANE_COMPRESSION_NONE)
- role = value_role(role | VAL_ROLE_DEFAULT);
- int v = sane_opt_trans::compression_to_twain(i);
- if (!setv(&v, role, VAL_LIMIT_ENUM, data))
- break;
- }
- }
- }
- else
- {
- int val = sane_opt_trans::compression_from_twain(*(int*)data);
- len = sizeof(val);
- ret = hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_SET_FINAL_COMPRESSION, &val, &len);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(final_format)
-{
- int ret = SCANNER_ERR_OK;
- SANE_FinalImgFormat ff;
- unsigned int len = sizeof(ff);
-
- if (setv)
- {
- ret = hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_GET_FINAL_IMAGE_FORMAT, &ff, &len);
- if (ret == SANE_STATUS_GOOD)
- {
- int now = ff.img_format, init = SANE_IMAGE_TYPE_BMP;
- std::vector all(sane_opt_trans::support_image_types());
- for (int i = 0; i < (int)all.size(); ++i)
- {
- value_role role = VAL_ROLE_NONE;
- ff.img_format = (SANE_ImageType)all[i];
- if (ff.img_format == now)
- role = VAL_ROLE_CURRENT;
- if (ff.img_format == init)
- role = value_role(role | VAL_ROLE_DEFAULT);
- if (!setv(&ff, role, VAL_LIMIT_ENUM, data))
- break;
- }
- }
- }
- else
- {
- ret = hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_SET_FINAL_IMAGE_FORMAT, data, &len);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(serial)
-{
- int ret = SCANNER_ERR_INVALID_PARAMETER;
- if (setv)
- {
- std::string val("");
-
- ret = control_read_string(IO_CTRL_CODE_GET_SERIAL, val);
- if (ret == SANE_STATUS_GOOD)
- setv(&val, VAL_ROLE_CURRENT, VAL_LIMIT_NONE, data);
- }
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(to_be_scan)
-{
- int ret = SCANNER_ERR_OK;
- SANE_Bool wait_paper = SANE_FALSE;
- unsigned int len = sizeof(wait_paper);
-
- if (setv)
- {
- ret = hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_GET_SCAN_WHEN_PAPER_ON, &wait_paper, &len);
- if (ret == SANE_STATUS_GOOD)
- {
- bool val = wait_paper == SANE_TRUE;
-
- set_cur_and_def_value(val, false, setv, data);
- }
- }
- else
- {
- wait_paper = *((bool*)data) ? SANE_TRUE : SANE_FALSE;
- ret = hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_SET_SCAN_WHEN_PAPER_ON, &wait_paper, &len);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(scan_with_hole)
-{
- int ret = SCANNER_ERR_OK;
- SANE_Bool with_hole = SANE_FALSE;
- unsigned int len = sizeof(with_hole);
-
- if (setv)
- {
- ret = hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_GET_SCAN_WITH_HOLE, &with_hole, &len);
- if (ret == SANE_STATUS_GOOD)
- {
- bool val = with_hole == SANE_TRUE;
-
- set_cur_and_def_value(val, false, setv, data);
- }
- }
- else
- {
- with_hole = *((bool*)data) ? SANE_TRUE : SANE_FALSE;
- ret = hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_SET_SCAN_WITH_HOLE, &with_hole, &len);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(device_code)
-{
- int ret = SCANNER_ERR_INVALID_PARAMETER;
- if (setv)
- {
- std::string val("");
-
- ret = control_read_string(IO_CTRL_CODE_GET_DEVICE_CODE, val);
- if (ret == SANE_STATUS_GOOD)
- setv(&val, VAL_ROLE_CURRENT, VAL_LIMIT_NONE, data);
- }
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(power)
-{
- int ret = SCANNER_ERR_OK;
-
- if (setv)
- {
- SANE_Power now = SANE_POWER_MINUTES_30, init = SANE_POWER_MINUTES_30;
- unsigned int len = sizeof(now);
-
- hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_GET_POWER_LEVEL, &now, &len);
- for (int i = SANE_POWER_FIRST; i < SANE_POWER_LAST; ++i)
- {
- value_role role = VAL_ROLE_NONE;
- if (i == now)
- role = VAL_ROLE_CURRENT;
- if (i == init)
- role = value_role(role | VAL_ROLE_DEFAULT);
-
- SANE_Power power = (SANE_Power)i;
- if (!setv(&power, role, VAL_LIMIT_ENUM, data))
- break;
- }
- }
- else
- {
- SANE_Power power = *((SANE_Power*)data);
- unsigned int len = sizeof(power);
- ret = hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_SET_POWER_LEVEL, &power, &len);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(hardware_version)
-{
- int ret = SCANNER_ERR_INVALID_PARAMETER;
- if (setv)
- {
- std::string val("");
-
- ret = control_read_string(IO_CTRL_CODE_GET_HARDWARE_VERSION, val);
- if (ret == SANE_STATUS_GOOD)
- setv(&val, VAL_ROLE_CURRENT, VAL_LIMIT_NONE, data);
- }
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(ip)
-{
- int ret = SCANNER_ERR_INVALID_PARAMETER;
- if (setv)
- {
- std::string val("");
-
- ret = control_read_string(IO_CTRL_CODE_GET_IP, val);
- if (ret == SANE_STATUS_GOOD)
- setv(&val, VAL_ROLE_CURRENT, VAL_LIMIT_NONE, data);
- }
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(erase_hole)
-{
- int ret = SCANNER_ERR_DEVICE_NOT_SUPPORT;
- if (is_erase_hole_l_id_ != -1 || is_erase_hole_r_id_ != -1)
- {
- SANE_Bool yes = SANE_FALSE, def = SANE_FALSE;
- SANE_Int after = 0;
- if (setv)
- {
- if (is_erase_hole_l_id_ != -1)
- {
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)is_erase_hole_l_id_, &yes);
- hg_sane_middleware::instance()->get_def_value(handle_, (void*)is_erase_hole_l_id_, &def);
- }
- if (!yes && is_erase_hole_r_id_ != -1)
- {
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)is_erase_hole_r_id_, &yes);
- hg_sane_middleware::instance()->get_def_value(handle_, (void*)is_erase_hole_r_id_, &def);
- }
-
- set_cur_and_def_value(yes == SANE_TRUE, def == SANE_TRUE, setv, data);
- ret = SCANNER_ERR_OK;
- }
- else
- {
- yes = *(bool*)data ? SANE_TRUE : SANE_FALSE;
- if (is_erase_hole_l_id_ != -1)
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)is_erase_hole_l_id_, SANE_ACTION_SET_VALUE, &yes, &after);
- yes = *(bool*)data ? SANE_TRUE : SANE_FALSE;
- if (is_erase_hole_r_id_ != -1)
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)is_erase_hole_r_id_, SANE_ACTION_SET_VALUE, &yes, &after);
- }
- }
-
- return ret;
-}
-EX_OPTION_HANDLER_IMPL(search_hole_range)
-{
- int ret = SCANNER_ERR_DEVICE_NOT_SUPPORT;
- if (search_hole_range_l_id_ != -1 || search_hole_range_r_id_ != -1)
- {
- SANE_Fixed val = 0;
- SANE_Int after = 0;
- double rv = .0f, def = .0f;
- if (setv)
- {
- const SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)base_id);
- void* init = hg_sane_middleware::instance()->get_def_value(handle_, (void*)base_id),
- * cur = hg_sane_middleware::instance()->get_cur_value(handle_, (void*)base_id);
- float n = SANE_UNFIX(*(SANE_Fixed*)cur),
- d = SANE_UNFIX(*(SANE_Fixed*)init);
-
- if (desc->constraint_type == SANE_CONSTRAINT_RANGE)
- {
- float l = SANE_UNFIX(desc->constraint.range->min),
- u = SANE_UNFIX(desc->constraint.range->max),
- s = SANE_UNFIX(desc->constraint.range->quant);
- set_value_range(*(SANE_Fixed*)cur, *(SANE_Fixed*)init, desc->constraint.range->min, desc->constraint.range->max, desc->constraint.range->quant, setv, data, &scanner::to_float);
- }
- else
- set_cur_and_def_value(n, d, setv, data);
- local_utility::free_memory(init);
- local_utility::free_memory(cur);
-
- ret = SCANNER_ERR_OK;
- }
- else
- {
- rv = (double)*(float*)data;
- val = SANE_FIX(rv);
- if (search_hole_range_l_id_ != -1)
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)search_hole_range_l_id_, SANE_ACTION_SET_VALUE, &val, &after);
- val = SANE_FIX(rv);
- if (search_hole_range_r_id_ != -1)
- ret = hg_sane_middleware::instance()->set_option(handle_, (void*)search_hole_range_r_id_, SANE_ACTION_SET_VALUE, &val, &after);
- }
- }
-
- return ret;
-}
-
-// ISaneInvoker
-COM_API_IMPLEMENT(scanner, int, start(void))
-{
- int ret = SANE_STATUS_GOOD;
-
- ev_cnt_ = 0;
- events_.clear();
- images_.clear();
- scan_msg_ = "OK";
- scan_err_ = false;
- user_cancel_ = false;
- app_wnd_ = setting_.get() ? setting_->hwnd() : callback::find_main_wnd();
- ret = hg_sane_middleware::instance()->start(handle_, NULL);
-
- // the third-APPs in linux will call 'stop' after every start, but it not happens in windows-apps, so we handle this as following ...
- if(ret == SANE_STATUS_NO_DOCS && prev_start_result_ == SANE_STATUS_GOOD)
- ret = hg_sane_middleware::instance()->start(handle_, NULL);
-
- if (ret == SANE_STATUS_GOOD)
- {
- if (indicator_.get() && !IsWindowVisible(indicator_->hwnd()))
- indicator_->show(true);
-
- unsigned int l = sizeof(img_fmt_);
- SANE_CompressionType cmprsn = img_fmt_.compress.compression;
- if (hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_GET_FINAL_IMAGE_FORMAT, &img_fmt_, &l))
- img_fmt_.img_format = SANE_IMAGE_TYPE_BMP;
- img_fmt_.compress.compression = cmprsn;
- }
- //else if (indicator_.get())
- //{
- // indicator_->notify_scan_over(hg_scanner_err_description(ret), true);
- //}
- else
- {
- std::wstring msg(local_trans::a2u(hg_scanner_err_description(ret), CP_UTF8));
-
- if (indicator_.get())
- indicator_->show(false);
- if (!IsWindow(app_wnd_))
- callback::bring_message_box_topmost(local_trans::lang_trans_between_hz936(CONST_STRING_START_FAILED).c_str());
- MessageBoxW(app_wnd_, msg.c_str(), local_trans::lang_trans_between_hz936(CONST_STRING_START_FAILED).c_str(), MB_OK | MB_ICONERROR);
- }
- prev_start_result_ = ret;
- is_scanning_ = ret == SANE_STATUS_GOOD;
-
- return local_utility::sane_statu_2_scanner_err(ret);
-}
-COM_API_IMPLEMENT(scanner, int, stop(void))
-{
- user_cancel_ = true;
- return hg_sane_middleware::instance()->stop(handle_);
-}
-COM_API_IMPLEMENT(scanner, int, get_event(void))
-{
- return events_.take();
-}
-COM_API_IMPLEMENT(scanner, void, set_event_callback(int(__stdcall* handle_ev)(int, void*), void* para))
-{
- scanner_ev_handler_ = handle_ev;
- evh_param_ = para;
-}
-COM_API_IMPLEMENT(scanner, bool, wait_image(DWORD milliseconds))
-{
- int count = get_scanned_images(milliseconds);
-
- return count > 0;
-}
-COM_API_IMPLEMENT(scanner, int, get_scanned_images(DWORD milliseconds))
-{
- size_t count = images_.count();
- DWORD elapse = 10;
-
- is_ui_wait_img_ = true;
- while (is_scanning_ && count == 0 && milliseconds)
- {
- MSG msg = { 0 };
- if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
- {
- TranslateMessage(&msg);
- DispatchMessageW(&msg);
- }
- else
- Sleep(elapse);
-
- int ev = get_event();
-
- count = images_.count();
- if (ev == SANE_EVENT_SCAN_FINISHED)
- {
- ui_hide();
- break;
- }
- else if (ev == SANE_EVENT_UI_CLOSE_CANCEL)
- {
- stop();
- ui_hide();
- break;
- }
- else if (ev == SANE_EVENT_UI_CLOSE_NORMAL)
- {
- ui_hide();
- break;
- }
- if (milliseconds != -1)
- {
- if (milliseconds <= elapse)
- break;
-
- milliseconds -= elapse;
- }
- }
- is_ui_wait_img_ = false;
- count = images_.count();
-
- {
- wchar_t msg[128] = { 0 };
- swprintf_s(msg, _countof(msg) - 1, L"Wait image count = %d\r\n", count);
- log_info(msg, 0);
- }
-
- return count;
-}
-COM_API_IMPLEMENT(scanner, IScanImg*, take_first_image(twain_xfer xfer))
-{
- scanned_img* img = images_.take();
-
- return dynamic_cast(img);
-}
-COM_API_IMPLEMENT(scanner, bool, get_first_image_header(SANE_Parameters* header, size_t* bytes, int* dpi))
-{
- return images_.get_header(header, bytes, dpi);
-}
-COM_API_IMPLEMENT(scanner, bool, is_online(void))
-{
- std::string sn("");
-
- return handle_ && control_read_string(IO_CTRL_CODE_GET_SERIAL, sn) != SCANNER_ERR_DEVICE_NOT_FOUND;
-}
-COM_API_IMPLEMENT(scanner, bool, is_paper_on(void))
-{
- SANE_Bool on = SANE_FALSE;
- unsigned int len = sizeof(on);
-
- if (hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_GET_PAPER_ON, &on, &len) == SANE_STATUS_GOOD)
- return on == SANE_TRUE;
- else
- return false;
-}
-COM_API_IMPLEMENT(scanner, int, last_error(void))
-{
- return err_;
-}
-
-COM_API_IMPLEMENT(scanner, bool, get_option_info(int sn, value_type* type, value_limit* limit, int* bytes))
-{
- EXAPIPOS ex = find_ex_api(sn);
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, ex == ex_opts_.end() ? (void*)sn : (void*)ex->base_ind);
- bool ret = false;
-
- if (desc)
- {
- if (type)
- *type = scanner::from_sane_type(desc->type);
- if (limit)
- *limit = scanner::from_sane_constraint(desc->constraint_type);
- if (bytes)
- *bytes = desc->size;
-
- ret = true;
- }
-
- return ret;
-}
-COM_API_IMPLEMENT(scanner, bool, get_value(int sn, set_opt_value setval, void* param))
-{
- EXAPIPOS ex = find_ex_api(sn);
- int ret = SANE_STATUS_INVAL;
- SANE_Int after = 0;
-
- if (ex == ex_opts_.end())
- {
- if (get_option_value_with_parent(sn, setval, param))
- return true;
-
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)sn);
- void* init = hg_sane_middleware::instance()->get_def_value(handle_, (void*)sn);
- ret = SANE_STATUS_GOOD;
- if (desc->type == SANE_TYPE_BOOL)
- {
- SANE_Bool v = SANE_FALSE;
- bool val = false;
-
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)sn, &v);
- val = v == SANE_TRUE;
- //set_cur_and_def_value(val, *(SANE_Bool*)init == SANE_TRUE, setval, param);
- {
- int role = VAL_ROLE_NONE;
- val = false;
- if (*(SANE_Bool*)init == SANE_FALSE)
- role |= VAL_ROLE_DEFAULT;
- if (v == SANE_FALSE)
- role |= VAL_ROLE_CURRENT;
- setval(&val, (value_role)role, VAL_LIMIT_ENUM, param);
- val = true;
- role = VAL_ROLE_NONE;
- if (*(SANE_Bool*)init == SANE_TRUE)
- role |= VAL_ROLE_DEFAULT;
- if (v == SANE_TRUE)
- role |= VAL_ROLE_CURRENT;
- setval(&val, (value_role)role, VAL_LIMIT_ENUM, param);
- }
- }
- else if (desc->type == SANE_TYPE_INT)
- {
- SANE_Int cur = 0, def = *(SANE_Int*)init;
- int val = 0;
-
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)sn, &cur);
- val = cur;
- if (sn == resolution_id_)
- dpi_ = cur;
- do
- {
- if (desc->constraint_type == SANE_CONSTRAINT_RANGE)
- {
- set_value_range(cur, def, desc->constraint.range->min, desc->constraint.range->max, desc->constraint.range->quant, setval, param, scanner::to_int);
- }
- else if (desc->constraint_type == SANE_CONSTRAINT_WORD_LIST)
- {
- const SANE_Word* v = desc->constraint.word_list;
- for (int i = 0; i < v[0]; ++i)
- {
- value_role role = VAL_ROLE_NONE;
- if (v[i + 1] == cur)
- role = value_role(role | VAL_ROLE_CURRENT);
- if (v[i + 1] == *(SANE_Int*)init)
- role = value_role(role | VAL_ROLE_DEFAULT);
- val = v[i + 1];
- if (!setval(&val, role, VAL_LIMIT_ENUM, param))
- break;
- }
- }
- else
- set_cur_and_def_value(val, *(SANE_Int*)init, setval, param);
-
- }while (0);
- }
- else if (desc->type == SANE_TYPE_FIXED)
- {
- SANE_Fixed cur = 0, def = *(SANE_Fixed*)init;
- float val = .0f;
-
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)sn, &cur);
- if (sn == resolution_id_)
- dpi_ = (int)(SANE_UNFIX(cur) + .5f);
- do
- {
- if (desc->constraint_type == SANE_CONSTRAINT_RANGE)
- {
- set_value_range(cur, def, desc->constraint.range->min, desc->constraint.range->max, desc->constraint.range->quant, setval, param, scanner::to_float);
- }
- else if (desc->constraint_type == SANE_CONSTRAINT_WORD_LIST)
- {
- const SANE_Word* v = desc->constraint.word_list;
- for (int i = 0; i < v[0]; ++i)
- {
- value_role role = VAL_ROLE_NONE;
- if (v[i + 1] == cur)
- role = value_role(role | VAL_ROLE_CURRENT);
- if (v[i + 1] == def)
- role = value_role(role | VAL_ROLE_DEFAULT);
- val = (float)SANE_UNFIX(v[i + 1]);
- if (!setval(&val, role, VAL_LIMIT_ENUM, param))
- break;
- }
- }
- else
- set_cur_and_def_value(val, (float)SANE_UNFIX(*(SANE_Fixed*)init), setval, param);
- } while (0);
- }
- else if (desc->type == SANE_TYPE_STRING)
- {
- char* buf = new char[desc->size + 4];
- std::string val(""), def((char*)init);
-
- memset(buf, 0, desc->size + 4);
- hg_sane_middleware::instance()->get_cur_value(handle_, (void*)sn, buf);
- val = buf;
- do
- {
- if (desc->constraint_type == SANE_CONSTRAINT_STRING_LIST)
- {
- for (int i = 0; desc->constraint.string_list[i]; ++i)
- {
- value_role role = VAL_ROLE_NONE;
- if (strcmp(desc->constraint.string_list[i], buf) == 0)
- role = value_role(role | VAL_ROLE_CURRENT);
- if (strcmp(desc->constraint.string_list[i], (char*)init) == 0)
- role = value_role(role | VAL_ROLE_DEFAULT);
-
- val = desc->constraint.string_list[i];
- if (!setval(&val, role, VAL_LIMIT_ENUM, param))
- break;
- }
- }
- else
- set_cur_and_def_value(val, def, setval, param);
- } while (0);
- delete[] buf;
- }
- else
- {
- ret = SANE_STATUS_INVAL;
- }
- local_utility::free_memory(init);
- }
- else
- {
- ret = (this->*ex->ex_api)(ex->base_ind, param, setval);
- }
-
- return ret == SANE_STATUS_GOOD;
-}
-COM_API_IMPLEMENT(scanner, int, set_value(int sn, void* val))
-{
- EXAPIPOS ex = find_ex_api(sn);
- int ret = SANE_STATUS_INVAL;
- SANE_Int after = 0;
- SANE_Option_Descriptor* desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)sn);
-
- {
- wchar_t msg[256] = { 0 };
- if (ex == ex_opts_.end())
- swprintf_s(msg, _countof(msg) - 1, L"set_value of %s(%s) of ID %d\r\n", local_trans::a2u(desc->name, CP_UTF8).c_str(), local_trans::a2u(hg_sane_middleware::option_value_2_string(desc->type, val).c_str(), CP_UTF8).c_str(), sn);
- else if(ex->base_ind != -1)
- {
- desc = hg_sane_middleware::instance()->get_option_descriptor(handle_, (void*)ex->base_ind);
- swprintf_s(msg, _countof(msg) - 1, L"set_value of %s(0x%x) of ID %d, base id = %d)\r\n", local_trans::a2u(desc->name, CP_UTF8).c_str(), *(unsigned*)val, sn, ex->base_ind);
- }
- log_info(msg, 0);
- }
-
- twain_set_ = true;
- if (ex == ex_opts_.end())
- {
- if (!set_option_value_with_parent(sn, val, &ret))
- ret = set_option_value(sn, desc->type, desc->size, val);
- ret = local_utility::sane_statu_2_scanner_err(ret);
- }
- else
- {
- ret = (this->*ex->ex_api)(ex->base_ind, val, NULL);
- }
-
- if (sn == resolution_id_)
- {
- if (desc->type == SANE_TYPE_FIXED)
- dpi_ = (int)(*(float*)val + .5f);
- else
- dpi_ = *(int*)val;
- }
-
- return ret;
-}
-COM_API_IMPLEMENT(scanner, int, convert_image(SANE_ImageFormatConvert* conv))
-{
- return hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_CONVERT_IMAGE_FORMAT, conv, NULL);
-}
-COM_API_IMPLEMENT(scanner, void, free_buffer(void* buf, int len))
-{
- hg_sane_middleware::instance()->io_control(handle_, IO_CTRL_CODE_FREE_MEMORY, buf, (unsigned int*)&len);
-}
-
-// SANE options ID ...
-SANE_OPTION_ID_IMPLEMENT(color_correction)
-SANE_OPTION_ID_IMPLEMENT(fold_type)
-SANE_OPTION_ID_IMPLEMENT(is_multiout)
-SANE_OPTION_ID_IMPLEMENT(multiout_type)
-SANE_OPTION_ID_IMPLEMENT(color_mode)
-SANE_OPTION_ID_IMPLEMENT(erase_color)
-SANE_OPTION_ID_IMPLEMENT(erase_multiout_red)
-SANE_OPTION_ID_IMPLEMENT(erase_paper_red)
-SANE_OPTION_ID_IMPLEMENT(is_erase_background)
-SANE_OPTION_ID_IMPLEMENT(background_color_range)
-SANE_OPTION_ID_IMPLEMENT(sharpen)
-SANE_OPTION_ID_IMPLEMENT(erase_morr)
-SANE_OPTION_ID_IMPLEMENT(erase_grids)
-SANE_OPTION_ID_IMPLEMENT(error_extend)
-SANE_OPTION_ID_IMPLEMENT(is_noise_modify)
-SANE_OPTION_ID_IMPLEMENT(noise_threshold)
-SANE_OPTION_ID_IMPLEMENT(paper)
-SANE_OPTION_ID_IMPLEMENT(is_custom_area)
-SANE_OPTION_ID_IMPLEMENT(curstom_area_l)
-SANE_OPTION_ID_IMPLEMENT(curstom_area_r)
-SANE_OPTION_ID_IMPLEMENT(curstom_area_t)
-SANE_OPTION_ID_IMPLEMENT(curstom_area_b)
-SANE_OPTION_ID_IMPLEMENT(is_size_check)
-SANE_OPTION_ID_IMPLEMENT(page)
-SANE_OPTION_ID_IMPLEMENT(blank_page_threshold)
-SANE_OPTION_ID_IMPLEMENT(resolution)
-SANE_OPTION_ID_IMPLEMENT(image_quality)
-SANE_OPTION_ID_IMPLEMENT(is_swap)
-SANE_OPTION_ID_IMPLEMENT(is_split)
-SANE_OPTION_ID_IMPLEMENT(is_auto_deskew)
-SANE_OPTION_ID_IMPLEMENT(is_custom_gamma)
-SANE_OPTION_ID_IMPLEMENT(bright)
-SANE_OPTION_ID_IMPLEMENT(contrast)
-SANE_OPTION_ID_IMPLEMENT(gamma)
-SANE_OPTION_ID_IMPLEMENT(is_erase_black_frame)
-SANE_OPTION_ID_IMPLEMENT(deep_sample)
-SANE_OPTION_ID_IMPLEMENT(threshold)
-SANE_OPTION_ID_IMPLEMENT(anti_noise)
-SANE_OPTION_ID_IMPLEMENT(margin)
-SANE_OPTION_ID_IMPLEMENT(fill_background)
-SANE_OPTION_ID_IMPLEMENT(is_anti_permeate)
-SANE_OPTION_ID_IMPLEMENT(anti_permeate_level)
-SANE_OPTION_ID_IMPLEMENT(is_erase_hole)
-SANE_OPTION_ID_IMPLEMENT(search_hole_range)
-SANE_OPTION_ID_IMPLEMENT(is_filling_color)
-SANE_OPTION_ID_IMPLEMENT(is_ultrasonic_check)
-SANE_OPTION_ID_IMPLEMENT(is_check_staple)
-SANE_OPTION_ID_IMPLEMENT(scan_mode)
-SANE_OPTION_ID_IMPLEMENT(scan_count)
-SANE_OPTION_ID_IMPLEMENT(text_direction)
-SANE_OPTION_ID_IMPLEMENT(is_rotate_bkg180)
-SANE_OPTION_ID_IMPLEMENT(is_check_dogear)
-SANE_OPTION_ID_IMPLEMENT(dogear_size)
-SANE_OPTION_ID_IMPLEMENT(is_check_skew)
-SANE_OPTION_ID_IMPLEMENT(skew_range)
-SANE_OPTION_ID_IMPLEMENT(black_white_threshold)
-SANE_OPTION_ID_IMPLEMENT(is_photo_mode)
-SANE_OPTION_ID_IMPLEMENT(double_feed_handle)
-SANE_OPTION_ID_IMPLEMENT(scan_when_paper_on)
-SANE_OPTION_ID_IMPLEMENT(feed_strength)
-SANE_OPTION_ID_IMPLEMENT(power_scheme)
-SANE_OPTION_ID_IMPLEMENT(is_auto_strength)
-SANE_OPTION_ID_IMPLEMENT(feed_strength_value)
-SANE_OPTION_ID_IMPLEMENT(is_reverse_bw)
-SANE_OPTION_ID_IMPLEMENT(is_erase_hole_l)
-SANE_OPTION_ID_IMPLEMENT(search_hole_range_l)
-SANE_OPTION_ID_IMPLEMENT(is_erase_hole_r)
-SANE_OPTION_ID_IMPLEMENT(search_hole_range_r)
-SANE_OPTION_ID_IMPLEMENT(is_erase_hole_t)
-SANE_OPTION_ID_IMPLEMENT(search_hole_range_t)
-SANE_OPTION_ID_IMPLEMENT(is_erase_hole_b)
-SANE_OPTION_ID_IMPLEMENT(search_hole_range_b)
-SANE_OPTION_ID_IMPLEMENT(fold_direction)
-
-// SANE-ex option ID:
-SANE_OPTION_ID_IMPLEMENT(ex_multiout_type)
-SANE_OPTION_ID_IMPLEMENT(ex_auto_color_type)
-SANE_OPTION_ID_IMPLEMENT(ex_color_mode)
-SANE_OPTION_ID_IMPLEMENT(ex_sharpen)
-SANE_OPTION_ID_IMPLEMENT(ex_paper)
-SANE_OPTION_ID_IMPLEMENT(ex_paper_lateral)
-SANE_OPTION_ID_IMPLEMENT(ex_auto_paper_size)
-SANE_OPTION_ID_IMPLEMENT(ex_is_paper_auto_crop)
-SANE_OPTION_ID_IMPLEMENT(ex_text_direction)
-SANE_OPTION_ID_IMPLEMENT(ex_duplex)
-SANE_OPTION_ID_IMPLEMENT(ex_fill_background)
-SANE_OPTION_ID_IMPLEMENT(ex_discard_blank_page)
-SANE_OPTION_ID_IMPLEMENT(ex_discard_blank_receipt)
-SANE_OPTION_ID_IMPLEMENT(ex_is_page_fold)
-SANE_OPTION_ID_IMPLEMENT(ex_color_filter)
-SANE_OPTION_ID_IMPLEMENT(ex_color_enhance)
-SANE_OPTION_ID_IMPLEMENT(ex_final_compression)
-SANE_OPTION_ID_IMPLEMENT(ex_final_format)
-SANE_OPTION_ID_IMPLEMENT(ex_serial)
-SANE_OPTION_ID_IMPLEMENT(ex_to_be_scan)
-SANE_OPTION_ID_IMPLEMENT(ex_scan_with_hole)
-SANE_OPTION_ID_IMPLEMENT(ex_device_code)
-SANE_OPTION_ID_IMPLEMENT(ex_power)
-SANE_OPTION_ID_IMPLEMENT(ex_hardware_version)
-SANE_OPTION_ID_IMPLEMENT(ex_ip)
-
-COM_API_IMPLEMENT(scanner, void, twain_set_transfer(twain_xfer xfer))
-{
- xfer_ = xfer;
-}
-COM_API_IMPLEMENT(scanner, void, twain_set_compression(SANE_CompressionType compression, void* detail))
-{
- img_fmt_.compress.compression = compression;
- img_fmt_.compress.detail = detail;
-}
-COM_API_IMPLEMENT(scanner, int, twain_get_config(char* buf, size_t* len))
-{
- if (cfg_)
- {
- std::string cont(cfg_->to_text_stream());
-
- if (*len < cont.length())
- {
- *len = cont.length() + 4;
-
- return SCANNER_ERR_INSUFFICIENT_MEMORY;
- }
- strcpy(buf, cont.c_str());
- }
-
- return SCANNER_ERR_OK;
-}
-COM_API_IMPLEMENT(scanner, int, twain_set_config(char* buf, size_t len))
-{
- if(cfg_ && cfg_->load_mem(buf))
- {
- update_config();
- apply_config();
-
- return SCANNER_ERR_OK;
- }
-
- return SCANNER_ERR_DATA_DAMAGED;
-}
-
-
-// ui ...
-COM_API_IMPLEMENT(scanner, bool, ui_show_main(HWND parent))
-{
- return false;
-}
-COM_API_IMPLEMENT(scanner, bool, ui_show_setting(HWND parent, bool with_scan, bool indicator))
-{
- if (callback::show_setting_ui)
- {
- auto cb = [&](int ev)
- {
- on_ui_event(ev, NULL);
- };
- callback::show_setting_ui(handle_, parent, &sane_api_, with_scan, cb);
- }
- else if (cfg_)
- {
- if (with_scan)
- {
- events_.clear();
- images_.clear();
- scan_msg_ = "OK";
- scan_err_ = false;
- }
-
- size_t pid = scanner_name_.find(L" - ");
- if (pid == -1)
- pid = scanner_name_.length();
- setting_.reset(new dlg_setting(parent, &sane_api_, handle_, with_scan, scanner_name_.substr(0, pid).c_str()));
- setting_->set_ui_event_notify(&scanner::ui_callback, this);
- setting_->set_config(cfg_, (cfg_path_ + scanner_name_.substr(0, pid) + L".cfg").c_str(), &scanner::apply_scheme, this, &twain_set_);
- indicator_.reset();
- if (indicator)
- {
- indicator_.reset(new dlg_indicator(setting_->hwnd()));
- indicator_->set_ui_event_notify(&scanner::ui_callback, this);
- }
- setting_->show(true);
- }
-
- return true;
-}
-COM_API_IMPLEMENT(scanner, bool, ui_show_progress(HWND parent))
-{
- if (callback::show_progress_ui)
- {
- }
- else
- {
- if (setting_.get() && IsWindowVisible(setting_->hwnd()))
- parent = setting_->hwnd();
- else if (!IsWindow(parent))
- parent = callback::find_main_wnd();
-
- indicator_.reset(new dlg_indicator(parent));
- indicator_->set_ui_event_notify(&scanner::ui_callback, this);
- indicator_->show(true);
- }
-
- return true;
-}
-COM_API_IMPLEMENT(scanner, void, ui_hide(void))
-{
- if (indicator_.get())
- indicator_.reset();
- if (setting_.get())
- setting_.reset();
-}
-COM_API_IMPLEMENT(scanner, bool, ui_is_ok(void))
-{
- return true;
-}
-
-
-
-// called from device-layer ...
-int scanner::handle_device_event(int ev_code, void* data, unsigned int* len)
-{
- if (ev_code == SANE_EVENT_WORKING)
- {
- if (indicator_.get())
- indicator_->notify_working();
- else
- on_ui_event(ev_code, (void*)ev_code);
-
- log_info(L"Scanning ...\r\n", 0);
- }
- else if (ev_code == SANE_EVENT_IMAGE_OK)
- {
- SANE_Image* simg = (SANE_Image*)data;
- scanned_img* img = NULL;
- wchar_t name[40] = { 0 };
-
- swprintf_s(name, _countof(name) - 1, L"img_%05u.bmp", ++img_ind_);
- img = new scanned_img(handle_, simg->header, simg->data, simg->bytes, simg->flag.dpi, (tmp_path_ + name).c_str(), xfer_, &img_fmt_);
- if (img->bytes() /*>= simg->bytes*/)
- {
- size_t bytes = 0;
- int times = 0;
-
- images_.count(&bytes);
- img->set_image_status((SANE_Image_Statu)simg->flag.statu);
- bytes /= 1024 * 1024;
- while (bytes > max_img_mem_ && !user_cancel_ && times++ < 20) // memory control
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(5));
- images_.count(&bytes);
- bytes /= 1024 * 1024;
- if (times == 1)
- log_info(L"Memory usage upto limit! wait up to 100 ms ...\r\n", 0);
- }
- images_.save(img, img->bytes());
- }
- else
- {
- img->release();
- }
- if (indicator_.get())
- indicator_->notify_data_arrived(true);
-
- {
- wchar_t msg[128] = { 0 };
- swprintf_s(msg, _countof(msg) - 1, L"New image(%u) received with %u bytes\r\n", img_ind_, simg->bytes);
- log_info(msg, 0);
- }
- }
- else if (ev_code == SANE_EVENT_USB_DATA_RECEIVED)
- {
- if (indicator_.get())
- indicator_->notify_data_arrived(false);
- }
- else if (ev_code == SANE_EVENT_SCAN_FINISHED)
- {
- err_ = *len;
- if (indicator_.get())
- indicator_->notify_scan_over((char*)data, *len != SCANNER_ERR_OK);
- else
- {
- if (*len)
- {
- std::wstring msg(local_trans::a2u((char*)data, CP_UTF8));
- if(!IsWindow(app_wnd_))
- callback::bring_message_box_topmost(local_trans::lang_trans_between_hz936(CONST_STRING_ERROR).c_str());
- MessageBoxW(app_wnd_, msg.c_str(), local_trans::lang_trans_between_hz936(CONST_STRING_ERROR).c_str(), MB_OK);
- }
- on_ui_event(ev_code, (void*)ev_code);
- }
- // is_scanning_ = false;
-
- {
- wchar_t msg[128] = { 0 };
- swprintf_s(msg, _countof(msg) - 1, L"Scan finished with error: %u\r\n", *len);
- log_info(msg, 0);
- }
- }
-
- return 0;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// log ...
-#include
-
-std::mutex g_lock_;
-std::string g_path_file_("");
-FILE* g_file_ = NULL;
-
-void init_log(void)
-{
- char* tmp = getenv("LOCALAPPDATA");
- if (tmp)
- {
- std::string path(tmp);
- char name[MAX_PATH] = { 0 }, * last = NULL;
-
- path += std::string("\\") + PRODUCT_VENDOR + "Scan\\Log\\";
- mkdir(path.c_str());
- GetModuleFileNameA(NULL, name, _countof(name) - 1);
- last = strrchr(name, '\\');
- if (last++ == NULL)
- last = name;
- path += last;
- path += "_twain.log";
- g_file_ = fopen(path.c_str(), "a+b");
- g_path_file_ = path;
- }
- else
- {
- char name[MAX_PATH] = { 0 }, * last = NULL;
- std::string path("");
-
- GetModuleFileNameA(NULL, name, _countof(name) - 1);
- path = std::string(name) + "_twain.log";
- g_file_ = fopen(path.c_str(), "a+b");
- g_path_file_ = path;
- }
- if (g_file_)
- {
- fseek(g_file_, 0, SEEK_END);
- if (ftell(g_file_))
- {
- std::wstring sep(L"\r\n\r\n\r\n=======================================================\r\n");
- fwrite(sep.c_str(), 2, sep.length(), g_file_);
- }
- else
- {
- unsigned short bom = 0x0feff;
- fwrite(&bom, sizeof(bom), 1, g_file_);
- }
-
- wchar_t ts[128] = { 0 }, now[40] = { 0 };
-
- hg_get_current_time_w(now);
- swprintf_s(ts, _countof(ts) - 1, L"==================%s==================\r\n", now);
- fwrite(ts, 2, lstrlenW(ts), g_file_);
- }
-}
-void close_log(void)
-{
- if (g_file_)
- fclose(g_file_);
- g_file_ = NULL;
-}
-void log(const wchar_t* info)
-{
- if (g_file_)
- {
- std::lock_guard lock(g_lock_);
-
- fwrite(info, 2, lstrlenW(info), g_file_);
- fflush(g_file_);
- if (ftell(g_file_) > 10 * 1024 * 1024)
- {
- fclose(g_file_);
- remove(g_path_file_.c_str());
- g_file_ = fopen(g_path_file_.c_str(), "a+b");
- if (g_file_)
- {
- unsigned short bom = 0x0feff;
- wchar_t ts[128] = { 0 }, now[40] = { 0 };
-
- hg_get_current_time_w(now);
- swprintf_s(ts, _countof(ts) - 1, L"==================%s (Truncated when size > 10MB) ==================\r\n", now);
- fwrite(&bom, sizeof(bom), 1, g_file_);
- fwrite(ts, 2, lstrlenW(ts), g_file_);
- }
- }
- }
-}
-
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// exports
-extern "C"
-{
-#ifdef EXPORT_SANE_API
- __declspec(dllexport)
-#else
- __declspec(dllimport)
-#endif
- int __stdcall initialize(void* reserve)
- {
- init_log();
- callback::init_ui();
-
- hg_sane_middleware::set_callback(callback::sane_event_callback, NULL);
- if (hg_sane_middleware::instance()->is_ready())
- return SANE_STATUS_GOOD;
- else
- return SCANNER_ERR_LANG_PAK_LOST;
- }
-#ifdef EXPORT_SANE_API
- __declspec(dllexport)
-#else
- __declspec(dllimport)
-#endif
- int __stdcall open_scanner(SCANNERID scanner_id, ISaneInvoker** invoker)
- {
- if (!invoker)
- return SCANNER_ERR_INVALID_PARAMETER;
-
- if (!is_scanner_online(scanner_id))
- return SCANNER_ERR_DEVICE_NOT_FOUND;
-
- scanner* scn = new scanner(scanner_id);
- if (scn->last_error() == SCANNER_ERR_OK)
- {
- *invoker = dynamic_cast(scn);
-
- return 0;
- }
- else
- {
- int ret = scn->last_error();
-
- scn->release();
- *invoker = NULL;
-
- return ret;
- }
- }
-#ifdef EXPORT_SANE_API
- __declspec(dllexport)
-#else
- __declspec(dllimport)
-#endif
- bool __stdcall is_scanner_online(SCANNERID scanner_id)
- {
- std::vector que;
-
- scanner::get_scanner_name(scanner_id, que);
-
- return !que.empty();
- }
-#ifdef EXPORT_SANE_API
- __declspec(dllexport)
-#else
- __declspec(dllimport)
-#endif
- int __stdcall uninitialize(void* reserve)
- {
- hg_sane_middleware::set_callback(NULL, NULL);
- hg_sane_middleware::clear();
- close_log();
-
- return 0;
- }
-#ifdef EXPORT_SANE_API
- __declspec(dllexport)
-#else
- __declspec(dllimport)
-#endif
- void __stdcall log_info(const wchar_t* info, int level)
- {
- log(info);
- }
-
-}
diff --git a/sane/scanner.h b/sane/scanner.h
deleted file mode 100644
index 59fab90..0000000
--- a/sane/scanner.h
+++ /dev/null
@@ -1,330 +0,0 @@
-#pragma once
-
-#include "scanned_img.h"
-#include
-#include
-#include
-
-#define SANE_OPTION_ID(name) \
- SANE_OPTION_ID_OVERRIDE(name); \
- int name##_id_ = -1;
-#define SANE_OPTION_ID_IMPLEMENT(name) \
- SANE_OPTION_IMPLEMENT(scanner, name) \
- { \
- return name##_id_; \
- }
-
-#define EX_HANDLER_PROTO(name) \
- int name(int base_id, void* data, set_opt_value setv)
-#define EX_OPTION_HANDLER_DECL(name) EX_HANDLER_PROTO(handle_ex_##name)
-#define EX_OPTION_HANDLER_IMPL(name) EX_HANDLER_PROTO(scanner::handle_ex_##name)
-
-#define EXTENSION_ID_BASE 0x300
-
-#include "DlgPage.h"
-class dlg_indicator;
-class dlg_setting;
-namespace gb
-{
- class scanner_cfg;
-}
-
-class scanner : public ISaneInvoker, virtual public refer
-{
- SANE_Handle handle_;
- SCANNERID id_;
- int err_;
- int ex_id_;
- int prev_start_result_;
- int dpi_;
- unsigned int img_ind_;
- std::wstring scanner_name_;
- std::wstring tmp_path_;
- std::wstring cfg_path_;
- std::string scan_msg_;
- bool scan_err_;
- volatile bool is_ui_wait_img_;
- volatile bool is_scanning_;
- volatile bool user_cancel_;
- twain_xfer xfer_;
- safe_img_queue images_;
- size_t max_img_mem_;
- safe_queue events_; //如果有界面,则全部保存从界面传回的消息;否则只保存开始扫描和结束扫描的事件
- int ev_cnt_;
- SANE_FinalImgFormat img_fmt_;
- std::unique_ptr indicator_;
- std::unique_ptr setting_;
- gb::scanner_cfg* cfg_;
- bool twain_set_;
- SANEAPI sane_api_;
-
- int(__stdcall* scanner_ev_handler_)(int, void*);
- void* evh_param_;
- HWND app_wnd_; // for MessageBox
-
- void transport_config_file(void);
- void update_config(void);
- void load_config(const wchar_t* file);
- void save_config(const wchar_t* file);
- void apply_config(void);
- void on_ui_event(int uev, void* sender);
- std::string choose_scanner(const std::vector& scanners);
- int open(void);
- int close(void);
- int init_options_id(void);
- int control_read_string(int code, std::string& ret);
-
- void extension_none(int id);
- void extension_multiout_type(int id);
- void extension_color_mode(int id);
- void extension_sharpen(int id);
- void extension_paper(int id);
- void extension_fill_bkg_method(int id);
- void extension_text_direction(int id);
- void extension_page(int id);
- void extension_erase_color(int id);
-
- bool get_option_value_with_parent(int sn, set_opt_value setv, void* param); // return true if handled
- bool set_option_value_with_parent(int sn, void* data, int* err); // return true if handled sn
- int set_option_value(int sn, SANE_Value_Type type, int size, void* data);
- int set_is_multiout(bool enable);
-
- typedef struct _ex_api
- {
- unsigned int ind;
- unsigned int base_ind;
- int(scanner::* ex_api)(int, void*, set_opt_value);
- bool operator==(const int& id)
- {
- return ind == id;
- }
- }EXAPI;
- std::vector ex_opts_;
- typedef std::vector::iterator EXAPIPOS;
- EXAPIPOS find_ex_api(int op_id);
- void apply_scheme(gb::sane_config_schm* schm);
-;
- EX_OPTION_HANDLER_DECL(multiout);
- EX_OPTION_HANDLER_DECL(auto_color_type);
- EX_OPTION_HANDLER_DECL(color_mode);
- EX_OPTION_HANDLER_DECL(sharpen); // int
- EX_OPTION_HANDLER_DECL(paper);
- EX_OPTION_HANDLER_DECL(paper_lateral);
- EX_OPTION_HANDLER_DECL(auto_paper_size);
- EX_OPTION_HANDLER_DECL(auto_paper_crop);
- EX_OPTION_HANDLER_DECL(text_direction);
- EX_OPTION_HANDLER_DECL(duplex);
- EX_OPTION_HANDLER_DECL(fill_background); // bool true - 凸多边形
- EX_OPTION_HANDLER_DECL(discard_blank_page);
- EX_OPTION_HANDLER_DECL(discard_blank_receipt);
- EX_OPTION_HANDLER_DECL(page_fold);
- EX_OPTION_HANDLER_DECL(color_filter);
- EX_OPTION_HANDLER_DECL(color_enhance);
-
- EX_OPTION_HANDLER_DECL(final_compression); // int
- EX_OPTION_HANDLER_DECL(final_format); // SANE_FinalImgFormat
- EX_OPTION_HANDLER_DECL(serial); // std::string
- EX_OPTION_HANDLER_DECL(to_be_scan); // bool
- EX_OPTION_HANDLER_DECL(scan_with_hole); // bool
- EX_OPTION_HANDLER_DECL(device_code); // std::string
- EX_OPTION_HANDLER_DECL(power); // int
- EX_OPTION_HANDLER_DECL(hardware_version); // std::string
- EX_OPTION_HANDLER_DECL(ip); // std::string
- EX_OPTION_HANDLER_DECL(erase_hole);
- EX_OPTION_HANDLER_DECL(search_hole_range);
-
-
- template
- bool set_cur_and_def_value(T cur, T def, set_opt_value setv, void* param)
- {
- if (cur == def)
- return setv(&cur, (value_role)(VAL_ROLE_CURRENT | VAL_ROLE_DEFAULT), VAL_LIMIT_NONE, param);
- else if (setv(&cur, VAL_ROLE_CURRENT, VAL_LIMIT_NONE, param))
- return setv(&def, VAL_ROLE_DEFAULT, VAL_LIMIT_NONE, param);
-
- return false;
- }
- template
- void set_value_range(S cur, S def, S l, S u, S s, set_opt_value setv, void* param, T(__stdcall* to_t)(S))
- {
- T v = to_t(cur);
- while (setv(&v, VAL_ROLE_CURRENT, VAL_LIMIT_RANGE, param))
- {
- v = to_t(def);
- if (!setv(&v, VAL_ROLE_DEFAULT, VAL_LIMIT_RANGE, param))
- break;
-
- v = to_t(l);
- if (!setv(&v, VAL_ROLE_LOWER, VAL_LIMIT_RANGE, param))
- break;
- v = to_t(u);
- if (!setv(&v, VAL_ROLE_UPPER, VAL_LIMIT_RANGE, param))
- break;
- v = to_t(s);
- setv(&v, VAL_ROLE_STEP, VAL_LIMIT_RANGE, param);
-
- break;
- }
- }
-
- static int __stdcall to_int(SANE_Int v);
- static float __stdcall to_float(SANE_Fixed v);
- static void __stdcall ui_callback(int uev, void* sender, void* param);
- static bool is_option_float(int sn, void* param);
- static void __stdcall apply_scheme(gb::sane_config_schm* schm, void* param);
-
-public:
- scanner(SCANNERID id);
-protected:
- ~scanner();
-
-public:
- static bool is_belong_serial(int vid, int pid, SCANNERID serial);
- static void get_scanner_name(SCANNERID id, std::vector& names);
- static value_type from_sane_type(SANE_Value_Type type);
- static value_limit from_sane_constraint(SANE_Constraint_Type type);
- static int control_read_string(SANE_Handle hdev, int code, std::string& str);
-
- // IRef
-public:
- COM_API_OVERRIDE(long, add_ref(void));
- COM_API_OVERRIDE(long, release(void));
-
- // ISaneInvoker
-public:
- COM_API_OVERRIDE(int, start(void));
- COM_API_OVERRIDE(int, stop(void));
- COM_API_OVERRIDE(int, get_event(void));
- COM_API_OVERRIDE(void, set_event_callback(int(__stdcall* handle_ev)(int, void*) = NULL, void* para = NULL));
- COM_API_OVERRIDE(bool, wait_image(DWORD milliseconds = -1));
- COM_API_OVERRIDE(int, get_scanned_images(DWORD milliseconds = 0));
- COM_API_OVERRIDE(IScanImg*, take_first_image(twain_xfer xfer = TWAIN_XFER_Native)); // call 'release' on returned value, plz
- COM_API_OVERRIDE(bool, get_first_image_header(SANE_Parameters* header, size_t* bytes = NULL, int* dpi = NULL));
- COM_API_OVERRIDE(bool, is_online(void));
- COM_API_OVERRIDE(bool, is_paper_on(void));
- COM_API_OVERRIDE(int, last_error(void));
- COM_API_OVERRIDE(bool, get_option_info(int sn, value_type* type, value_limit* limit, int* bytes));
- COM_API_OVERRIDE(bool, get_value(int sn, set_opt_value, void* param));
- COM_API_OVERRIDE(int, set_value(int sn, void* val));
- COM_API_OVERRIDE(int, convert_image(SANE_ImageFormatConvert* conv));
- COM_API_OVERRIDE(void, free_buffer(void* buf, int len));
-
- // SANE options ID ...
- SANE_OPTION_ID(color_correction); // 2023-02-24 15:31:19 色偏校正
- SANE_OPTION_ID(fold_type); // 2023-02-24 15:28:46 对折模式
- SANE_OPTION_ID(is_multiout);
- SANE_OPTION_ID(multiout_type);
- SANE_OPTION_ID(color_mode);
- SANE_OPTION_ID(erase_color);
- SANE_OPTION_ID(erase_multiout_red);
- SANE_OPTION_ID(erase_paper_red);
- SANE_OPTION_ID(is_erase_background);
- SANE_OPTION_ID(background_color_range);
- SANE_OPTION_ID(sharpen);
- SANE_OPTION_ID(erase_morr);
- SANE_OPTION_ID(erase_grids); // 除网纹
- SANE_OPTION_ID(error_extend);
- SANE_OPTION_ID(is_noise_modify);
- SANE_OPTION_ID(noise_threshold);
- SANE_OPTION_ID(paper);
- SANE_OPTION_ID(is_custom_area);
- SANE_OPTION_ID(curstom_area_l);
- SANE_OPTION_ID(curstom_area_r);
- SANE_OPTION_ID(curstom_area_t);
- SANE_OPTION_ID(curstom_area_b);
- SANE_OPTION_ID(is_size_check);
- SANE_OPTION_ID(page);
- SANE_OPTION_ID(blank_page_threshold); // 跳过空白页灵敏度
- SANE_OPTION_ID(resolution);
- SANE_OPTION_ID(image_quality);
- SANE_OPTION_ID(is_swap); // 交换正反面
- SANE_OPTION_ID(is_split); // 图像拆分
- SANE_OPTION_ID(is_auto_deskew); // 自动纠偏
- SANE_OPTION_ID(is_custom_gamma);
- SANE_OPTION_ID(bright);
- SANE_OPTION_ID(contrast);
- SANE_OPTION_ID(gamma);
- SANE_OPTION_ID(is_erase_black_frame); // bool
- SANE_OPTION_ID(deep_sample);
- SANE_OPTION_ID(threshold);
- SANE_OPTION_ID(anti_noise); // 抗噪等级
- SANE_OPTION_ID(margin);
- SANE_OPTION_ID(fill_background);
- SANE_OPTION_ID(is_anti_permeate);
- SANE_OPTION_ID(anti_permeate_level);
- SANE_OPTION_ID(is_erase_hole);
- SANE_OPTION_ID(search_hole_range);
- SANE_OPTION_ID(is_filling_color); // 色彩填充
- SANE_OPTION_ID(is_ultrasonic_check);
- SANE_OPTION_ID(is_check_staple);
- SANE_OPTION_ID(scan_mode); // 扫描张数
- SANE_OPTION_ID(scan_count); // 扫描数量
- SANE_OPTION_ID(text_direction);
- SANE_OPTION_ID(is_rotate_bkg180);
- SANE_OPTION_ID(is_check_dogear);
- SANE_OPTION_ID(dogear_size);
- SANE_OPTION_ID(is_check_skew);
- SANE_OPTION_ID(skew_range);
- SANE_OPTION_ID(black_white_threshold); // 二值化图像阈值
- SANE_OPTION_ID(is_photo_mode); // 照片模式
- SANE_OPTION_ID(double_feed_handle); // 双张图片处理
- SANE_OPTION_ID(scan_when_paper_on); // 待纸扫描
- SANE_OPTION_ID(feed_strength); // 分纸强度
- SANE_OPTION_ID(power_scheme); // 休眠时间
- SANE_OPTION_ID(is_auto_strength); // 自动搓纸强度
- SANE_OPTION_ID(feed_strength_value); // 自动搓纸强度设定值
- SANE_OPTION_ID(is_reverse_bw); // 黑白图像反色输出
- SANE_OPTION_ID(is_erase_hole_l); // 穿孔移除 - 左
- SANE_OPTION_ID(search_hole_range_l); // 穿孔搜索范围 - 左
- SANE_OPTION_ID(is_erase_hole_r); // 穿孔移除 - 右
- SANE_OPTION_ID(search_hole_range_r); // 穿孔搜索范围 - 右
- SANE_OPTION_ID(is_erase_hole_t); // 穿孔移除 - 上
- SANE_OPTION_ID(search_hole_range_t); // 穿孔搜索范围 - 上
- SANE_OPTION_ID(is_erase_hole_b); // 穿孔移除 - 下
- SANE_OPTION_ID(search_hole_range_b); // 穿孔搜索范围 - 下
- SANE_OPTION_ID(fold_direction); // 对折模式
-
- // SANE-ex option ID:
- SANE_OPTION_ID(ex_multiout_type); // int
- SANE_OPTION_ID(ex_auto_color_type); // int
- SANE_OPTION_ID(ex_color_mode); // int
- SANE_OPTION_ID(ex_sharpen); // int
- SANE_OPTION_ID(ex_paper); // paper_value
- SANE_OPTION_ID(ex_paper_lateral); // bool
- SANE_OPTION_ID(ex_auto_paper_size); // bool
- SANE_OPTION_ID(ex_is_paper_auto_crop); // bool
- SANE_OPTION_ID(ex_text_direction); // float 90, 180, ..., -1 is auto-text-direction
- SANE_OPTION_ID(ex_duplex); // bool
- SANE_OPTION_ID(ex_fill_background); // bool true - 凸多边形
- SANE_OPTION_ID(ex_discard_blank_page); // bool
- SANE_OPTION_ID(ex_discard_blank_receipt); // bool
- SANE_OPTION_ID(ex_is_page_fold); // bool
- SANE_OPTION_ID(ex_color_filter); // int (filter_value)
- SANE_OPTION_ID(ex_color_enhance); // int (enhance_value)
- SANE_OPTION_ID(ex_final_compression); // int
- SANE_OPTION_ID(ex_final_format); // SANE_FinalImgFormat
- SANE_OPTION_ID(ex_serial); // std::string
- SANE_OPTION_ID(ex_to_be_scan); // bool
- SANE_OPTION_ID(ex_scan_with_hole); // bool
- SANE_OPTION_ID(ex_device_code); // std::string
- SANE_OPTION_ID(ex_power); // int
- SANE_OPTION_ID(ex_hardware_version); // std::string
- SANE_OPTION_ID(ex_ip); // std::string
-
- // ui ...
- COM_API_OVERRIDE(bool, ui_show_main(HWND parent));
- COM_API_OVERRIDE(bool, ui_show_setting(HWND parent, bool with_scan, bool indicator = true));
- COM_API_OVERRIDE(bool, ui_show_progress(HWND parent));
- COM_API_OVERRIDE(void, ui_hide(void));
- COM_API_OVERRIDE(bool, ui_is_ok(void));
-
- // twain
- COM_API_OVERRIDE(void, twain_set_transfer(twain_xfer xfer));
- COM_API_OVERRIDE(void, twain_set_compression(SANE_CompressionType compression, void* detail = NULL));
- COM_API_OVERRIDE(int, twain_get_config(char* buf, size_t* len));
- COM_API_OVERRIDE(int, twain_set_config(char* buf, size_t len));
-
- // methods:
-public:
- int handle_device_event(int ev_code, void* data, unsigned int* len);
-};
\ No newline at end of file
diff --git a/sane/ui.cpp b/sane/ui.cpp
deleted file mode 100644
index 7c9c779..0000000
--- a/sane/ui.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-#include "pch.h"
-#include "ui.h"
-
-#include "huagaotwain.h" // for sane_invoker::load_dll
-
-
-twain_ui::twain_ui(const wchar_t* path) : path_(path), dll_(NULL)
- , show_(NULL), hide_(NULL), event_(NULL), hui_(NULL)
- , good_(false)
-{
- good_ = load();
-}
-twain_ui::~twain_ui()
-{
- if (hui_ && hide_)
- hide_(hui_);
-
- if (dll_)
- FreeLibrary(dll_);
-}
-
-bool twain_ui::load()
-{
- std::wstring dll(path_ + L"\\huagaoui.dll");
-
- sane_invoker::load_dll(dll.c_str(), &dll_);
- if (!dll_)
- return false;
-
- show_ = (ui_show_api)GetProcAddress(dll_, "ui_show");
- hide_ = (ui_hide_api)GetProcAddress(dll_, "ui_hide");
- event_ = (handle_event_api)GetProcAddress(dll_, "handle_event");
-
- return show_ && hide_ && event_;
-}
-
-void twain_ui::show_main_ui(LPSANEAPI api)
-{
- type_ = UITYPE::UI_MAIN;
- if (show_)
- hui_ = show_(UITYPE::UI_MAIN, api);
-}
-void twain_ui::show_setting_ui(LPSANEAPI api, bool with_scan)
-{
- if (show_)
- {
- type_ = with_scan ? UITYPE::UI_SETTING_AND_SCAN : UITYPE::UI_SETTING;
- hui_ = show_(type_, api);
- }
-}
-void twain_ui::show_progress_ui(LPSANEAPI api)
-{
- type_ = UITYPE::UI_PROGRESS;
- if (show_)
- hui_ = show_(UITYPE::UI_PROGRESS, api);
-}
-void twain_ui::hide_ui(void)
-{
- if (hui_ && hide_)
- hide_(hui_);
- hui_ = NULL;
-}
-void twain_ui::handle_sane_event(int sane_ev, void* data, unsigned int* len)
-{
- if (event_)
- event_((SANE_Event)sane_ev, data, len);
-}
-
-bool twain_ui::is_ok(void)
-{
- return good_;
-}
-
-bool twain_ui::is_progress_ui_showing(void)
-{
- return type_ == UITYPE::UI_PROGRESS;
-}
\ No newline at end of file
diff --git a/sane/ui.h b/sane/ui.h
deleted file mode 100644
index 3cd151a..0000000
--- a/sane/ui.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#pragma once
-
-#include
-#include
-#include "huagao/huagao_ui.h"
-
-
-class twain_ui
-{
- HMODULE dll_;
- ui_show_api show_;
- ui_hide_api hide_;
- handle_event_api event_;
- ui_handle hui_;
- std::wstring path_;
- bool good_;
- UITYPE type_;
-
- bool load(void);
-
-public:
- twain_ui(const wchar_t* path);
- ~twain_ui();
-
-public:
- void show_main_ui(LPSANEAPI api);
- void show_setting_ui(LPSANEAPI api, bool with_scan);
- void show_progress_ui(LPSANEAPI api);
- void hide_ui(void);
- void handle_sane_event(int sane_ev, void* data, unsigned int* len);
-
- bool is_ok(void);
- bool is_progress_ui_showing(void);
-};
diff --git a/sln/hgscanner.sln b/sln/hgscanner.sln
index 9b65298..b2d57b4 100644
--- a/sln/hgscanner.sln
+++ b/sln/hgscanner.sln
@@ -4,10 +4,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 16.0.33214.272
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sane", "..\sane\sane.vcxproj", "{6EEC8A02-7F98-4422-8ED6-2434D43BD1E1}"
+ ProjectSection(ProjectDependencies) = postProject
+ {9ED4B425-73E0-423E-9712-455E777481B4} = {9ED4B425-73E0-423E-9712-455E777481B4}
+ EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scanner", "..\device\scanner.vcxproj", "{9ED4B425-73E0-423E-9712-455E777481B4}"
+ ProjectSection(ProjectDependencies) = postProject
+ {7776AB6D-6296-4F7A-A6ED-E9A4D6290DD9} = {7776AB6D-6296-4F7A-A6ED-E9A4D6290DD9}
+ EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "twain", "..\twain\twain.vcxproj", "{C3B47CE2-27CE-4509-AB59-3C0F194F0FCE}"
+ ProjectSection(ProjectDependencies) = postProject
+ {6EEC8A02-7F98-4422-8ED6-2434D43BD1E1} = {6EEC8A02-7F98-4422-8ED6-2434D43BD1E1}
+ EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "setup", "setup", "{F6774650-403F-476C-8373-2EA8D4AF06FF}"
EndProject
diff --git a/twain/load_sane.cpp b/twain/load_sane.cpp
deleted file mode 100644
index 9660d61..0000000
--- a/twain/load_sane.cpp
+++ /dev/null
@@ -1,246 +0,0 @@
-#include "pch.h"
-#include "load_sane.h"
-#include
-#include // for SHFileOperationW
-#include "../../sdk/include/huagao/brand.h"
-
-#pragma comment(lib, "shell32.lib")
-
-namespace load_sane_util
-{
- static std::wstring sane_path(L"");
- static HMODULE sane_module(NULL);
- static int (__stdcall* sane_inst)(SCANNERID, ISaneInvoker**) = NULL;
- static int(__stdcall* is_on)(SCANNERID) = NULL;
- static int(__stdcall* init)(void*) = NULL;
- static int(__stdcall* uninit)(void*) = NULL;
- static void(__stdcall* log)(const wchar_t*, int) = NULL;
-
- static std::string u2m(const wchar_t* u, int page)
- {
- char* ansi = NULL;
- int len = 0;
- std::string mb("");
-
- len = WideCharToMultiByte(page, 0, u, lstrlenW(u), NULL, 0, NULL, NULL);
- ansi = new char[len + 2];
- len = WideCharToMultiByte(page, 0, u, lstrlenW(u), ansi, len, NULL, NULL);
- ansi[len--] = 0;
- mb = ansi;
- delete[] ansi;
-
- return mb;
- }
- static std::wstring m2u(const char* m, int page)
- {
- wchar_t* unic = NULL;
- int len = 0;
- std::wstring u(L"");
-
- len = MultiByteToWideChar(page, 0, m, lstrlenA(m), NULL, 0);
- unic = new wchar_t[len + 2];
- len = MultiByteToWideChar(page, 0, m, lstrlenA(m), unic, len);
- unic[len--] = 0;
- u = unic;
- delete[] unic;
-
- return u;
- }
- static std::wstring reg_read(HKEY root, const wchar_t* path, const wchar_t* name)
- {
- HKEY key = NULL;
-
- RegOpenKeyW(root, path, &key);
- if (!key)
- return L"";
-
- wchar_t* buf = NULL;
- DWORD len = 0;
- DWORD type = REG_SZ;
- std::wstring ret(L"");
-
- RegQueryValueExW(key, name, NULL, &type, (LPBYTE)buf, &len);
- if (len)
- {
- buf = new wchar_t[len + 4];
- memset(buf, 0, (len + 4) * sizeof(*buf));
- RegQueryValueExW(key, name, NULL, &type, (LPBYTE)buf, &len);
- ret = buf;
- delete[] buf;
- }
- RegCloseKey(key);
-
- return ret;
- }
- static std::wstring reg_get_app_installing_path(std::wstring* rp = NULL)
- {
- std::wstring path(m2u(PRODUCT_VENDOR, CP_ACP)), key(L"DriverPath");
-
- path.insert(0, L"Software\\");
- path += L"Scan";
-
- if (sizeof(void*) != 4)
- key += L"64";
-
- if (rp)
- *rp = path + L"\\" + key;
-
- return reg_read(HKEY_LOCAL_MACHINE, path.c_str(), key.c_str());
- }
- static int load_dll(const wchar_t* path_dll, HMODULE* dll)
- {
- HMODULE h = LoadLibraryW(path_dll);
- int ret = GetLastError();
- wchar_t info[128] = { 0 };
-
- swprintf_s(info, _countof(info) - 1, L" = %d\r\n", ret);
- OutputDebugStringW((L"[TWAIN]Load: " + std::wstring(path_dll) + info).c_str());
- if (!h && (ret == ERROR_MOD_NOT_FOUND || ret == ERROR_BAD_EXE_FORMAT))
- {
- std::wstring dir(path_dll);
- size_t pos = dir.rfind(L'\\');
- wchar_t path[MAX_PATH] = { 0 };
-
- GetDllDirectoryW(_countof(path) - 1, path);
- if (pos != std::wstring::npos)
- dir.erase(pos);
- OutputDebugStringW((L"[TWAIN]Load: try change directory to " + dir + L"\r\n").c_str());
- SetDllDirectoryW(dir.c_str());
- h = LoadLibraryW(path_dll);
- // h = LoadLibraryExW(path_dll, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
- ret = GetLastError();
- swprintf_s(info, _countof(info) - 1, L" = %d\r\n", ret);
- OutputDebugStringW((L"[TWAIN]Load: " + std::wstring(path_dll) + info).c_str());
- OutputDebugStringW((L"[TWAIN]Load: restore directory to " + std::wstring(path) + L"\r\n").c_str());
- SetDllDirectoryW(path);
- }
-
- if (dll)
- *dll = h;
-
- return ret;
- }
-
- bool initialize(HMODULE me)
- {
- std::wstring reg_path(L"");
- bool ret = false;
- sane_path = reg_get_app_installing_path(®_path);
- if (!sane_path.empty())
- {
- sane_path += L"\\sane.dll";
- load_dll(sane_path.c_str(), &sane_module);
- if (sane_module)
- {
- *((FARPROC*)&init) = GetProcAddress(sane_module, "initialize");
- *((FARPROC*)&sane_inst) = GetProcAddress(sane_module, "open_scanner");
- *((FARPROC*)&is_on) = GetProcAddress(sane_module, "is_scanner_online");
- *((FARPROC*)&uninit) = GetProcAddress(sane_module, "uninitialize");
- *((FARPROC*)&log) = GetProcAddress(sane_module, "log_info");
- ret = is_ok();
- if (ret)
- ret = init(NULL) == 0;
- }
- }
-
- if (!ret)
- MessageBoxW(NULL, (reg_path + L": " + sane_path).c_str(), L"Load scanner driver failed:", MB_OK);
-
- return ret;
- }
- bool is_ok(void)
- {
- wchar_t info[128] = { 0 };
- swprintf_s(info, _countof(info) - 1, L"[TWAIN]Load: sane_inst: %s, is_on: %s, init: %s, uninit: %s\r\n"
- , sane_inst != NULL ? "ok" : "not found"
- , is_on != NULL ? "ok" : "not found"
- , init != NULL ? "ok" : "not found"
- , uninit != NULL ? "ok" : "not found");
-
- return sane_inst != NULL && is_on != NULL && init != NULL && uninit != NULL;
- }
- bool is_online(SCANNERID guid)
- {
- if (is_on)
- return is_on(guid);
- else
- return false;
- }
- ISaneInvoker* open(SCANNERID guid, int* err)
- {
- ISaneInvoker* ret = NULL;
- int code = 0;
-
- if (!err)
- err = &code;
-
- if (sane_inst)
- *err = sane_inst(guid, &ret);
-
- return ret;
- }
- void uninitialize(void)
- {
- sane_inst = NULL;
- is_on = NULL;
- init = NULL;
- log = NULL;
-
- if (uninit)
- uninit(NULL);
- uninit = NULL;
-
- if (sane_module)
- {
- FreeLibrary(sane_module);
- sane_module = NULL;
- }
- sane_path = L"";
- sane_inst = NULL;
- }
- void log_info(const wchar_t* info, int level)
- {
- if (log)
- log(info, level);
- }
-
- std::string utf82ansi(const char* utf8)
- {
- return u2m(m2u(utf8, CP_UTF8).c_str(), CP_ACP);
- }
- std::string ansi2utf8(const char* ansi)
- {
- return u2m(m2u(ansi, CP_ACP).c_str(), CP_UTF8);
- }
- std::wstring ansi2unic(const char* ansi)
- {
- return m2u(ansi, CP_ACP);
- }
-
- int move_file(const char* from, const char* to)
- {
- return move_file(ansi2unic(from).c_str(), ansi2unic(to).c_str());
- }
- int move_file(const wchar_t* from, const wchar_t* to)
- {
- SHFILEOPSTRUCTW fo = { 0 };
- int ret = 0;
- std::wstring _from(from), _to(to ? to : L"");
-
- if (wcsicmp(from, to) == 0)
- return 0;
-
- _from += std::wstring((wchar_t*)&ret, 2); // ended with double '\0'
- fo.pFrom = &_from[0];
- _to += std::wstring((wchar_t*)&ret, 2); // ended with double '\0'
- fo.pTo = &_to[0];
- fo.fFlags = FOF_NO_UI | FOF_NO_CONNECTED_ELEMENTS; // 614 | 2000
- fo.wFunc = FO_MOVE;
-
- ret = SHFileOperationW(&fo);
- if (ret == /*DE_SAMEFILE*/0x71)
- ret = 0;
-
- return ret;
- }
-};
diff --git a/twain/load_sane.h b/twain/load_sane.h
deleted file mode 100644
index 137fe29..0000000
--- a/twain/load_sane.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#pragma once
-
-// utility for loading sane component ...
-
-#include "../sane/s2t_api.h"
-#include
-
-namespace load_sane_util
-{
- bool initialize(HMODULE me);
- bool is_ok(void);
- bool is_online(SCANNERID guid);
- ISaneInvoker* open(SCANNERID guid, int* err);
- void uninitialize(void);
- void log_info(const wchar_t* info, int level);
-
- std::string utf82ansi(const char* utf8);
- std::string ansi2utf8(const char* ansi);
- std::wstring ansi2unic(const char* ansi);
-
- int move_file(const char* from, const char* to);
- int move_file(const wchar_t* from, const wchar_t* to);
-};
-
diff --git a/twain/twain.vcxproj b/twain/twain.vcxproj
index 566b172..17c4b26 100644
--- a/twain/twain.vcxproj
+++ b/twain/twain.vcxproj
@@ -77,32 +77,36 @@
$(SolutionDir)..\..\sdk\include\;$(SolutionDir)..\..\sdk\include\twain\;$(IncludePath)
$(SolutionDir)..\..\release\win\$(PlatformTarget)\OEM\huagao\
$(SolutionDir)..\..\tmp\$(PlatformTarget)\huagao\$(Configuration)\$(ProjectName)\
- $(LibraryPath)
- huagaotwain400.ds
+ $(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\oem\huagao;$(LibraryPath)
+ huagaotwain200.ds
+ true
- $(LibraryPath)
- huagaotwain400.ds
+ $(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\oem\huagao;$(LibraryPath)
+ huagaotwain200.ds
true
$(SolutionDir)..\..\sdk\include\;$(SolutionDir)..\..\sdk\include\twain\;$(IncludePath)
$(SolutionDir)..\..\release\win\$(PlatformTarget)\OEM\huagao\
$(SolutionDir)..\..\tmp\$(PlatformTarget)\huagao\$(Configuration)\$(ProjectName)\
+ true
false
$(SolutionDir)..\..\sdk\include\;$(SolutionDir)..\..\sdk\include\twain\;$(IncludePath)
$(SolutionDir)..\..\release\win\$(PlatformTarget)\OEM\huagao\
$(SolutionDir)..\..\tmp\$(PlatformTarget)\huagao\$(Configuration)\$(ProjectName)\
- $(LibraryPath)
- huagaotwain400.ds
+ $(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\oem\huagao;$(LibraryPath)
+ huagaotwain100.ds
+ false
- $(LibraryPath)
+ $(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\oem\huagao;$(LibraryPath)
huagaotwain400.ds
false
$(SolutionDir)..\..\sdk\include\;$(SolutionDir)..\..\sdk\include\twain\;$(IncludePath)
$(SolutionDir)..\..\release\win\$(PlatformTarget)\OEM\huagao\
$(SolutionDir)..\..\tmp\$(PlatformTarget)\huagao\$(Configuration)\$(ProjectName)\
+ false
@@ -119,16 +123,14 @@
Console
true
$(ProjectDir)twain.def
-
-
+ advapi32.lib
- copy "$(TargetPath)" C:\Windows\twain_32\HuagoTwain\$(TargetName) /y
-move /Y "$(TargetPath)" "$(OutputPath)$(TargetName)"
-mkdir "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
-move /Y "$(OutputPath)$(TargetName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
-move /Y "$(OutputPath)$(TargetName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
-move /Y "$(OutputPath)$(TargetName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+ move /Y "$(TargetDir)$(TargetName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(TargetName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(TargetName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetPath)" "$(TargetDir)$(TargetName)"
+copy /y "$(TargetDir)$(TargetName)" "C:\Windows\twain_32\HuaGoTwain"
@@ -147,16 +149,14 @@ move /Y "$(OutputPath)$(TargetName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(Platf
Console
true
$(ProjectDir)twain.def
-
-
+ advapi32.lib
- copy "$(TargetPath)" C:\Windows\twain_64\HuagoTwain\$(TargetName) /y
-move /Y "$(TargetPath)" "$(OutputPath)$(TargetName)"
-mkdir "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
-move /Y "$(OutputPath)$(TargetName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
-move /Y "$(OutputPath)$(TargetName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
-move /Y "$(OutputPath)$(TargetName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+ move /Y "$(TargetDir)$(TargetName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(TargetName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(TargetName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetPath)" "$(TargetDir)$(TargetName)"
+copy /y "$(TargetDir)$(TargetName)" "C:\Windows\twain_64\HuaGoTwain"
@@ -177,12 +177,13 @@ move /Y "$(OutputPath)$(TargetName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(Platf
true
true
$(ProjectDir)twain.def
-
-
+ advapi32.lib
-
-
+ move /Y "$(TargetDir)$(TargetName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(TargetName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(TargetName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetPath)" "$(TargetDir)$(TargetName)"
@@ -204,16 +205,26 @@ move /Y "$(OutputPath)$(TargetName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(Platf
true
true
$(ProjectDir)twain.def
-
-
+ advapi32.lib
-
-
+ move /Y "$(TargetDir)$(TargetName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(TargetName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetDir)$(TargetName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
+move /Y "$(TargetPath)" "$(TargetDir)$(TargetName)"
+
+
+
+
+
+
+
+
+
@@ -254,27 +265,54 @@ move /Y "$(OutputPath)$(TargetName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(Platf
-
-
+
+ NotUsing
+ NotUsing
+ NotUsing
+ NotUsing
+
+
+ NotUsing
+ NotUsing
+ NotUsing
+ NotUsing
+
+
+ NotUsing
+ NotUsing
+ NotUsing
+ NotUsing
+
+
+ NotUsing
+ NotUsing
+ NotUsing
+ NotUsing
+
+
+ NotUsing
+ NotUsing
+ NotUsing
+ NotUsing
+
+
+ NotUsing
+ NotUsing
+ NotUsing
+ NotUsing
+
-
Create
Create
Create
Create
-
- NotUsing
- NotUsing
- NotUsing
- NotUsing
-
diff --git a/twain/twain.vcxproj.filters b/twain/twain.vcxproj.filters
index 9f05408..993bede 100644
--- a/twain/twain.vcxproj.filters
+++ b/twain/twain.vcxproj.filters
@@ -5,37 +5,49 @@
{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tga;tiff;tif;png;wav;mfcribbon-ms
-
- {668e9513-f6db-4f9d-9e0e-76cb8b5b7882}
-
-
- {df21031b-938a-4a08-ae64-e869e2586201}
-
{89716198-13ed-4593-819e-97f4426c7baa}
{6d97172d-832d-4c93-ad0e-92fdf76af26b}
+
+ {d0f46d55-47e2-4b28-98e4-37435c417da3}
+
+
+ {ccf8d5b8-eea9-4223-87d3-6edea662380f}
+
+
+ {904bc294-9f58-4953-85d2-8cbd009a978f}
+
-
- twain
-
Sources
Sources
-
- Sources
+
+ imports
+
+
+ imports
+
+
+ imports
+
+
+ imports
+
+
+ imports
+
+
+ imports
-
- twain
-
Headers
@@ -48,128 +60,152 @@
Headers
-
- Headers
-
Headers
-
- twain\twpp
+
+ imports
-
- twain\twpp
+
+ imports
-
- twain\twpp
+
+ imports
-
- twain\twpp
+
+ imports
-
- twain\twpp
+
+ imports
-
- twain\twpp
+
+ imports
-
- twain\twpp
+
+ imports
-
- twain\twpp
+
+ Headers\twain
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
-
-
- twain\twpp
+
+ Headers\twain
- twain
+ Headers\twain
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
+
+
+ Headers\twain\twpp
diff --git a/twain/twain/huagaods.cpp b/twain/twain/huagaods.cpp
deleted file mode 100644
index b7634e4..0000000
--- a/twain/twain/huagaods.cpp
+++ /dev/null
@@ -1,3556 +0,0 @@
-#ifdef max
-#undef max
-#endif
-#ifdef min
-#undef min
-#endif
-
-#include
-#include "huagaods.hpp"
-//#include "twpp/twglue.hpp"
-#include
-#include
-#if defined(WIN32) || defined(_WIN64)
-#include
-#include
-#include
-#define mktemp _mktemp
-#endif // WIN32
-
-using namespace std;
-
-#define enum2str(R) #R
-
-#pragma warning(disable: 4700)
-
-using namespace Twpp;
-using namespace std::placeholders;
-
-extern HMODULE me_;
-
-// WIA COM: IStiUSD & IWiaMiniDrv
-
-//custom define caps enum
-enum CapTypeEx : unsigned short {
- CAP_TYPE_EX_FILL_BLACK_BKG = 0x8004,
- CAP_TYPE_EX_ROTATE_BKG_180 = 0x8005,
- CAP_TYPE_EX_SCREW_DETECT = 0x8006,
- CAP_TYPE_EX_ENHANCE_COLOR = 0x8007,
- CAP_TYPE_EX_DARK_SAMPLE = 0x8016,
- CAP_TYPE_EX_FILL_HOLE = 0x8018,
- CAP_TYPE_EX_SCREW_DETECT_LEVEL = 0x8021,
- CAP_TYPE_EX_SHARPEN = 0x8022,
- CAP_TYPE_EX_HARDWARE_VERSION = 0x8025,
- CAP_TYPE_EX_RID_RED = 0x8026,
- CAP_TYPE_EX_FOLD = 0x8037,
- CAP_TYPE_EX_STAPLE_DETECT = 0x8090,
- CAP_TYPE_EX_DISCARD_BLANK_RECEIPT = 0x8091,
- CAP_TYPE_EX_FILL_HOLE_RATIO = 0x8092,
- CAP_TYPE_EX_FLIP = 0x8094, // switch front back
- CAP_TYPE_EX_RID_RED_HSV = 0x8095,
- CAP_TYPE_EX_DOGEAR_DETECT = 0x8096,
- CAP_TYPE_EX_BKG_FILLING_METHOD = 0x8097,
- CAP_TYPE_EX_EDGE_IDENT = 0x8098,
- CAP_TYPE_EX_ANTI_NOISE = 0x8099,
- CAP_TYPE_EX_THRESHOLD = 0x8100,
- CAP_TYPE_EX_DETACH_NOISE = 0x8101,
- CAP_TYPE_EX_DETACH_NOISE_THRESHOLD = 0x8102,
- CAP_TYPE_EX_SIZE_DETECT = 0x8103,
- CAP_TYPE_EX_POWER_LEVEL = 0x8104,
- CAP_TYPE_EX_ENCODE = 0x8105,
- CAP_TYPE_EX_CROP_MODEL = 0x8106,
- CAP_TYPE_EX_DOGEAR_DIST = 0x8107,
- CAP_TYPE_EX_IMAGE_SPLIT = 0x8108,
- CAP_TYPE_EX_FADE_BKG = 0x8109,
- CAP_TYPE_EX_FADE_BKG_VALUE = 0x8110,
- CAP_TYPE_EX_TO_BE_SCAN = 0x8111,
- CAP_TYPE_EX_MULTI_OUT = 0x8112,
- CAP_TYPE_EX_MULTI_OUT_TYPE = 0x8113,
- CAP_TYPE_EX_SCAN_WITH_HOLE = 0x8114,
- CAP_TYPE_EX_IP = 0x8200,
-
- // SANE豸ԭʼ
- CAP_EX_SANE = (int)CapType::CustomBase + 0x800,
- CAP_EX_SANE_is_multiout,
- CAP_EX_SANE_multiout_type,
- CAP_EX_SANE_color_mode,
- CAP_EX_SANE_erase_color,
- CAP_EX_SANE_erase_multiout_red,
- CAP_EX_SANE_erase_paper_red,
- CAP_EX_SANE_is_erase_background,
- CAP_EX_SANE_background_color_range,
- CAP_EX_SANE_sharpen,
- CAP_EX_SANE_erase_morr,
- CAP_EX_SANE_erase_grids,
- CAP_EX_SANE_error_extend,
- CAP_EX_SANE_is_noise_modify,
- CAP_EX_SANE_noise_threshold,
- CAP_EX_SANE_paper,
- CAP_EX_SANE_is_custom_area,
- CAP_EX_SANE_curstom_area_l,
- CAP_EX_SANE_curstom_area_r,
- CAP_EX_SANE_curstom_area_t,
- CAP_EX_SANE_curstom_area_b,
- CAP_EX_SANE_is_size_check,
- CAP_EX_SANE_page,
- CAP_EX_SANE_blank_page_threshold,
- CAP_EX_SANE_resolution,
- CAP_EX_SANE_image_quality,
- CAP_EX_SANE_is_swap,
- CAP_EX_SANE_is_split,
- CAP_EX_SANE_is_auto_deskew,
- CAP_EX_SANE_is_custom_gamma,
- CAP_EX_SANE_bright,
- CAP_EX_SANE_contrast,
- CAP_EX_SANE_gamma,
- CAP_EX_SANE_is_erase_black_frame,
- CAP_EX_SANE_deep_sample,
- CAP_EX_SANE_threshold,
- CAP_EX_SANE_anti_noise,
- CAP_EX_SANE_margin,
- CAP_EX_SANE_fill_background,
- CAP_EX_SANE_is_anti_permeate,
- CAP_EX_SANE_anti_permeate_level,
- CAP_EX_SANE_is_erase_hole,
- CAP_EX_SANE_search_hole_range,
- CAP_EX_SANE_is_filling_color,
- CAP_EX_SANE_is_ultrasonic_check,
- CAP_EX_SANE_is_check_staple,
- CAP_EX_SANE_scan_mode,
- CAP_EX_SANE_scan_count,
- CAP_EX_SANE_text_direction,
- CAP_EX_SANE_is_rotate_bkg180,
- CAP_EX_SANE_is_check_dogear,
- CAP_EX_SANE_dogear_size,
- CAP_EX_SANE_is_check_skew,
- CAP_EX_SANE_skew_range,
- CAP_EX_SANE_black_white_threshold,
- CAP_EX_SANE_is_photo_mode,
- CAP_EX_SANE_double_feed_handle,
- CAP_EX_SANE_scan_when_paper_on,
- CAP_EX_SANE_feed_strength,
- CAP_EX_SANE_power_scheme,
- CAP_EX_SANE_is_auto_strength,
- CAP_EX_SANE_feed_strength_value,
- CAP_EX_SANE_is_reverse_bw,
- CAP_EX_SANE_is_erase_hole_l,
- CAP_EX_SANE_search_hole_range_l,
- CAP_EX_SANE_is_erase_hole_r,
- CAP_EX_SANE_search_hole_range_r,
- CAP_EX_SANE_is_erase_hole_t,
- CAP_EX_SANE_search_hole_range_t,
- CAP_EX_SANE_is_erase_hole_b,
- CAP_EX_SANE_search_hole_range_b,
- CAP_EX_SANE_fold_direction,
- //CAP_EX_SANE_fold_type,
- CAP_EX_SANE_color_correction, // 2023-02-24 15:31:19 ɫƫУ // 2023-02-24 15:28:46 ģʽ
- // END for SANE豸ԭʼ
- /////////////////////////////////////////////////////////////////////////
-};
-enum // .twain/first.cfg: [twain-app] flow=0
-{
- TWAIN_APP_TRANSFER_NORMAL = 0, // first get head and then bits
- TWAIN_APP_TRANSFER_REVERSE, // first get bits and then head
-};
-
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// entry ...
-TWPP_ENTRY(huagao_ds)
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// utilites ...
-// some helper functions to handle capability stuff
-#define RETURN_ENUM_DESC(en, v, space) \
- if(v == space::en) \
- return L###en;
-
-const wchar_t* desc_state(DsState s, wchar_t unk[20])
-{
- RETURN_ENUM_DESC(Closed, s, DsState);
- RETURN_ENUM_DESC(Open, s, DsState);
- RETURN_ENUM_DESC(Enabled, s, DsState);
- RETURN_ENUM_DESC(XferReady, s, DsState);
- RETURN_ENUM_DESC(Xferring, s, DsState);
-
- swprintf(unk, L"%d", s);
-
- return unk;
-}
-const wchar_t* desc_data_group(DataGroup d, wchar_t unk[20])
-{
- RETURN_ENUM_DESC(Control, d, DataGroup);
- RETURN_ENUM_DESC(Image, d, DataGroup);
- RETURN_ENUM_DESC(Audio, d, DataGroup);
-
- {
- swprintf(unk, L"%d", d);
-
- return unk;
- }
-}
-const wchar_t* desc_data(Dat d, wchar_t unk[20])
-{
- RETURN_ENUM_DESC(Null, d, Dat);
- RETURN_ENUM_DESC(Capability, d, Dat);
- RETURN_ENUM_DESC(Event, d, Dat);
- RETURN_ENUM_DESC(Identity, d, Dat);
- RETURN_ENUM_DESC(Parent, d, Dat);
- RETURN_ENUM_DESC(PendingXfers, d, Dat);
- RETURN_ENUM_DESC(SetupMemXfer, d, Dat);
- RETURN_ENUM_DESC(SetupFileXfer, d, Dat);
- RETURN_ENUM_DESC(Status, d, Dat);
- RETURN_ENUM_DESC(UserInterface, d, Dat);
- RETURN_ENUM_DESC(XferGroup, d, Dat);
- RETURN_ENUM_DESC(CustomData, d, Dat);
- RETURN_ENUM_DESC(DeviceEvent, d, Dat);
- RETURN_ENUM_DESC(FileSystem, d, Dat);
- RETURN_ENUM_DESC(PassThrough, d, Dat);
- RETURN_ENUM_DESC(Callback, d, Dat);
- RETURN_ENUM_DESC(StatusUtf8, d, Dat);
- RETURN_ENUM_DESC(Callback2, d, Dat);
- RETURN_ENUM_DESC(ImageInfo, d, Dat);
- RETURN_ENUM_DESC(ImageLayout, d, Dat);
- RETURN_ENUM_DESC(ImageMemXfer, d, Dat);
- RETURN_ENUM_DESC(ImageNativeXfer, d, Dat);
- RETURN_ENUM_DESC(ImageFileXfer, d, Dat);
- RETURN_ENUM_DESC(CieColor, d, Dat);
- RETURN_ENUM_DESC(GrayResponse, d, Dat);
- RETURN_ENUM_DESC(RgbResponse, d, Dat);
- RETURN_ENUM_DESC(JpegCompression, d, Dat);
- RETURN_ENUM_DESC(Palette8, d, Dat);
- RETURN_ENUM_DESC(ExtImageInfo, d, Dat);
- RETURN_ENUM_DESC(Filter, d, Dat);
- RETURN_ENUM_DESC(AudioFileXfer, d, Dat);
- RETURN_ENUM_DESC(AudioInfo, d, Dat);
- RETURN_ENUM_DESC(AudioNativeXfer, d, Dat);
- RETURN_ENUM_DESC(IccProfile, d, Dat);
- RETURN_ENUM_DESC(ImageMemFileXfer, d, Dat);
- RETURN_ENUM_DESC(EntryPoint, d, Dat);
-
- {
- swprintf(unk, L"%d", d);
-
- return unk;
- }
-}
-const wchar_t* desc_msg(Msg m, wchar_t unk[20])
-{
- RETURN_ENUM_DESC(Null, m, Msg);
- RETURN_ENUM_DESC(Get, m, Msg);
- RETURN_ENUM_DESC(GetCurrent, m, Msg);
- RETURN_ENUM_DESC(GetDefault, m, Msg);
- RETURN_ENUM_DESC(GetFirst, m, Msg);
- RETURN_ENUM_DESC(GetNext, m, Msg);
- RETURN_ENUM_DESC(Set, m, Msg);
- RETURN_ENUM_DESC(Reset, m, Msg);
- RETURN_ENUM_DESC(QuerySupport, m, Msg);
- RETURN_ENUM_DESC(GetHelp, m, Msg);
- RETURN_ENUM_DESC(GetLabel, m, Msg);
- RETURN_ENUM_DESC(GetLabelEnum, m, Msg);
- RETURN_ENUM_DESC(SetConstraint, m, Msg);
- RETURN_ENUM_DESC(XferReady, m, Msg);
- RETURN_ENUM_DESC(CloseDsReq, m, Msg);
- RETURN_ENUM_DESC(CloseDsOk, m, Msg);
- RETURN_ENUM_DESC(DeviceEvent, m, Msg);
- RETURN_ENUM_DESC(OpenDsm, m, Msg);
- RETURN_ENUM_DESC(CloseDsm, m, Msg);
- RETURN_ENUM_DESC(OpenDs, m, Msg);
- RETURN_ENUM_DESC(CloseDs, m, Msg);
- RETURN_ENUM_DESC(UserSelect, m, Msg);
- RETURN_ENUM_DESC(DisableDs, m, Msg);
- RETURN_ENUM_DESC(EnableDs, m, Msg);
- RETURN_ENUM_DESC(EnableDsUiOnly, m, Msg);
- RETURN_ENUM_DESC(ProcessEvent, m, Msg);
- RETURN_ENUM_DESC(EndXfer, m, Msg);
- RETURN_ENUM_DESC(StopFeeder, m, Msg);
- RETURN_ENUM_DESC(ChangeDir, m, Msg);
- RETURN_ENUM_DESC(CreateDir, m, Msg);
- RETURN_ENUM_DESC(Delete, m, Msg);
- RETURN_ENUM_DESC(FormatMedia, m, Msg);
- RETURN_ENUM_DESC(GetClose, m, Msg);
- RETURN_ENUM_DESC(GetFirstFile, m, Msg);
- RETURN_ENUM_DESC(GetInfo, m, Msg);
- RETURN_ENUM_DESC(GetNextFile, m, Msg);
- RETURN_ENUM_DESC(Rename, m, Msg);
- RETURN_ENUM_DESC(Copy, m, Msg);
- RETURN_ENUM_DESC(AutomaticCaptureDir, m, Msg);
- RETURN_ENUM_DESC(PassThrough, m, Msg);
- RETURN_ENUM_DESC(RegisterCallback, m, Msg);
- RETURN_ENUM_DESC(ResetAll, m, Msg);
- RETURN_ENUM_DESC(CustomBase, m, Msg);
-
-
- {
- swprintf(unk, L"%d", m);
-
- return unk;
- }
-}
-const wchar_t* desc_return_code(ReturnCode rc, wchar_t unk[20])
-{
- RETURN_ENUM_DESC(Success, rc, ReturnCode);
- RETURN_ENUM_DESC(Failure, rc, ReturnCode);
- RETURN_ENUM_DESC(CheckStatus, rc, ReturnCode);
- RETURN_ENUM_DESC(Cancel, rc, ReturnCode);
- RETURN_ENUM_DESC(DsEvent, rc, ReturnCode);
- RETURN_ENUM_DESC(NotDsEvent, rc, ReturnCode);
- RETURN_ENUM_DESC(XferDone, rc, ReturnCode);
- RETURN_ENUM_DESC(EndOfList, rc, ReturnCode);
- RETURN_ENUM_DESC(InfoNotSupported, rc, ReturnCode);
- RETURN_ENUM_DESC(DataNotAvailable, rc, ReturnCode);
- RETURN_ENUM_DESC(Busy, rc, ReturnCode);
- RETURN_ENUM_DESC(ScannerLocked, rc, ReturnCode);
-
- {
- swprintf(unk, L"%d", rc);
-
- return unk;
- }
-}
-const wchar_t* desc_condition_code(ConditionCode c, wchar_t unk[20])
-{
- RETURN_ENUM_DESC(Success, c, ConditionCode);
- RETURN_ENUM_DESC(Bummer, c, ConditionCode);
- RETURN_ENUM_DESC(LowMemory, c, ConditionCode);
- RETURN_ENUM_DESC(NoDs, c, ConditionCode);
- RETURN_ENUM_DESC(MaxConnections, c, ConditionCode);
- RETURN_ENUM_DESC(OperationError, c, ConditionCode);
- RETURN_ENUM_DESC(BadCap, c, ConditionCode);
- RETURN_ENUM_DESC(BadProtocol, c, ConditionCode);
- RETURN_ENUM_DESC(BadValue, c, ConditionCode);
- RETURN_ENUM_DESC(SeqError, c, ConditionCode);
- RETURN_ENUM_DESC(BadDest, c, ConditionCode);
- RETURN_ENUM_DESC(CapUnsupported, c, ConditionCode);
- RETURN_ENUM_DESC(CapBadOperation, c, ConditionCode);
- RETURN_ENUM_DESC(CapSeqError, c, ConditionCode);
- RETURN_ENUM_DESC(Denied, c, ConditionCode);
- RETURN_ENUM_DESC(FileExists, c, ConditionCode);
- RETURN_ENUM_DESC(FileNotFound, c, ConditionCode);
- RETURN_ENUM_DESC(NotEmpty, c, ConditionCode);
- RETURN_ENUM_DESC(PaperJam, c, ConditionCode);
- RETURN_ENUM_DESC(PaperDoubleFeed, c, ConditionCode);
- RETURN_ENUM_DESC(FileWriteError, c, ConditionCode);
- RETURN_ENUM_DESC(CheckDeviceOnline, c, ConditionCode);
- RETURN_ENUM_DESC(InterLock, c, ConditionCode);
- RETURN_ENUM_DESC(DamagedCorner, c, ConditionCode);
- RETURN_ENUM_DESC(FocusError, c, ConditionCode);
- RETURN_ENUM_DESC(DocTooLight, c, ConditionCode);
- RETURN_ENUM_DESC(DocTooDark, c, ConditionCode);
- RETURN_ENUM_DESC(NoMedia, c, ConditionCode);
-
- {
- swprintf(unk, L"%d", c);
-
- return unk;
- }
-}
-
-template
-static Result oneValGet(Msg msg, Capability& data, const T& value) {
- switch (msg) {
- case Msg::Get:
- case Msg::GetCurrent:
- case Msg::GetDefault:
- data = Capability::createOneValue(data.type(), value);
- return {};
-
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
-}
-
-static Result oneValGetString(Msg msg, Capability& data, std::string value) {
- Str255 str;
- str.setData(value.c_str(), value.size());
- return oneValGet(msg, data, str);
-}
-
-template
-static Result enmGet(Msg msg, Capability& data, const T& value) {
- switch (msg) {
- case Msg::Get:
- data = Capability::createEnumeration(data.type(), { value });
- return {};
- case Msg::GetCurrent:
- case Msg::GetDefault:
- data = Capability::createOneValue(data.type(), value);
- return {};
-
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
-}
-
-template
-static Result oneValGetSet(Msg msg, Capability& data, T& value, const T& def) {
- switch (msg) {
- case Msg::Reset:
- value = def;
- // fallthrough
- case Msg::Get:
- case Msg::GetCurrent:
- data = Capability::createOneValue(data.type(), value);
- return {};
-
- case Msg::GetDefault:
- data = Capability::createOneValue(data.type(), def);
- return {};
-
- case Msg::Set:
- value = data.currentItem();
- return {};
-
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
-}
-
-template
-static Result oneValGetSetConst(Msg msg, Capability& data, const T& def) {
- switch (msg) {
- case Msg::Get:
- case Msg::GetCurrent:
- case Msg::GetDefault:
- case Msg::Reset:
- data = Capability::createOneValue(data.type(), def);
- return {};
-
- case Msg::Set:
- return data.currentItem() == def ?
- Result() : Result(ReturnCode::Failure, ConditionCode::BadValue);
-
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
-}
-
-template
-static Result enmGetSetConst(Msg msg, Capability& data, const T& def) {
- switch (msg) {
- case Msg::Get:
- data = Capability::createEnumeration(data.type(), { def });
- return {};
-
- case Msg::GetCurrent:
- case Msg::GetDefault:
- case Msg::Reset:
- data = Capability::createOneValue(data.type(), def);
- return {};
-
- case Msg::Set:
- return data.currentItem() == def ?
- Result() : Result(ReturnCode::Failure, ConditionCode::BadValue);
-
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
-}
-
-template
-Result CapSupGetAllReset(Msg msg, Capability& data, std::initializer_list values, T1& currvalue, T2 defaultvalue, UInt32 currindex, UInt32 defaultindex) {
- switch (msg) {
- case Msg::Get:
- data = Capability::createEnumeration(values, currindex, defaultindex);
- return { ReturnCode::Success, ConditionCode::Success };
- case Msg::GetCurrent:
- data = Capability::createOneValue((T2)currvalue);
- return { ReturnCode::Success, ConditionCode::Success };
- case Msg::Reset:
- case Msg::GetDefault:
- currvalue = (T1)defaultvalue;
- data = Capability::createOneValue(defaultvalue);
- return { ReturnCode::Success, ConditionCode::Success };
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
-}
-template
-Result CapSupGetAllReset(Msg msg, Capability& data, std::list values, T1& currvalue, T2 defaultvalue, UInt32 currindex, UInt32 defaultindex) {
- switch (msg) {
- case Msg::Get:
- data = Capability::createEnumeration(values, currindex, defaultindex);
- return { ReturnCode::Success, ConditionCode::Success };
- case Msg::GetCurrent:
- data = Capability::createOneValue((T2)currvalue);
- return { ReturnCode::Success, ConditionCode::Success };
- case Msg::Reset:
- case Msg::GetDefault:
- currvalue = (T1)defaultvalue;
- data = Capability::createOneValue(defaultvalue);
- return { ReturnCode::Success, ConditionCode::Success };
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
-}
-template
-Result CapSupGetAllResetEx(Msg msg, Capability& data, std::initializer_list values, T1& currvalue, T2 defaultvalue, UInt32 currindex, UInt32 defaultindex) {
- switch (msg) {
- case Msg::Get:
- data = Capability::createEnumeration(cap, values, currindex, defaultindex);
- return { ReturnCode::Success, ConditionCode::Success };
- case Msg::GetCurrent:
- data = Capability::createOneValue(cap, (T2)currvalue);
- return { ReturnCode::Success, ConditionCode::Success };
- case Msg::Reset:
- case Msg::GetDefault:
- currvalue = (T1)defaultvalue;
- data = Capability::createOneValue(cap, defaultvalue);
- return { ReturnCode::Success, ConditionCode::Success };
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
-}
-template
-Result CapSupGetAllResetEx(Msg msg, Capability& data, std::list values, T1& currvalue, T2 defaultvalue, UInt32 currindex, UInt32 defaultindex) {
- switch (msg) {
- case Msg::Get:
- data = Capability::createEnumeration(cap, values, currindex, defaultindex);
- return { ReturnCode::Success, ConditionCode::Success };
- case Msg::GetCurrent:
- data = Capability::createOneValue(cap, (T2)currvalue);
- return { ReturnCode::Success, ConditionCode::Success };
- case Msg::Reset:
- case Msg::GetDefault:
- currvalue = (T1)defaultvalue;
- data = Capability::createOneValue(cap, defaultvalue);
- return { ReturnCode::Success, ConditionCode::Success };
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
-}
-
-template
-Result CapSupGetAllReset(Msg msg, Capability& data, T1& currvalue, T2 defaultvalue) {
- switch (msg) {
- case Msg::Get:
- case Msg::GetCurrent:
- data = Capability::createOneValue((T2)currvalue);
- return { ReturnCode::Success, ConditionCode::Success };
- case Msg::Reset:
- case Msg::GetDefault:
- currvalue = (T1)defaultvalue;
- data = Capability::createOneValue(defaultvalue);
- return { ReturnCode::Success, ConditionCode::Success };
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
-}
-template
-Result CapSupGetAllResetEx(Msg msg, Capability& data, T1& currvalue, T2 defaultvalue) {
- switch (msg) {
- case Msg::Get:
- case Msg::GetCurrent:
- data = Capability::createOneValue(cap, (T2)currvalue);
- return { ReturnCode::Success, ConditionCode::Success };
- case Msg::Reset:
- case Msg::GetDefault:
- currvalue = (T1)defaultvalue;
- data = Capability::createOneValue(cap, defaultvalue);
- return { ReturnCode::Success, ConditionCode::Success };
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
-}
-
-template
-Result cap_get_enum_values(Msg msg, Capability& data, std::list values, T& cur, T& def, UInt32 cur_ind, UInt32 def_ind)
-{
- switch (msg)
- {
- case Msg::Get:
- data = Capability::createEnumeration(cap, values.size(), cur_ind, def_ind);
- //data = Capability::createArray(cap, values.size());
- {
- auto arr = data.enumeration();
- int i = 0;
- for (const auto& v : values)
- arr[i++] = v;
- }
- return { ReturnCode::Success, ConditionCode::Success };
- case Msg::GetCurrent:
- data = Capability::createOneValue(cap, cur);
- return { ReturnCode::Success, ConditionCode::Success };
- case Msg::Reset:
- case Msg::GetDefault:
- data = Capability::createOneValue(cap, def);
- return { ReturnCode::Success, ConditionCode::Success };
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
-}
-template
-Result cap_get_one_value(Msg msg, Capability& data, T& cur, T& def, T* lower, T* upper, T* step)
-{
- switch (msg)
- {
- case Msg::Get:
- if (lower && upper && step)
- {
- data = Capability::createRange(cap, *lower, *upper, *step, cur, def);
- return { ReturnCode::Success, ConditionCode::Success };
- }
- case Msg::GetCurrent:
- data = Capability::createOneValue(cap, cur);
- return { ReturnCode::Success, ConditionCode::Success };
- case Msg::Reset:
- case Msg::GetDefault:
- data = Capability::createOneValue(cap, def);
- return { ReturnCode::Success, ConditionCode::Success };
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
-}
-
-template
-Result CapSupGetAll(Msg msg, Capability& data, T1& currvalue, T2 defaultvalue) {
- switch (msg) {
- case Msg::Get:
- case Msg::GetCurrent:
- case Msg::GetDefault:
- data = Capability::createOneValue((T2)defaultvalue);
- return { ReturnCode::Success, ConditionCode::Success };
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
-}
-template
-Result CapSupGetAllEx(Msg msg, Capability& data, T1& currvalue, T2 defaultvalue) {
- switch (msg) {
- case Msg::Get:
- case Msg::GetCurrent:
- case Msg::GetDefault:
- data = Capability::createOneValue(defaultvalue);
- return { ReturnCode::Success, ConditionCode::Success };
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
-}
-
-static void copy_type(Bool& to, bool from)
-{
- to = from;
-}
-static void copy_type(bool& to, Bool from)
-{
- to = (bool)from;
-}
-static void copy_type(BYTE& to, bool from)
-{
- to = from;
-}
-static void copy_type(bool& to, BYTE from)
-{
- to = (bool)from;
-}
-static void copy_type(UInt32& to, int from)
-{
- to = from;
-}
-static void copy_type(int& to, UInt32 from)
-{
- to = from;
-}
-static void copy_type(Fix32& to, double from)
-{
- to = (float)from;
-}
-static void copy_type(Fix32& to, float from)
-{
- to = from;
-}
-static void copy_type(float& to, Fix32 from)
-{
- to = from.toFloat();
-}
-static void copy_type(Str255& to, std::string from)
-{
- to.setData(load_sane_util::utf82ansi(from.c_str()).c_str());
-}
-static void copy_type(std::string& to, Str255 from)
-{
- to = load_sane_util::ansi2utf8(from.data());
-}
-static void copy_type(Str64& to, std::string from)
-{
- to.setData(load_sane_util::utf82ansi(from.c_str()).c_str());
-}
-static void copy_type(std::string& to, Str64 from)
-{
- to = load_sane_util::ansi2utf8(from.data());
-}
-
-template
-bool list_value_at(std::list& lst, int ind, T& t)
-{
- bool found = false;
-
- if (ind >= 0)
- {
- typename std::list::iterator it = lst.begin();
- for (; it != lst.end(); ++it, --ind)
- {
- if (ind == 0)
- {
- t = *it;
- found = true;
- break;
- }
- }
- }
-
- return found;
-}
-template
-int distance(std::vector& vec, const T& v, int offset = sane_opts::RANGE_POS_ENUM_BEGIN)
-{
- return std::distance(vec.begin() + offset,
- std::find(vec.begin() + offset, vec.end(), v));
-}
-
-UINT16 bit_depth_from_sane(int sane)
-{
- if (sane == COLOR_BW)
- return 1;
- else if (sane == COLOR_GRAY)
- return 8;
- else if (sane == COLOR_RGB)
- return 24;
- else
- return /*sane*/24;
-}
-static ImageFileFormat from_sane_image_type(int sane_img_type)
-{
- ImageFileFormat fmt = ImageFileFormat::Bmp;
- switch (sane_img_type)
- {
- case SANE_IMAGE_TYPE_PNG:
- fmt = ImageFileFormat::Png;
- break;
- case SANE_IMAGE_TYPE_JPG:
- fmt = ImageFileFormat::Jpx;
- break;
- case SANE_IMAGE_TYPE_TIFF:
- fmt = ImageFileFormat::Tiff;
- break;
- case SANE_IMAGE_TYPE_JFIF:
- fmt = ImageFileFormat::Jfif;
- break;
- case SANE_IMAGE_TYPE_WEBP:
- break;
- case SANE_IMAGE_TYPE_PDF:
- fmt = ImageFileFormat::Pdf;
- break;
- case SANE_IMAGE_TYPE_GIF:
- break;
- case SANE_IMAGE_TYPE_SVG:
- break;
- default:
- break;
- }
-
- return fmt;
-}
-
-struct
-{
- Filter twain;
- int sane;
-}g_filter[] = { {Filter::Red, FILTER_RED}, {Filter::Green, FILTER_GREEN}, {Filter::Blue, FILTER_BLUE}, {Filter::None, FILTER_NONE} };
-Filter from_sane_filter(int sane)
-{
- for (int i = 0; i < _countof(g_filter); ++i)
- {
- if (g_filter[i].sane == sane)
- return g_filter[i].twain;
- }
-
- return Filter::None;
-}
-int to_sane_filter(Filter twain)
-{
- for (int i = 0; i < _countof(g_filter); ++i)
- {
- if (g_filter[i].twain == twain)
- return g_filter[i].sane;
- }
-
- return FILTER_NONE;
-}
-
-struct
-{
- Filter twain;
- int sane;
-}g_enhance[] = { {Filter::Red, ENHANCE_RED}, {Filter::Green, ENHANCE_GREEN}, {Filter::Blue, ENHANCE_BLUE}, {Filter::None, ENHANCE_NONE} };
-Filter from_sane_enhance(int sane)
-{
- for (int i = 0; i < _countof(g_filter); ++i)
- {
- if (g_filter[i].sane == sane)
- return g_filter[i].twain;
- }
-
- return Filter::None;
-}
-int to_sane_enhance(Filter twain)
-{
- for (int i = 0; i < _countof(g_filter); ++i)
- {
- if (g_filter[i].twain == twain)
- return g_filter[i].sane;
- }
-
- return FILTER_NONE;
-}
-
-float trans_range(float val, float min_from, float max_from, float min_to, float max_to, bool for_step = false)
-{
- // transfer val in range [min_from, max_from] to value in range [min_to, max_to]
- if (for_step)
- {
- val /= max_from - min_from;
- val *= max_to - min_to;
- }
- else
- {
- val -= min_from;
- val /= max_from - min_from;
- val *= max_to - min_to;
- val += min_to;
- }
-
- return val;
-}
-
-static void log_attr_access(int attr, int method)
-{
- wchar_t msg[128] = { 0 };
- const wchar_t* op = L"Unknown Oper";
-
-#define METHOD_DESC(oper) \
- if (method == (int)Msg::oper) \
- op = L###oper;
-
- METHOD_DESC(Set)
- else METHOD_DESC(Reset)
- else METHOD_DESC(Get)
- else METHOD_DESC(GetCurrent)
- else METHOD_DESC(GetDefault)
-
- swprintf_s(msg, _countof(msg) - 1, L"%s %04x\r\n", op, attr);
- load_sane_util::log_info(msg, 0);
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// huagao_ds ...
-#include "../../../sdk/include/huagao/brand.h"
-
-static Identity* srcIdent = new Identity(
- Version(VERSION_MAIN, VERSION_SUB, Language::English, Country::China, VERSION_STR(VERSION_MAIN, VERSION_SUB, VERSION_BUILD1, VERSION_PATCH)),
- DataGroup::Image, PRODUCT_VENDOR, PRODUCT_FAMILY, PRODUCT_NAME);
-static const SCANNERID scanner_guid = MAKE_SCANNER_ID(PRODUCT_PID, PRODUCT_VID);
-
-
-static std::once_flag oc;
-huagao_ds::huagao_ds() : cur_head_(NULL), dpi_(200), xfer_ready_failed_(false), log_all_triple_(false), scanner_status_(SCANNER_STATUS_NOT_INIT),count_(-1)
-{
- //std::call_once(oc, [&]() { log4cplus::Initializer(); });
-}
-huagao_ds::~huagao_ds()
-{
- if (memoryinfo.get()) {
- m_memoryfalg = false;
- if (memoryinfo->joinable())
- memoryinfo->join();
- }
- if (cur_head_)
- delete cur_head_;
-}
-
-std::string huagao_ds::get_hidedlg_path(void)
-{
- char szIniFile[MAX_PATH] = { 0 };
- SHGetSpecialFolderPathA(NULL, szIniFile, CSIDL_WINDOWS, TRUE);
-#ifdef MAKEHUAGAO
- strcat(szIniFile, "\\twain_32\\HuaGoScan\\hidedlg.exe");
-#elif defined AUGE
- strcat(szIniFile, "\\twain_32\\AuGeScan\\hidedlg.exe");
-#elif defined HANVON
- strcat(szIniFile, "\\twain_32\\HanvonScan\\hidedlg.exe");
-#elif defined LANXUM
- strcat(szIniFile, "\\twain_32\\LANXUMSCAN\\hidedlg.exe");
-#else // MAKEHUAGAO
- strcat(szIniFile, "\\twain_32\\ZhibenScan\\hidedlg.exe");
-#endif
-
- return szIniFile;
-}
-void huagao_ds::showmsg(const char* msg, int err)
-{
- ShellExecuteA(NULL, "open", huagao_ds::get_hidedlg_path().c_str(), msg, NULL, SW_HIDE);
-}
-int __stdcall huagao_ds::on_scanner_event(int ev, void* param)
-{
- return ((huagao_ds*)param)->handle_scanner_event(ev, false);
-}
-
-const Identity& huagao_ds::defaultIdentity() noexcept {
- // remember, we return a reference, therefore the identity must not be placed on the stack of this method
- return *srcIdent;
-}
-Result huagao_ds::selectIdentity(Twpp::Identity& ident) noexcept {
- // remember, we return a reference, therefore the identity must not be placed on the stack of this method
- ident = *srcIdent;
-
- return success();
-
- return { ReturnCode::Failure, ConditionCode::NoDs };
-}
-Twpp::ConditionCode huagao_ds::condition_code_from_hg_error(int hgerr)
-{
- if (hgerr == SCANNER_ERR_OK)
- return Twpp::ConditionCode::Success;
- if (hgerr == SCANNER_ERR_DEVICE_NOT_FOUND)
- return Twpp::ConditionCode::CheckDeviceOnline;
- if (hgerr == SCANNER_ERR_IO)
- return Twpp::ConditionCode::OperationError;
- if(hgerr == SCANNER_ERR_OUT_OF_RANGE)
- return Twpp::ConditionCode::BadCap;
- if(hgerr == SCANNER_ERR_DEVICE_NOT_SUPPORT)
- return Twpp::ConditionCode::BadProtocol;
- if(hgerr == SCANNER_ERR_INVALID_PARAMETER)
- return Twpp::ConditionCode::BadValue;
- if(hgerr == SCANNER_ERR_ACCESS_DENIED)
- return Twpp::ConditionCode::Denied;
- if(hgerr == SCANNER_ERR_OPEN_FILE_FAILED)
- return Twpp::ConditionCode::FileNotFound;
- if (hgerr == SCANNER_ERR_DEVICE_PAPER_JAMMED)
- return Twpp::ConditionCode::PaperJam;
- if (hgerr == SCANNER_ERR_DEVICE_DOUBLE_FEEDING)
- return Twpp::ConditionCode::PaperDoubleFeed;
- if (hgerr == SCANNER_ERR_WRITE_FILE_FAILED)
- return Twpp::ConditionCode::FileWriteError;
- if (hgerr == SCANNER_ERR_DEVICE_DOGEAR)
- return Twpp::ConditionCode::DamagedCorner;
- if (hgerr == SCANNER_ERR_DEVICE_NO_PAPER)
- return Twpp::ConditionCode::NoMedia;
- if (hgerr == SCANNER_ERR_OPENED_BY_OTHER_PROCESS)
- return Twpp::ConditionCode::MaxConnections;
- if(hgerr == SCANNER_ERR_INSUFFICIENT_MEMORY)
- return Twpp::ConditionCode::LowMemory;
- if(hgerr == SCANNER_ERR_DEVICE_NOT_FOUND)
- return Twpp::ConditionCode::NoDs;
-
- return ConditionCode::Bummer;
-
- // return (Twpp::ConditionCode)((int)Twpp::ConditionCode::CustomBase + hgerr);
-}
-
-Result huagao_ds::capabilityGet(const Identity& origin, Capability& data)
-{
- return capCommon(origin, Msg::Get, data);
-}
-Result huagao_ds::capabilityGetCurrent(const Identity& origin, Capability& data)
-{
- return capCommon(origin, Msg::GetCurrent, data);
-}
-Result huagao_ds::capabilityGetDefault(const Identity& origin, Capability& data)
-{
- return capCommon(origin, Msg::GetDefault, data);
-}
-Result huagao_ds::capabilityQuerySupport(const Identity&, Capability& data)
-{
- auto it = m_query.find(data.type());
- MsgSupport sup = it != m_query.end() ? it->second : msgSupportEmpty;
- data = Capability::createOneValue(data.type(), sup);
- return success();
-}
-Result huagao_ds::capabilityReset(const Identity& origin, Capability& data)
-{
- return capCommon(origin, Msg::Reset, data);
-}
-Result huagao_ds::capabilityResetAll(const Identity& origin)
-{
- for (auto& pair : m_query) {
- if ((pair.second & MsgSupport::Reset) != msgSupportEmpty) {
- Capability dummyCap(pair.first);
- capCommon(origin, Msg::Reset, dummyCap);
- }
- }
-
- return success();
-}
-Result huagao_ds::capabilitySet(const Identity& origin, Capability& data)
-{
- return capCommon(origin, Msg::Set, data);
-}
-Result huagao_ds::eventProcess(const Identity&, Event& event)
-{
- const MSG* msg = (const MSG*)event.event();
- if (scanner_.get())
- {
- int ev = scanner_->get_event();
-
- if(ev)
- handle_scanner_event(ev);
- }
- // event.setMessage(Msg::Null);
-
-
- return { ReturnCode::NotDsEvent, ConditionCode::Success };
-}
-Twpp::Result huagao_ds::deviceEventGet(const Twpp::Identity& origin, Twpp::DeviceEvent& data)
-{
- // data = DeviceEvent::simple(load_sane_util::take_event(), "HUAGAO");
- // return success();
-
- return seqError();
-}
-Result huagao_ds::identityOpenDs(const Identity& id)
-{
- //singleton_ = CreateMutexA(NULL, FALSE, "LookitApp");
- //if (GetLastError() == ERROR_ALREADY_EXISTS) { //ѾͬMutexõ.
- // CloseHandle(singleton_);
- // singleton_ = NULL;
- // showmsg("ʾ", 202);
- //
- // return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- //}
- if (!load_sane_util::is_ok())
- load_sane_util::initialize(me_);
- if (!load_sane_util::is_ok())
- {
- CloseHandle(singleton_);
- singleton_ = NULL;
- return bummer();
- }
-
- Identity target(id);
- Result result = huagao_ds::selectIdentity(target);
- if (scanner_.get())
- scanner_.reset();
-
- if (result.returnCode() != ReturnCode::Success)
- {
- CloseHandle(singleton_);
- singleton_ = NULL;
- load_sane_util::uninitialize();
- return result;
- }
-
- int err = 0;
- Sleep(100);
- scanner_.reset(load_sane_util::open(scanner_guid, &err));
- if (!scanner_.get())
- {
- //CloseHandle(singleton_);
- //singleton_ = NULL;
-
- load_sane_util::uninitialize();
- return { ReturnCode::Failure, huagao_ds::condition_code_from_hg_error(err) };
- }
- // ui_.reset(new twain_ui(local_utility::reg_get_app_installing_path().c_str()));
- scanner_->set_event_callback(&huagao_ds::on_scanner_event, this);
- if (get_config_number(L"twain-app", L"flow") == TWAIN_APP_TRANSFER_REVERSE)
- {
- cur_head_ = new SANE_Parameters;
- memset(cur_head_, 0, sizeof(SANE_Parameters));
- }
- log_all_triple_ = get_config_number(L"twain-app", L"log-all-triple") == 1;
-
- m_compression = Compression::None;
- init_support_caps();
- m_fileXfer.setFormat(ImageFileFormat::Bmp);
- scanner_status_ = SCANNER_STATUS_READY;
-
- return success();
-}
-Result huagao_ds::identityCloseDs(const Identity&)
-{
- // ui_.reset();
- if (scanner_.get())
- {
- scanner_->set_event_callback();
- scanner_.reset();
- }
- if (singleton_)
- {
- CloseHandle(singleton_);
- singleton_ = NULL;
- }
- load_sane_util::uninitialize();
- scanner_status_ = SCANNER_STATUS_NOT_INIT;
-
- return success();
-}
-Result huagao_ds::pendingXfersGet(const Identity&, PendingXfers& data)
-{
- if (!scanner_.get())
- return seqError();
-
- data.setCount(get_scanned_image_count(-1));
- return success();
-}
-Result huagao_ds::pendingXfersEnd(const Identity& id, PendingXfers& data)
-{
- return pendingXfersGet(id, data);
-}
-Result huagao_ds::pendingXfersReset(const Identity&, PendingXfers& data)
-{
- pending_xfer_.clear();
- data.setCount(get_scanned_image_count(-1));
-
- return success();
-}
-Result huagao_ds::setupMemXferGet(const Identity& id, SetupMemXfer& data)
-{
- SANE_Parameters head;
- size_t total = 0;
- DWORD to = cur_head_ ? -1 : 0;
-
- if (!scanner_.get() || get_scanned_image_count(to) == 0)
- {
- if (cur_head_)
- {
- UserInterface ui(FALSE, FALSE, (Twpp::Handle)0);
- data.setPreferredSize(1);
- call(id, DataGroup::Control, Dat::UserInterface, Msg::DisableDs, &ui);
- }
- else
- {
- int def_w = 2000,
- def_h = 6000;
- data.setMinSize(def_w * 3 * def_h);
- data.setPreferredSize(def_w * 3 * def_h);
- data.setMaxSize(def_w * 3 * def_h);
- }
- return success();
- }
-
- if (scanner_->get_first_image_header(&head, &total))
- {
- if (m_compression == Compression::None)
- {
- int line_bytes = (head.bytes_per_line + 3) / 4 * 4;
- data.setMinSize(head.bytes_per_line);
- data.setPreferredSize(line_bytes * head.lines);
- data.setMaxSize(line_bytes * head.lines);
- }
- else
- {
- data.setMinSize(total);
- data.setPreferredSize(total);
- data.setMaxSize(total);
- }
-
- return success();
- }
- else
- return badValue();
-}
-Result huagao_ds::userInterfaceDisable(const Identity&, UserInterface& ui)
-{
- if (scanner_.get())
- scanner_->stop();
-
- return success();
-}
-Result huagao_ds::userInterfaceEnable(const Identity&, UserInterface& ui)
-{
- if (!ui.showUi())
- {
- if (m_bIndicator && !scanner_->ui_show_progress((HWND)ui.parent().raw()))
- return seqError();
-
- xfer_ready_failed_ = false;
- scanner_->twain_set_transfer((twain_xfer)m_capXferMech);
- scanner_status_ = SCANNER_STATUS_SCAN_1;
- app_trigger_event_ = false;
- int err = scanner_->start();
- if (err == SCANNER_ERR_OK)
- {
- return success();
- }
- else
- {
- scanner_status_ = SCANNER_STATUS_READY;
- // if (err == SCANNER_ERR_DEVICE_NO_PAPER)
- return { ReturnCode::Failure, huagao_ds::condition_code_from_hg_error(err) };
-
- return bummer();
- }
- }
-
- return showTwainUI(ui);
-}
-Result huagao_ds::userInterfaceEnableUiOnly(const Identity&, UserInterface& ui)
-{
- // as a minimal source, we do not support GUI that just saves settings
- return showTwainUI(ui, true);
-}
-Twpp::Result huagao_ds::extImageInfoGet(const Identity& origin, ExtImageInfo& data)
-{
- for (int i = 0; i < data.size(); ++i)
- {
- InfoId id = data.at(i).id();
- Twpp::Info& info = data.at(i);
-
- if (id == InfoId::BarCodeCount)
- {
- info.allocSimple(Type::UInt32);
- *info.items()[0].data() = 0;
- }
- else if (id == InfoId::BarCodeType)
- {
- info.allocSimple(Type::UInt32);
- *info.items()[0].data() = BarCodeType::ThreeOfNine;
- }
- else if(id == InfoId::BarCodeTextLength)
- {
- info.allocSimple(Type::UInt32);
- *info.items()[0].data() = 0;
- }
- else if (id == InfoId::BarCodeText)
- {
- //info.allocSimple(Type::Str255, 1);
- //info.items()[0].data()->setData(std::to_string(6922868285266 + i).c_str());
- }
- else
- info.setReturnCode(ReturnCode::InfoNotSupported);
- }
-
- return success();
-
- return { ReturnCode::Failure, ConditionCode::NoMedia };
-}
-Result huagao_ds::imageInfoGet(const Identity&, ImageInfo& data)
-{
- SANE_Parameters head;
- bool ok = false;
- int res = 200;
-
- if (!scanner_.get())
- return seqError();
- if (cur_head_ && cur_head_->lines)
- {
- memcpy(&head, cur_head_, sizeof(head));
- ok = true;
- cur_head_->lines = 0;
- res = dpi_;
- }
- else
- {
- if (!scanner_->wait_image())
- {
- // notifyCloseOk();
- return success(); // ÷Ҫسɹ
- }
- ok = scanner_->get_first_image_header(&head, NULL, &res);
- if(ok)
- dpi_ = res;
- }
-
- if (ok)
- {
- if (head.format == SANE_FRAME_RGB)
- {
- data.setBitsPerPixel(head.depth * 3);
- data.setSamplesPerPixel(3);
- data.bitsPerSample()[0] = data.bitsPerSample()[1] = data.bitsPerSample()[2] = head.depth;
- }
- else
- {
- data.setSamplesPerPixel(1);
- data.setBitsPerPixel(head.depth);
- data.bitsPerSample()[0] = head.depth;
- }
- data.setHeight(head.lines);
- if (m_compression == Compression::Group4)
- data.setPixelType(PixelType::BlackWhite);
- else
- {
- if (head.format == SANE_FRAME_RGB)
- data.setPixelType(PixelType::Rgb);
- else if(head.format == SANE_FRAME_GRAY)
- data.setPixelType(head.depth == 1 ? PixelType::BlackWhite : PixelType::Gray);
- }
- data.setPlanar(false);
- data.setWidth(head.pixels_per_line);
-
- data.setXResolution((float)res);
- data.setYResolution((float)res);
- data.compression(m_compression);
- }
- else
- {
- load_sane_util::log_info(L" imageInfoGet is false\r\n", 0);
- }
- wchar_t buf[128];
- std::wstring f(L"imageInfoGet:");
- int h = data.height();
- int w = data.width();
- int bitsPerPixel = data.bitsPerPixel();
- Compression compression = data.compression();
- PixelType pixelType = data.pixelType();
- bool planar = data.planar();
- Fix32 xr = data.xResolution();
- swprintf_s(buf, _countof(buf) - 1,L"imageInfoGet: h-->%d w-->%d bitsPerPixel-->%d compression-->%d pixelType-->%d planar-->%d\r\n", h, w, bitsPerPixel, compression, pixelType, planar);
- load_sane_util::log_info(buf, 0);
- return success();
-}
-Result huagao_ds::imageLayoutGet(const Identity&, ImageLayout& data)
-{
- SANE_Parameters head = { 0 };
-
- if (!scanner_.get())
- return seqError();
- else if(get_scanned_image_count(-1) == 0)
- return { ReturnCode::Failure, condition_code_from_hg_error(scanner_->last_error()) };
-
- int res = 200;
-
- scanner_->get_first_image_header(&head, NULL, &res);
- data.setDocumentNumber(1);
- data.setFrameNumber(1);
- data.setPageNumber(1);
- data.setFrame(Frame(0, 0, static_cast(head.pixels_per_line) / res, static_cast(head.lines) / res));
-
- return success();
-}
-Result huagao_ds::imageLayoutGetDefault(const Identity& origin, ImageLayout& data)
-{
- return imageLayoutGet(origin, data);
-}
-Result huagao_ds::imageLayoutSet(const Identity& origin, ImageLayout& lay)
-{
- // we dont support setting image frame
-
- ImageLayout def;
- imageLayoutGetDefault(origin, def);
-
- return lay.frame() == def.frame() ? success() : badValue();
-}
-Result huagao_ds::imageLayoutReset(const Identity& origin, ImageLayout& data)
-{
- return imageLayoutGet(origin, data);
-}
-Result huagao_ds::imageMemXferGet(const Identity& origin, ImageMemXfer& data)
-{
- if (!scanner_.get())
- return seqError();
-
- if (get_scanned_image_count(-1) == 0 && !pending_xfer_.img)
- {
- //if (!cur_head_ || !scanner_->wait_image())
- //{
- // notifyCloseOk();
- // return seqError();
- //}
-
- return { ReturnCode::Failure, condition_code_from_hg_error(scanner_->last_error()) };
- }
-
- IScanImg *img = pending_xfer_.img ? pending_xfer_.img : scanner_->take_first_image(TWAIN_XFER_Memory);
- unsigned long long off = pending_xfer_.img ? pending_xfer_.off : 0;
- unsigned char *dst = (unsigned char*)data.memory().data().data();
- UInt32 buf_l = data.memory().size();
- unsigned int line_l = img->line_bytes(),
- rows = data.memory().size() / line_l;
- size_t want_read = rows * line_l;
- Result ret = { ReturnCode::XferDone, ConditionCode::Success };
-
- if (rows == 0)
- return badValue();
-
- if (pending_xfer_.img)
- {
- img->add_ref();
- pending_xfer_.clear();
- }
- else if(cur_head_)
- {
- img->copy_header(cur_head_);
- }
- data.setBytesPerRow(line_l);
- data.setColumns(img->width());
- data.setRows(rows);
- data.setXOffset(0);
- data.setYOffset(UInt32(off / line_l));
- data.setCompression(m_compression);
- if (m_compression != Compression::None)
- {
- want_read = img->bytes() - off;
- if (buf_l < want_read)
- {
- want_read = buf_l;
- }
- img->read(dst, &want_read, off);
- data.setBytesWritten(want_read);
- off += want_read;
- if (off < img->bytes())
- {
- pending_xfer_.img = img;
- pending_xfer_.off = (unsigned int)off;
- img->add_ref();
- ret = success();
- }
- }
- else if (img->read(dst, &want_read, off) == SCANNER_ERR_OK)
- {
- want_read /= line_l;
- data.setRows(want_read);
- want_read *= line_l;
- data.setBytesWritten(want_read);
- off += want_read;
- if (off < img->bytes())
- {
- pending_xfer_.img = img;
- pending_xfer_.off = (unsigned int)off;
- img->add_ref();
- ret = success();
- }
- }
- else
- {
- ret = { ReturnCode::XferDone, ConditionCode::Bummer };
- }
- img->release();
-
- return ret;
-}
-Result huagao_ds::imageNativeXferGet(const Identity& id, ImageNativeXfer& data)
-{
- if (!scanner_.get())
- return seqError();
- else if(get_scanned_image_count(-1) == 0)
- return { ReturnCode::Failure, condition_code_from_hg_error(scanner_->last_error()) };
-
- IScanImg* img = scanner_->take_first_image(TWAIN_XFER_Native);
-
- if (!img)
- return seqError();
- if (data)
- data.release();
- data = ImageNativeXfer(img->bytes());
-
- unsigned long long off = 0;
- unsigned int total = img->bytes();
- unsigned char* src = img->data(off, &total),
- * dst = data.data().data();
- while (off < img->bytes() && src)
- {
- std::copy(src, src + total, dst);
- dst += total;
- off += total;
- if (off >= img->bytes())
- break;
- total = img->bytes() - (unsigned int)off;
- src = img->data(off, &total);
- }
- img->release();
-
- return { ReturnCode::XferDone, ConditionCode::Success };
-}
-Twpp::Result huagao_ds::pendingXfersStopFeeder(const Identity& origin, PendingXfers& data)
-{
- if (scanner_.get())
- scanner_->stop();
-
- return success();
-}
-Twpp::Result huagao_ds::imageFileXferGet(const Twpp::Identity& origin)
-{
- // assume that the file format has set before start-scanning, so we write-down the image content to file directly here ...
- if (!scanner_.get())
- return seqError();
- else if(get_scanned_image_count(-1) == 0)
- return { ReturnCode::Failure, condition_code_from_hg_error(scanner_->last_error()) };
-
- IScanImg* img = scanner_->take_first_image(TWAIN_XFER_File);
- Twpp::Result ret = seqError();
- FILE* dst = NULL;
-
- if (img)
- {
- std::string file(img->file());
- int cv_e = 0,
- status = img->image_status();
- if (file.empty())
- {
- dst = fopen(m_fileXfer.filePath().string().c_str(), "wb");
- ret = { ReturnCode::Failure, ConditionCode::FileWriteError };
- if (dst)
- {
- unsigned long long off = 0;
- unsigned int total = img->bytes();
- unsigned char* src = img->data(off, &total);
- while (src)
- {
- if (fwrite(src, 1, total, dst) != total)
- break;
- off += total;
- if (off >= img->bytes())
- {
- ret = Result(ReturnCode::XferDone, ConditionCode::Success);
- break;
- }
- total = img->bytes() - (unsigned int)off;
- src = img->data(off, &total);
- }
-
- fclose(dst);
- }
- else
- {
- std::wstring f(L"CreateFile(" + load_sane_util::ansi2unic(m_fileXfer.filePath().string().c_str()));
- wchar_t msg[128] = { 0 };
-
- swprintf_s(msg, _countof(msg) - 1, L") = %d\r\n", GetLastError());
- f += msg;
- load_sane_util::log_info(f.c_str(), 0);
- }
- img->release();
- }
- else
- {
- load_sane_util::log_info((L"Map file to " + load_sane_util::ansi2unic(m_fileXfer.filePath().string().c_str()) + L"\r\n").c_str(), 0);
-
- img->keep_file(true);
- img->release();
- cv_e = load_sane_util::move_file(file.c_str(), m_fileXfer.filePath().string().c_str());
- if (cv_e == 0)
- ret = Result(ReturnCode::XferDone, ConditionCode::Success);
- else
- DeleteFileA(file.c_str());
- }
-
- if (ret.status() == ConditionCode::Success && m_fileXfer.format() != ImageFileFormat::Bmp)
- {
- SANE_ImageFormatConvert conv;
- std::string target(m_fileXfer.filePath().string().c_str());
-
- memset(&conv, 0, sizeof(conv));
- file = target + ".src";
- conv.src.fmt.img_format = SANE_IMAGE_TYPE_BMP;
- conv.src.is_file = SANE_TRUE;
- conv.src.data = file.c_str();
- conv.src.data_len = file.length();
-
- conv.dst.fmt.img_format = (SANE_ImageType)m_fileXfer.format();
- conv.dst.fmt.compress.compression = (SANE_CompressionType)m_compression;
- conv.dst.fmt.compress.detail = (void*)0;
- conv.dst.fmt.detail = (void*)m_jpegQuality;
- conv.dst.is_file = SANE_TRUE;
- conv.dst.data = target.c_str();
- conv.dst.data_len = target.length();
- while (!MoveFileA(target.c_str(), file.c_str()))
- {
- if (cv_e == 0)
- {
- std::wstring info(L"[convert image format] Move '");
- wchar_t buf[80] = { 0 };
-
- swprintf_s(buf, _countof(buf) - 1, L"%d\r\n", GetLastError());
- info += load_sane_util::ansi2unic(target.c_str()) + L"' to '" + load_sane_util::ansi2unic(file.c_str()) + L"' failed: ";
- load_sane_util::log_info((info + buf).c_str(), 0);
- }
- if (++cv_e >= 9)
- break;
- Sleep(30);
- }
- if (cv_e < 9)
- {
- cv_e = scanner_->convert_image(&conv);
- if (cv_e != SCANNER_ERR_OK)
- ret = { ReturnCode::Failure, ConditionCode::OperationError };
- DeleteFileA(file.c_str());
- }
- }
-
- //if (ret.status() == ConditionCode::Success)
- //{
- // switch (status)
- // {
- // case SANE_Image_Statu_Blank:
- // break;
- // case SANE_Image_Statu_Double:
- // ret.setStatus(ConditionCode::PaperDoubleFeed);
- // break;
- // case SANE_Image_Statu_Jammed:
- // ret.setStatus(ConditionCode::PaperJam);
- // break;
- // }
- //}
-
- {
- std::wstring info(load_sane_util::ansi2unic(m_fileXfer.filePath().string().c_str()));
- wchar_t r[80] = { 0 };
- swprintf_s(r, _countof(r) - 1, L": status = %d(Fail: 0x%x)\r\n", (int)ret.status(), cv_e);
- load_sane_util::log_info((info + r).c_str(), 0);
- }
- }
-
- return ret;
-}
-Twpp::Result huagao_ds::setupFileXferGet(const Twpp::Identity& origin, Twpp::SetupFileXfer& data)
-{
- data.setFilePath(m_fileXfer.filePath());
- data.setFormat(m_fileXfer.format());
- return success();
-}
-Twpp::Result huagao_ds::setupFileXferGetDefault(const Twpp::Identity& origin, Twpp::SetupFileXfer& data)
-{
- Str255 str("HGTwain.bmp");
- data.setFilePath(str);
- data.setFormat(ImageFileFormat::Bmp);
- return success();
-}
-Twpp::Result huagao_ds::setupFileXferSet(const Twpp::Identity& origin, Twpp::SetupFileXfer& data)
-{
- m_fileXfer.setFilePath(data.filePath());
- m_fileXfer.setFormat(data.format());
- return success();
-}
-Twpp::Result huagao_ds::setupFileXferReset(const Twpp::Identity& origin, Twpp::SetupFileXfer& data)
-{
- m_fileXfer.setFormat(Twpp::ImageFileFormat::Bmp);
- std::string templateName = "HG";
- char* tempPath = mktemp((char*)templateName.c_str());
- if (tempPath) {
- Str255 str;
- str.setData(tempPath, strlen(tempPath));
- m_fileXfer.setFilePath(str);
- return success();
- }
-
- return badProtocol();
-}
-Result huagao_ds::call(const Identity& origin, DataGroup dg, Dat dat, Msg msg, void* data) {
- try {
- // we can override almost anything from SourceFromThis, even the top-most source instance call
- //FileTools::write_log("D:\\1.txt", "call:datagroup-"+to_string((int)dg)+"dat-"+to_string(int(dat))+"msg-"+to_string(int(msg)));
- Result rt;
-
- trigger_ProcessEvent(dg, dat, msg); // some APPs may be not trigger (Control, Event, ProcessEvent), we help them :( ... // ľɨ˲״̬ı䣬ֱȡͼ˴һ״̬ 2022-11-07
-
- rt = Base::call(origin, dg, dat, msg, data);
- if(log_all_triple_ || (int)rt.returnCode())
- {
- wchar_t buf[128] = { 0 }, dgs[20] = { 0 }, dts[20] = { 0 }, ms[20] = { 0 }, ss[20] = { 0 }, rcs[20] = { 0 }, cs[20] = { 0 };
- swprintf_s(buf, _countof(buf) - 1, L"[%x - %s]DSEntry(%s, %s, %s) = {%s, %s}\r\n", GetCurrentThreadId(), desc_state(state(), ss),
- desc_data_group(dg, dgs), desc_data(dat, dts), desc_msg(msg, ms), desc_return_code(rt, rcs), desc_condition_code((ConditionCode)(Status)rt, cs));
- load_sane_util::log_info(buf, 0);
- }
- return rt;
- }
- catch (const CapabilityException& e) {
- //FileTools::writelog(log_ERROR, e.what());
- UNREFERENCED_PARAMETER(e);
- return badValue();
- }
-}
-Result huagao_ds::customDataGet(const Twpp::Identity& origin, Twpp::CustomData& data)
-{
- // get user setting from local file ...
- if (!scanner_.get())
- return seqError();
-
- char * buf = NULL;
- size_t len = 0;
- if (scanner_->twain_get_config(buf, &len) == SCANNER_ERR_INSUFFICIENT_MEMORY)
- {
- data = CustomData(len);
- buf = data.lock();
- scanner_->twain_get_config(buf, &len);
- }
-
- return success();
-}
-Result huagao_ds::customDataSet(const Twpp::Identity& origin, Twpp::CustomData& data)
-{
- // write user setting to local file ...
- if (!scanner_.get())
- return seqError();
-
- char* buf = data.lock();
- scanner_->twain_set_config(buf, data.size());
-
- return success();
-}
-
-void huagao_ds::CapabilityPrintf(Twpp::Msg msg, std::string capability, std::string value)
-{
-
-}
-Result huagao_ds::capCommon(const Identity&, Msg msg, Capability& data) {
- auto it = m_caps.find(data.type());
- if (it != m_caps.end()) {
- return (it->second)(msg, data);
- }
-
- return capUnsupported();
-}
-Twpp::Result huagao_ds::showTwainUI(Twpp::UserInterface& data, bool bUiOnly)
-{
- // display user UI ... (setting UI, can we show my own main window here ?)
- return scanner_->ui_show_setting((HWND)data.parent().raw(), !bUiOnly, m_bIndicator) ? success() : seqError();
-}
-void huagao_ds::init_support_caps(void)
-{
-#define SANE_ID(name) scanner_->sane_opt_id_##name##()
-
- m_query.clear();
- m_caps.clear();
-
- //m_query[CapType::IExtImageInfo] = msgSupportGetAll;
- //m_caps[CapType::IExtImageInfo] = std::bind(enmGet, _1, _2, Bool(true));
-
- m_query[CapType::ISupportedExtImageInfo] = msgSupportGetAll;
- m_caps[CapType::ISupportedExtImageInfo] = [this](Msg msg, Capability& data) {
- data = Capability::createArray< CapType::ISupportedExtImageInfo>({ InfoId::BarCodeCount, InfoId::BarCodeText, InfoId::BarCodeType, InfoId::BarCodeTextLength });
- return success();
- };
-
- m_query[CapType::SupportedCaps] = msgSupportGetAll;
- m_caps[CapType::SupportedCaps] = [this](Msg msg, Capability& data) {
- log_attr_access((int)CapType::SupportedCaps, (int)msg);
- if ((msg == Msg::Get) || (Msg::GetCurrent == msg) || (Msg::GetDefault == msg)) {
- data = Capability::createArray(m_caps.size());
- auto arr = data.array();
- std::vector all;
- for (const auto& v : m_caps)
- all.push_back((int)v.first);
- std::sort(all.begin(), all.end());
- UInt32 i = 0;
- for (const auto& kv : all) {
- arr[i] = (CapType)kv;
- i++;
- }
- return success();
- }
- else
- return capBadOperation();
- };
-
- m_query[CapType::XferCount] = msgSupportGetAllSetReset;
- m_caps[CapType::XferCount] = [this](Msg msg, Capability& data) -> Result {
- log_attr_access((int)CapType::XferCount, (int)msg);
- if (msg == Msg::Set) {
- auto item = data.currentItem();
- if (item > 65535 || item < -1 || item == 0) {
- return badValue();
- }
- int ret = SCANNER_ERR_OK;
- int count = count_ = item;
-
- BYTE dup = 1;
- std::vector all;
- GET_SANE_OPT(bool, scanner_, ex_duplex, NULL, &all);
- dup = all[sane_opts::RANGE_POS_CURRENT];
-
- if (dup && count >= 2)
- {
- count /= 2;
- }
- SET_SANE_OPT(ret, scanner_, scan_count, &count);
- return ret == SCANNER_ERR_OK ? success() : badValue();
- }
- std::vector count;
- Int16 tmp_count = 0;
- GET_SANE_OPT(int, scanner_, scan_count, NULL, &count);
- tmp_count = count[sane_opts::RANGE_POS_CURRENT];
-
- BYTE dup = 1;
- std::vector all;
- GET_SANE_OPT(bool, scanner_, ex_duplex, NULL, &all);
- dup = all[sane_opts::RANGE_POS_CURRENT];
- if (dup && tmp_count > 0 && tmp_count < 65535)
- {
- tmp_count *= 2;
- }
-
- return oneValGetSet(msg, data, tmp_count, -1);
- };
-
- m_bIndicator = scanner_->ui_is_ok();
- if (m_bIndicator)
- {
- m_query[CapType::UiControllable] = msgSupportGetAll;
- m_caps[CapType::UiControllable] = std::bind(oneValGet, _1, _2, Bool(true));
-
- m_query[CapType::Indicators] = msgSupportGetAllSetReset;
- m_caps[CapType::Indicators] = [this](Msg msg, Capability& data) -> Result {
- log_attr_access((int)CapType::Indicators, (int)msg);
- if (Msg::Set == msg) {
- auto show = data.currentItem();
- m_bIndicator = show;
- load_sane_util::log_info(m_bIndicator ? L"Set show indicator: true\r\n" : L"Set show indicator: false\r\n", 0);
- return success();
- }
- load_sane_util::log_info(m_bIndicator ? L"Set show indicator: true\r\n" : L"Set show indicator: false\r\n", 0);
- // data.type
- if (!data.operator bool()) //з () Twain sample app ,data.m_cont is null,but DotNet data.m_cont not is null .
- {
- data = Capability::createEnumeration({ FALSE,TRUE }, m_bIndicator ? 1 : 0, 1);
- }
- else
- data = Capability::createOneValue(m_bIndicator);
-
- return success();
- //return CapSupGetAllReset(msg, data, { TRUE,FALSE }, m_bIndicator, TRUE, (BOOL)(m_bIndicator ? 1 : 0), 1);
- };
- }
-
- m_query[CapType::DeviceOnline] = msgSupportGetAll;
- m_caps[CapType::DeviceOnline] = [this](Msg msg, Capability& data) -> Result {
- log_attr_access((int)CapType::DeviceOnline, (int)msg);
- // CapabilityPrintf(msg, enum2str(CapType::DeviceOnline));
- switch (msg) {
- case Msg::Get:
- case Msg::GetCurrent:
- case Msg::GetDefault:
- if(scanner_.get())
- data = Capability::createOneValue((Twpp::Bool)scanner_->is_online());
- else
- data = Capability::createOneValue((Twpp::Bool)(load_sane_util::is_online(scanner_guid)));
- return success();
-
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
- };
-
- m_query[CapType::ICompression] = msgSupportGetAllSetReset;
- m_caps[CapType::ICompression] = [this](Msg msg, Capability& data)->Result {
- log_attr_access((int)CapType::ICompression, (int)msg);
- if (!scanner_.get())
- return seqError();
- if (Msg::Set == msg) {
- auto mech = data.currentItem();
- if (Compression::None == mech || mech == Compression::Group4) {
- m_compression = mech;
- scanner_->twain_set_compression((SANE_CompressionType)m_compression);
- {
- wchar_t info[128] = { 0 };
- swprintf_s(info, _countof(info) - 1, L"set CapType::ICompression = %s\r\n", Compression::None == mech ? L"None" : L"Group4");
- load_sane_util::log_info(info, 0);
- }
- return success();
- }
- else
- return badValue();
- }
- return CapSupGetAllReset(msg, data, { Compression::None, Compression::Group4 }, m_compression, Compression::None, m_compression == Compression::None ? 0 : 1, 0);
- };
-
- m_query[CapType::IUnits] = msgSupportGetAllSetReset;
- m_caps[CapType::IUnits] = std::bind(enmGetSetConst, _1, _2, Unit::Inches);
-
- m_query[CapType::IBitDepth] = msgSupportGetAllSetReset;
- m_caps[CapType::IBitDepth] = [this](Msg msg, Capability& data) -> Result {
- log_attr_access((int)CapType::IBitDepth, (int)msg);
- std::vector all;
- int val = 0;
- GET_SANE_OPT(int, scanner_, ex_color_mode, NULL, &all);
- if (Msg::Set == msg || Msg::Reset == msg) {
- int ret = SCANNER_ERR_INVALID_PARAMETER;
- val = all[sane_opts::RANGE_POS_DEFAULT];
- if (Msg::Set == msg)
- {
- auto mech = data.currentItem();
- if (mech == 1)
- val = COLOR_BW;
- else if (mech == 8)
- val = COLOR_GRAY;
- else if (mech == 24)
- val = COLOR_RGB;
- else
- val = mech;
- }
- {
- wchar_t info[128] = { 0 };
- swprintf_s(info, _countof(info) - 1, L"set CapType::IBitDepth = %d\r\n", val);
- load_sane_util::log_info(info, 0);
- }
- SET_SANE_OPT(ret, scanner_, ex_color_mode, &val);
- if (Msg::Reset == msg)
- {
- UINT16 v = val;
- data = Capability::createOneValue(CapType::IBitDepth, v);
- }
- return ret == SCANNER_ERR_OK ? success() : badValue();
- }
- UINT16 Now = bit_depth_from_sane(all[sane_opts::RANGE_POS_CURRENT]), Init = bit_depth_from_sane(all[sane_opts::RANGE_POS_DEFAULT]);
- std::list vals;
- UInt32 ni = distance(all, all[sane_opts::RANGE_POS_CURRENT]),
- ii = distance(all, all[sane_opts::RANGE_POS_DEFAULT]);
- for (size_t i = sane_opts::RANGE_POS_ENUM_BEGIN; i < all.size(); ++i)
- vals.push_back(bit_depth_from_sane(all[i]));
- return cap_get_enum_values(msg, data, vals, Now, Init, ni, ii);
- };
-
- m_query[CapType::IBitOrder] = msgSupportGetAllSetReset;
- m_caps[CapType::IBitOrder] = std::bind(oneValGetSetConst, _1, _2, BitOrder::MsbFirst);
-
- m_query[CapType::IPlanarChunky] = msgSupportGetAllSetReset;
- m_caps[CapType::IPlanarChunky] = std::bind(enmGetSetConst, _1, _2, PlanarChunky::Chunky);
-
- m_query[CapType::IXResolution] = msgSupportGetAllSetReset;
- m_caps[CapType::IXResolution] = /*m_caps[CapTypeEx::CAP_EX_SANE_resolution];*/ [this](Msg msg, Capability& data) {
- log_attr_access((int)CapType::IXResolution, (int)msg);
- if (!scanner_.get())
- return seqError();
- std::vector values;
- value_limit limit = VAL_LIMIT_RANGE;
- int init = 0, now = 0;
- GET_SANE_OPT(int, scanner_, resolution, NULL, &values);
- init = values[sane_opts::RANGE_POS_DEFAULT];
- now = values[sane_opts::RANGE_POS_CURRENT];
- switch (msg) {
- case Msg::Get:
- if (limit == VAL_LIMIT_RANGE)
- {
- data = Capability::createRange(Fix32((float)values[sane_opts::RANGE_POS_LOWER])
- , Fix32((float)values[sane_opts::RANGE_POS_UPPER])
- , Fix32((float)values[sane_opts::RANGE_POS_STEP])
- , Fix32((float)values[sane_opts::RANGE_POS_CURRENT])
- , Fix32((float)values[sane_opts::RANGE_POS_DEFAULT]));
- return success();
- }
- else if (limit == VAL_LIMIT_ENUM)
- {
- std::list vals;
- Fix32 Now, Init;
- UInt32 ni, ii;
- for (size_t i = sane_opts::RANGE_POS_ENUM_BEGIN; i < values.size(); ++i)
- {
- Fix32 f;
- float vf = (float)values[i];
- copy_type(f, vf);
- vals.push_back(f);
- }
- float nowf = (float)now, initf = (float)init;
- copy_type(Now, nowf);
- copy_type(Init, initf);
- ni = std::distance(vals.begin(), std::find(vals.begin(), vals.end(), Now));
- ii = std::distance(vals.begin(), std::find(vals.begin(), vals.end(), Init));
- return cap_get_enum_values(msg, data, vals, Now, Init, ni, ii);
- }
- case Msg::GetCurrent:
- data = Capability::createOneValue(Fix32((float)now));
- return success();
- case Msg::GetDefault:
- data = Capability::createOneValue(Fix32((float)init));
- return success();
- case Msg::Reset:
- data = Capability::createOneValue(Fix32((float)init));
- case Msg::Set: {
- auto mech = data.currentItem();
- int ret = SCANNER_ERR_OK;
- float resl = (float)mech;
- int resli = (int)resl;
- SET_SANE_OPT(ret, scanner_, resolution, &resli);
- return ret == SCANNER_ERR_OK ? success() : badValue();
- }
- default:
- return capBadOperation();
- }
- };
-
- m_query[CapType::IYResolution] = msgSupportGetAllSetReset;
- m_caps[CapType::IYResolution] = /*m_caps[CapType::IXResolution];*/ [this](Msg msg, Capability& data)
- {
- Result ret = m_caps[CapType::IXResolution](msg, data);
-
- if (data.type() == CapType::IXResolution)
- data.dangerous_set_cap(CapType::IYResolution);
-
- return ret;
- };
-
- m_query[CapType::IXNativeResolution] = msgSupportGetAll;
- m_caps[CapType::IXNativeResolution] = std::bind(enmGet, _1, _2, Fix32(200.0));
-
- m_query[CapType::IYNativeResolution] = msgSupportGetAll;
- m_caps[CapType::IYNativeResolution] = m_caps[CapType::IXNativeResolution];
-
- m_query[CapType::ISupportedSizes] = msgSupportGetAllSetReset;
- m_caps[CapType::ISupportedSizes] = [this](Msg msg, Capability& data) {
- log_attr_access((int)CapType::ISupportedSizes, (int)msg);
- int now = 0,
- init = 0;
- std::vector all;
- GET_SANE_OPT(int, scanner_, ex_paper, NULL, &all);
- now = all[sane_opts::RANGE_POS_CURRENT];
- init = all[sane_opts::RANGE_POS_DEFAULT];
- if (msg == Msg::Set || msg == Msg::Reset)
- {
- if(msg == Msg::Set)
- init = (int)data.currentItem();
- else
- data = Capability::createOneValue((Twpp::PaperSize)init);
-
- SET_SANE_OPT(now, scanner_, ex_paper, &init);
- return now == SCANNER_ERR_OK ? success() : badValue();
- }
-
- std::list vals;
- Twpp::PaperSize Now = (PaperSize)now,
- Init = (PaperSize)init;
- UInt32 ni = distance(all, now),
- ii = distance(all, init);
- for (size_t i = sane_opts::RANGE_POS_ENUM_BEGIN; i < all.size(); ++i)
- vals.push_back((PaperSize)all[i]);
-
- return cap_get_enum_values(msg, data, vals, Now, Init, ni, ii);
- };
-
- m_query[CapType::IPhysicalWidth] = msgSupportGetAll;
- m_caps[CapType::IPhysicalWidth] = [this](Msg msg, Capability& data) -> Result {
- log_attr_access((int)CapType::IPhysicalWidth, (int)msg);
- switch (msg) {
- case Msg::Get:
- case Msg::GetCurrent:
- case Msg::GetDefault:
- {
- float init = 10.0f;
- int cur = 200;
- SANE_Parameters param = { 0 };
- if (scanner_.get() && scanner_->get_first_image_header(¶m, NULL, &cur))
- init = param.bytes_per_line * 1.0f / cur;
- data = Capability::createOneValue(data.type(), Fix32(init));
- return success();
- }
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
- };
-
- m_query[CapType::IPhysicalHeight] = msgSupportGetAll;
- m_caps[CapType::IPhysicalHeight] = [this](Msg msg, Capability& data) -> Result {
- log_attr_access((int)CapType::IPhysicalHeight, (int)msg);
- switch (msg) {
- case Msg::Get:
- case Msg::GetCurrent:
- case Msg::GetDefault:
- {
- float init = 10.0f;
- int cur = 200;
- SANE_Parameters param = { 0 };
- if (scanner_.get() && scanner_->get_first_image_header(¶m, NULL, &cur))
- init = param.lines * 1.0f / cur;
- data = Capability::createOneValue(data.type(), Fix32(init));
- return success();
- }
- default:
- return { ReturnCode::Failure, ConditionCode::CapBadOperation };
- }
- };
-
- m_query[CapType::IPixelFlavor] = msgSupportGetAllSetReset;
- m_caps[CapType::IPixelFlavor] = std::bind(enmGetSetConst, _1, _2, PixelFlavor::Chocolate);
-
- m_query[CapType::IXferMech] = msgSupportGetAllSetReset;
- m_caps[CapType::IXferMech] = [this](Msg msg, Capability& data) -> Result {
- log_attr_access((int)CapType::IXferMech, (int)msg);
- if (Msg::Set == msg) {
- auto mech = data.currentItem();
- if (mech == XferMech::Native || mech == XferMech::Memory || mech == XferMech::File) {
- m_capXferMech = mech;
- scanner_->twain_set_transfer((twain_xfer)m_capXferMech);
- {
- wchar_t info[128] = { 0 }, * des[] = {L"Native", L"File", L"Memory"};
- swprintf_s(info, _countof(info) - 1, L"set CapType::IXferMech = %s\r\n", des[(int)m_capXferMech]);
- load_sane_util::log_info(info, 0);
- }
- return success();
- }
- else {
- return badValue();
- }
- }
- return CapSupGetAllReset(msg, data, { XferMech::Native, XferMech::File, XferMech::Memory }, m_capXferMech, XferMech::Native, (int)m_capXferMech, 0);
- };
-
- m_query[CapType::IPixelType] = msgSupportGetAllSetReset;
- m_caps[CapType::IPixelType] = [this](Msg msg, Capability& data) -> Result {
- log_attr_access((int)CapType::IPixelType, (int)msg);
- if (!scanner_.get())
- return seqError();
- std::vector values;
- int init = 0, now = 0;
-
- GET_SANE_OPT(int, scanner_, ex_color_mode, NULL, &values);
- now = values[sane_opts::RANGE_POS_CURRENT];
- init = values[sane_opts::RANGE_POS_DEFAULT];
- if (Msg::Reset == msg || Msg::Set == msg)
- {
- if(Msg::Set == msg)
- init = (int)data.currentItem();
- {
- wchar_t info[128] = { 0 }, * des[] = { L"BlackWhite", L"Gray", L"Rgb" };
- if((int)init < _countof(des))
- swprintf_s(info, _countof(info) - 1, L"set CapType::IPixelType = %s\r\n", des[(int)init]);
- else
- swprintf_s(info, _countof(info) - 1, L"set CapType::IPixelType = 0x%x\r\n", (int)init);
- load_sane_util::log_info(info, 0);
- }
- int ret = SCANNER_ERR_OK;
- SET_SANE_OPT(ret, scanner_, ex_color_mode, &init);
- data = Capability::createOneValue((Twpp::PixelType)init);
- return ret == SCANNER_ERR_OK ? success() : badValue();
- }
- switch (msg) {
- case Msg::Get:
- if (1)
- {
- std::list vals;
- UInt32 ni = distance(values, now), ii = distance(values, init);
- Twpp::PixelType Init = (Twpp::PixelType)init, Now = (Twpp::PixelType)now;
- for (size_t i = sane_opts::RANGE_POS_ENUM_BEGIN; i < values.size(); ++i)
- vals.push_back((Twpp::PixelType)values[i]);
- return cap_get_enum_values(msg, data, vals, Now, Init, ni, ii);
- }
- case Msg::GetCurrent:
- data = Capability::createOneValue((Twpp::PixelType)now);
- return success();
- case Msg::GetDefault:
- data = Capability::createOneValue((Twpp::PixelType)init);
- return success();
- }
- return capBadOperation();
- };
-
- m_query[CapType::IAutomaticColorEnabled] = msgSupportGetAllSetReset;
- m_caps[CapType::IAutomaticColorEnabled] = [this](Msg msg, Capability& data)->Result {
- log_attr_access((int)CapType::IAutomaticColorEnabled, (int)msg);
- if (Msg::Set == msg) {
- auto mech = data.currentItem();
- int ret = SCANNER_ERR_OK, val = mech ? COLOR_AUTO_MATCH : COLOR_RGB;
- SET_SANE_OPT(ret, scanner_, ex_auto_color_type, &val);
-
- return success();
- }
- std::vector all;
- GET_SANE_OPT(int, scanner_, ex_auto_color_type, NULL, &all);
- int twpt = all[sane_opts::RANGE_POS_CURRENT] == COLOR_AUTO_MATCH ? 1 : 0;
- return CapSupGetAllReset(msg, data, { FALSE,TRUE }, twpt, false, twpt ? 1 : 0, 0);
- };
-
- m_query[CapType::IAutomaticColorNonColorPixelType] = msgSupportGetAllSetReset;
- m_caps[CapType::IAutomaticColorNonColorPixelType] = [this](Msg msg, Capability& data)->Result {
- log_attr_access((int)CapType::IAutomaticColorNonColorPixelType, (int)msg);
- if (msg == Msg::Set) {
- int mech = (int)data.currentItem();
- {
- if ((UInt16)mech == 0 || (UInt16)mech == 1) {
- int ret = SCANNER_ERR_OK,
- val = mech;
- SET_SANE_OPT(ret, scanner_, ex_auto_color_type, &val);
- if (ret == SCANNER_ERR_OK)
- {
- automaticcolortype_ = (UInt16)mech;
- return success();
- }
- }
- }
- return seqError();
- }
- return CapSupGetAllReset(msg, data, { PixelType::BlackWhite, PixelType::Gray }, automaticcolortype_, PixelType::Gray, automaticcolortype_, 1);
- };
-
- m_query[CapType::IJpegQuality] = msgSupportGetAllSetReset;
- m_caps[CapType::IJpegQuality] = [this](Msg msg, Capability& data)->Result {
- log_attr_access((int)CapType::IJpegQuality, (int)msg);
- SANE_FinalImgFormat fif;
- fif.img_format = SANE_IMAGE_TYPE_JPG;
- if (Msg::Set == msg) {
- auto mech = data.currentItem();
- if ((int)mech <= 0 || (int)mech > 100)
- return badValue();
-
- m_jpegQuality = (int)mech;
- return success();
- //int ret = SCANNER_ERR_OK;
- //fif.detail = (void*)mech;
- //SET_SANE_OPT(ret, scanner_, ex_final_format, &fif);
- //return ret == SCANNER_ERR_OK ? success() : badValue();
- }
- //unsigned short q = 80;
- //fif.detail = (void*)q;
- //GET_SANE_OPT(SANE_FinalImgFormat, scanner_, ex_final_format, &fif, NULL, NULL, NULL);
- //if(fif.img_format == SANE_IMAGE_TYPE_JPG)
- // q = (unsigned short)fif.detail;
- //return CapSupGetAllResetEx(msg, data, q, 80);
- unsigned short q = m_jpegQuality;
- return CapSupGetAllResetEx(msg, data, q, (UInt16)80);
- };
-
- m_query[CapType::IOrientation] = msgSupportGetAllSetReset;
- m_caps[CapType::IOrientation] = [this](Msg msg, Capability& data) -> Result {
- log_attr_access((int)CapType::IOrientation, (int)msg);
- CapabilityPrintf(msg, enum2str(CapTypeEx::IOrientation), msg == Msg::Set ? to_string((int)data.currentItem()) : "");
- if (Msg::Set == msg) {
- auto mech = data.currentItem();
- bool lateral = mech == Orientation::Landscape;
- int ret = SCANNER_ERR_OK;
- SET_SANE_OPT(ret, scanner_, ex_paper_lateral, &lateral);
- return ret == SCANNER_ERR_OK ? success() : badValue();
- }
- std::vector values;
- GET_SANE_OPT(bool, scanner_, ex_paper_lateral, NULL, &values);
- int lateral = values[sane_opts::RANGE_POS_CURRENT] ? (int)Orientation::Landscape : (int)Orientation::Portrait;
- return CapSupGetAllReset(msg, data, { Orientation::Portrait, Orientation::Landscape }, lateral, Orientation::Portrait, lateral == 0 ? 0 : 1, 0);
- };
-
- m_query[CapType::IRotation] = msgSupportGetAllSetReset;
- m_caps[CapType::IRotation] = [this](Msg msg, Capability& data) -> Result {
- log_attr_access((int)CapType::IRotation, (int)msg);
- if (Msg::Set == msg) {
- auto res = data.currentItem();
- float angle = res.toFloat();
- int ret = SCANNER_ERR_OK;
- SET_SANE_OPT(ret, scanner_, ex_text_direction, &angle);
- return ret == SCANNER_ERR_OK ? success() : badValue();
- }
- std::vector values;
-
- GET_SANE_OPT(float, scanner_, ex_text_direction, NULL, &values);
-
- Fix32 Init = Fix32(values[sane_opts::RANGE_POS_DEFAULT]), Now = Fix32(values[sane_opts::RANGE_POS_CURRENT]);
- std::list vls;
- UInt32 i = distance(values, values[sane_opts::RANGE_POS_DEFAULT]),
- n = distance(values, values[sane_opts::RANGE_POS_CURRENT]);
- for (size_t i = sane_opts::RANGE_POS_ENUM_BEGIN; i < values.size(); ++i)
- vls.push_back(Fix32(values[i]));
-
- return cap_get_enum_values(msg, data, vls, Now, Init, n, i);
- };
-
- m_query[CapType::EnableDsUiOnly] = msgSupportGetAll;
- m_caps[CapType::EnableDsUiOnly] = std::bind(enmGet, _1, _2, Bool(true));
-
- m_query[CapType::PaperDetectable] = msgSupportGetAll;
- m_caps[CapType::PaperDetectable] = std::bind(oneValGet, _1, _2, Bool(true));
-
- m_query[CapType::FeederEnabled] = msgSupportGetAllSetReset;
- m_caps[CapType::FeederEnabled] = [this](Msg msg, Capability& data) -> Result {
- log_attr_access((int)CapType::FeederEnabled, (int)msg);
- CapabilityPrintf(msg, enum2str(CapType::FeederEnabled), msg == Msg::Set ? to_string((int)data.currentItem()) : "");
- if (Msg::Set == msg) {
- auto mech = data.currentItem();
- m_bFeederEnabled = mech;
- return success();
- }
- return CapSupGetAllReset(msg, data, m_bFeederEnabled, Bool(true));
- };
-
- m_query[CapType::Duplex] = msgSupportGetAll;
- m_caps[CapType::Duplex] = std::bind(oneValGet, _1, _2, Duplex::OnePass);
-
- m_query[CapType::DuplexEnabled] = msgSupportGetAllSetReset;
- m_caps[CapType::DuplexEnabled] = [this](Msg msg, Capability& data) -> Result {
- log_attr_access((int)CapType::DuplexEnabled, (int)msg);
- if (Msg::Set == msg) {
- bool mech = data.currentItem();
-
- int ret = SCANNER_ERR_OK;
- SET_SANE_OPT(ret, scanner_, ex_duplex, &mech);
- load_sane_util::log_info(mech ? L"Set1 Duplex is: true\r\n" : L"Set1 Duplex is: false\r\n", 0);
- int count = count_;
- if (mech && count_ >= 2)
- {
- count /= 2;
- SET_SANE_OPT(ret, scanner_, scan_count, &count);
- }
- else if (!mech && count_ >= 2)
- SET_SANE_OPT(ret, scanner_, scan_count, &count);
-
- return ret == SCANNER_ERR_OK ? success() : badValue();
- }
- BYTE dup = 1;
- std::vector all;
- GET_SANE_OPT(bool, scanner_, ex_duplex, NULL, &all);
- dup = all[sane_opts::RANGE_POS_CURRENT];
-
- load_sane_util::log_info(dup ? L"Get Duplex is: true\r\n" : L"Get Duplex is: false\r\n", 0);
-
- int ret = SCANNER_ERR_OK;
- int count = count_;
- if (dup && count_ >= 2)
- {
- count /= 2;
- SET_SANE_OPT(ret, scanner_, scan_count, &count);
- }
- else if (!dup && count_ >= 2)
- SET_SANE_OPT(ret, scanner_, scan_count, &count)
-
- return CapSupGetAllReset(msg, data, dup, Bool(true));
- };
-
- m_query[CapType::AutoFeed] = msgSupportGetAllSetReset;
- m_caps[CapType::AutoFeed] = [this](Msg msg, Capability& data) -> Result {
- log_attr_access((int)CapType::AutoFeed, (int)msg);
- if (Msg::Set == msg) {
- auto mech = data.currentItem();
- m_bAutoFeed = mech;
- return success();
- }
- return CapSupGetAllReset(msg, data, { false,true }, m_bAutoFeed, true, m_bAutoFeed ? 1 : 0, 1);
- };
-
- m_query[CapType::IImageFileFormat] = msgSupportGetAllSetReset;
- m_caps[CapType::IImageFileFormat] = [this](Msg msg, Capability& data) -> Result {
- log_attr_access((int)CapType::IImageFileFormat, (int)msg);
- SANE_FinalImgFormat now, init;
- std::vector all;
- GET_SANE_OPT(SANE_FinalImgFormat, scanner_, ex_final_format, NULL, &all);
- init = all[sane_opts::RANGE_POS_DEFAULT];
- now = all[sane_opts::RANGE_POS_CURRENT];
- if (Msg::Set == msg || Msg::Reset == msg) {
- if (Msg::Set == msg)
- {
- auto fmt = data.currentItem();
- if (fmt != Twpp::ImageFileFormat::Bmp &&
- fmt != Twpp::ImageFileFormat::Jfif &&
- fmt != Twpp::ImageFileFormat::Tiff)
- return badValue();
- init.img_format = (SANE_ImageType)fmt;
- {
- if (fmt == Twpp::ImageFileFormat::Bmp)
- load_sane_util::log_info(L"set CapType::IImageFileFormat = Bmp\r\n", 0);
- else if (fmt == Twpp::ImageFileFormat::Jfif)
- load_sane_util::log_info(L"set CapType::IImageFileFormat = Jfif\r\n", 0);
- else if (fmt == Twpp::ImageFileFormat::Tiff)
- load_sane_util::log_info(L"set CapType::IImageFileFormat = Tiff\r\n", 0);
- }
- }
- else
- data = Capability::createOneValue((Twpp::ImageFileFormat)init.img_format);
-
- m_fileXfer.setFormat((Twpp::ImageFileFormat)init.img_format);
- return success();
- //if(Msg::Set == msg)
- // init.img_format = (SANE_ImageType)(int)data.currentItem();
- //int ret = SCANNER_ERR_OK;
- //SET_SANE_OPT(ret, scanner_, ex_final_format, &init);
- //return ret == SCANNER_ERR_OK ? success() : badValue();
- }
- // ImageFileFormat Now = (ImageFileFormat)(int)now.img_format, Init = (ImageFileFormat)(int)init.img_format;
- ImageFileFormat Now = m_fileXfer.format() , Init = Twpp::ImageFileFormat::Bmp;
- std::list vals;
- UInt32 i = 0, // distance(all, init),
- n = 0; // distance(all, now);
- for (size_t ind = sane_opts::RANGE_POS_ENUM_BEGIN; ind < all.size(); ++ind)
- {
- vals.push_back((ImageFileFormat)(int)all[ind].img_format);
- if (all[ind].img_format == init.img_format)
- i = ind;
- else if (all[ind].img_format == now.img_format)
- n = ind;
- }
-
- return cap_get_enum_values(msg, data, vals, Now, Init, n, i);
- };
-
- m_query[CapType::IAutomaticDeskew] = msgSupportGetAllSetReset;
- m_caps[CapType::IAutomaticDeskew] = [this](Msg msg, Capability& data)->Result {
- log_attr_access((int)CapType::IAutomaticDeskew, (int)msg);
- if (Msg::Set == msg) {
- auto atuodsw = data.currentItem