1.增加除穿孔功能

2.修复TWAINEVENT回调内存异常问题
3.修复xfercount在更新时xfercount协议时更新传输张数
4.修复USB轮询检查时间间隔,以避免轮询时间间隔导致的内存读取异常问题
This commit is contained in:
pm 2019-05-10 10:51:26 +08:00
parent e0b42b7784
commit 7aa3df7bee
36 changed files with 823 additions and 270 deletions

View File

@ -5,14 +5,18 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hugaotwainds", "hugaotwaind
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.WPF", "..\wpf源码\Sample.WPF.csproj", "{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.WPF", "..\wpf源码\Sample.WPF.csproj", "{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Twacker", "H:\官方Twain工具及例子\Twacker source\TWAIN toolkit\twacker\Twacker.vcxproj", "{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64 Debug|x64 = Debug|x64
Debug|x86 = Debug|x86 Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms Release|Mixed Platforms = Release|Mixed Platforms
Release|Win32 = Release|Win32
Release|x64 = Release|x64 Release|x64 = Release|x64
Release|x86 = Release|x86 Release|x86 = Release|x86
EndGlobalSection EndGlobalSection
@ -20,6 +24,8 @@ Global
{F928F998-CD13-478E-8D23-5943C2B108F5}.Debug|Any CPU.ActiveCfg = Debug|x64 {F928F998-CD13-478E-8D23-5943C2B108F5}.Debug|Any CPU.ActiveCfg = Debug|x64
{F928F998-CD13-478E-8D23-5943C2B108F5}.Debug|Mixed Platforms.ActiveCfg = Debug|x64 {F928F998-CD13-478E-8D23-5943C2B108F5}.Debug|Mixed Platforms.ActiveCfg = Debug|x64
{F928F998-CD13-478E-8D23-5943C2B108F5}.Debug|Mixed Platforms.Build.0 = Debug|x64 {F928F998-CD13-478E-8D23-5943C2B108F5}.Debug|Mixed Platforms.Build.0 = Debug|x64
{F928F998-CD13-478E-8D23-5943C2B108F5}.Debug|Win32.ActiveCfg = Debug|Win32
{F928F998-CD13-478E-8D23-5943C2B108F5}.Debug|Win32.Build.0 = Debug|Win32
{F928F998-CD13-478E-8D23-5943C2B108F5}.Debug|x64.ActiveCfg = Debug|x64 {F928F998-CD13-478E-8D23-5943C2B108F5}.Debug|x64.ActiveCfg = Debug|x64
{F928F998-CD13-478E-8D23-5943C2B108F5}.Debug|x64.Build.0 = Debug|x64 {F928F998-CD13-478E-8D23-5943C2B108F5}.Debug|x64.Build.0 = Debug|x64
{F928F998-CD13-478E-8D23-5943C2B108F5}.Debug|x86.ActiveCfg = Debug|Win32 {F928F998-CD13-478E-8D23-5943C2B108F5}.Debug|x86.ActiveCfg = Debug|Win32
@ -27,6 +33,8 @@ Global
{F928F998-CD13-478E-8D23-5943C2B108F5}.Release|Any CPU.ActiveCfg = Release|x64 {F928F998-CD13-478E-8D23-5943C2B108F5}.Release|Any CPU.ActiveCfg = Release|x64
{F928F998-CD13-478E-8D23-5943C2B108F5}.Release|Mixed Platforms.ActiveCfg = Release|x64 {F928F998-CD13-478E-8D23-5943C2B108F5}.Release|Mixed Platforms.ActiveCfg = Release|x64
{F928F998-CD13-478E-8D23-5943C2B108F5}.Release|Mixed Platforms.Build.0 = Release|x64 {F928F998-CD13-478E-8D23-5943C2B108F5}.Release|Mixed Platforms.Build.0 = Release|x64
{F928F998-CD13-478E-8D23-5943C2B108F5}.Release|Win32.ActiveCfg = Release|Win32
{F928F998-CD13-478E-8D23-5943C2B108F5}.Release|Win32.Build.0 = Release|Win32
{F928F998-CD13-478E-8D23-5943C2B108F5}.Release|x64.ActiveCfg = Release|x64 {F928F998-CD13-478E-8D23-5943C2B108F5}.Release|x64.ActiveCfg = Release|x64
{F928F998-CD13-478E-8D23-5943C2B108F5}.Release|x64.Build.0 = Release|x64 {F928F998-CD13-478E-8D23-5943C2B108F5}.Release|x64.Build.0 = Release|x64
{F928F998-CD13-478E-8D23-5943C2B108F5}.Release|x86.ActiveCfg = Release|Win32 {F928F998-CD13-478E-8D23-5943C2B108F5}.Release|x86.ActiveCfg = Release|Win32
@ -35,6 +43,7 @@ Global
{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Debug|Any CPU.Build.0 = Debug|Any CPU {1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU {1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Debug|Win32.ActiveCfg = Debug|x86
{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Debug|x64.ActiveCfg = Debug|x86 {1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Debug|x64.ActiveCfg = Debug|x86
{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Debug|x86.ActiveCfg = Debug|x86 {1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Debug|x86.ActiveCfg = Debug|x86
{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Debug|x86.Build.0 = Debug|x86 {1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Debug|x86.Build.0 = Debug|x86
@ -42,9 +51,26 @@ Global
{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Release|Any CPU.Build.0 = Release|Any CPU {1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Release|Any CPU.Build.0 = Release|Any CPU
{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Release|Mixed Platforms.Build.0 = Release|Any CPU {1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Release|Win32.ActiveCfg = Release|x86
{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Release|x64.ActiveCfg = Release|x86 {1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Release|x64.ActiveCfg = Release|x86
{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Release|x86.ActiveCfg = Release|x86 {1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Release|x86.ActiveCfg = Release|x86
{1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Release|x86.Build.0 = Release|x86 {1715C2B7-5C35-4F8B-9D9B-8D68A3D5284D}.Release|x86.Build.0 = Release|x86
{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}.Debug|Any CPU.ActiveCfg = Debug|x64
{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}.Debug|Mixed Platforms.ActiveCfg = Debug|x64
{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}.Debug|Mixed Platforms.Build.0 = Debug|x64
{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}.Debug|Win32.ActiveCfg = Debug|Win32
{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}.Debug|Win32.Build.0 = Debug|Win32
{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}.Debug|x64.ActiveCfg = Debug|x64
{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}.Debug|x64.Build.0 = Debug|x64
{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}.Debug|x86.ActiveCfg = Debug|Win32
{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}.Release|Any CPU.ActiveCfg = Release|x64
{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}.Release|Mixed Platforms.ActiveCfg = Release|x64
{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}.Release|Mixed Platforms.Build.0 = Release|x64
{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}.Release|Win32.ActiveCfg = Release|Win32
{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}.Release|Win32.Build.0 = Release|Win32
{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}.Release|x64.ActiveCfg = Release|x64
{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}.Release|x64.Build.0 = Release|x64
{3A13A242-7ED1-4167-8C39-15ABC3AD3A8A}.Release|x86.ActiveCfg = Release|x64
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Binary file not shown.

View File

@ -141,35 +141,22 @@ int CAutoCrop::ProcessRect(Mat & image, RotatedRect & rotatedRect, vector<Point>
} }
Mat threshold_img; Mat threshold_img;
threshold(gray, threshold_img, thresh, 255.0, CV_THRESH_BINARY); threshold(gray, threshold_img, thresh, 255.0, CV_THRESH_BINARY);
//imwrite("threshold_img.bmp",threshold_img);
//vector<Point> aaa;
//aaa.push_back(Point(0, 0));
//double bbb = contourArea(aaa);
vector<vector<Point>> contours; vector<vector<Point>> contours;
//XdPrint("findContours Before \n");
vector<Vec4i> h1; vector<Vec4i> h1;
//findContours(threshold_img,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
GetContours(threshold_img, contours,h1,CV_RETR_EXTERNAL); GetContours(threshold_img, contours,h1,CV_RETR_EXTERNAL);
//XdPrint("threshold_img.release() Before \n");
threshold_img.release();
//XdPrint("findContours after \n");
//for (int i=0;i<contours.size();i++) threshold_img.release();
//{
// XdPrint("Conutours %d",contours[i].size());
//}
if (contours.size() == 0) if (contours.size() == 0)
{ {
return blockCount; return blockCount;
} }
vector<Point> list_com; vector<Point> list_com;
////XdPrint("contours.size() %d \n",contours.size());
for (int i = 0; i < contours.size(); i++) for (int i = 0; i < contours.size(); i++)
{ {
double area = contourArea(contours[i]); double area = contourArea(contours[i]);
//XdPrint("area %f \n",area);
//XdPrint("contours.Cycle times %d \n",i);
if (area > blobAreaSize) if (area > blobAreaSize)
{ {
blockCount++; blockCount++;
@ -184,14 +171,14 @@ int CAutoCrop::ProcessRect(Mat & image, RotatedRect & rotatedRect, vector<Point>
{ {
return blockCount; return blockCount;
} }
////XdPrint("minAreaRect Before \n ");
rotatedRect = minAreaRect(list_com); rotatedRect = minAreaRect(list_com);
rotatedRect.center.x /= (float)scale; rotatedRect.center.x /= (float)scale;
rotatedRect.center.y /= (float)scale; rotatedRect.center.y /= (float)scale;
rotatedRect.size.width /= (float)scale; rotatedRect.size.width /= (float)scale;
rotatedRect.size.height /= (float)scale; rotatedRect.size.height /= (float)scale;
////XdPrint("rotatedRect.angle < -45.0f \n");
if (rotatedRect.angle < -45.0f) if (rotatedRect.angle < -45.0f)
{ {
rotatedRect.angle += 90.0f; rotatedRect.angle += 90.0f;
@ -201,10 +188,7 @@ int CAutoCrop::ProcessRect(Mat & image, RotatedRect & rotatedRect, vector<Point>
} }
vector<int> hull(list_com.size()); vector<int> hull(list_com.size());
//for (int i=0;i<list_com.size();i++)
//{
// XdPrint("X :%d Y:%d \n",list_com[i].x,list_com[i].y);
//}
convexHull(list_com, hull); convexHull(list_com, hull);
for (int i = 0; i < hull.size(); i++) for (int i = 0; i < hull.size(); i++)
{ {

View File

@ -55,6 +55,10 @@
#include "ImageApplyResize.h" #include "ImageApplyResize.h"
#include "ImageRotation.h" #include "ImageRotation.h"
#include "ImageProcDiscardBlank.h" #include "ImageProcDiscardBlank.h"
#include "filetools.h"
#include "hugaotwainds.h"
extern ChugaotwaindsApp theApp;
#ifdef TWH_CMP_MSC #ifdef TWH_CMP_MSC
#include <io.h> #include <io.h>
#elif __APPLE__ #elif __APPLE__
@ -128,7 +132,7 @@ class ImageTranferBW : public ImageTransfer
public: public:
ImageTranferBW(cv::Mat& mat) ImageTranferBW(cv::Mat& mat)
{ {
threshold(mat,mat,128.0,255.0,CV_THRESH_BINARY); threshold(mat,mat,220.0,255.0,CV_THRESH_BINARY);
//imwrite("threshold.bmp",mat); //imwrite("threshold.bmp",mat);
m_width = mat.cols; m_width = mat.cols;
m_height = mat.rows; m_height = mat.rows;
@ -547,20 +551,59 @@ SFreeImage* CScanner_FreeImage::getSetting() const
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
bool CScanner_FreeImage::acquireImage(bool bscan) bool CScanner_FreeImage::acquireImage(bool bscan)
{ {
if (g_drv.IsConnected()) //if (g_drv.IsConnected())
{ //{
g_drv.run(); // g_drv.run();
} //}
if (bscan) if (bscan)
{ {
if (getDeviceOnline()) if (getDeviceOnline())
{ {
USBCB checkStatus= g_drv.Get_Scanner_Status();
UINT32 u32Data=checkStatus.u32_Data;
std::string notify=StringToUtf("提示");
int res;
std::string msg;
switch (u32Data)
{
case COUNT_MODE:
{
msg=StringToUtf("计数模式,请先退出计数模式!");
MessageBox(theApp.m_pMainWnd->GetSafeHwnd(),msg.c_str(),notify.c_str(),MB_ICONINFORMATION|MB_OK);
return false;
}
//case OPEN_COVER:
// {
// msg=StringToUtf("开盖!请关闭扫描仪盖!");
// MessageBox(theApp.m_pMainWnd->GetSafeHwnd(),msg.c_str(),notify.c_str(),MB_ICONINFORMATION|MB_OK);
// return false;
// }
//case PAPER_JAM:
// {
// msg=StringToUtf("卡纸!");
// MessageBox(theApp.m_pMainWnd->GetSafeHwnd(),msg.c_str(),notify.c_str(),MB_ICONINFORMATION|MB_OK);
// return false;
// }
//case HARDWARE_ERROR:
// {
// msg=StringToUtf("硬件错误!");
// MessageBox(theApp.m_pMainWnd->GetSafeHwnd(),msg.c_str(),notify.c_str(),MB_ICONINFORMATION|MB_OK);
// return false;
// }
//case PC_SCAN_BUSY_or_ERROR:
// {
// msg=StringToUtf("PC错误");
// MessageBox(theApp.m_pMainWnd->GetSafeHwnd(),msg.c_str(),notify.c_str(),MB_ICONINFORMATION|MB_OK);
// return false;
// }
default:
break;
}
while (!isPaperOn()) while (!isPaperOn())
{ {
std::string cvt=StringToUtf("纸仓内无纸,请放纸!"); std::string cvt=StringToUtf("纸仓内无纸,请放纸!");
std::string notify=StringToUtf("提示"); res= MessageBox(NULL, cvt.c_str(),notify.c_str(), MB_OKCANCEL | MB_ICONINFORMATION);
int res= MessageBox(NULL, cvt.c_str(),notify.c_str(), MB_OKCANCEL | MB_ICONINFORMATION);
switch (res) switch (res)
{ {
case IDCANCEL: case IDCANCEL:
@ -569,6 +612,7 @@ bool CScanner_FreeImage::acquireImage(bool bscan)
} }
UpdateList(); UpdateList();
g_drv.setlist(m_iaList); g_drv.setlist(m_iaList);
g_drv.SetIsDuplex(m_bDuplex);
hgConfigClass cf; hgConfigClass cf;
cf.setDoubleFeedEnable(m_HardWareParams.DoubleFeederOn); cf.setDoubleFeedEnable(m_HardWareParams.DoubleFeederOn);
cf.setResolution(200.0); cf.setResolution(200.0);
@ -603,14 +647,17 @@ bool CScanner_FreeImage::acquireImage(bool bscan)
default: default:
break; break;
} }
g_drv.ResetScanner();//初始化DSP状态
cf.setStapleEnable(m_HardWareParams.StapleDetectOn); cf.setStapleEnable(m_HardWareParams.StapleDetectOn);
cf.setTwPixelType(m_HardWareParams.PixType); cf.setTwPixelType(m_HardWareParams.PixType);
cf.settwSS(m_HardWareParams.PaperType); cf.settwSS(m_HardWareParams.PaperType);
UINT32 cfg_Value =cf.GetData(); UINT32 cfg_Value =cf.GetData();
USBCB usbcb = { CONFIGURED_DATA , cfg_Value,0 }; USBCB usbcb = { CONFIGURED_DATA , cfg_Value,0 };
g_drv.set_decompress_pix_type(m_HardWareParams.PixType); g_drv.set_decompress_pix_type(m_HardWareParams.PixType);
g_drv.SetOutHoleParam(m_OutHole);
g_drv.Config_Scanner(&usbcb); g_drv.Config_Scanner(&usbcb);
g_drv.Scanner_StartScan(m_bDuplex?m_wScanCount/2:m_wScanCount); g_drv.run();
g_drv.Scanner_StartScan(m_wScanCount);
} }
else else
{ {
@ -623,6 +670,7 @@ bool CScanner_FreeImage::acquireImage(bool bscan)
#ifdef HW_VER #ifdef HW_VER
m_matDib.release(); m_matDib.release();
//m_matDib=imread("D:/1.jpg");
int ret = g_drv.aquire_image(m_matDib); int ret = g_drv.aquire_image(m_matDib);
//imwrite("1.bmp",m_matDib); //imwrite("1.bmp",m_matDib);
if (ret) if (ret)
@ -771,6 +819,11 @@ void CScanner_FreeImage::UpdateList(bool canUpdate/*=true*/)
m_iaList.push_back(shared_ptr<CImageApply>(new CImageProcDiscardBlank(m_bAutoDiscardBlank?true:false))); m_iaList.push_back(shared_ptr<CImageApply>(new CImageProcDiscardBlank(m_bAutoDiscardBlank?true:false)));
} }
if(m_HardWareParams.PaperType==90)
{
m_bAutoCrop=true;
}
m_iaList.push_back(shared_ptr<CImageApply>(new CAutoCrop(m_bFillBlackRect, m_bAutoDeskew, m_bAutoCrop,getSize((TwSS)m_HardWareParams.PaperType,m_fXResolution),getSize((TwSS)m_HardWareParams.PaperType,200.0)))); m_iaList.push_back(shared_ptr<CImageApply>(new CAutoCrop(m_bFillBlackRect, m_bAutoDeskew, m_bAutoCrop,getSize((TwSS)m_HardWareParams.PaperType,m_fXResolution),getSize((TwSS)m_HardWareParams.PaperType,200.0))));
if (m_nFilter) if (m_nFilter)
@ -791,7 +844,6 @@ void CScanner_FreeImage::UpdateList(bool canUpdate/*=true*/)
{ {
m_iaList.push_back(shared_ptr<CImageApply>(new CImageRotation(m_wRotation,m_bBackRotate180))); m_iaList.push_back(shared_ptr<CImageApply>(new CImageRotation(m_wRotation,m_bBackRotate180)));
} }
g_drv.SetIsDuplex(m_bDuplex);
} }
@ -874,6 +926,7 @@ bool CScanner_FreeImage::isImageQueueEmpty()
bool ret=true; bool ret=true;
if (!g_drv.is_scan()&&g_drv.Get_IsImageQueueEmpty()) if (!g_drv.is_scan()&&g_drv.Get_IsImageQueueEmpty())
{ {
//FileTools::write_log("D:/1.txt","!g_drv.is_scan()&&g_drv.Get_IsImageQueueEmpty()");
m_nDocCount=0; m_nDocCount=0;
} }
else else

View File

@ -151,6 +151,7 @@ struct SFreeImage
WORD m_wRotation; /**< 旋转方向*/ WORD m_wRotation; /**< 旋转方向*/
bool m_bBackRotate180; /**< 背面旋转180*/ bool m_bBackRotate180; /**< 背面旋转180*/
HARDWAREPARAMS m_HardWareParams; /**< 硬件扫描参数*/ HARDWAREPARAMS m_HardWareParams; /**< 硬件扫描参数*/
OutHole m_OutHole;
}; };
class CImageProc; class CImageProc;

View File

@ -37,7 +37,8 @@
*/ */
#include "stdafx.h" #include "stdafx.h"
#include "CTWAINDS_Base.h" #include "CTWAINDS_Base.h"
#include "filetools.h"
#include <Windows.h>
#if (TWNDS_CMP == TWNDS_CMP_VISUALCPP) #if (TWNDS_CMP == TWNDS_CMP_VISUALCPP)
#include <io.h> #include <io.h>
#endif #endif
@ -108,57 +109,82 @@ TW_UINT16 CTWAINDS_Base::DS_Entry( pTW_IDENTITY _pOrigin,
{ {
TW_INT16 twrc = TWRC_SUCCESS; TW_INT16 twrc = TWRC_SUCCESS;
//string ss;
switch (_DG) switch (_DG)
{ {
case DG_CONTROL: case DG_CONTROL:
{ {
//ss="DG_CONTROL";
switch (_DAT) switch (_DAT)
{ {
case DAT_EVENT: case DAT_EVENT:
{
//ss+=" DAT_EVENT";
twrc = dat_event(_MSG, (pTW_EVENT) _pData); twrc = dat_event(_MSG, (pTW_EVENT) _pData);
}
break; break;
case DAT_IDENTITY: case DAT_IDENTITY:
{
//ss+=" DAT_IDENTITY";
twrc = dat_identity(_pOrigin, _MSG, (pTW_IDENTITY) _pData); twrc = dat_identity(_pOrigin, _MSG, (pTW_IDENTITY) _pData);
}
break; break;
case DAT_CAPABILITY: case DAT_CAPABILITY:
//ss+=" DAT_CAPABILITY";
twrc = dat_capability(_MSG, (pTW_CAPABILITY) _pData); twrc = dat_capability(_MSG, (pTW_CAPABILITY) _pData);
break; break;
case DAT_USERINTERFACE: case DAT_USERINTERFACE:
{
//ss+=" DAT_USERINTERFACE";
twrc = dat_userinterface(_MSG, (pTW_USERINTERFACE) _pData); twrc = dat_userinterface(_MSG, (pTW_USERINTERFACE) _pData);
}
break; break;
case DAT_SETUPFILEXFER: case DAT_SETUPFILEXFER:
//ss+=" DAT_SETUPFILEXFER";
twrc = dat_setupfilexfer(_MSG, (pTW_SETUPFILEXFER) _pData); twrc = dat_setupfilexfer(_MSG, (pTW_SETUPFILEXFER) _pData);
break; break;
case DAT_SETUPMEMXFER: case DAT_SETUPMEMXFER:
{
//ss+=" DAT_SETUPMEMXFER";
twrc = dat_setupmemxfer(_MSG, (pTW_SETUPMEMXFER) _pData); twrc = dat_setupmemxfer(_MSG, (pTW_SETUPMEMXFER) _pData);
}
break; break;
case DAT_STATUS: case DAT_STATUS:
{
//ss+=" DAT_STATUS";
twrc = dat_status(_MSG, (pTW_STATUS) _pData); twrc = dat_status(_MSG, (pTW_STATUS) _pData);
}
break; break;
case DAT_PENDINGXFERS: case DAT_PENDINGXFERS:
//ss+=" DAT_PENDINGXFERS";
twrc = dat_pendingxfers(_MSG, (pTW_PENDINGXFERS)_pData); twrc = dat_pendingxfers(_MSG, (pTW_PENDINGXFERS)_pData);
break; break;
case DAT_ENTRYPOINT: case DAT_ENTRYPOINT:
//ss+=" DAT_ENTRYPOINT";
twrc = dat_entrypoint(_MSG, (pTW_ENTRYPOINT)_pData); twrc = dat_entrypoint(_MSG, (pTW_ENTRYPOINT)_pData);
break; break;
case DAT_XFERGROUP: case DAT_XFERGROUP:
//ss="DAT_XFERGROUP";
twrc = dat_xfergroup(_MSG, (pTW_UINT32)_pData); twrc = dat_xfergroup(_MSG, (pTW_UINT32)_pData);
break; break;
case DAT_CUSTOMDSDATA: case DAT_CUSTOMDSDATA:
//ss+=" DAT_CUSTOMDSDATA";
twrc = dat_customdsdata(_MSG, (pTW_CUSTOMDSDATA)_pData); twrc = dat_customdsdata(_MSG, (pTW_CUSTOMDSDATA)_pData);
break; break;
default: default:
//ss="setConditionCode(TWCC_BADPROTOCOL)";
setConditionCode(TWCC_BADPROTOCOL); setConditionCode(TWCC_BADPROTOCOL);
//assert(0); //assert(0);
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
@ -169,38 +195,47 @@ TW_UINT16 CTWAINDS_Base::DS_Entry( pTW_IDENTITY _pOrigin,
case DG_IMAGE: case DG_IMAGE:
{ {
// ss="DG_IMAGE ";
switch (_DAT) switch (_DAT)
{ {
case DAT_IMAGEINFO: case DAT_IMAGEINFO:
//ss+="DAT_IMAGEINFO";
twrc = dat_imageinfo(_MSG, (pTW_IMAGEINFO)_pData); twrc = dat_imageinfo(_MSG, (pTW_IMAGEINFO)_pData);
break; break;
case DAT_IMAGENATIVEXFER: case DAT_IMAGENATIVEXFER:
if(0 == _pData) if(0 == _pData)
{ {
//ss+="DAT_IMAGENATIVEXFER Error";
setConditionCode(TWCC_BADVALUE); setConditionCode(TWCC_BADVALUE);
return TWRC_FAILURE; return TWRC_FAILURE;
} }
//ss+="DAT_IMAGENATIVEXFER";
twrc = dat_imagenativexfer(_MSG, *((TW_HANDLE*)_pData)); twrc = dat_imagenativexfer(_MSG, *((TW_HANDLE*)_pData));
break; break;
case DAT_IMAGEFILEXFER: case DAT_IMAGEFILEXFER:
//ss+="DAT_IMAGEFILEXFER";
twrc = dat_imagefilexfer(_MSG); twrc = dat_imagefilexfer(_MSG);
break; break;
case DAT_IMAGEMEMXFER: case DAT_IMAGEMEMXFER:
//ss+="DAT_IMAGEMEMXFER";
twrc = dat_imagememxfer(_MSG, (pTW_IMAGEMEMXFER)_pData); twrc = dat_imagememxfer(_MSG, (pTW_IMAGEMEMXFER)_pData);
break; break;
case DAT_IMAGELAYOUT: case DAT_IMAGELAYOUT:
//ss+="DAT_IMAGELAYOUT";
twrc = dat_imagelayout(_MSG, (pTW_IMAGELAYOUT)_pData); twrc = dat_imagelayout(_MSG, (pTW_IMAGELAYOUT)_pData);
break; break;
case DAT_EXTIMAGEINFO: case DAT_EXTIMAGEINFO:
//ss+="DAT_EXTIMAGEINFO";
twrc = dat_extimageinfo(_MSG, (pTW_EXTIMAGEINFO)_pData); twrc = dat_extimageinfo(_MSG, (pTW_EXTIMAGEINFO)_pData);
break; break;
default: default:
//ss+="default setConditionCode(TWCC_CAPUNSUPPORTED)";
setConditionCode(TWCC_CAPUNSUPPORTED); setConditionCode(TWCC_CAPUNSUPPORTED);
//assert(0); //assert(0);
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
@ -210,12 +245,14 @@ TW_UINT16 CTWAINDS_Base::DS_Entry( pTW_IDENTITY _pOrigin,
break; break;
default: default:
//ss+="default setConditionCode(TWCC_CAPUNSUPPORTED)";
setConditionCode(TWCC_CAPUNSUPPORTED); setConditionCode(TWCC_CAPUNSUPPORTED);
//assert(0); //assert(0);
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
break; break;
} }
//ss+=twrc==TWRC_FAILURE?" TWRC_FAILURE":" TWRC_SUCCESS";
//FileTools::write_log("D:/1.txt",ss);
return twrc; return twrc;
} }
@ -256,20 +293,23 @@ TW_INT16 CTWAINDS_Base::dat_identity(pTW_IDENTITY _pOrigin,
pTW_IDENTITY _pData) pTW_IDENTITY _pData)
{ {
TW_INT16 twrc = TWRC_SUCCESS; TW_INT16 twrc = TWRC_SUCCESS;
//string ss="dat_identity ";
switch(_MSG) switch(_MSG)
{ {
case MSG_GET: case MSG_GET:
//ss+="MSG_GET";
memcpy(_pData, &m_MyIdentity, sizeof(TW_IDENTITY)); memcpy(_pData, &m_MyIdentity, sizeof(TW_IDENTITY));
break; break;
case MSG_OPENDS: case MSG_OPENDS:
// store the id assigned to us by the DSM. // store the id assigned to us by the DSM.
//ss+="MSG_OPENDS ";
m_MyIdentity.Id = _pData->Id; m_MyIdentity.Id = _pData->Id;
twrc = openDS(_pOrigin); twrc = openDS(_pOrigin);
break; break;
case MSG_CLOSEDS: case MSG_CLOSEDS:
//ss+="MSG_CLOSEDS ";
twrc = closeDS(); twrc = closeDS();
break; break;
@ -279,7 +319,8 @@ TW_INT16 CTWAINDS_Base::dat_identity(pTW_IDENTITY _pOrigin,
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
break; break;
} }
//ss+=twrc==TWRC_SUCCESS?"TWRC_SUCCESS":"TWRC_FAILURE";
//FileTools::write_log("D:/1.txt",ss);
return twrc; return twrc;
} }
@ -287,10 +328,7 @@ TW_INT16 CTWAINDS_Base::dat_identity(pTW_IDENTITY _pOrigin,
TW_INT16 CTWAINDS_Base::dat_capability(TW_UINT16 _MSG, TW_INT16 CTWAINDS_Base::dat_capability(TW_UINT16 _MSG,
pTW_CAPABILITY _pCap) pTW_CAPABILITY _pCap)
{ {
if (_pCap->Cap==4156)
{
}
TW_INT16 twrc = TWRC_FAILURE; TW_INT16 twrc = TWRC_FAILURE;
if(MSG_RESETALL == _MSG) // special case if(MSG_RESETALL == _MSG) // special case
@ -299,6 +337,7 @@ TW_INT16 CTWAINDS_Base::dat_capability(TW_UINT16 _MSG,
if(m_CurrentState >= dsState_Enabled) if(m_CurrentState >= dsState_Enabled)
{ {
setConditionCode(TWCC_SEQERROR); setConditionCode(TWCC_SEQERROR);
//FileTools::write_log("D:/1.txt","dat_capability m_CurrentState >= dsState_Enabled");
return TWRC_FAILURE; return TWRC_FAILURE;
} }
// Loop through all supported caps and reset them. // Loop through all supported caps and reset them.
@ -306,6 +345,7 @@ TW_INT16 CTWAINDS_Base::dat_capability(TW_UINT16 _MSG,
CTWAINContainerInt *pCapSC = dynamic_cast<CTWAINContainerInt*>(findCapability(CAP_SUPPORTEDCAPS)); CTWAINContainerInt *pCapSC = dynamic_cast<CTWAINContainerInt*>(findCapability(CAP_SUPPORTEDCAPS));
if(!pCapSC) if(!pCapSC)
{ {
//FileTools::write_log("D:/1.txt","dat_capability !pCapSC");
setConditionCode(TWCC_BADCAP); setConditionCode(TWCC_BADCAP);
return TWRC_FAILURE; return TWRC_FAILURE;
} }
@ -323,6 +363,12 @@ TW_INT16 CTWAINDS_Base::dat_capability(TW_UINT16 _MSG,
{ {
if(!pCap->Reset()) if(!pCap->Reset())
{ {
//ostringstream os;
//os<<pCap->GetCapID();
//istringstream is(os.str());
//string out;
//is>>out;
//FileTools::write_log("D:/1.txt","dat_capability !pCap->Reset())"+out);
setConditionCode(TWCC_CAPUNSUPPORTED); setConditionCode(TWCC_CAPUNSUPPORTED);
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
} }
@ -335,6 +381,7 @@ TW_INT16 CTWAINDS_Base::dat_capability(TW_UINT16 _MSG,
// check for invalid args // check for invalid args
if(0 == _pCap) if(0 == _pCap)
{ {
//FileTools::write_log("D:/1.txt","0 == _pCap");
setConditionCode(TWCC_BADVALUE); setConditionCode(TWCC_BADVALUE);
return TWRC_FAILURE; return TWRC_FAILURE;
} }
@ -346,6 +393,26 @@ TW_INT16 CTWAINDS_Base::dat_capability(TW_UINT16 _MSG,
if(0 != pCap) if(0 != pCap)
{ {
twrc = handleCap(_MSG, pCap, _pCap); twrc = handleCap(_MSG, pCap, _pCap);
if (twrc!=TWRC_SUCCESS)
{
//ostringstream os;
//os<<pCap->GetCapID();
//istringstream is(os.str());
//string out;
//is>>out;
//ostringstream osc;
//osc<<_MSG;
//istringstream isc(osc.str());
//string sc;
//isc>> sc;
//ostringstream osrc;
//osrc<<twrc;
//istringstream isrc(osrc.str());
//string src;
//isrc>> src;
//FileTools::write_log("D:/1.txt","handleCap "+out+"MSG "+sc +"TWRC "+src );
}
// when some capabilities are successfully changed with Set or Reset // when some capabilities are successfully changed with Set or Reset
// it requires changing others // it requires changing others
@ -353,6 +420,15 @@ TW_INT16 CTWAINDS_Base::dat_capability(TW_UINT16 _MSG,
(MSG_SET == _MSG || MSG_RESET == _MSG) ) (MSG_SET == _MSG || MSG_RESET == _MSG) )
{ {
TW_INT16 twrc2 = updatePostDependencies(_MSG, _pCap->Cap); TW_INT16 twrc2 = updatePostDependencies(_MSG, _pCap->Cap);
//if (twrc2!=TWRC_SUCCESS)
//{
//ostringstream os;
//os<<pCap->GetCapID();
//istringstream is(os.str());
//string out;
//is>>out;
//FileTools::write_log("D:/1.txt","handleCap 1 "+out);
//}
if(twrc == TWRC_SUCCESS && twrc2 != TWRC_SUCCESS) if(twrc == TWRC_SUCCESS && twrc2 != TWRC_SUCCESS)
{ {
twrc = twrc2; twrc = twrc2;
@ -428,7 +504,7 @@ TW_INT16 CTWAINDS_Base::dat_setupfilexfer( TW_UINT16 _MSG,
pTW_SETUPFILEXFER _pData) pTW_SETUPFILEXFER _pData)
{ {
TW_INT16 twrc = TWRC_SUCCESS; TW_INT16 twrc = TWRC_SUCCESS;
//FileTools::write_log("D:/1.txt","dat_setupfilexfer");
switch(_MSG) switch(_MSG)
{ {
case MSG_GET: case MSG_GET:
@ -462,7 +538,7 @@ TW_INT16 CTWAINDS_Base::dat_setupmemxfer(TW_UINT16 _MSG,
pTW_SETUPMEMXFER _pData) pTW_SETUPMEMXFER _pData)
{ {
TW_INT16 twrc = TWRC_SUCCESS; TW_INT16 twrc = TWRC_SUCCESS;
//FileTools::write_log("D:/1.txt","getMemoryXfer");
switch(_MSG) switch(_MSG)
{ {
case MSG_GET: case MSG_GET:
@ -587,9 +663,11 @@ TW_INT16 CTWAINDS_Base::dat_imagelayout(TW_UINT16,
TW_INT16 CTWAINDS_Base::dat_extimageinfo(TW_UINT16, TW_INT16 CTWAINDS_Base::dat_extimageinfo(TW_UINT16,
pTW_EXTIMAGEINFO) pTW_EXTIMAGEINFO)
{ {
//pTW_EXTIMAGEINFO->Info[0].
// This should be implemented in the derived class. // This should be implemented in the derived class.
setConditionCode(TWCC_CAPUNSUPPORTED); setConditionCode(TWCC_CAPUNSUPPORTED);
return TWRC_FAILURE; return TWRC_FAILURE;
//return TWRC_SUCCESS;
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -673,14 +751,17 @@ TW_INT16 CTWAINDS_Base::dat_pendingxfers(TW_UINT16 _MSG,
switch(_MSG) switch(_MSG)
{ {
case MSG_ENDXFER: case MSG_ENDXFER:
//FileTools::write_log("D:/1.txt","dat_pendingxfers endxfer");
twrc = endXfer(_pXfers); twrc = endXfer(_pXfers);
break; break;
case MSG_GET: case MSG_GET:
//FileTools::write_log("D:/1.txt","dat_pendingxfers getXfer");
twrc = getXfer(_pXfers); twrc = getXfer(_pXfers);
break; break;
case MSG_RESET: case MSG_RESET:
//FileTools::write_log("D:/1.txt","dat_pendingxfers resetXfer");
twrc = resetXfer(_pXfers); twrc = resetXfer(_pXfers);
break; break;
@ -866,6 +947,7 @@ bool CTWAINDS_Base::DoCloseDSOkEvent()
0)) 0))
{ {
bRC = true; bRC = true;
//FileTools::write_log("D:/1.txt"," DoCloseDSOkEvent");
} }
#endif #endif
return bRC; return bRC;
@ -912,6 +994,7 @@ TW_INT16 CTWAINDS_Base::handleCap(TW_UINT16 _MSG, TWAINContainerType* _pContaine
// first check if the operation is allowed on this container // first check if the operation is allowed on this container
if(!_pContainer->isOperationAllowed(_MSG)) if(!_pContainer->isOperationAllowed(_MSG))
{ {
//FileTools::write_log("D:/1.txt","handleCap !_pContainer->isOperationAllowed(_MSG)");
setConditionCode(TWCC_CAPBADOPERATION); setConditionCode(TWCC_CAPBADOPERATION);
return TWRC_FAILURE; return TWRC_FAILURE;
} }
@ -949,6 +1032,7 @@ TW_INT16 CTWAINDS_Base::handleCap(TW_UINT16 _MSG, TWAINContainerType* _pContaine
//MSG_RESET is supposed to reset and then return the current value //MSG_RESET is supposed to reset and then return the current value
if(m_CurrentState >= dsState_Enabled) if(m_CurrentState >= dsState_Enabled)
{ {
//FileTools::write_log("D:/1.txt"," handleCap m_CurrentState >= dsState_Enabled");
setConditionCode(TWCC_SEQERROR); setConditionCode(TWCC_SEQERROR);
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
break; break;
@ -963,17 +1047,23 @@ TW_INT16 CTWAINDS_Base::handleCap(TW_UINT16 _MSG, TWAINContainerType* _pContaine
twrc = updatePreDependencies(_pContainer); twrc = updatePreDependencies(_pContainer);
if(twrc != TWRC_SUCCESS) if(twrc != TWRC_SUCCESS)
{ {
//FileTools::write_log("D:/1.txt"," handleCap twrc != TWRC_SUCCESS");
break; break;
} }
_pCap->hContainer = _pContainer->GetContainer(_MSG); _pCap->hContainer = _pContainer->GetContainer(_MSG);
twrc = updatePostContainer(_pCap); twrc = updatePostContainer(_pCap);
if (twrc!=TWRC_SUCCESS)
{
//FileTools::write_log("D:/1.txt"," handleCap twrc != TWRC_SUCCESS 2");
}
break; break;
case MSG_SET: case MSG_SET:
{ {
if(m_CurrentState >= dsState_Enabled) if(m_CurrentState >= dsState_Enabled)
{ {
//FileTools::write_log("D:/1.txt"," handleCap MSG_SET m_CurrentState >= dsState_Enabled");
setConditionCode(TWCC_SEQERROR); setConditionCode(TWCC_SEQERROR);
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
break; break;
@ -981,29 +1071,37 @@ TW_INT16 CTWAINDS_Base::handleCap(TW_UINT16 _MSG, TWAINContainerType* _pContaine
twrc = updatePreDependencies(_pContainer); twrc = updatePreDependencies(_pContainer);
if(twrc != TWRC_SUCCESS) if(twrc != TWRC_SUCCESS)
{ {
//FileTools::write_log("D:/1.txt"," handleCap MSG_SET twrc != TWRC_SUCCESS 3");
break; break;
} }
twrc = updatePreContainer(_pCap); twrc = updatePreContainer(_pCap);
if(twrc!=TWRC_SUCCESS) if(twrc!=TWRC_SUCCESS)
{ {
//FileTools::write_log("D:/1.txt"," handleCap MSG_SET twrc != TWRC_SUCCESS 4");
break; break;
} }
BYTE * pContainer = (BYTE*)_DSM_LockMemory(_pCap->hContainer); BYTE * pContainer = (BYTE*)_DSM_LockMemory(_pCap->hContainer);
if(pContainer==0) if(pContainer==0)
{ {
setConditionCode(TWCC_LOWMEMORY); setConditionCode(TWCC_LOWMEMORY);
//FileTools::write_log("D:/1.txt"," pContainer==0 512");
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
break; break;
} }
twrc = validateCapabilitySet(_pCap->Cap,_pCap->ConType, pContainer); twrc = validateCapabilitySet(_pCap->Cap,_pCap->ConType, pContainer);
//if (twrc!=TWRC_SUCCESS)
//{
// FileTools::write_log("D:/1.txt"," pContainer==0 1024");
//}
_DSM_UnlockMemory(_pCap->hContainer); _DSM_UnlockMemory(_pCap->hContainer);
if(twrc != TWRC_SUCCESS) if(twrc != TWRC_SUCCESS)
{ {
setConditionCode(TWCC_BADVALUE); setConditionCode(TWCC_BADVALUE);
if(twrc == TWRC_FAILURE) // if(twrc == TWRC_FAILURE)
{ // {
break; //FileTools::write_log("D:/1.txt"," handleCap MSG_SET twrc = validateCapabilitySet(_pCap->Cap,_pCap->ConType, pContainer);");
} // break;
// }
} }
TW_INT16 Condition; TW_INT16 Condition;
@ -1013,6 +1111,7 @@ TW_INT16 CTWAINDS_Base::handleCap(TW_UINT16 _MSG, TWAINContainerType* _pContaine
setConditionCode(Condition); setConditionCode(Condition);
if(twrc == TWRC_SUCCESS && twrc2 != TWRC_SUCCESS) if(twrc == TWRC_SUCCESS && twrc2 != TWRC_SUCCESS)
{ {
//FileTools::write_log("D:/1.txt"," handleCap MSG_SET TW_INT16 twrc2 = _pContainer->Set(_pCap, Condition);");
twrc = twrc2; twrc = twrc2;
} }
} }
@ -1088,6 +1187,7 @@ TW_INT16 CTWAINDS_Base::validateCapabilitySet(TW_UINT16 _Cap, TW_UINT16 _ConTyp
if(!ConstrainFrameToScanner(frame,bConstrained)) if(!ConstrainFrameToScanner(frame,bConstrained))
{ {
setConditionCode(TWCC_BADVALUE); setConditionCode(TWCC_BADVALUE);
//FileTools::write_log("D:/1.txt","uvalidateCapabilitySet 6");
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
} }
else if(bConstrained) else if(bConstrained)
@ -1103,6 +1203,7 @@ TW_INT16 CTWAINDS_Base::validateCapabilitySet(TW_UINT16 _Cap, TW_UINT16 _ConTyp
if(pDepCapMax==0) if(pDepCapMax==0)
{ {
setConditionCode(TWCC_BUMMER); setConditionCode(TWCC_BUMMER);
//FileTools::write_log("D:/1.txt","uvalidateCapabilitySet 7");
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
} }
else else
@ -1112,6 +1213,7 @@ TW_INT16 CTWAINDS_Base::validateCapabilitySet(TW_UINT16 _Cap, TW_UINT16 _ConTyp
if(!pDepCapMax->GetCurrent(nMax) || pCap->NumItems>(TW_UINT32)nMax) if(!pDepCapMax->GetCurrent(nMax) || pCap->NumItems>(TW_UINT32)nMax)
{ {
setConditionCode(TWCC_BADVALUE); setConditionCode(TWCC_BADVALUE);
//FileTools::write_log("D:/1.txt","uvalidateCapabilitySet 8");
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
} }
else else
@ -1125,11 +1227,13 @@ TW_INT16 CTWAINDS_Base::validateCapabilitySet(TW_UINT16 _Cap, TW_UINT16 _ConTyp
if(!ConstrainFrameToScanner(frame,bConstrained)) if(!ConstrainFrameToScanner(frame,bConstrained))
{ {
setConditionCode(TWCC_BADVALUE); setConditionCode(TWCC_BADVALUE);
//FileTools::write_log("D:/1.txt","uvalidateCapabilitySet 9");
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
} }
else if(bConstrained) else if(bConstrained)
{ {
pCap->ItemList[x] = frame.AsTW_FRAME(unit, Xres, Yres); pCap->ItemList[x] = frame.AsTW_FRAME(unit, Xres, Yres);
//FileTools::write_log("D:/1.txt","uvalidateCapabilitySet 10");
twrc = TWRC_CHECKSTATUS; twrc = TWRC_CHECKSTATUS;
} }
} }
@ -1146,11 +1250,13 @@ TW_INT16 CTWAINDS_Base::validateCapabilitySet(TW_UINT16 _Cap, TW_UINT16 _ConTyp
if(!pCap || pCap->ItemType != TWTY_UINT16 || pCap->Item!=1) if(!pCap || pCap->ItemType != TWTY_UINT16 || pCap->Item!=1)
{ {
//FileTools::write_log("D:/1.txt","uvalidateCapabilitySet 11");
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
} }
} }
else else
{ {
//FileTools::write_log("D:/1.txt","uvalidateCapabilitySet 12");
setConditionCode(TWCC_CAPBADOPERATION); setConditionCode(TWCC_CAPBADOPERATION);
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
} }
@ -1168,6 +1274,7 @@ TW_INT16 CTWAINDS_Base::updatePreContainer(pTW_CAPABILITY _pCap)
BYTE * pContainer = (BYTE*)_DSM_LockMemory(_pCap->hContainer); BYTE * pContainer = (BYTE*)_DSM_LockMemory(_pCap->hContainer);
if(pContainer==0) if(pContainer==0)
{ {
//FileTools::write_log("D:/1.txt","updatePreContainer(pTW_CAPABILITY _pCap) 12");
setConditionCode(TWCC_LOWMEMORY); setConditionCode(TWCC_LOWMEMORY);
return TWRC_FAILURE; return TWRC_FAILURE;
} }
@ -1182,6 +1289,7 @@ TW_INT16 CTWAINDS_Base::updatePreContainer(pTW_CAPABILITY _pCap)
if( 0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_UNITS))) if( 0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_UNITS)))
|| false == pnCap->GetCurrent(nUnit)) || false == pnCap->GetCurrent(nUnit))
{ {
//FileTools::write_log("D:/1.txt","updatePreContainer(pTW_CAPABILITY _pCap) 6");
setConditionCode(TWCC_OPERATIONERROR); setConditionCode(TWCC_OPERATIONERROR);
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
} }
@ -1189,6 +1297,7 @@ TW_INT16 CTWAINDS_Base::updatePreContainer(pTW_CAPABILITY _pCap)
{ {
if(nUnit==TWUN_PIXELS) if(nUnit==TWUN_PIXELS)
{ {
//FileTools::write_log("D:/1.txt","updatePreContainer(pTW_CAPABILITY _pCap) 5");
setConditionCode(TWCC_CAPSEQERROR); setConditionCode(TWCC_CAPSEQERROR);
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
} }
@ -1201,6 +1310,7 @@ TW_INT16 CTWAINDS_Base::updatePreContainer(pTW_CAPABILITY _pCap)
if(pCap==0 || pCap->ItemType != TWTY_FIX32) if(pCap==0 || pCap->ItemType != TWTY_FIX32)
{ {
setConditionCode(TWCC_BADVALUE); setConditionCode(TWCC_BADVALUE);
//FileTools::write_log("D:/1.txt","updatePreContainer(pTW_CAPABILITY _pCap) 7");
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
} }
else else
@ -1213,6 +1323,7 @@ TW_INT16 CTWAINDS_Base::updatePreContainer(pTW_CAPABILITY _pCap)
pTW_ENUMERATION_FIX32 pCap = (pTW_ENUMERATION_FIX32)pContainer; pTW_ENUMERATION_FIX32 pCap = (pTW_ENUMERATION_FIX32)pContainer;
if(pCap==0 || pCap->ItemType != TWTY_FIX32) if(pCap==0 || pCap->ItemType != TWTY_FIX32)
{ {
//FileTools::write_log("D:/1.txt","updatePreContainer(pTW_CAPABILITY _pCap) 0");
setConditionCode(TWCC_BADVALUE); setConditionCode(TWCC_BADVALUE);
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
} }
@ -1241,6 +1352,7 @@ TW_INT16 CTWAINDS_Base::updatePostContainer(pTW_CAPABILITY _pCap)
if(pContainer==0) if(pContainer==0)
{ {
setConditionCode(TWCC_LOWMEMORY); setConditionCode(TWCC_LOWMEMORY);
//FileTools::write_log("D:/1.txt","updatePostContainer(pTW_CAPABILITY _pCap) 0");
return TWRC_FAILURE; return TWRC_FAILURE;
} }
@ -1265,12 +1377,13 @@ TW_INT16 CTWAINDS_Base::updatePostContainer(pTW_CAPABILITY _pCap)
if(pCap==0 || pCap->ItemType != TWTY_FIX32) if(pCap==0 || pCap->ItemType != TWTY_FIX32)
{ {
//FileTools::write_log("D:/1.txt","updatePostContainer(pTW_CAPABILITY _pCap) 1");
setConditionCode(TWCC_BADVALUE); setConditionCode(TWCC_BADVALUE);
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
} }
else else
{ {
pCap->Item = ConvertUnits(pCap->Item,nUnit,TWUN_PIXELS,Xres); pCap->Item = ConvertUnits(pCap->Item,nUnit,TWUN_INCHES,Xres);
} }
} }
else if(TWON_ENUMERATION == _pCap->ConType) else if(TWON_ENUMERATION == _pCap->ConType)
@ -1278,6 +1391,7 @@ TW_INT16 CTWAINDS_Base::updatePostContainer(pTW_CAPABILITY _pCap)
pTW_ENUMERATION_FIX32 pCap = (pTW_ENUMERATION_FIX32)pContainer; pTW_ENUMERATION_FIX32 pCap = (pTW_ENUMERATION_FIX32)pContainer;
if(pCap==0 || pCap->ItemType != TWTY_FIX32) if(pCap==0 || pCap->ItemType != TWTY_FIX32)
{ {
//FileTools::write_log("D:/1.txt","updatePostContainer(pTW_CAPABILITY _pCap) 2");
setConditionCode(TWCC_BADVALUE); setConditionCode(TWCC_BADVALUE);
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
} }
@ -1311,6 +1425,7 @@ TW_INT16 CTWAINDS_Base::updatePostContainer(pTW_CAPABILITY _pCap)
if(pCap==0 || pCap->ItemType != TWTY_FIX32) if(pCap==0 || pCap->ItemType != TWTY_FIX32)
{ {
//FileTools::write_log("D:/1.txt","updatePostContainer(pTW_CAPABILITY _pCap) 3");
setConditionCode(TWCC_BADVALUE); setConditionCode(TWCC_BADVALUE);
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
} }
@ -1322,6 +1437,7 @@ TW_INT16 CTWAINDS_Base::updatePostContainer(pTW_CAPABILITY _pCap)
else else
{ {
setConditionCode(TWCC_OPERATIONERROR); setConditionCode(TWCC_OPERATIONERROR);
//FileTools::write_log("D:/1.txt","updatePostContainer(pTW_CAPABILITY _pCap) 4");
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
} }
} }
@ -1352,6 +1468,7 @@ TW_INT16 CTWAINDS_Base::updatePreDependencies(CTWAINContainer* _pContainer)
} }
else else
{ {
//FileTools::write_log("D:/1.txt","(CTWAINContainer* _pContainer) 1");
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
} }
} }
@ -1385,6 +1502,7 @@ TW_INT16 CTWAINDS_Base::updatePostDependencies(TW_UINT16 MSG, TW_UINT16 Cap)
if(0 == pDepCapSS || 0 == pDepCapFrames) if(0 == pDepCapSS || 0 == pDepCapFrames)
{ {
setConditionCode(TWCC_CAPBADOPERATION); setConditionCode(TWCC_CAPBADOPERATION);
//FileTools::write_log("D:/1.txt","updatePostDependencies 0");
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
break; break;
} }
@ -1411,6 +1529,7 @@ TW_INT16 CTWAINDS_Base::updatePostDependencies(TW_UINT16 MSG, TW_UINT16 Cap)
if(0 == pDepCapSS || 0 == pDepCapFrames) if(0 == pDepCapSS || 0 == pDepCapFrames)
{ {
setConditionCode(TWCC_CAPBADOPERATION); setConditionCode(TWCC_CAPBADOPERATION);
//FileTools::write_log("D:/1.txt","updatePostDependencies 1");
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
break; break;
} }
@ -1463,6 +1582,7 @@ TW_INT16 CTWAINDS_Base::updatePostDependencies(TW_UINT16 MSG, TW_UINT16 Cap)
if(pDepCapFrames ==0) if(pDepCapFrames ==0)
{ {
setConditionCode(TWCC_BUMMER); setConditionCode(TWCC_BUMMER);
//FileTools::write_log("D:/1.txt","updatePostDependencies 3");
twrc = TWRC_FAILURE; twrc = TWRC_FAILURE;
break; break;
} }
@ -1474,6 +1594,7 @@ TW_INT16 CTWAINDS_Base::updatePostDependencies(TW_UINT16 MSG, TW_UINT16 Cap)
else else
{ {
setConditionCode(TWCC_BUMMER); setConditionCode(TWCC_BUMMER);
//FileTools::write_log("D:/1.txt","updatePostDependencies 4");
return TWRC_FAILURE; return TWRC_FAILURE;
} }
} }

View File

@ -47,6 +47,7 @@
#include <signal.h> #include <signal.h>
#include <typeinfo> #include <typeinfo>
#include "PublicFunc.h" #include "PublicFunc.h"
#include "filetools.h"
#ifdef TWH_CMP_MSC #ifdef TWH_CMP_MSC
#include <Winbase.h> #include <Winbase.h>
#endif #endif
@ -102,7 +103,7 @@ TW_IDENTITY CTWAINDS_Base::m_TheIdentity =
#ifdef __APPLE__ #ifdef __APPLE__
"\p" "\p"
#endif #endif
"HUAGOSCAN HI-5100 TWAIN" // TW_STR32 ProductName; Product name, e.g. "ScanJet Plus" "HS-0805 TWAIN" // TW_STR32 ProductName; Product name, e.g. "ScanJet Plus"
}; };
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -114,6 +115,7 @@ CTWAINDS_FreeImage::CTWAINDS_FreeImage(TW_IDENTITY AppID) :
// Setup our identity // Setup our identity
fillIdentityStructure(*getIdentity()); fillIdentityStructure(*getIdentity());
m_pGUI = CreateUI(this); m_pGUI = CreateUI(this);
isDestroyed=false;
} }
bool CTWAINDS_FreeImage::StoreCapInStream(stringstream &_DsData, TW_UINT16 _unCapID, TW_UINT16 _unCapIdx, TW_UINT16 unContType) bool CTWAINDS_FreeImage::StoreCapInStream(stringstream &_DsData, TW_UINT16 _unCapID, TW_UINT16 _unCapIdx, TW_UINT16 unContType)
@ -434,7 +436,9 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
|| !pnCap->Add(ICAP_AUTOMATICDESKEW)//自动纠偏 || !pnCap->Add(ICAP_AUTOMATICDESKEW)//自动纠偏
|| !pnCap->Add(ICAP_FILTER)//除色 || !pnCap->Add(ICAP_FILTER)//除色
|| !pnCap->Add(0x8005)//背面旋转180 || !pnCap->Add(0x8005)//背面旋转180
|| !pnCap->Add(0x8027)//填充黑框 || !pnCap->Add(0x8004)//填充黑框
|| !pnCap->Add(0x8018)//去除穿孔
|| !pnCap->Add(0x8092)//去除穿孔所占幅面占比
//硬件协议 //硬件协议
|| !pnCap->Add(0x8006)//歪斜检测 || !pnCap->Add(0x8006)//歪斜检测
@ -472,8 +476,8 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
m_IndependantCapMap[ICAP_UNITS] = new CTWAINContainerInt(ICAP_UNITS, TWTY_UINT16, TWON_ENUMERATION); m_IndependantCapMap[ICAP_UNITS] = new CTWAINContainerInt(ICAP_UNITS, TWTY_UINT16, TWON_ENUMERATION);
if (NULL == (pnCap = dynamic_cast<CTWAINContainerInt*>(m_IndependantCapMap[ICAP_UNITS])) if (NULL == (pnCap = dynamic_cast<CTWAINContainerInt*>(m_IndependantCapMap[ICAP_UNITS]))
|| !pnCap->Add(TWUN_INCHES) || !pnCap->Add(TWUN_INCHES,true)
|| !pnCap->Add(TWUN_PIXELS, true) || !pnCap->Add(TWUN_PIXELS)
|| !pnCap->Add(TWUN_CENTIMETERS) || !pnCap->Add(TWUN_CENTIMETERS)
|| !pnCap->Add(TWUN_PICAS) || !pnCap->Add(TWUN_PICAS)
|| !pnCap->Add(TWUN_POINTS) || !pnCap->Add(TWUN_POINTS)
@ -484,7 +488,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
return TWRC_FAILURE; return TWRC_FAILURE;
} }
m_IndependantCapMap[ICAP_XFERMECH] = new CTWAINContainerInt(ICAP_XFERMECH, TWTY_UINT16, TWON_ENUMERATION); m_IndependantCapMap[ICAP_XFERMECH] = new CTWAINContainerInt(ICAP_XFERMECH, TWTY_UINT16, TWON_ONEVALUE);
if (NULL == (pnCap = dynamic_cast<CTWAINContainerInt*>(m_IndependantCapMap[ICAP_XFERMECH])) if (NULL == (pnCap = dynamic_cast<CTWAINContainerInt*>(m_IndependantCapMap[ICAP_XFERMECH]))
|| !pnCap->Add(TWSX_FILE) || !pnCap->Add(TWSX_FILE)
|| !pnCap->Add(TWSX_MEMORY) || !pnCap->Add(TWSX_MEMORY)
@ -564,7 +568,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
setConditionCode(TWCC_LOWMEMORY); setConditionCode(TWCC_LOWMEMORY);
return TWRC_FAILURE; return TWRC_FAILURE;
} }
//TWSS_B5
//文稿类型 //文稿类型
m_IndependantCapMap[ICAP_SUPPORTEDSIZES] = new CTWAINContainerInt(ICAP_SUPPORTEDSIZES, TWTY_UINT16, TWON_ENUMERATION); m_IndependantCapMap[ICAP_SUPPORTEDSIZES] = new CTWAINContainerInt(ICAP_SUPPORTEDSIZES, TWTY_UINT16, TWON_ENUMERATION);
if (NULL == (pnCap = dynamic_cast<CTWAINContainerInt*>(m_IndependantCapMap[ICAP_SUPPORTEDSIZES])) if (NULL == (pnCap = dynamic_cast<CTWAINContainerInt*>(m_IndependantCapMap[ICAP_SUPPORTEDSIZES]))
@ -593,7 +597,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
return TWRC_FAILURE; return TWRC_FAILURE;
} }
//图像旋转 //图像旋转
m_IndependantCapMap[ICAP_ORIENTATION] = new CTWAINContainerInt(ICAP_ORIENTATION, TWTY_UINT16, TWON_ENUMERATION); m_IndependantCapMap[ICAP_ORIENTATION] = new CTWAINContainerInt(ICAP_ORIENTATION, TWTY_UINT16, TWON_ONEVALUE);
if (NULL == (pnCap = dynamic_cast<CTWAINContainerInt*>(m_IndependantCapMap[ICAP_ORIENTATION])) if (NULL == (pnCap = dynamic_cast<CTWAINContainerInt*>(m_IndependantCapMap[ICAP_ORIENTATION]))
|| !pnCap->Add(TWOR_PORTRAIT, true) || !pnCap->Add(TWOR_PORTRAIT, true)
|| !pnCap->Add(TWOR_ROT90) || !pnCap->Add(TWOR_ROT90)
@ -645,10 +649,9 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
return TWRC_FAILURE; return TWRC_FAILURE;
} }
m_IndependantCapMap[CAP_DUPLEX] = new CTWAINContainerInt(CAP_DUPLEX, TWTY_UINT16, TWON_ENUMERATION, TWQC_ALL); m_IndependantCapMap[CAP_DUPLEX] = new CTWAINContainerInt(CAP_DUPLEX, TWTY_UINT16, TWON_ONEVALUE, TWQC_GETS);
if (NULL == (pnCap = dynamic_cast<CTWAINContainerInt*>(m_IndependantCapMap[CAP_DUPLEX])) if (NULL == (pnCap = dynamic_cast<CTWAINContainerInt*>(m_IndependantCapMap[CAP_DUPLEX]))
|| !pnCap->Add(TWDX_1PASSDUPLEX, true) || !pnCap->Add(TWDX_1PASSDUPLEX, true))
|| !pnCap->Add(TWDX_2PASSDUPLEX))
{ {
cerr << "Could not create CAP_DUPLEX" << endl; cerr << "Could not create CAP_DUPLEX" << endl;
setConditionCode(TWCC_LOWMEMORY); setConditionCode(TWCC_LOWMEMORY);
@ -657,6 +660,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
m_IndependantCapMap[CAP_DUPLEXENABLED] = new CTWAINContainerBool(CAP_DUPLEXENABLED, (m_AppID.SupportedGroups&DF_APP2) != 0, TWQC_ALL); m_IndependantCapMap[CAP_DUPLEXENABLED] = new CTWAINContainerBool(CAP_DUPLEXENABLED, (m_AppID.SupportedGroups&DF_APP2) != 0, TWQC_ALL);
if (NULL == (pbCap = dynamic_cast<CTWAINContainerBool*>(m_IndependantCapMap[CAP_DUPLEXENABLED])) if (NULL == (pbCap = dynamic_cast<CTWAINContainerBool*>(m_IndependantCapMap[CAP_DUPLEXENABLED]))
|| !pbCap->Add(TRUE)
|| !pbCap->Add(FALSE, true)) || !pbCap->Add(FALSE, true))
{ {
cerr << "Could not create CAP_DUPLEXENABLED" << endl; cerr << "Could not create CAP_DUPLEXENABLED" << endl;
@ -721,7 +725,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
} }
// setup dependant caps // setup dependant caps
if (NULL == (m_BitDepthMap[TWPT_BW] = new CTWAINContainerInt(ICAP_BITDEPTH, TWTY_UINT16, TWON_ENUMERATION)) if (NULL == (m_BitDepthMap[TWPT_BW] = new CTWAINContainerInt(ICAP_BITDEPTH, TWTY_UINT16, TWON_ONEVALUE))
|| !m_BitDepthMap[TWPT_BW]->Add(1, true)) || !m_BitDepthMap[TWPT_BW]->Add(1, true))
{ {
cerr << "Could not create ICAP_BITDEPTH" << endl; cerr << "Could not create ICAP_BITDEPTH" << endl;
@ -729,7 +733,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
return TWRC_FAILURE; return TWRC_FAILURE;
} }
if (NULL == (m_BitDepthMap[TWPT_GRAY] = new CTWAINContainerInt(ICAP_BITDEPTH, TWTY_UINT16, TWON_ENUMERATION)) if (NULL == (m_BitDepthMap[TWPT_GRAY] = new CTWAINContainerInt(ICAP_BITDEPTH, TWTY_UINT16, TWON_ONEVALUE))
|| !m_BitDepthMap[TWPT_GRAY]->Add(8, true)) || !m_BitDepthMap[TWPT_GRAY]->Add(8, true))
{ {
cerr << "Could not create ICAP_BITDEPTH" << endl; cerr << "Could not create ICAP_BITDEPTH" << endl;
@ -737,7 +741,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
return TWRC_FAILURE; return TWRC_FAILURE;
} }
if (NULL == (m_BitDepthMap[TWPT_RGB] = new CTWAINContainerInt(ICAP_BITDEPTH, TWTY_UINT16, TWON_ENUMERATION)) if (NULL == (m_BitDepthMap[TWPT_RGB] = new CTWAINContainerInt(ICAP_BITDEPTH, TWTY_UINT16, TWON_ONEVALUE))
|| !m_BitDepthMap[TWPT_RGB]->Add(24, true)) || !m_BitDepthMap[TWPT_RGB]->Add(24, true))
{ {
cerr << "Could not create ICAP_BITDEPTH" << endl; cerr << "Could not create ICAP_BITDEPTH" << endl;
@ -803,14 +807,14 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
return TWRC_FAILURE; return TWRC_FAILURE;
} }
// expressed internally as pixels per inch // expressed internally as pixels per inch
m_IndependantCapMap[ICAP_XRESOLUTION] = new CTWAINContainerFix32(ICAP_XRESOLUTION, TWON_ENUMERATION, TWQC_ALL); m_IndependantCapMap[ICAP_XRESOLUTION] = new CTWAINContainerFix32(ICAP_XRESOLUTION, TWON_ONEVALUE, TWQC_ALL);
if (NULL == (pfixCap = dynamic_cast<CTWAINContainerFix32*>(m_IndependantCapMap[ICAP_XRESOLUTION])) if (NULL == (pfixCap = dynamic_cast<CTWAINContainerFix32*>(m_IndependantCapMap[ICAP_XRESOLUTION]))
//|| !pfixCap->Add(50) //|| !pfixCap->Add(50)
|| !pfixCap->Add(100) || !pfixCap->Add(100.0f)
|| !pfixCap->Add(150) || !pfixCap->Add(150.0f)
|| !pfixCap->Add(200, true) || !pfixCap->Add(200.0f, true)
|| !pfixCap->Add(240) || !pfixCap->Add(240.0f)
|| !pfixCap->Add(300)) || !pfixCap->Add(300.0f))
//|| !pfixCap->Add(500) //|| !pfixCap->Add(500)
//|| !pfixCap->Add(600)) //|| !pfixCap->Add(600))
{ {
@ -820,14 +824,14 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
} }
// expressed internally as pixels per inch // expressed internally as pixels per inch
m_IndependantCapMap[ICAP_YRESOLUTION] = new CTWAINContainerFix32(ICAP_YRESOLUTION, TWON_ENUMERATION, TWQC_ALL); m_IndependantCapMap[ICAP_YRESOLUTION] = new CTWAINContainerFix32(ICAP_YRESOLUTION, TWON_ONEVALUE, TWQC_ALL);
if (NULL == (pfixCap = dynamic_cast<CTWAINContainerFix32*>(m_IndependantCapMap[ICAP_YRESOLUTION])) if (NULL == (pfixCap = dynamic_cast<CTWAINContainerFix32*>(m_IndependantCapMap[ICAP_YRESOLUTION]))
//|| !pfixCap->Add(50) //|| !pfixCap->Add(50)
|| !pfixCap->Add(100) || !pfixCap->Add(100.0f)
|| !pfixCap->Add(150) || !pfixCap->Add(150.0f)
|| !pfixCap->Add(200, true) || !pfixCap->Add(200.0f, true)
|| !pfixCap->Add(240) || !pfixCap->Add(240.0f)
|| !pfixCap->Add(300)) || !pfixCap->Add(300.0f))
//|| !pfixCap->Add(500) //|| !pfixCap->Add(500)
//|| !pfixCap->Add(600)) //|| !pfixCap->Add(600))
{ {
@ -903,9 +907,9 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
/*一下为后加协议 2018-11-15 ByPeng*/ /*一下为后加协议 2018-11-15 ByPeng*/
//扫描仪序列号 //扫描仪序列号
if (NULL == (m_IndependantCapMap[CAP_SERIALNUMBER] = new CTWAINContainerString(CAP_SERIALNUMBER, TWTY_STR255, TWON_ONEVALUE, TWQC_GETS))) m_IndependantCapMap[CAP_SERIALNUMBER] = new CTWAINContainerString(CAP_SERIALNUMBER, TWTY_STR255, TWON_ONEVALUE, TWQC_GETS);
if (NULL == (pstrCap = dynamic_cast<CTWAINContainerString*>(m_IndependantCapMap[CAP_SERIALNUMBER])) if (NULL == (pstrCap = dynamic_cast<CTWAINContainerString*>(m_IndependantCapMap[CAP_SERIALNUMBER]))
|| !pstrCap->Add(m_Scanner.getSerialNum(), true)) || !pstrCap->Add("G20018000000", true))//m_Scanner.getSerialNum()
{ {
cerr << "Could not create CAP_SERIALNUMBER" << endl; cerr << "Could not create CAP_SERIALNUMBER" << endl;
setConditionCode(TWCC_LOWMEMORY); setConditionCode(TWCC_LOWMEMORY);
@ -914,9 +918,9 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
//扫描仪固件版本号 //扫描仪固件版本号
if (NULL == (m_IndependantCapMap[0x8025] = new CTWAINContainerString(0x8025, TWTY_STR255, TWON_ONEVALUE, TWQC_GETS))) m_IndependantCapMap[0x8025] = new CTWAINContainerString(0x8025, TWTY_STR255, TWON_ONEVALUE, TWQC_GETS);
if (NULL == (pstrCap = dynamic_cast<CTWAINContainerString*>(m_IndependantCapMap[0x8025])) if (NULL == (pstrCap = dynamic_cast<CTWAINContainerString*>(m_IndependantCapMap[0x8025]))
|| !pstrCap->Add(m_Scanner.getFWVersion(), true)) || !pstrCap->Add("51000000", true))
{ {
cerr << "Could not create Get FWVersion" << endl; cerr << "Could not create Get FWVersion" << endl;
setConditionCode(TWCC_LOWMEMORY); setConditionCode(TWCC_LOWMEMORY);
@ -946,7 +950,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
} }
//自动丢弃空白页(发票) //自动丢弃空白页(发票)
m_IndependantCapMap[0x8091] = new CTWAINContainerBool(0x8091, (m_AppID.SupportedGroups&DF_APP2) != 0, TWQC_ALL); m_IndependantCapMap[0x8091] = new CTWAINContainerBool(0x8091, TWON_ONEVALUE, TWQC_ALL);
if (NULL == (pbCap = dynamic_cast<CTWAINContainerBool*>(m_IndependantCapMap[0x8091])) if (NULL == (pbCap = dynamic_cast<CTWAINContainerBool*>(m_IndependantCapMap[0x8091]))
|| !pbCap->Add(TRUE) || !pbCap->Add(TRUE)
|| !pbCap->Add(FALSE, true)) || !pbCap->Add(FALSE, true))
@ -957,8 +961,8 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
} }
//填充黑框 //填充黑框
m_IndependantCapMap[0x8027] = new CTWAINContainerBool(0x8027, (m_AppID.SupportedGroups&DF_APP2) != 0, TWQC_ALL); m_IndependantCapMap[0x8004] = new CTWAINContainerBool(0x8004, TWON_ONEVALUE, TWQC_ALL);
if (NULL == (pbCap = dynamic_cast<CTWAINContainerBool*>(m_IndependantCapMap[0x8027])) if (NULL == (pbCap = dynamic_cast<CTWAINContainerBool*>(m_IndependantCapMap[0x8004]))
|| !pbCap->Add(TRUE) || !pbCap->Add(TRUE)
|| !pbCap->Add(FALSE, true)) || !pbCap->Add(FALSE, true))
{ {
@ -1001,7 +1005,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
} }
//除色与颜色增强 //除色与颜色增强
m_IndependantCapMap[ICAP_FILTER] = new CTWAINContainerInt(ICAP_FILTER, TWTY_UINT16,TWON_ENUMERATION); m_IndependantCapMap[ICAP_FILTER] = new CTWAINContainerInt(ICAP_FILTER, TWTY_UINT16,TWON_ONEVALUE);
if (NULL == (pnCap = dynamic_cast<CTWAINContainerInt*>(m_IndependantCapMap[ICAP_FILTER])) if (NULL == (pnCap = dynamic_cast<CTWAINContainerInt*>(m_IndependantCapMap[ICAP_FILTER]))
|| !pnCap->Add(0, true)//不除色 || !pnCap->Add(0, true)//不除色
|| !pnCap->Add(1)//除红色 || !pnCap->Add(1)//除红色
@ -1018,7 +1022,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
} }
//背面旋转180 //背面旋转180
m_IndependantCapMap[0x8005] = new CTWAINContainerBool(0x8005, (m_AppID.SupportedGroups&DF_APP2) != 0, TWQC_ALL); m_IndependantCapMap[0x8005] = new CTWAINContainerBool(0x8005,TWON_ONEVALUE, TWQC_ALL);
if (NULL == (pbCap = dynamic_cast<CTWAINContainerBool*>(m_IndependantCapMap[0x8005])) if (NULL == (pbCap = dynamic_cast<CTWAINContainerBool*>(m_IndependantCapMap[0x8005]))
|| !pbCap->Add(TRUE) || !pbCap->Add(TRUE)
|| !pbCap->Add(FALSE, true)) || !pbCap->Add(FALSE, true))
@ -1028,8 +1032,32 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
return TWRC_FAILURE; return TWRC_FAILURE;
} }
//去除穿孔
m_IndependantCapMap[0x8018] = new CTWAINContainerBool(0x8018,TWON_ONEVALUE, TWQC_ALL);
if (NULL == (pbCap = dynamic_cast<CTWAINContainerBool*>(m_IndependantCapMap[0x8018]))
|| !pbCap->Add(TRUE)
|| !pbCap->Add(FALSE, true))
{
cerr << "Could not create OutHole" << endl;
setConditionCode(TWCC_LOWMEMORY);
return TWRC_FAILURE;
}
//去除穿孔占幅面比例
fRange.fCurrentValue =10.0f;
fRange.fMaxValue = 50.0f;
fRange.fMinValue = 1.0f;
fRange.fStepSize = 1.0f;
m_IndependantCapMap[0x8092] = new CTWAINContainerFix32Range(0x8092, fRange, TWQC_ALL);
if (NULL == dynamic_cast<CTWAINContainerFix32Range*>(m_IndependantCapMap[0x8092]))
{
cerr << "Could not create Outhole ration" << endl;
setConditionCode(TWCC_LOWMEMORY);
return TWRC_FAILURE;
}
//歪斜检测 //歪斜检测
m_IndependantCapMap[0x8006] = new CTWAINContainerBool(0x8006, (m_AppID.SupportedGroups&DF_APP2) != 0, TWQC_ALL); m_IndependantCapMap[0x8006] = new CTWAINContainerBool(0x8006, TWON_ONEVALUE, TWQC_ALL);
if (NULL == (pbCap = dynamic_cast<CTWAINContainerBool*>(m_IndependantCapMap[0x8006])) if (NULL == (pbCap = dynamic_cast<CTWAINContainerBool*>(m_IndependantCapMap[0x8006]))
|| !pbCap->Add(TRUE) || !pbCap->Add(TRUE)
|| !pbCap->Add(FALSE, true)) || !pbCap->Add(FALSE, true))
@ -1064,7 +1092,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
} }
//装订检测 //装订检测
m_IndependantCapMap[0x8090] = new CTWAINContainerBool(0x8090, (m_AppID.SupportedGroups&DF_APP2) != 0, TWQC_ALL); m_IndependantCapMap[0x8090] = new CTWAINContainerBool(0x8090, TWON_ONEVALUE, TWQC_ALL);
if (NULL == (pbCap = dynamic_cast<CTWAINContainerBool*>(m_IndependantCapMap[0x8090])) if (NULL == (pbCap = dynamic_cast<CTWAINContainerBool*>(m_IndependantCapMap[0x8090]))
|| !pbCap->Add(TRUE) || !pbCap->Add(TRUE)
|| !pbCap->Add(FALSE, true)) || !pbCap->Add(FALSE, true))
@ -1132,8 +1160,8 @@ TW_INT16 CTWAINDS_FreeImage::getImageInfo(pTW_IMAGEINFO _pImageInfo)
} }
_pImageInfo->XResolution = FloatToFIX32(ConvertUnits(float(settings->m_fXResolution), nUnit, TWUN_PIXELS, settings->m_fXResolution)); _pImageInfo->XResolution = FloatToFIX32(ConvertUnits(float(settings->m_fXResolution), nUnit, TWUN_INCHES, settings->m_fXResolution));
_pImageInfo->YResolution = FloatToFIX32(ConvertUnits(float(settings->m_fYResolution), nUnit, TWUN_PIXELS, settings->m_fYResolution)); _pImageInfo->YResolution = FloatToFIX32(ConvertUnits(float(settings->m_fYResolution), nUnit, TWUN_INCHES, settings->m_fYResolution));
_pImageInfo->ImageWidth = m_Scanner.m_nSourceWidth; _pImageInfo->ImageWidth = m_Scanner.m_nSourceWidth;
_pImageInfo->ImageLength = m_Scanner.m_nSourceHeight; _pImageInfo->ImageLength = m_Scanner.m_nSourceHeight;
//XdPrint("_pImageInfo->ImageWidth = %d, aaa\n",_pImageInfo->ImageWidth); //XdPrint("_pImageInfo->ImageWidth = %d, aaa\n",_pImageInfo->ImageWidth);
@ -1217,7 +1245,7 @@ TW_INT16 CTWAINDS_FreeImage::openDS(pTW_IDENTITY _pOrigin)
} }
JsonConfig js; JsonConfig js;
CONFIGPARAMS configParams=js.ReadDefaultConfig(); CONFIGPARAMS configParams=js.ReadDefaultConfig();
UpdateCapsFromConfig(configParams); bool ss= UpdateCapsFromConfig(configParams);
return ret; return ret;
} }
@ -1226,13 +1254,26 @@ TW_INT16 CTWAINDS_FreeImage::closeDS()
{ {
// check if ok to return success // check if ok to return success
// Must be in state 4 // Must be in state 4
if (dsState_Open != m_CurrentState) //if (!isDestroyed)//m_CurrentState==dsState_Enabled
//{
//m_pGUI->DestroyTWAINGUI();
//XdPrint("closeDS m_pGUI->DestroyTWAINGUI() \n");
//// // allow the scanners caps to be writeable again because we are moving back
//// // to state 4. If this source had a UI, it would be lowered at this time.
//m_Scanner.Unlock();
//m_CurrentState = dsState_Open;
//isDestroyed=true;
//}
//else
if(dsState_Open != m_CurrentState)
{ {
setConditionCode(TWCC_SEQERROR); setConditionCode(TWCC_SEQERROR);
return TWRC_FAILURE; return TWRC_FAILURE;
} }
memset(&m_App, 0, sizeof(m_App)); memset(&m_App, 0, sizeof(m_App));
//FileTools::write_log("D:/1.txt"," Close DS ");
XdPrint(" CloseDS !\n");
return TWRC_SUCCESS; return TWRC_SUCCESS;
} }
@ -1247,6 +1288,7 @@ TW_INT16 CTWAINDS_FreeImage::enableDS(pTW_USERINTERFACE _pData)
if (dsState_Open != m_CurrentState) if (dsState_Open != m_CurrentState)
{ {
setConditionCode(TWCC_SEQERROR); setConditionCode(TWCC_SEQERROR);
//FileTools::write_log("D:/1.txt","enableDS dsState_Open != m_CurrentState");
return TWRC_FAILURE; return TWRC_FAILURE;
} }
m_CurrentState = dsState_Enabled; m_CurrentState = dsState_Enabled;
@ -1254,13 +1296,17 @@ TW_INT16 CTWAINDS_FreeImage::enableDS(pTW_USERINTERFACE _pData)
m_bCanceled = false; m_bCanceled = false;
//set pending xfers to whatever the user configured for XferCount //set pending xfers to whatever the user configured for XferCount
int Count = TWON_DONTCARE32; //int Count = TWON_DONTCARE32;
CTWAINContainerInt *pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(CAP_XFERCOUNT)); //CTWAINContainerInt *pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(CAP_XFERCOUNT));
if (pnCap) //if (pnCap)
{ //{
pnCap->GetCurrent(Count); // pnCap->GetCurrent(Count);
} //}
m_Xfers.Count = Count; //m_Xfers.Count = Count;
//stringstream ss;
//ss<<m_Xfers.Count;
//string sout=ss.str();
//FileTools::write_log("D:/1.txt","XferCount"+sout );
// Indicate we have not transferred any images yet // Indicate we have not transferred any images yet
m_DocumentNumber = 0; m_DocumentNumber = 0;
m_PageNumber = 0; m_PageNumber = 0;
@ -1276,10 +1322,11 @@ TW_INT16 CTWAINDS_FreeImage::enableDS(pTW_USERINTERFACE _pData)
} }
if (m_pGUI->DisplayTWAINGUI(*_pData, false, bIndicators) != TWRC_SUCCESS) if (m_pGUI->DisplayTWAINGUI(*_pData, false, bIndicators) != TWRC_SUCCESS)
{ {
// A user interface is not supported as of right now because we are //A user interface is not supported as of right now because we are
// in text mode. //in text mode.
m_CurrentState = dsState_Open; m_CurrentState = dsState_Open;
setConditionCode(TWCC_OPERATIONERROR); setConditionCode(TWCC_SEQERROR);
//FileTools::write_log("D:/1.txt","enableDS m_pGUI->DisplayTWAINGUI(*_pData, false, bIndicators) != TWRC_SUCCESS");
return TWRC_FAILURE; return TWRC_FAILURE;
} }
@ -1305,6 +1352,7 @@ TW_INT16 CTWAINDS_FreeImage::enableDS(pTW_USERINTERFACE _pData)
cerr << "ds: There was an error while trying to get scanner to acquire image" << endl; cerr << "ds: There was an error while trying to get scanner to acquire image" << endl;
m_CurrentState = dsState_Open; m_CurrentState = dsState_Open;
setConditionCode(TWCC_SEQERROR); setConditionCode(TWCC_SEQERROR);
//FileTools::write_log("D:/1.txt","enableDS !StartScanning()");
return TWRC_FAILURE; return TWRC_FAILURE;
} }
@ -1312,6 +1360,7 @@ TW_INT16 CTWAINDS_FreeImage::enableDS(pTW_USERINTERFACE _pData)
{ {
m_CurrentState = dsState_Open; m_CurrentState = dsState_Open;
setConditionCode(TWCC_SEQERROR); setConditionCode(TWCC_SEQERROR);
//FileTools::write_log("D:/1.txt","enableDS !DoXferReadyEvent()");
return TWRC_FAILURE; return TWRC_FAILURE;
} }
} }
@ -1323,26 +1372,27 @@ TW_INT16 CTWAINDS_FreeImage::enableDS(pTW_USERINTERFACE _pData)
//} //}
//if (m_pGUI->DisplayTWAINGUI(*_pData, false, bIndicators) != TWRC_SUCCESS) //if (m_pGUI->DisplayTWAINGUI(*_pData, false, bIndicators) != TWRC_SUCCESS)
//{ //{
// // A user interface is not supported as of right now because we are //// // A user interface is not supported as of right now because we are
// // in text mode. //// // in text mode.
// m_CurrentState = dsState_Open; // m_CurrentState = dsState_Open;
// setConditionCode(TWCC_OPERATIONERROR); // setConditionCode(TWCC_OPERATIONERROR);
// return TWRC_FAILURE; // return TWRC_FAILURE;
//} //}
return TWRC_SUCCESS; return TWRC_SUCCESS;
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
TW_INT16 CTWAINDS_FreeImage::enableDSOnly(pTW_USERINTERFACE _pData) TW_INT16 CTWAINDS_FreeImage::enableDSOnly(pTW_USERINTERFACE _pData)
{ {
if (b_created==FALSE)//Twain被其他程序占用 //if (b_created==FALSE)//Twain被其他程序占用
{ //{
return TWRC_FAILURE; // //FileTools::write_log("D:/1.txt","b_created==FALSE");
} // return TWRC_FAILURE;
//}
if (dsState_Open != m_CurrentState) if (dsState_Open != m_CurrentState)
{ {
setConditionCode(TWCC_SEQERROR); setConditionCode(TWCC_SEQERROR);
//FileTools::write_log("D:/1.txt","dsState_Open != m_CurrentState");
return TWRC_FAILURE; return TWRC_FAILURE;
} }
m_CurrentState = dsState_Enabled; m_CurrentState = dsState_Enabled;
@ -1351,6 +1401,7 @@ TW_INT16 CTWAINDS_FreeImage::enableDSOnly(pTW_USERINTERFACE _pData)
{ {
// A user interface is not supported as of right now because we are // A user interface is not supported as of right now because we are
// in text mode. // in text mode.
//FileTools::write_log("D:/1.txt","m_pGUI->DisplayTWAINGUI(*_pData, true, false) != TWRC_SUCCESS");
m_CurrentState = dsState_Open; m_CurrentState = dsState_Open;
setConditionCode(TWCC_OPERATIONERROR); setConditionCode(TWCC_OPERATIONERROR);
return TWRC_FAILURE; return TWRC_FAILURE;
@ -1358,16 +1409,23 @@ TW_INT16 CTWAINDS_FreeImage::enableDSOnly(pTW_USERINTERFACE _pData)
return TWRC_SUCCESS; return TWRC_SUCCESS;
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
TW_INT16 CTWAINDS_FreeImage::disableDS(pTW_USERINTERFACE _pData) TW_INT16 CTWAINDS_FreeImage::disableDS(pTW_USERINTERFACE _pData)
{ {
if (dsState_Enabled != m_CurrentState) if (dsState_Enabled != m_CurrentState)
{ {
//FileTools::write_log("D:/1.txt"," disableDS dsState_Enabled != m_CurrentState");
setConditionCode(TWCC_SEQERROR); setConditionCode(TWCC_SEQERROR);
return TWRC_FAILURE; return TWRC_FAILURE;
} }
//if (!isDestroyed)
//{
m_pGUI->DestroyTWAINGUI(); m_pGUI->DestroyTWAINGUI();
// isDestroyed=true;
//}
// allow the scanners caps to be writeable again because we are moving back // allow the scanners caps to be writeable again because we are moving back
// to state 4. If this source had a UI, it would be lowered at this time. // to state 4. If this source had a UI, it would be lowered at this time.
@ -1378,6 +1436,7 @@ TW_INT16 CTWAINDS_FreeImage::disableDS(pTW_USERINTERFACE _pData)
// There is no UI in this text interface so there is nothing // There is no UI in this text interface so there is nothing
// to do here. // to do here.
m_CurrentState = dsState_Open; m_CurrentState = dsState_Open;
XdPrint(" disableDS !\n");
return TWRC_SUCCESS; return TWRC_SUCCESS;
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -1504,6 +1563,10 @@ TW_INT16 CTWAINDS_FreeImage::processEvent(pTW_EVENT _pEvent)
TW_INT16 CTWAINDS_FreeImage::transfer() TW_INT16 CTWAINDS_FreeImage::transfer()
{ {
TW_INT16 twrc = TWRC_SUCCESS; TW_INT16 twrc = TWRC_SUCCESS;
//if (bIndicators)
//{
// m_pGUI->UpdateProgress(true,' ',0,"");
//}
getImageInfo(&m_ImageInfo); getImageInfo(&m_ImageInfo);
if (m_bCanceled) if (m_bCanceled)
{ {
@ -1559,7 +1622,8 @@ TW_INT16 CTWAINDS_FreeImage::transfer()
pImageData += dwReceived; pImageData += dwReceived;
nImageSize -= dwReceived; nImageSize -= dwReceived;
} while (nImageSize > 0 && twrc == TWRC_SUCCESS); }
while (nImageSize > 0 && twrc == TWRC_SUCCESS);
_DSM_UnlockMemory(m_hImageData); _DSM_UnlockMemory(m_hImageData);
} }
@ -1585,6 +1649,7 @@ TW_INT16 CTWAINDS_FreeImage::endXfer(pTW_PENDINGXFERS _pXfers)
//static int aa=0; //static int aa=0;
//XdPrint("inter times %d\n",aa); //XdPrint("inter times %d\n",aa);
//aa++; //aa++;
//FileTools::write_log("D:/1.txt"," 1");
TW_INT16 twrc = TWRC_SUCCESS; TW_INT16 twrc = TWRC_SUCCESS;
if (!(dsState_XferReady == m_CurrentState || if (!(dsState_XferReady == m_CurrentState ||
dsState_Xferring == m_CurrentState)) dsState_Xferring == m_CurrentState))
@ -1602,13 +1667,14 @@ TW_INT16 CTWAINDS_FreeImage::endXfer(pTW_PENDINGXFERS _pXfers)
if (rs) if (rs)
{ {
m_Xfers.Count = 0; m_Xfers.Count = 0;
//MessageBox(NULL,"null","1",MB_OK); //FileTools::write_log("D:/1.txt"," rs: m_Xfers.Count==0");
} }
if (m_bCanceled) if (m_bCanceled)
{ {
m_bCanceled = false; m_bCanceled = false;
m_Xfers.Count = 0; m_Xfers.Count = 0;
//FileTools::write_log("D:/1.txt"," m_bCanceled: m_Xfers.Count==0");
} }
if (0 != m_Xfers.Count) if (0 != m_Xfers.Count)
{ {
@ -1628,9 +1694,11 @@ TW_INT16 CTWAINDS_FreeImage::endXfer(pTW_PENDINGXFERS _pXfers)
if (m_Scanner.isImageQueueEmpty()) if (m_Scanner.isImageQueueEmpty())
{ {
m_Xfers.Count = 0; m_Xfers.Count = 0;
cerr << "ds: There was an error while prepping the image for scanning" << endl; //MessageBox(NULL,"_pXfers ==0 ","1",MB_OK);
setConditionCode(TWCC_BUMMER); //FileTools::write_log("D:/1.txt"," (m_Scanner.isImageQueueEmpty: m_Xfers.Count==0");
twrc = TWRC_FAILURE; //cerr << "ds: There was an error while prepping the image for scanning" << endl;
//setConditionCode(TWCC_BUMMER);
//twrc = TWRC_FAILURE;
} }
} }
} }
@ -1643,6 +1711,8 @@ TW_INT16 CTWAINDS_FreeImage::endXfer(pTW_PENDINGXFERS _pXfers)
if (_pXfers == 0) if (_pXfers == 0)
{ {
//FileTools::write_log("D:/1.txt"," (_pXfers: m_Xfers.Count==0");
setConditionCode(TWCC_BADVALUE); setConditionCode(TWCC_BADVALUE);
// Did everyting but return the currect count. // Did everyting but return the currect count.
return TWRC_CHECKSTATUS; return TWRC_CHECKSTATUS;
@ -1656,6 +1726,7 @@ TW_INT16 CTWAINDS_FreeImage::endXfer(pTW_PENDINGXFERS _pXfers)
{ {
if (bIndicators) if (bIndicators)
{ {
//FileTools::write_log("D:/1.txt"," (bIndicators: HIDDEN");
m_pGUI->UpdateProgress(false,'0',0,"0"); m_pGUI->UpdateProgress(false,'0',0,"0");
} }
} }
@ -1723,7 +1794,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
CTWAINContainerFix32 *pfCap = 0; CTWAINContainerFix32 *pfCap = 0;
CTWAINContainerFix32Range *pfRCap = 0; CTWAINContainerFix32Range *pfRCap = 0;
DWORD index = -1; DWORD index = -1;
//FileTools::write_log("D:/1.txt",)
if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_PIXELTYPE)))) if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_PIXELTYPE))))
{ {
cerr << "Could not get ICAP_PIXELTYPE" << endl; cerr << "Could not get ICAP_PIXELTYPE" << endl;
@ -1731,7 +1802,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
} }
else else
{ {
pnCap->SetCurrent(pConfig.Pixtype); bret=pnCap->SetCurrent(pConfig.Pixtype);
} }
if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_SUPPORTEDSIZES)))) if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_SUPPORTEDSIZES))))
@ -1741,17 +1812,17 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
} }
else else
{ {
pnCap->SetCurrent(pConfig.PaperSize); bret=pnCap->SetCurrent(pConfig.PaperSize);
} }
if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(CAP_DUPLEX)))) if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(CAP_DUPLEXENABLED))))
{ {
cerr << "Could not get ICAP_PIXELTYPE" << endl; cerr << "Could not get ICAP_PIXELTYPE" << endl;
bret = false; bret = false;
} }
else else
{ {
pnCap->SetCurrent(pConfig.Duplex==0? TWDX_1PASSDUPLEX:TWDX_2PASSDUPLEX); bret=pbCap->SetCurrent(pConfig.Duplex==0? FALSE:TRUE);
} }
if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_ORIENTATION)))) if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_ORIENTATION))))
@ -1761,7 +1832,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
} }
else else
{ {
pnCap->SetCurrent(pConfig.Orentation==4?TWOR_AUTOTEXT:pConfig.Orentation); bret=pnCap->SetCurrent(pConfig.Orentation==4?TWOR_AUTOTEXT:pConfig.Orentation);
} }
if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_FILTER)))) if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_FILTER))))
@ -1771,7 +1842,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
} }
else else
{ {
pnCap->SetCurrent(pConfig.Filter); bret=pnCap->SetCurrent(pConfig.Filter);
} }
if (0 == (pfCap = dynamic_cast<CTWAINContainerFix32*>(findCapability(ICAP_XRESOLUTION)))) if (0 == (pfCap = dynamic_cast<CTWAINContainerFix32*>(findCapability(ICAP_XRESOLUTION))))
@ -1782,7 +1853,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
else else
{ {
//pfCap->SetCurrent(pConfig->wDPI); //pfCap->SetCurrent(pConfig->wDPI);
pfCap->SetCurrent(pConfig.Resolution); bret=pfCap->SetCurrent((float)pConfig.Resolution);
} }
// Y resolution the same. // Y resolution the same.
@ -1794,7 +1865,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
else else
{ {
//pfCap->SetCurrent(pConfig->wDPI); //pfCap->SetCurrent(pConfig->wDPI);
pfCap->SetCurrent(pConfig.Resolution); bret=pfCap->SetCurrent(pConfig.Resolution);
} }
if (0 == (pfRCap = dynamic_cast<CTWAINContainerFix32Range*>(findCapability(ICAP_CONTRAST)))) if (0 == (pfRCap = dynamic_cast<CTWAINContainerFix32Range*>(findCapability(ICAP_CONTRAST))))
@ -1805,7 +1876,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
else else
{ {
float value_Contrast=GetContrast(pConfig.Contrast); float value_Contrast=GetContrast(pConfig.Contrast);
pfRCap->SetCurrent(value_Contrast); bret=pfRCap->SetCurrent(value_Contrast);
} }
if (0 == (pfRCap = dynamic_cast<CTWAINContainerFix32Range*>(findCapability(ICAP_BRIGHTNESS)))) if (0 == (pfRCap = dynamic_cast<CTWAINContainerFix32Range*>(findCapability(ICAP_BRIGHTNESS))))
@ -1815,7 +1886,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
} }
else else
{ {
pfRCap->SetCurrent(pConfig.Brightness); bret=pfRCap->SetCurrent(pConfig.Brightness);
} }
// Y resolution the same. // Y resolution the same.
if (0 == (pfRCap = dynamic_cast<CTWAINContainerFix32Range*>(findCapability(ICAP_GAMMA)))) if (0 == (pfRCap = dynamic_cast<CTWAINContainerFix32Range*>(findCapability(ICAP_GAMMA))))
@ -1825,30 +1896,30 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
} }
else else
{ {
pfRCap->SetCurrent(pConfig.Gamma/10.0); bret=pfRCap->SetCurrent(pConfig.Gamma/10.0);
} }
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(ICAP_AUTOMATICCROPUSESFRAME)))) if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(ICAP_AUTOMATICCROPUSESFRAME))))
{ {
cerr << "Could not get ICAP_AUTOMATICCROPUSESFRAME" << endl; cerr << "Could not get ICAP_AUTOMATICCROPUSESFRAME" << endl;
bret = false; bret=bret = false;
} }
else else
{ {
bool temp = (pConfig.PaperSize) == 90; bool temp = (pConfig.PaperSize) == 90;
pbCap->SetCurrent(temp); bret=pbCap->SetCurrent(temp);
} }
//填充黑框 //填充黑框
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8027)))) if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8004))))
{ {
cerr << "Could not get ICAP_AUTOMATICCROPUSESFRAME" << endl; cerr << "Could not get ICAP_AUTOMATICCROPUSESFRAME" << endl;
bret = false; bret = false;
} }
else else
{ {
pbCap->SetCurrent(pConfig.EnFillBlack); bret=pbCap->SetCurrent(pConfig.EnFillBlack);
} }
@ -1860,7 +1931,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
else else
{ {
bool temp = (pConfig.Duplex) == 2; bool temp = (pConfig.Duplex) == 2;
pbCap->SetCurrent(temp); bret=pbCap->SetCurrent(temp);
} }
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8091)))) if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8091))))
@ -1871,7 +1942,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
else else
{ {
bool temp = (pConfig.Duplex) == 3; bool temp = (pConfig.Duplex) == 3;
pbCap->SetCurrent(temp); bret=pbCap->SetCurrent(temp);
} }
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(ICAP_AUTOMATICDESKEW)))) if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(ICAP_AUTOMATICDESKEW))))
@ -1881,7 +1952,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
} }
else else
{ {
pbCap->SetCurrent(pConfig.EnAutoDescrew); bret=pbCap->SetCurrent(pConfig.EnAutoDescrew);
} }
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8005))))//背面旋转180 if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8005))))//背面旋转180
@ -1891,7 +1962,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
} }
else else
{ {
pbCap->SetCurrent(pConfig.EnBackRotate180); bret=pbCap->SetCurrent(pConfig.EnBackRotate180);
} }
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8006))))//歪斜检测 if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8006))))//歪斜检测
@ -1901,7 +1972,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
} }
else else
{ {
pbCap->SetCurrent(pConfig.EnScrewDetect); bret=pbCap->SetCurrent(pConfig.EnScrewDetect);
} }
if (0==(pbCap=dynamic_cast<CTWAINContainerBool*>(findCapability((CAP_DOUBLEFEEDDETECTION))))) if (0==(pbCap=dynamic_cast<CTWAINContainerBool*>(findCapability((CAP_DOUBLEFEEDDETECTION)))))
@ -1911,36 +1982,60 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
} }
else else
{ {
pbCap->SetCurrent(pConfig.EnUltrasonicDetect); bret=pbCap->SetCurrent(pConfig.EnUltrasonicDetect);
} }
if (0 == (pfRCap = dynamic_cast<CTWAINContainerFix32Range*>(findCapability(0x8021))))//歪斜检测等级 //歪斜检测等级
if (0 == (pfRCap = dynamic_cast<CTWAINContainerFix32Range*>(findCapability(0x8021))))
{ {
cerr << "Could not get CAP_SKREWDETECTLEVEL" << endl; cerr << "Could not get CAP_SKREWDETECTLEVEL" << endl;
bret = false; bret = false;
} }
else else
{ {
pfRCap->SetCurrent(pConfig.ScrewDetectLevel); bret=pfRCap->SetCurrent(pConfig.ScrewDetectLevel);
} }
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8090))))//装订检测 //装订检测
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8090))))
{ {
cerr << "Could not get CAP_STAPLEDETECT" << endl; cerr << "Could not get CAP_STAPLEDETECT" << endl;
bret = false; bret = false;
} }
else else
{ {
pbCap->SetCurrent(pConfig.EnBindingDetect); bret=pbCap->SetCurrent(pConfig.EnBindingDetect);
} }
//扫描张数
if (0==(pnCap=dynamic_cast<CTWAINContainerInt*>(findCapability(CAP_XFERCOUNT)))) if (0==(pnCap=dynamic_cast<CTWAINContainerInt*>(findCapability(CAP_XFERCOUNT))))
{ {
//XdPrint("updateScannerFromCaps CAP_XFERCOUNT Error"); //XdPrint("updateScannerFromCaps CAP_XFERCOUNT Error");
bret = false;
} }
else else
{ {
pnCap->SetCurrent(pConfig.ScanCount); bret=pnCap->SetCurrent(pConfig.ScanCount);
}
//去除穿孔
if (0==(pbCap=dynamic_cast<CTWAINContainerBool*>(findCapability(0x8018))))
{
bret = false;
}
else
{
pbCap->SetCurrent(pConfig.EnOutHole);
}
//去除穿孔占幅面比例
if (0==(pfRCap=dynamic_cast<CTWAINContainerFix32Range*>(findCapability(0x8092))))
{
bret=false;
}
else
{
pbCap->SetCurrent(pConfig.OutHoleRatio);
} }
return bret; return bret;
@ -1988,7 +2083,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pnCap->GetCurrent(nVal); bret=pnCap->GetCurrent(nVal);
settings->m_nPixelType = nVal; settings->m_nPixelType = nVal;
if (nVal==2) if (nVal==2)
@ -2008,19 +2103,19 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pnCap->GetCurrent(nVal); bret=pnCap->GetCurrent(nVal);
settings->m_HardWareParams.PaperType = nVal; settings->m_HardWareParams.PaperType = nVal;
} }
if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(CAP_DUPLEX)))) if (0 == (pbRCap = dynamic_cast<CTWAINContainerBool*>(findCapability(CAP_DUPLEXENABLED))))
{ {
cerr << "Could not get ICAP_PIXELTYPE" << endl; cerr << "Could not get ICAP_PIXELTYPE" << endl;
bret = false; bret = false;
} }
else else
{ {
pnCap->GetCurrent(nVal); bret=pbRCap->GetCurrent(bVal);
settings->m_bDuplex = nVal==TWDX_1PASSDUPLEX?false:true; settings->m_bDuplex = bVal;
} }
if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_ORIENTATION)))) if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_ORIENTATION))))
@ -2030,7 +2125,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pnCap->GetCurrent(nVal); bret=pnCap->GetCurrent(nVal);
settings->m_wRotation = nVal==TWOR_AUTOTEXT?4:nVal;; settings->m_wRotation = nVal==TWOR_AUTOTEXT?4:nVal;;
} }
@ -2041,7 +2136,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pnCap->GetCurrent(nVal); bret=pnCap->GetCurrent(nVal);
settings->m_nFilter = nVal; settings->m_nFilter = nVal;
if (nVal!=0) if (nVal!=0)
{ {
@ -2057,7 +2152,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pfCap->GetCurrent(fVal); bret=pfCap->GetCurrent(fVal);
settings->m_fXResolution = fVal; settings->m_fXResolution = fVal;
settings->m_HardWareParams.Resolution = 200; settings->m_HardWareParams.Resolution = 200;
} }
@ -2070,7 +2165,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pfCap->GetCurrent(fVal); bret=pfCap->GetCurrent(fVal);
settings->m_fYResolution = fVal; settings->m_fYResolution = fVal;
} }
@ -2081,7 +2176,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pfRCap->GetCurrent(fVal); bret=pfRCap->GetCurrent(fVal);
settings->m_fContrast = fVal; settings->m_fContrast = fVal;
} }
@ -2092,7 +2187,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pfRCap->GetCurrent(fVal); bret=pfRCap->GetCurrent(fVal);
settings->m_fBrightness = fVal; settings->m_fBrightness = fVal;
} }
// Y resolution the same. // Y resolution the same.
@ -2103,7 +2198,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pfRCap->GetCurrent(fVal); bret=pfRCap->GetCurrent(fVal);
settings->m_fGamma = fVal; settings->m_fGamma = fVal;
} }
@ -2114,19 +2209,19 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pbRCap->GetCurrent(bVal); bret=pbRCap->GetCurrent(bVal);
settings->m_bAutoCrop = bVal; settings->m_bAutoCrop = bVal;
} }
//填充黑框 //填充黑框
if (0 == (pbRCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8027)))) if (0 == (pbRCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8004))))
{ {
cerr << "Could not get ICAP_AUTOMATICCROPUSESFRAME" << endl; cerr << "Could not get ICAP_AUTOMATICCROPUSESFRAME" << endl;
bret = false; bret = false;
} }
else else
{ {
pbRCap->GetCurrent(bVal); bret=pbRCap->GetCurrent(bVal);
settings->m_bFillBlackRect=bVal; settings->m_bFillBlackRect=bVal;
} }
@ -2137,7 +2232,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pbRCap->GetCurrent(bVal); bret=pbRCap->GetCurrent(bVal);
settings->m_bAutoDiscardBlank = bVal; settings->m_bAutoDiscardBlank = bVal;
} }
@ -2149,7 +2244,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pbRCap->GetCurrent(bVal); bret=pbRCap->GetCurrent(bVal);
settings->m_bAutoDiscardBlankInvoice = bVal; settings->m_bAutoDiscardBlankInvoice = bVal;
} }
@ -2160,7 +2255,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pbRCap->GetCurrent(bVal); bret=pbRCap->GetCurrent(bVal);
settings->m_bAutoDeskew = bVal; settings->m_bAutoDeskew = bVal;
} }
@ -2171,7 +2266,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pbRCap->GetCurrent(bVal); bret= pbRCap->GetCurrent(bVal);
settings->m_HardWareParams.DoubleFeederOn=bVal; settings->m_HardWareParams.DoubleFeederOn=bVal;
} }
@ -2182,7 +2277,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pbRCap->GetCurrent(bVal); bret=pbRCap->GetCurrent(bVal);
settings->m_bBackRotate180 = bVal; settings->m_bBackRotate180 = bVal;
} }
@ -2193,7 +2288,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pbRCap->GetCurrent(bVal); bret=pbRCap->GetCurrent(bVal);
settings->m_HardWareParams.SkrewDetectOn = bVal; settings->m_HardWareParams.SkrewDetectOn = bVal;
} }
@ -2205,7 +2300,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pfRCap->GetCurrent(fVal); bret=pfRCap->GetCurrent(fVal);
settings->m_HardWareParams.SkrewDetectLevel= fVal; settings->m_HardWareParams.SkrewDetectLevel= fVal;
} }
@ -2216,7 +2311,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pbRCap->GetCurrent(bVal); bret=pbRCap->GetCurrent(bVal);
settings->m_HardWareParams.StapleDetectOn = bVal; settings->m_HardWareParams.StapleDetectOn = bVal;
} }
@ -2226,16 +2321,39 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
} }
else else
{ {
pnCap->GetCurrent(nVal); bret=pnCap->GetCurrent(nVal);
m_Xfers.Count=nVal;
bool bVal=settings->m_bDuplex;
//settings->m_wScanCount = 0; //settings->m_wScanCount = 0;
settings->m_wScanCount = nVal; settings->m_wScanCount = bVal?nVal/2:nVal;
//XdPrint("updateScannerFromCaps CAP_XFERCOUNT :%d \n", settings->m_wScanCount); //XdPrint("updateScannerFromCaps CAP_XFERCOUNT :%d \n", settings->m_wScanCount);
} }
//if (bret) //去除穿孔
//{ if (0==(pbRCap=dynamic_cast<CTWAINContainerBool*>(findCapability(0x8018))))
// m_Scanner.setSetting(*settings); {
//} bret=false;
}
else
{
bret=pbRCap->GetCurrent(bVal);
settings->m_OutHole.EnOutHole=bVal;
if (bVal)
{
//settings->m_bDuplex=true;
}
}
//去除穿孔占幅面比例
if (0==(pfRCap=dynamic_cast<CTWAINContainerFix32Range*>(findCapability(0x8092))))
{
bret=false;
}
else
{
pfRCap->GetCurrent(fVal);
settings->m_OutHole.OutHoleRatio=(int)fVal;
}
return bret; return bret;
} }
@ -2249,10 +2367,10 @@ bool CTWAINDS_FreeImage::DoCloseDSOkEvent()
} }
// Update the scanner with the latest negotiated caps // Update the scanner with the latest negotiated caps
if (!updateScannerFromCaps()) //if (!updateScannerFromCaps())
{ //{
return false; // return false;
} //}
return CTWAINDS_Base::DoCloseDSOkEvent(); return CTWAINDS_Base::DoCloseDSOkEvent();
} }
@ -2649,11 +2767,15 @@ bool CTWAINDS_FreeImage::StartScanning(bool showUI)
if (bIndicators) if (bIndicators)
{ {
m_pGUI->UpdateProgress(true,'0',0,"0"); m_pGUI->UpdateProgress(true,'0',0,"0");
//indi.ShowWindow(SW_SHOWNORMAL);
} }
bool ret=m_Scanner.acquireImage(); bool ret=m_Scanner.acquireImage();
if (bIndicators) if (bIndicators)
{ {
m_pGUI->UpdateProgress(ret?true:false,'0',0,"0"); if (!ret)
{
m_pGUI->UpdateProgress(false,'0',0,"0");
}
} }
return ret; return ret;
}; };

