添加解码失败时保存原数据功能;添加pop_first_image失败时停止扫描功能
This commit is contained in:
parent
27fa305c9a
commit
ecf7e2e071
|
@ -204,6 +204,30 @@ hg_scanner::hg_scanner(ScannerSerial serial, const char* dev_name, usb_io* io, i
|
||||||
{
|
{
|
||||||
VLOG_MINI_1(LOG_LEVEL_WARNING, "temporary image folder: %s\n", final_path_.c_str());
|
VLOG_MINI_1(LOG_LEVEL_WARNING, "temporary image folder: %s\n", final_path_.c_str());
|
||||||
final_path_ += PATH_SEPARATOR;
|
final_path_ += PATH_SEPARATOR;
|
||||||
|
|
||||||
|
// delete previous failed images, check the name as pattern '%04d-xxx.jpg'
|
||||||
|
std::vector<std::string> files;
|
||||||
|
hg_log::get_foler_files((final_path_ + "failedimgs").c_str(), files);
|
||||||
|
for (auto& v : files)
|
||||||
|
{
|
||||||
|
size_t pos = v.rfind(PATH_SEPARATOR[0]);
|
||||||
|
std::string name("");
|
||||||
|
char num[20] = { 0 };
|
||||||
|
|
||||||
|
if (pos == std::string::npos)
|
||||||
|
name = v;
|
||||||
|
else
|
||||||
|
name = v.substr(pos + 1);
|
||||||
|
sprintf(num, "%04d-", atoi(name.c_str()));
|
||||||
|
if (name.find(num) == 0)
|
||||||
|
{
|
||||||
|
pos = name.rfind('.');
|
||||||
|
if(pos != std::string::npos && STRICMP(name.c_str() + pos, ".jpg") == 0)
|
||||||
|
remove(v.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rmdir((final_path_ + "failedimgs").c_str());
|
||||||
|
hg_log::create_folder((final_path_ + "failedimgs").c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -5158,13 +5182,45 @@ void hg_scanner::image_process(std::shared_ptr<tiny_buffer>& buffer, uint32_t id
|
||||||
hg_imgproc::IMGHEAD ih;
|
hg_imgproc::IMGHEAD ih;
|
||||||
int err = SCANNER_ERR_OK,
|
int err = SCANNER_ERR_OK,
|
||||||
index = 0;
|
index = 0;
|
||||||
|
std::string fimg(final_path_ + "failedimgs" + PATH_SEPARATOR);
|
||||||
void* buf = NULL;
|
void* buf = NULL;
|
||||||
|
|
||||||
hg_imgproc::load_buffer(ImagePrc_pHandle_, buffer);
|
hg_imgproc::load_buffer(ImagePrc_pHandle_, buffer);
|
||||||
int imgStatus = buffer->get_image_statu();
|
int imgStatus = buffer->get_image_statu();
|
||||||
|
|
||||||
hg_imgproc::decode(ImagePrc_pHandle_, pid_, &img_conf_, ¶m, correction_image_map_);
|
err = hg_imgproc::decode(ImagePrc_pHandle_, pid_, &img_conf_, ¶m, correction_image_map_);
|
||||||
(this->*dump_img_)(ImagePrc_pHandle_, "decode");
|
(this->*dump_img_)(ImagePrc_pHandle_, "decode");
|
||||||
|
if (err != SCANNER_ERR_OK)
|
||||||
|
{
|
||||||
|
char name[128] = { 0 };
|
||||||
|
FILE *dst = nullptr;
|
||||||
|
|
||||||
|
sprintf(name, "%04d-decode.jpg", id);
|
||||||
|
dst = fopen((fimg + name).c_str(), "wb");
|
||||||
|
if (dst)
|
||||||
|
{
|
||||||
|
unsigned int off = 0,
|
||||||
|
len = buffer->size(),
|
||||||
|
size = len;
|
||||||
|
unsigned char *mem = buffer->data(off, &size);
|
||||||
|
while (mem)
|
||||||
|
{
|
||||||
|
fwrite(mem, 1, size, dst);
|
||||||
|
off += size;
|
||||||
|
if (off >= len)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size = len - off;
|
||||||
|
mem = buffer->data(off, &size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(dst);
|
||||||
|
}
|
||||||
|
VLOG_MINI_2(LOG_LEVEL_FATAL, "Decode image(%d) with bytes %u failed, stop scanning.\n", id, buffer->size());
|
||||||
|
do_stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_dpi_color_check)
|
if (is_dpi_color_check)
|
||||||
{
|
{
|
||||||
|
|
|
@ -217,7 +217,20 @@ void hg_scanner_200::thread_handle_usb_read(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
io_->set_timeout(200);
|
io_->set_timeout(200);
|
||||||
pop_image();
|
ret = pop_image();
|
||||||
|
if (ret != SCANNER_ERR_OK)
|
||||||
|
{
|
||||||
|
hg_log::log(LOG_LEVEL_FATAL, "Try ONCE pop_firt_image after 100ms ...\n");
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
ret = pop_image();
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
hg_log::log(LOG_LEVEL_FATAL, "pop_firt_image failed, stop scanning!\n");
|
||||||
|
do_stop();
|
||||||
|
status_ = ret;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
sw.reset();
|
sw.reset();
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -791,8 +791,15 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
|
||||||
}
|
}
|
||||||
if (is_scanner_err_ok)
|
if (is_scanner_err_ok)
|
||||||
{
|
{
|
||||||
pop_first_image();
|
ret = pop_first_image();
|
||||||
|
if (ret != SCANNER_ERR_OK)
|
||||||
|
{
|
||||||
|
hg_log::log(LOG_LEVEL_FATAL, "Try ONCE pop_firt_image after 100ms ...\n");
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
ret = pop_first_image();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
int hg_scanner_239::discard_all_images(void)
|
int hg_scanner_239::discard_all_images(void)
|
||||||
|
|
|
@ -264,6 +264,13 @@ extern "C"
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
static bool save_dir_files(const char* path_file, void* param)
|
||||||
|
{
|
||||||
|
((std::vector<std::string>*)param)->push_back(path_file);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(WIN32) || defined(_WIN64)
|
#if defined(WIN32) || defined(_WIN64)
|
||||||
static std::string u2a(const wchar_t* u, UINT cp = CP_ACP)
|
static std::string u2a(const wchar_t* u, UINT cp = CP_ACP)
|
||||||
{
|
{
|
||||||
|
@ -287,6 +294,9 @@ extern "C"
|
||||||
static int enum_files(const char* dir, bool recursive, bool(*found_file)(const char* path_file, void* param), void* param)
|
static int enum_files(const char* dir, bool recursive, bool(*found_file)(const char* path_file, void* param), void* param)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
if (!dir || *dir == 0)
|
||||||
|
{
|
||||||
HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
|
HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
|
||||||
MODULEENTRY32W pei = { 0 };
|
MODULEENTRY32W pei = { 0 };
|
||||||
|
|
||||||
|
@ -307,6 +317,34 @@ extern "C"
|
||||||
}
|
}
|
||||||
CloseHandle(h);
|
CloseHandle(h);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WIN32_FIND_DATAA wfd = { 0 };
|
||||||
|
HANDLE h = FindFirstFileA((std::string(dir) + "\\*").c_str(), &wfd);
|
||||||
|
if (h == INVALID_HANDLE_VALUE)
|
||||||
|
ret = GetLastError();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (strcmp(wfd.cFileName, ".") == 0 || strcmp(wfd.cFileName, "..") == 0)
|
||||||
|
continue;
|
||||||
|
if (!found_file((std::string(dir) + "\\" + wfd.cFileName).c_str(), param))
|
||||||
|
{
|
||||||
|
ret = ECANCELED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && recursive)
|
||||||
|
{
|
||||||
|
ret = enum_files((std::string(dir) + "\\" + wfd.cFileName).c_str(), recursive, found_file, param);
|
||||||
|
if (ret == ECANCELED)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (FindNextFileA(h, &wfd));
|
||||||
|
FindClose(h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -539,6 +577,10 @@ extern "C"
|
||||||
{
|
{
|
||||||
return MKDIR(fodler, S_IREAD | S_IWRITE | S_IEXEC) == 0 || errno == EEXIST;
|
return MKDIR(fodler, S_IREAD | S_IWRITE | S_IEXEC) == 0 || errno == EEXIST;
|
||||||
}
|
}
|
||||||
|
void get_foler_files(const char* folder, std::vector<std::string>& files, bool recursive)
|
||||||
|
{
|
||||||
|
enum_files(folder, recursive, save_dir_files, &files);
|
||||||
|
}
|
||||||
std::string ini_get(const char* app, const char* key)
|
std::string ini_get(const char* app, const char* key)
|
||||||
{
|
{
|
||||||
return ini_.get(app, key);
|
return ini_.get(app, key);
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "../../sdk/hginclude/huagaoxxx_warraper_ex.h"
|
#include "../../sdk/hginclude/huagaoxxx_warraper_ex.h"
|
||||||
#include "lang/app_language.h"
|
#include "lang/app_language.h"
|
||||||
#if defined(WIN32) || defined(_WIN64)
|
#if defined(WIN32) || defined(_WIN64)
|
||||||
|
@ -64,6 +66,7 @@ extern "C"
|
||||||
unsigned long long available_memory(void);
|
unsigned long long available_memory(void);
|
||||||
void str_tolower(std::string& str);
|
void str_tolower(std::string& str);
|
||||||
bool create_folder(const char* fodler);
|
bool create_folder(const char* fodler);
|
||||||
|
void get_foler_files(const char* folder, std::vector<std::string>& files, bool recursive = false);
|
||||||
|
|
||||||
std::string ini_get(const char* app, const char* key);
|
std::string ini_get(const char* app, const char* key);
|
||||||
void ini_set(const char* app, const char* key, const char* val);
|
void ini_set(const char* app, const char* key, const char* val);
|
||||||
|
|
Loading…
Reference in New Issue