优化扫描结束处理流程
This commit is contained in:
parent
2c138cd89d
commit
17b81d3925
|
@ -112,6 +112,30 @@ shared_memory* hg_scanner::create_device_singleton(int vid, int pid, int addr)
|
|||
|
||||
return new shared_memory(key);
|
||||
}
|
||||
image_holder_ptr hg_scanner::make_finished_image_holder(int err)
|
||||
{
|
||||
PACKIMAGE over;
|
||||
image_holder_ptr ihp = nullptr;
|
||||
|
||||
memset(&over, 0, sizeof(over));
|
||||
over.info_size = err;
|
||||
ihp = new image_holder(&over);
|
||||
|
||||
return ihp;
|
||||
}
|
||||
bool hg_scanner::is_finished_image_holder(image_holder_ptr ptr, int* err)
|
||||
{
|
||||
PACKIMAGE over;
|
||||
bool finish = false;
|
||||
|
||||
memset(&over, 0, sizeof(over));
|
||||
over.info_size = ptr->get_info()->info_size;
|
||||
finish = memcmp(&over, ptr->get_info(), sizeof(over)) == 0;
|
||||
if (finish && err)
|
||||
*err = over.info_size;
|
||||
|
||||
return finish;
|
||||
}
|
||||
|
||||
void hg_scanner::init(void)
|
||||
{
|
||||
|
@ -132,10 +156,10 @@ void hg_scanner::init(void)
|
|||
}
|
||||
else if (pimg == IMG_RECEIVER_FINISHED)
|
||||
{
|
||||
status_ = size;
|
||||
image_holder_ptr ihp = hg_scanner::make_finished_image_holder(size);
|
||||
|
||||
raw_imgs_.save(ihp, true);
|
||||
utils::to_log(LOG_LEVEL_DEBUG, "Scan finished with error: %s\n", scanner_error_name(status_).c_str());
|
||||
if (scan_over_notify_)
|
||||
scan_over_notify_(status_);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -249,7 +273,17 @@ void hg_scanner::thread_image_processor(void)
|
|||
//processor->add_ref();
|
||||
while (raw_imgs_.take(raw, true))
|
||||
{
|
||||
process_image(raw);
|
||||
int err = 0;
|
||||
if (hg_scanner::is_finished_image_holder(raw, &err))
|
||||
{
|
||||
status_ = err;
|
||||
if (scan_over_notify_)
|
||||
scan_over_notify_(status_);
|
||||
}
|
||||
else
|
||||
{
|
||||
process_image(raw);
|
||||
}
|
||||
|
||||
raw->release();
|
||||
}
|
||||
|
@ -258,10 +292,10 @@ void hg_scanner::thread_image_processor(void)
|
|||
void hg_scanner::process_image(image_holder_ptr img)
|
||||
{
|
||||
bool addref = true;
|
||||
int stage = img->get_info()->prc_stage;
|
||||
|
||||
if (!dump_path_.empty())
|
||||
{
|
||||
int stage = img->get_info()->prc_stage;
|
||||
char alg[128] = { 0 };
|
||||
|
||||
if (img_prc_name_.count(stage))
|
||||
|
@ -270,6 +304,12 @@ void hg_scanner::process_image(image_holder_ptr img)
|
|||
sprintf(alg, "%s", "Unk");
|
||||
img->save_2_file(dump_path_.c_str(), stage, alg);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string alg(img_prc_name_.count(stage) ? img_prc_name_[stage] : std::to_string(stage));
|
||||
utils::to_log(LOG_LEVEL_ALL, "Image-Process '%s' of picture '%04d-%d%d%d' is %ums.\n", alg.c_str()
|
||||
, img->get_info()->pos.paper_ind, img->get_info()->pos.paper_side, img->get_info()->pos.split_ind, img->get_info()->pos.multiout_ind, img->get_info()->prc_time);
|
||||
}
|
||||
|
||||
if (img->get_info()->format != IMG_FMT_BMP)
|
||||
{
|
||||
|
|
|
@ -71,6 +71,8 @@ class hg_scanner : public sane_opt_provider
|
|||
std::map<int, std::string> img_prc_name_; // <position, key-name>
|
||||
|
||||
static shared_memory* create_device_singleton(int vid, int pid, int addr);
|
||||
static image_holder_ptr make_finished_image_holder(int err);
|
||||
static bool is_finished_image_holder(image_holder_ptr ptr, int* err);
|
||||
|
||||
void init(void);
|
||||
void thread_image_processor(void);
|
||||
|
|
|
@ -156,6 +156,8 @@ int image_holder::save_2_file(const char* root_dir, int alg_ind, const char* alg
|
|||
file += buf;
|
||||
if (alg && *alg)
|
||||
file += std::string("_") + alg;
|
||||
else
|
||||
alg = "";
|
||||
if (head_.format == IMG_FMT_PNG)
|
||||
file += ".png";
|
||||
else if (head_.format == IMG_FMT_JPEG)
|
||||
|
@ -194,7 +196,7 @@ int image_holder::save_2_file(const char* root_dir, int alg_ind, const char* alg
|
|||
|
||||
if (dst)
|
||||
fclose(dst);
|
||||
utils::to_log(LOG_LEVEL_ALL, "Image-Process of file '%s' is %ums.\n", file.c_str(), head_.prc_time);
|
||||
utils::to_log(LOG_LEVEL_ALL, "Image-Process %s of file '%s' is %ums.\n", alg, file.c_str(), head_.prc_time);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue