From 6a8302a0668dced29f5f6eef308a33ac463d519c Mon Sep 17 00:00:00 2001 From: masayume <1936714878@qq.com> Date: Fri, 23 Jul 2021 10:49:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=AB=E6=8F=8F=E4=B8=A2?= =?UTF-8?q?=E5=9B=BE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- huagao/Device/GScanO1003399.cpp | 132 +++++++++++++++++++------------- huagao/huagaods.cpp | 3 +- 2 files changed, 82 insertions(+), 53 deletions(-) diff --git a/huagao/Device/GScanO1003399.cpp b/huagao/Device/GScanO1003399.cpp index b3fd8c28..3d49af0d 100644 --- a/huagao/Device/GScanO1003399.cpp +++ b/huagao/Device/GScanO1003399.cpp @@ -42,7 +42,10 @@ GScanO1003399::GScanO1003399(): { im_data.reset(new std::vector()); open(0, 0); - + if (!m_usbthread.get()) { + b_usbthread = true; + m_usbthread.reset(new thread(&GScanO1003399::usb_run, this)); + } devState = DEV_STOP; } @@ -113,7 +116,6 @@ void GScanO1003399::DogEar_callback(std::function fun) } static int aquirenum = 0; static int getimgnum = 0; -static StopWatch stopwatch; int GScanO1003399::aquire_bmpdata(std::vector& bmpdata) { StopWatch sw; @@ -150,8 +152,6 @@ int GScanO1003399::aquire_bmpdata(std::vector& bmpdata) UpdateScanInfo(get_imgnReaded(), countNTransfered()); image--; sw.reset(); - FileTools::writelog(log_DEBUG, "3399上层取图间隔 " + to_string(stopwatch.elapsed_ms())); - stopwatch.reset(); return 0; } DoEvents(); @@ -327,6 +327,7 @@ void GScanO1003399::Scanner_StartScan(UINT16 count) { devState = DEV_WRONG; Set_ErrorCode(COUNT_MODE); + scanflag = false; return; } //if (!Get_Scanner_PaperOn()) @@ -337,10 +338,6 @@ void GScanO1003399::Scanner_StartScan(UINT16 count) //} start(); - if (!m_usbthread.get()) { - b_usbthread = true; - m_usbthread.reset(new thread(&GScanO1003399::usb_run, this)); - } } void GScanO1003399::Stop_scan() @@ -533,52 +530,53 @@ bool GScanO1003399::is_dev_tx() { return scanner_read_reg(m_usb, SR_IM_TXING); } -static StopWatch swatch; + void GScanO1003399::im_rx() { - if (!is_rx() && !is_dev_tx()) - { - fu_rx = m_imgthread.enqueue([this] { - while (im_dev_count()){ - /* code */ - if (keeplastimg) - { - this_thread::sleep_for(chrono::microseconds(10)); - if (m_param.is_duplex) { - if(im_dev_count()<3) - continue; - } - if(im_dev_count()<2) - continue; + + fu_rx = m_imgthread.enqueue([this] { + while (im_dev_count()){ + /* code */ + if (is_dev_tx()) + { + this_thread::sleep_for(chrono::microseconds(20)); + continue; + } + if (keeplastimg) + { + this_thread::sleep_for(chrono::microseconds(10)); + if (m_param.is_duplex) { + if(im_dev_count()<3) + continue; } - //auto &buffi = im_data; - std::shared_ptr> buffi(new std::vector); - int count = front_datasize(); - buffi->resize(count); - rx_cmd(); - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - count = read_data(buffi->data(), count, count / (0.01 * 1024 * 1024)); - pop_dev_im(); - vector mats; - if (m_param.multi_output_red) - image += 2; - else - image++; - UpdateScanInfo(countNReaded(), get_imgTransfered()); - FileTools::writelog(log_DEBUG, "3399usb取图间隔 " + to_string(swatch.elapsed_ms())); - swatch.reset(); - imgs.Put(buffi); - fu_imgpro.push(m_imgprocthread.enqueue([this] { - imgproce(imgs.Take()); - })); - while (fu_imgpro.size()>1) - { - fu_imgpro.front().get(); - fu_imgpro.pop(); - } - } - }); - } + if(im_dev_count()<2) + continue; + } + //auto &buffi = im_data; + std::shared_ptr> buffi(new std::vector); + int count = front_datasize(); + buffi->resize(count); + rx_cmd(); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + count = read_data(buffi->data(), count, count / (0.01 * 1024 * 1024)); + pop_dev_im(); + vector mats; + if (m_param.multi_output_red) + image += 2; + else + image++; + UpdateScanInfo(countNReaded(), get_imgTransfered()); + imgs.Put(buffi); + fu_imgpro.push(m_imgprocthread.enqueue([this] { + imgproce(imgs.Take()); + })); + while (fu_imgpro.size()>1) + { + fu_imgpro.front().get(); + fu_imgpro.pop(); + } + } + }); } int GScanO1003399::read_data(void* data, int length, int timeout) @@ -643,8 +641,38 @@ void GScanO1003399::imgproce(std::shared_ptr>& buff) FileTools::writelog(log_ERROR, e.what()); } } - FileTools::writelog(log_DEBUG, "3399图像解码耗时 " + to_string(sw.elapsed_ms())); + FileTools::writelog(log_DEBUG, "图像解码耗时 " + to_string(sw.elapsed_ms())); + sw.reset(); buffs.clear(); + if (m_param.imageRotateDegree != 0.0 || m_param.is_backrotate180 || 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 + type = CImageApplyRotation::RotationType::Invalid; + + if (m_param.is_autotext) + type = CImageApplyRotation::RotationType::AutoTextOrientation; + + 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, "图像旋转耗时 " + 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); diff --git a/huagao/huagaods.cpp b/huagao/huagaods.cpp index e7c52c7c..c6a0108b 100644 --- a/huagao/huagaods.cpp +++ b/huagao/huagaods.cpp @@ -819,7 +819,8 @@ Result HuagaoDs::identityOpenDs(const Identity&) { if (vid == 0 || pid == 0) { //ShellExecute(NULL, TEXT("open"), GetHidedlgPath(), CString("201"), NULL, SW_HIDE); - showmsg("警告", msgs[(UsbSupported)201]); + //showmsg("警告", msgs[(UsbSupported)201]); + ShellExecute(NULL, TEXT("open"), GetHidedlgPath(), CString("未找到扫描仪!请检查电源或者USB连接线是否接通! 警告"), NULL, SW_HIDE); if (hMutex) { CloseHandle(hMutex); hMutex = NULL;