支持TWAIN回调;读图失败时将字节数置为0

This commit is contained in:
gb 2022-06-18 08:55:15 +08:00
parent fbf3fedadc
commit ee1a8450fb
3 changed files with 18 additions and 5 deletions

View File

@ -2333,7 +2333,10 @@ int hg_scanner::read_image_data(unsigned char* buf, int* len)
return over ? SCANNER_ERR_NO_DATA : SCANNER_ERR_OK;
}
else
{
*len = 0;
return SCANNER_ERR_NO_DATA;
}
}
int hg_scanner::stop(void)
{

View File

@ -308,6 +308,12 @@ namespace local_utility
if (version_code)
*version_code = SANE_VERSION_CODE(SANE_CURRENT_MAJOR, SANE_CURRENT_MINOR, VERSION_BUILD); // leading-char '1' is used for avoid compiler considering '0118' as an octal number :)
}
void set_callback(sane_callback cb, void* param)
{
std::lock_guard<std::mutex> lck(cb_lock_);
cb_ui_ = cb;
cb_ui_parm_ = param;
}
void stop_work(void)
{
std::lock_guard<std::mutex> lck(cb_lock_);
@ -469,6 +475,10 @@ hg_sane_middleware* hg_sane_middleware::instance(void)
return hg_sane_middleware::inst_;
}
void hg_sane_middleware::set_callback(sane_callback cb, void* param)
{
local_utility::set_callback(cb, param);
}
void hg_sane_middleware::clear(void)
{
local_utility::stop_work();
@ -1097,7 +1107,7 @@ bool hg_sane_middleware::get_current_value(scanner_handle handle, int option, vo
jsn->get_value("title", val);
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "<--Get option(%d - %s) value: %s\n", option, val.c_str(), hg_sane_middleware::option_value_2_string(t, value).c_str());
VLOG_MINI_3(LOG_LEVEL_ALL, "<--Get option(%d - %s) value: %s\n", option, val.c_str(), hg_sane_middleware::option_value_2_string(t, value).c_str());
}
delete jsn;
@ -1458,11 +1468,11 @@ SANE_Status hg_sane_middleware::set_option(SANE_Handle h, SANE_Int option, SANE_
if (prev == v)
{
VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "-->Set option(%d - %s) value: %s\n", option, desc->title, v.c_str());
VLOG_MINI_3(LOG_LEVEL_ALL, "-->Set option(%d - %s) value: %s\n", option, desc->title, v.c_str());
}
else
{
VLOG_4(LOG_LEVEL_DEBUG_INFO, 512, "-->Set option(%d - %s) value: %s(Applied: %s)\n", option, desc->title, prev.c_str(), v.c_str());
VLOG_4(LOG_LEVEL_ALL, 512, "-->Set option(%d - %s) value: %s(Applied: %s)\n", option, desc->title, prev.c_str(), v.c_str());
}
if (err == SCANNER_ERR_OK)
@ -1996,8 +2006,7 @@ extern "C" { // avoid compiler exporting name in C++ style !!!
SANE_Status inner_sane_init_ex(SANE_Int* version_code, sane_callback cb, void* param)
{
local_utility::cb_ui_ = cb;
local_utility::cb_ui_parm_ = param;
local_utility::set_callback(cb, param);
hg_sane_middleware::instance();
local_utility::get_version(version_code);

View File

@ -162,6 +162,7 @@ protected:
public:
static std::string sane_path(void);
static hg_sane_middleware* instance(void);
static void set_callback(sane_callback cb, void* param);
static void clear(void);
static scanner_handle sane_handle_to_scanner(SANE_Handle h);
static SANE_Handle scanner_handle_to_sane(scanner_handle h);