4217 lines
124 KiB
C++
4217 lines
124 KiB
C++
#include "hg_scanner.h"
|
||
|
||
#include "../../sdk/hginclude/utils.h"
|
||
#include <lang/app_language.h>
|
||
#include "sane/sane_option_definitions.h"
|
||
#include "scanner_setting.h"
|
||
#include "scanner_manager.h"
|
||
#include "../../sdk/json/gb_json.h"
|
||
#include "device_opt.h"
|
||
#include <string.h>
|
||
|
||
#if defined(WIN32) || defined(_WIN64)
|
||
#include <direct.h>
|
||
#endif
|
||
|
||
#define DYN_JSON_BETWEEN_PAPER_AND_DPI
|
||
|
||
#if defined(WIN32) || defined(_WIN64)
|
||
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)
|
||
{
|
||
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);
|
||
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;
|
||
}
|
||
|
||
static int strToWchar(string str, wchar_t* s)
|
||
{
|
||
if (str.empty() || !s)
|
||
{
|
||
return -1;
|
||
}
|
||
size_t size = str.length();
|
||
//获取缓冲区大小,并申请空间,缓冲区大小按字符计算
|
||
int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), size, NULL, 0);
|
||
wchar_t* buffer = new wchar_t[size + 1];
|
||
MultiByteToWideChar(CP_ACP, 0, str.c_str(), size, buffer, len);
|
||
buffer[len] = '\0';
|
||
wcscpy(s, buffer);
|
||
if (!buffer || !s)
|
||
return -1;
|
||
delete[]buffer;
|
||
buffer = NULL;
|
||
return 0;
|
||
}
|
||
#endif
|
||
static int ui_default_callback(scanner_handle, int, void*, unsigned int*, void*)
|
||
{
|
||
return 0;
|
||
}
|
||
static std::string bmp_821(unsigned char* bits/*bits data*/, int w, int h, int* lbytes/*in/out 行字节*/, bool line_align_4/*是否行对齐4字节*/, int threashold/*黑白像素阈值*/, bool reverse/*是否反色输出*/)
|
||
{
|
||
static unsigned int g_bmp8_pallete[] = {
|
||
0x00000000, 0x00800000, 0x00008000, 0x00808000, 0x00000080, 0x00800080, 0x00008080, 0x00c0c0c0, 0x00c0dcc0, 0x00a6caf0, 0x00402000, 0x00602000, 0x00802000, 0x00a02000, 0x00c02000, 0x00e02000
|
||
, 0x00004000, 0x00204000, 0x00404000, 0x00604000, 0x00804000, 0x00a04000, 0x00c04000, 0x00e04000, 0x00006000, 0x00206000, 0x00406000, 0x00606000, 0x00806000, 0x00a06000, 0x00c06000, 0x00e06000
|
||
, 0x00008000, 0x00208000, 0x00408000, 0x00608000, 0x00808000, 0x00a08000, 0x00c08000, 0x00e08000, 0x0000a000, 0x0020a000, 0x0040a000, 0x0060a000, 0x0080a000, 0x00a0a000, 0x00c0a000, 0x00e0a000
|
||
, 0x0000c000, 0x0020c000, 0x0040c000, 0x0060c000, 0x0080c000, 0x00a0c000, 0x00c0c000, 0x00e0c000, 0x0000e000, 0x0020e000, 0x0040e000, 0x0060e000, 0x0080e000, 0x00a0e000, 0x00c0e000, 0x00e0e000
|
||
, 0x00000040, 0x00200040, 0x00400040, 0x00600040, 0x00800040, 0x00a00040, 0x00c00040, 0x00e00040, 0x00002040, 0x00202040, 0x00402040, 0x00602040, 0x00802040, 0x00a02040, 0x00c02040, 0x00e02040
|
||
, 0x00004040, 0x00204040, 0x00404040, 0x00604040, 0x00804040, 0x00a04040, 0x00c04040, 0x00e04040, 0x00006040, 0x00206040, 0x00406040, 0x00606040, 0x00806040, 0x00a06040, 0x00c06040, 0x00e06040
|
||
, 0x00008040, 0x00208040, 0x00408040, 0x00608040, 0x00808040, 0x00a08040, 0x00c08040, 0x00e08040, 0x0000a040, 0x0020a040, 0x0040a040, 0x0060a040, 0x0080a040, 0x00a0a040, 0x00c0a040, 0x00e0a040
|
||
, 0x0000c040, 0x0020c040, 0x0040c040, 0x0060c040, 0x0080c040, 0x00a0c040, 0x00c0c040, 0x00e0c040, 0x0000e040, 0x0020e040, 0x0040e040, 0x0060e040, 0x0080e040, 0x00a0e040, 0x00c0e040, 0x00e0e040
|
||
, 0x00000080, 0x00200080, 0x00400080, 0x00600080, 0x00800080, 0x00a00080, 0x00c00080, 0x00e00080, 0x00002080, 0x00202080, 0x00402080, 0x00602080, 0x00802080, 0x00a02080, 0x00c02080, 0x00e02080
|
||
, 0x00004080, 0x00204080, 0x00404080, 0x00604080, 0x00804080, 0x00a04080, 0x00c04080, 0x00e04080, 0x00006080, 0x00206080, 0x00406080, 0x00606080, 0x00806080, 0x00a06080, 0x00c06080, 0x00e06080
|
||
, 0x00008080, 0x00208080, 0x00408080, 0x00608080, 0x00808080, 0x00a08080, 0x00c08080, 0x00e08080, 0x0000a080, 0x0020a080, 0x0040a080, 0x0060a080, 0x0080a080, 0x00a0a080, 0x00c0a080, 0x00e0a080
|
||
, 0x0000c080, 0x0020c080, 0x0040c080, 0x0060c080, 0x0080c080, 0x00a0c080, 0x00c0c080, 0x00e0c080, 0x0000e080, 0x0020e080, 0x0040e080, 0x0060e080, 0x0080e080, 0x00a0e080, 0x00c0e080, 0x00e0e080
|
||
, 0x000000c0, 0x002000c0, 0x004000c0, 0x006000c0, 0x008000c0, 0x00a000c0, 0x00c000c0, 0x00e000c0, 0x000020c0, 0x002020c0, 0x004020c0, 0x006020c0, 0x008020c0, 0x00a020c0, 0x00c020c0, 0x00e020c0
|
||
, 0x000040c0, 0x002040c0, 0x004040c0, 0x006040c0, 0x008040c0, 0x00a040c0, 0x00c040c0, 0x00e040c0, 0x000060c0, 0x002060c0, 0x004060c0, 0x006060c0, 0x008060c0, 0x00a060c0, 0x00c060c0, 0x00e060c0
|
||
, 0x000080c0, 0x002080c0, 0x004080c0, 0x006080c0, 0x008080c0, 0x00a080c0, 0x00c080c0, 0x00e080c0, 0x0000a0c0, 0x0020a0c0, 0x0040a0c0, 0x0060a0c0, 0x0080a0c0, 0x00a0a0c0, 0x00c0a0c0, 0x00e0a0c0
|
||
, 0x0000c0c0, 0x0020c0c0, 0x0040c0c0, 0x0060c0c0, 0x0080c0c0, 0x00a0c0c0, 0x00fffbf0, 0x00a0a0a4, 0x00808080, 0x00ff0000, 0x0000ff00, 0x00ffff00, 0x000000ff, 0x00ff00ff, 0x0000ffff, 0x00ffffff
|
||
};
|
||
int l = (w + 31) / 32 * 4,
|
||
size = l * h,
|
||
line_bytes = (w + 3) / 4 * 4;
|
||
std::string f("");
|
||
unsigned char* data = nullptr, mask = reverse ? -1 : 0;
|
||
unsigned int* pallete = g_bmp8_pallete;
|
||
|
||
if (!line_align_4)
|
||
{
|
||
l = (w + 7) / 8;
|
||
size = l * h;
|
||
}
|
||
if (lbytes && *lbytes)
|
||
line_bytes = *lbytes;
|
||
f.resize(size);
|
||
data = (unsigned char*)&f[0];
|
||
for (int i = 0; i < h; ++i)
|
||
{
|
||
unsigned char v = 0,
|
||
*dst = data;
|
||
for (int j = 0; j < w; ++j)
|
||
{
|
||
v <<= 1;
|
||
|
||
unsigned char pixel = ((pallete[bits[j]] & 0x0ff) + ((pallete[bits[j]] >> 8) & 0x0ff) + ((pallete[bits[j]] >> 16) & 0x0ff)) / 3;
|
||
if (pixel >= threashold)
|
||
v |= 1;
|
||
if ((j + 1) % 8 == 0)
|
||
{
|
||
*dst++ = v ^ mask;
|
||
v = 0;
|
||
}
|
||
}
|
||
if (w % 8)
|
||
{
|
||
v ^= mask;
|
||
v <<= 8 - (w % 8);
|
||
*dst++ = v;
|
||
}
|
||
|
||
data += l;
|
||
bits += line_bytes;
|
||
}
|
||
if (lbytes)
|
||
*lbytes = l;
|
||
|
||
return f;
|
||
}
|
||
|
||
static bool is_firstopen_ = true; //第二次打开设备就不在去获取和设置设备锁定状态
|
||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||
// hg_scanner
|
||
hg_scanner::hg_scanner(ScannerSerial serial, const char* dev_name, usb_io* io, int pid)
|
||
: name_(dev_name ? dev_name : ""), family_(""), io_(io), status_(SCANNER_ERR_NOT_START), serial_(serial)
|
||
, scan_count_(-1), run_(true), paper_size_(TwSS::A4), erase_bkg_range_(10), read_over_with_no_data_(false)
|
||
, noise_range_(30), omit_empty_level_(50), resolution_(200), rid_hole_range_(10.0f)
|
||
, bright_(128), contrast_(4), gamma_(1.0f), threshold_(40), anti_noise_(8), margin_(5)
|
||
, fractate_level_(50), ui_ev_cb_(ui_default_callback), scan_life_(NULL)
|
||
, notify_setting_result_(false), user_cancel_(false), cb_mem_(true), test_1_paper_(false)
|
||
, img_type_(""), online_(false), is_quality_(-1), is_color_fill(false), is_multiout(false), save_multiout(lang_load_string(ID_OPTION_VALUE_DLSCLX_CS_HD_HB, nullptr))
|
||
, final_img_index_(0), custom_area_(false), save_sizecheck(false), bw_threshold_(128), custom_gamma_(false)
|
||
, double_paper_handle_(0), keep_watermark_(false), save_feedmode_type_(false), feedmode_(1), sleeptime_(-1), split3399_(0)
|
||
, async_io_(false), is_white_0_(true), isremove_left_hole(false), isremove_right_hole(false), isremove_top_hole(false), isremove_low_hole(false)
|
||
, isremove_left_hole_threshold(0), isremove_right_hole_threshold(0), isremove_top_hole_threshold(0), isremove_low_hole_threshold(0)
|
||
, dump_usb_path_(""), dump_img_(&hg_scanner::dump_image_empty)
|
||
, memory_size_(4000/*USB+JPEG压缩及图像处理图队列,总共1GB*/), isx86_Advan_(true), stop_fatal_(SCANNER_ERR_OK), is_auto_paper_scan(false)
|
||
, size_check(false), save_sleeptime_type_(false), is_checksum_strat_scan(false), is_cis_image(false)
|
||
, is_dpi_color_check(false), save_dpi_color_check_val(0.0f), is_auto_falt(false), HGVersion_mgr_(NULL), HGVersion_Init_(NULL)
|
||
, HGVersion_Islock_(NULL), HGVersion_Postlog_(NULL), HGVersion_Free_(NULL), Dynamicopen_HGVersion_pHandle_(NULL), pid_(pid), fetching_id_(-1), color_correction_(false)
|
||
, is_auto_paper_scan_exit_time(60), is_read_int(true), is_auto_feedmode_(false)
|
||
, firmware_sup_wait_paper_(false),firmware_sup_pick_strength_(false),firmware_sup_log_export_(false),firmware_sup_color_corr_(false),firmware_sup_wake_device_(false)
|
||
, firmware_sup_double_img(false),firmware_sup_devs_lock_(false),firmware_sup_dpi_300(false),firmware_sup_dpi_600(false),firmware_sup_auto_speed_(false),firmware_sup_morr_(false)
|
||
, firmware_sup_color_fill_(false),firmware_sup_history_cnt(false), is_discardblank(false)
|
||
, setting_jsn_(new device_option())
|
||
{
|
||
#if !defined(_WIN32) && !defined(_WIN64) &&defined(x86_64)
|
||
isx86_Advan_ = false;
|
||
#endif
|
||
std::string config_file(utils::get_local_data_path() + PATH_SEPARATOR + "config" + PATH_SEPARATOR + "debug.cfg");
|
||
char strbuf[260] = {0};
|
||
int getl = GetPrivateProfileStringA("path", "final_img", "", strbuf, sizeof(strbuf) - 1, config_file.c_str());
|
||
|
||
init_setting_func_map();
|
||
strbuf[getl] = 0;
|
||
final_path_ = strbuf;
|
||
if(final_path_.empty())
|
||
final_path_ = utils::get_local_data_path() + PATH_SEPARATOR + "imgs";
|
||
if (GetPrivateProfileIntA("dump", "dumpusb", 0, config_file.c_str()) == 1)
|
||
{
|
||
getl = GetPrivateProfileStringA("dump", "usb_path", "", strbuf, sizeof(strbuf) - 1, config_file.c_str());
|
||
strbuf[getl] = 0;
|
||
dump_usb_path_ = strbuf;
|
||
if (dump_usb_path_.empty())
|
||
dump_usb_path_ = final_path_;
|
||
if (!dump_usb_path_.empty())
|
||
dump_img_ = &hg_scanner::dump_image_real;
|
||
}
|
||
|
||
getl = GetPrivateProfileStringA("mem", "max_img", "", strbuf, sizeof(strbuf) - 1, config_file.c_str());
|
||
strbuf[getl] = 0;
|
||
|
||
std::string mem(strbuf);
|
||
if (!mem.empty())
|
||
{
|
||
memory_size_ = std::stoi(mem);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Get the config file --->memory_size_ set is :%lld", memory_size_);
|
||
}
|
||
getl = GetPrivateProfileStringA("cpu", "advanced", "", strbuf, sizeof(strbuf) - 1, config_file.c_str());
|
||
strbuf[getl] = 0;
|
||
std::string adv(strbuf);
|
||
if (!adv.empty())
|
||
{
|
||
isx86_Advan_ = adv == "0" ? false : true;
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Get the config file --->isx86_Advan_ set is :%d", isx86_Advan_);
|
||
}
|
||
|
||
if (utils::create_folder(final_path_.c_str()))
|
||
{
|
||
utils::to_log(LOG_LEVEL_WARNING, "temporary image folder: %s\n", final_path_.c_str());
|
||
final_path_ += PATH_SEPARATOR;
|
||
}
|
||
else
|
||
{
|
||
utils::to_log(LOG_LEVEL_WARNING, "create temporary image folder failed: %s\n", final_path_.c_str());
|
||
final_path_ = "";
|
||
}
|
||
|
||
custom_gamma_val_ = new SANE_Gamma;
|
||
memset(custom_gamma_val_, 0, sizeof(SANE_Gamma));
|
||
for (int i = 0; i < ARRAY_SIZE(custom_gamma_val_->table); ++i)
|
||
custom_gamma_val_->table[i] = i & 0x0ff;
|
||
|
||
paper_size_mm_.cx = 210;
|
||
paper_size_mm_.cy = 297;
|
||
|
||
utils::to_log(LOG_LEVEL_DEBUG, "%s(%p) constructed\n", name_.c_str(), this);
|
||
image_prc_param_.value = 0;
|
||
|
||
if (io_)
|
||
{
|
||
io_->add_ref();
|
||
status_ = io_->last_error();
|
||
online_ = status_ == SCANNER_ERR_OK;
|
||
}
|
||
|
||
wait_usb_.set_debug_info("USB");
|
||
wait_img_.set_debug_info("Image");
|
||
wait_usb_result_.set_debug_info("start");
|
||
wait_devsislock_.set_debug_info("Devsislock");
|
||
//wait_read_int.set_debug_info("read_int");
|
||
//thread_read_int_.reset(new std::thread(&hg_scanner::thread_read_int, this));
|
||
thread_usb_read_.reset(new std::thread(&hg_scanner::thread_handle_usb, this));
|
||
thread_img_handle_.reset(new std::thread(&hg_scanner::thread_image_handle, this));
|
||
|
||
#ifdef OEM_HUAGAO
|
||
thread_devslock_handle_.reset(new std::thread(&hg_scanner::thread_devslock_handle, this));
|
||
#endif
|
||
|
||
ImagePrc_pHandle_ = hg_imgproc::init(pid_, isx86_Advan_);;
|
||
//ImagePrc_pHandle_ = nullptr;
|
||
}
|
||
hg_scanner::~hg_scanner()
|
||
{
|
||
close(true);
|
||
|
||
hg_version_free_handle();
|
||
//if (thread_read_int_.get() && thread_read_int_->joinable())
|
||
// thread_read_int_->join();
|
||
if (thread_usb_read_.get() && thread_usb_read_->joinable())
|
||
thread_usb_read_->join();
|
||
if (thread_img_handle_.get() && thread_img_handle_->joinable())
|
||
thread_img_handle_->join();
|
||
|
||
#ifdef OEM_HUAGAO
|
||
if (thread_devslock_handle_.get() && thread_devslock_handle_->joinable())
|
||
thread_devslock_handle_->join();
|
||
#endif
|
||
|
||
delete custom_gamma_val_;
|
||
if(ImagePrc_pHandle_)
|
||
hg_imgproc::release(ImagePrc_pHandle_);
|
||
|
||
name_.insert(0, lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_DEVS, nullptr));
|
||
name_ += lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_IS_CLOSE, nullptr);
|
||
notify_ui_working_status(name_.c_str(), SANE_EVENT_SCANNER_CLOSED);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "%s(%p) destroyed.\n", name_.c_str(), this);
|
||
delete setting_jsn_; // ->release();
|
||
}
|
||
|
||
std::string hg_scanner::temporary_file(char* tail, char* head)
|
||
{
|
||
std::string path("/tmp/");
|
||
char buf[128];
|
||
FILE* src = NULL;
|
||
unsigned int ind = 1;
|
||
|
||
if (!head || *head == 0)
|
||
head = (char*)"scan";
|
||
if (!tail)
|
||
tail = (char*)"";
|
||
|
||
#if defined(WIN32) || defined(_WIN64)
|
||
char me[MAX_PATH] = { 0 }, * n = NULL;
|
||
|
||
GetModuleFileNameA(NULL, me, _countof(me) - 1);
|
||
n = strrchr(me, '\\');
|
||
if (n++ == NULL)
|
||
n = me;
|
||
*n = 0;
|
||
path = me;
|
||
path += "img_tmp\\";
|
||
mkdir(path.c_str());
|
||
#endif
|
||
|
||
srand(time(NULL));
|
||
sprintf(buf, "%s%s", head, tail);
|
||
while ((src = fopen((path + buf).c_str(), "rb")))
|
||
{
|
||
fclose(src);
|
||
sprintf(buf, "%s(%u)%s", head, ind++, tail);
|
||
}
|
||
|
||
return path + buf;
|
||
}
|
||
int hg_scanner::save_2_tempory_file(std::shared_ptr<std::vector<char>> data, std::string* path_file, unsigned int index)
|
||
{
|
||
char head[40] = { 0 };
|
||
std::string file("");
|
||
FILE* dst = nullptr;
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
sprintf(head, "usb_%05u", index);
|
||
if(!path_file || path_file->empty())
|
||
file = hg_scanner::temporary_file((char*)".jpg", (char*)head);
|
||
dst = fopen(file.c_str(), "wb");
|
||
if (dst)
|
||
{
|
||
size_t wrote = fwrite(data->data(), 1, data->size(), dst);
|
||
if (wrote == data->size())
|
||
{
|
||
if (path_file)
|
||
*path_file = file;
|
||
utils::to_log(LOG_LEVEL_DEBUG, "--->Wrote %u bytes to file '%s'\n", wrote, file.c_str());
|
||
}
|
||
else
|
||
{
|
||
ret = SCANNER_ERR_WRITE_FILE_FAILED;
|
||
utils::to_log(LOG_LEVEL_FATAL, "Failed in writting file(%u/%u) '%s'\n", wrote, data->size(), file.c_str());
|
||
}
|
||
fclose(dst);
|
||
}
|
||
else
|
||
{
|
||
ret = SCANNER_ERR_CREATE_FILE_FAILED;
|
||
utils::to_log(LOG_LEVEL_FATAL, "Failed in creating file '%s'\n", file.c_str());
|
||
}
|
||
|
||
return ret;
|
||
}
|
||
void hg_scanner::thread_devslock_handle(void)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
while (run_)
|
||
{
|
||
wait_devsislock_.wait();
|
||
#ifdef OEM_HUAGAO
|
||
if (is_firstopen_ && firmware_sup_devs_lock_)
|
||
{
|
||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||
ret = set_server_blacklist_lock();
|
||
hg_version_free_handle();
|
||
}
|
||
#endif
|
||
is_firstopen_ = false;
|
||
//is_read_int = false;
|
||
break;
|
||
}
|
||
|
||
//int ret = SCANNER_ERR_OK;
|
||
//wait_devsislock_.wait();
|
||
//while (is_firstopen_ && firmware_sup_devs_lock_)
|
||
//{
|
||
// if (!is_read_int)
|
||
// {
|
||
// std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||
// ret = set_server_blacklist_lock();
|
||
// hg_version_free_handle();
|
||
// is_firstopen_ = false;
|
||
// }
|
||
//}
|
||
}
|
||
void hg_scanner::thread_read_int(void)
|
||
{
|
||
while (run_)
|
||
{
|
||
wait_read_int.wait();
|
||
if (is_read_int && is_firstopen_ && pid_ == 0x300)
|
||
{
|
||
is_read_int = true;
|
||
//notify_ui_working_status(STATU_DESC_SCANNER_ERR_DEVICE_DEVS_BOOTING, SANE_EVENT_STATUS, status_);
|
||
//discard_all_images();
|
||
set_updata0303();
|
||
//notify_ui_working_status(STATU_DESC_SCANNER_ERR_DEVICE_DEVS_START_SUCCES, SANE_EVENT_STATUS, status_);
|
||
}
|
||
if (is_firstopen_)
|
||
{
|
||
//wait_devsislock_.notify();
|
||
}
|
||
}
|
||
|
||
//if (is_read_int && pid_ == 0x0300)
|
||
//{
|
||
// wait_read_int.wait();
|
||
// is_read_int = true;
|
||
// notify_ui_working_status(STATU_DESC_SCANNER_ERR_DEVICE_DEVS_BOOTING, SANE_EVENT_STATUS, status_);
|
||
// //discard_all_images();
|
||
// set_updata0303();
|
||
// notify_ui_working_status(STATU_DESC_SCANNER_ERR_DEVICE_DEVS_START_SUCCES, SANE_EVENT_STATUS, status_);
|
||
//}
|
||
//is_read_int = false;
|
||
}
|
||
void hg_scanner::thread_handle_usb(void)
|
||
{
|
||
int cnt = 0;
|
||
utils::to_log(LOG_LEVEL_DEBUG, "[thread_handle_usb 'START' !!!]:[%d]\n", cnt);
|
||
while (run_)
|
||
{
|
||
cnt++;
|
||
utils::to_log(LOG_LEVEL_DEBUG, "[thread_handle_usb 'WAIT' !!!]:[%d]\n", cnt);
|
||
wait_usb_.wait();
|
||
utils::to_log(LOG_LEVEL_DEBUG, "[thread_handle_usb 'NOTIFY' !!!]:[%d]\n", cnt);
|
||
if (!run_)
|
||
break;
|
||
|
||
if (scan_life_)
|
||
{
|
||
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
|
||
if (scan_life_)
|
||
{
|
||
utils::to_log(LOG_LEVEL_FATAL, "[thread_handle_usb image process is still running!]:[%d]\n", cnt);
|
||
continue;
|
||
}
|
||
}
|
||
|
||
scan_life_ = new do_when_born_and_dead<hg_scanner>(this, &hg_scanner::working_begin, &hg_scanner::working_done, NULL);
|
||
usb_img_index_ = 0;
|
||
thread_handle_usb_read();
|
||
if (scan_life_->release() == 0)
|
||
scan_life_ = NULL;
|
||
|
||
utils::to_log(LOG_LEVEL_DEBUG, "[thread_handle_usb_read 'GET IMAGE END'!!!]:[%d]\n", cnt);
|
||
}
|
||
utils::to_log(LOG_LEVEL_DEBUG, "[thread_handle_usb EXIT !!!]:[%d]\n", cnt);
|
||
}
|
||
void hg_scanner::thread_image_handle(void)
|
||
{
|
||
while (run_)
|
||
{
|
||
wait_img_.wait();
|
||
if (!run_)
|
||
break;
|
||
|
||
scan_life_->add_ref();
|
||
thread_handle_image_process();
|
||
if (scan_life_->release() == 0)
|
||
scan_life_ = NULL;
|
||
}
|
||
}
|
||
|
||
int hg_scanner::hg_version_init_handle()
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
string scanner_path = utils::get_module_full_path(SCANNER_DRIVER_PART_NAME);
|
||
if (scanner_path.empty())
|
||
{
|
||
return SCANNER_ERR_OUT_OF_RANGE;
|
||
}
|
||
size_t pos = scanner_path.rfind(PATH_SEPARATOR[0]);
|
||
if(pos++ == std::string::npos)
|
||
pos = 0;
|
||
scanner_path.erase(pos);
|
||
|
||
#ifndef WIN32
|
||
string HGVersionlib_path = scanner_path + HGVERSION_LIBNANE;
|
||
|
||
if (access(HGVersionlib_path.c_str(), F_OK) != 0)
|
||
{
|
||
return SCANNER_ERR_OUT_OF_RANGE;
|
||
}
|
||
printf("HGVersionlib_path:%s \r\n", HGVersionlib_path.c_str());
|
||
Dynamicopen_HGVersion_pHandle_ = dlopen(HGVersionlib_path.c_str(), RTLD_LAZY);
|
||
|
||
if (!Dynamicopen_HGVersion_pHandle_ )
|
||
{
|
||
utils::to_log(LOG_LEVEL_DEBUG, "HGVersionlib_path open dll is error: %s\n", hg_scanner_err_name(SCANNER_ERR_INSUFFICIENT_MEMORY));
|
||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
}
|
||
HGVersion_Init_ = (SDKHGVersion_Init_)dlsym(Dynamicopen_HGVersion_pHandle_, "HGVersion_CreateMgr");
|
||
HGVersion_Islock_ = (SDKHGVersion_Islock_)dlsym(Dynamicopen_HGVersion_pHandle_, "HGVersion_BlackListCheck");
|
||
HGVersion_Postlog_ = (SDKHGVersion_Postlog_)dlsym(Dynamicopen_HGVersion_pHandle_, "HGVersion_PostDeviceLockInfo");
|
||
HGVersion_Free_ = (SDKHGVersion_Free_)dlsym(Dynamicopen_HGVersion_pHandle_, "HGVersion_DestroyMgr");
|
||
|
||
#else
|
||
//string scanner_path = utils::get_module_full_path(LIBNAME);
|
||
//scanner_path = scanner_path.substr(0, scanner_path.size() - strlen(LIBNAME));
|
||
|
||
string HGVersionlib_path = scanner_path + HGVERSION_LIBNANE;
|
||
wchar_t* Prclibbuffer = new wchar_t[HGVersionlib_path.length() + 1];
|
||
|
||
ret = strToWchar(HGVersionlib_path, Prclibbuffer);
|
||
if (ret == -1)
|
||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
|
||
load_dll(Prclibbuffer, &Dynamicopen_HGVersion_pHandle_); //windows下可能会找不到他所在的依赖库导致直接打开动态库的时候找不到模块
|
||
if (Prclibbuffer)
|
||
{
|
||
delete []Prclibbuffer;
|
||
Prclibbuffer = NULL;
|
||
}
|
||
//int l = GetLastError();
|
||
if (!Dynamicopen_HGVersion_pHandle_ )
|
||
{
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Dynamicopen_HGVersion_pHandle_ open dll is error: %s\n", hg_scanner_err_name(SCANNER_ERR_INSUFFICIENT_MEMORY));
|
||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
}
|
||
HGVersion_Init_ = (SDKHGVersion_Init_) GetProcAddress(Dynamicopen_HGVersion_pHandle_, "HGVersion_CreateMgr");
|
||
HGVersion_Islock_ = (SDKHGVersion_Islock_) GetProcAddress(Dynamicopen_HGVersion_pHandle_, "HGVersion_BlackListCheck");
|
||
HGVersion_Postlog_ = (SDKHGVersion_Postlog_) GetProcAddress(Dynamicopen_HGVersion_pHandle_, "HGVersion_PostDeviceLockInfo");
|
||
HGVersion_Free_ = (SDKHGVersion_Free_) GetProcAddress(Dynamicopen_HGVersion_pHandle_, "HGVersion_DestroyMgr");
|
||
#endif
|
||
|
||
if (!HGVersion_Init_ ||!HGVersion_Islock_ || !HGVersion_Postlog_ || !HGVersion_Free_)
|
||
{
|
||
return SCANNER_ERR_INVALID_PARAMETER;
|
||
}
|
||
HGVersion_Init_(&HGVersion_mgr_);
|
||
return ret;
|
||
}
|
||
int hg_scanner::set_server_blacklist_lock()
|
||
{
|
||
if (!HGVersion_mgr_)
|
||
{
|
||
return SCANNER_ERR_INVALID_PARAMETER;
|
||
}
|
||
char snbuffer[20];
|
||
char fvbuffer[15];
|
||
char pidbuffer[5];
|
||
SANE_Bool scan_islock = false;
|
||
memset(snbuffer, 0, sizeof(snbuffer));
|
||
memset(fvbuffer, 0, sizeof(fvbuffer));
|
||
memset(pidbuffer, 0, sizeof(pidbuffer));
|
||
HGBool islock = false;
|
||
|
||
string sn = get_serial_num();
|
||
string fv = get_firmware_version();
|
||
if (fv.empty() || sn.empty())
|
||
return -1;
|
||
::strcpy(snbuffer, sn.c_str());
|
||
::strcpy(fvbuffer, fv.c_str());
|
||
sprintf(pidbuffer, "%0x", pid_);
|
||
//优先从机器设备上进行校验
|
||
int ret = HGVersion_Islock_(HGVersion_mgr_, snbuffer, &islock);
|
||
int islock_file = 0;
|
||
if (ret != 0) //服务器没有连接到网络
|
||
{
|
||
ret = get_dev_islock_file(islock_file);
|
||
is_checksum_strat_scan = islock_file <= 0 ? true : false; //使用校验码来进行扫描,以后只会使用这种方法进行扫描
|
||
utils::to_log(LOG_LEVEL_DEBUG, "net is 404 , devs list is:%d\n", islock_file);
|
||
}
|
||
else if (!islock)
|
||
{
|
||
ret = HGVersion_Postlog_(HGVersion_mgr_, pidbuffer, snbuffer, fv.substr(0, 4).c_str(), fvbuffer, islock); //发送日志到服务,第三个参数随意字符串但不能为NULL
|
||
is_checksum_strat_scan = true;
|
||
set_dev_islock_file(0);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "use checksum start scan:%d\n", islock);
|
||
}
|
||
else
|
||
{
|
||
ret = HGVersion_Postlog_(HGVersion_mgr_, pidbuffer, snbuffer, fv.substr(0, 4).c_str(), fvbuffer, islock); //发送日志到服务,第三个参数随意字符串但不能为NULL
|
||
is_checksum_strat_scan = false;
|
||
set_dev_islock_file(1);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "devs is lock:%d\n", islock);
|
||
}
|
||
return 0 ;
|
||
}
|
||
void hg_scanner::hg_version_free_handle()
|
||
{
|
||
int ret = 0;
|
||
if (HGVersion_mgr_)
|
||
{
|
||
int ret = HGVersion_Free_(HGVersion_mgr_);
|
||
HGVersion_mgr_ = NULL;
|
||
}
|
||
if (Dynamicopen_HGVersion_pHandle_)
|
||
{
|
||
#if (!defined WIN32)
|
||
ret = dlclose(Dynamicopen_HGVersion_pHandle_);
|
||
#else
|
||
ret = FreeLibrary(Dynamicopen_HGVersion_pHandle_);
|
||
#endif
|
||
Dynamicopen_HGVersion_pHandle_ = NULL;
|
||
}
|
||
}
|
||
void hg_scanner::dump_image_empty(hg_imgproc::HIMGPRC himg, const char* desc)
|
||
{}
|
||
void hg_scanner::dump_image_real(hg_imgproc::HIMGPRC himg, const char* desc)
|
||
{
|
||
char sn[40] = { 0 };
|
||
|
||
sprintf(sn, "%03d_", final_img_index_ + 1);
|
||
hg_imgproc::dump_2_file(himg, (dump_usb_path_ + PATH_SEPARATOR + sn + desc + ".jpg").c_str());
|
||
}
|
||
void hg_scanner::init_setting_func_map(void)
|
||
{
|
||
setting_map_[SANE_STD_OPT_NAME_RESTORE] = &hg_scanner::setting_restore;
|
||
setting_map_[SANE_STD_OPT_NAME_HELP] = &hg_scanner::setting_help;
|
||
setting_map_[SANE_STD_OPT_NAME_COLOR_MODE] = &hg_scanner::setting_color_mode;
|
||
setting_map_[SANE_STD_OPT_NAME_IS_MULTI_OUT] = &hg_scanner::setting_multi_out;
|
||
setting_map_[SANE_STD_OPT_NAME_MULTI_OUT_TYPE] = &hg_scanner::setting_multi_out_type;
|
||
setting_map_[SANE_STD_OPT_NAME_FILTER] = &hg_scanner::setting_rid_color;
|
||
setting_map_[SANE_STD_OPT_NAME_RID_MULTIOUT_RED] = &hg_scanner::setting_rid_multi_red;
|
||
setting_map_[SANE_STD_OPT_NAME_RID_ANSWER_SHEET_RED] = &hg_scanner::setting_rid_answer_red;
|
||
setting_map_[SANE_STD_OPT_NAME_ERASE_BACKGROUND] = &hg_scanner::setting_erase_background;
|
||
setting_map_[SANE_STD_OPT_NAME_BKG_COLOR_RANGE] = &hg_scanner::setting_erase_background_range;
|
||
setting_map_[SANE_STD_OPT_NAME_NOISE_OPTIMIZE] = &hg_scanner::setting_noise_optimize;
|
||
setting_map_[SANE_STD_OPT_NAME_NOISE_SIZE] = &hg_scanner::setting_noise_optimize_range;
|
||
setting_map_[SANE_STD_OPT_NAME_PAPER] = &hg_scanner::setting_paper;
|
||
setting_map_[SANE_STD_OPT_NAME_SIZE_CHECK] = &hg_scanner::setting_paper_check;
|
||
setting_map_[SANE_STD_OPT_NAME_PAGE] = &hg_scanner::setting_page;
|
||
setting_map_[SANE_STD_OPT_NAME_DISCARD_BLANK_SENS] = &hg_scanner::setting_page_omit_empty;
|
||
setting_map_[SANE_STD_OPT_NAME_RESOLUTION] = &hg_scanner::setting_resolution;
|
||
setting_map_[SANE_STD_OPT_NAME_EXCHANGE] = &hg_scanner::setting_exchagnge;
|
||
setting_map_[SANE_STD_OPT_NAME_SPLIT] = &hg_scanner::setting_split_image;
|
||
setting_map_[SANE_STD_OPT_NAME_ANTI_SKEW] = &hg_scanner::setting_automatic_skew;
|
||
setting_map_[SANE_STD_OPT_NAME_RID_HOLE] = &hg_scanner::setting_rid_hole;
|
||
setting_map_[SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE] = &hg_scanner::setting_rid_hoe_range;
|
||
setting_map_[SANE_STD_OPT_NAME_BRIGHTNESS] = &hg_scanner::setting_bright;
|
||
setting_map_[SANE_STD_OPT_NAME_CONTRAST] = &hg_scanner::setting_contrast;
|
||
setting_map_[SANE_STD_OPT_NAME_GAMMA] = &hg_scanner::setting_gamma;
|
||
setting_map_[SANE_STD_OPT_NAME_SHARPEN] = &hg_scanner::setting_sharpen;
|
||
setting_map_[SANE_STD_OPT_NAME_DARK_SAMPLE] = &hg_scanner::setting_dark_sample;
|
||
setting_map_[SANE_STD_OPT_NAME_ERASE_BLACK_FRAME] = &hg_scanner::setting_erase_black_frame;
|
||
setting_map_[SANE_STD_OPT_NAME_THRESHOLD] = &hg_scanner::setting_threshold;
|
||
setting_map_[SANE_STD_OPT_NAME_ANTI_NOISE_LEVEL] = &hg_scanner::setting_anti_noise;
|
||
setting_map_[SANE_STD_OPT_NAME_MARGIN] = &hg_scanner::setting_margin;
|
||
setting_map_[SANE_STD_OPT_NAME_FILL_BKG_MODE] = &hg_scanner::setting_filling_background;
|
||
setting_map_[SANE_STD_OPT_NAME_IS_ANTI_PERMEATE] = &hg_scanner::setting_is_permeate;
|
||
setting_map_[SANE_STD_OPT_NAME_ANTI_PERMEATE_LEVEL] = &hg_scanner::setting_is_permeate_lv;
|
||
setting_map_[SANE_STD_OPT_NAME_RID_MORR] = &hg_scanner::setting_remove_morr;
|
||
setting_map_[SANE_STD_OPT_NAME_ERROR_EXTENSION] = &hg_scanner::setting_error_extention;
|
||
setting_map_[SANE_STD_OPT_NAME_RID_GRID] = &hg_scanner::setting_remove_texture;
|
||
setting_map_[SANE_STD_OPT_NAME_IS_ULTROSONIC_CHECK] = &hg_scanner::setting_ultrasonic_check;
|
||
setting_map_[SANE_STD_OPT_NAME_DOUBLE_FEED_HANDLE] = &hg_scanner::setting_go_on_when_double_checked;
|
||
setting_map_[SANE_STD_OPT_NAME_IS_CHECK_STAPLE] = &hg_scanner::setting_staple_check;
|
||
setting_map_[SANE_STD_OPT_NAME_SCAN_MODE] = &hg_scanner::setting_scan_mode;
|
||
setting_map_[SANE_STD_OPT_NAME_SCAN_COUNT] = &hg_scanner::setting_scan_count;
|
||
setting_map_[SANE_STD_OPT_NAME_TEXT_DIRECTION] = &hg_scanner::setting_text_direction;
|
||
setting_map_[SANE_STD_OPT_NAME_IS_ROTATE_BKG_180] = &hg_scanner::setting_rotate_bkg_180;
|
||
setting_map_[SANE_STD_OPT_NAME_IS_CHECK_DOG_EAR] = &hg_scanner::setting_fractate_check;
|
||
setting_map_[SANE_STD_OPT_NAME_DOG_EAR_SIZE] = &hg_scanner::setting_fractate_check_level;
|
||
setting_map_[SANE_STD_OPT_NAME_IS_CHECK_ASKEW] = &hg_scanner::setting_skew_check;
|
||
setting_map_[SANE_STD_OPT_NAME_ASKEW_RANGE] = &hg_scanner::setting_skew_check_level;
|
||
setting_map_[SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA] = &hg_scanner::setting_is_custom_gamma;
|
||
|
||
setting_map_[SANE_STD_OPT_NAME_CUSTOM_AREA] = &hg_scanner::setting_is_custom_area;
|
||
setting_map_[SANE_STD_OPT_NAME_CUSTOM_AREA_LEFT] = &hg_scanner::setting_custom_area_left;
|
||
setting_map_[SANE_STD_OPT_NAME_CUSTOM_AREA_RIGHT] = &hg_scanner::setting_custom_area_right;
|
||
setting_map_[SANE_STD_OPT_NAME_CUSTOM_AREA_TOP] = &hg_scanner::setting_custom_area_top;
|
||
setting_map_[SANE_STD_OPT_NAME_CUSTOM_AREA_BOTTOM] = &hg_scanner::setting_custom_area_bottom;
|
||
setting_map_[SANE_STD_OPT_NAME_IMAGE_QUALITY] = &hg_scanner::setting_img_quality;
|
||
setting_map_[SANE_STD_OPT_NAME_IS_FILL_COLOR] = &hg_scanner::setting_color_fill;
|
||
setting_map_[SANE_STD_OPT_NAME_IS_PHOTO_MODE] = &hg_scanner::setting_keep_watermark;
|
||
setting_map_[SANE_STD_OPT_NAME_BINARY_THRESHOLD] = &hg_scanner::setting_black_white_threshold;
|
||
setting_map_[SANE_STD_OPT_NAME_REVERSE_01] = &hg_scanner::setting_white_pixel_0;
|
||
setting_map_[SANE_STD_OPT_NAME_FEED_STRENGTH] = &hg_scanner::setting_feedmode;
|
||
setting_map_[SANE_STD_OPT_NAME_TIME_TO_SLEEP] = &hg_scanner::setting_sleeptime;
|
||
setting_map_[SANE_STD_OPT_NAME_IS_AUTO_FEED_STRENGTH] = &hg_scanner::setting_auto_pick_paper;
|
||
setting_map_[SANE_STD_OPT_NAME_FEED_STRENGTH_VALUE] = &hg_scanner::setting_auto_pick_paper_threshold;
|
||
setting_map_[SANE_STD_OPT_NAME_WAIT_TO_SCAN] = &hg_scanner::setting_auto_paper_scan;
|
||
setting_map_[SANE_STD_OPT_NAME_RID_HOLE_L] = &hg_scanner::setting_isremove_left_hole;
|
||
setting_map_[SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_L] = &hg_scanner::setting_isremove_left_hole_threshold;
|
||
setting_map_[SANE_STD_OPT_NAME_RID_HOLE_R] = &hg_scanner::setting_isremove_right_hole;
|
||
setting_map_[SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_R] = &hg_scanner::setting_isremove_right_hole_threshold;
|
||
setting_map_[SANE_STD_OPT_NAME_RID_HOLE_T] = &hg_scanner::setting_isremove_top_hole;
|
||
setting_map_[SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_T] = &hg_scanner::setting_isremove_top_hole_threshold;
|
||
setting_map_[SANE_STD_OPT_NAME_RID_HOLE_B] = &hg_scanner::setting_isremove_low_hole;
|
||
setting_map_[SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_B] = &hg_scanner::setting_isremove_low_hole_threshold;
|
||
setting_map_[SANE_STD_OPT_NAME_FOLD_TYPE] = &hg_scanner::setting_fold_type;
|
||
setting_map_[SANE_STD_OPT_NAME_COLOR_CORRECTION] = &hg_scanner::setting_color_correction;
|
||
setting_map_[SANE_STD_OPT_NAME_WAIT_SCAN_EXIT] = &hg_scanner::setting_auto_paper_scan_exit_time;
|
||
setting_map_[SANE_STD_OPT_NAME_DISCARDBLANK] = &hg_scanner::setting_set_discardblank;
|
||
|
||
|
||
|
||
|
||
|
||
setting_map_[SANE_STD_OPT_NAME_DEVICE_VID] = &hg_scanner::setting_get_dev_vid;
|
||
setting_map_[SANE_STD_OPT_NAME_DEVICE_PID] = &hg_scanner::setting_get_dev_pid;
|
||
setting_map_[SANE_STD_OPT_NAME_DEVICE_MODEL] = &hg_scanner::setting_get_dev_family;
|
||
setting_map_[SANE_STD_OPT_NAME_DEVICE_NAME] = &hg_scanner::setting_get_dev_name;
|
||
setting_map_[SANE_STD_OPT_NAME_DEVICE_SERIAL_NO] = &hg_scanner::setting_get_dev_sn;
|
||
setting_map_[SANE_STD_OPT_NAME_FIRMWARE_VERSION] = &hg_scanner::setting_get_dev_fmver;
|
||
setting_map_[SANE_STD_OPT_NAME_DEVICE_IP_ADDR] = &hg_scanner::setting_get_dev_ip;
|
||
setting_map_[SANE_STD_OPT_NAME_ROLLER_COUNT] = &hg_scanner::setting_get_roller_count;
|
||
setting_map_[SANE_STD_OPT_NAME_TOTAL_COUNT] = &hg_scanner::setting_get_history_count;
|
||
setting_map_[SANE_STD_OPT_NAME_GET_DEVS_L0G] = &hg_scanner::setting_get_devs_log;
|
||
setting_map_[SANE_STD_OPT_NAME_LANGUAGE] = &hg_scanner::setting_set_language;
|
||
setting_map_[SANE_STD_OPT_NAME_MOTOR_VER] = &hg_scanner::setting_get_motor_ver;
|
||
setting_map_[SANE_STD_OPT_NAME_INITIAL_BOOT_TIME] = &hg_scanner::setting_get_initial_boot_time;
|
||
}
|
||
int hg_scanner::restore(const char* name)
|
||
{
|
||
std::string type(setting_jsn_->get_option_value_type(name)), val("");
|
||
int ret = SCANNER_ERR_OK, size = 0;
|
||
|
||
if (type != JSON_SANE_TYPE_BOOL && type != JSON_SANE_TYPE_INT && type != JSON_SANE_TYPE_FIXED && type != JSON_SANE_TYPE_STRING)
|
||
return ret;
|
||
|
||
ret = set_setting(name, nullptr, true);
|
||
|
||
return ret;
|
||
}
|
||
bool hg_scanner::is_to_file(void)
|
||
{
|
||
return resolution_ > 200
|
||
|| paper_size_ == TwSS::USStatement
|
||
|| paper_size_ == TwSS::MaxSize
|
||
|| paper_size_ == TwSS::Trigeminy;
|
||
}
|
||
void hg_scanner::thread_handle_image_process(void)
|
||
{
|
||
//VLDGlobalEnable();
|
||
//VLDReportLeaks();
|
||
//while (run_ && !user_cancel_)
|
||
int cnt = 0;
|
||
while (run_)
|
||
{
|
||
std::shared_ptr<tiny_buffer> tiny_buffer;
|
||
if (imgs_.Size() == 0)
|
||
{
|
||
if (wait_usb_.is_waiting())
|
||
{
|
||
utils::to_log(LOG_LEVEL_DEBUG, "[thread_handle_image_process 'break thread!!!'] Total pic %d.\n", cnt);
|
||
cnt = 0;
|
||
break;
|
||
}
|
||
this_thread::sleep_for(chrono::milliseconds(30));
|
||
continue;
|
||
}
|
||
|
||
uint32_t id = -1;
|
||
cnt++;
|
||
utils::log_info("\r\n", LOG_LEVEL_DEBUG);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "[thread_handle_image_process] Total from the queue:[%d].\n", cnt);
|
||
tiny_buffer = imgs_.Take(&id);
|
||
if (tiny_buffer->swap())
|
||
{
|
||
try
|
||
{
|
||
if (!ImagePrc_pHandle_)
|
||
{
|
||
ImagePrc_pHandle_ = hg_imgproc::init(pid_, isx86_Advan_);
|
||
if (!ImagePrc_pHandle_)
|
||
{
|
||
utils::to_log(LOG_LEVEL_FATAL, "[thread_handle_image_process]:Get Image Process is NULL pid is %d.\n", pid_);
|
||
stop_fatal_ = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
stop();
|
||
break;
|
||
}
|
||
}
|
||
image_process(tiny_buffer, id);
|
||
}
|
||
catch (const std::exception& e)
|
||
{
|
||
if (is_dpi_color_check)
|
||
{
|
||
is_dpi_color_check = false;
|
||
stop_fatal_ = SCANNER_ERR_DEVICE_DISTORTION;
|
||
}
|
||
else
|
||
stop_fatal_ = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
utils::to_log(LOG_LEVEL_FATAL, "[thread_handle_image_process]:is opencv Fatal and stop scanner: %s\n", e.what());
|
||
stop();
|
||
break;
|
||
|
||
}
|
||
catch (...)
|
||
{
|
||
utils::to_log(LOG_LEVEL_FATAL, "[thread_handle_image_process]:stop scanner!!! Insufficient memory when proecss image with %d bytes.\n", tiny_buffer->size());
|
||
stop_fatal_ = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
stop();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
utils::to_log(LOG_LEVEL_FATAL, "[thread_handle_image_process]:Reload USB data '%s' failed!\n", tiny_buffer->file().c_str());
|
||
}
|
||
}
|
||
utils::log_info("[thread_handle_image_process 'EXIT !!!']\n", LOG_LEVEL_DEBUG);
|
||
//VLDGlobalDisable();
|
||
}
|
||
void hg_scanner::working_begin(void*)
|
||
{
|
||
stop_fatal_ = SCANNER_ERR_OK;
|
||
final_img_index_ = 0;
|
||
status_ = SCANNER_ERR_OK;
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCAN_WORKING, nullptr), SANE_EVENT_WORKING, SCANNER_ERR_OK);
|
||
utils::log_info("scanning ...\n", LOG_LEVEL_DEBUG);
|
||
}
|
||
void hg_scanner::working_done(void*)
|
||
{
|
||
// imgs_.Clear(); // do before start ...
|
||
// if(user_cancel_)
|
||
// final_imgs_.clear();
|
||
|
||
if (status_ == SCANNER_ERR_OK && stop_fatal_)
|
||
status_ = stop_fatal_;
|
||
|
||
switch (status_)
|
||
{
|
||
case SCANNER_ERR_OK:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCAN_STOPPED, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_BUSY:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_PC_BUSY, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_STOPPED:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCAN_STOPPED, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_COVER_OPENNED:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_COVER_OPENNED, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_NO_PAPER:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_NO_PAPER, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_FEEDING_PAPER:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_FEEDING_PAPER, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_NOT_FOUND:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_NOT_FOUND, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_SLEEPING:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_SLEEPING, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_COUNT_MODE:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_COUNT_MODE, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_DOUBLE_FEEDING:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_DOUBLE_FEEDING, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_PAPER_JAMMED:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_PAPER_JAMMED, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_STAPLE_ON:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_STAPLE_ON, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_PAPER_SKEW:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_PAPER_SKEW, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_SIZE_CHECK:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_SIZE_CHECK, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_DOGEAR:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_DOGEAR, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_NO_IMAGE:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_NO_IMAGE, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_SCANN_ERROR:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_SCANN_ERROR, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_PC_BUSY:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_PC_BUSY, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_INSUFFICIENT_MEMORY:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_INSUFFICIENT_MEMORY, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_TIMEOUT:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_TIMEOUT, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_ISLOCK:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_ISLOCK, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_AUTO_FAIL_OVER:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_AUTO_FAIL_OVER, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_DISTORTION:
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_DEVICE_DISTORTION, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_MAYBE_IS_HOLE:
|
||
notify_ui_working_status(from_default_language(STATU_DESC_SCANNER_ERR_DEVICE_MAYBE_IS_HOLE, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
case SCANNER_ERR_DEVICE_DEVS_BOOTING:
|
||
notify_ui_working_status(from_default_language(STATU_DESC_SCANNER_ERR_DEVICE_DEVS_BOOTING, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
default:
|
||
notify_ui_working_status(user_cancel_ ? lang_load_string(ID_STATU_DESC_SCAN_CANCELED, nullptr) : lang_load_string(ID_STATU_DESC_SCAN_STOPPED, nullptr), SANE_EVENT_SCAN_FINISHED, status_);
|
||
break;
|
||
}
|
||
|
||
if (test_1_paper_)
|
||
{
|
||
utils::log_info("scanning mode: finished testing ONE paper, restore to normal scanning.\n", LOG_LEVEL_DEBUG);
|
||
}
|
||
else
|
||
{
|
||
utils::to_log(LOG_LEVEL_DEBUG, "EXIT All Thread--->Total picture: [%d] and scanner status [%s].\n", final_img_index_, hg_scanner_err_description(status_));
|
||
}
|
||
utils::to_log(LOG_LEVEL_DEBUG, "----------Main End scan status----------%s:\n", hg_scanner_err_description(status_));
|
||
|
||
test_1_paper_ = false;
|
||
}
|
||
|
||
bool hg_scanner::jsn_reorganize()
|
||
{
|
||
gb_json* paper = nullptr, * range = nullptr;
|
||
|
||
if (!firmware_sup_wait_paper_ && pid_ == 0x239)
|
||
{
|
||
erase_option(SANE_STD_OPT_NAME_WAIT_TO_SCAN);
|
||
erase_option(SANE_STD_OPT_NAME_WAIT_SCAN_EXIT);
|
||
}
|
||
if (!firmware_sup_pick_strength_ && pid_ == 0x239)
|
||
{
|
||
erase_option(SANE_STD_OPT_NAME_IS_AUTO_FEED_STRENGTH);
|
||
erase_option(SANE_STD_OPT_NAME_FEED_STRENGTH_VALUE);
|
||
erase_option(SANE_STD_OPT_NAME_FEED_STRENGTH);
|
||
}
|
||
if (!firmware_sup_color_fill_ && (pid_ == 0x239 || pid_ == 0x439))
|
||
{
|
||
erase_option(SANE_STD_OPT_NAME_IS_FILL_COLOR);
|
||
}
|
||
if (!firmware_sup_color_corr_ && (pid_ == 0x239 || pid_ == 0x439))
|
||
{
|
||
erase_option(SANE_STD_OPT_NAME_COLOR_CORRECTION);
|
||
}
|
||
if (!firmware_sup_morr_)
|
||
{
|
||
erase_option(SANE_STD_OPT_NAME_RID_MORR);
|
||
}
|
||
|
||
if (pid_ == 0x239 || pid_ == 0x439) //固件不支持防止渗透等级
|
||
{
|
||
erase_option(SANE_STD_OPT_NAME_ANTI_PERMEATE_LEVEL);
|
||
}
|
||
erase_option(SANE_STD_OPT_NAME_RID_GRID); //全系移除 除网纹
|
||
|
||
return true;
|
||
}
|
||
int hg_scanner::hgpaper_to_devspaper(Paper_Map papermap[], int len, int& paper, bool* exact, TwSS* type)
|
||
{
|
||
int ind = 0;
|
||
bool good = true, * r = exact ? exact : &good;
|
||
|
||
for (int i = 0; i < len; ++i)
|
||
{
|
||
if (paper == papermap[i].paper)
|
||
{
|
||
ind = i;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (paper == papermap[ind].paper)
|
||
*r = true;
|
||
else
|
||
*r = false;
|
||
paper = papermap[ind].paper;
|
||
if (type)
|
||
*type = papermap[ind].type;
|
||
|
||
return ind;
|
||
}
|
||
int hg_scanner::invoke_setting_xxx(int(hg_scanner::*func)(void*, long*), void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
auto it = setting_map_.begin();
|
||
while (it != setting_map_.end())
|
||
{
|
||
if (it->second == func)
|
||
{
|
||
ret = set_setting(it->first.c_str(), data, false);
|
||
break;
|
||
}
|
||
++it;
|
||
}
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_restore(void* data, long* len)
|
||
{
|
||
// restore ...
|
||
notify_setting_result_ = false;
|
||
for (int i = 0; i < setting_jsn_->count(); ++i)
|
||
restore(setting_jsn_->get_name_by_sane_id(i + 1).c_str());
|
||
notify_setting_result_ = true;
|
||
|
||
return SCANNER_ERR_CONFIGURATION_CHANGED;
|
||
}
|
||
|
||
static int GetModuleName(void* addr, char* name, int maxLen)
|
||
{
|
||
if (NULL == name || 0 == maxLen)
|
||
{
|
||
return -1;
|
||
}
|
||
|
||
#if !defined(_WIN32)
|
||
if (NULL == addr)
|
||
{
|
||
char dir[PATH_MAX] = { 0 };
|
||
if (0 == readlink("/proc/self/exe", dir, PATH_MAX))
|
||
return -1;
|
||
if (maxLen < strlen(dir) + 1)
|
||
return -1;
|
||
::strcpy(name, dir);
|
||
}
|
||
else
|
||
{
|
||
Dl_info dlinfo;
|
||
if (0 == dladdr(addr, &dlinfo))
|
||
return -1;
|
||
if (maxLen < strlen(dlinfo.dli_fname) + 1)
|
||
return -1;
|
||
::strcpy(name, dlinfo.dli_fname);
|
||
}
|
||
#else
|
||
HMODULE hModule = NULL;
|
||
GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
|
||
| GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR)addr, &hModule);
|
||
|
||
CHAR moduleName[MAX_PATH] = { 0 };
|
||
DWORD len = GetModuleFileNameA(hModule, moduleName, MAX_PATH);
|
||
if (0 == len || maxLen < strlen(moduleName) + 1)
|
||
return -1;
|
||
::strcpy(name, moduleName);
|
||
#endif
|
||
return 0;
|
||
}
|
||
|
||
static int GetFilePath(const char* fileName, char* path, int maxLen)
|
||
{
|
||
if (NULL == fileName || NULL == path || 0 == maxLen)
|
||
{
|
||
return -1;
|
||
}
|
||
|
||
#if defined(_WIN32)
|
||
const char* pcName = strrchr(fileName, '\\');
|
||
if (NULL == pcName)
|
||
{
|
||
pcName = strrchr(fileName, '/');
|
||
if (NULL == pcName)
|
||
return -1;
|
||
}
|
||
#else
|
||
const char* pcName = strrchr(fileName, '/');
|
||
if (NULL == pcName)
|
||
return -1;
|
||
#endif
|
||
|
||
++pcName;
|
||
if (maxLen < (int)(pcName - fileName + 1))
|
||
return -1;
|
||
memcpy(path, fileName, pcName - fileName);
|
||
path[pcName - fileName] = 0;
|
||
return 0;
|
||
}
|
||
|
||
int hg_scanner::setting_help(void* data, long* len)
|
||
{
|
||
char moduleName[256];
|
||
GetModuleName(NULL, moduleName, 256);
|
||
char exePath[256];
|
||
GetFilePath(moduleName, exePath, 256);
|
||
std:string exePath2 = exePath;
|
||
|
||
std::string helpfile = exePath2 + HELP_PATH;
|
||
std::string com = "xdg-open ";//注意空格保留
|
||
int code_page = lang_get_cur_code_page();
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
if (code_page == 20127)
|
||
{
|
||
helpfile = exePath2 + HELP_PATH_EN;
|
||
}
|
||
|
||
#if defined(WIN32) || defined(_WIN64)
|
||
com = "";
|
||
//helpfile.insert(0, root);
|
||
FILE* src = fopen(helpfile.c_str(), "rb");
|
||
if (src)
|
||
fclose(src);
|
||
else
|
||
#else
|
||
if (access(helpfile.c_str(),F_OK) == -1)
|
||
#endif
|
||
{
|
||
utils::to_log(LOG_LEVEL_DEBUG,"open help file fail,not find file :%d code page :%d\r\n",helpfile.c_str(), code_page);
|
||
ret = SCANNER_ERR_OPEN_FILE_FAILED;
|
||
return ret ;
|
||
}
|
||
|
||
com += helpfile;
|
||
#if defined(WIN32) || defined(_WIN64)
|
||
ShellExecuteA(NULL, "Open", com.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||
#else
|
||
system(com.c_str());
|
||
#endif
|
||
utils::to_log(LOG_LEVEL_DEBUG,"App_Help_pdf Path is:%s Code Page is:%d\n",helpfile.c_str(), code_page);
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_color_mode(void* data, long* len)
|
||
{
|
||
int old = image_prc_param_.bits.color_mode,
|
||
sub = SCANNER_ERR_OK,
|
||
val = 0,
|
||
ret = SCANNER_ERR_OK;
|
||
std::string str((char*)data);
|
||
|
||
val = image_prc_param_.bits.color_mode = match_best_color_mode(str, NULL);
|
||
|
||
sub = on_color_mode_changed(val);
|
||
image_prc_param_.bits.color_mode = val;
|
||
|
||
if (sub == SCANNER_ERR_NOT_EXACT)
|
||
{
|
||
image_prc_param_.bits.color_mode = old;
|
||
str = color_mode_string(image_prc_param_.bits.color_mode);
|
||
ret = SCANNER_ERR_NOT_EXACT;
|
||
}
|
||
else if (sub)
|
||
{
|
||
ret = sub;
|
||
image_prc_param_.bits.color_mode = old;
|
||
}
|
||
|
||
is_auto_matic_color = image_prc_param_.bits.color_mode == COLOR_MODE_AUTO_MATCH ? true :false; // 等于COLOR_MODE_AUTO_MATCH 的时候颜色模式需要变为2 彩色模式图像参数和硬件参数都如此
|
||
|
||
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Change color mode from %s to %s = %s color is =%s\n", color_mode_string(old).c_str(), (char*)data, hg_scanner_err_name(ret),str.c_str());
|
||
if(ret == SCANNER_ERR_NOT_EXACT)
|
||
::strcpy((char*)data, str.c_str());
|
||
|
||
return SCANNER_ERR_RELOAD_OPT_PARAM; // ret;
|
||
}
|
||
int hg_scanner::setting_multi_out(void* data, long* len)
|
||
{
|
||
is_multiout = *((bool*)data);
|
||
int val = image_prc_param_.bits.color_mode;
|
||
|
||
utils::to_log(LOG_LEVEL_DEBUG, "image_prc_param_.bits.multi_out %d\n", image_prc_param_.bits.multi_out);
|
||
|
||
//if (is_multiout)
|
||
//{
|
||
// if (image_prc_param_.bits.multi_out == MULTI_GRAY_AND_BW)
|
||
// val = COLOR_MODE_256_GRAY;
|
||
// else
|
||
// val = COLOR_MODE_24_BITS;
|
||
//}
|
||
//on_color_mode_changed(val);
|
||
|
||
return SCANNER_ERR_RELOAD_OPT_PARAM; // SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_multi_out_type(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
std::string str((char*)data);
|
||
|
||
int color;
|
||
image_prc_param_.bits.multi_out = match_best_multi_out(str,NULL);
|
||
|
||
save_multiout = str;
|
||
utils::to_log(LOG_LEVEL_DEBUG, "set multi_out type from %s to %s = %s\n", multi_out_string(image_prc_param_.bits.multi_out).c_str(), (char*)data, hg_scanner_err_name(ret));
|
||
|
||
/*if (image_prc_param_.bits.multi_out == MULTI_GRAY_AND_BW)
|
||
color = COLOR_MODE_256_GRAY;
|
||
else
|
||
color = COLOR_MODE_24_BITS;
|
||
|
||
on_color_mode_changed(color);*/
|
||
return SCANNER_ERR_RELOAD_OPT_PARAM; // ret;
|
||
}
|
||
int hg_scanner::setting_rid_color(void* data, long* len)
|
||
{
|
||
std::string str((char*)data);
|
||
int ret = SCANNER_ERR_OK,
|
||
old = image_prc_param_.bits.rid_color;
|
||
|
||
image_prc_param_.bits.rid_color = match_best_rid_color(str, NULL);
|
||
|
||
int color = image_prc_param_.bits.color_mode;
|
||
on_color_mode_changed(color);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_rid_multi_red(void* data, long* len)
|
||
{
|
||
int val = 2;
|
||
image_prc_param_.bits.rid_red = *((bool*)data);
|
||
if (*((bool*)data))
|
||
{
|
||
on_color_mode_changed(val);
|
||
}
|
||
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_rid_answer_red(void* data, long* len)
|
||
{
|
||
int val = 2;
|
||
image_prc_param_.bits.rid_answer_red = *((bool*)data);
|
||
if (*((bool*)data))
|
||
{
|
||
on_color_mode_changed(val);
|
||
}
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_erase_background(void* data, long* len)
|
||
{
|
||
image_prc_param_.bits.erase_bakground = *((bool*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_erase_background_range(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
erase_bkg_range_ = *((int*)data);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_noise_optimize(void* data, long* len)
|
||
{
|
||
image_prc_param_.bits.noise_optimize = *((bool*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_noise_optimize_range(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
noise_range_ = *((int*)data);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_paper(void* data, long* len)
|
||
{
|
||
std::string paper((char*)data);
|
||
int ret = SCANNER_ERR_OK, sub = SCANNER_ERR_OK,
|
||
val = 0,
|
||
old = image_prc_param_.bits.paper;
|
||
|
||
val = image_prc_param_.bits.paper = match_best_paper(paper, NULL);
|
||
|
||
// check 600 dpi ...
|
||
|
||
sub = on_paper_changed(val);
|
||
image_prc_param_.bits.paper = val;
|
||
if (sub == SCANNER_ERR_NOT_EXACT)
|
||
{
|
||
ret = sub;
|
||
paper = paper_string(image_prc_param_.bits.paper);
|
||
}
|
||
else if (sub)
|
||
{
|
||
ret = sub;
|
||
image_prc_param_.bits.paper = old;
|
||
}
|
||
|
||
if (save_sizecheck)
|
||
{
|
||
//setting_paper_check(0,(void*)&save_sizecheck);
|
||
long l = sizeof(save_sizecheck);
|
||
invoke_setting_xxx(&hg_scanner::setting_paper_check, &save_sizecheck, &l);
|
||
}
|
||
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Change paper from %s to %s = %s\n", paper_string(old).c_str(), (char*)data, hg_scanner_err_name(ret));
|
||
|
||
return SCANNER_ERR_RELOAD_OPT_PARAM; // ret;
|
||
}
|
||
int hg_scanner::setting_paper_check(void* data, long* len)
|
||
{
|
||
bool use = *((bool*)data);
|
||
|
||
int ret = on_paper_check_changed(use);
|
||
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Change paper size-checking %s = %s\n", *((bool*)data) ? "enabled" : "disabled", hg_scanner_err_name(ret));
|
||
if (ret == SCANNER_ERR_DEVICE_NOT_SUPPORT)
|
||
{
|
||
*((bool*)data) = use;
|
||
}
|
||
|
||
save_sizecheck = use;
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_page(void* data, long* len)
|
||
{
|
||
std::string val((char*)data);
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Change page from %s to %s = %s\n", page_string(image_prc_param_.bits.page).c_str(), (char*)data, hg_scanner_err_name(ret));
|
||
image_prc_param_.bits.page = match_best_page(val, NULL);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_page_omit_empty(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
omit_empty_level_ = *((int*)data);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_resolution(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK,
|
||
old = resolution_,
|
||
sub = SCANNER_ERR_OK;
|
||
|
||
resolution_ = *((int*)data);
|
||
|
||
return SCANNER_ERR_RELOAD_OPT_PARAM; // ret;
|
||
}
|
||
int hg_scanner::setting_exchagnge(void* data, long* len)
|
||
{
|
||
image_prc_param_.bits.exchange = *((bool*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_split_image(void* data, long* len)
|
||
{
|
||
image_prc_param_.bits.split = *((bool*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_automatic_skew(void* data, long* len)
|
||
{
|
||
// automatic_skew_detection_ = *((bool*)data);
|
||
image_prc_param_.bits.automatic_skew = *((bool*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_rid_hole(void* data, long* len)
|
||
{
|
||
image_prc_param_.bits.rid_hole = *((bool*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_rid_hoe_range(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
rid_hole_range_ = *((double*)data);
|
||
rid_hole_range_*=100;
|
||
utils::to_log(LOG_LEVEL_WARNING, "set rid_hole_range_ = %f\r\n", rid_hole_range_);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_bright(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
bright_ = *((int*)data);
|
||
utils::to_log(LOG_LEVEL_WARNING, "set bright_ = %d\r\n", bright_);
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_contrast(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
contrast_ = *((int*)data);
|
||
utils::to_log(LOG_LEVEL_WARNING, "set contrast_ = %d\r\n", contrast_);
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_gamma(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
gamma_ = *((double*)data);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_sharpen(void* data, long* len)
|
||
{
|
||
std::string str((char*)data);
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Change sharpen from %s to %s = ", sharpen_string(image_prc_param_.bits.sharpen).c_str(), (char*)data);
|
||
|
||
image_prc_param_.bits.sharpen = match_best_sharpen(str, NULL);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "%d\n", ret);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_dark_sample(void* data, long* len)
|
||
{
|
||
image_prc_param_.bits.dark_sample = *((bool*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_erase_black_frame(void* data, long* len)
|
||
{
|
||
image_prc_param_.bits.erase_black_frame = *((bool*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_threshold(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
threshold_ = *((int*)data);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_anti_noise(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
anti_noise_ = *((int*)data);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_margin(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
margin_ = *((int*)data);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_filling_background(void* data, long* len)
|
||
{
|
||
std::string str((char*)data);
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
image_prc_param_.bits.fill_background = match_best_fill_background(str, NULL);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_is_permeate(void* data, long* len)
|
||
{
|
||
image_prc_param_.bits.is_permeate = *((bool*)data);
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_is_permeate_lv(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
std::string str((char*)data);
|
||
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Change is_permeate_lv from %s to %s = ", is_permaeate_string(image_prc_param_.bits.is_permeate_lv_).c_str(), (char*)data);
|
||
image_prc_param_.bits.is_permeate_lv_ = match_best_permaeate_lv(str, NULL);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "%d\n", ret);
|
||
|
||
return ret;
|
||
|
||
}
|
||
int hg_scanner::setting_remove_morr(void* data, long* len)
|
||
{
|
||
if (resolution_ > 300 )
|
||
{
|
||
image_prc_param_.bits.remove_txtture = image_prc_param_.bits.remove_morr = *((bool*)data) = false;
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
|
||
image_prc_param_.bits.remove_morr = *((bool*)data);
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_error_extention(void* data, long* len)
|
||
{
|
||
image_prc_param_.bits.error_extention = *((bool*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_remove_texture(void* data, long* len)
|
||
{
|
||
if (resolution_ > 300)
|
||
{
|
||
image_prc_param_.bits.remove_txtture = *((bool*)data) = false;
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
image_prc_param_.bits.remove_txtture = *((bool*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_ultrasonic_check(void* data, long* len)
|
||
{
|
||
bool use = *((bool*)data);
|
||
int ret = on_ultrasonic_check_changed(use);
|
||
|
||
if (ret)
|
||
*((bool*)data) = use;
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_go_on_when_double_checked(void* data, long* len)
|
||
{
|
||
|
||
bool ok = true;
|
||
std::string val((char*)data);
|
||
if (!firmware_sup_double_img && val.compare(lang_load_string(ID_OPTION_VALUE_SZTPCL_DQTXBTZSM, nullptr)))
|
||
{
|
||
::strcpy((char*)data, lang_load_string(ID_OPTION_VALUE_SZTPCL_SCTXBTZSM, nullptr));
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
|
||
double_paper_handle_ = double_paper_flag_from_option_value(val, &ok);
|
||
|
||
// 此处需要通知设备双张处理方式 !!!
|
||
// OPTION_VALUE_SZTPCL_xxx 共4种选择,目前只支持出现双张后停止的两种方式
|
||
// 若要上传出现双张的图片,请确保双张信号在图片之前发出来 !!!
|
||
|
||
if(ok)
|
||
return SCANNER_ERR_OK;
|
||
else
|
||
{
|
||
::strcpy((char*)data, val.c_str());
|
||
|
||
return SCANNER_ERR_NOT_EXACT;
|
||
}
|
||
}
|
||
int hg_scanner::setting_staple_check(void* data, long* len)
|
||
{
|
||
bool use = *((bool*)data);
|
||
int ret = on_staple_check_changed(use);
|
||
|
||
if (ret)
|
||
*((bool*)data) = use;
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_scan_mode(void* data, long* len)
|
||
{
|
||
std::string str((char*)data);
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
if (strcmp(str.c_str(), from_default_language(OPTION_VALUE_SMZS_LXSM)) == 0)
|
||
{
|
||
scan_count_ = -1;
|
||
}
|
||
else
|
||
{
|
||
scan_count_ = *(int*)setting_jsn_->get_option_value(SANE_STD_OPT_NAME_SCAN_COUNT, OPT_VAL_CURRENT).c_str();
|
||
}
|
||
|
||
utils::to_log(LOG_LEVEL_DEBUG, "set scanning pages to %d\n", scan_count_);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_scan_count(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
std::string val(get_setting_item_string(SANE_STD_OPT_NAME_SCAN_MODE, "cur"));
|
||
|
||
if (val == lang_load_string(ID_OPTION_VALUE_SMZS_LXSM, nullptr))
|
||
{
|
||
scan_count_ = -1;
|
||
}
|
||
else
|
||
{
|
||
scan_count_ = *((int*)data);
|
||
}
|
||
utils::to_log(LOG_LEVEL_DEBUG, "set scanning pages to %d\n", scan_count_);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_text_direction(void* data, long* len)
|
||
{
|
||
std::string str((char*)data);
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Change text direction from '%s' to '%s' = %s\n", text_direction_string(image_prc_param_.bits.text_direction).c_str()
|
||
, (char*)data, hg_scanner_err_name(ret));
|
||
image_prc_param_.bits.text_direction = match_best_text_direction(str, NULL);
|
||
|
||
if (image_prc_param_.bits.text_direction == TEXT_DIRECTION_AUTO && ImagePrc_pHandle_)
|
||
{
|
||
hg_imgproc::init_auto_txt_hanld(ImagePrc_pHandle_);
|
||
}
|
||
else if (image_prc_param_.bits.text_direction != TEXT_DIRECTION_AUTO && ImagePrc_pHandle_)
|
||
{
|
||
hg_imgproc::free_auto_txt_hanld(ImagePrc_pHandle_);
|
||
}
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_rotate_bkg_180(void* data, long* len)
|
||
{
|
||
image_prc_param_.bits.rotate_back_180 = *((bool*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_fractate_check(void* data, long* len)
|
||
{
|
||
image_prc_param_.bits.fractate_check = *((bool*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_fractate_check_level(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
fractate_level_ = *((int*)data);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_skew_check(void* data, long* len)
|
||
{
|
||
bool use = *((bool*)data);
|
||
int ret = on_skew_check_changed(use);
|
||
|
||
if (ret)
|
||
*((bool*)data) = use;
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_skew_check_level(void* data, long* len)
|
||
{
|
||
int level = *((int*)data);
|
||
int ret = SCANNER_ERR_OK,
|
||
sub = on_skew_check_level_changed(level);
|
||
|
||
if (sub)
|
||
{
|
||
ret = sub;
|
||
}
|
||
if (ret)
|
||
*((int*)data) = level;
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_is_custom_gamma(void* data, long* len)
|
||
{
|
||
custom_gamma_ = *((bool*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_custom_gamma_data(void* data, long* len)
|
||
{
|
||
SANE_Gamma* gamma = (SANE_Gamma*)data;
|
||
|
||
memcpy(custom_gamma_val_, gamma, sizeof(*custom_gamma_val_));
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_is_custom_area(void* data, long* len)
|
||
{
|
||
custom_area_ = *((bool*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_custom_area_left(void* data, long* len)
|
||
{
|
||
SANE_Fixed* v = (SANE_Fixed*)data;
|
||
|
||
custom_area_lt_x_ = *((double*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_custom_area_top(void* data, long* len)
|
||
{
|
||
SANE_Fixed* v = (SANE_Fixed*)data;
|
||
|
||
custom_area_lt_y_ = *((double*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_custom_area_right(void* data, long* len)
|
||
{
|
||
SANE_Fixed* v = (SANE_Fixed*)data;
|
||
|
||
custom_area_br_x_ = *((double*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_custom_area_bottom(void* data, long* len)
|
||
{
|
||
SANE_Fixed* v = (SANE_Fixed*)data;
|
||
|
||
custom_area_br_y_ = *((double*)data);
|
||
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_img_quality(void* data, long* len)
|
||
{
|
||
std::string str((char*)data);
|
||
int ret = SCANNER_ERR_OK;
|
||
int old = is_quality_;
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Change quality from '%s' to '%s' = %s\n", is_img_quality(is_quality_).c_str()
|
||
, (char*)data, hg_scanner_err_name(ret));
|
||
|
||
is_quality_ = match_best_img_quality(str,NULL);
|
||
/*if (!check_resolution_and_quality(resolution_, is_img_quality(is_quality_).c_str()))
|
||
{
|
||
is_quality_ = old;
|
||
::strcpy((char*)data, is_img_quality(is_quality_).c_str());
|
||
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}*/
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_color_fill(void* data, long* len)
|
||
{
|
||
is_color_fill = *((bool *)data);
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_keep_watermark(void* data, long* len)
|
||
{
|
||
keep_watermark_ = *(bool*)data;
|
||
on_pic_type(keep_watermark_);
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_black_white_threshold(void* data, long* len)
|
||
{
|
||
bw_threshold_ = (unsigned char)(*(SANE_Int*)data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_white_pixel_0(void* data, long* len)
|
||
{
|
||
is_white_0_ = *(bool*)data;
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_feedmode(void* data, long* len)
|
||
{
|
||
if (is_auto_feedmode_)
|
||
{
|
||
return SCANNER_ERR_OK;;
|
||
}
|
||
std::string str((char *)data);
|
||
int val = match_best_paper_strength(str,NULL);
|
||
|
||
if (val == feedmode_)
|
||
return SCANNER_ERR_OK;
|
||
|
||
int ret = on_set_feedmode(val);
|
||
if (ret == SCANNER_ERR_OK)
|
||
feedmode_ = val;
|
||
|
||
utils::to_log(LOG_LEVEL_DEBUG, "setfeedmode from '%s' to '%s' = %s\n", is_paper_strength(feedmode_).c_str()
|
||
, (char*)data, hg_scanner_err_name(ret));
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_sleeptime(void* data, long* len)
|
||
{
|
||
std::string str((char *)data);
|
||
int val = match_best_sleep_time(str,0);
|
||
int mintosec = 0;
|
||
switch (val)
|
||
{
|
||
case SLEEP_TIME_0MIN:
|
||
val = -1; //不休眠 -1
|
||
break;
|
||
case SLEEP_TIME_5MIN:
|
||
val = 5;
|
||
break;
|
||
case SLEEP_TIME_10MIN:
|
||
val = 10;
|
||
break;
|
||
case SLEEP_TIME_30MIN:
|
||
val = 30;
|
||
break;
|
||
case SLEEP_TIME_60MIN:
|
||
val = 60;
|
||
break;
|
||
case SLEEP_TIME_120MIN:
|
||
val = 120;
|
||
break;
|
||
case SLEEP_TIME_240MIN:
|
||
val = 240;
|
||
break;
|
||
}
|
||
|
||
/*if (val == sleeptime_)
|
||
return SCANNER_ERR_OK;*/
|
||
|
||
mintosec = val ;
|
||
if (val != -1)
|
||
{
|
||
mintosec = val * 60;
|
||
}
|
||
|
||
int ret = set_sleep_time(mintosec);
|
||
if (ret == SCANNER_ERR_OK)
|
||
sleeptime_ = val;
|
||
|
||
utils::to_log(LOG_LEVEL_DEBUG, "set sleeptime from (%s)min to (%s)min = %s\n", is_sleep_time(sleeptime_).c_str()
|
||
, (char*)data, hg_scanner_err_name(ret));
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_auto_pick_paper(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
is_auto_feedmode_ = *((bool *)data);
|
||
ret = on_pick_paper(is_auto_feedmode_);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_auto_pick_paper_threshold(void* data, long* len)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
double threshold = *((double*)data);
|
||
ret = on_pick_paper_threshold(threshold);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_auto_paper_scan(void* data, long* len)
|
||
{
|
||
is_auto_paper_scan = *((bool *)data);
|
||
if (!firmware_sup_wait_paper_ && is_auto_paper_scan)
|
||
{
|
||
is_auto_paper_scan = *(bool*)data = false;
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
on_is_auto_paper(is_auto_paper_scan);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_isremove_left_hole(void* data, long* len)
|
||
{
|
||
isremove_left_hole = *((bool*)data);
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_isremove_right_hole(void* data, long* len)
|
||
{
|
||
isremove_right_hole = *((bool*)data);
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_isremove_top_hole(void* data, long* len)
|
||
{
|
||
isremove_top_hole = *((bool*)data);
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_isremove_low_hole(void* data, long* len)
|
||
{
|
||
isremove_low_hole = *((bool*)data);
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_isremove_left_hole_threshold(void* data, long* len)
|
||
{
|
||
isremove_left_hole_threshold = *((double*)data);
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_isremove_right_hole_threshold(void* data, long* len)
|
||
{
|
||
isremove_right_hole_threshold = *((double*)data);
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_isremove_top_hole_threshold(void* data, long* len)
|
||
{
|
||
isremove_top_hole_threshold = *((double*)data);
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_isremove_low_hole_threshold(void* data, long* len)
|
||
{
|
||
isremove_low_hole_threshold = *((double*)data);
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_fold_type(void* data, long* len)
|
||
{
|
||
string str((char*)data);
|
||
bool exact = NULL;
|
||
int val = match_best_fold_type(str, 0);
|
||
fold_type_ = val;
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_color_correction(void* data, long* len)
|
||
{
|
||
color_correction_ = *((bool*)data);
|
||
if (!color_correction_)
|
||
{
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
if (pid_ == 0x239 || pid_ == 0x439)
|
||
{
|
||
if (!firmware_sup_color_corr_)
|
||
{
|
||
*((bool*)data) = color_correction_ = false;
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
}
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_auto_paper_scan_exit_time(void* data, long* len)
|
||
{
|
||
string str((char*)data);
|
||
if (str.compare("15s") == 0)
|
||
is_auto_paper_scan_exit_time = 15;
|
||
else if (str.compare("30s") == 0)
|
||
is_auto_paper_scan_exit_time = 30;
|
||
else if (str.compare("60s") == 0)
|
||
is_auto_paper_scan_exit_time = 60;
|
||
else if (str.compare("2min") == 0)
|
||
is_auto_paper_scan_exit_time = 120;
|
||
else if (str.compare("4min") == 0)
|
||
is_auto_paper_scan_exit_time = 240;
|
||
else if (str.compare("8min") == 0)
|
||
is_auto_paper_scan_exit_time = 480;
|
||
else
|
||
is_auto_paper_scan_exit_time = 60;
|
||
//is_auto_paper_scan_exit_time = *((int*)data);
|
||
//utils::to_log(LOG_LEVEL_DEBUG, "set paper_scan_exit_time from (%d)min to (%s)min = %d\n", is_auto_paper_scan_exit_time, (char*)data);
|
||
return 0;
|
||
}
|
||
int hg_scanner::setting_get_dev_vid(void* data, long* len)
|
||
{
|
||
if (io_)
|
||
{
|
||
*(int*)data = io_->get_vid();
|
||
if (len)
|
||
*len = sizeof(int);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
|
||
return SCANNER_ERR_NOT_OPEN;
|
||
}
|
||
int hg_scanner::setting_get_dev_pid(void* data, long* len)
|
||
{
|
||
if (io_)
|
||
{
|
||
*(int*)data = io_->get_pid();
|
||
if (len)
|
||
*len = sizeof(int);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
|
||
return SCANNER_ERR_NOT_OPEN;
|
||
}
|
||
int hg_scanner::setting_get_dev_family(void* data, long* len)
|
||
{
|
||
::strcpy((char*)data, family_.c_str());
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_get_dev_name(void* data, long* len)
|
||
{
|
||
::strcpy((char*)data, name_.c_str());
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_get_dev_sn(void* data, long* len)
|
||
{
|
||
if (!data)
|
||
{
|
||
return SCANNER_ERR_NO_DATA;
|
||
}
|
||
::strcpy((char*)data, get_serial_num().c_str());
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_get_dev_fmver(void* data, long* len)
|
||
{
|
||
if (!data)
|
||
{
|
||
return SCANNER_ERR_NO_DATA;
|
||
}
|
||
::strcpy((char*)data, get_firmware_version().c_str());
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_get_dev_ip(void* data, long* len)
|
||
{
|
||
if (!data)
|
||
{
|
||
return SCANNER_ERR_NO_DATA;
|
||
}
|
||
::strcpy((char*)data, get_ip().c_str());
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::setting_get_roller_count(void* data, long* len)
|
||
{
|
||
if (!data)
|
||
{
|
||
return SCANNER_ERR_NO_DATA;
|
||
}
|
||
if (len)
|
||
*len = sizeof(int);
|
||
return get_roller_num(*((int*)data));
|
||
}
|
||
int hg_scanner::setting_get_history_count(void* data, long* len)
|
||
{
|
||
if (!data)
|
||
{
|
||
return SCANNER_ERR_NO_DATA;
|
||
}
|
||
if (len)
|
||
*len = sizeof(int);
|
||
return get_history_scan_count(*((int*)data));
|
||
}
|
||
int hg_scanner::setting_get_devs_log(void* data, long* len)
|
||
{
|
||
if (!data)
|
||
{
|
||
return SCANNER_ERR_NO_DATA;
|
||
}
|
||
string str;
|
||
int ret = get_device_log(str);
|
||
if(ret == SCANNER_ERR_OK)
|
||
::strcpy((char*)data, str.c_str());
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_set_language(void* data, long* len)
|
||
{
|
||
int err = SCANNER_ERR_OK;
|
||
LANATTR **pla = lang_get_supported_languages();
|
||
|
||
if (!pla)
|
||
err = SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
else
|
||
{
|
||
std::string n(to_default_language((char*)data, nullptr)), now("");
|
||
int id = -1, cur = lang_get_cur_code_page();
|
||
for (int i = 0; pla[i]; ++i)
|
||
{
|
||
if (pla[i]->cp == cur)
|
||
now = pla[i]->name;
|
||
if (n == pla[i]->name)
|
||
{
|
||
id = pla[i]->cp;
|
||
break;
|
||
}
|
||
}
|
||
if (id == -1)
|
||
{
|
||
err = SCANNER_ERR_INVALID_PARAMETER;
|
||
::strcpy((char*)data, now.c_str());
|
||
}
|
||
else if(cur != id)
|
||
{
|
||
int lid = lang_get_string_id((char*)data, false);
|
||
|
||
err = SCANNER_ERR_CONFIGURATION_CHANGED;
|
||
lang_set_code_page(id);
|
||
on_language_changed();
|
||
}
|
||
}
|
||
|
||
return err;
|
||
}
|
||
int hg_scanner::setting_get_motor_ver(void* data, long* len)
|
||
{
|
||
string str;
|
||
int ret = get_motor_board_ver(str);
|
||
if (ret == SCANNER_ERR_OK)
|
||
{
|
||
::strcpy((char*)data, str.c_str());
|
||
}
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_get_initial_boot_time(void* data, long* len)
|
||
{
|
||
string str;
|
||
int ret = get_devs_time(str);
|
||
if (ret == SCANNER_ERR_OK)
|
||
{
|
||
::strcpy((char*)data, str.c_str());
|
||
}
|
||
return ret;
|
||
}
|
||
int hg_scanner::setting_set_discardblank(void* data, long* len)
|
||
{
|
||
is_discardblank = *(bool*)data;
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::on_color_mode_changed(int& color_mode)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::on_paper_changed(int& paper)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::on_paper_check_changed(bool& check)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::on_resolution_changed(int& dpi)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::on_ultrasonic_check_changed(bool& check)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::on_staple_check_changed(bool& check)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::on_skew_check_changed(bool& check)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::on_skew_check_level_changed(int& check)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::on_set_feedmode(int feedmode)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::on_get_feedmode(int &feedmode)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::on_pic_type(bool& pic)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::on_pick_paper(bool autostrength)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::on_pick_paper_threshold(double threshold)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::on_is_auto_paper(bool isautopaper)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::on_cis_get_image(bool isautopaper)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
void hg_scanner::on_device_reconnected(void)
|
||
{
|
||
std::lock_guard<std::mutex> lock(io_lock_);
|
||
|
||
utils::to_log(LOG_LEVEL_DEBUG, "%04x:%04x reconnected.\n", io_->get_vid(), io_->get_pid());
|
||
}
|
||
int hg_scanner::set_setting_value(const char* name, void* data, long* len)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::on_scanner_closing(bool force)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
|
||
void hg_scanner::thread_handle_usb_read(void)
|
||
{
|
||
}
|
||
void hg_scanner::thread_handle_islock_read(void)
|
||
{
|
||
}
|
||
void hg_scanner::adjust_color(hg_imgproc::HIMGPRC handle)
|
||
{
|
||
int tableLength = 0; // ZERO length perform color-adjust only
|
||
unsigned char buffer1[256 * 3];
|
||
|
||
if (custom_gamma_)
|
||
{
|
||
if (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE || img_conf_.pixtype == COLOR_MODE_256_GRAY)
|
||
{
|
||
tableLength = 256;
|
||
memcpy(buffer1, custom_gamma_val_->table + 256 * GAMMA_INDEX_GRAY, tableLength);
|
||
}
|
||
else
|
||
{
|
||
// convert R[256] + G[256] + B[256] to BGR[256] ...
|
||
//
|
||
// To be modified: here should be color[256] + R[256] + G[256] + B[256] to BGR[256], final pixel = color[R[x]] - commented on 2023-08-07
|
||
tableLength = 256 * 3;
|
||
for (int i = 0; i < 256; ++i)
|
||
{
|
||
//buffer1[i * 3 + 0] = custom_gamma_val_->table[256 * GAMMA_INDEX_BLUE + i];
|
||
//buffer1[i * 3 + 1] = custom_gamma_val_->table[256 * GAMMA_INDEX_GREEN + i];
|
||
//buffer1[i * 3 + 2] = custom_gamma_val_->table[256 * GAMMA_INDEX_RED + i];
|
||
buffer1[i * 3 + 0] = custom_gamma_val_->table[256 * GAMMA_INDEX_COLOR + custom_gamma_val_->table[256 * GAMMA_INDEX_BLUE + i]];
|
||
buffer1[i * 3 + 1] = custom_gamma_val_->table[256 * GAMMA_INDEX_COLOR + custom_gamma_val_->table[256 * GAMMA_INDEX_GREEN + i]];
|
||
buffer1[i * 3 + 2] = custom_gamma_val_->table[256 * GAMMA_INDEX_COLOR + custom_gamma_val_->table[256 * GAMMA_INDEX_RED + i]];
|
||
}
|
||
}
|
||
}
|
||
hg_imgproc::adjust_color(handle, buffer1, tableLength);
|
||
}
|
||
hg_imgproc::IMGPRCPARAM hg_scanner::get_image_process_object(int model)
|
||
{
|
||
hg_imgproc::IMGPRCPARAM param;
|
||
hg_imgproc::HIMGPRC handle = nullptr;
|
||
//float bright = img_conf_.brightness,
|
||
// contrast = img_conf_.contrast;
|
||
|
||
bzero(¶m, sizeof(param));
|
||
param.bits = 8;
|
||
//image_prc_param_.bits.color_mode == COLOR_MODE_256_GRAY || image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE
|
||
|
||
param.black_white = image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE;
|
||
if (image_prc_param_.bits.multi_out == MULTI_GRAY_AND_BW && is_multiout)
|
||
param.channels = 1;
|
||
else if ((image_prc_param_.bits.multi_out == MULTI_OUT_ALL
|
||
|| image_prc_param_.bits.multi_out == MULTI_COLOR_AND_GRAY
|
||
||image_prc_param_.bits.multi_out== MULTI_COLOR_AND_BW) && is_multiout)
|
||
param.channels = 3;
|
||
else
|
||
param.channels = (image_prc_param_.bits.color_mode == COLOR_MODE_24_BITS || image_prc_param_.bits.color_mode == COLOR_MODE_AUTO_MATCH) ? 3 : 1;
|
||
|
||
param.color_mode = image_prc_param_.bits.color_mode == COLOR_MODE_AUTO_MATCH ? 2 : image_prc_param_.bits.color_mode;
|
||
param.double_side = img_conf_.is_duplex;
|
||
param.dpi = img_conf_.resolution_dst;
|
||
param.cis_image = is_cis_image;
|
||
//img_conf_.brightness = (float)bright_;
|
||
//img_conf_.contrast = (float)contrast_;
|
||
|
||
return param;
|
||
}
|
||
SANE_Image_Statu hg_scanner::last_usb_image_statu(int err)
|
||
{
|
||
SANE_Image_Statu statu = SANE_Image_Statu_OK;
|
||
|
||
if (!is_continue_when_double_paper(double_paper_handle_) &&
|
||
is_save_img_when_double_paper(double_paper_handle_))
|
||
{
|
||
if (err == SCANNER_ERR_DEVICE_DOUBLE_FEEDING)
|
||
statu = SANE_Image_Statu_Double;
|
||
//else if (err == SCANNER_ERR_DEVICE_PAPER_JAMMED)
|
||
//statu = SANE_Image_Statu_Jammed;
|
||
}
|
||
|
||
return statu;
|
||
}
|
||
void hg_scanner::erase_option(const char* name)
|
||
{
|
||
//erase_depend_.push_back(name);
|
||
//setting_jsn_->remove(name);
|
||
}
|
||
void hg_scanner::init_settings(const char* json_setting_text)
|
||
{
|
||
const char* lang = language_option_descriptor();
|
||
bool empty = true;
|
||
|
||
if (lang && *lang)
|
||
{
|
||
std::string txt(json_setting_text);
|
||
size_t pos = txt.rfind('}');
|
||
if (pos != std::string::npos)
|
||
{
|
||
txt[pos] = ',';
|
||
}
|
||
if (strstr(lang, "{"))
|
||
txt += strstr(lang, "{") + 1;
|
||
setting_jsn_->init(txt.c_str());
|
||
empty = setting_jsn_->count() != 0;
|
||
}
|
||
if(empty)
|
||
{
|
||
std::string txt(json_setting_text);
|
||
setting_jsn_->init(txt.c_str());
|
||
}
|
||
|
||
jsn_reorganize();
|
||
|
||
|
||
utils::to_log(LOG_LEVEL_ALL, "Initialize %d settings ...\n", setting_jsn_->count());
|
||
notify_setting_result_ = false;
|
||
utils::to_log(LOG_LEVEL_ALL, "Initialize %d settings ... OK\n", setting_jsn_->count());
|
||
if (lang_get_cur_code_page() != DEFAULT_CODE_PAGE)
|
||
on_language_changed();
|
||
notify_setting_result_ = true;
|
||
|
||
|
||
|
||
//setting_jsn_
|
||
|
||
}
|
||
int hg_scanner::init_settings(int pid)
|
||
{
|
||
char rel_path[80] = { 0 };
|
||
std::string root(utils::get_module_full_path(SCANNER_DRIVER_PART_NAME)), jsn("");
|
||
int ret = root.rfind(PATH_SEPARATOR[0]);
|
||
|
||
if((size_t)ret++ == std::string::npos)
|
||
ret = 0;
|
||
root.erase(ret);
|
||
sprintf(rel_path, "%ssettings%s%04x.hsc", PATH_SEPARATOR, PATH_SEPARATOR, pid);
|
||
root += rel_path;
|
||
ret = load_scanner_setting(root.c_str(), jsn);
|
||
utils::to_log(LOG_LEVEL_WARNING, "Apply '%s' setting: %d\n", root.c_str(), ret);
|
||
if (ret)
|
||
return SCANNER_ERR_DATA_DAMAGED;
|
||
|
||
init_settings(jsn.c_str());
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
std::string hg_scanner::get_setting_item_string(const char* name, const char* key)
|
||
{
|
||
return std::move(setting_jsn_->get_option_field_string(name, key));
|
||
}
|
||
int hg_scanner::on_scann_error(int err)
|
||
{
|
||
status_ = err;
|
||
|
||
utils::to_log(LOG_LEVEL_FATAL, "[xxx]Device status: 0x%x\n", err);
|
||
|
||
unsigned int e = err;
|
||
|
||
return ui_ev_cb_((scanner_handle)this, SANE_EVENT_ERROR, (void*)hg_scanner_err_name(err), &e, NULL);
|
||
}
|
||
int hg_scanner::try_third_app_handle_start(bool& handled)
|
||
{
|
||
int ret = SCANNER_ERR_OK; // status_
|
||
|
||
handled = !async_io_;
|
||
if (handled)
|
||
{
|
||
while (wait_usb_result_.try_wait())
|
||
std::this_thread::sleep_for(std::chrono::milliseconds(3));
|
||
|
||
if (!wait_img_.is_waiting() || !wait_usb_.is_waiting() || final_imgs_.size())
|
||
{
|
||
// working or has images ...
|
||
while (final_imgs_.size() == 0)
|
||
{
|
||
if (wait_img_.is_waiting() && wait_usb_.is_waiting())
|
||
break;
|
||
|
||
std::this_thread::sleep_for(std::chrono::milliseconds(3));
|
||
}
|
||
if (final_imgs_.size() == 0)
|
||
{
|
||
final_img_index_ = 0;
|
||
|
||
if (user_cancel_)
|
||
handled = false;
|
||
else if (status_ == SCANNER_ERR_OK)
|
||
ret = SCANNER_ERR_DEVICE_NO_PAPER;
|
||
else
|
||
ret = status_;
|
||
}
|
||
}
|
||
else if (final_img_index_)
|
||
{
|
||
final_img_index_ = 0;
|
||
|
||
if (user_cancel_)
|
||
handled = false;
|
||
else if (status_ == SCANNER_ERR_OK)
|
||
ret = SCANNER_ERR_DEVICE_NO_PAPER;
|
||
else
|
||
ret = status_;
|
||
}
|
||
else
|
||
handled = false;
|
||
}
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::try_third_app_after_start(int err)
|
||
{
|
||
if (!async_io_)
|
||
{
|
||
while (wait_img_.is_waiting() && !wait_usb_.is_waiting())
|
||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||
if (wait_img_.is_waiting() && wait_usb_.is_waiting())
|
||
err = status_;
|
||
}
|
||
|
||
return err;
|
||
}
|
||
std::shared_ptr<tiny_buffer> hg_scanner::aquire_memory(int size, bool from_usb)
|
||
{
|
||
std::string lead(from_usb ? "usb" : "imgp"), ext(from_usb ? "jpg" : "dat");
|
||
unsigned int ind = from_usb ? usb_img_index_ : final_img_index_;
|
||
std::shared_ptr<tiny_buffer> mem(new tiny_buffer(size, final_path_.c_str(), lead.c_str(), ext.c_str(), ind));
|
||
|
||
if (!mem->data(0, (unsigned int*)&size))
|
||
{
|
||
mem.reset();
|
||
utils::log_info("Can't aquire enough memory, working must be stopped!\n", LOG_LEVEL_FATAL);
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_SCANNER_ERR_INSUFFICIENT_MEMORY, nullptr), SANE_EVENT_ERROR, SCANNER_ERR_INSUFFICIENT_MEMORY);
|
||
stop();
|
||
}
|
||
|
||
return mem;
|
||
}
|
||
int hg_scanner::notify_ui_working_status(const char* msg, int ev, int status)
|
||
{
|
||
unsigned int s = status;
|
||
|
||
return ui_ev_cb_((scanner_handle)this, ev, (void*)msg, &s, NULL);
|
||
}
|
||
bool hg_scanner::waiting_for_memory_enough(unsigned need_bytes)
|
||
{
|
||
return true; // disable the memory control - added on 2022-03-22
|
||
|
||
bool ret = true;
|
||
|
||
if(cb_mem_)
|
||
{
|
||
int ret = ui_ev_cb_((scanner_handle)this, SANE_EVENT_IS_MEMORY_ENOUGH, NULL, &need_bytes, NULL);
|
||
|
||
if (ret == SCANNER_ERR_INSUFFICIENT_MEMORY)
|
||
{
|
||
user_cancel_ = true;
|
||
status_ = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
ret = false;
|
||
}
|
||
else if (ret == SCANNER_ERR_NOT_ANY_MORE)
|
||
cb_mem_ = false;
|
||
}
|
||
else
|
||
{
|
||
need_bytes *= 4;
|
||
|
||
void* buf = malloc(need_bytes);
|
||
bool first = true;
|
||
while (!buf && !user_cancel_)
|
||
{
|
||
if (first)
|
||
{
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Memory is too small for aquiring image(%u bytes), wait for ENOUGH ...\n", need_bytes);
|
||
notify_ui_working_status(lang_load_string(ID_STATU_DESC_WAIT_FOR_MEM, nullptr));
|
||
first = false;
|
||
}
|
||
std::this_thread::sleep_for(std::chrono::milliseconds(30));
|
||
buf = malloc(need_bytes);
|
||
}
|
||
if (!first)
|
||
{
|
||
if (buf)
|
||
{
|
||
utils::to_log(LOG_LEVEL_DEBUG, "waited for memory need(%u)\n", need_bytes);
|
||
}
|
||
else
|
||
{
|
||
utils::to_log(LOG_LEVEL_DEBUG, "canceled by user while waiting for memory need(%u)\n", need_bytes);
|
||
}
|
||
}
|
||
ret = (!user_cancel_) && (buf != NULL);
|
||
if (buf)
|
||
free(buf);
|
||
}
|
||
|
||
return ret;
|
||
}
|
||
void hg_scanner::copy_to_sane_image_header(SANE_Parameters* header, int w, int h, int line_bytes, int channels, int bits)
|
||
{
|
||
if (channels == 3)
|
||
header->format = SANE_FRAME_RGB;
|
||
else
|
||
header->format = SANE_FRAME_GRAY;
|
||
header->depth = bits >= 8 ? 8 : bits; // 此处指每一个颜色分量的位深,我们的扫描仪固定为“8”
|
||
header->last_frame = SANE_TRUE; // 一幅图片如果各个分量相互分离,则最后一个分量的时候设置为true。彩色图像RGB时也只有一“帧”,所以也为true
|
||
header->pixels_per_line = w;
|
||
header->lines = h;
|
||
header->bytes_per_line = line_bytes;
|
||
}
|
||
int hg_scanner::save_usb_data(std::shared_ptr<tiny_buffer> data)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
unsigned int bytes = data->size();
|
||
|
||
usb_img_index_++;
|
||
utils::to_log(LOG_LEVEL_DEBUG, "USB read one picture with %u bytes\n", data->size());
|
||
if (dump_usb_path_.length()) //这两台设备不是jpg的图 所以不能直接处理
|
||
{
|
||
char name[80] = { 0 };
|
||
FILE* dst = nullptr;
|
||
|
||
sprintf(name, "%s%03u_usb_img.jpg", PATH_SEPARATOR, usb_img_index_);
|
||
if ((dst = fopen((dump_usb_path_ + name).c_str(), "wb")))
|
||
{
|
||
unsigned int off = 0, len = bytes;
|
||
unsigned char* buf = data->data(off, &len);
|
||
while (buf)
|
||
{
|
||
fwrite(buf, 1, len, dst);
|
||
off += len;
|
||
if (off >= bytes)
|
||
break;
|
||
len = bytes - off;
|
||
buf = data->data(off, &len);
|
||
}
|
||
fclose(dst);
|
||
}
|
||
}
|
||
if (!data->swap())
|
||
{
|
||
ret = SCANNER_ERR_OPEN_FILE_FAILED;
|
||
}
|
||
else
|
||
{
|
||
int num = 0;
|
||
float Memoryusae = .0f; // hg_log::GetAppMemoryUsage();;
|
||
size_t que_size = 0;
|
||
imgs_.Size(&que_size);
|
||
Memoryusae = que_size / 1024.0f / 1024.0f;
|
||
if (async_io_)
|
||
Memoryusae *= 10;
|
||
else
|
||
Memoryusae += final_imgs_.mem_usage() / 1024.0f / 1024.0f;
|
||
while (Memoryusae >= memory_size_ && !user_cancel_ && num < 20)//三个条件以防止卡死
|
||
{
|
||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||
//Memoryusae = hg_log::GetAppMemoryUsage();
|
||
imgs_.Size(&que_size);
|
||
Memoryusae = que_size / 1024.0f / 1024.0f;
|
||
if (async_io_)
|
||
Memoryusae *= 10;
|
||
else
|
||
Memoryusae += final_imgs_.mem_usage() / 1024.0f / 1024.0f;
|
||
if(num++ == 0)
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Memory Usage is Too big:%f ,Please wait -_- ...\r\n", Memoryusae);
|
||
}
|
||
if (num && Memoryusae >= memory_size_ && !user_cancel_)
|
||
{
|
||
utils::to_log(LOG_LEVEL_WARNING, "Warning: memory usage(%.2fMB) maybe leading exception!\r\n", Memoryusae);
|
||
}
|
||
imgs_.Put(data, data->size(), hg_scanner_mgr::unique_id());
|
||
if (wait_img_.is_waiting())
|
||
wait_img_.notify();
|
||
}
|
||
|
||
if((serial_ != G10039Serial && serial_ != G20039Serial) || (usb_img_index_ & 1))
|
||
ui_ev_cb_((scanner_handle)this, SANE_EVENT_USB_DATA_RECEIVED, NULL, &bytes, NULL);
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::save_final_image(hg_imgproc::LPIMGHEAD head, void* buf, uint32_t id)
|
||
{
|
||
std::string bw("");
|
||
|
||
final_img_index_++;
|
||
bool is_1bit = false;
|
||
if (image_prc_param_.bits.multi_out == MULTI_OUT_ALL && is_multiout)
|
||
{
|
||
if(final_img_index_%3 == 0)
|
||
is_1bit = true;
|
||
}
|
||
else if ((image_prc_param_.bits.multi_out == MULTI_GRAY_AND_BW||image_prc_param_.bits.multi_out == MULTI_COLOR_AND_BW) && is_multiout)
|
||
{
|
||
if(final_img_index_%2 == 0)
|
||
is_1bit = true;
|
||
}
|
||
|
||
if ((image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE && !is_multiout) || (is_1bit && is_multiout))
|
||
{
|
||
int old = head->line_bytes;
|
||
/*/
|
||
bw = bmp_821((unsigned char*)buf, head->width, head->height, &head->line_bytes, async_io_, bw_threshold_, is_white_0_);
|
||
/*/
|
||
bw = hg_imgproc::bmp8_2_1bit((unsigned char*)buf, head->width, head->height, head->line_bytes, bw_threshold_, is_white_0_, async_io_);
|
||
head->line_bytes = bw.length() / head->height;////////*//////////
|
||
buf = &bw[0];
|
||
head->channels = head->bits = 1;
|
||
head->total_bytes = head->line_bytes * head->height;
|
||
utils::to_log(LOG_LEVEL_DEBUG, "convert to 1-bit bmp(%d * %d), total = %u, len = %u , black_white_image_threshold_ =%d\n", head->width, head->height, head->total_bytes, bw.length(), bw_threshold_);
|
||
}
|
||
|
||
if (async_io_)
|
||
{
|
||
SANE_Image img;
|
||
|
||
ZERO_STRUCT(&img);
|
||
copy_to_sane_image_header(&img.header, head->width, head->height, head->line_bytes, head->channels, head->bits);
|
||
img.data = (unsigned char*)buf;
|
||
img.bytes = head->total_bytes;
|
||
img.flag.statu = head->statu;
|
||
img.flag.dpi = resolution_;
|
||
img.src_id = id;
|
||
|
||
if (img.flag.statu)
|
||
{
|
||
utils::to_log(LOG_LEVEL_DEBUG, "some error with final image: %s\n", hg_scanner_image_statu_name(img.flag.statu));
|
||
}
|
||
|
||
return ui_ev_cb_((scanner_handle)this, SANE_EVENT_IMAGE_OK, &img, &final_img_index_, NULL);
|
||
}
|
||
|
||
if (final_imgs_.put(head->width, head->height, head->bits, head->channels, head->line_bytes, buf, head->total_bytes
|
||
, final_path_.c_str(), "final", "dat", final_img_index_, id))
|
||
return SCANNER_ERR_OK;
|
||
else
|
||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
}
|
||
void hg_scanner::adjust_filling_hole(LPSCANCONF conf)
|
||
{
|
||
int maxval = 0;
|
||
#define SET_FILL_HOLE(member, me) \
|
||
conf->fillholeratio_##member = isremove_##me##_hole ? isremove_##me##_hole_threshold * 100 + .5f : 0; \
|
||
if(conf->fillholeratio_##member < 0) \
|
||
conf->fillholeratio_##member = 0; \
|
||
else if(conf->fillholeratio_##member > 50) \
|
||
conf->fillholeratio_##member = 50; \
|
||
if(maxval < conf->fillholeratio_##member) \
|
||
maxval = conf->fillholeratio_##member;
|
||
|
||
SET_FILL_HOLE(up, top);
|
||
SET_FILL_HOLE(down, low);
|
||
SET_FILL_HOLE(left, left);
|
||
SET_FILL_HOLE(right, right);
|
||
|
||
if (maxval)
|
||
{
|
||
conf->fillhole.is_fillhole = true;
|
||
conf->fillhole.fillholeratio = maxval;
|
||
}
|
||
}
|
||
int hg_scanner::is_running(void)
|
||
{
|
||
if (!scan_life_)
|
||
return THREAD_RUNNING_IDLE;
|
||
|
||
int run = THREAD_RUNNING_IDLE;
|
||
if (!wait_usb_.is_waiting())
|
||
run |= THREAD_RUNNING_USB;
|
||
if (!wait_img_.is_waiting())
|
||
run |= THREAD_RUNNING_IMAGE;
|
||
|
||
return run;
|
||
}
|
||
int hg_scanner::reset_io(usb_io* io)
|
||
{
|
||
online_ = false;
|
||
if (!io)
|
||
return SCANNER_ERR_INVALID_PARAMETER;
|
||
|
||
{
|
||
std::lock_guard<std::mutex> lock(io_lock_);
|
||
|
||
usb_io* old = io_;
|
||
|
||
io->add_ref();
|
||
io_ = io;
|
||
status_ = io_->last_error();
|
||
online_ = status_ == SCANNER_ERR_OK;
|
||
if (old)
|
||
old->release();
|
||
}
|
||
on_device_reconnected();
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::io_disconnected(void)
|
||
{
|
||
std::lock_guard<std::mutex> lock(io_lock_);
|
||
|
||
online_ = false;
|
||
io_->on_disconnected();
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
void hg_scanner::set_ui_callback(sane_callback cb, bool enable_async_io)
|
||
{
|
||
ui_ev_cb_ = cb ? cb : ui_default_callback;
|
||
async_io_ = enable_async_io;
|
||
is_white_0_ = !async_io_;
|
||
}
|
||
void hg_scanner::set_dev_family(const char* family)
|
||
{
|
||
family_ = family ? family : "";
|
||
}
|
||
void hg_scanner::set_read_over_with_no_data(bool no_data)
|
||
{
|
||
read_over_with_no_data_ = no_data;
|
||
}
|
||
int hg_scanner::get_pid(void)
|
||
{
|
||
std::lock_guard<std::mutex> lock(io_lock_);
|
||
|
||
return io_->get_pid();
|
||
}
|
||
int hg_scanner::get_vid(void)
|
||
{
|
||
std::lock_guard<std::mutex> lock(io_lock_);
|
||
|
||
return io_->get_vid();
|
||
}
|
||
int hg_scanner::close(bool force)
|
||
{
|
||
int ret = on_scanner_closing(force);
|
||
|
||
online_ = false;
|
||
if (ret == SCANNER_ERR_OK)
|
||
{
|
||
run_ = false;
|
||
wait_usb_.notify();
|
||
wait_img_.notify();
|
||
|
||
if (thread_devslock_handle_.get())
|
||
wait_devsislock_.notify();
|
||
//wait_read_int.notify();
|
||
if(!scan_life_)
|
||
{
|
||
std::lock_guard<std::mutex> lock(io_lock_);
|
||
|
||
if (io_)
|
||
{
|
||
io_->close();
|
||
io_->release();
|
||
io_ = NULL;
|
||
}
|
||
}
|
||
else if (io_)
|
||
{
|
||
utils::log_info("close scanner: USB thread or Image thread is still running.\n", LOG_LEVEL_WARNING);
|
||
io_->close();
|
||
while (scan_life_)
|
||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||
io_->release();
|
||
io_ = NULL;
|
||
}
|
||
|
||
status_ = SCANNER_ERR_NOT_OPEN;
|
||
}
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::set_setting(const char* name, void* data, bool to_default)
|
||
{
|
||
int ret = SCANNER_ERR_OUT_OF_RANGE, refine = 0;
|
||
bool hit = false, del_mem = false;
|
||
long len = 0;
|
||
std::string real_n(name);
|
||
|
||
if (to_default)
|
||
{
|
||
int size = 0;
|
||
std::string val(setting_jsn_->get_option_value(name, OPT_VAL_DEFAULT, &size));
|
||
|
||
if (!data)
|
||
{
|
||
data = new char[size];
|
||
memset(data, 0, size);
|
||
del_mem = true;
|
||
}
|
||
if (setting_jsn_->get_option_value_type(name) == JSON_SANE_TYPE_STRING)
|
||
strcpy((char*)data, val.c_str());
|
||
else
|
||
memcpy(data, &val[0], val.length());
|
||
}
|
||
else
|
||
refine = setting_jsn_->refine_data(real_n.c_str(), data);
|
||
|
||
hit = setting_map_.count(real_n) > 0;
|
||
if (hit)
|
||
{
|
||
ret = (this->*setting_map_[real_n])(data, &len);
|
||
}
|
||
else
|
||
{
|
||
utils::to_log(LOG_LEVEL_WARNING, "Setting '%s' is not found in base setting functions.\n", real_n.c_str());
|
||
ret = set_setting_value(real_n.c_str(), data, &len);
|
||
}
|
||
if (setting_jsn_->update_data(real_n.c_str(), data) == SCANNER_ERR_RELOAD_OPT_PARAM)
|
||
ret = SCANNER_ERR_RELOAD_OPT_PARAM;
|
||
|
||
if (del_mem)
|
||
delete[] data;
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::get_setting(const char* name, char* buf, int* len, int type)
|
||
{
|
||
if (!len)
|
||
return SCANNER_ERR_INVALID_PARAMETER;
|
||
|
||
if (name == nullptr)
|
||
{
|
||
*len = setting_jsn_->count() + 1;
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
else if (name == PARAM_ALL)
|
||
{
|
||
std::string text(setting_jsn_->get_option_value(nullptr, OPT_VAL_JSON));
|
||
|
||
if (*len <= text.length())
|
||
{
|
||
*len = text.length() + 4;
|
||
|
||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
}
|
||
::strcpy(buf, text.c_str());
|
||
*len = text.length();
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
|
||
std::string real_n(name);
|
||
|
||
if (real_n.empty())
|
||
{
|
||
return SCANNER_ERR_OUT_OF_RANGE;
|
||
}
|
||
else
|
||
{
|
||
int size = 0;
|
||
std::string val(setting_jsn_->get_option_value(name, OPT_VAL_CURRENT, &size));
|
||
|
||
if (val.empty())
|
||
return SCANNER_ERR_INVALID_PARAMETER;
|
||
|
||
if (*len < val.length())
|
||
{
|
||
*len = size;
|
||
|
||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
}
|
||
|
||
memcpy(buf, &val[0], val.length());
|
||
if (setting_jsn_->get_option_value_type(name) == JSON_SANE_TYPE_STRING)
|
||
buf[val.length()] = 0;
|
||
}
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
std::string hg_scanner::name(void)
|
||
{
|
||
return name_;
|
||
}
|
||
int hg_scanner::status(void)
|
||
{
|
||
if (!online_)
|
||
return SCANNER_ERR_DEVICE_NOT_FOUND;
|
||
else if (!wait_usb_.is_waiting() || !wait_img_.is_waiting())
|
||
return SCANNER_ERR_DEVICE_BUSY;
|
||
else
|
||
return status_;
|
||
}
|
||
bool hg_scanner::is_online(void)
|
||
{
|
||
return online_;
|
||
}
|
||
void hg_scanner::on_language_changed(void)
|
||
{
|
||
// change the 'size' member of string settings ...
|
||
}
|
||
int hg_scanner::start(void)
|
||
{
|
||
user_cancel_ = false;
|
||
|
||
return status_;
|
||
}
|
||
int hg_scanner::get_image_info(SANE_Parameters* ii)
|
||
{
|
||
int ret = SCANNER_ERR_OK;
|
||
IMH imh;
|
||
|
||
fetching_id_ = -1;
|
||
bzero(&imh, sizeof(imh));
|
||
bzero(ii, sizeof(*ii));
|
||
while ((!wait_img_.is_waiting() || !wait_usb_.is_waiting()) && final_imgs_.size() <= 0)
|
||
this_thread::sleep_for(chrono::milliseconds(10));
|
||
|
||
if (final_imgs_.size() <= 0)
|
||
ret = SCANNER_ERR_NO_DATA;
|
||
else
|
||
{
|
||
if (!final_imgs_.front(&imh))
|
||
ret = SCANNER_ERR_NO_DATA;
|
||
else
|
||
{
|
||
copy_to_sane_image_header(ii, imh.width, imh.height, imh.line_bytes, imh.channels, imh.bits);
|
||
fetching_id_ = imh.src_id;
|
||
}
|
||
}
|
||
|
||
if (ret == SCANNER_ERR_NO_DATA /*&& final_img_index_ == 0*/)
|
||
{
|
||
//if (status_ != SCANNER_ERR_OK && status_ != SCANNER_ERR_DEVICE_BUSY)
|
||
// ret = SCANNER_ERR_NO_DATA;
|
||
//else
|
||
{
|
||
ii->depth = image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE ? 1 : 8;
|
||
ii->last_frame = SANE_TRUE;
|
||
ii->format = image_prc_param_.bits.color_mode == COLOR_MODE_24_BITS || image_prc_param_.bits.color_mode == COLOR_MODE_AUTO_MATCH ?
|
||
SANE_FRAME_RGB : SANE_FRAME_GRAY;
|
||
|
||
SIZE paper = paper_size(image_prc_param_.bits.paper);
|
||
ii->pixels_per_line = paper.cx * 1.0f / 25.4 * resolution_ + .5f;
|
||
ii->lines = paper.cy * 1.0f / 25.4 * resolution_ + .5f;
|
||
ii->bytes_per_line = ii->format == SANE_FRAME_RGB ? ii->pixels_per_line * 3 : ii->pixels_per_line;
|
||
if (ii->bytes_per_line > ii->pixels_per_line)
|
||
imh.bits = 24;
|
||
else
|
||
imh.bits = 8;
|
||
|
||
ret = SCANNER_ERR_OK;
|
||
}
|
||
}
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Get image info(%d * %d * %d) = %s\n", ii->pixels_per_line, ii->lines, imh.bits, hg_scanner_err_name(ret));
|
||
|
||
return ret;
|
||
}
|
||
int hg_scanner::read_image_data(unsigned char* buf, int* len)
|
||
{
|
||
if (!len)
|
||
return SCANNER_ERR_INVALID_PARAMETER;
|
||
|
||
if (!buf)
|
||
{
|
||
IMH imh;
|
||
final_imgs_.front(&imh);
|
||
*len = imh.bytes;
|
||
|
||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
}
|
||
|
||
if (final_imgs_.size() > 0)
|
||
{
|
||
int fetch = *len;
|
||
bool over = false;
|
||
|
||
final_imgs_.fetch_front(buf, len, &over);
|
||
if (over)
|
||
{
|
||
if (read_over_with_no_data_)
|
||
return SCANNER_ERR_NO_DATA;
|
||
}
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
else
|
||
{
|
||
*len = 0;
|
||
return SCANNER_ERR_NO_DATA;
|
||
}
|
||
}
|
||
int hg_scanner::stop(void)
|
||
{
|
||
user_cancel_ = true;
|
||
|
||
return status_;
|
||
}
|
||
int hg_scanner::reset(void)
|
||
{
|
||
return status_;
|
||
}
|
||
int hg_scanner::device_io_control(unsigned long code, void* data, unsigned* len)
|
||
{
|
||
//SANE_Bool devs_status = false;
|
||
//int ret = get_scan_is_sleep(devs_status);
|
||
//if (ret == SCANNER_ERR_OK)
|
||
//{
|
||
// if (!devs_status)
|
||
// {
|
||
// if (pid_ == 0x239 || pid_ == 0x402)
|
||
// {
|
||
// set_notify_sleep();
|
||
// }
|
||
// return SCANNER_ERR_DEVICE_SLEEPING;
|
||
// }
|
||
//}
|
||
if (code == IO_CTRL_CODE_RESTORE_SETTINGS)
|
||
{
|
||
long l = len ? *len : 0;
|
||
int ret = invoke_setting_xxx(&hg_scanner::setting_restore, data, &l);
|
||
|
||
if (ret == SCANNER_ERR_OK)
|
||
{
|
||
ret = SCANNER_ERR_CONFIGURATION_CHANGED;
|
||
}
|
||
if (len)
|
||
*len = l;
|
||
|
||
return ret;
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_DEFAULT_VALUE)
|
||
{
|
||
if (*len <= 0)
|
||
{
|
||
*len = setting_jsn_->count() + 1;
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
else if (*len >= setting_jsn_->count())
|
||
{
|
||
return SCANNER_ERR_OUT_OF_RANGE;
|
||
}
|
||
else
|
||
{
|
||
std::string val(setting_jsn_->get_option_value((int)*len, OPT_VAL_DEFAULT));
|
||
memcpy(data, &val[0], val.length());
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_CLEAR_ROLLER_COUNT)
|
||
{
|
||
return set_clear_roller_num();
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_CLEAR_HISTORY_COUNT)
|
||
{
|
||
return set_clear_history_num();
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_FINAL_IMAGE_FORMAT)
|
||
{
|
||
SANE_FinalImgFormat* fmt = (SANE_FinalImgFormat*)data;
|
||
if (!fmt)
|
||
{
|
||
*len = sizeof(SANE_FinalImgFormat);
|
||
|
||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
}
|
||
|
||
if (img_type_ == ".bmp")
|
||
fmt->img_format = SANE_IMAGE_TYPE_BMP;
|
||
else if (img_type_ == ".jpg")
|
||
fmt->img_format = SANE_IMAGE_TYPE_JPG;
|
||
else if (img_type_ == ".png")
|
||
fmt->img_format = SANE_IMAGE_TYPE_PNG;
|
||
else if (img_type_ == ".gif")
|
||
fmt->img_format = SANE_IMAGE_TYPE_GIF;
|
||
else
|
||
fmt->img_format = SANE_IMAGE_TYPE_BMP;
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_FINAL_IMAGE_FORMAT)
|
||
{
|
||
SANE_FinalImgFormat* fmt = (SANE_FinalImgFormat*)data;
|
||
|
||
return set_final_image_format(fmt);
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_FINAL_COMPRESSION)
|
||
{
|
||
*(int*)data = SANE_COMPRESSION_NONE;
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_FINAL_COMPRESSION)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
else if(code == IO_CTRL_CODE_TEST_SINGLE)
|
||
{
|
||
return set_leaflet_scan();
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_AUTO_COLOR_TYPE)
|
||
{
|
||
return set_auto_color_type();
|
||
}
|
||
else if(code == IO_CTRL_CODE_GET_HARDWARE_VERSION)
|
||
{
|
||
|
||
std::string fw = get_firmware_version();
|
||
if (fw.empty())
|
||
{
|
||
return SCANNER_ERR_NO_DATA;
|
||
}
|
||
if (*len < fw.size() + 1)
|
||
{
|
||
*len = fw.size() + 1;
|
||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
}
|
||
|
||
if (data && fw.length())
|
||
::strcpy((char*)data, fw.c_str());
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
else if(code == IO_CTRL_CODE_GET_SERIAL)
|
||
{
|
||
if (!is_online())
|
||
return SCANNER_ERR_DEVICE_NOT_FOUND;
|
||
|
||
std::string ser = get_serial_num();
|
||
if (*len < ser.size() + 1)
|
||
{
|
||
*len = ser.size() + 1;
|
||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
}
|
||
if(data && ser.length())
|
||
::strcpy((char*)data, ser.c_str());
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_IP)
|
||
{
|
||
std::string ip = get_ip();
|
||
if (*len < ip.size() + 1)
|
||
{
|
||
*len = ip.size() + 1;
|
||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
}
|
||
if(data && ip.length())
|
||
::strcpy((char*)data, ip.c_str());
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_PAPER_ON)
|
||
{
|
||
return get_scanner_paperon(*(SANE_Bool*)data);
|
||
}
|
||
else if(code == IO_CTRL_CODE_GET_POWER_LEVEL)
|
||
{
|
||
int val = 0,
|
||
ret = SCANNER_ERR_OK;
|
||
|
||
if (*len < sizeof(int *))
|
||
{
|
||
*len = sizeof(int *);
|
||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
}
|
||
|
||
ret = get_sleep_time(val);
|
||
if (ret == SCANNER_ERR_OK)
|
||
{
|
||
*((int *)data) = val;
|
||
}
|
||
return ret;
|
||
}
|
||
else if(code == IO_CTRL_CODE_SET_POWER_LEVEL)
|
||
{
|
||
int val = *((int*)data);
|
||
int sleeptime = 0;
|
||
|
||
switch (val)
|
||
{
|
||
case SLEEP_TIME_0MIN:
|
||
if (pid_ == 0x300 || pid_ == 0x400)
|
||
val = INT_MAX; //3288不休眠
|
||
else
|
||
val = -1; //不休眠 -1 3399
|
||
break;
|
||
case SLEEP_TIME_5MIN:
|
||
val = 5;
|
||
break;
|
||
case SLEEP_TIME_10MIN:
|
||
val = 10;
|
||
break;
|
||
case SLEEP_TIME_20MIN:
|
||
val = 20;
|
||
break;
|
||
case SLEEP_TIME_30MIN:
|
||
val = 30;
|
||
break;
|
||
case SLEEP_TIME_60MIN:
|
||
val = 60;
|
||
break;
|
||
case SLEEP_TIME_120MIN:
|
||
val = 120;
|
||
break;
|
||
case SLEEP_TIME_240MIN:
|
||
val = 240;
|
||
break;
|
||
case SANE_POWER_SHUTDOWN:
|
||
return set_devshtudown();
|
||
case SANE_POWER_RESTART:
|
||
return set_devreboot(val);
|
||
default:
|
||
val = -1;
|
||
break;
|
||
}
|
||
|
||
sleeptime = val;
|
||
if (val != -1 && val != INT_MAX)
|
||
{
|
||
sleeptime = val * 60;
|
||
}
|
||
return set_sleep_time(sleeptime);
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_CUSTOM_GAMMA)
|
||
{
|
||
SANE_Gamma* v = (SANE_Gamma*)data;
|
||
|
||
memcpy(v, custom_gamma_val_, sizeof(*custom_gamma_val_));
|
||
if (len)
|
||
*len = sizeof(*custom_gamma_val_);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_CUSTOM_GAMMA)
|
||
{
|
||
SANE_Gamma* v = (SANE_Gamma*)data;
|
||
|
||
memcpy(custom_gamma_val_, v, sizeof(*custom_gamma_val_));
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
else if(code == IO_CTRL_CODE_DISPLAY_APP_HELP)
|
||
{
|
||
//setting_help(data);
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_IMAGE_QUEUE_COUNT)
|
||
{
|
||
*len = final_imgs_.size();
|
||
|
||
return wait_img_.is_waiting() && wait_usb_.is_waiting() ? SCANNER_ERR_NO_DATA : SCANNER_ERR_OK;
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_PAPER_SIZE)
|
||
{
|
||
std::string name((char*)data);
|
||
int paper = match_best_paper(name, NULL);
|
||
SIZE size = paper_size(paper);
|
||
|
||
*len = (size.cx & 0x0ffff) | ((size.cy & 0x0ffff) << 16);
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
else if (code == IO_CTRL_CODE_CONVERT_IMAGE_FORMAT)
|
||
{
|
||
SANE_ImageFormatConvert *conv = (SANE_ImageFormatConvert*)data;
|
||
void* threshold = conv->dst.fmt.compress.detail;
|
||
int ret = SCANNER_ERR_OK;
|
||
|
||
conv->dst.fmt.compress.detail = (void*)bw_threshold_;
|
||
ret = hg_imgproc::convert_image_file(conv);
|
||
conv->dst.fmt.compress.detail = threshold;
|
||
|
||
return ret;
|
||
}
|
||
else if (code == IO_CTRL_CODE_FREE_MEMORY)
|
||
{
|
||
free_memory(data);
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
else if(code == IO_CTRL_CODE_GET_LOG_FILE && len && *len == LOG_FILE_DEVICE)
|
||
{
|
||
string str;
|
||
int ret = get_device_log(str);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "str = %d\n", str.length());
|
||
|
||
*(char*)data = 0;
|
||
if (ret != SCANNER_ERR_OK)
|
||
{
|
||
return ret;
|
||
}
|
||
::strcpy((char*)data, str.c_str());
|
||
return 0;
|
||
}
|
||
else if(code == IO_CTRL_CODE_SET_SCAN_LOCK_CHECK_VAL)
|
||
{
|
||
string str = (char*)data;
|
||
|
||
return set_scan_lock_check_val(str);
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_SCAN_LOCK)
|
||
{
|
||
SANE_Bool set_islock = *((SANE_Bool *)data);
|
||
//set_scan_islock(set_islock);
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_SCAN_ISLOCK)
|
||
{
|
||
|
||
SANE_Bool islock = *((SANE_Bool*)data);
|
||
int ret = get_scan_islock(islock);
|
||
*((SANE_Bool*)data) = islock;
|
||
utils::to_log(LOG_LEVEL_DEBUG, "io ctrl islock:%d\r\n", *((SANE_Bool*)data));
|
||
return ret;
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_FIRMWARE_UPGRADE)
|
||
{
|
||
string str = (char*)data;
|
||
return set_firmware_upgrade(str);
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_HISTORY_SCAN_NUM)
|
||
{
|
||
int num = 0;
|
||
int ret = get_history_scan_count(num);
|
||
(*(int*)data) = num;
|
||
return ret;
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_CLEAN_PAPER_ROAD)
|
||
{
|
||
return set_clean_paper_road();
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_ROLLER_NUM)
|
||
{
|
||
int num = 0;
|
||
int ret = get_roller_num(num);
|
||
(*(int*)data) = num;
|
||
return ret;
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_FEEDMODE)
|
||
{
|
||
return on_set_feedmode(*((int*)data));
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_SKEW_CHECK)
|
||
{
|
||
return on_skew_check_changed(*((bool*)data));
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_SKEW_CHECK_VAL)
|
||
{
|
||
return on_skew_check_level_changed(*((int*)data));
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_IS_MODE)
|
||
{
|
||
return get_scan_mode(*((bool*)data));
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_ULTRASONIC_MODULE)
|
||
{
|
||
return on_ultrasonic_check_changed(*((bool*)data));
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_SPEED_MODE)
|
||
{
|
||
return set_speed_mode(*((int*)data));
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_SPEED_MODE)
|
||
{
|
||
return get_speed_mode(*((int*)data));
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_CIS_IMAGE)
|
||
{
|
||
return on_cis_get_image(*((bool*)data));
|
||
}
|
||
else if(code == IO_CTRL_CODE_GET_IMAGE)
|
||
{
|
||
return start();;
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_DISTORTION_IMAGE)
|
||
{
|
||
return set_distortion_image(*((bool*)data));
|
||
}
|
||
else if(code == IO_CTRL_CODE_GET_PC_DISTORTION_CHECK_VAL)
|
||
{
|
||
if (distortion_val.h > 0)
|
||
{
|
||
*(SANE_DISTORTION_VAL*)data = distortion_val;
|
||
}
|
||
return SCANNER_ERR_OK;
|
||
//return get_distortion_check_val(*((int*)data));
|
||
}
|
||
else if(code == IO_CTRL_CODE_SET_DISTORTION_DEVS_CHECK_VAL)
|
||
{
|
||
return set_devs_distortion_check_val(*((float*)data));
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_DISTORTION_DEVS_CHECK_VAL)
|
||
{
|
||
return get_devs_distortion_check_val(*((float*)data));
|
||
}
|
||
else if(code == IO_CTRL_CODE_SET_DEVS_REBOOT)
|
||
{
|
||
return set_devreboot(*((int*)data));
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_AUTO_FALT)
|
||
{
|
||
is_auto_falt = true;
|
||
return set_auto_flat(*((int*)data));
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_COLOR)
|
||
{
|
||
long l = len ? *len : 0;
|
||
int err = setting_color_mode(data, &l);
|
||
if (len)
|
||
*len = l;
|
||
|
||
return err;
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_DPI)
|
||
{
|
||
long l = len ? *len : sizeof(int);
|
||
int err = setting_resolution(data, &l);
|
||
|
||
if (len)
|
||
*len = l;
|
||
|
||
return err;
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_VIDPID)
|
||
{
|
||
int num = *((int*)data);
|
||
return set_vid_pid(num);
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_SERIAL)
|
||
{
|
||
string str = (char*)data;
|
||
return set_serial_num((char*)data);
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_VIDPID)
|
||
{
|
||
int num = 0;
|
||
int ret = get_vid_pid(num);
|
||
(*(int*)data) = num;
|
||
return ret;
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_DEVS_MODEL)
|
||
{
|
||
return set_device_model((char*)data);
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_DEVS_MODEL)
|
||
{
|
||
int num = 0;
|
||
string str = get_device_model();
|
||
if (str.empty())
|
||
{
|
||
return SCANNER_ERR_NO_DATA;
|
||
}
|
||
if (*len < str.size())
|
||
{
|
||
*len = str.size();
|
||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
}
|
||
::strcpy((char*)data, str.c_str());
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_SCAN_WITH_HOLE)
|
||
{
|
||
*(SANE_Bool*)data = image_prc_param_.bits.rid_hole || isremove_left_hole || isremove_low_hole || isremove_right_hole || isremove_top_hole ? SANE_TRUE : SANE_FALSE;
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_SCAN_WITH_HOLE)
|
||
{
|
||
image_prc_param_.bits.rid_hole = *(SANE_Bool*)data == SANE_TRUE;
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
else if (code == IO_CTRL_CODE_SET_SCAN_WHEN_PAPER_ON)
|
||
{
|
||
long l = len ? *len : sizeof(bool);
|
||
int ret = setting_auto_paper_scan(data, &l);
|
||
if (len)
|
||
*len = l;
|
||
|
||
return ret;
|
||
}
|
||
else if (code == IO_CTRL_CODE_GET_SCAN_WHEN_PAPER_ON)
|
||
{
|
||
if (!len)
|
||
return SCANNER_ERR_INVALID_PARAMETER;
|
||
if (*len < sizeof(bool))
|
||
{
|
||
*len = sizeof(bool);
|
||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||
}
|
||
*(bool*)data = is_auto_paper_scan;
|
||
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::get_roller_life(void)
|
||
{
|
||
return 150000;
|
||
}
|
||
int hg_scanner::discard_all_images(void)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
std::string hg_scanner::get_firmware_version(void)
|
||
{
|
||
return BRAND_DEVICE_NOT_SUPPORT;
|
||
}
|
||
std::string hg_scanner::get_serial_num(void)
|
||
{
|
||
return BRAND_DEVICE_NOT_SUPPORT;
|
||
}
|
||
std::string hg_scanner::get_ip(void)
|
||
{
|
||
return BRAND_DEVICE_NOT_SUPPORT;
|
||
}
|
||
std::string hg_scanner::get_device_model(void)
|
||
{
|
||
return BRAND_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::get_roller_num(int &val)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::get_device_log(string &log)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_devreboot(int data)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_devshtudown()
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_clear_roller_num(void)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_clear_history_num(void)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::get_history_scan_count(int &num)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_scan_islock(SANE_Bool set_islock)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::get_scan_islock(SANE_Bool& islock)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_scan_lock_check_val(string check_str)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_firmware_upgrade(std::string filename)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_clean_paper_road()
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::get_dev_islock_file(int& islockfile)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_dev_islock_file(int islockfile)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::get_scan_mode(bool& type)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_speed_mode(int data)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::get_speed_mode(int& data)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
|
||
int hg_scanner::set_distortion_image(bool type)
|
||
{
|
||
is_dpi_color_check = type;
|
||
int ret = SCANNER_ERR_OK;
|
||
if (type)
|
||
{
|
||
ret = set_leaflet_scan();
|
||
}
|
||
return ret;
|
||
}
|
||
int hg_scanner::get_distortion_check_val(int &val)
|
||
{
|
||
val = *(int*)&save_dpi_color_check_val;
|
||
//val = ;
|
||
|
||
if (val != 0)
|
||
{
|
||
return SCANNER_ERR_NO_DATA;
|
||
}
|
||
return 0;
|
||
}
|
||
int hg_scanner::set_devs_distortion_check_val(float data)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::get_devs_distortion_check_val(float& data)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_auto_flat(int data)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_updata0303(void)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::get_motor_board_ver(string& ver)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_devs_time(string times)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::get_devs_time(string& times)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_device_model(string sts)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_serial_num(string str)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_vid_pid(int data)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::get_vid_pid(int& data)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
|
||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||
int hg_scanner::set_leaflet_scan(void)
|
||
{
|
||
return SCANNER_ERR_NO_DATA;
|
||
}
|
||
int hg_scanner::get_abuot_info(void)
|
||
{
|
||
|
||
return SCANNER_ERR_NO_DATA;
|
||
}
|
||
int hg_scanner::restore_default_setting(void)
|
||
{
|
||
return SCANNER_ERR_NO_DATA;
|
||
}
|
||
int hg_scanner::set_final_image_format(SANE_FinalImgFormat* fmt)
|
||
{
|
||
switch (fmt->img_format)
|
||
{
|
||
case SANE_IMAGE_TYPE_BMP:
|
||
img_type_ = ".bmp";
|
||
break;
|
||
case SANE_IMAGE_TYPE_PNG:
|
||
img_type_ = ".png";
|
||
break;
|
||
case SANE_IMAGE_TYPE_JPG:
|
||
img_type_ = ".jpg";
|
||
break;
|
||
case SANE_IMAGE_TYPE_TIFF:
|
||
return SCANNER_ERR_INVALID_PARAMETER;
|
||
case SANE_IMAGE_TYPE_WEBP:
|
||
return SCANNER_ERR_INVALID_PARAMETER;
|
||
case SANE_IMAGE_TYPE_PDF:
|
||
return SCANNER_ERR_INVALID_PARAMETER;
|
||
case SANE_IMAGE_TYPE_GIF:
|
||
return SCANNER_ERR_INVALID_PARAMETER;
|
||
case SANE_IMAGE_TYPE_SVG:
|
||
return SCANNER_ERR_INVALID_PARAMETER;
|
||
default:
|
||
img_type_ = ".bmp";
|
||
break;
|
||
}
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::get_compression_format(void)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_compression_format(void)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_auto_color_type(void)
|
||
{
|
||
is_auto_matic_color = true;
|
||
return SCANNER_ERR_OK;
|
||
}
|
||
int hg_scanner::get_device_code(void)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::get_sleep_time(int& data)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_sleep_time(int data)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
int hg_scanner::set_notify_sleep()
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
|
||
int hg_scanner::get_scanner_paperon(SANE_Bool& paperon)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
|
||
int hg_scanner::get_scan_is_sleep(SANE_Bool& data)
|
||
{
|
||
return SCANNER_ERR_DEVICE_NOT_SUPPORT;
|
||
}
|
||
void hg_scanner::image_process(std::shared_ptr<tiny_buffer>& buffer, uint32_t id)
|
||
{
|
||
if (!buffer.get() || !ImagePrc_pHandle_)
|
||
{
|
||
return;
|
||
}
|
||
int ret = SCANNER_ERR_OK;
|
||
hg_imgproc::IMGPRCPARAM param = get_image_process_object(pid_);
|
||
hg_imgproc::IMGHEAD ih;
|
||
int err = SCANNER_ERR_OK,
|
||
index = 0;
|
||
void* buf = NULL;
|
||
|
||
hg_imgproc::load_buffer(ImagePrc_pHandle_, buffer);
|
||
hg_imgproc::decode(ImagePrc_pHandle_, pid_, &img_conf_, ¶m);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "decode");
|
||
|
||
if (is_dpi_color_check)
|
||
{
|
||
CISTestImageProcess::CISTestResult res;
|
||
distortion_val.h = 0;
|
||
distortion_val.w =0;
|
||
distortion_val.scaleXY = 0;
|
||
save_dpi_color_check_val = 0;
|
||
|
||
err = hg_imgproc::cis_test_image(ImagePrc_pHandle_, res);
|
||
distortion_val.h = res.h;
|
||
distortion_val.w = res.w;
|
||
save_dpi_color_check_val = distortion_val.scaleXY = res.scaleXY;
|
||
is_dpi_color_check = false;
|
||
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Set distortion val is:h:%f w:%f distortion val is:%f\n", distortion_val.h, distortion_val.w, distortion_val.scaleXY);
|
||
}
|
||
else if (param.cis_image
|
||
|| ((img_conf_.papertype == TwSS::MaxSize || img_conf_.papertype == TwSS::USStatement)
|
||
&& pid_ == 0x0300
|
||
&& firmware_sup_dpi_600))
|
||
{
|
||
printf("cis 原图测试无需任何算法\r\n");
|
||
}
|
||
else
|
||
{
|
||
if ((isremove_left_hole || isremove_right_hole || isremove_top_hole || isremove_low_hole) && (pid_ != 0x239 && pid_ != 0x439))
|
||
{
|
||
//ret = hg_imgproc::fillhole(ImagePrc_pHandle_, isremove_top_hole_threshold, isremove_low_hole_threshold, isremove_left_hole_threshold, isremove_right_hole_threshold);
|
||
/*double left = isremove_left_hole ? isremove_left_hole_threshold : 0;
|
||
double right = isremove_right_hole ? isremove_right_hole_threshold : 0;
|
||
double top = isremove_top_hole ? isremove_top_hole_threshold : 0;
|
||
double low = isremove_low_hole ? isremove_low_hole_threshold : 0;*/
|
||
|
||
//double left = img_conf_.fillholeratio_left / 100.0;
|
||
//double right = img_conf_.fillholeratio_right / 100.0;
|
||
//double top = img_conf_.fillholeratio_up / 100.0 ;
|
||
//double low = img_conf_.fillholeratio_down / 100.0 ;
|
||
|
||
//ret = hg_imgproc::fillhole(ImagePrc_pHandle_, top, low, left, right);
|
||
|
||
//(this->*dump_img_)(ImagePrc_pHandle_, "fillhole");
|
||
//utils::to_log(LOG_LEVEL_WARNING, "Image proc fillhole is:%d\n", ret);
|
||
}
|
||
|
||
if (pid_ != 0x239 && pid_ != 0x439)
|
||
{
|
||
float dpi3288 = 200;
|
||
if (pid_ == 0x300|| pid_== 0x400)
|
||
{
|
||
if (firmware_sup_dpi_300 && pid_ == 0x300)
|
||
dpi3288 = (img_conf_.resolution_dst >= 300) ? 300 : 200;
|
||
else if (firmware_sup_dpi_600 && pid_ == 0x300)
|
||
dpi3288 = (img_conf_.resolution_dst == 600) ? 600 : (img_conf_.resolution_dst < 600 && img_conf_.resolution_dst >= 300) ? 300 : 200;
|
||
else
|
||
dpi3288 = 200;
|
||
}
|
||
ret = hg_imgproc::auto_crop(ImagePrc_pHandle_, dpi3288);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "auto_crop");
|
||
}
|
||
|
||
if (is_quality_ == IMG_SPEED && resolution_ >= 300)//239
|
||
{
|
||
utils::to_log(LOG_LEVEL_DEBUG, "set resolution_ is :%d\n", resolution_);
|
||
err = hg_imgproc::quality(ImagePrc_pHandle_, resolution_);
|
||
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "quality");
|
||
}
|
||
|
||
if (img_conf_.is_colorcast && pid_ != 0x239 && pid_ != 0x439)
|
||
{
|
||
ret = hg_imgproc::color_cast_correction(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "discardBlank");
|
||
}
|
||
if ((img_conf_.is_autodiscradblank_normal || img_conf_.is_autodiscradblank_vince) && (pid_ != 0x239 && pid_ != 0x439))
|
||
{
|
||
ret = hg_imgproc::discardBlank(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "discardBlank");
|
||
}
|
||
|
||
if (img_conf_.fadeback) //239
|
||
{
|
||
hg_imgproc::fadeback(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "fadeback");
|
||
}
|
||
|
||
if ( (((img_conf_.resolution_dst != img_conf_.resolution_native) && (pid_ == 0x300 || pid_ == 0x0400 || pid_ == 0x302 || pid_ == 0x402))
|
||
&& !firmware_sup_dpi_300 && !firmware_sup_dpi_600)
|
||
|
||
|| (pid_ == 0x300 && firmware_sup_dpi_300 && img_conf_.resolution_dst != 200 && img_conf_.resolution_dst != 300)
|
||
|| (pid_ == 0x300 && firmware_sup_dpi_600 && img_conf_.resolution_dst != 200 && img_conf_.resolution_dst != 300 && img_conf_.resolution_dst != 600))
|
||
{
|
||
float dpi3288 = 0.0;
|
||
dpi3288 = (img_conf_.resolution_dst >= 300 && (firmware_sup_dpi_300 || firmware_sup_dpi_600)) ? 300 : 200;
|
||
|
||
hg_imgproc::resolution_change(ImagePrc_pHandle_, dpi3288);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "resolution_change");
|
||
}
|
||
|
||
if ((img_conf_.cropRect.enable && !img_conf_.is_autocrop) && (pid_ != 0x239 && pid_ != 0x439))
|
||
{
|
||
hg_imgproc::croprect(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "resolution_change");
|
||
}
|
||
|
||
if ((img_conf_.filter != ColorFilter::FILTER_NONE
|
||
&& (image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE
|
||
|| image_prc_param_.bits.color_mode == COLOR_MODE_256_GRAY))
|
||
&& (pid_ != 0x239 && pid_ != 0x439))
|
||
{
|
||
hg_imgproc::channel(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "filter");
|
||
}
|
||
|
||
{
|
||
adjust_color(ImagePrc_pHandle_); //色调曲线 普通dsp版本需要矫正颜色 色调曲线目前是PC支持
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "adjust_color");
|
||
}
|
||
|
||
if ((img_conf_.pixtype == COLOR_MODE_24_BITS && img_conf_.hsvcorrect) && (pid_ != 0x239 && pid_ != 0x439))
|
||
{
|
||
hg_imgproc::answerSheetFilterRed(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "answerSheetFilterRed");
|
||
}
|
||
|
||
if ((img_conf_.refuseInflow) && (pid_ != 0x239 && pid_ != 0x439))
|
||
{
|
||
int lv = 5 + image_prc_param_.bits.is_permeate_lv_ * 10; //image_prc_param_.bits.is_permeate_lv_ = 0 1 2 3 4
|
||
|
||
hg_imgproc::antiInflow(ImagePrc_pHandle_, lv);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "antiInflow");
|
||
}
|
||
if ((img_conf_.colorCorrection && img_conf_.pixtype != COLOR_MODE_BLACK_WHITE) && (pid_ != 0x239 && pid_ != 0x439))
|
||
{
|
||
hg_imgproc::colorCorrection(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "colorCorrection");
|
||
}
|
||
|
||
if (((img_conf_.en_fold && pid_ != 0x239 && pid_ != 0x439)))
|
||
{
|
||
hg_imgproc::fold(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "fold");
|
||
}
|
||
|
||
if (((img_conf_.imageRotateDegree != TEXT_DIRECTION_0 || img_conf_.is_backrotate180) && (!img_conf_.is_autotext)) && (pid_ != 0x239 && pid_ != 0x439))
|
||
{
|
||
hg_imgproc::orentation(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "orentation");
|
||
}
|
||
|
||
if ((img_conf_.textureRemove) && (pid_ != 0x239 && pid_ != 0x439))
|
||
{
|
||
//hg_imgproc::textureRemove(ImagePrc_pHandle_);
|
||
hg_imgproc::remove_morr(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "textureRemove");
|
||
}
|
||
|
||
if (img_conf_.removeMorr && (pid_ != 0x239 && pid_ != 0x439))
|
||
{
|
||
hg_imgproc::remove_morr(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "remove_morr");
|
||
}
|
||
|
||
if ((img_conf_.detachnoise.is_detachnoise) && (pid_ != 0x239 && pid_ != 0x439))
|
||
{
|
||
hg_imgproc::nosieDetach(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "nosieDetach");
|
||
}
|
||
|
||
if ((img_conf_.pixtype == COLOR_MODE_BLACK_WHITE) && (pid_ != 0x239 && pid_ != 0x439))
|
||
{
|
||
hg_imgproc::errorextention(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "errorextention");
|
||
}
|
||
|
||
|
||
if (img_conf_.multi_output_red && img_conf_.pixtype == COLOR_MODE_24_BITS)//239
|
||
{
|
||
err = hg_imgproc::multi_out_red(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "multi_out_red");
|
||
}
|
||
|
||
if ((img_conf_.sharpen) && (pid_ != 0x239 && pid_ != 0x439))
|
||
{
|
||
hg_imgproc::sharpenType(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "sharpenType");
|
||
}
|
||
|
||
if (image_prc_param_.bits.split) //239
|
||
{
|
||
split3399_++;
|
||
err = hg_imgproc::split(ImagePrc_pHandle_,split3399_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "split");
|
||
}
|
||
|
||
if (!img_conf_.splitImage && !img_conf_.multi_output_red && !is_multiout) //239
|
||
{
|
||
if (img_conf_.automaticcolor)
|
||
{
|
||
hg_imgproc::auto_matic_color(ImagePrc_pHandle_, img_conf_.automaticcolortype);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "auto_matic_color");
|
||
}
|
||
}
|
||
if (img_conf_.is_autotext)//239
|
||
{
|
||
//hg_imgproc::ocr_auto_txtdirect(ImagePrc_pHandle_);
|
||
hg_imgproc::tesseract_auto_txtdirect(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "ocr_auto_txtdirect");
|
||
}
|
||
|
||
|
||
|
||
if (is_multiout)//239
|
||
{
|
||
int multi_out = img_conf_.multiOutput;
|
||
err = hg_imgproc::multi_out(ImagePrc_pHandle_, multi_out);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "multi_out");
|
||
}
|
||
}
|
||
|
||
hg_imgproc::final(ImagePrc_pHandle_);
|
||
(this->*dump_img_)(ImagePrc_pHandle_, "final");
|
||
while (hg_imgproc::get_final_data(ImagePrc_pHandle_, &ih, &buf, index++) == SCANNER_ERR_OK)
|
||
{
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Final picture %d (%d * %d * %d) with %u bytes!\n", index
|
||
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
|
||
|
||
if (!img_type_.empty())
|
||
{
|
||
std::vector<unsigned char>bmpdata;
|
||
//cv::imencode(img_type_,*((cv::Mat*)buf),bmpdata);
|
||
hg_imgproc::imgtypechange(ImagePrc_pHandle_, img_type_, buf, bmpdata);
|
||
if (bmpdata.empty())
|
||
{
|
||
status_ = SCANNER_ERR_NO_DATA;
|
||
return;
|
||
}
|
||
buf = bmpdata.data();
|
||
ih.total_bytes = bmpdata.size();
|
||
|
||
utils::to_log(LOG_LEVEL_DEBUG, "Set img type is:%s Final picture %d (%d * %d * %d) with %u bytes!\n", img_type_.c_str(), index
|
||
, ih.width, ih.height, ih.bits * ih.channels, ih.total_bytes);
|
||
}
|
||
if (id == -1)
|
||
id = hg_scanner_mgr::unique_id();
|
||
save_final_image(&ih, buf, id);
|
||
id = -1;
|
||
}
|
||
}
|
||
int hg_scanner::image_configuration(SCANCONF& ic)
|
||
{
|
||
int ret = 0;
|
||
ic.papertype = paper_size_;
|
||
|
||
if (is_lateral(image_prc_param_.bits.paper))
|
||
ic.paperAlign = Rot270;
|
||
else
|
||
ic.paperAlign = Rot0;
|
||
//{
|
||
//子类处理
|
||
//ic.en_sizecheck = dev_conf_.params_3399.enable_sizecheck;
|
||
//if (image_prc_param_.bits.text_direction != TEXT_DIRECTION_AUTO)
|
||
// ic.imageRotateDegree = (float)image_prc_param_.bits.text_direction;
|
||
//else
|
||
// ic.imageRotateDegree = 0;
|
||
|
||
//ic.imageRotateDegree *= 90.0f;
|
||
//}
|
||
|
||
ic.is_duplex = (image_prc_param_.bits.page == PAGE_DOUBLE
|
||
|| image_prc_param_.bits.page == PAGE_OMIT_EMPTY
|
||
|| image_prc_param_.bits.page == PAGE_OMIT_EMPTY_RECEIPT
|
||
|| image_prc_param_.bits.page == PAGE_FOLIO);
|
||
|
||
if (is_dpi_color_check)
|
||
{
|
||
ic.is_duplex = false;
|
||
}
|
||
ic.en_fold = (image_prc_param_.bits.page == PAGE_FOLIO);
|
||
|
||
ic.pixtype = image_prc_param_.bits.color_mode == COLOR_MODE_AUTO_MATCH ? 2 : image_prc_param_.bits.color_mode;
|
||
ic.automaticcolor = is_auto_matic_color;
|
||
ic.automaticcolortype = 1;// ic.pixtype; //存疑
|
||
|
||
ic.resolution_dst = (resolution_ >= 300) ? (is_quality_ == IMG_SPEED ? 200 : resolution_) : resolution_;
|
||
|
||
//if (resolution_ >= 300)
|
||
//{
|
||
// if (is_quality_ == IMG_SPEED)
|
||
// ic.resolution_dst = 200;
|
||
// else
|
||
// ic.resolution_dst = resolution_;
|
||
//}
|
||
//else
|
||
// ic.resolution_dst = resolution_;
|
||
|
||
ic.resolution_native = 200.0f;
|
||
ic.gamma = (float)gamma_;
|
||
{
|
||
//子类处理
|
||
/*ic.contrast = (contrast_ - 4) * 333.0;
|
||
ic.brightness = (bright_ - 128) * (2000.0 / 254.0);*/
|
||
}
|
||
|
||
ic.threshold = threshold_;
|
||
ic.is_autocontrast = 0; //无参数
|
||
ic.is_autocrop = (ic.papertype == TwSS::None || ic.papertype == TwSS::USStatement);
|
||
ic.is_autodiscradblank_normal = image_prc_param_.bits.page == PAGE_OMIT_EMPTY || is_discardblank;
|
||
ic.discardblank_percent = omit_empty_level_;
|
||
ic.is_autodiscradblank_vince = image_prc_param_.bits.page == PAGE_OMIT_EMPTY_RECEIPT;
|
||
ic.is_switchfrontback = image_prc_param_.bits.exchange;
|
||
ic.autodescrew = image_prc_param_.bits.automatic_skew;
|
||
ic.multi_output_red = image_prc_param_.bits.rid_red; //之前加上可能导致超时,或者未知错误不可描述。
|
||
ic.hsvcorrect = image_prc_param_.bits.rid_answer_red;
|
||
ic.sharpen = image_prc_param_.bits.sharpen;
|
||
//ic.enhance_color = image_prc_param_.bits.rid_color; //加这个会有问题
|
||
ic.fillbackground = image_prc_param_.bits.erase_black_frame;
|
||
ic.is_convex = (image_prc_param_.bits.fill_background == FILL_BKG_CONVEX_POLYGON);
|
||
if (ic.resolution_dst == 300)
|
||
ic.noise = anti_noise_ * 1.5;
|
||
else if (ic.resolution_dst == 600)
|
||
ic.noise = anti_noise_ * 3;
|
||
else
|
||
ic.noise = anti_noise_;
|
||
|
||
ic.indent = margin_;
|
||
ic.AutoCrop_threshold = threshold_;
|
||
{
|
||
//子类处理
|
||
//if (test_1_paper_)
|
||
//{
|
||
// LOG_INFO(LOG_LEVEL_DEBUG, "scanning mode: testing ONE paper ...\n");
|
||
// ic.scannum = ic.is_duplex ? 2 : 1;
|
||
//}
|
||
//else
|
||
//{
|
||
// if (scan_count_ == -1)
|
||
// ic.scannum = -1;
|
||
// else
|
||
// ic.scannum = (ic.is_duplex ? scan_count_ * 2 : scan_count_);
|
||
//}
|
||
}
|
||
ic.is_backrotate180 = image_prc_param_.bits.rotate_back_180;
|
||
ic.is_dogeardetection = image_prc_param_.bits.fractate_check;
|
||
{
|
||
//子类处理
|
||
//ic.hardwarecaps.en_skrewdetect = dev_conf_.params_3399.screw_detect_enable;
|
||
//ic.hardwarecaps.en_doublefeed = dev_conf_.params_3399.ultrasonic_enable;
|
||
//ic.hardwarecaps.en_stapledetect = dev_conf_.params_3399.staple_enbale;
|
||
//ic.hardwarecaps.skrewdetectlevel = dev_conf_.params_3399.screw_detect_level;
|
||
//ic.hardwarecaps.is_autopaper = dev_conf_.params_3399.is_autopaper;
|
||
}
|
||
ic.hardwarecaps.capturepixtype = 0; //暂无参数 获取图像类型
|
||
ic.hardwarecaps.lowpowermode = LowPowerMode::Min_None; //暂无参数 设置休眠时间 两个参数3399未使用
|
||
ic.fillhole.is_fillhole = image_prc_param_.bits.rid_hole;
|
||
ic.fillhole.fillholeratio = rid_hole_range_;
|
||
ic.detachnoise.is_detachnoise = image_prc_param_.bits.noise_optimize;
|
||
ic.detachnoise.detachnoise = noise_range_;
|
||
ic.is_autotext = image_prc_param_.bits.text_direction == TEXT_DIRECTION_AUTO ? 1 : 0;
|
||
ic.isfillcolor = is_color_fill;
|
||
ic.refuseInflow = image_prc_param_.bits.is_permeate;
|
||
ic.colorCorrection = 0;
|
||
ic.removeMorr = image_prc_param_.bits.remove_morr;
|
||
ic.errorExtention = image_prc_param_.bits.error_extention;//
|
||
ic.textureRemove = image_prc_param_.bits.remove_txtture;//
|
||
ic.splitImage = image_prc_param_.bits.split;
|
||
{
|
||
ic.cropRect.enable = custom_area_;
|
||
int height = (custom_area_br_y_ * ic.resolution_dst) / 25.4 - (custom_area_lt_y_ * ic.resolution_dst / 25.4);
|
||
int width = (custom_area_br_x_ * ic.resolution_dst) / 25.4 - (custom_area_lt_x_ * ic.resolution_dst / 25.4);
|
||
ic.cropRect.height = height;
|
||
ic.cropRect.width = width;
|
||
ic.cropRect.x = custom_area_lt_x_ * ic.resolution_dst / 25.4;
|
||
ic.cropRect.y = custom_area_lt_y_ * ic.resolution_dst / 25.4;
|
||
}
|
||
ic.multiOutput = (MultiOutput)image_prc_param_.bits.multi_out;
|
||
ic.normalCrop = image_prc_param_.bits.dark_sample;
|
||
ic.dogeardistabce = fractate_level_;
|
||
ic.fadeback = image_prc_param_.bits.erase_bakground;
|
||
ic.fadebackrange = erase_bkg_range_;
|
||
ic.isuoloadexceptionimage = pid_ == 0x0439 ? false : (double_paper_handle_ & DOUBLE_PAPER_SAVE_IMG) == DOUBLE_PAPER_SAVE_IMG;
|
||
adjust_filling_hole(&ic);
|
||
|
||
ic.fold_concatmode = fold_type_;
|
||
ic.HsvFilterType = 0;//暂定为0
|
||
ic.is_colorcast = color_correction_;
|
||
if (ic.en_fold)
|
||
{
|
||
ic.splitImage = false;
|
||
}
|
||
|
||
//多流输出优先级最高
|
||
if (is_multiout)
|
||
{
|
||
ic.pixtype = image_prc_param_.bits.multi_out == MULTI_GRAY_AND_BW ? COLOR_MODE_256_GRAY : COLOR_MODE_24_BITS;
|
||
ic.filter = 3;
|
||
ic.hsvcorrect = 0;
|
||
ic.multi_output_red = 0;
|
||
ic.fadeback = false;
|
||
ic.sharpen = 0;
|
||
ic.removeMorr = 0;
|
||
ic.textureRemove = 0;
|
||
ic.errorExtention = 0;
|
||
ic.detachnoise.is_detachnoise = 0;
|
||
}
|
||
else if (image_prc_param_.bits.color_mode == COLOR_MODE_24_BITS)
|
||
{
|
||
ic.filter = 3;
|
||
ic.errorExtention = 0;
|
||
ic.detachnoise.is_detachnoise = 0;
|
||
}
|
||
else if (image_prc_param_.bits.color_mode == COLOR_MODE_256_GRAY)
|
||
{
|
||
int filter_clr[] = { 3, 0, 1, 2, 5, 6, 7 };
|
||
ic.filter = filter_clr[image_prc_param_.bits.rid_color];
|
||
if (ic.filter != 3)
|
||
{
|
||
ic.pixtype = 2;
|
||
}
|
||
ic.multi_output_red = 0;
|
||
ic.hsvcorrect = 0;
|
||
ic.fadeback = false;
|
||
ic.errorExtention = 0;
|
||
ic.detachnoise.is_detachnoise = 0;
|
||
ic.is_colorcast = false;
|
||
}
|
||
else if (image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE)
|
||
{
|
||
int filter_clr[] = { 3, 0, 1, 2, 5, 6, 7 };
|
||
ic.filter = filter_clr[image_prc_param_.bits.rid_color];
|
||
if (ic.filter != 3)
|
||
{
|
||
ic.pixtype = 2;
|
||
}
|
||
ic.multi_output_red = 0;
|
||
ic.hsvcorrect = 0;
|
||
ic.fadeback = false;
|
||
ic.sharpen = 0;
|
||
ic.removeMorr = 0;
|
||
ic.textureRemove = 0;
|
||
ic.is_colorcast = false;
|
||
}
|
||
else if (image_prc_param_.bits.color_mode == COLOR_MODE_AUTO_MATCH)
|
||
{
|
||
ic.pixtype = 2;
|
||
ic.filter = 3;
|
||
ic.hsvcorrect = 0;
|
||
ic.multi_output_red = 0;
|
||
ic.fadeback = false;
|
||
ic.sharpen = 0;
|
||
ic.removeMorr = 0;
|
||
ic.textureRemove = 0;
|
||
ic.errorExtention = 0;
|
||
ic.detachnoise.is_detachnoise = 0;
|
||
ic.is_colorcast = false;
|
||
|
||
}
|
||
if (ic.resolution_dst >= 500
|
||
|| image_prc_param_.bits.paper == PAPER_MAX_SIZE
|
||
|| image_prc_param_.bits.paper == PAPER_MAX_SIZE_CLIP
|
||
|| image_prc_param_.bits.paper == PAPER_TRIGEMINY)
|
||
{
|
||
ic.removeMorr = 0;
|
||
ic.textureRemove = 0;
|
||
}
|
||
//自定义裁切
|
||
if (image_prc_param_.bits.paper == PAPER_AUTO_MATCH
|
||
|| image_prc_param_.bits.paper == PAPER_MAX_SIZE
|
||
|| image_prc_param_.bits.paper == PAPER_MAX_SIZE_CLIP
|
||
|| image_prc_param_.bits.paper == PAPER_TRIGEMINY
|
||
)
|
||
{
|
||
ic.cropRect.enable = false;
|
||
}
|
||
img_conf_ = ic;
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.pixtype=%d\r\n", ic.pixtype);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.papertype=%d\r\n", ic.papertype);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.AutoCrop_threshold=%d\r\n", ic.AutoCrop_threshold);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.autodescrew=%d\r\n", ic.autodescrew);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.automaticcolor=%d\r\n", ic.automaticcolor);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.brightness=%f\r\n", ic.brightness);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.contrast=%f\r\n", ic.contrast);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.en_fold=%d\r\n", ic.en_fold);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.en_sizecheck=%d\r\n", ic.en_sizecheck);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.enhance_color=%d\r\n", ic.enhance_color);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.fillbackground=%d\r\n", ic.fillbackground);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.filter=%d\r\n", ic.filter);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.gamma=%f\r\n", ic.gamma);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.hardwarecaps.capturepixtype=%d\r\n", ic.hardwarecaps.capturepixtype);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.hardwarecaps.en_doublefeed=%d\r\n", ic.hardwarecaps.en_doublefeed);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.hsvcorrect=%d", ic.hsvcorrect);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.imageRotateDegree=%f\r\n", ic.imageRotateDegree);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.indent=%d\r\n", 5);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.is_autocontrast=%d\r\n", ic.is_autocontrast);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.is_autocrop=%d\r\n", ic.is_autocrop);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.is_autodiscradblank_normal=%d\r\n", ic.is_autodiscradblank_normal);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.is_autodiscradblank_vince=%d\r\n", ic.is_autodiscradblank_vince);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.isfillcolor=%d\r\n", ic.isfillcolor);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.is_autotext=%d\r\n", ic.is_autotext);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.is_backrotate180=%d\r\n", ic.is_backrotate180);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.is_convex=%d\r\n", ic.is_convex);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.is_duplex=%d\r\n", ic.is_duplex);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.is_switchfrontback=%d\r\n", ic.is_switchfrontback);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.is_dogeardetection=%d\r\n", ic.is_dogeardetection);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.fillhole.multi_output_red=%d\r\n", ic.multi_output_red);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.noise=%d\r\n", ic.noise);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.pixtype=%d\r\n", ic.pixtype);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.resolution_dst=%f\r\n", ic.resolution_dst);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.resolution_native=%f\r\n", ic.resolution_native);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.scannum=%d\r\n", ic.scannum);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.sharpen=%d\r\n", ic.sharpen);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.discardblank_percent=%d\r\n", ic.discardblank_percent);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.detachnoise.is_detachnoise=%d\r\n", ic.detachnoise.is_detachnoise);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.detachnoise.detachnoise=%d\r\n", ic.detachnoise.detachnoise);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.detachnoise.refuseInflow=%d\r\n", ic.refuseInflow);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.detachnoise.refuseInflow=%d\r\n", ic.refuseInflow);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.removeMorr=%d\r\n", ic.removeMorr);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.errorExtention=%d\r\n", ic.errorExtention);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.textureRemove=%d\r\n", ic.refuseInflow);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.fillhole.is_fillhole=%d\r\n", ic.fillhole.is_fillhole);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.ic.fillhole.fillholeratio=%d\r\n ", ic.fillhole.fillholeratio);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.fadeback=%d\r\n", ic.fadeback);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.cropRect.enable=%d\r\n", ic.cropRect.enable);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.cropRect.width=%d\r\n", ic.cropRect.width);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.cropRect.height=%d\r\n", ic.cropRect.height);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.cropRect.x=%d\r\n", ic.cropRect.x);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.cropRect.y=%d\r\n", ic.cropRect.y);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.dogeardistabce=%d\r\n", ic.dogeardistabce);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.fold_concatmode=%d\r\n", ic.fold_concatmode);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.HsvFilterType=%d\r\n", ic.HsvFilterType);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.is_colorcast =%d\r\n", ic.is_colorcast);
|
||
utils::to_log(LOG_LEVEL_DEBUG, "ic.isuoloadexceptionimage=%d\r\n", ic.isuoloadexceptionimage);
|
||
return ret;
|
||
} |