twain3.0/huagao/Device/GScanO1003399.cpp

919 lines
22 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "GScanO1003399.h"
#include "ImageProcess/ImageApplyHeaders.h"
#include "ImageMultiOutput.h"
#include "scn_config.h"
#include "UsbScanEx.h"
#include "PaperSize.h"
#include "GScan.h"
static std::mutex mx_ctrl;
static int scanner_read_reg(std::shared_ptr<IUsb>& usb, int addr)
{
std::lock_guard<std::mutex> lck(mx_ctrl);
if (usb.get() && usb->is_connected()) {
int val = 0;
usb->control_msg(0xc0, USB_REQ_GET_DEV_REGS, addr, 0, 4, &val);
return val;
}
return 0;
}
static void scanner_write_reg(std::shared_ptr<IUsb>& usb, int addr, int val)
{
std::lock_guard<std::mutex> lck(mx_ctrl);
if (usb.get() && usb->is_connected())
{
usb->control_msg(0x40, USB_REQ_SET_DEV_REGS, addr, 0, 4, &val);
}
}
static void scanner_cmd(std::shared_ptr<IUsb>& usb, int cmd)
{
scanner_write_reg(usb, 0, cmd);
}
GScanO1003399::GScanO1003399()
{
im_data.reset(new std::vector<char>());
//open(0x3072, 0x139);
if (!m_usbthread.get()) {
b_usbthread = true;
m_usbthread.reset(new thread(&GScanO1003399::usb_run, this));
}
devState = DEV_STOP;
}
GScanO1003399::~GScanO1003399()
{
imagecount = 0;
if (m_usbthread.get() && m_usbthread->joinable())
{
b_usbthread = false;
m_usbthread->join();
m_usbthread.reset();
}
m_usb.reset();
scanflag = false;
b_imgprothread = false;
imgs.ShutDown();
while (m_paths.Size() > 0)
{
remove(m_paths.Take().c_str());
}
m_paths.ShutDown();
if (m_imgprocthread.get() && m_imgprocthread->joinable())
{
m_imgprocthread->join();
}
}
void GScanO1003399::open(int vid, int pid)
{
if (m_usb.get() && m_usb->is_connected())
return;
auto lsusb = UsbScan_List::find_vid_pid(vid, pid);
if (!lsusb.empty())
{
m_usb = *lsusb.begin();
m_usb->open();
if (m_usb->is_open())
m_usb->set_usbhotplug_callback(usbhotplug_callback, this);
}
}
void GScanO1003399::regist_deviceevent_callback(deviceevent_callback callback, void* usrdata)
{
huagods = usrdata;
dev_callback = callback;
}
void GScanO1003399::usbhotplug_callback(bool isconnect, void* userdata)
{
GScanO1003399* This = (GScanO1003399*)userdata;
This->usbhotplug(isconnect);
}
void GScanO1003399::usbhotplug(bool isleft)
{
FileTools::writelog(log_ERROR, "enable usb callback ");
if (isleft) {
devState = DEV_WRONG;
Error_Code = USB_DISCONNECTED;
scanflag = false;
if (m_usb.get())
m_usb.reset();
if (huagods)
dev_callback(USB_DISCONNECTED, huagods);
}
}
void GScanO1003399::DogEar_callback(std::function<void(int)> fun)
{
}
static int aquirenum = 0;
static int getimgnum = 0;
int GScanO1003399::aquire_bmpdata(std::vector<unsigned char>& bmpdata)
{
StopWatch sw;
while (true)
{
if ((imagecount == 0) && (!is_runing()) && (!scanflag) || (sw.elapsed_s() > 30))
{
DoEvents();
this_thread::sleep_for(chrono::milliseconds(1));
if (sw.elapsed_s() > 30.0)
{
devState = DEV_STOP;
Stop_scan();
ResetScanner();
int roller_num_new = count();
set_scannum(abs(roller_num_new - roller_num));
return AQUIRE_IMAGE_TIMEOUT;
}
if (!is_runing())
{
int roller_num_new = count();
set_scannum(abs(roller_num_new - roller_num));
if (devState == DEV_WRONG)
return get_ErrorCode();
return -1;
}
}
else
{
if ((m_imagedata.Size() > 0))
{
FileTools::writelog(log_INFO, "aquire_bmpdata num =" + to_string(aquirenum++));
bmpdata = *(m_imagedata.Take());
UpdateScanInfo(get_imgnReaded(), countNTransfered());
imagecount--;
sw.reset();
return 0;
}
DoEvents();
this_thread::sleep_for(chrono::milliseconds(2));
}
}
}
BOOL GScanO1003399::IsConnected()
{
return m_usb.get()&&m_usb->is_connected();
}
std::string GScanO1003399::GetFWVersion()
{
std::string fw;
if (m_usb.get() && m_usb->is_connected())
{
scanner_write_reg(m_usb, SR_GET_FWVERSION, 0);
fw.resize(10);
read_data(&fw[0], fw.length(), 200);
}
return fw;
}
std::string GScanO1003399::GetSerialNum()
{
std::string sn;
if (m_usb.get() && m_usb->is_connected())
{
scanner_write_reg(m_usb, SR_GET_SERIALNUM, 0);
sn.resize(14);
read_data(&sn[0], sn.length(), 200);
}
return sn;
}
std::uint32_t GScanO1003399::GetMotorFPGA()
{
return std::uint32_t();
}
std::uint32_t GScanO1003399::GetScanFPGA()
{
return std::uint32_t();
}
bool GScanO1003399::is_scan()
{
//return devState==DEV_ISRUNNING;
return is_runing() || (m_imagedata.Size() > 0);
}
BOOL GScanO1003399::Get_Scanner_PaperOn()
{
//return scanner_read_reg(m_usb, SR_PAPER_READY);
return true;
}
int GScanO1003399::Get_Roller_num()
{
return count();
}
void GScanO1003399::config_params(GScanCap& param)
{
m_param = param;
HGScanConfig cfg;
cfg = { 0 };
#ifdef G200
PaperStatus ps = { param.papertype,param.paperAlign };
cfg.g200params.paper = SupPaperTyps.count(ps)>0 ? SupPaperTyps[ps] : 0;
if (param.filter != 3 || param.enhance_color != 0 || param.hsvcorrect)
cfg.g200params.color = 1;//color
else
{
cfg.g200params.color = SupPixelTypes.count(param.pixtype) > 0 ? SupPixelTypes[param.pixtype] : 2;
}
cfg.g200params.dpi = SupResolutions.count(param.resolution_native)>0 ? SupResolutions[param.resolution_native] : 1;
cfg.g200params.double_feed_enbale = (unsigned int)param.hardwarecaps.en_doublefeed;
cfg.g200params.stable_enbale = (unsigned int)param.hardwarecaps.en_stapledetect;
cfg.g200params.screw_detect_enable = (unsigned int)param.hardwarecaps.en_skrewdetect;
cfg.g200params.screw_detect_level = (unsigned int)cfg.g200params.screw_detect_enable ? secrewMaps[param.hardwarecaps.skrewdetectlevel] : 0;
cfg.g200params.enable_sizecheck = param.en_sizecheck == 1 ? 1 : 0;
cfg.g200params.unused_one = cfg.g200params.sizeerror_errorratio = 0;
param.resolution_dst >= 240.0f ? 1 : 0;
#else
cfg.g400params.doubleFeeded = param.hardwarecaps.en_doublefeed == 0 ? 0 : 1;
cfg.g400params.dpi = G400_DPI::G400_D200;//gcap.resolution_dst <= 200.0f ? G400_DPI::G400_D200 : (gcap.resolution_dst <= 300.0f ? G400_DPI::G400_D300 : G400_DPI::G400_D600);
cfg.g400params.enableLed = 1;
if (param.filter != 3 || param.enhance_color)
cfg.g400params.isColor = 1;
else
cfg.g400params.isColor = SupPixelTypes[param.pixtype];
cfg.g400params.enableStable = 0;//gcap.hardwarecaps.en_stapledetect==0?0:1;
cfg.g400params.isCorrect = 1;//1 <20><><EFBFBD><EFBFBD>У<EFBFBD><D0A3>
PaperStatus ps = { param.papertype,param.paperAlign };
cfg.g400params.pageSize = SupPaperTyps[ps];
CSize size;
#ifdef G300
size = Device::PaperSize().GetPaperSize(TwSS::A4, 200.0f, gcap.paperAlign);//G300 <20><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>A4<41><34><EFBFBD><EFBFBD>
#else
size = Device::PaperSize().GetPaperSize(param.papertype, 200.0f, param.paperAlign);
#endif// G300
cfg.g400params.dstHeight = (int)((size.cy + 200) / 100);
cfg.g400params.reversed1 = cfg.g400params.reversed2 = 0;
#endif // G200
config_scanparam(cfg);
config_imgprocparam({0});
GScanCap_3399 param39{ 0 };
param39.AutoCrop_threshold = param.AutoCrop_threshold;
param39.autodescrew = param.autodescrew;
param39.automaticcolor = param.automaticcolor;
param39.automaticcolortype = param39.automaticcolortype;
param39.brightness = param.brightness;
param39.contrast = param.contrast;
param39.detachnoise = param.detachnoise;
param39.discardblank_percent = param.discardblank_percent;
param39.en_fold = param.en_fold;
param39.en_sizecheck = param.en_sizecheck;
param39.enhance_color = param.enhance_color;
param39.fillbackground = param.fillbackground;
param39.fillhole = param.fillhole;
param39.filter = param.filter;
param39.gamma = param.gamma;
param39.hardwarecaps = param.hardwarecaps;
param39.hsvcorrect = param.hsvcorrect;
param39.imageRotateDegree = param.imageRotateDegree;
param39.indent = param.indent;
param39.is_autocontrast = param.is_autocontrast;
param39.is_autocrop = param.is_autocrop;
param39.is_autodiscradblank_normal = param.is_autodiscradblank_normal;
param39.is_autodiscradblank_vince = param.is_autodiscradblank_vince;
param39.is_autotext = param.is_autotext;
param39.is_backrotate180 = param.is_backrotate180;
param39.is_convex = param.is_convex;
param39.is_dogeardetection = param.is_dogeardetection;
param39.is_duplex = param.is_duplex;
param39.is_switchfrontback = param.is_switchfrontback;
param39.multi_output_red = param.multi_output_red;
param39.noise = param.noise;
param39.paperAlign = param.paperAlign;
param39.papertype = param.papertype;
param39.pixtype = param.pixtype;
param39.resolution_dst = param.resolution_dst;
param39.resolution_native = param.resolution_native;
param39.scannum = param.scannum;
param39.sharpen = param.sharpen;
param39.threshold = param.threshold;
m_usb->write_bulk(&param39, sizeof(param39));
}
void GScanO1003399::Scanner_StartScan(UINT16 count)
{
roller_num = this->count();
scanflag = true;
while (m_paths.Size() > 0)
{
remove(m_paths.Take().c_str());
}
Set_ErrorCode(0);
getimgnum = 0;
aquirenum = 0;
imagecount = 0;
keeplastimg = true;
reset();
devState = DEV_ISRUNNING;
//if (scanner_read_reg(m_usb, SR_GET_SLEEP_STAUTUS) != 1)
//{
// devState = DEV_WRONG;
// Set_ErrorCode(SLEEPING);
// scanflag = false;
// return;
//}
if (scan_mode())
{
devState = DEV_WRONG;
Set_ErrorCode(COUNT_MODE);
scanflag = false;
return;
}
//if (!Get_Scanner_PaperOn())
//{
// devState = DEV_WRONG;
// Set_ErrorCode(NO_FEED);
// return;
//}
start();
bool procmode = (m_param.resolution_dst > 200.0f || m_param.papertype == 52 || m_param.papertype == 54 || m_param.papertype == 131);
if (m_imgprocthread.get() && m_imgprocthread->joinable())
{
b_imgprothread = false;
m_imgprocthread->join();
}
m_imgprocthread.reset(new thread(&GScanO1003399::proc, this, procmode));
//if (m_param.resolution_dst > 200.0f || m_param.papertype == 52 || m_param.papertype == 54 || m_param.papertype == 131) {
// b_imgprothread = true;
// m_imgprocthread.enqueue([this] {
// while (b_imgprothread)
// {
// if (m_paths.Size() < 1)
// {
// this_thread::sleep_for(chrono::milliseconds(10));
// continue;
// }
// auto path = m_paths.Take();
// if (!path.empty())
// {
// auto fd = fopen(path.c_str(), "rb+");
// if (fd)
// {
// auto lenght = FileTools::get_file_size(path.c_str());
// std::shared_ptr<std::vector<char>> buff(new std::vector<char>);
// buff->resize(lenght);
// fread(buff->data(), lenght, 1, fd);
// fclose(fd);
// remove(path.c_str());
// imgproce(buff);
// }
// else {
// FileTools::writelog(log_ERROR, "img tmp file read error file name =" + path);
// }
// }
// }
// });
//}
//else
//{
// b_imgprothread = false;
//}
}
void GScanO1003399::Stop_scan()
{
stop();
if ((devState == DEV_WRONG) || (devState == DEV_STOP))
return;
devState = DEV_STOP;
}
int GScanO1003399::notifyscan()
{
return 0;
}
void GScanO1003399::ResetScanner()
{
}
bool GScanO1003399::Get_IsImageQueueEmpty()
{
return m_imagedata.Size() < 1;
}
void GScanO1003399::reset()
{
devState = DEV_STOP;
m_imagedata.Clear();
}
void GScanO1003399::clear_hwerror()
{
}
UINT32 GScanO1003399::get_ErrorCode()
{
return Error_Code;
}
void GScanO1003399::Set_ErrorCode(UINT32 value)
{
Error_Code = value;
}
int GScanO1003399::get_scanned_num()
{
return 0;
}
void GScanO1003399::set_sleep_time(int mode)
{
}
bool GScanO1003399::set_scannercode(std::string str)
{
return false;
}
std::string GScanO1003399::get_scannercode()
{
return std::string();
}
void GScanO1003399::usb_run()
{
unsigned char buff[64];
while (b_usbthread)
{
if (!m_usb.get() || !m_usb->is_connected())
{
this_thread::sleep_for(chrono::milliseconds(20));
continue;
}
memset(buff, 0, sizeof(buff));
auto length = m_usb->read_int(buff, sizeof(buff));
if (((length) == sizeof(buff)))//|| im_dev_count()
{
HGEIntInfo info = *(HGEIntInfo*)&buff;
switch (info.From)
{
case IMG:
if (is_runing())
im_rx();
break;
case MtBoard:
FileTools::writelog(log_ERROR, "Got MotorBoard error code = " + to_string(info.Code));
break;
case FPGA:
FileTools::writelog(log_ERROR, "Got FPGA Error code = " + to_string(info.Code));
break;
case V4L2:
FileTools::writelog(log_ERROR, "Got V4L2 Error code = " + to_string(info.Code));
stop();
break;
case STOPSCAN:
FileTools::writelog(log_INFO, "StopScan");
break;
default:
FileTools::writelog(log_ERROR, "Got Unkown error code ! From =" + to_string(info.From) + " Code = " + to_string(info.Code));
break;
}
if (codeconvter(info) > 0)
{
Set_ErrorCode(codeconvter(info));
}
if ((codeconvter(info) == -1))
{
if ((get_ErrorCode() != PAPER_JAM) && (get_ErrorCode() != DETECT_DOUBLE_FEED) && (get_ErrorCode() != DETECT_STAPLE))
{
keeplastimg = false;
while (im_dev_count())
im_rx();
scanflag = false;
}
else {
while (!scanner_read_reg(m_usb, SR_GET_IMAGEPROCESSDONE))
this_thread::sleep_for(chrono::microseconds(30));
if (scanner_read_reg(m_usb, SR_GET_KEEP_LAST_PAPER))
{
this_thread::sleep_for(chrono::milliseconds(100));
while(im_dev_count()>( m_param.is_duplex?2:1))
im_rx();
if (m_param.is_duplex)
pop_dev_im();
pop_dev_im();
}
else
{
keeplastimg = false;
while (im_dev_count())
im_rx();
}
scanflag = false;
}
if ((devState != DEV_WRONG) && (get_ErrorCode()<=0))
devState = DEV_STOP;
else if ((devState != DEV_WRONG) && (get_ErrorCode() > 0))
devState = DEV_WRONG;
}
this_thread::sleep_for(chrono::microseconds(10));
}
}
}
void GScanO1003399::start()
{
scanner_cmd(m_usb, SC_START);
}
void GScanO1003399::stop()
{
scanner_cmd(m_usb, SC_STOP);
}
bool GScanO1003399::is_runing()
{
int val = scanner_read_reg(m_usb, SR_STATUS) & 0x3;
return (val > 0) && (val < 4);
}
int GScanO1003399::scan_mode()
{
return scanner_read_reg(m_usb, SR_OS) & 0x01;
}
int GScanO1003399::count()
{
return scanner_read_reg(m_usb, SR_GET_ROLLER_NUM);
}
void GScanO1003399::abort_dev_tx()
{
scanner_write_reg(m_usb, SR_IM_ABORT, 1); //!< to-list
}
void GScanO1003399::config_scanparam(const HG_ScanConfig& cfg)
{
scanner_write_reg(m_usb, SR_CONFIG_SCAN_PARAM, cfg.value);
}
void GScanO1003399::config_imgprocparam(const HGImgProcParms& imgprocparams)
{
scanner_write_reg(m_usb, SR_CONFIF_IMGPROCPARAM,imgprocparams.value);
}
bool GScanO1003399::is_rx()
{
return false;
}
bool GScanO1003399::rx_cmd()
{
scanner_write_reg(m_usb, 8, 1);
return true;
}
bool GScanO1003399::is_dev_tx()
{
return scanner_read_reg(m_usb, SR_IM_TXING);
}
void GScanO1003399::im_rx()
{
//m_imgthread.enqueue([this] {
//StopWatch sw;
//while (im_dev_count()){
if (is_dev_tx())
return;
if (keeplastimg)
{
if (m_param.is_duplex) {
if(im_dev_count()<3)
return;
}
if(im_dev_count()<2)
return;
}
//std::shared_ptr<std::vector<char>> buffi(new std::vector<char>);
auto& buffi = im_data;
int count = front_datasize();
buffi->resize(count);
rx_cmd();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
count = read_data(buffi->data(), count, count / (0.005 * 1024 * 1024)); //
pop_dev_im();
//vector<cv::Mat> mats;
m_param.multi_output_red? imagecount += 2: imagecount++;
UpdateScanInfo(countNReaded(), get_imgTransfered());
if (m_param.resolution_dst > 200.0f || m_param.papertype == 52 || m_param.papertype == 54 || m_param.papertype == 131)
{
auto path = cv::tempfile();
auto fd = fopen(path.c_str(), "wb+");
if (fd)
{
fwrite(buffi->data(), buffi->size(), 1, fd);
fclose(fd);
m_paths.Put(path);
}
else {
FileTools::writelog(log_ERROR, "img temp file save error flie name =" + path);
}
}
else {
imgs.Put(buffi);
//fu_imgpro.push(m_imgprocthread.enqueue([this] {
// imgproce(imgs.Take());
//}));
//while (fu_imgpro.size()>1)
//{
// fu_imgpro.front().get();
// if(fu_imgpro.size()>0)
// fu_imgpro.pop();
//}
}
//}
//});
}
int GScanO1003399::read_data(void* data, int length, int timeout)
{
if (!m_usb.get() && !m_usb->is_connected())
{
FileTools::writelog(log_INFO, "if (!m_usb.get() && !m_usb->is_connected())");
return 0;
}
timeout = std::max(500, timeout);
int readed = 0;
int reading = 0;
const int buffer_size = 512 * 1024;
StopWatch sw;
FileTools::writelog(log_INFO, "read_data timeout =" + to_string(timeout));
while (readed < length) {
if (sw.elapsed_ms() < timeout)
{
reading = std::max(0, std::min(length - readed, buffer_size));
reading = m_usb->read_bulk((unsigned char*)data + readed, reading);
if (reading > 0) {
readed += reading;
sw.reset();
}
}
else
{
FileTools::writelog(log_INFO, "read usb image data time out ,time = " + std::to_string(sw.elapsed_ms()));
break;
}
}
return readed;
}
void GScanO1003399::pop_dev_im()
{
if(im_dev_count()>0)
scanner_write_reg(m_usb, SR_IM_POP, 1); //!< to-list
}
int GScanO1003399::front_datasize()
{
return scanner_read_reg(m_usb, SR_IM_FRONT_SIZE);
}
int GScanO1003399::im_dev_count()
{
return scanner_read_reg(m_usb, SR_IM_COUNT); //!< to-list ;
}
void GScanO1003399::imgproce(std::shared_ptr<std::vector<char>>& buff)
{
auto& buffs= G400Decode(buff).getImageBuffs();
vector<cv::Mat> mats;
StopWatch sw;
bool isbwimg = false;
for (auto& buf : buffs) {
cv::ImreadModes rmc = m_param.pixtype == 2 ? cv::IMREAD_COLOR : cv::IMREAD_GRAYSCALE;
try
{
if (buf->at(0) == -119 && buf->at(1) == 0x50 && buf->at(2) == 0x4e && buf->at(3) == 0x47)
{
isbwimg = true;
rmc = cv::IMREAD_GRAYSCALE;
}
cv::Mat mat = cv::imdecode(*buf, rmc);
if (mat.empty()) {
FileTools::writelog(log_ERROR, "decode image data error");
continue;
}
buf.reset();
mats.push_back(mat);
FileTools::writelog(log_INFO, "push_back image num= " + to_string(getimgnum++));
}
catch (const std::exception& e)
{
FileTools::writelog(log_ERROR, e.what());
}
}
FileTools::writelog(log_DEBUG, "ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ " + to_string(sw.elapsed_ms()));
sw.reset();
buffs.clear();
if (m_param.is_autotext)
{
CImageApplyRotation::RotationType type;
/*if (m_param.imageRotateDegree > 89.0f && m_param.imageRotateDegree < 91.0f)
type = CImageApplyRotation::RotationType::Rotate_90_clockwise;
else if (m_param.imageRotateDegree > 269.0f && m_param.imageRotateDegree < 271.0f)
type = CImageApplyRotation::RotationType::Rotate_90_anti_clockwise;
else if (m_param.imageRotateDegree > 179.0f && m_param.imageRotateDegree < 181.0f)
type = CImageApplyRotation::RotationType::Rotate_180;
else*/
if (m_param.is_autotext)
type = CImageApplyRotation::RotationType::AutoTextOrientation;
else
type = CImageApplyRotation::RotationType::Invalid;//ֻ<><D6BB><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><CAB6> <20><><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>
TCHAR szIniFile[MAX_PATH] = { 0 };
SHGetSpecialFolderPath(NULL, szIniFile, CSIDL_WINDOWS, TRUE);
#ifdef LANXUM
_tcscat(szIniFile, _T("\\twain_32\\LANXUMSCAN\\tessdata"));
#else
_tcscat(szIniFile, _T("\\twain_32\\HuaGoScan\\tessdata"));
#endif //
int iLen = WideCharToMultiByte(CP_ACP, 0, szIniFile, -1, NULL, 0, NULL, NULL);
char* chRtn = new char[iLen * sizeof(char)];
WideCharToMultiByte(CP_ACP, 0, szIniFile, -1, chRtn, iLen, NULL, NULL);
CImageApplyRotation(type, m_param.is_backrotate180, m_param.resolution_dst, chRtn).apply(mats,m_param.is_duplex);
delete[] chRtn;
}
FileTools::writelog(log_DEBUG, "ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>ʱ " + to_string(sw.elapsed_ms()));
if (m_param.automaticcolor)
{
CImageApplyColorRecognition(m_param.automaticcolortype == 1 ? CImageApplyColorRecognition::ColorRecognitionMode::Color_Gray : CImageApplyColorRecognition::ColorRecognitionMode::Color_Mono).apply(mats,m_param.is_duplex);
}
for (int i = 0; i < mats.size(); i++) {
if (!mats[i].empty()) {
IMat2Bmp idata;
if (m_param.pixtype == 1 && m_param.hsvcorrect)
if (mats[i].channels() == 3)
cvtColor(mats[i], mats[i], cv::COLOR_BGR2GRAY);
idata = (isbwimg|| m_param.pixtype == 0 || (((m_param.automaticcolortype == 0) && (m_param.automaticcolor == true)) && (mats[i].channels() == 1))) ? (IMat2Bmp)Mat2BmpBw(mats[i], m_param.resolution_dst) : Mat2Bmp(mats[i], m_param.resolution_dst);
m_imagedata.Put(idata.getBmpDataBuffer());
}
}
if (m_param.multi_output_red) {
for (int i = 0; i < mats.size(); i++) {
if (!mats[i].empty()) {
ImageMultiOutput m_mlt;
cv::Mat ret = m_mlt.GetMultiFilterMat(mats[i], 2);
mats[i].release();
if (!ret.empty()) {
if (!m_param.is_duplex && i == 1) {
ret.release();
break;
}
Mat2Bmp mb(ret, m_param.resolution_dst);
m_imagedata.Put(mb.getBmpDataBuffer());
ret.release();
}
}
}
}
mats.clear();
}
int GScanO1003399::codeconvter(HGEIntInfo code)
{
if (code.From == HGType::FPGA)
{
switch (code.Code)
{
default:
break;
}
}
if (code.From == HGType::MtBoard)
{
switch (code.Code)
{
case 0x00002:
return NO_FEED;
case 0x00004:
return OPEN_COVER;
case 0x00008:
return FEED_IN_ERROR;
case 0x00010:
return PAPER_JAM;
case 0x00020:
return DETECT_DOUBLE_FEED;
case 0x00040:
return DETECT_STAPLE;
case 0x00080:
return PAPER_SKEW;
case 0x10000:
return AQUIRE_IMAGE_TIMEOUT;
case 0x20000:
return SIZE_ERROR;
default:
break;
}
}
if (code.From == HGType::V4L2)
{
switch (code.Code)
{
case 0:
return V4L2_AQULRE_ERROR;
case 1:
return V4L2_IMAGE_EMPTY;
default:
break;
}
}
if (code.From == HGType::IMG)
{
switch (code.Code)
{
case 0:
return HAVE_DOGEAR;
default:
break;
}
}
if (code.From == HGType::STOPSCAN)
return -1;
return 0;
}
void GScanO1003399::proc(bool bcachemode)
{
b_imgprothread = true;
while (b_imgprothread)
{
std::shared_ptr<std::vector<char>> buffer;
if (bcachemode) {
if (m_paths.Size() < 1)
{
this_thread::sleep_for(chrono::milliseconds(10));
continue;
}
auto path = m_paths.Take();
if (!path.empty())
{
auto fd = fopen(path.c_str(), "rb+");
if (fd)
{
auto lenght = FileTools::get_file_size(path.c_str());
buffer.reset(new std::vector<char>);
buffer->resize(lenght);
fread(buffer->data(), lenght, 1, fd);
fclose(fd);
remove(path.c_str());
}
else {
FileTools::writelog(log_ERROR, "img tmp file read error file name =" + path);
}
}
}
else
{
if (imgs.Size() < 1)
{
std::this_thread::sleep_for(chrono::milliseconds(2));
continue;
}
buffer = imgs.Take();
}
imgproce(buffer);
}
}