View File

@ -265,5 +265,6 @@ protected:
CTWAIN_UI *m_pGUI; /**< This is the main MFC UI dialog */ CTWAIN_UI *m_pGUI; /**< This is the main MFC UI dialog */
bool bIndicators; bool bIndicators;
BOOL b_created; BOOL b_created;
bool isDestroyed;
}; };
#endif // __CTWAINDS_FREEIMAGE_H__ #endif // __CTWAINDS_FREEIMAGE_H__

Binary file not shown.

View File

@ -20,7 +20,7 @@ void CImageApplyResize::apply(cv::Mat& pDib,int side)
{ {
float ratio = m_dpi / m_orgDpi; float ratio = m_dpi / m_orgDpi;
cv::resize(pDib, pDib, cv::Size(0, 0), ratio, ratio); cv::resize(pDib, pDib, cv::Size(0, 0), ratio, ratio);
XdPrint("1"); //XdPrint("1");
} }
} }
else else

View File

@ -171,7 +171,7 @@ cv::Mat CImageChannel::FilterColor(cv::Mat image,short channel)
for ( int x = 0; x < image.cols; x++, src += channels , dst++ ) for ( int x = 0; x < image.cols; x++, src += channels , dst++ )
{ {
unsigned short pix = *src; unsigned short pix = *src;
if(pix >=100){ if(pix >=130){
pix = 255; pix = 255;
} }
*dst = pix; *dst = pix;
@ -181,5 +181,4 @@ cv::Mat CImageChannel::FilterColor(cv::Mat image,short channel)
} }
} }
return dstImage; return dstImage;
} }

