add image processing finished notification

This commit is contained in:
gb 2023-05-09 18:03:33 +08:00
parent 11a3b02543
commit 4d4a690f71
14 changed files with 176 additions and 43 deletions

View File

@ -36,7 +36,7 @@ ImageUsbHandler::~ImageUsbHandler()
static int num = 0; static int num = 0;
void ImageUsbHandler::add_image(void *data, int width, int height, int type, int scannnum,unsigned int fpgaversion) void ImageUsbHandler::add_image(void *data, int width, int height, int type, int scannnum,unsigned int fpgaversion)
{ {
printf("ImageUsbHandler::add_image(%d * %d), fpgaversion = %d, HRatio = %f, VRatio = %f\n", width, height, fpgaversion, H_ratio, V_ratio); printf("ImageUsbHandler::add_image %d(%d * %d), fpgaversion = %d, HRatio = %f, VRatio = %f\n", scannnum, width, height, fpgaversion, H_ratio, V_ratio);
if(images->push_raw(data, width, height, type == CV_8UC1 ? COLOR_CHANNEL_GRAY : COLOR_CHANNEL_RGB, scannnum, fpgaversion, 0)) if(images->push_raw(data, width, height, type == CV_8UC1 ? COLOR_CHANNEL_GRAY : COLOR_CHANNEL_RGB, scannnum, fpgaversion, 0))
{ {
@ -293,6 +293,8 @@ void ImageUsbHandler::Set_ratio(u32 h_ratio,u32 v_ratio)
bool ImageUsbHandler::done() bool ImageUsbHandler::done()
{ {
return images->is_image_processing_over();
std::lock_guard<std::mutex> guard(mtx); std::lock_guard<std::mutex> guard(mtx);
if(results.size() >= 1){ if(results.size() >= 1){
auto &fu_run = results.back(); auto &fu_run = results.back();

View File

@ -138,6 +138,12 @@ bool ScannerRegAccess::write(unsigned int addr, const unsigned int val)
return true; return true;
} }
else if(addr == (unsigned int)-5)
{
usbimages->set_image_processing(val);
return true;
}
else if((addr & (~0x0ff)) == SR_CAPTURE_SET) else if((addr & (~0x0ff)) == SR_CAPTURE_SET)
{ {
std::shared_ptr<ICapturer> capturer = scanner->get_capture(); std::shared_ptr<ICapturer> capturer = scanner->get_capture();
@ -1079,6 +1085,11 @@ void ScannerRegAccess::set_image_callback(void(*cb)(MemoryPtr, bool, void*), voi
if(usbimages) if(usbimages)
usbimages->set_image_keeper(cb, para); usbimages->set_image_keeper(cb, para);
} }
void ScannerRegAccess::set_image_process_over(bool over)
{
if(usbimages)
usbimages->set_image_processing(over);
}
void ScannerRegAccess::setcameraparmSp(int speedmode){ void ScannerRegAccess::setcameraparmSp(int speedmode){
if(cameraparmSp.find(SpeedMode(speedmode)) == cameraparmSp.end()) if(cameraparmSp.find(SpeedMode(speedmode)) == cameraparmSp.end())

View File

@ -23,6 +23,7 @@ public:
void write_info(std::string info); void write_info(std::string info);
void set_image_callback(void(*cb)(MemoryPtr, bool, void*), void* para); void set_image_callback(void(*cb)(MemoryPtr, bool, void*), void* para);
void set_image_process_over(bool over = true);
private: private:
void setcameraparmSp(int speedmode); void setcameraparmSp(int speedmode);

View File

@ -34,6 +34,7 @@ public:
int set_paper_type(int type); int set_paper_type(int type);
int set_pixel_type(int *type); int set_pixel_type(int *type);
int set_capturer_parameter(int type, int ind, int val); int set_capturer_parameter(int type, int ind, int val);
int set_image_processing_finished(bool finished);
#endif #endif
public: public:

View File

@ -345,7 +345,7 @@ void image_capture::refresh_paper_size(int from)
child->release(); child->release();
} }
if(from != CHG_PAPER_SIZE_FROM_DPI) // if(from != CHG_PAPER_SIZE_FROM_DPI)
change_custom_area_range(w, h); change_custom_area_range(w, h);
} }
void image_capture::change_custom_area_range(double mm_w, double mm_h) void image_capture::change_custom_area_range(double mm_w, double mm_h)

View File

@ -7,13 +7,14 @@
// configuration text // configuration text
// //
static std::string g_cis_cfg("{\"montage\":{\"cat\":\"cis\",\"group\":\"CIS\",\"title\":\"\\u56fe\\u50cf\\u62fc\\u63a5\",\"desc\":\"\\u5c06CIS\\u91c7\\u96c6\\u7684\\u539f\\u59cb\\u6570\\u636e\\u6062\\u590d\\u4e3a\\u6b63\\u5e38\\u7684\\u56fe\\u50cf\",\"ver\":1,\"pos\":10,\"type\":\"bool\",\"unit\":\"none\",\"affect\":0,\"readonly\":false,\"visible\":false,\"enabled\":true,\"size\":4,\"cur\":true,\"default\":true},\"reinstate\":{\"cat\":\"CIS\",\"group\":\"CIS\",\"title\":\"\\u786c\\u4ef6\\u590d\\u539f\",\"desc\":\"\\u6d88\\u9664CIS\\u786c\\u4ef6\\u62c9\\u4f38\\u56e0\\u7d20\\uff0c\\u6062\\u590d\\u56fe\\u7247\\u521d\\u59cb\\u72b6\\u6001\",\"ver\":1,\"pos\":20,\"type\":\"bool\",\"unit\":\"none\",\"affect\":0,\"readonly\":false,\"visible\":false,\"enabled\":true,\"size\":4,\"cur\":true,\"default\":true},\"fb-split\":{\"cat\":\"CIS\",\"group\":\"CIS\",\"title\":\"\\u62c6\\u5206\\u6b63\\u53cd\\u9762\",\"desc\":\"\\u5c06\\u6b63\\u53cd\\u9762\\u5408\\u6210\\u7684\\u4e00\\u5f20\\u56fe\\u7247\\u62c6\\u5206\\u6210\\u6b63\\u9762\\u548c\\u53cd\\u9762\\u56fe\\u7247\",\"ver\":1,\"pos\":30,\"type\":\"bool\",\"unit\":\"none\",\"affect\":2,\"readonly\":false,\"visible\":false,\"enabled\":true,\"size\":4,\"cur\":true,\"default\":true},\"page\":{\"cat\":\"CIS\",\"group\":\"base\",\"title\":\"\\u9875\\u9762\",\"desc\":\"\\u83b7\\u53d6\\u7eb8\\u5f20\\u6307\\u5b9a\\u9762\\u7684\\u56fe\\u7247\",\"ver\":1,\"pos\":40,\"type\":\"string\",\"unit\":\"none\",\"affect\":2,\"readonly\":false,\"visible\":true,\"enabled\":true,\"size\":30,\"cur\":\"\\u53cc\\u9762\",\"default\":\"\\u53cc\\u9762\",\"range\":[\"\\u6b63\\u9762\",\"\\u80cc\\u9762\",\"\\u53cc\\u9762\"],\"depend_or\":[\"fb-split==true\"]}}"); static std::string g_cis_cfg("{\"montage\":{\"cat\":\"cis\",\"group\":\"CIS\",\"title\":\"\\u56fe\\u50cf\\u62fc\\u63a5\",\"desc\":\"\\u5c06CIS\\u91c7\\u96c6\\u7684\\u539f\\u59cb\\u6570\\u636e\\u6062\\u590d\\u4e3a\\u6b63\\u5e38\\u7684\\u56fe\\u50cf\",\"ver\":1,\"pos\":10,\"type\":\"bool\",\"unit\":\"none\",\"affect\":0,\"readonly\":false,\"visible\":false,\"enabled\":true,\"size\":4,\"cur\":true,\"default\":true},\"cis-color-correct\":{\"cat\":\"CIS\",\"group\":\"CIS\",\"title\":\"\\u5149\\u5b66\\u989c\\u8272\\u6821\\u6b63\",\"desc\":\"\\u5bf9CIS\\u7684\\u539f\\u56fe\\u989c\\u8272\\u8fdb\\u884c\\u6821\\u6b63\",\"ver\":1,\"pos\":20,\"type\":\"bool\",\"unit\":\"none\",\"affect\":0,\"readonly\":false,\"visible\":false,\"enabled\":true,\"size\":4,\"cur\":true,\"default\":true},\"reinstate\":{\"cat\":\"CIS\",\"group\":\"CIS\",\"title\":\"\\u786c\\u4ef6\\u590d\\u539f\",\"desc\":\"\\u6d88\\u9664CIS\\u786c\\u4ef6\\u62c9\\u4f38\\u56e0\\u7d20\\uff0c\\u6062\\u590d\\u56fe\\u7247\\u521d\\u59cb\\u72b6\\u6001\",\"ver\":1,\"pos\":30,\"type\":\"bool\",\"unit\":\"none\",\"affect\":0,\"readonly\":false,\"visible\":false,\"enabled\":true,\"size\":4,\"cur\":true,\"default\":true},\"fb-split\":{\"cat\":\"CIS\",\"group\":\"CIS\",\"title\":\"\\u62c6\\u5206\\u6b63\\u53cd\\u9762\",\"desc\":\"\\u5c06\\u6b63\\u53cd\\u9762\\u5408\\u6210\\u7684\\u4e00\\u5f20\\u56fe\\u7247\\u62c6\\u5206\\u6210\\u6b63\\u9762\\u548c\\u53cd\\u9762\\u56fe\\u7247\",\"ver\":1,\"pos\":40,\"type\":\"bool\",\"unit\":\"none\",\"affect\":2,\"readonly\":false,\"visible\":false,\"enabled\":true,\"size\":4,\"cur\":true,\"default\":true},\"page\":{\"cat\":\"CIS\",\"group\":\"base\",\"title\":\"\\u9875\\u9762\",\"desc\":\"\\u83b7\\u53d6\\u7eb8\\u5f20\\u6307\\u5b9a\\u9762\\u7684\\u56fe\\u7247\",\"ver\":1,\"pos\":50,\"type\":\"string\",\"unit\":\"none\",\"affect\":2,\"readonly\":false,\"visible\":true,\"enabled\":true,\"size\":30,\"cur\":\"\\u53cc\\u9762\",\"default\":\"\\u53cc\\u9762\",\"range\":[\"\\u6b63\\u9762\",\"\\u80cc\\u9762\",\"\\u53cc\\u9762\"],\"depend_or\":[\"fb-split==true\"]},\"is-exchange\":{\"cat\":\"CIS\",\"group\":\"base\",\"title\":\"\\u4ea4\\u6362\\u6b63\\u53cd\\u9762\",\"desc\":\"\\u4ea4\\u6362\\u6bcf\\u5f20\\u6587\\u7a3f\\u7684\\u6b63\\u53cd\\u9762\\u51fa\\u56fe\\u987a\\u5e8f\",\"ver\":1,\"pos\":60,\"type\":\"bool\",\"unit\":\"none\",\"affect\":0,\"readonly\":false,\"visible\":true,\"enabled\":true,\"size\":4,\"cur\":false,\"default\":false,\"depend_and\":[\"fb-split==true\",\"page==\\u53cc\\u9762\"]}}");
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// class cis_pre_do // class cis_pre_do
#ifdef TEMPORARY_API #ifdef TEMPORARY_API
#include "../capimage/hgutils.h" #include "../capimage/hgutils.h"
#include "../capimage/correct_ultis.h"
img_one_paper* cis_montager(img_one_paper* in) img_one_paper* cis_montager(img_one_paper* in)
{ {
@ -28,7 +29,7 @@ img_one_paper* cis_montager(img_one_paper* in)
return in; return in;
} }
img_one_paper* cis_spliter(img_one_paper* in) img_one_paper* cis_spliter(img_one_paper* in, bool swap)
{ {
std::vector<PROCIMG> result; std::vector<PROCIMG> result;
@ -39,12 +40,13 @@ img_one_paper* cis_spliter(img_one_paper* in)
{ {
int actwidth = v.img.cols / 2; int actwidth = v.img.cols / 2;
int actheight = v.img.rows; int actheight = v.img.rows;
int off[] = {0, 1}; int off[] = {swap, !swap};
if(v.head.pos.paper_side == PAPER_SIDE_RIGHT) if(v.head.pos.paper_side == PAPER_SIDE_RIGHT)
{ {
off[0] = 1; int n = off[0];
off[1] = 0; off[0] = off[1];
off[1] = n;
} }
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
@ -66,12 +68,13 @@ img_one_paper* cis_spliter(img_one_paper* in)
{ {
int actwidth = v.img.cols; int actwidth = v.img.cols;
int actheight = v.img.rows / 2; int actheight = v.img.rows / 2;
int off[] = {0, 1}; int off[] = {swap, !swap};
if(v.head.pos.paper_side == PAPER_SIDE_RIGHT) if(v.head.pos.paper_side == PAPER_SIDE_RIGHT)
{ {
off[0] = 1; int n = off[0];
off[1] = 0; off[0] = off[1];
off[1] = n;
} }
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
@ -100,9 +103,10 @@ img_one_paper* cis_spliter(img_one_paper* in)
#endif #endif
cis_pre_do::cis_pre_do(std::function<img_one_paper* (img_one_paper*)> montage cis_pre_do::cis_pre_do(std::function<img_one_paper* (img_one_paper*)> montage
, std::function< img_one_paper* (img_one_paper*)> split) , std::function<SPLIT_PROTO> split)
: montage_(montage), split_(split) : montage_(montage), split_(split)
, cfg_(g_cis_cfg), is_montage_(true), is_split_(true), page_(PAGE_DUPLEX), cis_dpi_(200), reinstate_(true) , cfg_(g_cis_cfg), is_montage_(true), is_split_(true), page_(PAGE_DUPLEX), cis_dpi_(200)
, reinstate_(true), photo_mode_(false), is_correct_(true), is_exchg_(false)
{ {
if (!montage_) if (!montage_)
montage_ = cis_montager; montage_ = cis_montager;
@ -143,6 +147,12 @@ void cis_pre_do::init_value(void)
is_montage_ = true; is_montage_ = true;
child->release(); child->release();
} }
if (jsn->get_value("cis-color-correct", child) && child)
{
if (!child->get_value("cur", is_correct_))
is_correct_ = true;
child->release();
}
if (jsn->get_value("reinstate", child) && child) if (jsn->get_value("reinstate", child) && child)
{ {
if (!child->get_value("cur", reinstate_)) if (!child->get_value("cur", reinstate_))
@ -170,6 +180,12 @@ void cis_pre_do::init_value(void)
printf("current page: %d(%s)\n", page_, val.c_str()); printf("current page: %d(%s)\n", page_, val.c_str());
child->release(); child->release();
} }
if (jsn->get_value("is-exchange", child) && child)
{
if (!child->get_value("cur", is_exchg_))
is_exchg_ = false;
child->release();
}
jsn->release(); jsn->release();
} }
} }
@ -187,7 +203,7 @@ void cis_pre_do::resize(cv::Mat& img, float ratio_h, float ratio_v)
} }
else else
{ {
cv::resize(img, img, cv::Size(0, 0), ratio_h, 1.432323f * ratio_v); cv::resize(img, img, cv::Size(0, 0), ratio_h, 1.43434f * ratio_v);
} }
} }
@ -236,9 +252,16 @@ bool cis_pre_do::update_enabled(const char* name, std::function<GET_SANE_OPT_PRO
gb_json* root = new gb_json(); gb_json* root = new gb_json();
std::string val(""); std::string val("");
if(strcmp(name, "cis-dpi") == 0 || strcmp(name, "resolution") == 0)
{
if(get_opt("cis-dpi", "cur", val, nullptr) == 0) if(get_opt("cis-dpi", "cur", val, nullptr) == 0)
cis_dpi_ = *(int*)val.c_str(); cis_dpi_ = *(int*)val.c_str();
printf("cis-dpi = %d\n", cis_dpi_); }
if(strcmp(name, "photo-mode") == 0)
{
if(get_opt(name, "cur", val, nullptr) == 0)
photo_mode_ = *(bool*)val.c_str();
}
if(root->attach_text(&cfg_[0])) if(root->attach_text(&cfg_[0]))
{ {
@ -286,6 +309,14 @@ img_one_paper* cis_pre_do::execute(img_one_paper* img)
img = mont; img = mont;
} }
if(is_correct_)
{
for(auto& v: img->images_queue())
{
correctColor(v.img, v.head.resolution_x, v.img.channels() == 3 ? 1 : 0, !photo_mode_);
}
}
if(reinstate_) if(reinstate_)
{ {
for(auto& v: img->images_queue()) for(auto& v: img->images_queue())
@ -298,7 +329,7 @@ img_one_paper* cis_pre_do::execute(img_one_paper* img)
if(is_split_) if(is_split_)
{ {
img_one_paper* sp = split_(img); img_one_paper* sp = split_(img, is_exchg_);
img->release(); img->release();
img = sp; img = sp;

View File

@ -28,13 +28,30 @@ class gb_json;
// "cur": true, // "cur": true,
// "default": true // "default": true
// }, // },
// "cis-color-correct": {
// "cat": "CIS",
// "group": "CIS",
// "title": "光学颜色校正",
// "desc": "对CIS的原图颜色进行校正",
// "ver": 1,
// "pos": 20,
// "type": "bool",
// "unit": "none",
// "affect": 0,
// "readonly": false,
// "visible": false,
// "enabled": true,
// "size": 4,
// "cur": true,
// "default": true
// },
// "reinstate": { // "reinstate": {
// "cat": "CIS", // "cat": "CIS",
// "group": "CIS", // "group": "CIS",
// "title": "硬件复原", // "title": "硬件复原",
// "desc": "消除CIS硬件拉伸因素恢复图片初始状态", // "desc": "消除CIS硬件拉伸因素恢复图片初始状态",
// "ver": 1, // "ver": 1,
// "pos": 20, // "pos": 30,
// "type": "bool", // "type": "bool",
// "unit": "none", // "unit": "none",
// "affect": 0, // "affect": 0,
@ -51,7 +68,7 @@ class gb_json;
// "title": "拆分正反面", // "title": "拆分正反面",
// "desc": "将正反面合成的一张图片拆分成正面和反面图片", // "desc": "将正反面合成的一张图片拆分成正面和反面图片",
// "ver": 1, // "ver": 1,
// "pos": 30, // "pos": 40,
// "type": "bool", // "type": "bool",
// "unit": "none", // "unit": "none",
// "affect": 2, // "affect": 2,
@ -68,7 +85,7 @@ class gb_json;
// "title": "页面", // "title": "页面",
// "desc": "获取纸张指定面的图片", // "desc": "获取纸张指定面的图片",
// "ver": 1, // "ver": 1,
// "pos": 40, // "pos": 50,
// "type": "string", // "type": "string",
// "unit": "none", // "unit": "none",
// "affect": 2, // "affect": 2,
@ -80,15 +97,38 @@ class gb_json;
// "default": "双面", // "default": "双面",
// "range": ["正面", "背面", "双面"], // "range": ["正面", "背面", "双面"],
// "depend_or": ["fb-split==true"] // "depend_or": ["fb-split==true"]
// },
// "is-exchange": {
// "cat": "CIS",
// "group": "base",
// "title": "交换正反面",
// "desc": "交换每张文稿的正反面出图顺序",
// "ver": 1,
// "pos": 60,
// "type": "bool",
// "unit": "none",
// "affect": 0,
// "readonly": false,
// "visible": true,
// "enabled": true,
// "size": 4,
// "cur": false,
// "default": false,
// "depend_and": ["fb-split==true", "page==双面"]
// } // }
// } // }
#define SPLIT_PROTO img_one_paper*(img_one_paper*, bool)
class cis_pre_do : public sane_cfg_provider class cis_pre_do : public sane_cfg_provider
{ {
std::string cfg_; std::string cfg_;
bool is_montage_; bool is_montage_;
bool is_split_; bool is_split_;
bool reinstate_; bool reinstate_;
bool photo_mode_;
bool is_correct_;
bool is_exchg_;
enum enum
{ {
@ -100,7 +140,7 @@ class cis_pre_do : public sane_cfg_provider
int cis_dpi_; int cis_dpi_;
std::function<img_one_paper* (img_one_paper*)> montage_; std::function<img_one_paper* (img_one_paper*)> montage_;
std::function<img_one_paper* (img_one_paper*)> split_; std::function<SPLIT_PROTO> split_;
gb_json* from_json_text(char* jsn_text = nullptr); gb_json* from_json_text(char* jsn_text = nullptr);
void init_value(void); void init_value(void);
@ -108,7 +148,7 @@ class cis_pre_do : public sane_cfg_provider
public: public:
cis_pre_do(std::function<img_one_paper*(img_one_paper*)> montage = std::function<img_one_paper* (img_one_paper*)>() cis_pre_do(std::function<img_one_paper*(img_one_paper*)> montage = std::function<img_one_paper* (img_one_paper*)>()
, std::function<img_one_paper*(img_one_paper*)> split = std::function<img_one_paper* (img_one_paper*)>()); , std::function<SPLIT_PROTO> split = std::function<SPLIT_PROTO>());
protected: protected:
~cis_pre_do(); ~cis_pre_do();

View File

@ -3,6 +3,7 @@
#include <string.h> #include <string.h>
#include "common/json/gb_json.h" #include "common/json/gb_json.h"
#include "img_process/algs/img_algorithm.h" #include "img_process/algs/img_algorithm.h"
#include "common/log_util.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -11,6 +12,9 @@
#ifdef TEMPORARY_API
extern int32_t (*set_image_process_over)(bool);
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// class img_processor // class img_processor
@ -182,12 +186,6 @@ void img_processor::worker_thread(bool first)
{ {
while(run_) while(run_)
{ {
if(!first && !speed_first_)
{
std::this_thread::sleep_for(std::chrono::milliseconds(500));
continue;
}
img_one_paper* img = nullptr; img_one_paper* img = nullptr;
if(img_que_.take(img, true)) if(img_que_.take(img, true))
{ {
@ -205,8 +203,24 @@ void img_processor::worker_thread(bool first)
std::this_thread::sleep_for(std::chrono::microseconds(50)); std::this_thread::sleep_for(std::chrono::microseconds(50));
img_sender_(nullptr, nullptr, nullptr, scan_staus_); img_sender_(nullptr, nullptr, nullptr, scan_staus_);
set_image_process_over(true);
for(auto& v: tids_)
img_que_.quit();
img_que_.quit();
} }
} }
else if(first)
{
for(auto& v: tids_)
worker_->thread_kill(v);
tids_.clear();
}
else
{
log_cls::log(LOG_LEVEL_ALL, "- Release image processing threads.\n");
break;
}
} }
} }
void img_processor::handle_image(img_one_paper* img) void img_processor::handle_image(img_one_paper* img)
@ -366,8 +380,11 @@ int32_t img_processor::push_image(img_one_paper* img, bool over)
size_t cnt = img_que_.save(img, true); size_t cnt = img_que_.save(img, true);
if(speed_first_ && cnt >= 4 && worker_->count() < 3) if(speed_first_ && cnt >= 6 && worker_->count() < 6)
worker_->thread_new(&img_processor::worker_thread, false); {
log_cls::log(LOG_LEVEL_ALL, "+ Add image processing threads ...\n");
tids_.push_back(worker_->thread_new(&img_processor::worker_thread, false));
}
} }
} }

View File

@ -34,6 +34,7 @@ class img_processor : public sane_cfg_provider
safe_fifo<img_one_paper*> img_que_; safe_fifo<img_one_paper*> img_que_;
thread_pool<img_processor>* worker_; thread_pool<img_processor>* worker_;
std::vector<uint32_t> tids_;
volatile bool speed_first_; volatile bool speed_first_;
volatile bool run_; volatile bool run_;
uint32_t scan_staus_; uint32_t scan_staus_;

View File

@ -31,7 +31,7 @@ image_packet::image_packet(LPPACKIMAGE head, MemoryPtr img, uint32_t scanid, uin
head_->set_len(sizeof(PACK_BASE) + sizeof(PACKIMAGE)); head_->set_len(sizeof(PACK_BASE) + sizeof(PACKIMAGE));
info_over_ = info_.empty(); info_over_ = info_.empty();
log_cls::log(LOG_LEVEL_ALL, "Image-%04u wait to be sent: size = %u\n", sn_, img->size() + info_.length()); // log_cls::log(LOG_LEVEL_ALL, "Image-%04u wait to be sent: size = %u\n", sn_, img->size() + info_.length());
} }
image_packet::~image_packet() image_packet::~image_packet()
{ {
@ -39,7 +39,7 @@ image_packet::~image_packet()
head_->release(); head_->release();
img_.reset(); img_.reset();
log_cls::log(LOG_LEVEL_ALL, "Image-%04u sending complete: %u/%u\n", sn_, offset_, size); // log_cls::log(LOG_LEVEL_ALL, "Image-%04u sending complete: %u/%u\n", sn_, offset_, size);
} }
bool image_packet::is_memory_block(void) bool image_packet::is_memory_block(void)

View File

@ -145,6 +145,12 @@ void async_scanner::push_image(int data_type, void* data, size_t w, size_t h, in
} }
} }
else if(data) else if(data)
{
if(paper_ind == (size_t)-1)
{
*(bool*)data = img_prc_->que_size() == 0;
}
else
{ {
img_one_paper *paper = new img_one_paper(); img_one_paper *paper = new img_one_paper();
@ -153,11 +159,12 @@ void async_scanner::push_image(int data_type, void* data, size_t w, size_t h, in
paper->release(); paper->release();
// paper count ... // paper count ...
dyn_mem_ptr reply = dyn_mem::memory(sizeof(PACK_BASE)); // dyn_mem_ptr reply = dyn_mem::memory(sizeof(PACK_BASE));
BASE_PACKET_REPLY(*((LPPACK_BASE)reply->ptr()), PACK_CMD_SCAN_PAPER_ROGER, scan_id_, paper_ind); // BASE_PACKET_REPLY(*((LPPACK_BASE)reply->ptr()), PACK_CMD_SCAN_PAPER_ROGER, scan_id_, paper_ind);
reply->set_len(sizeof(PACK_BASE)); // reply->set_len(sizeof(PACK_BASE));
usb_->write_bulk(reply); // usb_->write_bulk(reply);
reply->release(); // reply->release();
}
} }
} }

View File

@ -26,6 +26,7 @@ int32_t (*set_paper_type)(int) = nullptr;
int32_t (*set_pixel_type)(int*) = nullptr; int32_t (*set_pixel_type)(int*) = nullptr;
int32_t (*set_capturer_param)(int, int, int) = nullptr; int32_t (*set_capturer_param)(int, int, int) = nullptr;
int32_t (*set_image_receiver)(void(*rcv)(int data_type, void* data, size_t w, size_t h, int, int, size_t paper_ind, paper_side side, clr_channel clr, img_status status, bool img_new, bool img_over, float ratio_h, float ratio_v, void* param), void* param) = nullptr; int32_t (*set_image_receiver)(void(*rcv)(int data_type, void* data, size_t w, size_t h, int, int, size_t paper_ind, paper_side side, clr_channel clr, img_status status, bool img_new, bool img_over, float ratio_h, float ratio_v, void* param), void* param) = nullptr;
int32_t (*set_image_process_over)(bool) = nullptr;
#endif #endif
#else #else
#define LOG_LEVEL_ALL 0 #define LOG_LEVEL_ALL 0
@ -118,6 +119,10 @@ int32_t call_set_image_receiver(void(*rcv)(int data_type, void* data, size_t w,
{ {
return inst->set_img_receiver((void*)rcv, param); return inst->set_img_receiver((void*)rcv, param);
} }
int32_t call_set_image_process_over(bool over)
{
return inst->set_image_processing_finished(over);
}
#endif #endif
@ -397,6 +402,7 @@ UsbDevice::UsbDevice(std::function<bool(int, struct usb_ctrlrequest *, unsigned
::set_paper_type = call_set_paper_type; ::set_paper_type = call_set_paper_type;
::set_pixel_type = call_set_pixel_type; ::set_pixel_type = call_set_pixel_type;
::set_capturer_param = call_set_capturer_param; ::set_capturer_param = call_set_capturer_param;
::set_image_process_over = call_set_image_process_over;
thread_pool<UsbDevice> *t = new thread_pool<UsbDevice>(this); thread_pool<UsbDevice> *t = new thread_pool<UsbDevice>(this);
t->thread_new(&UsbDevice::do_system_command, R"(echo linaro | sudo -S sh -c "echo fe900000.dwc3 > /opt/cfg/usb_gadget/g1/UDC")"); t->thread_new(&UsbDevice::do_system_command, R"(echo linaro | sudo -S sh -c "echo fe900000.dwc3 > /opt/cfg/usb_gadget/g1/UDC")");
@ -1528,4 +1534,8 @@ int UsbDevice::set_capturer_parameter(int type, int ind, int val)
return ctrl_handler(-1, (usb_ctrlrequest*)ind, (unsigned char*)val) ? 0 : EBADF; return ctrl_handler(-1, (usb_ctrlrequest*)ind, (unsigned char*)val) ? 0 : EBADF;
} }
int UsbDevice::set_image_processing_finished(bool finished)
{
return ctrl_handler(-1, (usb_ctrlrequest*)-5, (unsigned char*)finished) ? 0 : EBADF;
}
#endif #endif

View File

@ -20,6 +20,7 @@ class UsbImageProcQueue
int dpi_y_; int dpi_y_;
float ratio_h_; float ratio_h_;
float ratio_v_; float ratio_v_;
bool imgp_over_;
int sensor_status_2_scanner_status(int ss) int sensor_status_2_scanner_status(int ss)
{ {
@ -107,7 +108,10 @@ public:
bool push_raw(void *data, int width, int height = 0, int type = 0, int scannnum = 0, unsigned int fpgaversion = 0, int status = 0) bool push_raw(void *data, int width, int height = 0, int type = 0, int scannnum = 0, unsigned int fpgaversion = 0, int status = 0)
{ {
if(scannnum == 1) if(scannnum == 1)
{
scan_status_ = 0; scan_status_ = 0;
imgp_over_ = false;
}
void (*push_image)(int data_type, void* data, size_t w, size_t h, int dpi_x, int dpi_y, size_t paper_ind, paper_side side, clr_channel clr, img_status status, bool img_new, bool img_over, float ratio_h, float ratio_v, void* param) = nullptr; void (*push_image)(int data_type, void* data, size_t w, size_t h, int dpi_x, int dpi_y, size_t paper_ind, paper_side side, clr_channel clr, img_status status, bool img_new, bool img_over, float ratio_h, float ratio_v, void* param) = nullptr;
@ -133,6 +137,14 @@ public:
dpi_x_ = x; dpi_x_ = x;
dpi_y_ = y; dpi_y_ = y;
} }
void set_image_processing(bool over)
{
imgp_over_ = over;
}
bool is_image_processing_over(void)
{
return imgp_over_;
}
MemoryPtr front() MemoryPtr front()
{ {