调整图像信息头;启动扫描成功接收硬件配置参数
This commit is contained in:
parent
cdefbff07d
commit
92ee8ac685
|
@ -63,6 +63,29 @@ hg_scanner::hg_scanner(ONLNSCANNER* dev, imgproc_mgr* imgproc, hguser* user, std
|
|||
for(auto& v: *constopts)
|
||||
dev_opts_->add(v);
|
||||
}
|
||||
std::string alg(dev_opts_->get_option_value(nullptr, SANE_ACTION_GET_ENTIRE_JSON));
|
||||
gb_json *root = new gb_json(), *child = nullptr;
|
||||
if (root->attach_text(&alg[0]))
|
||||
{
|
||||
alg = "";
|
||||
child = root->first_child();
|
||||
while (child)
|
||||
{
|
||||
child->get_value("cat", alg);
|
||||
if (alg == "imgp")
|
||||
{
|
||||
int pos = 0;
|
||||
if (child->get_value("pos", pos))
|
||||
{
|
||||
img_prc_name_[pos] = child->key();
|
||||
}
|
||||
}
|
||||
child->release();
|
||||
child = root->next_child();
|
||||
}
|
||||
}
|
||||
root->release();
|
||||
|
||||
#ifdef USE_SAFE_THREAD
|
||||
auto tf = [this](void) -> void
|
||||
{
|
||||
|
@ -110,6 +133,9 @@ void hg_scanner::init(void)
|
|||
}
|
||||
else if (pimg == IMG_RECEIVER_FINISHED)
|
||||
{
|
||||
status_ = size;
|
||||
if (scan_over_notify_)
|
||||
scan_over_notify_(status_);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -226,9 +252,9 @@ void hg_scanner::dump_image(image_holder_ptr img)
|
|||
char alg[128] = { 0 };
|
||||
|
||||
if (img_prc_name_.count(stage))
|
||||
sprintf(alg, "%04X_%s", stage, img_prc_name_[stage].c_str());
|
||||
sprintf(alg, "%04X_%s(%u)", stage, img_prc_name_[stage].c_str(), img->get_info()->prc_time);
|
||||
else
|
||||
sprintf(alg, "%04X_Unk", stage);
|
||||
sprintf(alg, "%04X_Unk(%u)", stage, img->get_info()->prc_time);
|
||||
img->save_2_file(dump_path_.c_str(), alg);
|
||||
}
|
||||
|
||||
|
@ -336,13 +362,18 @@ int hg_scanner::set_value(const char* name, void* val)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int hg_scanner::start(void)
|
||||
int hg_scanner::start(std::string* devcfg, std::function<void(int)> over_cb)
|
||||
{
|
||||
int ret = SCANNER_ERR_OK;
|
||||
|
||||
cancelled_ = false;
|
||||
if (scanner_)
|
||||
ret = scanner_->scan_start();
|
||||
{
|
||||
ret = scanner_->scan_start(devcfg);
|
||||
scan_over_notify_ = over_cb;
|
||||
if (ret == SCANNER_ERR_OK)
|
||||
status_ = SCANNER_ERR_DEVICE_BUSY;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,8 @@ class hg_scanner : public sane_opt_provider
|
|||
hguser *user_ = nullptr;
|
||||
|
||||
double tx_prg_ = .0f; // file transfer progress
|
||||
|
||||
|
||||
std::function<void(int)> scan_over_notify_ = std::function<void(int)>(); // finish(err)
|
||||
volatile bool cancelled_ = false;
|
||||
volatile bool run_ = true;
|
||||
safe_fifo<image_holder*> raw_imgs_;
|
||||
|
@ -85,7 +86,7 @@ public:
|
|||
|
||||
// scanner operation ...
|
||||
public:
|
||||
int start(void);
|
||||
int start(std::string* devcfg, std::function<void(int)> over_cb = std::function<void(int)>());
|
||||
int stop(void);
|
||||
int close(void);
|
||||
int re_connect(void);
|
||||
|
|
|
@ -473,7 +473,7 @@ void scanner_handler::set_status_notifyer(std::function<void(uint32_t)> stntf)
|
|||
{
|
||||
status_notify_ = stntf;
|
||||
}
|
||||
int scanner_handler::scan_start(void)
|
||||
int scanner_handler::scan_start(std::string* devcfg)
|
||||
{
|
||||
auto call = [&](cmd_result* cmd) -> int
|
||||
{
|
||||
|
@ -488,14 +488,19 @@ int scanner_handler::scan_start(void)
|
|||
{
|
||||
LPPACK_BASE pack = (LPPACK_BASE)data->ptr();
|
||||
|
||||
*used = sizeof(PACK_BASE);
|
||||
*used = sizeof(PACK_BASE) + pack->payload_len;
|
||||
*more = nullptr;
|
||||
status_ = pack->data == 0 ? SCANNER_ERR_DEVICE_BUSY : SCANNER_ERR_OK;
|
||||
status_ = pack->data == 0 ? SCANNER_ERR_DEVICE_BUSY : pack->data;
|
||||
if (devcfg && pack->payload_len)
|
||||
*devcfg = std::move(std::string(pack->payload, pack->payload_len));
|
||||
cmd->trigger();
|
||||
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
if (status_ == SCANNER_ERR_DEVICE_BUSY)
|
||||
return SCANNER_ERR_DEVICE_BUSY;
|
||||
|
||||
if (!is_scanner_available())
|
||||
return ENODEV;
|
||||
|
||||
|
@ -837,6 +842,9 @@ int scanner_handler::reset_message_que(void)
|
|||
}
|
||||
bool scanner_handler::is_scanner_available(void)
|
||||
{
|
||||
return status_ == SCANNER_ERR_OK ||
|
||||
status_ == SCANNER_ERR_DEVICE_BUSY;
|
||||
//return status_ == SCANNER_ERR_OK ||
|
||||
// status_ == SCANNER_ERR_DEVICE_BUSY ||
|
||||
// status_ == SCANNER_ERR_DEVICE_NO_PAPER;
|
||||
return SCANNER_ERR_NOT_OPEN != status_
|
||||
&& SCANNER_ERR_DEVICE_NOT_FOUND != status_;
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ public:
|
|||
|
||||
void set_image_receiver(std::function<data_holder_ptr(LPPACKIMAGE/*NULL when scanning stopped*/, uint64_t/*size in image, error in stopped*/)> img);
|
||||
void set_status_notifyer(std::function<void(uint32_t)> stntf);
|
||||
int scan_start(void);
|
||||
int scan_start(std::string* devcfg = nullptr);
|
||||
int scan_stop(void);
|
||||
|
||||
int file_transfer(const char* local_path, const char* remote_path, bool to_device
|
||||
|
|
|
@ -51,7 +51,7 @@ enum ep0_req
|
|||
USB_REQ_EP0_GET_STATUS, // 获取各工作线程状态, return EP0REPLYSTATUS. req = me, ind = 0, val = bool: whether write log, len = sizeof(EP0REPLYSTATUS)
|
||||
USB_REQ_EP0_CANCEL_IO, // 设置当前IO数据的有效性. req = me, ind = 0, val = 0, len = sizeof(uint32_t), discard IO data when data is CANCEL_IO_CANCEL
|
||||
// work-flow: write control with 'CANCEL_IO_CANCEL', write bulk with 1 byte, write control with not 'CANCEL_IO_CANCEL' to restore
|
||||
USB_REQ_EP0_SET_ENCRYPT, // 设置加密方式, req = me, ind = 0, val = 0, len = sizeof(PACK_BASE)
|
||||
USB_REQ_EP0_SET_ENCRYPT, // 设置加密方式, req = me, ind = 0, val = 0, len = sizeof(PACK_BASE)
|
||||
};
|
||||
enum woker_status
|
||||
{
|
||||
|
@ -121,9 +121,9 @@ enum packet_cmd
|
|||
|
||||
enum img_cb_type
|
||||
{
|
||||
IMG_CB_IMAGE = 0,
|
||||
IMG_CB_STATUS,
|
||||
IMG_CB_STOPPED,
|
||||
IMG_CB_IMAGE = 0,
|
||||
IMG_CB_STATUS,
|
||||
IMG_CB_STOPPED,
|
||||
};
|
||||
|
||||
// option affection if value changed, see SANE_INFO_xxx
|
||||
|
@ -158,13 +158,13 @@ enum img_compression
|
|||
enum img_status
|
||||
{
|
||||
IMG_STATUS_OK = 0, // normal
|
||||
IMG_STATUS_DOUBLE = 1 << 0, // double-feeded paper
|
||||
IMG_STATUS_JAM = 1 << 1, // jammed paper
|
||||
IMG_STATUS_STAPLE = 1 << 2, // staples on the paper
|
||||
IMG_STATUS_DOUBLE = 1 << 0, // double-feeded paper
|
||||
IMG_STATUS_JAM = 1 << 1, // jammed paper
|
||||
IMG_STATUS_STAPLE = 1 << 2, // staples on the paper
|
||||
IMG_STATUS_SIZE_ERR = 1 << 3, // size check failed
|
||||
IMG_STATUS_DOGEAR = 1 << 4, // paper has dogear - common
|
||||
IMG_STATUS_DOGEAR = 1 << 4, // paper has dogear - common
|
||||
IMG_STATUS_DOGEAR_PARTIAL = 1 << 5, // dogear - scanned partial
|
||||
IMG_STATUS_BLANK = 1 << 6, // blank image
|
||||
IMG_STATUS_BLANK = 1 << 6, // blank image
|
||||
};
|
||||
enum data_type
|
||||
{
|
||||
|
@ -228,14 +228,14 @@ typedef struct _ep0_reply
|
|||
uint32_t task_required_bytes; // required byte of this packet
|
||||
uint32_t packets_to_sent; // how many packets in sent queue
|
||||
uint32_t bytes_to_sent; // how many bytes data is waiting for be sent in one replying packet
|
||||
}EP0REPLYSTATUS, *LPEP0REPLYSTATUS;
|
||||
}EP0REPLYSTATUS, * LPEP0REPLYSTATUS;
|
||||
|
||||
typedef struct _peer_config
|
||||
{
|
||||
uint64_t pid; // [in] - host pc process id; [out] - usb service process id
|
||||
uint32_t io_size; // IO buffer size
|
||||
uint16_t ver; // protocol version
|
||||
}PEERCFG, *LPPEERCFG;
|
||||
}PEERCFG, * LPPEERCFG;
|
||||
|
||||
typedef struct _pack_base // A piece of data has only one header
|
||||
{
|
||||
|
@ -272,7 +272,7 @@ typedef struct _config_val
|
|||
uint16_t val_size; // real size of value
|
||||
uint16_t max_size; // max size of this option, this value has given in gb_json::size
|
||||
char data[0]; // contains value and name. fetch them according name_off and val_off members.
|
||||
}CFGVAL, *LPCFGVAL;
|
||||
}CFGVAL, * LPCFGVAL;
|
||||
|
||||
typedef struct _img_pos
|
||||
{
|
||||
|
@ -301,10 +301,11 @@ typedef struct _pack_img
|
|||
uint32_t bpp : 6; // bits per pixel. (image-collector set)
|
||||
uint32_t bppc : 6; // bits per pixel in this channel, equal to 'bpp' if pos.channel_ind == 0x0f. (image-collector set)
|
||||
uint32_t compression : 6; // image data compression, see 'img_compression'. (image-collector set)
|
||||
uint32_t reserve : 2; // unused now
|
||||
uint32_t reserved : 2; //
|
||||
uint32_t prc_stage : 14; // position of image processor, 0 is raw from CIS directly
|
||||
uint32_t prc_time : 18; // spent time in milliseconds of image-process prc_stage
|
||||
uint32_t info_size; // image information size in bytes, information part is used for quality of JPEG, pallete of BMP .... (image-collector set)
|
||||
uint64_t prc_stage : 16; // position of image processor, 0 is raw from CIS directly
|
||||
uint64_t data_size : 48; // image data size in 'data' with bytes. (image-collector set)
|
||||
uint32_t data_size; // image data size in 'data' with bytes. (image-collector set)
|
||||
// char data[0]; // two parts: image info (info_size) + image data (data_size)
|
||||
|
||||
STRUCT_CONSTRUCTOR(_pack_img)
|
||||
|
@ -321,7 +322,7 @@ typedef struct _tx_file
|
|||
uint64_t size; // total size
|
||||
uint64_t offset; // offset in the file
|
||||
char path[2]; // file full path-name
|
||||
}TXFILE, *LPTXFILE;
|
||||
}TXFILE, * LPTXFILE;
|
||||
typedef struct _file_info
|
||||
{
|
||||
OPERTOKEN token; // operation token, returned by command PACK_CMD_TOKEN_GET
|
||||
|
|
|
@ -1087,6 +1087,67 @@ namespace utils
|
|||
return err;
|
||||
}
|
||||
|
||||
int get_memory_usage(uint64_t* peak, uint64_t* now, uint64_t* phymem, uint32_t pid)
|
||||
{
|
||||
if(pid == -1)
|
||||
pid = GetCurrentProcessId();
|
||||
|
||||
#if OW_WIN
|
||||
#else
|
||||
char cmd[40] = {0};
|
||||
std::string result(""), tag("");
|
||||
size_t pos = 0;
|
||||
|
||||
sprintf(cmd, "cat /proc/%u/status | grep Vm", pid);
|
||||
result = get_command_result(cmd);
|
||||
if(result.empty())
|
||||
return -1;
|
||||
|
||||
if(peak)
|
||||
{
|
||||
tag = "VmPeak";
|
||||
pos = result.find(tag);
|
||||
if(pos != std::string::npos)
|
||||
sscanf(result.c_str() + pos, (tag + ": %llu kB").c_str(), peak);
|
||||
else
|
||||
*peak = 0;
|
||||
*peak *= 1024;
|
||||
}
|
||||
|
||||
if(now)
|
||||
{
|
||||
tag = "VmSize";
|
||||
pos = result.find(tag);
|
||||
if(pos != std::string::npos)
|
||||
sscanf(result.c_str() + pos, (tag + ": %llu kB").c_str(), now);
|
||||
else
|
||||
*now = 0;
|
||||
*now *= 1024;
|
||||
}
|
||||
|
||||
if(phymem)
|
||||
{
|
||||
tag = "VmRSS";
|
||||
pos = result.find(tag);
|
||||
if(pos != std::string::npos)
|
||||
sscanf(result.c_str() + pos, (tag + ": %llu kB").c_str(), phymem);
|
||||
else
|
||||
*phymem = 0;
|
||||
*phymem *= 1024;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
void print_memory_usage(const char* tips, bool to_log_file)
|
||||
{
|
||||
uint64_t peak = 0, now = 0, phy = 0;
|
||||
|
||||
get_memory_usage(&peak, &now, &phy);
|
||||
if(to_log_file)
|
||||
to_log(LOG_LEVEL_DEBUG, "%s: Peak = %llu, Now = %llu, Phy = %llu\n", tips, peak, now, phy);
|
||||
else
|
||||
printf("%s: Peak = %llu, Now = %llu, Phy = %llu\n", tips, peak, now, phy);
|
||||
}
|
||||
int get_disk_space(const char* path, unsigned long long* total, unsigned long long* avail, unsigned long long* block)
|
||||
{
|
||||
int ret = 0;
|
||||
|
@ -1707,7 +1768,10 @@ int __stdcall sem_init(sem_t* handle, int, int)
|
|||
|
||||
*handle = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
if (*handle)
|
||||
{
|
||||
ResetEvent(*handle);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = GetLastError();
|
||||
|
@ -1783,9 +1847,16 @@ bool platform_event::wait(unsigned timeout)
|
|||
sem_wait(&sem_);
|
||||
else
|
||||
{
|
||||
struct timespec to;
|
||||
to.tv_sec = timeout / 1000;
|
||||
to.tv_nsec = (long)((timeout % 1000) * 1000 * 1000);
|
||||
struct timespec to = {0};
|
||||
#if !OS_WIN
|
||||
if(clock_gettime(CLOCK_REALTIME, &to) == -1)
|
||||
{
|
||||
utils::to_log(LOG_LEVEL_DEBUG, "clock_gettime failed: %d - %s\n", errno, strerror(errno));
|
||||
to.tv_sec = time(nullptr);
|
||||
}
|
||||
#endif
|
||||
to.tv_sec += timeout / 1000;
|
||||
to.tv_nsec += (long)((timeout % 1000) * 1000 * 1000);
|
||||
waited = sem_timedwait(&sem_, &to) == 0;
|
||||
}
|
||||
if (log_)
|
||||
|
@ -1798,6 +1869,10 @@ void platform_event::trigger(void)
|
|||
{
|
||||
sem_post(&sem_);
|
||||
}
|
||||
void platform_event::reset(void)
|
||||
{
|
||||
sem_init(&sem_, 0, 0);
|
||||
}
|
||||
bool platform_event::is_waiting(void)
|
||||
{
|
||||
return waiting_;
|
||||
|
|
|
@ -64,6 +64,8 @@ namespace utils
|
|||
int move_file(const char* from, const char* to);
|
||||
int make_file_size(const char* file, uint64_t size); // truncate or extend file size to 'size', create if not exist
|
||||
|
||||
int get_memory_usage(uint64_t* peak, uint64_t* now, uint64_t* phymem, uint32_t pid = -1);
|
||||
void print_memory_usage(const char* tips, bool to_log_file);
|
||||
int get_disk_space(const char* path, unsigned long long* total, unsigned long long* avail, unsigned long long* block);
|
||||
unsigned int get_page_size(unsigned int* map_unit = nullptr);
|
||||
|
||||
|
@ -220,6 +222,40 @@ public:
|
|||
virtual int32_t release(void);
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class refer_guard
|
||||
{
|
||||
T *obj_ = nullptr;
|
||||
|
||||
void clear(void)
|
||||
{
|
||||
if(obj_)
|
||||
obj_->release();
|
||||
obj_ = nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
refer_guard()
|
||||
{}
|
||||
refer_guard(T* obj) : obj_(obj)
|
||||
{}
|
||||
~refer_guard()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
public:
|
||||
void reset(T* obj)
|
||||
{
|
||||
clear();
|
||||
obj_ = obj;
|
||||
}
|
||||
T* operator->(void)
|
||||
{
|
||||
return obj_;
|
||||
}
|
||||
};
|
||||
|
||||
// time utility
|
||||
class chronograph
|
||||
{
|
||||
|
@ -270,6 +306,7 @@ public:
|
|||
bool try_wait(void);
|
||||
bool wait(unsigned timeout = USB_TIMEOUT_INFINITE/*ms*/); // USB_TIMEOUT_INFINITE is waiting unfinite, true when watied and false for wait timeout
|
||||
void trigger(void);
|
||||
void reset(void);
|
||||
bool is_waiting(void);
|
||||
void enable_log(bool enable);
|
||||
|
||||
|
@ -335,11 +372,12 @@ public:
|
|||
|
||||
return cnt + 1;
|
||||
}
|
||||
bool take(T& t, bool wait = false)
|
||||
bool take(T& t, bool wait = false, uint32_t to_ms = USB_TIMEOUT_INFINITE)
|
||||
{
|
||||
if (wait && size() == 0)
|
||||
{
|
||||
wait_->wait();
|
||||
if(!wait_->wait(to_ms))
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -369,6 +407,7 @@ public:
|
|||
SIMPLE_LOCK(lock_);
|
||||
|
||||
que_.clear();
|
||||
wait_->reset();
|
||||
}
|
||||
void trigger(void)
|
||||
{
|
||||
|
|
|
@ -25,7 +25,7 @@ bool image_processor::set_opt_json_text(char* txt)
|
|||
if (first)
|
||||
{
|
||||
first->get_value("ver", ver_);
|
||||
first->get_value("position", pos_);
|
||||
first->get_value("pos", pos_);
|
||||
if (!first->get_value("enabled", enabled_))
|
||||
enabled_ = true;
|
||||
first->release();
|
||||
|
|
|
@ -8,39 +8,23 @@
|
|||
//
|
||||
// NOTE: the interface is for all algorithms are in ONE module
|
||||
|
||||
#include <base/packet.h>
|
||||
#include <sane_opt_json/base_opt.h>
|
||||
#include "../../hgdriver/3rdparty/opencv/include/opencv2/opencv.hpp"
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
typedef struct _hg_img_info
|
||||
{
|
||||
uint32_t paper_ind : 16; // paper index in this turn/start, based ZERO. (image-collector set)
|
||||
uint32_t new_img : 1; // 0 - partial data; 1 - new image data. (image-collector set)
|
||||
uint32_t img_over : 1; // 0 - has data yet; 1 - END for the image. (image-collector set)
|
||||
uint32_t paper_side : 4; // paper_side
|
||||
uint32_t status : 10; // img_status
|
||||
uint32_t split_ind : 4; // splitting order, from left to right and then top to bottom, based ZERO
|
||||
uint32_t compress : 6; // compression type
|
||||
uint32_t channels : 3;
|
||||
uint32_t bits : 6;
|
||||
uint32_t reserved : 13;
|
||||
}HGIMGINFO;
|
||||
|
||||
typedef struct _proc_img_info_
|
||||
{
|
||||
HGIMGINFO info;
|
||||
PACKIMAGE info;
|
||||
cv::Mat img;
|
||||
std::string ext_info; // 图片扩展信息(图像处理过程中可以保存各算法间的共有信息;处理完后为向用户提供的扩展信息)
|
||||
}PROCIMGINFO, *LPPROCIMGINFO;
|
||||
|
||||
typedef struct _proc_img_info_modules // 跨模块参数
|
||||
{
|
||||
HGIMGINFO info;
|
||||
uint32_t width; // in px
|
||||
uint32_t height; // in px
|
||||
uint32_t channels;
|
||||
uint32_t bits; // bits per channel
|
||||
PACKIMAGE info;
|
||||
uint32_t bytes_per_line;
|
||||
uint8_t* data; // size = bytes_per_line * height
|
||||
}PROCIIM, *LPPROCIIM;
|
||||
|
|
|
@ -65,7 +65,7 @@ imgproc_mgr::~imgproc_mgr()
|
|||
opts_->release();
|
||||
}
|
||||
|
||||
std::vector<imgproc_mgr::DECDAT> imgproc_mgr::decode_before_simple(uint8_t* data, size_t bytes, HGIMGINFO* info)
|
||||
std::vector<imgproc_mgr::DECDAT> imgproc_mgr::decode_before_simple(uint8_t* data, size_t bytes, PACKIMAGE* info)
|
||||
{
|
||||
std::vector<DECDAT> simple;
|
||||
DECDAT in;
|
||||
|
@ -78,7 +78,7 @@ std::vector<imgproc_mgr::DECDAT> imgproc_mgr::decode_before_simple(uint8_t* data
|
|||
|
||||
return std::move(simple);
|
||||
}
|
||||
std::vector<imgproc_mgr::DECDAT> imgproc_mgr::decode_before_g200dsp(uint8_t* data, size_t bytes, HGIMGINFO* info)
|
||||
std::vector<imgproc_mgr::DECDAT> imgproc_mgr::decode_before_g200dsp(uint8_t* data, size_t bytes, PACKIMAGE* info)
|
||||
{
|
||||
// pid == 0x100 || pid == 0x200
|
||||
std::vector<DECDAT> g200dsp;
|
||||
|
@ -86,11 +86,11 @@ std::vector<imgproc_mgr::DECDAT> imgproc_mgr::decode_before_g200dsp(uint8_t* dat
|
|||
int line = 1024, off_f = 0, off_b = 0;
|
||||
|
||||
f.info = *info;
|
||||
f.info.paper_side = PAPER_SIDE_FRONT;
|
||||
f.info.pos.paper_side = PAPER_SIDE_FRONT;
|
||||
f.img.reset(new std::vector<char>(bytes));
|
||||
|
||||
b.info = *info;
|
||||
b.info.paper_side = PAPER_SIDE_BACK;
|
||||
b.info.pos.paper_side = PAPER_SIDE_BACK;
|
||||
b.img.reset(new std::vector<char>(bytes));
|
||||
|
||||
for (int i = 0; i < bytes / line; ++i)
|
||||
|
@ -128,16 +128,16 @@ void imgproc_mgr::dump_real(const std::vector<PROCIMGINFO>& img, const char* aft
|
|||
char name[128] = { 0 };
|
||||
int ind = 0;
|
||||
|
||||
sprintf(name, "%04x-%d-%d-%04x-%s", v.info.paper_ind, v.info.paper_side, v.info.split_ind, pos, after);
|
||||
sprintf(name, "%04x-%d-%d-%04x-%s", v.info.pos.paper_ind, v.info.pos.paper_side, v.info.pos.split_ind, pos, after);
|
||||
while(std::find(existing.begin(), existing.end(), name) != existing.end())
|
||||
sprintf(name, "%04x-%d-%d-%04x-%s(%d)", v.info.paper_ind, v.info.paper_side, v.info.split_ind, pos, after, ++ind);
|
||||
sprintf(name, "%04x-%d-%d-%04x-%s(%d)", v.info.pos.paper_ind, v.info.pos.paper_side, v.info.pos.split_ind, pos, after, ++ind);
|
||||
existing.push_back(name);
|
||||
cv::imwrite((root + name + ".jpg").c_str(), v.img);
|
||||
}
|
||||
}
|
||||
void imgproc_mgr::dump_empty(const std::vector<PROCIMGINFO>& img, const char* after, int pos)
|
||||
{}
|
||||
std::string imgproc_mgr::dump_usb_img_real(uint8_t* data, size_t bytes, HGIMGINFO* info, const char* tail)
|
||||
std::string imgproc_mgr::dump_usb_img_real(uint8_t* data, size_t bytes, PACKIMAGE* info, const char* tail)
|
||||
{
|
||||
std::string root(dump_path_ + PATH_SEPARATOR);
|
||||
char name[128] = { 0 };
|
||||
|
@ -150,7 +150,7 @@ std::string imgproc_mgr::dump_usb_img_real(uint8_t* data, size_t bytes, HGIMGINF
|
|||
else
|
||||
tail = "";
|
||||
|
||||
sprintf(name, "%04x-usb%s%s", info->paper_ind, tail_leader, tail);
|
||||
sprintf(name, "%04x-usb%s%s", info->pos.paper_ind, tail_leader, tail);
|
||||
|
||||
{
|
||||
// check repeat ...
|
||||
|
@ -158,7 +158,7 @@ std::string imgproc_mgr::dump_usb_img_real(uint8_t* data, size_t bytes, HGIMGINF
|
|||
while (dst)
|
||||
{
|
||||
fclose(dst);
|
||||
sprintf(name, "%04x-usb%s%s(%d)", info->paper_ind, tail_leader, tail, ++ind);
|
||||
sprintf(name, "%04x-usb%s%s(%d)", info->pos.paper_ind, tail_leader, tail, ++ind);
|
||||
dst = fopen((root + name + ".jpg").c_str(), "rb");
|
||||
}
|
||||
}
|
||||
|
@ -177,13 +177,13 @@ std::string imgproc_mgr::dump_usb_img_real(uint8_t* data, size_t bytes, HGIMGINF
|
|||
|
||||
return std::move(root + name + ".jpg");
|
||||
}
|
||||
std::string imgproc_mgr::dump_usb_img_empty(uint8_t* data, size_t bytes, HGIMGINFO* info, const char* tail)
|
||||
std::string imgproc_mgr::dump_usb_img_empty(uint8_t* data, size_t bytes, PACKIMAGE* info, const char* tail)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
int imgproc_mgr::decode(HGIMGINFO* info, uint8_t* data, size_t bytes, std::vector<PROCIMGINFO>& result)
|
||||
int imgproc_mgr::decode(PACKIMAGE* info, uint8_t* data, size_t bytes, std::vector<PROCIMGINFO>& result)
|
||||
{
|
||||
std::vector<DECDAT> tmp(info->paper_side == PAPER_SIDE_DSP ? imgproc_mgr::decode_before_g200dsp(data, bytes, info) : imgproc_mgr::decode_before_simple(data, bytes, info));
|
||||
std::vector<DECDAT> tmp(info->pos.paper_side == PAPER_SIDE_DSP ? imgproc_mgr::decode_before_g200dsp(data, bytes, info) : imgproc_mgr::decode_before_simple(data, bytes, info));
|
||||
int ret = SCANNER_ERR_OK;
|
||||
|
||||
(this->*dumpusbf_)(data, bytes, info, nullptr);
|
||||
|
@ -207,12 +207,12 @@ int imgproc_mgr::decode(HGIMGINFO* info, uint8_t* data, size_t bytes, std::vecto
|
|||
}
|
||||
else
|
||||
{
|
||||
if (info->paper_side == PAPER_SIDE_LEFT || info->paper_side == PAPER_SIDE_RIGHT)
|
||||
if (info->pos.paper_side == PAPER_SIDE_LEFT || info->pos.paper_side == PAPER_SIDE_RIGHT)
|
||||
{
|
||||
PROCIMGINFO front(pii);
|
||||
|
||||
front.info.paper_side = PAPER_SIDE_FRONT;
|
||||
if (info->paper_side == PAPER_SIDE_LEFT)
|
||||
front.info.pos.paper_side = PAPER_SIDE_FRONT;
|
||||
if (info->pos.paper_side == PAPER_SIDE_LEFT)
|
||||
{
|
||||
front.img = pii.img(cv::Rect(0, 0, pii.img.cols / 2, pii.img.rows));
|
||||
pii.img = pii.img(cv::Rect(pii.img.cols / 2, 0, pii.img.cols / 2, pii.img.rows));
|
||||
|
@ -223,14 +223,14 @@ int imgproc_mgr::decode(HGIMGINFO* info, uint8_t* data, size_t bytes, std::vecto
|
|||
pii.img = pii.img(cv::Rect(0, 0, pii.img.cols / 2, pii.img.rows));
|
||||
}
|
||||
result.push_back(front);
|
||||
pii.info.paper_side = PAPER_SIDE_BACK;
|
||||
pii.info.pos.paper_side = PAPER_SIDE_BACK;
|
||||
}
|
||||
else if (info->paper_side == PAPER_SIDE_TOP || info->paper_side == PAPER_SIDE_BOTTOM)
|
||||
else if (info->pos.paper_side == PAPER_SIDE_TOP || info->pos.paper_side == PAPER_SIDE_BOTTOM)
|
||||
{
|
||||
PROCIMGINFO front(pii);
|
||||
|
||||
front.info.paper_side = PAPER_SIDE_FRONT;
|
||||
if (info->paper_side == PAPER_SIDE_TOP)
|
||||
front.info.pos.paper_side = PAPER_SIDE_FRONT;
|
||||
if (info->pos.paper_side == PAPER_SIDE_TOP)
|
||||
{
|
||||
front.img = pii.img(cv::Rect(0, 0, pii.img.cols, pii.img.rows / 2));
|
||||
pii.img = pii.img(cv::Rect(0, pii.img.rows / 2, pii.img.cols, pii.img.rows / 2));
|
||||
|
@ -241,7 +241,7 @@ int imgproc_mgr::decode(HGIMGINFO* info, uint8_t* data, size_t bytes, std::vecto
|
|||
pii.img = pii.img(cv::Rect(0, 0, pii.img.cols, pii.img.rows / 2));
|
||||
}
|
||||
result.push_back(front);
|
||||
pii.info.paper_side = PAPER_SIDE_BACK;
|
||||
pii.info.pos.paper_side = PAPER_SIDE_BACK;
|
||||
}
|
||||
|
||||
result.push_back(pii);
|
||||
|
@ -249,18 +249,18 @@ int imgproc_mgr::decode(HGIMGINFO* info, uint8_t* data, size_t bytes, std::vecto
|
|||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
utils::to_log(LOG_LEVEL_FATAL, "FATAL: exception occurs when decode image %d-%d failed with reason '%s'!\n", info->paper_ind, pii.info.paper_side, e.what());
|
||||
utils::to_log(LOG_LEVEL_FATAL, "FATAL: exception occurs when decode image %d-%d failed with reason '%s'!\n", info->pos.paper_ind, pii.info.pos.paper_side, e.what());
|
||||
std::string f(dump_usb_img_real((uint8_t*)&(*v.img)[0], v.img->size(), info, "decode"));
|
||||
utils::to_log(LOG_LEVEL_WARNING, "FATAL: decode image %d-%d failed, source content save to file '%s'\n", info->paper_ind, pii.info.paper_side, f.c_str());
|
||||
utils::to_log(LOG_LEVEL_WARNING, "FATAL: decode image %d-%d failed, source content save to file '%s'\n", info->pos.paper_ind, pii.info.pos.paper_side, f.c_str());
|
||||
//throw(e); // continue the error handling
|
||||
ret = SCANNER_ERR_THROW_EXCEPTION;
|
||||
break; // fatal occurs, stop
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
utils::to_log(LOG_LEVEL_FATAL, "FATAL: exception occurs when decode image %d-%d failed\n", info->paper_ind, pii.info.paper_side);
|
||||
utils::to_log(LOG_LEVEL_FATAL, "FATAL: exception occurs when decode image %d-%d failed\n", info->pos.paper_ind, pii.info.pos.paper_side);
|
||||
std::string f(dump_usb_img_real((uint8_t*)&(*v.img)[0], v.img->size(), info, "decode"));
|
||||
utils::to_log(LOG_LEVEL_WARNING, "FATAL: decode image %d-%d failed, source content save to file '%s'\n", info->paper_ind, pii.info.paper_side, f.c_str());
|
||||
utils::to_log(LOG_LEVEL_WARNING, "FATAL: decode image %d-%d failed, source content save to file '%s'\n", info->pos.paper_ind, pii.info.pos.paper_side, f.c_str());
|
||||
ret = SCANNER_ERR_THROW_EXCEPTION;
|
||||
break; // fatal occurs, stop
|
||||
}
|
||||
|
@ -331,7 +331,7 @@ int imgproc_mgr::clear(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int imgproc_mgr::process(HGIMGINFO* info, uint8_t* data, size_t bytes, std::vector<PROCIMGINFO>& out)
|
||||
int imgproc_mgr::process(PACKIMAGE* info, uint8_t* data, size_t bytes, std::vector<PROCIMGINFO>& out)
|
||||
{
|
||||
std::vector<PROCIMGINFO> mid[2], in, *src = &in, * dst = &mid[0];
|
||||
int ret = decode(info, data, bytes, in), sn = 0;
|
||||
|
@ -361,9 +361,9 @@ int imgproc_mgr::process(HGIMGINFO* info, uint8_t* data, size_t bytes, std::vect
|
|||
catch (const std::exception& e)
|
||||
{
|
||||
ret = SCANNER_ERR_THROW_EXCEPTION;
|
||||
utils::to_log(LOG_LEVEL_DEBUG, "FATAL: image %d process '%s' throws exception: %s!\n", info->paper_ind, v->from(), e.what());
|
||||
utils::to_log(LOG_LEVEL_DEBUG, "FATAL: image %d process '%s' throws exception: %s!\n", info->pos.paper_ind, v->from(), e.what());
|
||||
std::string f(dump_usb_img_real(data, bytes, info, v->from()));
|
||||
utils::to_log(LOG_LEVEL_WARNING, "FATAL: process image %d failed on '%s', source content save to file '%s'\n", info->paper_ind, v->from(), f.c_str());
|
||||
utils::to_log(LOG_LEVEL_WARNING, "FATAL: process image %d failed on '%s', source content save to file '%s'\n", info->pos.paper_ind, v->from(), f.c_str());
|
||||
break;
|
||||
}
|
||||
catch (...)
|
||||
|
@ -371,7 +371,7 @@ int imgproc_mgr::process(HGIMGINFO* info, uint8_t* data, size_t bytes, std::vect
|
|||
ret = SCANNER_ERR_THROW_EXCEPTION;
|
||||
utils::to_log(LOG_LEVEL_DEBUG, "FATAL: image process '%s' throws unknown exception!\n", v->from());
|
||||
std::string f(dump_usb_img_real(data, bytes, info, v->from()));
|
||||
utils::to_log(LOG_LEVEL_WARNING, "FATAL: process image %d failed on '%s', source content save to file '%s'\n", info->paper_ind, v->from(), f.c_str());
|
||||
utils::to_log(LOG_LEVEL_WARNING, "FATAL: process image %d failed on '%s', source content save to file '%s'\n", info->pos.paper_ind, v->from(), f.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "img_processor.h"
|
||||
#include <base/utils.h> // for refer
|
||||
#include <base/packet.h>
|
||||
#include <vector>
|
||||
|
||||
typedef std::shared_ptr<std::vector<char>> dcptr;
|
||||
|
@ -19,7 +20,7 @@ class imgproc_mgr : public sane_opt_provider
|
|||
{
|
||||
typedef struct _decode_data
|
||||
{
|
||||
HGIMGINFO info;
|
||||
PACKIMAGE info;
|
||||
dcptr img;
|
||||
}DECDAT;
|
||||
|
||||
|
@ -31,21 +32,21 @@ class imgproc_mgr : public sane_opt_provider
|
|||
device_option* opts_;
|
||||
|
||||
void(imgproc_mgr::* dumpf_)(const std::vector<PROCIMGINFO>& img, const char* after, int pos) = nullptr;
|
||||
std::string(imgproc_mgr::* dumpusbf_)(uint8_t* data, size_t bytes, HGIMGINFO* info, const char* tail) = nullptr;
|
||||
std::string(imgproc_mgr::* dumpusbf_)(uint8_t* data, size_t bytes, PACKIMAGE* info, const char* tail) = nullptr;
|
||||
|
||||
static bool sort_processor_by_pos(image_processor* l, image_processor* r);
|
||||
|
||||
void dump_real(const std::vector<PROCIMGINFO>& img, const char* after, int pos);
|
||||
void dump_empty(const std::vector<PROCIMGINFO>& img, const char* after, int pos);
|
||||
std::string dump_usb_img_real(uint8_t* data, size_t bytes, HGIMGINFO* info, const char* tail);
|
||||
std::string dump_usb_img_empty(uint8_t* data, size_t bytes, HGIMGINFO* info, const char* tail);
|
||||
int decode(HGIMGINFO* info, uint8_t* data, size_t bytes, std::vector<PROCIMGINFO>& result);
|
||||
std::string dump_usb_img_real(uint8_t* data, size_t bytes, PACKIMAGE* info, const char* tail);
|
||||
std::string dump_usb_img_empty(uint8_t* data, size_t bytes, PACKIMAGE* info, const char* tail);
|
||||
int decode(PACKIMAGE* info, uint8_t* data, size_t bytes, std::vector<PROCIMGINFO>& result);
|
||||
|
||||
public:
|
||||
imgproc_mgr(device_option* devopts, bool dumpimg, const char* dumpath);
|
||||
|
||||
static std::vector<DECDAT> decode_before_simple(uint8_t* data, size_t bytes, HGIMGINFO* info);
|
||||
static std::vector<DECDAT> decode_before_g200dsp(uint8_t* data, size_t bytes, HGIMGINFO* info);
|
||||
static std::vector<DECDAT> decode_before_simple(uint8_t* data, size_t bytes, PACKIMAGE* info);
|
||||
static std::vector<DECDAT> decode_before_g200dsp(uint8_t* data, size_t bytes, PACKIMAGE* info);
|
||||
|
||||
protected:
|
||||
virtual ~imgproc_mgr();
|
||||
|
@ -56,7 +57,7 @@ public:
|
|||
public:
|
||||
int load_processor(const char* path); // outer-modules path
|
||||
int clear(void);
|
||||
int process(HGIMGINFO* info, uint8_t* data, size_t bytes, std::vector<PROCIMGINFO>& out);
|
||||
int process(PACKIMAGE* info, uint8_t* data, size_t bytes, std::vector<PROCIMGINFO>& out);
|
||||
};
|
||||
|
||||
//{
|
||||
|
|
Loading…
Reference in New Issue