View File

@ -1,6 +1,8 @@
#include "StdAfx.h" #include "StdAfx.h"
#include "ImageMatQueue.h" #include "ImageMatQueue.h"
#include "PublicFunc.h" #include "PublicFunc.h"
#include "filetools.h"
#include "ImageOutHole.h"
ImageMatQueue::ImageMatQueue(void) ImageMatQueue::ImageMatQueue(void)
{ {
@ -16,8 +18,8 @@ void ImageMatQueue::run()
{ {
if(!bRun) if(!bRun)
{ {
m_threadProc = boost::thread(&ImageMatQueue::proc, this);
bRun = true; bRun = true;
m_threadProc = boost::thread(&ImageMatQueue::proc, this);
} }
} }
@ -87,20 +89,58 @@ void ImageMatQueue::proc()
if(m_images.empty() && !m_pImages.empty()) if(m_images.empty() && !m_pImages.empty())
{ {
if (pixType!=-1) if (pixType!=-1)
{
if (outHole.EnOutHole&&m_pImages.size()>=2)//确保能够获取正反两面图
{
cv::Mat imgF=m_pImages.front().getMat(pixType);
m_pImages.pop();
cv::Mat imgB=m_pImages.front().getMat(pixType);
m_pImages.pop();
vector<cv::Mat> mats;
ImageOutHole outhole;
if (!imgF.empty()&&!imgB.empty())
{
outhole.puncture(imgF,imgB,50.0,outHole.OutHoleRatio/100.0,50);
mats.push_back(imgF);
mats.push_back(imgB);
for (int i=0,length=mats.size();i<length;i++)
{
if (!mats[i].empty())
{
for (int j=0;j<m_iaList.size();j++)
{
if (mats[i].empty())
break;
m_iaList[j]->apply(mats[i],i);
}
}
if (!mats[i].empty())
{
m_images.push(mats[i]);
}
}
}
}
else
{ {
cv::Mat image = m_pImages.front().getMat(pixType); cv::Mat image = m_pImages.front().getMat(pixType);
int side=m_pImages.front().getSide(); int side=m_pImages.front().getSide();
m_pImages.pop();
for (int i=0;i<m_iaList.size();i++) for (int i=0;i<m_iaList.size();i++)
{ {
if (image.empty()) if (image.empty())
break; break;
m_iaList[i]->apply(image,side); m_iaList[i]->apply(image,side);
} }
m_pImages.pop(); char pC[1000];
char* str="1111";
strcpy(pC,str);
if (!image.empty()) if (!image.empty())
{
m_images.push(image); m_images.push(image);
} }
} }
} }
} }

