优化扫描结束处理流程

This commit is contained in:
gb 2024-02-29 12:32:01 +08:00
parent 2c138cd89d
commit 17b81d3925
3 changed files with 50 additions and 6 deletions

View File

@ -112,6 +112,30 @@ shared_memory* hg_scanner::create_device_singleton(int vid, int pid, int addr)
return new shared_memory(key); 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) void hg_scanner::init(void)
{ {
@ -132,10 +156,10 @@ void hg_scanner::init(void)
} }
else if (pimg == IMG_RECEIVER_FINISHED) 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()); 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 else
{ {
@ -248,8 +272,18 @@ void hg_scanner::thread_image_processor(void)
//processor->add_ref(); //processor->add_ref();
while (raw_imgs_.take(raw, true)) while (raw_imgs_.take(raw, true))
{
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); process_image(raw);
}
raw->release(); raw->release();
} }
@ -258,10 +292,10 @@ void hg_scanner::thread_image_processor(void)
void hg_scanner::process_image(image_holder_ptr img) void hg_scanner::process_image(image_holder_ptr img)
{ {
bool addref = true; bool addref = true;
int stage = img->get_info()->prc_stage;
if (!dump_path_.empty()) if (!dump_path_.empty())
{ {
int stage = img->get_info()->prc_stage;
char alg[128] = { 0 }; char alg[128] = { 0 };
if (img_prc_name_.count(stage)) if (img_prc_name_.count(stage))
@ -270,6 +304,12 @@ void hg_scanner::process_image(image_holder_ptr img)
sprintf(alg, "%s", "Unk"); sprintf(alg, "%s", "Unk");
img->save_2_file(dump_path_.c_str(), stage, alg); 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) if (img->get_info()->format != IMG_FMT_BMP)
{ {

View File

@ -71,6 +71,8 @@ class hg_scanner : public sane_opt_provider
std::map<int, std::string> img_prc_name_; // <position, key-name> std::map<int, std::string> img_prc_name_; // <position, key-name>
static shared_memory* create_device_singleton(int vid, int pid, int addr); 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 init(void);
void thread_image_processor(void); void thread_image_processor(void);

View File

@ -156,6 +156,8 @@ int image_holder::save_2_file(const char* root_dir, int alg_ind, const char* alg
file += buf; file += buf;
if (alg && *alg) if (alg && *alg)
file += std::string("_") + alg; file += std::string("_") + alg;
else
alg = "";
if (head_.format == IMG_FMT_PNG) if (head_.format == IMG_FMT_PNG)
file += ".png"; file += ".png";
else if (head_.format == IMG_FMT_JPEG) 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) if (dst)
fclose(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; return err;
} }