change scan-count to paper count; change STOPSCAN pushed position

This commit is contained in:
gb 2023-05-10 12:17:50 +08:00
parent 4d4a690f71
commit d56e482a7a
9 changed files with 47 additions and 26 deletions

View File

@ -71,6 +71,8 @@ MemoryPtr JpegImageEncode::encode(cv::Mat &image)
type = ".png"; type = ".png";
else if(fmt_ == "TIFF") else if(fmt_ == "TIFF")
type = ".tiff"; type = ".tiff";
else if(fmt_ == "BMP")
type = ".bmp";
else else
type = ".jpg"; type = ".jpg";

View File

@ -104,10 +104,10 @@ Scanner::Scanner(std::shared_ptr<ICapturer> capturer, std::shared_ptr<MotorBoard
auto mb_scandone_call = [&]() auto mb_scandone_call = [&]()
{ {
done_scan = 1; done_scan = 1;
if(mb_error_code == 0) // if(mb_error_code == 0)
mb_error_code = 0xffffffff; // mb_error_code = 0xffffffff;
printf("motorboard callback scan_done"); printf("motorboard callback scan_done");
imagehandler->add_scanevent({.From = STOPSCAN, .Code = mb_error_code}); // imagehandler->add_scanevent({.From = STOPSCAN, .Code = mb_error_code});
}; };
auto mb_osmode_call = [&](unsigned int osmode) auto mb_osmode_call = [&](unsigned int osmode)
@ -261,7 +261,7 @@ void Scanner::add_scansever(HGIntInfo event)
bool Scanner::set_hgimgconfig(GScanCap config) bool Scanner::set_hgimgconfig(GScanCap config)
{ {
printf("enter config set_hgimgconfig \n"); printf("enter config set_hgimgconfig \n");
scancount = config.is_duplex ? config.scannum / 2 : config.scannum; scancount = /*config.is_duplex ? config.scannum / 2 :*/ config.scannum;
m_cap = config; m_cap = config;
if (config.resolution_dst < 300) if (config.resolution_dst < 300)
m_config.g200params.dpi = 1; m_config.g200params.dpi = 1;
@ -574,6 +574,7 @@ void Scanner::runScan()
else else
autosizescan(); autosizescan();
savescannerinfo(scannerinfo); savescannerinfo(scannerinfo);
imagehandler->add_scanevent({.From = STOPSCAN, mb_error_code});
while (!imagehandler->done()) while (!imagehandler->done())
this_thread::sleep_for(chrono::milliseconds(10)); this_thread::sleep_for(chrono::milliseconds(10));
done_scan = 0; done_scan = 0;
@ -595,7 +596,7 @@ void Scanner::runScan()
if ((((mb_error_code != 0) && (mb_error_code != 0xffffffff)) || imagehandler->getimgstatus().status != NO_error) && m_config.g200params.is_autopaper) if ((((mb_error_code != 0) && (mb_error_code != 0xffffffff)) || imagehandler->getimgstatus().status != NO_error) && m_config.g200params.is_autopaper)
mb->set_auto_paper(false, false); mb->set_auto_paper(false, false);
mb->startcapimage(false); mb->startcapimage(false);
imagehandler->add_scanevent({.From = STOPSCAN, 0}); // imagehandler->add_scanevent({.From = STOPSCAN, 0});
ControlFeedMode(); ControlFeedMode();
printf("-------scanner done-------\n"); printf("-------scanner done-------\n");
} }

View File

@ -89,7 +89,9 @@ public:
if (wait && size() == 0) if (wait && size() == 0)
{ {
wait_->wait(); wait_->wait();
#if defined(WIN32) || defined(_WIN64)
wait_->reset(); wait_->reset();
#endif
} }
{ {

View File

@ -8,6 +8,8 @@
// #include <semaphore.h> // #include <semaphore.h>
#include <mutex> #include <mutex>
#include <vector> #include <vector>
#include <iosfwd>
#include <sstream>
#if defined(WIN32) || defined(_WIN64) #if defined(WIN32) || defined(_WIN64)
#define WAIT_INFINITE INFINITE #define WAIT_INFINITE INFINITE
@ -34,6 +36,7 @@ extern int gettimeofday(TIMEV* tv, struct timezone* tz);
#include <sys/time.h> #include <sys/time.h>
#include <memory> #include <memory>
#include <thread> #include <thread>
#include <pthread.h>
typedef struct timeval TIMEV; typedef struct timeval TIMEV;
#define WAIT_INFINITE 0 #define WAIT_INFINITE 0
#define FSEEK fseek #define FSEEK fseek
@ -110,7 +113,7 @@ class thread_pool : public refer
{ {
typedef struct _thrd typedef struct _thrd
{ {
uint32_t id; uint64_t id;
std::shared_ptr<std::thread> thread; std::shared_ptr<std::thread> thread;
}THRD; }THRD;
T* obj_; T* obj_;
@ -122,23 +125,33 @@ public:
thread_pool(T* obj) : obj_(obj), id_(1) thread_pool(T* obj) : obj_(obj), id_(1)
{} {}
static uint64_t thread_id(std::thread* thrd)
{
std::stringstream ss;
ss << thrd->get_id();
return std::stoull(ss.str());
}
protected: protected:
virtual ~thread_pool() virtual ~thread_pool()
{} {}
public: public:
template<typename ... Args> template<typename ... Args>
uint32_t thread_new(void(T::* thrd)(Args ...), Args ... args) // return thread ID (not pthread_t), used in thread_stop function uint64_t thread_new(void(T::* thrd)(Args ...), Args ... args) // return thread ID (not pthread_t), used in thread_stop function
{ {
THRD t; THRD t;
t.id = id_++; t.id = id_++;
t.thread.reset(new std::thread(thrd, obj_, args ...)); t.thread.reset(new std::thread(thrd, obj_, args ...));
t.id = thread_id(t.thread.get());
threads_.push_back(t); threads_.push_back(t);
return t.id; return t.id;
} }
bool thread_stop(uint32_t id = -1) bool thread_stop(uint64_t id = -1)
{ {
bool ret = true; bool ret = true;
if (id == -1) if (id == -1)

View File

@ -940,8 +940,6 @@ namespace sys_util
} }
uint64_t thread_id(const std::thread::id& tid) uint64_t thread_id(const std::thread::id& tid)
{ {
return (uint64_t)pthread_self();
std::stringstream ss; std::stringstream ss;
ss << tid; ss << tid;

View File

@ -567,8 +567,8 @@ bool img_color_transfer::is_enabled(std::function<int32_t(const char*, void*, si
// "img-format": { // "img-format": {
// "cat": "Common", // "cat": "Common",
// "group": "output", // "group": "output",
// "title": "图片格式", // "title": "\u56fe\u7247\u683c\u5f0f",
// "desc": "设备输出的图片文件格式", // "desc": "\u8bbe\u5907\u8f93\u51fa\u7684\u56fe\u7247\u6587\u4ef6\u683c\u5f0f",
// "ver": 1, // "ver": 1,
// "pos": 0, // "pos": 0,
// "type": "string", // "type": "string",
@ -580,13 +580,13 @@ bool img_color_transfer::is_enabled(std::function<int32_t(const char*, void*, si
// "size": 42, // "size": 42,
// "cur": "JPEG", // "cur": "JPEG",
// "default": "JPEG", // "default": "JPEG",
// "range": ["JPEG", "PNG", "TIFF"] // "range": ["JPEG", "PNG", "TIFF", "BMP"]
// }, // },
// "jpeg-quality": { // "jpeg-quality": {
// "cat": "Common", // "cat": "Common",
// "group": "output", // "group": "output",
// "title": "JPEG质量", // "title": "JPEG\u8d28\u91cf",
// "desc": "设置JPEG压缩质量质量越高压缩率越低", // "desc": "\u8bbe\u7f6eJPEG\u538b\u7f29\u8d28\u91cf\uff0c\u8d28\u91cf\u8d8a\u9ad8\uff0c\u538b\u7f29\u7387\u8d8a\u4f4e",
// "ver": 1, // "ver": 1,
// "pos": 0, // "pos": 0,
// "type": "int", // "type": "int",
@ -608,7 +608,7 @@ bool img_color_transfer::is_enabled(std::function<int32_t(const char*, void*, si
// } // }
static std::string fmt_json = static std::string fmt_json =
"{\"img-format\":{\"cat\":\"Common\",\"group\":\"output\",\"title\":\"\\u56fe\\u7247\\u683c\\u5f0f\",\"desc\":\"\\u8bbe\\u5907\\u8f93\\u51fa\\u7684\\u56fe\\u7247\\u6587\\u4ef6\\u683c\\u5f0f\",\"ver\":1,\"pos\":0,\"type\":\"string\",\"unit\":\"none\",\"affect\":2,\"readonly\":false,\"visible\":true,\"enabled\":true,\"size\":42,\"cur\":\"JPEG\",\"default\":\"JPEG\",\"range\":[\"JPEG\",\"PNG\",\"TIFF\"]},\"jpeg-quality\":{\"cat\":\"Common\",\"group\":\"output\",\"title\":\"JPEG\\u8d28\\u91cf\",\"desc\":\"\\u8bbe\\u7f6eJPEG\\u538b\\u7f29\\u8d28\\u91cf\\uff0c\\u8d28\\u91cf\\u8d8a\\u9ad8\\uff0c\\u538b\\u7f29\\u7387\\u8d8a\\u4f4e\",\"ver\":1,\"pos\":0,\"type\":\"int\",\"unit\":\"%\",\"affect\":4,\"readonly\":false,\"visible\":true,\"enabled\":true,\"size\":4,\"cur\":100,\"default\":100,\"range\":{\"min\":10,\"max\":100,\"step\":1},\"depend_or\":[\"img-format==JPEG\"]}}"; "{\"img-format\":{\"cat\":\"Common\",\"group\":\"output\",\"title\":\"\\u56fe\\u7247\\u683c\\u5f0f\",\"desc\":\"\\u8bbe\\u5907\\u8f93\\u51fa\\u7684\\u56fe\\u7247\\u6587\\u4ef6\\u683c\\u5f0f\",\"ver\":1,\"pos\":0,\"type\":\"string\",\"unit\":\"none\",\"affect\":2,\"readonly\":false,\"visible\":true,\"enabled\":true,\"size\":42,\"cur\":\"JPEG\",\"default\":\"JPEG\",\"range\":[\"JPEG\",\"PNG\",\"TIFF\",\"BMP\"]},\"jpeg-quality\":{\"cat\":\"Common\",\"group\":\"output\",\"title\":\"JPEG\\u8d28\\u91cf\",\"desc\":\"\\u8bbe\\u7f6eJPEG\\u538b\\u7f29\\u8d28\\u91cf\\uff0c\\u8d28\\u91cf\\u8d8a\\u9ad8\\uff0c\\u538b\\u7f29\\u7387\\u8d8a\\u4f4e\",\"ver\":1,\"pos\":0,\"type\":\"int\",\"unit\":\"%\",\"affect\":4,\"readonly\":false,\"visible\":true,\"enabled\":true,\"size\":4,\"cur\":100,\"default\":100,\"range\":{\"min\":10,\"max\":100,\"step\":1},\"depend_or\":[\"img-format==JPEG\"]}}";
img_encoder::img_encoder() : fmt_("JPEG"), jpeg_quality_(100) img_encoder::img_encoder() : fmt_("JPEG"), jpeg_quality_(100)
{ {
@ -719,6 +719,8 @@ MemoryPtr img_encoder::encode(PROCIMG* img)
img->head.format = IMG_FMT_PNG; img->head.format = IMG_FMT_PNG;
else if(fmt_ == "TIFF") else if(fmt_ == "TIFF")
img->head.format = IMG_FMT_TIFF; img->head.format = IMG_FMT_TIFF;
else if(fmt_ == "BMP")
img->head.format = IMG_FMT_BMP;
return encoder.encode(img->img); return encoder.encode(img->img);
} }

View File

@ -4,6 +4,7 @@
#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" #include "common/log_util.h"
#include "common/sys_util.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -184,6 +185,8 @@ uint32_t img_processor::add_busy_count(int adden)
} }
void img_processor::worker_thread(bool first) void img_processor::worker_thread(bool first)
{ {
log_cls::log(LOG_LEVEL_ALL, "+img_processor::worker_thread(%p) entered ...\n", sys_util::thread_id(std::this_thread::get_id()));
while(run_) while(run_)
{ {
img_one_paper* img = nullptr; img_one_paper* img = nullptr;
@ -191,6 +194,7 @@ void img_processor::worker_thread(bool first)
{ {
if(img) if(img)
{ {
int paper = img->images_queue()[0].head.pos.paper_ind;
add_busy_count(); add_busy_count();
handle_image(img); handle_image(img);
add_busy_count(-1); add_busy_count(-1);
@ -200,7 +204,7 @@ void img_processor::worker_thread(bool first)
else else
{ {
while(add_busy_count(0)) while(add_busy_count(0))
std::this_thread::sleep_for(std::chrono::microseconds(50)); std::this_thread::sleep_for(std::chrono::milliseconds(50));
img_sender_(nullptr, nullptr, nullptr, scan_staus_); img_sender_(nullptr, nullptr, nullptr, scan_staus_);
set_image_process_over(true); set_image_process_over(true);
@ -213,15 +217,15 @@ void img_processor::worker_thread(bool first)
else if(first) else if(first)
{ {
for(auto& v: tids_) for(auto& v: tids_)
worker_->thread_kill(v); worker_->thread_stop(v);
tids_.clear(); tids_.clear();
} }
else else
{ {
log_cls::log(LOG_LEVEL_ALL, "- Release image processing threads.\n");
break; break;
} }
} }
log_cls::log(LOG_LEVEL_ALL, "-img_processor::worker_thread(%p) exited.\n", sys_util::thread_id(std::this_thread::get_id()));
} }
void img_processor::handle_image(img_one_paper* img) void img_processor::handle_image(img_one_paper* img)
{ {
@ -380,9 +384,8 @@ 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 >= 6 && worker_->count() < 6) if(speed_first_ && cnt >= 4 && worker_->count() < 2)
{ {
log_cls::log(LOG_LEVEL_ALL, "+ Add image processing threads ...\n");
tids_.push_back(worker_->thread_new(&img_processor::worker_thread, false)); tids_.push_back(worker_->thread_new(&img_processor::worker_thread, false));
} }
} }

View File

@ -34,7 +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_; std::vector<uint64_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

@ -73,10 +73,10 @@ class async_usb_gadget : public refer
volatile bool run_ = true; volatile bool run_ = true;
volatile bool reset_bulk_ = false; volatile bool reset_bulk_ = false;
usb_gadget *gadget_ = nullptr; usb_gadget *gadget_ = nullptr;
int thread_ep0_id_ = -1; uint64_t thread_ep0_id_ = -1;
int thread_bulk_in_id_ = -1; uint64_t thread_bulk_in_id_ = -1;
int thread_bulk_out_id_ = -1; uint64_t thread_bulk_out_id_ = -1;
int thread_restart_id_ = -1; uint64_t thread_restart_id_ = -1;
uint32_t enc_head_; uint32_t enc_head_;
uint32_t enc_payload_; uint32_t enc_payload_;
uint8_t enc_data_; uint8_t enc_data_;