View File

@ -6,6 +6,7 @@
#include "JpegBuffer.h" #include "JpegBuffer.h"
#include <queue> #include <queue>
#include "ImageApply.h" #include "ImageApply.h"
#include "PublicFunc.h"
class ImageMatQueue class ImageMatQueue
{ {
@ -19,10 +20,10 @@ public:
bool valid(); bool valid();
void clear(); void clear();
void setlist(std::vector<std::shared_ptr<CImageApply>> list); void setlist(std::vector<std::shared_ptr<CImageApply>> list);
void run(); void run();
public: public:
int pixType; int pixType;
OutHole outHole;
private: private:
void proc(); void proc();
cv::Mat _popMat(); cv::Mat _popMat();
@ -33,6 +34,7 @@ private:
boost::mutex m_mtxJB; boost::mutex m_mtxJB;
boost::thread m_threadProc; boost::thread m_threadProc;
volatile bool bRun; volatile bool bRun;
std::vector<std::shared_ptr<CImageApply>> m_iaList; std::vector<std::shared_ptr<CImageApply>> m_iaList;
}; };

View File

@ -3,7 +3,7 @@
using namespace cv; using namespace cv;
static int ProcessRectR(Mat & image, RotatedRect & rotatedRect, vector<Point>& maxContour, double scale, double thresh, int blobAreaSize) int CImageProcDiscardBlank::ProcessRectR(Mat & image, RotatedRect & rotatedRect, vector<Point>& maxContour, double scale, double thresh, int blobAreaSize)
{ {
Mat gray; Mat gray;
int blockCount = 0; int blockCount = 0;
@ -34,7 +34,8 @@ static int ProcessRectR(Mat & image, RotatedRect & rotatedRect, vector<Point>& m
Mat threshold_img; Mat threshold_img;
threshold(gray, threshold_img, thresh, 255.0, CV_THRESH_BINARY); threshold(gray, threshold_img, thresh, 255.0, CV_THRESH_BINARY);
vector<vector<Point>> contours; vector<vector<Point>> contours;
findContours(threshold_img, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); cv::vector<Vec4i> h1;
GetContours(threshold_img, contours, h1, CV_CHAIN_APPROX_SIMPLE);
threshold_img.release(); threshold_img.release();
if (contours.size() == 0) if (contours.size() == 0)
@ -75,7 +76,7 @@ static int ProcessRectR(Mat & image, RotatedRect & rotatedRect, vector<Point>& m
rotatedRect.size.height = l_temp; rotatedRect.size.height = l_temp;
} }
vector<int> hull; vector<int> hull(list_com.size());
convexHull(list_com, hull); convexHull(list_com, hull);
for (int i = 0; i < hull.size(); i++) for (int i = 0; i < hull.size(); i++)
@ -89,7 +90,7 @@ static int ProcessRectR(Mat & image, RotatedRect & rotatedRect, vector<Point>& m
return blockCount; return blockCount;
} }
static bool Scalar_LE(cv::Scalar& val1, cv::Scalar& val2) bool CImageProcDiscardBlank:: Scalar_LE(cv::Scalar& val1, cv::Scalar& val2)
{ {
for(int i = 0; i < 3; i++) for(int i = 0; i < 3; i++)
{ {
@ -120,6 +121,50 @@ void CImageProcDiscardBlank::setMinArea(int val)
dSize = max(min(500, val), 100); dSize = max(min(500, val), 100);
} }
void CImageProcDiscardBlank::GetContours(const Mat& src, vector<vector<Point>>& contours, vector<Vec4i>& hierarchy, int retr /*= RETR_CCOMP*/)
{
CvMat c_image = src;
MemStorage storage(cvCreateMemStorage());
CvSeq* _ccontours = 0;
cvFindContours(&c_image, storage, &_ccontours, sizeof(CvContour), retr, CHAIN_APPROX_SIMPLE);
if (!_ccontours)
{
contours.clear();
return;
}
Seq<CvSeq*> all_contours(cvTreeToNodeSeq(_ccontours, sizeof(CvSeq), storage));
int total = (int)all_contours.size();
contours.resize(total);
SeqIterator<CvSeq*> it = all_contours.begin();
for (int i = 0; i < total; i++, ++it)
{
CvSeq* c = *it;
((CvContour*)c)->color = (int)i;
int count = (int)c->total;
int* data = new int[count * 2];
cvCvtSeqToArray(c, data);
for (int j = 0; j < count; j++)
{
contours[i].push_back(Point(data[j * 2], data[j * 2 + 1]));
}
delete[] data;
}
hierarchy.resize(total);
it = all_contours.begin();
for (int i = 0; i < total; i++, ++it)
{
CvSeq* c = *it;
int h_next = c->h_next ? ((CvContour*)c->h_next)->color : -1;
int h_prev = c->h_prev ? ((CvContour*)c->h_prev)->color : -1;
int v_next = c->v_next ? ((CvContour*)c->v_next)->color : -1;
int v_prev = c->v_prev ? ((CvContour*)c->v_prev)->color : -1;
hierarchy[i] = Vec4i(h_next, h_prev, v_next, v_prev);
}
}
cv::Mat CImageProcDiscardBlank::getRoiMat(cv::Mat& image) cv::Mat CImageProcDiscardBlank::getRoiMat(cv::Mat& image)
{ {
int gap = 100; int gap = 100;

View File

@ -1,6 +1,10 @@
#pragma once #pragma once
#include "ImageApply.h" #include "ImageApply.h"
#include <math.h> #include <math.h>
#include "opencv2/opencv.hpp"
#include "opencv/cv.h"
#include "opencv2/core/core.hpp"
using namespace cv;
class CImageProcDiscardBlank : class CImageProcDiscardBlank :
public CImageApply public CImageApply
@ -14,7 +18,9 @@ public:
private: private:
void setIntensity(int val); void setIntensity(int val);
void setMinArea(int val); void setMinArea(int val);
int ProcessRectR(Mat & image, RotatedRect & rotatedRect, vector<Point>& maxContour, double scale, double thresh, int blobAreaSize);
bool Scalar_LE(cv::Scalar& val1, cv::Scalar& val2);
void GetContours(const Mat& src, cv::vector<cv::vector<Point>>& contours, cv::vector<Vec4i>& hierarchy, int retr = RETR_CCOMP);
private: private:
int dSize; int dSize;

Binary file not shown.

Binary file not shown.

View File

@ -30,13 +30,19 @@ void JsonConfig::WriteToJson(PCONFIGPARAMS pConfigItem,const std::string fileNam
outJson["Config"].Add(RESOLUTION,(int)(pConfigItem->Resolution)); outJson["Config"].Add(RESOLUTION,(int)(pConfigItem->Resolution));
outJson["Config"].Add(DUPLEX,(int)(pConfigItem->Duplex)); outJson["Config"].Add(DUPLEX,(int)(pConfigItem->Duplex));
outJson["Config"].Add(DISCARBLANK,(bool)(pConfigItem->EnDiscardBlank),false); outJson["Config"].Add(DISCARBLANK,(bool)(pConfigItem->EnDiscardBlank),false);
outJson["Config"].Add(DISCARBLANKVINCE,(bool)(pConfigItem->EnDiscardBlankVince),false);
outJson["Config"].Add(BRIGHTNESS,(int)(pConfigItem->Brightness)); outJson["Config"].Add(BRIGHTNESS,(int)(pConfigItem->Brightness));
outJson["Config"].Add(AUTOCONTRAST,(bool)(pConfigItem->EnAutoContrast),false); outJson["Config"].Add(AUTOCONTRAST,(bool)(pConfigItem->EnAutoContrast),false);
outJson["Config"].Add(CONTRAST,(int)(pConfigItem->Contrast)); outJson["Config"].Add(CONTRAST,(int)(pConfigItem->Contrast));
outJson["Config"].Add(GAMMA,(int)(pConfigItem->Gamma)); outJson["Config"].Add(GAMMA,(int)(pConfigItem->Gamma));
outJson["Config"].Add(FILTERTYPE,(int)(pConfigItem->Filter)); outJson["Config"].Add(FILTERTYPE,(int)(pConfigItem->Filter));
outJson["Config"].Add(AUTODESCREW,(bool)(pConfigItem->EnAutoDescrew),false); outJson["Config"].Add(AUTODESCREW,(bool)(pConfigItem->EnAutoDescrew),false);
outJson["Config"].Add(FILLBLACK,(bool)(pConfigItem->EnFillBlack),false); outJson["Config"].Add(FILLBLACK,(bool)(pConfigItem->EnFillBlack),false);
outJson["Config"].Add(OUTHOLE,(bool)(pConfigItem->EnOutHole),false);
outJson["Config"].Add(OUTHOLERATIO,(int)(pConfigItem->OutHoleRatio));
outJson["Config"].Add(ULTRADETECT,(bool)(pConfigItem->EnUltrasonicDetect),false); outJson["Config"].Add(ULTRADETECT,(bool)(pConfigItem->EnUltrasonicDetect),false);
outJson["Config"].Add(BINDINGDETECT,(bool)(pConfigItem->EnBindingDetect),false); outJson["Config"].Add(BINDINGDETECT,(bool)(pConfigItem->EnBindingDetect),false);
outJson["Config"].Add(SCANCOUNT,(int)(pConfigItem->ScanCount)); outJson["Config"].Add(SCANCOUNT,(int)(pConfigItem->ScanCount));
@ -82,13 +88,19 @@ void JsonConfig::WriteJsonArrayToFile(std::vector<CONFIGPARAMS> cfgArray,const s
root["Config"].AddEmptySubArray(RESOLUTION); root["Config"].AddEmptySubArray(RESOLUTION);
root["Config"].AddEmptySubArray(DUPLEX); root["Config"].AddEmptySubArray(DUPLEX);
root["Config"].AddEmptySubArray(DISCARBLANK); root["Config"].AddEmptySubArray(DISCARBLANK);
root["Config"].AddEmptySubArray(DISCARBLANKVINCE);
root["Config"].AddEmptySubArray(BRIGHTNESS); root["Config"].AddEmptySubArray(BRIGHTNESS);
root["Config"].AddEmptySubArray(AUTOCONTRAST); root["Config"].AddEmptySubArray(AUTOCONTRAST);
root["Config"].AddEmptySubArray(CONTRAST); root["Config"].AddEmptySubArray(CONTRAST);
root["Config"].AddEmptySubArray(GAMMA); root["Config"].AddEmptySubArray(GAMMA);
root["Config"].AddEmptySubArray(FILTERTYPE); root["Config"].AddEmptySubArray(FILTERTYPE);
root["Config"].AddEmptySubArray(AUTODESCREW); root["Config"].AddEmptySubArray(AUTODESCREW);
root["Config"].AddEmptySubArray(FILLBLACK); root["Config"].AddEmptySubArray(FILLBLACK);
root["Config"].AddEmptySubArray(OUTHOLE);
root["Config"].AddEmptySubArray(OUTHOLERATIO);
root["Config"].AddEmptySubArray(ULTRADETECT); root["Config"].AddEmptySubArray(ULTRADETECT);
root["Config"].AddEmptySubArray(BINDINGDETECT); root["Config"].AddEmptySubArray(BINDINGDETECT);
root["Config"].AddEmptySubArray(SCANCOUNT); root["Config"].AddEmptySubArray(SCANCOUNT);
@ -96,6 +108,7 @@ void JsonConfig::WriteJsonArrayToFile(std::vector<CONFIGPARAMS> cfgArray,const s
root["Config"].AddEmptySubArray(BACKROTATE180); root["Config"].AddEmptySubArray(BACKROTATE180);
root["Config"].AddEmptySubArray(SCREWDETECT); root["Config"].AddEmptySubArray(SCREWDETECT);
root["Config"].AddEmptySubArray(SCREWLEVEL); root["Config"].AddEmptySubArray(SCREWLEVEL);
root["Config"].AddEmptySubArray(ITEMCAPTION); root["Config"].AddEmptySubArray(ITEMCAPTION);
root["Config"].AddEmptySubArray(SAVEPATH); root["Config"].AddEmptySubArray(SAVEPATH);
for (int i=0;i<cfgArray.size();i++) for (int i=0;i<cfgArray.size();i++)
@ -106,13 +119,19 @@ void JsonConfig::WriteJsonArrayToFile(std::vector<CONFIGPARAMS> cfgArray,const s
root["Config"][RESOLUTION].Add(cfgArray[i].Resolution); root["Config"][RESOLUTION].Add(cfgArray[i].Resolution);
root["Config"][DUPLEX].Add(cfgArray[i].Duplex); root["Config"][DUPLEX].Add(cfgArray[i].Duplex);
root["Config"][DISCARBLANK].Add(i,cfgArray[i].EnDiscardBlank); root["Config"][DISCARBLANK].Add(i,cfgArray[i].EnDiscardBlank);
root["Config"][DISCARBLANKVINCE].Add(i,cfgArray[i].EnDiscardBlankVince);
root["Config"][BRIGHTNESS].Add(cfgArray[i].Brightness); root["Config"][BRIGHTNESS].Add(cfgArray[i].Brightness);
root["Config"][AUTOCONTRAST].Add(i,cfgArray[i].EnAutoContrast); root["Config"][AUTOCONTRAST].Add(i,cfgArray[i].EnAutoContrast);
root["Config"][CONTRAST].Add(cfgArray[i].Contrast); root["Config"][CONTRAST].Add(cfgArray[i].Contrast);
root["Config"][GAMMA].Add(cfgArray[i].Gamma); root["Config"][GAMMA].Add(cfgArray[i].Gamma);
root["Config"][FILTERTYPE].Add(cfgArray[i].Filter); root["Config"][FILTERTYPE].Add(cfgArray[i].Filter);
root["Config"][AUTODESCREW].Add(i,cfgArray[i].EnAutoDescrew); root["Config"][AUTODESCREW].Add(i,cfgArray[i].EnAutoDescrew);
root["Config"][FILLBLACK].Add(i,cfgArray[i].EnFillBlack); root["Config"][FILLBLACK].Add(i,cfgArray[i].EnFillBlack);
root["Config"][OUTHOLE].Add(i,cfgArray[i].EnOutHole);
root["Config"][OUTHOLERATIO].Add(cfgArray[i].OutHoleRatio);
root["Config"][ULTRADETECT].Add(i,cfgArray[i].EnUltrasonicDetect); root["Config"][ULTRADETECT].Add(i,cfgArray[i].EnUltrasonicDetect);
root["Config"][BINDINGDETECT].Add(i,cfgArray[i].EnBindingDetect); root["Config"][BINDINGDETECT].Add(i,cfgArray[i].EnBindingDetect);
root["Config"][SCANCOUNT].Add(cfgArray[i].ScanCount); root["Config"][SCANCOUNT].Add(cfgArray[i].ScanCount);
@ -120,6 +139,7 @@ void JsonConfig::WriteJsonArrayToFile(std::vector<CONFIGPARAMS> cfgArray,const s
root["Config"][BACKROTATE180].Add(i,cfgArray[i].EnBackRotate180); root["Config"][BACKROTATE180].Add(i,cfgArray[i].EnBackRotate180);
root["Config"][SCREWDETECT].Add(i,cfgArray[i].EnScrewDetect); root["Config"][SCREWDETECT].Add(i,cfgArray[i].EnScrewDetect);
root["Config"][SCREWLEVEL].Add(cfgArray[i].ScrewDetectLevel); root["Config"][SCREWLEVEL].Add(cfgArray[i].ScrewDetectLevel);
if (cfgArray[i].Caption.c_str()!=NULL) if (cfgArray[i].Caption.c_str()!=NULL)
{ {
root["Config"][ITEMCAPTION].Add(cfgArray[i].Caption); root["Config"][ITEMCAPTION].Add(cfgArray[i].Caption);
@ -138,7 +158,7 @@ void JsonConfig::WriteJsonArrayToFile(std::vector<CONFIGPARAMS> cfgArray,const s
CONFIGPARAMS JsonConfig::ReadDefaultConfig() CONFIGPARAMS JsonConfig::ReadDefaultConfig()
{ {
TCHAR szIniFile[MAX_PATH] = { 0 }; TCHAR szIniFile[MAX_PATH] = { 0 };
SHGetSpecialFolderPath(NULL, szIniFile, CSIDL_COMMON_DOCUMENTS, TRUE); SHGetSpecialFolderPath(NULL, szIniFile, CSIDL_LOCAL_APPDATA, TRUE);
_tcscat(szIniFile, HUAGAO_SCAN); _tcscat(szIniFile, HUAGAO_SCAN);
_tcscat(szIniFile,TWAIN_INIPATH); _tcscat(szIniFile,TWAIN_INIPATH);
_tcscat(szIniFile, TEXT("\\")); _tcscat(szIniFile, TEXT("\\"));
@ -192,13 +212,19 @@ CONFIGPARAMS JsonConfig::GetDefaultConfigParams()
params.Resolution=200;//200dpi params.Resolution=200;//200dpi
params.Duplex=1;//双面 params.Duplex=1;//双面
params.EnDiscardBlank=FALSE;//自动丢弃空白页 params.EnDiscardBlank=FALSE;//自动丢弃空白页
params.EnDiscardBlankVince=FALSE;
params.Brightness=0;//亮度 params.Brightness=0;//亮度
params.EnAutoContrast=FALSE;//自动对比度 params.EnAutoContrast=FALSE;//自动对比度
params.Contrast=0;//对比度 params.Contrast=0;//对比度
params.Gamma=10;//伽玛值 params.Gamma=10;//伽玛值
params.Filter=0;//除色 无 params.Filter=0;//除色 无
params.EnFillBlack=FALSE;//不填黑框 params.EnFillBlack=FALSE;//不填黑框
params.EnAutoDescrew=TRUE;//不自动纠偏 params.EnAutoDescrew=TRUE;//不自动纠偏
params.EnOutHole=FALSE;//²»È¥³ý¿×¶´
params.OutHoleRatio=10;//ĬÈÏÖµ0.10
params.EnUltrasonicDetect=TRUE;//超声检测开关 开 params.EnUltrasonicDetect=TRUE;//超声检测开关 开
params.EnBindingDetect=FALSE;//装订检测开关 开 params.EnBindingDetect=FALSE;//装订检测开关 开
params.ScanCount=-1;//扫描张数 params.ScanCount=-1;//扫描张数
@ -231,6 +257,9 @@ std::vector<CONFIGPARAMS> JsonConfig::parseJsonFromString(const std::string str)
root["Config"].Get(DUPLEX,itmDulpex); root["Config"].Get(DUPLEX,itmDulpex);
neb::CJsonObject itmDiscardBlk; neb::CJsonObject itmDiscardBlk;
root["Config"].Get(DISCARBLANK,itmDiscardBlk); root["Config"].Get(DISCARBLANK,itmDiscardBlk);
neb::CJsonObject itmDiscardBlkVince;
root["Config"].Get(DISCARBLANKVINCE,itmDiscardBlkVince);
neb::CJsonObject itmBrtnes; neb::CJsonObject itmBrtnes;
root["Config"].Get(BRIGHTNESS,itmBrtnes); root["Config"].Get(BRIGHTNESS,itmBrtnes);
neb::CJsonObject itmAutoCrnt; neb::CJsonObject itmAutoCrnt;
@ -239,12 +268,18 @@ std::vector<CONFIGPARAMS> JsonConfig::parseJsonFromString(const std::string str)
root["Config"].Get(CONTRAST,itmContrast); root["Config"].Get(CONTRAST,itmContrast);
neb::CJsonObject itmGamma; neb::CJsonObject itmGamma;
root["Config"].Get(GAMMA,itmGamma); root["Config"].Get(GAMMA,itmGamma);
neb::CJsonObject itmFilter; neb::CJsonObject itmFilter;
root["Config"].Get(FILTERTYPE,itmFilter); root["Config"].Get(FILTERTYPE,itmFilter);
neb::CJsonObject itmAutoDescrew; neb::CJsonObject itmAutoDescrew;
root["Config"].Get(AUTODESCREW,itmAutoDescrew); root["Config"].Get(AUTODESCREW,itmAutoDescrew);
neb::CJsonObject itmFillBlack; neb::CJsonObject itmFillBlack;
root["Config"].Get(FILLBLACK,itmFillBlack); root["Config"].Get(FILLBLACK,itmFillBlack);
neb::CJsonObject itmOutHole;
root["Config"].Get(OUTHOLE,itmOutHole);
neb::CJsonObject itmOutHoleRatio;
root["Config"].Get(OUTHOLERATIO,itmOutHoleRatio);
neb::CJsonObject itmUltDetect; neb::CJsonObject itmUltDetect;
root["Config"].Get(ULTRADETECT,itmUltDetect); root["Config"].Get(ULTRADETECT,itmUltDetect);
neb::CJsonObject itmBingdingDetect; neb::CJsonObject itmBingdingDetect;
@ -259,6 +294,7 @@ std::vector<CONFIGPARAMS> JsonConfig::parseJsonFromString(const std::string str)
root["Config"].Get(SCREWDETECT,itmScrewDetct); root["Config"].Get(SCREWDETECT,itmScrewDetct);
neb::CJsonObject itmScrewLevel; neb::CJsonObject itmScrewLevel;
root["Config"].Get(SCREWLEVEL,itmScrewLevel); root["Config"].Get(SCREWLEVEL,itmScrewLevel);
neb::CJsonObject itmCaption; neb::CJsonObject itmCaption;
if (!root["Config"][ITEMCAPTION].IsEmpty()) if (!root["Config"][ITEMCAPTION].IsEmpty())
{ {
@ -275,6 +311,7 @@ std::vector<CONFIGPARAMS> JsonConfig::parseJsonFromString(const std::string str)
int i_value; int i_value;
bool b_value; bool b_value;
std::string s_value; std::string s_value;
itmPixType.Get(i,i_value); itmPixType.Get(i,i_value);
cfp.Pixtype=i_value; cfp.Pixtype=i_value;
itmPaparSize.Get(i,i_value); itmPaparSize.Get(i,i_value);
@ -287,6 +324,9 @@ std::vector<CONFIGPARAMS> JsonConfig::parseJsonFromString(const std::string str)
cfp.Duplex=i_value; cfp.Duplex=i_value;
itmDiscardBlk.Get(i,b_value); itmDiscardBlk.Get(i,b_value);
cfp.EnDiscardBlank=b_value; cfp.EnDiscardBlank=b_value;
itmDiscardBlkVince.Get(i,b_value);
cfp.EnDiscardBlankVince=b_value;
itmBrtnes.Get(i,i_value); itmBrtnes.Get(i,i_value);
cfp.Brightness=i_value; cfp.Brightness=i_value;
itmAutoCrnt.Get(i,b_value); itmAutoCrnt.Get(i,b_value);
@ -295,12 +335,18 @@ std::vector<CONFIGPARAMS> JsonConfig::parseJsonFromString(const std::string str)
cfp.Contrast=i_value; cfp.Contrast=i_value;
itmGamma.Get(i,i_value); itmGamma.Get(i,i_value);
cfp.Gamma=i_value; cfp.Gamma=i_value;
itmFilter.Get(i,i_value); itmFilter.Get(i,i_value);
cfp.Filter=i_value; cfp.Filter=i_value;
itmAutoDescrew.Get(i,b_value); itmAutoDescrew.Get(i,b_value);
cfp.EnAutoDescrew=b_value; cfp.EnAutoDescrew=b_value;
itmFillBlack.Get(i,b_value); itmFillBlack.Get(i,b_value);
cfp.EnFillBlack=b_value; cfp.EnFillBlack=b_value;
itmOutHole.Get(i,b_value);
cfp.EnOutHole=b_value;
itmOutHoleRatio.Get(i,i_value);
cfp.OutHoleRatio=i_value;
itmUltDetect.Get(i,b_value); itmUltDetect.Get(i,b_value);
cfp.EnUltrasonicDetect=b_value; cfp.EnUltrasonicDetect=b_value;
itmBingdingDetect.Get(i,b_value); itmBingdingDetect.Get(i,b_value);
@ -315,6 +361,7 @@ std::vector<CONFIGPARAMS> JsonConfig::parseJsonFromString(const std::string str)
cfp.EnScrewDetect=b_value; cfp.EnScrewDetect=b_value;
itmScrewLevel.Get(i,i_value); itmScrewLevel.Get(i,i_value);
cfp.ScrewDetectLevel=i_value; cfp.ScrewDetectLevel=i_value;
if (!root["Config"][ITEMCAPTION].IsEmpty()) if (!root["Config"][ITEMCAPTION].IsEmpty())
{ {
itmCaption.Get(i,s_value); itmCaption.Get(i,s_value);
@ -334,6 +381,7 @@ std::vector<CONFIGPARAMS> JsonConfig::parseJsonFromString(const std::string str)
int index; int index;
bool bvalue; bool bvalue;
std::string svalue; std::string svalue;
root["Config"].Get(PIXTYPE,index); root["Config"].Get(PIXTYPE,index);
cfp.Pixtype=index; cfp.Pixtype=index;
root["Config"].Get(PAPARSIZE,index); root["Config"].Get(PAPARSIZE,index);
@ -346,6 +394,9 @@ std::vector<CONFIGPARAMS> JsonConfig::parseJsonFromString(const std::string str)
cfp.Duplex=index; cfp.Duplex=index;
root["Config"].Get(DISCARBLANK,bvalue); root["Config"].Get(DISCARBLANK,bvalue);
cfp.EnDiscardBlank=bvalue; cfp.EnDiscardBlank=bvalue;
root["Config"].Get(DISCARBLANKVINCE,bvalue);
cfp.EnDiscardBlankVince=bvalue;
root["Config"].Get(BRIGHTNESS,index); root["Config"].Get(BRIGHTNESS,index);
cfp.Brightness=index; cfp.Brightness=index;
root["Config"].Get(AUTOCONTRAST,bvalue); root["Config"].Get(AUTOCONTRAST,bvalue);
@ -354,12 +405,18 @@ std::vector<CONFIGPARAMS> JsonConfig::parseJsonFromString(const std::string str)
cfp.Contrast=index; cfp.Contrast=index;
root["Config"].Get(GAMMA,index); root["Config"].Get(GAMMA,index);
cfp.Gamma=index; cfp.Gamma=index;
root["Config"].Get(FILTERTYPE,index); root["Config"].Get(FILTERTYPE,index);
cfp.Filter=index; cfp.Filter=index;
root["Config"].Get(AUTODESCREW,bvalue); root["Config"].Get(AUTODESCREW,bvalue);
cfp.EnAutoCrop=bvalue; cfp.EnAutoCrop=bvalue;
root["Config"].Get(FILLBLACK,bvalue); root["Config"].Get(FILLBLACK,bvalue);
cfp.EnFillBlack=bvalue; cfp.EnFillBlack=bvalue;
root["Config"].Get(OUTHOLE,bvalue);
cfp.EnOutHole=bvalue;
root["Config"].Get(OUTHOLERATIO,index);
cfp.OutHoleRatio=index;
root["Config"].Get(ULTRADETECT,bvalue); root["Config"].Get(ULTRADETECT,bvalue);
cfp.EnUltrasonicDetect=bvalue; cfp.EnUltrasonicDetect=bvalue;
root["Config"].Get(BINDINGDETECT,bvalue); root["Config"].Get(BINDINGDETECT,bvalue);
@ -374,6 +431,7 @@ std::vector<CONFIGPARAMS> JsonConfig::parseJsonFromString(const std::string str)
cfp.EnScrewDetect=bvalue; cfp.EnScrewDetect=bvalue;
root["Config"].Get(SCREWLEVEL,index); root["Config"].Get(SCREWLEVEL,index);
cfp.ScrewDetectLevel=index; cfp.ScrewDetectLevel=index;
if (!root["Config"][ITEMCAPTION].IsEmpty()) if (!root["Config"][ITEMCAPTION].IsEmpty())
{ {
root["Config"].Get(ITEMCAPTION,svalue); root["Config"].Get(ITEMCAPTION,svalue);

View File

@ -4,7 +4,6 @@
#include "IndicatorDlg.h" #include "IndicatorDlg.h"
#include "hugaotwainds.h" #include "hugaotwainds.h"
#include "Resource.h" #include "Resource.h"
#include "hugaotwainds.h"
extern ChugaotwaindsApp theApp; extern ChugaotwaindsApp theApp;
@ -25,6 +24,7 @@ MFC_UI::~MFC_UI()
TW_INT16 MFC_UI::DisplayTWAINGUI(TW_USERINTERFACE Data, bool bSetup, bool bIndicators) TW_INT16 MFC_UI::DisplayTWAINGUI(TW_USERINTERFACE Data, bool bSetup, bool bIndicators)
{ {
TW_INT16 ret=TWRC_SUCCESS;
TW_INT16 nRes = CTWAIN_UI::DisplayTWAINGUI(Data, bSetup, bIndicators); TW_INT16 nRes = CTWAIN_UI::DisplayTWAINGUI(Data, bSetup, bIndicators);
if (nRes) if (nRes)
{ {
@ -37,30 +37,32 @@ TW_INT16 MFC_UI::DisplayTWAINGUI(TW_USERINTERFACE Data, bool bSetup, bool bIndic
if (Data.ShowUI == 0 && !bIndicators) if (Data.ShowUI == 0 && !bIndicators)
{ {
return TWRC_SUCCESS; return ret;
} }
if (Data.hParent) if (Data.hParent)
{ {
CDialog* dlg = new CDialog(); if (m_pChildWnd==NULL)
dlg->Create(IDD_DIALOG_TWAINUI); {
CDialog* dlg =new CDialog();
dlg->Create(IDD_DIALOGBACK);
m_pChildWnd = dlg; m_pChildWnd = dlg;
theApp.m_pMainWnd = m_pChildWnd; theApp.m_pMainWnd = m_pChildWnd;
//long ll = GetWindowLong(m_pChildWnd->GetSafeHwnd(), GWL_STYLE);
long ll = GetWindowLong(m_pChildWnd->GetSafeHwnd(), GWL_STYLE); //SetWindowLong(m_pChildWnd->GetSafeHwnd(), GWL_STYLE, WS_CHILD | ll);
SetWindowLong(m_pChildWnd->GetSafeHwnd(), GWL_STYLE, WS_CHILD | ll);
SetParent(m_pChildWnd->GetSafeHwnd(), (HWND)Data.hParent); SetParent(m_pChildWnd->GetSafeHwnd(), (HWND)Data.hParent);
//dlg->ShowWindow(SW_SHOWNORMAL);
}
} }
if (bIndicators)
{
indicator=new IndicatorDlg(this,Data.ShowUI?m_pDlg:m_pChildWnd);
showUI=Data.ShowUI;
}
if (Data.ShowUI) if (Data.ShowUI)
{
if (m_pDlg==NULL)
{ {
m_pDlg = new TwainUIDlg(this, m_pChildWnd); m_pDlg = new TwainUIDlg(this, m_pChildWnd);
m_pDlg->Create(IDD_DIALOG_TWAINUI, m_pChildWnd); m_pDlg->Create(IDD_DIALOG_TWAINUI, m_pChildWnd);
}
if (!bSetup) if (!bSetup)
{ {
m_pDlg->SetDlgItemTextA(IDC_CONFIRM, _T("ɨÃè")); m_pDlg->SetDlgItemTextA(IDC_CONFIRM, _T("ɨÃè"));
@ -69,16 +71,31 @@ TW_INT16 MFC_UI::DisplayTWAINGUI(TW_USERINTERFACE Data, bool bSetup, bool bIndic
{ {
m_pDlg->SetDlgItemTextA(IDC_CONFIRM, _T("È·¶¨")); m_pDlg->SetDlgItemTextA(IDC_CONFIRM, _T("È·¶¨"));
} }
if (m_pDlg) if (m_pDlg)
{ {
//long ll = GetWindowLong(m_pChildWnd->GetSafeHwnd(), GWL_STYLE);
SetWindowPos((HWND)Data.hParent,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
m_pDlg->ShowWindow(SW_SHOWNORMAL); m_pDlg->ShowWindow(SW_SHOWNORMAL);
} }
else else
{ {
return TWRC_FAILURE; ret=TWRC_FAILURE;
} }
} }
return TWRC_SUCCESS;
if (bIndicators)
{
if (indicator==NULL)
{
indicator=new IndicatorDlg(this,Data.ShowUI?m_pDlg:m_pChildWnd);
}
showUI=Data.ShowUI;
}
return ret;
} }
@ -99,6 +116,7 @@ void MFC_UI::DestroyTWAINGUI()
delete m_pDlg; delete m_pDlg;
m_pDlg = NULL; m_pDlg = NULL;
} }
if (m_pChildWnd!=NULL) if (m_pChildWnd!=NULL)
{ {
m_pChildWnd->DestroyWindow(); m_pChildWnd->DestroyWindow();
@ -110,16 +128,29 @@ void MFC_UI::DestroyTWAINGUI()
void MFC_UI::UpdateProgress(bool bShow, unsigned char ucProgress, unsigned int unPageNo, string strProgressTitle) void MFC_UI::UpdateProgress(bool bShow, unsigned char ucProgress, unsigned int unPageNo, string strProgressTitle)
{ {
if (indicator==NULL) return; if (indicator==NULL)
{
indicator=new IndicatorDlg(this,NULL);
}
if (!indicatorCreated) if (!indicatorCreated)
{ {
//indicator->Create(IDD_DIALOG_INDICATOR,showUI?m_pDlg:m_pChildWnd); indicator->Create(IDD_DIALOG_INDICATOR,m_pChildWnd);//m_pChildWnd
indicator->Create(IDD_DIALOG_INDICATOR,m_pChildWnd);
indicatorCreated=true; indicatorCreated=true;
} }
indicator->ShowWindow(bShow?SW_SHOWNORMAL:SW_HIDE); if (bShow)
{
indicator->ShowWindow(SW_SHOWNORMAL);
}
else
{
indicator->DestroyWindow();
delete indicator;
indicator=NULL;
indicatorCreated=false;
}
//indicator->ShowWindow(bShow?SW_SHOWNORMAL:SW_HIDE);
if (m_pDlg) if (m_pDlg)
{ {
m_pDlg->EnableWindow(bShow?FALSE:TRUE); m_pDlg->EnableWindow(bShow?FALSE:TRUE);
@ -129,15 +160,21 @@ void MFC_UI::UpdateProgress(bool bShow, unsigned char ucProgress, unsigned int
unsigned int MFC_UI::MessageBox(string strMessage, string strTitle, unsigned int unIconID) unsigned int MFC_UI::MessageBox(string strMessage, string strTitle, unsigned int unIconID)
{ {
//QMessageBox msgBox(QMessageBox::NoIcon, strTitle.c_str(), strMessage.c_str()); //QMessageBox msgBox(QMessageBox::NoIcon, strTitle.c_str(), strMessage.c_str());
if (m_pChildWnd!=NULL)
{
return ::MessageBox(m_pChildWnd->m_hWnd, strMessage.c_str(), strTitle.c_str(), unIconID);
}
return ::MessageBox(NULL, strMessage.c_str(), strTitle.c_str(), unIconID); return ::MessageBox(NULL, strMessage.c_str(), strTitle.c_str(), unIconID);
} }
bool MFC_UI::processEvent(pTW_EVENT _pEvent) bool MFC_UI::processEvent(pTW_EVENT _pEvent)
{ {
if(m_pChildWnd) if(m_pDlg)
{ {
if (IsDialogMessage(m_pChildWnd->m_hWnd, (LPMSG)(((pTW_EVENT)_pEvent)->pEvent))) if (IsDialogMessage(m_pDlg->m_hWnd, (LPMSG)(((pTW_EVENT)_pEvent)->pEvent)))
{ {
m_pDlg->SendMessage(_pEvent->TWMessage);
//XdPrint("_pEvent->TWMessage %d\n",_pEvent->TWMessage);
return TRUE; return TRUE;
} }
} }

View File

@ -28,8 +28,6 @@ public:
unsigned int MessageBox(string strMessage, string strTitle, unsigned int unIconID); unsigned int MessageBox(string strMessage, string strTitle, unsigned int unIconID);
bool processEvent(pTW_EVENT _pEvent); bool processEvent(pTW_EVENT _pEvent);
public:
//CUI_INI *m_pCUI_INI;
private: private:
TwainUIDlg* m_pDlg; TwainUIDlg* m_pDlg;
CWnd* m_pChildWnd; CWnd* m_pChildWnd;
@ -37,6 +35,5 @@ private:
bool indicatorCreated; bool indicatorCreated;
bool showUI; bool showUI;
ChugaotwaindsApp* m_app; ChugaotwaindsApp* m_app;
}; };

View File

@ -330,7 +330,7 @@ BOOL MallocTwainFileListMem()
if ( g_st_twain_bmp_info.n_wifl_cur_count +3 > g_st_twain_bmp_info.n_wifl_count) if ( g_st_twain_bmp_info.n_wifl_cur_count +3 > g_st_twain_bmp_info.n_wifl_count)
{ {
if ( SHGetSpecialFolderPath(NULL, g_st_twain_bmp_info.sz_path_dir, CSIDL_COMMON_DOCUMENTS, TRUE) ) if ( SHGetSpecialFolderPath(NULL, g_st_twain_bmp_info.sz_path_dir, CSIDL_LOCAL_APPDATA, TRUE) )
{ {
INT len = _tcslen(g_st_twain_bmp_info.sz_path_dir); INT len = _tcslen(g_st_twain_bmp_info.sz_path_dir);
if ( len > 0 ) if ( len > 0 )

View File

@ -18,6 +18,7 @@ using namespace std;
#define RESOLUTION "iResolution" #define RESOLUTION "iResolution"
#define DUPLEX "iDuplex" #define DUPLEX "iDuplex"
#define DISCARBLANK "bDiscardBlank" #define DISCARBLANK "bDiscardBlank"
#define DISCARBLANKVINCE "bDiscardBlankVince"
#define FLOD "bFlod" #define FLOD "bFlod"
#define BRIGHTNESS "iBrightness" #define BRIGHTNESS "iBrightness"
#define AUTOCONTRAST "bAutoContrast" #define AUTOCONTRAST "bAutoContrast"
@ -35,26 +36,38 @@ using namespace std;
#define SCREWLEVEL "iScrewLevel" #define SCREWLEVEL "iScrewLevel"
#define ITEMCAPTION "Caption" #define ITEMCAPTION "Caption"
#define SAVEPATH "SavePath" #define SAVEPATH "SavePath"
#define OUTHOLE "bOutHole"
#define OUTHOLERATIO "iOutHoleRatio"
/****************** /******************
**²ÎÊý±£´æ½á¹¹Ìå** **²ÎÊý±£´æ½á¹¹Ìå**
*******************/ *******************/
struct tagCONFIGPARAMS struct tagCONFIGPARAMS
{ {
/*基本选项卡参数*/
INT Pixtype; INT Pixtype;
INT PaperSize; INT PaperSize;
BOOL EnAutoCrop; BOOL EnAutoCrop;
INT Resolution; INT Resolution;
INT Duplex; INT Duplex;
BOOL EnDiscardBlank; BOOL EnDiscardBlank;
BOOL EnDiscardBlankVince;
BOOL EnFlod; BOOL EnFlod;
/*亮度对比度选项卡参数*/
INT Brightness; INT Brightness;
BOOL EnAutoContrast; BOOL EnAutoContrast;
INT Contrast; INT Contrast;
INT Gamma; INT Gamma;
/*图像处理选项卡参数*/
INT Filter; INT Filter;
BOOL EnFillBlack; BOOL EnFillBlack;
BOOL EnAutoDescrew; BOOL EnAutoDescrew;
BOOL EnOutHole;
INT OutHoleRatio;
BOOL EnMultiOutPutR;
/*送纸部分选项卡参数*/
BOOL EnUltrasonicDetect; BOOL EnUltrasonicDetect;
BOOL EnBindingDetect; BOOL EnBindingDetect;
INT ScanCount; INT ScanCount;
@ -62,6 +75,8 @@ struct tagCONFIGPARAMS
BOOL EnBackRotate180; BOOL EnBackRotate180;
BOOL EnScrewDetect; BOOL EnScrewDetect;
INT ScrewDetectLevel; INT ScrewDetectLevel;
/*保存信息*/
std::string Caption; std::string Caption;
std::string SavePath; std::string SavePath;
}; };
@ -76,6 +91,14 @@ struct tagCONFIGINFO
typedef struct tagCONFIGINFO CONFIGINFO,*PCONFIGINFO; typedef struct tagCONFIGINFO CONFIGINFO,*PCONFIGINFO;
struct tagOutHole
{
BOOL EnOutHole;
INT OutHoleRatio;
};
typedef tagOutHole OutHole,*pOutHole;
#define CAPTION_LEN 256 #define CAPTION_LEN 256
#define TWAIN_IMAGE_FILE_LIST_NAME TEXT(".dat") #define TWAIN_IMAGE_FILE_LIST_NAME TEXT(".dat")

Binary file not shown.

View File

@ -63,7 +63,7 @@ void SaveConfigDlg::OnBnClickedOk()
); );
return; return;
} }
SHGetSpecialFolderPath(NULL, szIniFile, CSIDL_COMMON_DOCUMENTS, TRUE); SHGetSpecialFolderPath(NULL, szIniFile, CSIDL_LOCAL_APPDATA, TRUE);
_tcscat(szIniFile,HUAGAO_SCAN); _tcscat(szIniFile,HUAGAO_SCAN);
_tcscat(szIniFile, TWAIN_DATA_PATH); _tcscat(szIniFile, TWAIN_DATA_PATH);
citem.Caption=m_sName; citem.Caption=m_sName;

Binary file not shown.

View File

@ -2,12 +2,13 @@
#include "gscn_drv.h" #include "gscn_drv.h"
#include "stdio.h" #include "stdio.h"
#include "turbojpeg.h" #include "turbojpeg.h"
#include "PublicFunc.h"
#include <map> #include <map>
#include "twainEx.h" #include "twainEx.h"
#include "jpeglib.h" #include "jpeglib.h"
#include "ImageProcDiscardBlank.h" #include "ImageProcDiscardBlank.h"
#include "ImageApply.h" #include "ImageApply.h"
#include "hugaotwainds.h"
extern ChugaotwaindsApp theApp;
GScn_Drv::GScn_Drv() GScn_Drv::GScn_Drv()
: m_discard(new CImageProcDiscardBlank()),canUseDiscardBlank(false) : m_discard(new CImageProcDiscardBlank()),canUseDiscardBlank(false)
@ -17,6 +18,7 @@ GScn_Drv::GScn_Drv()
devState = DEV_STOP; devState = DEV_STOP;
isDuplex=TRUE; isDuplex=TRUE;
m_h_usb_thread=NULL; m_h_usb_thread=NULL;
InitMSGMap();
} }
GScn_Drv::~GScn_Drv() GScn_Drv::~GScn_Drv()
@ -28,6 +30,22 @@ GScn_Drv::~GScn_Drv()
//m_threadUsb.join(); //m_threadUsb.join();
} }
} }
void GScn_Drv::InitMSGMap()
{
if (ntcMsg.size()>0)
ntcMsg.clear();
ntcMsg[COUNT_MODE]="计数模式,请先退出计数模式!";
ntcMsg[NO_FEED]="无纸,请放置纸张!";
ntcMsg[OPEN_COVER]="扫描仪开盖!";
ntcMsg[FEED_IN_ERROR]="拾纸错误!";
ntcMsg[PAPER_JAM]="卡纸!";
ntcMsg[DETECT_DOUBLE_FEED]="双张!";
ntcMsg[DETECT_STAPLE]="订书针!";
ntcMsg[PAPER_SKEW]="纸张歪斜!";
ntcMsg[HARDWARE_ERROR]="硬件错误!";
ntcMsg[PC_SCAN_BUSY_or_ERROR]="PC错误";
}
void GScn_Drv::open(int vid, int pid) void GScn_Drv::open(int vid, int pid)
{ {
@ -35,7 +53,7 @@ void GScn_Drv::open(int vid, int pid)
if (devs._NumberOfDevs != 0) if (devs._NumberOfDevs != 0)
{ {
m_usb.open(devs.dev_infos[0].index); m_usb.open(devs.dev_infos[0].index);//同时存在多个同种扫描设备时默认选取第一个vid pid匹配的设备
} }
} }
@ -70,10 +88,24 @@ twainImage GScn_Drv::PopTwainImage()
int GScn_Drv::aquire_image(cv::Mat& image) int GScn_Drv::aquire_image(cv::Mat& image)
{ {
bool begin=false;
struct timeval start;
struct timeval end;
float time_used=0;
while (true) while (true)
{ {
if (Get_IsImageQueueEmpty()) if (Get_IsImageQueueEmpty())
{ {
if (!begin)
{
begin=true;
//DWORD s= timeGetTime();
//gettimeofday(&start,NULL);
}
//gettimeofday(&end,NULL);
//time_used=end.tv_sec-start.tv_sec;
//Sleep(100); //Sleep(100);
DoEvents(); DoEvents();
if (!is_scan()) if (!is_scan())
@ -119,7 +151,7 @@ cv::Mat GScn_Drv::Get_Img_Data(int bufferSize)
USBCB usbcb = { GET_IMAGE,0,bufferSize }; USBCB usbcb = { GET_IMAGE,0,bufferSize };
DWORD transfer; DWORD transfer;
m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer);
m_usb.Read_Data(iData.data, bufferSize, 600, &transfer); m_usb.Read_Data(iData.data, bufferSize, 1000, &transfer);
return iData; return iData;
} }
@ -174,6 +206,11 @@ void GScn_Drv::setlist(std::vector<std::shared_ptr<CImageApply> >list)
m_pImages.setlist(list); m_pImages.setlist(list);
} }
void GScn_Drv::SetOutHoleParam(OutHole outhole)
{
m_pImages.outHole=outhole;
}
DWORD GScn_Drv::usbmain() DWORD GScn_Drv::usbmain()
{ {
while (m_bRun) while (m_bRun)
@ -215,7 +252,6 @@ DWORD GScn_Drv::usbmain()
if (isDuplex) if (isDuplex)
{ {
pushMat(JpegBuffer(bufferF,pixType,1,0)); pushMat(JpegBuffer(bufferF,pixType,1,0));
//XdPrint("Enter Back\n");
} }
Pop_Image(); Pop_Image();
break; break;
@ -226,43 +262,16 @@ DWORD GScn_Drv::usbmain()
break; break;
} }
case COUNT_MODE: case COUNT_MODE:
MessageBox(NULL, "计数模式,请先退出计数模式!", "提示", MB_OK | MB_ICONERROR);
devState = DEV_WRONG;
break;
case NO_FEED: case NO_FEED:
MessageBox(NULL, "无纸,请放置纸张!", "提示", MB_OK | MB_ICONEXCLAMATION);
devState = DEV_WRONG;
break;
case OPEN_COVER: case OPEN_COVER:
MessageBox(NULL, "扫描仪开盖!", "警告", MB_OK | MB_ICONERROR);
devState = DEV_WRONG;
break;
case FEED_IN_ERROR: case FEED_IN_ERROR:
MessageBox(NULL, "拾纸错误!", "提示", MB_OK | MB_ICONERROR);
devState = DEV_WRONG;
break;
case PAPER_JAM: case PAPER_JAM:
MessageBox(NULL, "卡纸!", "提示", MB_OK | MB_ICONERROR);
devState = DEV_WRONG;
break;
case DETECT_DOUBLE_FEED: case DETECT_DOUBLE_FEED:
MessageBox(NULL, "双张!", "提示", MB_OK | MB_ICONERROR);
devState = DEV_WRONG;
break;
case DETECT_STAPLE: case DETECT_STAPLE:
MessageBox(NULL, "订书针!", "提示", MB_OK | MB_ICONERROR);
devState = DEV_WRONG;
break;
case PAPER_SKEW: case PAPER_SKEW:
MessageBox(NULL, "纸张歪斜!", "提示", MB_OK | MB_ICONERROR);
devState = DEV_WRONG;
break;
case HARDWARE_ERROR: case HARDWARE_ERROR:
MessageBox(NULL, "硬件错误!", "提示", MB_OK | MB_ICONERROR);
devState = DEV_WRONG;
break;
case PC_SCAN_BUSY_or_ERROR: case PC_SCAN_BUSY_or_ERROR:
MessageBox(NULL, "PC错误", "提示", MB_OK | MB_ICONERROR); MessageBox(theApp.m_pMainWnd->GetSafeHwnd(), ntcMsg[usbcb.u32_Data].c_str(), "提示", MB_OK | MB_ICONERROR);
devState = DEV_WRONG; devState = DEV_WRONG;
break; break;
case NORMAL: case NORMAL:
@ -270,7 +279,7 @@ DWORD GScn_Drv::usbmain()
default: default:
break; break;
} }
Sleep(5); Sleep(50);
} }
m_h_usb_thread = NULL; m_h_usb_thread = NULL;
return 0; return 0;
@ -313,7 +322,7 @@ std::string GScn_Drv::GetFWVersion()
USBCB usbcb = { GET_FW_VERSION,8,0 }; USBCB usbcb = { GET_FW_VERSION,8,0 };
DWORD transfer; DWORD transfer;
m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer);
m_usb.Read_Data(&pFWVersion[0], 8, 100, &transfer); m_usb.Read_Data(&pFWVersion[0], 8, 200, &transfer);
return pFWVersion; return pFWVersion;
} }
return ""; return "";
@ -329,7 +338,7 @@ std::string GScn_Drv::GetSerialNum()
USBCB usbcb = { GET_SERIAL,12,0 }; USBCB usbcb = { GET_SERIAL,12,0 };
DWORD transfer; DWORD transfer;
m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer);
m_usb.Read_Data(&pserialNum[0], 12, 100, &transfer); m_usb.Read_Data(&pserialNum[0], 12, 200, &transfer);
return pserialNum; return pserialNum;
} }
return ""; return "";
@ -348,7 +357,7 @@ USBCB GScn_Drv::Get_Scanner_Status()
USBCB usbcb = { GET_DSP_STATUS ,0,0 }; USBCB usbcb = { GET_DSP_STATUS ,0,0 };
DWORD transfer; DWORD transfer;
m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer);
m_usb.Read_Data(&usbcb, sizeof(usbcb), 100, &transfer); m_usb.Read_Data(&usbcb, sizeof(usbcb), 200, &transfer);
return usbcb; return usbcb;
} }
@ -400,6 +409,17 @@ void GScn_Drv::Stop_scan()
m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer); m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer);
} }
void GScn_Drv::ResetScanner()
{
if (!m_usb.is_connected())
return;
boost::lock_guard<boost::mutex> lck(m_imgLocker);
USBCB usbcb = { INIT_HARDWARE_SYS ,0,0 };
DWORD transfer;
m_usb.bulk_out(0x00, &usbcb, sizeof(usbcb), &transfer);
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
bool GScn_Drv::Get_IsImageQueueEmpty() bool GScn_Drv::Get_IsImageQueueEmpty()
{ {

View File

@ -13,6 +13,8 @@
#include <boost\thread\mutex.hpp> #include <boost\thread\mutex.hpp>
#include <boost\thread.hpp> #include <boost\thread.hpp>
#include "ImageMatQueue.h" #include "ImageMatQueue.h"
#include <map>
#include "PublicFunc.h"
using namespace cv; using namespace cv;
typedef struct tag_USBCB { typedef struct tag_USBCB {
@ -219,6 +221,7 @@ public:
void Config_Scanner(PUSBCB pUSBCB); void Config_Scanner(PUSBCB pUSBCB);
void Scanner_StartScan(UINT16 count); void Scanner_StartScan(UINT16 count);
void Stop_scan(); void Stop_scan();
void ResetScanner();
bool Get_IsImageQueueEmpty(); bool Get_IsImageQueueEmpty();
void reset(); void reset();
void run(); void run();
@ -235,11 +238,13 @@ public:
void setlist(std::vector<std::shared_ptr<CImageApply> >list); void setlist(std::vector<std::shared_ptr<CImageApply> >list);
void SetOutHoleParam(OutHole outhole);
private: private:
cv::Mat popMat(); cv::Mat popMat();
twainImage PopTwainImage(); twainImage PopTwainImage();
void pushMat(JpegBuffer& data); void pushMat(JpegBuffer& data);
void InitMSGMap();
cv::Mat Get_Img_Data(int buffersize); cv::Mat Get_Img_Data(int buffersize);
TCHAR *m_sMutexName; TCHAR *m_sMutexName;
DWORD usbmain(); DWORD usbmain();
@ -263,4 +268,5 @@ private:
BOOL canUseDiscardBlank; BOOL canUseDiscardBlank;
boost::thread m_threadUsb; boost::thread m_threadUsb;
std::vector<std::shared_ptr<CImageApply>> m_iaList; std::vector<std::shared_ptr<CImageApply>> m_iaList;
std::map<int,string> ntcMsg;
}; };

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -234,6 +234,7 @@ opencv_imgproc2410.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ClCompile Include="ImageBWBinaray.cpp" /> <ClCompile Include="ImageBWBinaray.cpp" />
<ClCompile Include="ImageChannel.cpp" /> <ClCompile Include="ImageChannel.cpp" />
<ClCompile Include="ImageMatQueue.cpp" /> <ClCompile Include="ImageMatQueue.cpp" />
<ClCompile Include="ImageOutHole.cpp" />
<ClCompile Include="ImageProcDiscardBlank.cpp" /> <ClCompile Include="ImageProcDiscardBlank.cpp" />
<ClCompile Include="ImageProcess.cpp" /> <ClCompile Include="ImageProcess.cpp" />
<ClCompile Include="ImageRotation.cpp" /> <ClCompile Include="ImageRotation.cpp" />
@ -285,6 +286,7 @@ opencv_imgproc2410.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ClInclude Include="CTwainMutex.h" /> <ClInclude Include="CTwainMutex.h" />
<ClInclude Include="DSMInterface.h" /> <ClInclude Include="DSMInterface.h" />
<ClInclude Include="FeederPaper.h" /> <ClInclude Include="FeederPaper.h" />
<ClInclude Include="filetools.h" />
<ClInclude Include="gscn_drv.h" /> <ClInclude Include="gscn_drv.h" />
<ClInclude Include="hugaotwainds.h" /> <ClInclude Include="hugaotwainds.h" />
<ClInclude Include="ImageAdjustColors.h" /> <ClInclude Include="ImageAdjustColors.h" />
@ -294,6 +296,7 @@ opencv_imgproc2410.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ClInclude Include="ImageBWBinaray.h" /> <ClInclude Include="ImageBWBinaray.h" />
<ClInclude Include="ImageChannel.h" /> <ClInclude Include="ImageChannel.h" />
<ClInclude Include="ImageMatQueue.h" /> <ClInclude Include="ImageMatQueue.h" />
<ClInclude Include="ImageOutHole.h" />
<ClInclude Include="ImageProcDiscardBlank.h" /> <ClInclude Include="ImageProcDiscardBlank.h" />
<ClInclude Include="ImageProcess.h" /> <ClInclude Include="ImageProcess.h" />
<ClInclude Include="ImageRotation.h" /> <ClInclude Include="ImageRotation.h" />

View File

@ -168,6 +168,9 @@
<ClCompile Include="jpeglib.cpp"> <ClCompile Include="jpeglib.cpp">
<Filter>USB通信</Filter> <Filter>USB通信</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="ImageOutHole.cpp">
<Filter>图像处理</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="hugaotwainds.def"> <None Include="hugaotwainds.def">
@ -340,6 +343,12 @@
<ClInclude Include="jpeglib.h"> <ClInclude Include="jpeglib.h">
<Filter>USB通信</Filter> <Filter>USB通信</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="filetools.h">
<Filter>公共库</Filter>
</ClInclude>
<ClInclude Include="ImageOutHole.h">
<Filter>图像处理</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="hugaotwainds.rc"> <ResourceCompile Include="hugaotwainds.rc">

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommand>C:\Program Files (x86)\TWAIN Working Group\TWAIN 2.3 App Sample\TWAIN_App_mfc32.exe</LocalDebuggerCommand> <LocalDebuggerCommand>C:\Program Files (x86)\TWAIN Working Group\Twacker 32\Twack_32.exe</LocalDebuggerCommand>
<LocalDebuggerWorkingDirectory>C:\Windows\twain_32\huagoscan</LocalDebuggerWorkingDirectory> <LocalDebuggerWorkingDirectory>C:\Windows\twain_32\huagoscan</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup> </PropertyGroup>
@ -12,7 +12,7 @@
<DebuggerFlavor Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">WindowsLocalDebugger</DebuggerFlavor> <DebuggerFlavor Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommand>C:\Users\pm\Desktop\第二次发送(现场应用)\Debug1\Debug\FClassroom.exe</LocalDebuggerCommand> <LocalDebuggerCommand>C:\Program Files (x86)\TWAIN Working Group\TWAIN 2.3 App Sample\TWAIN_App_mfc32.exe</LocalDebuggerCommand>
<LocalDebuggerWorkingDirectory>..\..\..\..\..\..\..\Windows\twain_32\huagoscan</LocalDebuggerWorkingDirectory> <LocalDebuggerWorkingDirectory>..\..\..\..\..\..\..\Windows\twain_32\huagoscan</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup> </PropertyGroup>

Binary file not shown.

Binary file not shown.

Binary file not shown.