change scan-count to paper count; change STOPSCAN pushed position
This commit is contained in:
parent
4d4a690f71
commit
d56e482a7a
|
@ -71,6 +71,8 @@ MemoryPtr JpegImageEncode::encode(cv::Mat &image)
|
|||
type = ".png";
|
||||
else if(fmt_ == "TIFF")
|
||||
type = ".tiff";
|
||||
else if(fmt_ == "BMP")
|
||||
type = ".bmp";
|
||||
else
|
||||
type = ".jpg";
|
||||
|
||||
|
|
|
@ -104,10 +104,10 @@ Scanner::Scanner(std::shared_ptr<ICapturer> capturer, std::shared_ptr<MotorBoard
|
|||
auto mb_scandone_call = [&]()
|
||||
{
|
||||
done_scan = 1;
|
||||
if(mb_error_code == 0)
|
||||
mb_error_code = 0xffffffff;
|
||||
// if(mb_error_code == 0)
|
||||
// mb_error_code = 0xffffffff;
|
||||
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)
|
||||
|
@ -261,7 +261,7 @@ void Scanner::add_scansever(HGIntInfo event)
|
|||
bool Scanner::set_hgimgconfig(GScanCap config)
|
||||
{
|
||||
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;
|
||||
if (config.resolution_dst < 300)
|
||||
m_config.g200params.dpi = 1;
|
||||
|
@ -574,6 +574,7 @@ void Scanner::runScan()
|
|||
else
|
||||
autosizescan();
|
||||
savescannerinfo(scannerinfo);
|
||||
imagehandler->add_scanevent({.From = STOPSCAN, mb_error_code});
|
||||
while (!imagehandler->done())
|
||||
this_thread::sleep_for(chrono::milliseconds(10));
|
||||
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)
|
||||
mb->set_auto_paper(false, false);
|
||||
mb->startcapimage(false);
|
||||
imagehandler->add_scanevent({.From = STOPSCAN, 0});
|
||||
// imagehandler->add_scanevent({.From = STOPSCAN, 0});
|
||||
ControlFeedMode();
|
||||
printf("-------scanner done-------\n");
|
||||
}
|
||||
|
|
|
@ -89,7 +89,9 @@ public:
|
|||
if (wait && size() == 0)
|
||||
{
|
||||
wait_->wait();
|
||||
#if defined(WIN32) || defined(_WIN64)
|
||||
wait_->reset();
|
||||
#endif
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
// #include <semaphore.h>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <iosfwd>
|
||||
#include <sstream>
|
||||
|
||||
#if defined(WIN32) || defined(_WIN64)
|
||||
#define WAIT_INFINITE INFINITE
|
||||
|
@ -34,6 +36,7 @@ extern int gettimeofday(TIMEV* tv, struct timezone* tz);
|
|||
#include <sys/time.h>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <pthread.h>
|
||||
typedef struct timeval TIMEV;
|
||||
#define WAIT_INFINITE 0
|
||||
#define FSEEK fseek
|
||||
|
@ -110,7 +113,7 @@ class thread_pool : public refer
|
|||
{
|
||||
typedef struct _thrd
|
||||
{
|
||||
uint32_t id;
|
||||
uint64_t id;
|
||||
std::shared_ptr<std::thread> thread;
|
||||
}THRD;
|
||||
T* obj_;
|
||||
|
@ -122,23 +125,33 @@ public:
|
|||
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:
|
||||
virtual ~thread_pool()
|
||||
{}
|
||||
|
||||
public:
|
||||
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;
|
||||
|
||||
t.id = id_++;
|
||||
t.thread.reset(new std::thread(thrd, obj_, args ...));
|
||||
t.id = thread_id(t.thread.get());
|
||||
threads_.push_back(t);
|
||||
|
||||
return t.id;
|
||||
}
|
||||
bool thread_stop(uint32_t id = -1)
|
||||
bool thread_stop(uint64_t id = -1)
|
||||
{
|
||||
bool ret = true;
|
||||
if (id == -1)
|
||||
|
|
|
@ -940,8 +940,6 @@ namespace sys_util
|
|||
}
|
||||
uint64_t thread_id(const std::thread::id& tid)
|
||||
{
|
||||
return (uint64_t)pthread_self();
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
ss << tid;
|
||||
|
|
|
@ -567,8 +567,8 @@ bool img_color_transfer::is_enabled(std::function<int32_t(const char*, void*, si
|
|||
// "img-format": {
|
||||
// "cat": "Common",
|
||||
// "group": "output",
|
||||
// "title": "图片格式",
|
||||
// "desc": "设备输出的图片文件格式",
|
||||
// "title": "\u56fe\u7247\u683c\u5f0f",
|
||||
// "desc": "\u8bbe\u5907\u8f93\u51fa\u7684\u56fe\u7247\u6587\u4ef6\u683c\u5f0f",
|
||||
// "ver": 1,
|
||||
// "pos": 0,
|
||||
// "type": "string",
|
||||
|
@ -580,13 +580,13 @@ bool img_color_transfer::is_enabled(std::function<int32_t(const char*, void*, si
|
|||
// "size": 42,
|
||||
// "cur": "JPEG",
|
||||
// "default": "JPEG",
|
||||
// "range": ["JPEG", "PNG", "TIFF"]
|
||||
// "range": ["JPEG", "PNG", "TIFF", "BMP"]
|
||||
// },
|
||||
// "jpeg-quality": {
|
||||
// "cat": "Common",
|
||||
// "group": "output",
|
||||
// "title": "JPEG质量",
|
||||
// "desc": "设置JPEG压缩质量,质量越高,压缩率越低",
|
||||
// "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",
|
||||
|
@ -608,7 +608,7 @@ bool img_color_transfer::is_enabled(std::function<int32_t(const char*, void*, si
|
|||
// }
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -719,6 +719,8 @@ MemoryPtr img_encoder::encode(PROCIMG* img)
|
|||
img->head.format = IMG_FMT_PNG;
|
||||
else if(fmt_ == "TIFF")
|
||||
img->head.format = IMG_FMT_TIFF;
|
||||
else if(fmt_ == "BMP")
|
||||
img->head.format = IMG_FMT_BMP;
|
||||
|
||||
return encoder.encode(img->img);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "common/json/gb_json.h"
|
||||
#include "img_process/algs/img_algorithm.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)
|
||||
{
|
||||
log_cls::log(LOG_LEVEL_ALL, "+img_processor::worker_thread(%p) entered ...\n", sys_util::thread_id(std::this_thread::get_id()));
|
||||
|
||||
while(run_)
|
||||
{
|
||||
img_one_paper* img = nullptr;
|
||||
|
@ -191,6 +194,7 @@ void img_processor::worker_thread(bool first)
|
|||
{
|
||||
if(img)
|
||||
{
|
||||
int paper = img->images_queue()[0].head.pos.paper_ind;
|
||||
add_busy_count();
|
||||
handle_image(img);
|
||||
add_busy_count(-1);
|
||||
|
@ -200,7 +204,7 @@ void img_processor::worker_thread(bool first)
|
|||
else
|
||||
{
|
||||
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_);
|
||||
set_image_process_over(true);
|
||||
|
@ -213,15 +217,15 @@ void img_processor::worker_thread(bool first)
|
|||
else if(first)
|
||||
{
|
||||
for(auto& v: tids_)
|
||||
worker_->thread_kill(v);
|
||||
worker_->thread_stop(v);
|
||||
tids_.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
log_cls::log(LOG_LEVEL_ALL, "- Release image processing threads.\n");
|
||||
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)
|
||||
{
|
||||
|
@ -380,9 +384,8 @@ int32_t img_processor::push_image(img_one_paper* img, bool over)
|
|||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class img_processor : public sane_cfg_provider
|
|||
|
||||
safe_fifo<img_one_paper*> img_que_;
|
||||
thread_pool<img_processor>* worker_;
|
||||
std::vector<uint32_t> tids_;
|
||||
std::vector<uint64_t> tids_;
|
||||
volatile bool speed_first_;
|
||||
volatile bool run_;
|
||||
uint32_t scan_staus_;
|
||||
|
|
|
@ -73,10 +73,10 @@ class async_usb_gadget : public refer
|
|||
volatile bool run_ = true;
|
||||
volatile bool reset_bulk_ = false;
|
||||
usb_gadget *gadget_ = nullptr;
|
||||
int thread_ep0_id_ = -1;
|
||||
int thread_bulk_in_id_ = -1;
|
||||
int thread_bulk_out_id_ = -1;
|
||||
int thread_restart_id_ = -1;
|
||||
uint64_t thread_ep0_id_ = -1;
|
||||
uint64_t thread_bulk_in_id_ = -1;
|
||||
uint64_t thread_bulk_out_id_ = -1;
|
||||
uint64_t thread_restart_id_ = -1;
|
||||
uint32_t enc_head_;
|
||||
uint32_t enc_payload_;
|
||||
uint8_t enc_data_;
|
||||
|
|
Loading…
Reference in New Issue