修改第三方取图最后一段数据的返回代码

This commit is contained in:
gb 2022-09-23 10:26:04 +08:00
parent bd292e11db
commit 0bd9dce3a6
6 changed files with 43 additions and 3 deletions

View File

@ -2,9 +2,9 @@
#include "../wrapper/hg_log.h"
#include "sane/sane_option_definitions.h"
#include "scanner_setting.h"
#include "scanner_manager.h"
#if defined(WIN32) || defined(_WIN64)
#include "scanner_manager.h"
#include <direct.h>
#endif
@ -88,7 +88,7 @@ static std::string bmp_821(unsigned char* bits/*bits data*/, int w, int h, int*
hg_scanner::hg_scanner(ScannerSerial serial
, const char* dev_name, usb_io* io)
: name_(dev_name ? dev_name : ""), io_(io), status_(SCANNER_ERR_NOT_START), serial_(serial)
, scan_count_(-1), run_(true), paper_size_(TwSS::A4), erase_bkg_range_(10)
, 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)
@ -2422,6 +2422,10 @@ void hg_scanner::set_ui_callback(sane_callback cb, bool enable_async_io)
async_io_ = enable_async_io;
is_white_0_ = !async_io_;
}
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_);
@ -2794,8 +2798,13 @@ int hg_scanner::read_image_data(unsigned char* buf, int* 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 over ? SCANNER_ERR_NO_DATA : SCANNER_ERR_OK;
return SCANNER_ERR_OK;
}
else
{

View File

@ -40,6 +40,7 @@ class hg_scanner
std::string name_;
std::string save_multiout; //保存多留输出类型
bool save_sizecheck;
bool read_over_with_no_data_; // 针对第三方调用在最后一段数据时是否返回“SCANNER_ERR_NO_DATA”
int is_color_type_;//保存最后下发到设备的颜色类型
sane_callback ui_ev_cb_;
do_when_born_and_dead<hg_scanner>* scan_life_;
@ -308,6 +309,7 @@ protected:
public:
void set_ui_callback(sane_callback cb, bool enable_async_io);
void set_read_over_with_no_data(bool no_data);
int reset_io(usb_io* io);
int io_disconnected(void);
int get_pid(void);

View File

@ -5,6 +5,9 @@
#include "raw_src.h"
#include "char_const.h"
#if !defined(WIN32) && !defined(_WIN64)
#endif
// kinds of scanners ...
#define SCAN_PTR(ptr) ((hg_scanner*)ptr)
@ -75,6 +78,8 @@ int hg_scanner_mgr::ver_major_ = 1;
int hg_scanner_mgr::ver_minor_ = 0;
int hg_scanner_mgr::ver_build_ = 0;
int hg_scanner_mgr::ver_patch_ = 1;
std::string hg_scanner_mgr::pe_path_("");
std::string hg_scanner_mgr::pe_name_("");
hg_scanner_mgr::hg_scanner_mgr() : same_ind_(1)
{
@ -134,6 +139,18 @@ void hg_scanner_mgr::set_version(int hh, int hl, int lh, int ll)
hg_scanner_mgr::ver_build_ = lh;
hg_scanner_mgr::ver_patch_ = ll;
}
void hg_scanner_mgr::set_exe_name(const char* path, const char* name)
{
hg_scanner_mgr::pe_path_ = path ? path : "";
hg_scanner_mgr::pe_name_ = name ? name : "";
}
std::string hg_scanner_mgr::get_pe_name(std::string* path)
{
if (path)
*path = hg_scanner_mgr::pe_path_;
return hg_scanner_mgr::pe_name_;
}
hg_scanner* hg_scanner_mgr::create_scanner_empty(const char* name, usb_io* io, scanner_handle* h)
{
@ -586,7 +603,10 @@ scanner_err hg_scanner_mgr::hg_scanner_open(scanner_handle* h, const char* name,
}
if (scanner)
{
scanner->set_ui_callback(&hg_scanner_mgr::ui_default_callback, hg_scanner_mgr::async_io_enabled_);
scanner->set_read_over_with_no_data(STRICMP(hg_scanner_mgr::pe_name_.c_str(), "xsane") == 0);
}
std::lock_guard<std::mutex> lock(mutex_dev_);
std::vector<OLSCANNER>::iterator ptr = std::find(online_devices_.begin(), online_devices_.end(), name);

View File

@ -64,6 +64,9 @@ class hg_scanner_mgr
static sane_callback event_callback_;
static bool async_io_enabled_;
static std::string pe_path_;
static std::string pe_name_;
static int ver_major_;
static int ver_minor_;
static int ver_build_;
@ -87,6 +90,8 @@ public:
static hg_scanner_mgr* instance(sane_callback cb = NULL);
static void clear(void);
static void set_version(int hh, int hl, int lh, int ll);
static void set_exe_name(const char* path, const char* name);
static std::string get_pe_name(std::string* path = nullptr);
static hg_scanner* create_scanner_empty(const char* name, usb_io* io, scanner_handle* h);
static hg_scanner* create_scanner_g100(const char* name, usb_io* io, scanner_handle* h);

View File

@ -12,9 +12,12 @@
#define bzero(a, l) memset(a, 0, l)
#define PATH_SEPARATOR "\\"
#define DLL_EXTESION ".dll"
#define STRICMP stricmp
#else
#include <string.h>
#define PATH_SEPARATOR "/"
#define DLL_EXTESION ".so"
#define STRICMP strcasecmp
#endif
#ifdef OEM_HANWANG

View File

@ -90,6 +90,7 @@ extern "C"
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Module exe : %s\n", (pe + path + name).c_str());
hg_scanner_mgr::set_version(VERSION_MAJOR, VERSION_MINOR, VERSION_YEAR, GET_BUILD_VER);
hg_scanner_mgr::set_exe_name(pe.c_str(), name.c_str());
hg_scanner_mgr::instance(callback);
return SCANNER_ERR_OK;