XP版本发布版本最新代码(v2.0.0.0)
This commit is contained in:
parent
72cba36185
commit
65069c9289
|
@ -1,54 +0,0 @@
|
|||
// AboutHuaGoDlg.cpp : 实现文件
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "hugaotwainds.h"
|
||||
#include "AboutHuaGoDlg.h"
|
||||
#include "afxdialogex.h"
|
||||
|
||||
|
||||
// AboutHuaGoDlg 对话框
|
||||
|
||||
IMPLEMENT_DYNAMIC(AboutHuaGoDlg, CDialog)
|
||||
|
||||
AboutHuaGoDlg::AboutHuaGoDlg(std::string scnrname,std::string serialNum,std::string hardVersion,CWnd* pParent /*=NULL*/)
|
||||
: CDialog(IDD_DIALOGABOUT, pParent)
|
||||
{
|
||||
this->scanHardVersion=hardVersion;
|
||||
this->scanName=scnrname;
|
||||
this->scanSerialNum=serialNum;
|
||||
}
|
||||
|
||||
AboutHuaGoDlg::~AboutHuaGoDlg()
|
||||
{
|
||||
}
|
||||
|
||||
void AboutHuaGoDlg::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
//DDX_Control(pDX,IDC_PICABOUTHUAGO,m_pic);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(AboutHuaGoDlg, CDialog)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
// AboutHuaGoDlg 消息处理程序
|
||||
|
||||
|
||||
BOOL AboutHuaGoDlg::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
// TODO: 在此添加额外的初始化
|
||||
UpdateScannerInfo();
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// 异常: OCX 属性页应返回 FALSE
|
||||
}
|
||||
|
||||
void AboutHuaGoDlg::UpdateScannerInfo()
|
||||
{
|
||||
((CStatic*)GetDlgItem(IDC_LBSCANNERNAMEVALUE))->SetWindowText(scanName.c_str());
|
||||
((CStatic*)GetDlgItem(IDC_LBSERIALNUMVALUE))->SetWindowText(scanSerialNum.c_str());
|
||||
((CStatic*)GetDlgItem(IDC_LBHARDWAREVALUE))->SetWindowText(scanHardVersion.c_str());
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
#pragma once
|
||||
#include "resource.h"
|
||||
#include <string>
|
||||
using namespace std;
|
||||
// AboutHuaGoDlg 对话框
|
||||
|
||||
class AboutHuaGoDlg : public CDialog
|
||||
{
|
||||
DECLARE_DYNAMIC(AboutHuaGoDlg)
|
||||
|
||||
public:
|
||||
AboutHuaGoDlg(std::string scnrname="",std::string serialNum="",std::string hardVersion="", CWnd* pParent = NULL); // 标准构造函数
|
||||
virtual ~AboutHuaGoDlg();
|
||||
|
||||
// 对话框数据
|
||||
#ifdef AFX_DESIGN_TIME
|
||||
enum { IDD = IDD_DIALOGABOUT };
|
||||
#endif
|
||||
protected:
|
||||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
public:
|
||||
virtual BOOL OnInitDialog();
|
||||
private:
|
||||
void UpdateScannerInfo();
|
||||
std::string scanName;
|
||||
std::string scanSerialNum;
|
||||
std::string scanHardVersion;
|
||||
};
|
BIN
BasicSetting.cpp
BIN
BasicSetting.cpp
Binary file not shown.
BIN
BasicSetting.h
BIN
BasicSetting.h
Binary file not shown.
|
@ -1,89 +0,0 @@
|
|||
#pragma once
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
|
||||
|
||||
template <typename T>
|
||||
class BlockingQueue
|
||||
{
|
||||
private:
|
||||
BlockingQueue(const BlockingQueue& rhs);
|
||||
BlockingQueue& operator =(const BlockingQueue& rhs);
|
||||
mutable std::mutex _mutex;
|
||||
std::condition_variable _condvar;
|
||||
std::deque<T> _queue;
|
||||
volatile bool isShutDown = false;
|
||||
T tRet;
|
||||
|
||||
public:
|
||||
BlockingQueue()
|
||||
: _mutex()
|
||||
, _condvar()
|
||||
, _queue()
|
||||
{
|
||||
}
|
||||
|
||||
~BlockingQueue()
|
||||
{
|
||||
ShutDown();
|
||||
std::cout << "blocking queue release" << std::endl;
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
_condvar.notify_all();
|
||||
_queue.clear();
|
||||
}
|
||||
|
||||
void ShutDown()
|
||||
{
|
||||
isShutDown = true;
|
||||
_condvar.notify_all();
|
||||
_queue.clear();
|
||||
}
|
||||
|
||||
bool IsShutDown()
|
||||
{
|
||||
return isShutDown;
|
||||
}
|
||||
|
||||
void Put(const T task)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
if (!isShutDown)
|
||||
{
|
||||
{
|
||||
_queue.push_back(task);
|
||||
}
|
||||
_condvar.notify_all();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
T Take()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_mutex);
|
||||
if (_queue.size() <= 0)
|
||||
_condvar.wait(lock);
|
||||
|
||||
if (isShutDown || _queue.empty())
|
||||
{
|
||||
return tRet;
|
||||
}
|
||||
|
||||
T front(_queue.front());
|
||||
_queue.pop_front();
|
||||
|
||||
return front;
|
||||
}
|
||||
|
||||
size_t Size() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
return _queue.size();
|
||||
}
|
||||
};
|
Binary file not shown.
BIN
BrightSetting.h
BIN
BrightSetting.h
Binary file not shown.
2914
CJsonObject.cpp
2914
CJsonObject.cpp
File diff suppressed because it is too large
Load Diff
153
CJsonObject.hpp
153
CJsonObject.hpp
|
@ -1,153 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Project: neb
|
||||
* @file CJsonObject.hpp
|
||||
* @brief Json
|
||||
* @author bwarliao
|
||||
* @date: 2014-7-16
|
||||
* @note
|
||||
* Modify history:
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef CJSONOBJECT_HPP_
|
||||
#define CJSONOBJECT_HPP_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <malloc.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
typedef struct cJSON cJSON;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
namespace neb
|
||||
{
|
||||
typedef int int32;
|
||||
typedef unsigned int uint32;
|
||||
typedef long long int64;
|
||||
typedef unsigned long long uint64;
|
||||
|
||||
class CJsonObject
|
||||
{
|
||||
public: // method of ordinary json object or json array
|
||||
CJsonObject();
|
||||
CJsonObject(const std::string& strJson);
|
||||
CJsonObject(const CJsonObject* pJsonObject);
|
||||
CJsonObject(const CJsonObject& oJsonObject);
|
||||
virtual ~CJsonObject();
|
||||
|
||||
CJsonObject& operator=(const CJsonObject& oJsonObject);
|
||||
bool operator==(const CJsonObject& oJsonObject) const;
|
||||
bool Parse(const std::string& strJson);
|
||||
void Clear();
|
||||
bool IsEmpty() const;
|
||||
bool IsArray() const;
|
||||
std::string ToString() const;
|
||||
std::string ToFormattedString() const;
|
||||
const std::string& GetErrMsg() const
|
||||
{
|
||||
return(m_strErrMsg);
|
||||
}
|
||||
|
||||
public: // method of ordinary json object
|
||||
bool AddEmptySubObject(const std::string& strKey);
|
||||
bool AddEmptySubArray(const std::string& strKey);
|
||||
CJsonObject& operator[](const std::string& strKey);
|
||||
std::string operator()(const std::string& strKey) const;
|
||||
bool Get(const std::string& strKey, CJsonObject& oJsonObject) const;
|
||||
bool Get(const std::string& strKey, std::string& strValue) const;
|
||||
bool Get(const std::string& strKey, int32& iValue) const;
|
||||
bool Get(const std::string& strKey, uint32& uiValue) const;
|
||||
bool Get(const std::string& strKey, int64& llValue) const;
|
||||
bool Get(const std::string& strKey, uint64& ullValue) const;
|
||||
bool Get(const std::string& strKey, bool& bValue) const;
|
||||
bool Get(const std::string& strKey, float& fValue) const;
|
||||
bool Get(const std::string& strKey, double& dValue) const;
|
||||
bool Add(const std::string& strKey, const CJsonObject& oJsonObject);
|
||||
bool Add(const std::string& strKey, const std::string& strValue);
|
||||
bool Add(const std::string& strKey, int32 iValue);
|
||||
bool Add(const std::string& strKey, uint32 uiValue);
|
||||
bool Add(const std::string& strKey, int64 llValue);
|
||||
bool Add(const std::string& strKey, uint64 ullValue);
|
||||
bool Add(const std::string& strKey, bool bValue, bool bValueAgain);
|
||||
bool Add(const std::string& strKey, float fValue);
|
||||
bool Add(const std::string& strKey, double dValue);
|
||||
bool Delete(const std::string& strKey);
|
||||
bool Replace(const std::string& strKey, const CJsonObject& oJsonObject);
|
||||
bool Replace(const std::string& strKey, const std::string& strValue);
|
||||
bool Replace(const std::string& strKey, int32 iValue);
|
||||
bool Replace(const std::string& strKey, uint32 uiValue);
|
||||
bool Replace(const std::string& strKey, int64 llValue);
|
||||
bool Replace(const std::string& strKey, uint64 ullValue);
|
||||
bool Replace(const std::string& strKey, bool bValue, bool bValueAgain);
|
||||
bool Replace(const std::string& strKey, float fValue);
|
||||
bool Replace(const std::string& strKey, double dValue);
|
||||
|
||||
public: // method of json array
|
||||
int GetArraySize();
|
||||
CJsonObject& operator[](unsigned int uiWhich);
|
||||
std::string operator()(unsigned int uiWhich) const;
|
||||
bool Get(int iWhich, CJsonObject& oJsonObject) const;
|
||||
bool Get(int iWhich, std::string& strValue) const;
|
||||
bool Get(int iWhich, int32& iValue) const;
|
||||
bool Get(int iWhich, uint32& uiValue) const;
|
||||
bool Get(int iWhich, int64& llValue) const;
|
||||
bool Get(int iWhich, uint64& ullValue) const;
|
||||
bool Get(int iWhich, bool& bValue) const;
|
||||
bool Get(int iWhich, float& fValue) const;
|
||||
bool Get(int iWhich, double& dValue) const;
|
||||
bool Add(const CJsonObject& oJsonObject);
|
||||
bool Add(const std::string& strValue);
|
||||
bool Add(int32 iValue);
|
||||
bool Add(uint32 uiValue);
|
||||
bool Add(int64 llValue);
|
||||
bool Add(uint64 ullValue);
|
||||
bool Add(int iAnywhere, bool bValue);
|
||||
bool Add(float fValue);
|
||||
bool Add(double dValue);
|
||||
bool AddAsFirst(const CJsonObject& oJsonObject);
|
||||
bool AddAsFirst(const std::string& strValue);
|
||||
bool AddAsFirst(int32 iValue);
|
||||
bool AddAsFirst(uint32 uiValue);
|
||||
bool AddAsFirst(int64 llValue);
|
||||
bool AddAsFirst(uint64 ullValue);
|
||||
bool AddAsFirst(int iAnywhere, bool bValue);
|
||||
bool AddAsFirst(float fValue);
|
||||
bool AddAsFirst(double dValue);
|
||||
bool Delete(int iWhich);
|
||||
bool Replace(int iWhich, const CJsonObject& oJsonObject);
|
||||
bool Replace(int iWhich, const std::string& strValue);
|
||||
bool Replace(int iWhich, int32 iValue);
|
||||
bool Replace(int iWhich, uint32 uiValue);
|
||||
bool Replace(int iWhich, int64 llValue);
|
||||
bool Replace(int iWhich, uint64 ullValue);
|
||||
bool Replace(int iWhich, bool bValue, bool bValueAgain);
|
||||
bool Replace(int iWhich, float fValue);
|
||||
bool Replace(int iWhich, double dValue);
|
||||
|
||||
private:
|
||||
CJsonObject(cJSON* pJsonData);
|
||||
|
||||
private:
|
||||
cJSON* m_pJsonData;
|
||||
cJSON* m_pExternJsonDataRef;
|
||||
std::string m_strErrMsg;
|
||||
std::map<unsigned int, CJsonObject*> m_mapJsonArrayRef;
|
||||
std::map<std::string, CJsonObject*> m_mapJsonObjectRef;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* CJSONHELPER_HPP_ */
|
|
@ -1,408 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright <EFBFBD> 2007 TWAIN Working Group:
|
||||
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
|
||||
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
|
||||
* Ricoh Corporation, and Xerox Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the TWAIN Working Group nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @file CScanner_FreeImage.cpp
|
||||
* Defines a scanner.
|
||||
* Create a virtual scanner.
|
||||
* @author TWAIN Working Group
|
||||
* @date April 2007
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "CScanner_FreeImage.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include "scn_config.h"
|
||||
#include "PublicFunc.h"
|
||||
#include "ImageProcess/ImageApplyHeaders.h"
|
||||
#include "filetools.h"
|
||||
#include "hugaotwainds.h"
|
||||
#include "GScanO200.h"
|
||||
#include "GScan200.h"
|
||||
|
||||
extern ChugaotwaindsApp theApp;
|
||||
#ifdef TWH_CMP_MSC
|
||||
#include <io.h>
|
||||
#elif __APPLE__
|
||||
//#include <io.h>
|
||||
#else //#ifdef TWH_CMP_MSC
|
||||
#include <sys/io.h>
|
||||
#endif //#ifdef TWH_CMP_MSC
|
||||
|
||||
#ifdef TWNDS_OS_LINUX
|
||||
#define kTWAIN_DS_DIR "/usr/local/lib/twain/sample2"
|
||||
#endif
|
||||
|
||||
#include "DSMInterface.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef TWNDS_OS_APPLE
|
||||
#include "CoreFoundation/CoreFoundation.h"
|
||||
#include "CoreFoundation/CFBundle.h"
|
||||
#include "CoreFoundation/CFURL.h"
|
||||
#include <Carbon/Carbon.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Environment vars to get the Xfer Count. Create this enviroment Varable on your system to simulate the
|
||||
* number of pages sitting in the scanner waiting to be scanned.
|
||||
*/
|
||||
#define kGETENV_XFERCOUNT "CAP_XFERCOUNT"
|
||||
|
||||
#ifdef TWH_CMP_MSC
|
||||
extern HINSTANCE g_hinstance;
|
||||
#endif
|
||||
|
||||
//GScn_Drv g_drv;
|
||||
std::shared_ptr<IGScan> g_scan(new GScan200());
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
CScanner_FreeImage::CScanner_FreeImage() :
|
||||
m_nScanLine(0),
|
||||
m_bReadOnly(false),
|
||||
m_nDestBytesPerRow(0),
|
||||
m_nRowOffset(0),
|
||||
m_nSourceWidth(0),
|
||||
m_nSourceHeight(0)
|
||||
{
|
||||
memset(m_szSourceImagePath, 0, PATH_MAX);
|
||||
resetScanner();
|
||||
InitMSGMap();
|
||||
g_scan->open(0x064B, 0x7823);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
CScanner_FreeImage::~CScanner_FreeImage()
|
||||
{
|
||||
g_scan.reset();
|
||||
}
|
||||
|
||||
void CScanner_FreeImage::InitMSGMap()
|
||||
{
|
||||
if (ntcMsg.size() > 0) {
|
||||
ntcMsg.clear();
|
||||
}
|
||||
ntcMsg[COUNT_MODE] = StringToUtf("计数模式,请先退出计数模式!");
|
||||
ntcMsg[NO_FEED] = StringToUtf("无纸,请放置纸张!");
|
||||
ntcMsg[OPEN_COVER] = StringToUtf("扫描仪开盖!");
|
||||
ntcMsg[FEED_IN_ERROR] = StringToUtf("拾纸错误!");
|
||||
ntcMsg[PAPER_JAM] = StringToUtf("卡纸!");
|
||||
ntcMsg[DETECT_DOUBLE_FEED] = StringToUtf("双张!");
|
||||
ntcMsg[DETECT_STAPLE] = StringToUtf("订书针!");
|
||||
ntcMsg[PAPER_SKEW] = StringToUtf("纸张歪斜!");
|
||||
ntcMsg[HARDWARE_ERROR] = StringToUtf("硬件异常!请重启扫描仪!");
|
||||
ntcMsg[PC_SCAN_BUSY_or_ERROR] = StringToUtf("PC错误!");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool CScanner_FreeImage::resetScanner()
|
||||
{
|
||||
bool bret = true;
|
||||
|
||||
// Unlock the scanner
|
||||
Unlock();
|
||||
|
||||
m_nScanLine = 0;
|
||||
m_nDestBytesPerRow = 0;
|
||||
m_nRowOffset = 0;
|
||||
|
||||
//m_nDocCount = //getDocumentCount();// Reloaded the scanner with paper
|
||||
m_nMaxDocCount = -1;
|
||||
m_nPixelType = TWPT_RGB;
|
||||
m_nPaperSource = SFI_PAPERSOURCE_ADF;
|
||||
m_bDuplex = false;
|
||||
m_fXResolution = 200.0;
|
||||
m_fYResolution = 200.0;
|
||||
|
||||
if (g_scan->Get_IsImageQueueEmpty() != 0)
|
||||
{
|
||||
g_scan->reset();
|
||||
}
|
||||
return bret;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
SFreeImage* CScanner_FreeImage::getSetting() const
|
||||
{
|
||||
return (SFreeImage*)this;
|
||||
}
|
||||
//static bool isreported;
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool CScanner_FreeImage::acquireImage(bool bscan)
|
||||
{
|
||||
if (bscan)
|
||||
{
|
||||
if (getDeviceOnline())
|
||||
{
|
||||
g_scan->config_params(*(getSetting()));
|
||||
g_scan->setdecodepixtype(m_HardWareParams.PixType);
|
||||
g_scan->Scanner_StartScan(m_wScanCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string cvt = StringToUtf("请检查电源是否打开或USB线缆是否已连接!");
|
||||
std::string notify = StringToUtf("提示");
|
||||
MessageBox(theApp.m_pMainWnd->GetSafeHwnd(), (TCHAR*)cvt.c_str(), (TCHAR*)notify.c_str(), MB_SYSTEMMODAL | MB_OK | MB_ICONINFORMATION);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HW_VER
|
||||
m_matDib.release();
|
||||
UINT32 ret = g_scan->aquire_image(m_matDib);
|
||||
if (ret != 0)
|
||||
{
|
||||
std::string notify = StringToUtf("提示");
|
||||
MessageBox(theApp.m_pMainWnd->GetSafeHwnd(), (TCHAR*)ntcMsg[ret].c_str(), (TCHAR*)notify.c_str(), MB_SYSTEMMODAL | MB_ICONINFORMATION | MB_OK);
|
||||
g_scan->Set_ErrorCode(0);//复位异常码
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (m_matDib.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (m_bMultiOutput)
|
||||
{
|
||||
if (m_matDib.channels() == 3)
|
||||
{
|
||||
m_nPixelType = TWPT_RGB;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_nPixelType = TWPT_GRAY;
|
||||
}
|
||||
}
|
||||
//Document scanned, remove it from simulated intray
|
||||
//m_nDocCount--;
|
||||
|
||||
// do whatever tranforms to the scanned image that was requested by the app
|
||||
// before the image is sent to the app.
|
||||
if (false == preScanPrep())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool CScanner_FreeImage::preScanPrep()
|
||||
{
|
||||
m_nRight = m_nSourceWidth = m_matDib.cols;
|
||||
m_nBottom = m_nSourceHeight = m_matDib.rows;
|
||||
m_nLeft = 0;
|
||||
m_nTop = 0;
|
||||
|
||||
switch (m_nPixelType)
|
||||
{
|
||||
case TWPT_BW:
|
||||
m_nDestBytesPerRow = BYTES_PERLINE(m_nSourceWidth, 1);
|
||||
m_nRowOffset = BYTES_PERLINE(0, 1);
|
||||
m_imageTrans.reset(new ImageTranferBW(m_matDib));
|
||||
break;
|
||||
|
||||
case TWPT_GRAY:
|
||||
m_nDestBytesPerRow = BYTES_PERLINE(m_nSourceWidth, 8);
|
||||
m_nRowOffset = BYTES_PERLINE(0, 8);
|
||||
m_imageTrans.reset(new ImageTranferMat(m_matDib));
|
||||
break;
|
||||
|
||||
case TWPT_RGB:
|
||||
m_nDestBytesPerRow = BYTES_PERLINE(m_nSourceWidth, 24);
|
||||
m_nRowOffset = BYTES_PERLINE(0, 24);
|
||||
m_imageTrans.reset(new ImageTranferMat(m_matDib));
|
||||
break;
|
||||
}
|
||||
|
||||
// setup some convenience vars because they are used during
|
||||
// every strip request
|
||||
m_nScanLine = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// We want to simulate getting a scan form a scanner.
|
||||
// if a size larger than the paper is scanned then there will be black on the bottom
|
||||
// and to the right of the image. We want to transfer the image top to bottom,
|
||||
// the black will be transfered after the image if neccessary.
|
||||
bool CScanner_FreeImage::getScanStrip(BYTE *pTransferBuffer, DWORD dwRead, DWORD &dwReceived)
|
||||
{
|
||||
dwReceived = 0;
|
||||
|
||||
if (NULL == pTransferBuffer || // Invalid paramiter
|
||||
dwRead < m_nDestBytesPerRow) // Need enough memory to transfer at least an entire row
|
||||
{
|
||||
return false;
|
||||
}
|
||||
BYTE *pBits = NULL;
|
||||
int nRow = 0;
|
||||
int nMaxRows = dwRead / m_nDestBytesPerRow; //number of rows to be transfered during this call (function of buffer size and line size)
|
||||
DWORD step = (DWORD)m_imageTrans->step();
|
||||
|
||||
m_nScanLine = 0;
|
||||
if (m_nScanLine < m_nSourceHeight)
|
||||
{
|
||||
//fill the buffer line by line to take care of alignment differences
|
||||
for (nRow = 0; nRow < nMaxRows; nRow++)
|
||||
{
|
||||
//get the next scan line position and copy it
|
||||
pBits = m_imageTrans->getLineBits(m_nScanLine);
|
||||
|
||||
memcpy(pTransferBuffer, pBits + m_nRowOffset, MIN(m_nDestBytesPerRow, step));
|
||||
|
||||
// Check to see if the result image width is wider than what we have.
|
||||
// If it is wider fill it in with 0es
|
||||
if (m_nDestBytesPerRow > step)
|
||||
{
|
||||
memset(pTransferBuffer + step, 0, m_nDestBytesPerRow - step);
|
||||
}
|
||||
|
||||
//increment the destination by the aligned line size
|
||||
pTransferBuffer += m_nDestBytesPerRow;
|
||||
|
||||
// increment the current scanline for next pass
|
||||
m_nScanLine++;
|
||||
|
||||
//update the number of bytes written
|
||||
dwReceived += m_nDestBytesPerRow;
|
||||
|
||||
// check for finished scan
|
||||
if (m_nScanLine >= m_nSourceHeight)
|
||||
{
|
||||
//we are done early
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
short CScanner_FreeImage::getDocumentCount() const
|
||||
{
|
||||
// Simulate the number of pages sitting in the scanner.
|
||||
int nCount = 1;
|
||||
|
||||
// Read this value from the environment. This will allow the simulation
|
||||
// of a sheet feeder.
|
||||
// If the value is <= 0, then a random number of pages will be scanned, else
|
||||
// the exact number will be used.
|
||||
char szCount[10];
|
||||
memset(szCount, 0, sizeof(szCount));
|
||||
|
||||
if (0 != SGETENV(szCount, sizeof(szCount), kGETENV_XFERCOUNT))
|
||||
{
|
||||
// something found, convert it to an int
|
||||
nCount = atoi(szCount);
|
||||
|
||||
if (nCount <= 0)
|
||||
{
|
||||
srand(int(time(0)));
|
||||
nCount = rand();
|
||||
nCount = nCount % 15;// upto 15 pages
|
||||
}
|
||||
}
|
||||
return nCount;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool CScanner_FreeImage::isFeederLoaded() const
|
||||
{
|
||||
bool rtn = g_scan->Get_Scanner_PaperOn();
|
||||
return rtn;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool CScanner_FreeImage::getDeviceOnline() const
|
||||
{
|
||||
return g_scan->IsConnected();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
std::string CScanner_FreeImage::getSerialNum() const
|
||||
{
|
||||
return g_scan->GetSerialNum();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
std::string CScanner_FreeImage::getFWVersion() const
|
||||
{
|
||||
return g_scan->GetFWVersion();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
bool CScanner_FreeImage::StopScan()
|
||||
{
|
||||
bool ret = true;
|
||||
g_scan->Stop_scan();
|
||||
int retry_times = 0;
|
||||
while (g_scan->is_scan())
|
||||
{
|
||||
if (retry_times > 10)//超过500ms还没停止则跳出 不进行DoCloseDSRequestEvent()
|
||||
{
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
Sleep(50);
|
||||
retry_times++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool CScanner_FreeImage::isPaperOn() //const
|
||||
{
|
||||
return g_scan->Get_Scanner_PaperOn();
|
||||
}
|
||||
|
||||
bool CScanner_FreeImage::isImageQueueEmpty()
|
||||
{
|
||||
bool ret;
|
||||
if (!g_scan->is_scan() && g_scan->Get_IsImageQueueEmpty() && (g_scan->get_ErrorCode() == 0))
|
||||
ret = true;
|
||||
else
|
||||
ret = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool CScanner_FreeImage::stillhaveImage()
|
||||
{
|
||||
return g_scan->Get_IsImageQueueEmpty();
|
||||
}
|
||||
|
|
@ -1,253 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright ?2007 TWAIN Working Group:
|
||||
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
|
||||
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
|
||||
* Ricoh Corporation, and Xerox Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the TWAIN Working Group nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @file CScanner_FreeImage.h
|
||||
* Defines a scanner.
|
||||
* Create a virtual scanner.
|
||||
* @author TWAIN Working Group
|
||||
* @date April 2007
|
||||
*/
|
||||
#ifndef __CSCANNER_H__
|
||||
#define __CSCANNER_H__
|
||||
|
||||
#include "Common.h"
|
||||
#include "twain.h"
|
||||
#include <vector>
|
||||
#include "gscn_drv.h"
|
||||
#include <memory>
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <map>
|
||||
#include "ImageTransfer.h"
|
||||
#include "ImageTranferBW.h"
|
||||
#include "ImageTranferMat.h"
|
||||
|
||||
using namespace std;
|
||||
/**
|
||||
* This is a virtual scanner. The virtual scanner is used by the data source
|
||||
* to try and somewhat simulate some real hardware interaction.
|
||||
* - It acquires the same image each time from an image file on the hard disk.
|
||||
* - It uses the FreeImage library to apply transforms to the base image.
|
||||
*
|
||||
* For simulation purposes the virtual Scanner is set up with the
|
||||
* following specifications:
|
||||
*
|
||||
* - Scanner Types
|
||||
* - ADF(Automatic Document Feeder)
|
||||
* - Flatbed
|
||||
*
|
||||
* - Image sensors
|
||||
* - CCD x 3 ( Front / Back / Flatbed )
|
||||
*
|
||||
* - Scanning area Minimum
|
||||
* - ADF - A8 @ 127g/m2 paper
|
||||
* - Flatbed - unlimited
|
||||
*
|
||||
* - Scanning area Maximum
|
||||
* - ADF - Legal paper
|
||||
* - Flatbed - A4 letter paper
|
||||
*
|
||||
* - Internal Optical Resolution
|
||||
* - 600dpi
|
||||
*
|
||||
* - Output Resolution
|
||||
* - Binary - 50, 100, 150, 200, 300, 400, 500, & 600
|
||||
* - Grayscale - 50, 100, 150, 200, 300, 400, 500, & 600
|
||||
* - Color - 50, 100, 150, 200, 300, 400, 500, & 600
|
||||
*
|
||||
* - Internal Bit Depth
|
||||
* - 8 bits per color
|
||||
*
|
||||
* - Output Bit Depth
|
||||
* - Binary - 1 bits
|
||||
* - Grayscale - 8 bits
|
||||
* - Color - 8 bits per color
|
||||
*
|
||||
* - Halftone Patterns
|
||||
* - Dither /error diffusion
|
||||
*
|
||||
* - compression: JPEG, and FAX4 (CCITT G4)
|
||||
*
|
||||
*/
|
||||
|
||||
// Defines used by Scanner FreeImage class to set and get attributes of the vurtual scanner.
|
||||
|
||||
/**
|
||||
* The FreeImage scanner define for PaperSource is ADF
|
||||
*/
|
||||
#define SFI_PAPERSOURCE_ADF 0
|
||||
/**
|
||||
* The FreeImage scanner define for PaperSource is Flatbed
|
||||
*/
|
||||
#define SFI_PAPERSOURCE_FB 1
|
||||
|
||||
/**
|
||||
* The FreeImage scanner data structure. This data is passed back and forth between the scanner class and driver.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* The FreeImage scanner. The software scanner using FreeImage.
|
||||
*
|
||||
*/
|
||||
class CScanner_FreeImage : public SFreeImage
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor for CScanner_FreeImage.
|
||||
*/
|
||||
CScanner_FreeImage();
|
||||
|
||||
/**
|
||||
* Deconstructor for CScanner_FreeImage.
|
||||
*/
|
||||
~CScanner_FreeImage();
|
||||
|
||||
/**
|
||||
* Resets the scanner to factory default settings.
|
||||
* Sets the scanners caps back to defaults.
|
||||
* @return true if successfully reset.
|
||||
*/
|
||||
bool resetScanner();
|
||||
|
||||
/**
|
||||
* Get a scan line and put it into the _ImageXfer, fill values in _ImageXfer.
|
||||
* @param[out] pTransferBuffer a pointer to an array of bytes to store the image data
|
||||
* @param[in] dwRead the number of bytes to read from scanner
|
||||
* @param[out] dwReceived the actual number of bytes transfered
|
||||
* @return true if successful
|
||||
*/
|
||||
bool getScanStrip(BYTE *pTransferBuffer, DWORD dwRead, DWORD &dwReceived);
|
||||
|
||||
/**
|
||||
* Sets all the scanners capabilities to read only.
|
||||
*/
|
||||
void Lock(void) {m_bReadOnly = true;}
|
||||
|
||||
/**
|
||||
* Sets all the scanners capabilities to read and write.
|
||||
*/
|
||||
void Unlock(void) {m_bReadOnly = false;}
|
||||
|
||||
/**
|
||||
* Retrieves the image to scan from disk into memory.
|
||||
* @return true if image was loaded into memory successfully.
|
||||
*/
|
||||
bool acquireImage(bool bscan = true);
|
||||
|
||||
////////////////
|
||||
// Accessors
|
||||
|
||||
/**
|
||||
* get the current settings
|
||||
* @return the current scanner settngs
|
||||
*/
|
||||
SFreeImage* getSetting() const;
|
||||
|
||||
/**
|
||||
* set the current settings
|
||||
* @param[in] settings the new settings for the scanner
|
||||
*/
|
||||
//void setSetting(SFreeImage settings);
|
||||
|
||||
/**
|
||||
* Determine if there is paper sitting in the feeder.
|
||||
* IF empty loads again for next time.
|
||||
* @return true if paper in feeder else return false.
|
||||
*/
|
||||
bool isFeederLoaded() const;
|
||||
|
||||
/**
|
||||
* Return status of the device is online or not.
|
||||
* @return true if online.
|
||||
*/
|
||||
bool getDeviceOnline() const;
|
||||
|
||||
bool isPaperOn();
|
||||
/* get scannner hardware version*/
|
||||
std::string getSerialNum() const;
|
||||
|
||||
std::string getFWVersion() const;
|
||||
|
||||
bool isImageQueueEmpty();
|
||||
|
||||
bool stillhaveImage();
|
||||
short GetMaxPagesInADF(void){return m_nMaxDocCount;}
|
||||
|
||||
void SetMaxPagesInADF(short nVal){m_nMaxDocCount = nVal;};
|
||||
|
||||
|
||||
bool StopScan();
|
||||
|
||||
WORD m_nSourceWidth; /**< Width of image in FreeImage */
|
||||
WORD m_nSourceHeight; /**< Height of image in FreeImage */
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Return the number of documents sitting in the feeder.
|
||||
* This number can be set with enviroment varible kGETENV_XFERCOUNT "CAP_XFERCOUNT"
|
||||
* this is so we can tell when the feeder is empty
|
||||
* - If CAP_XFERCOUNT is not set will return 1.
|
||||
* - if < 0 will return random number.
|
||||
* @return default number of documents.
|
||||
*/
|
||||
short getDocumentCount() const;
|
||||
|
||||
|
||||
/**
|
||||
* Transform the image according to the caps set by the application.
|
||||
* @return true if successful
|
||||
*/
|
||||
bool preScanPrep();
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
WORD m_nScanLine; /**< Current scan line of image in FreeImage */
|
||||
bool m_bReadOnly; /**< current mode */
|
||||
DWORD m_nDestBytesPerRow; /**< number of bytes needed for a row of data */
|
||||
DWORD m_nRowOffset; /**< offset of the first byte on every row*/
|
||||
//short m_nDocCount; /**< number of documents waiting to transfer */
|
||||
short m_nMaxDocCount; /**< Max number of documents waiting to transfer */
|
||||
char m_szSourceImagePath[PATH_MAX]; /**< image used with FreeImage */
|
||||
cv::Mat m_matDib;
|
||||
|
||||
private:
|
||||
void InitMSGMap();
|
||||
std::shared_ptr<ImageTransfer> m_imageTrans;
|
||||
std::map<UINT32,std::string> ntcMsg;
|
||||
};
|
||||
|
||||
#endif // __CSCANNER_H__
|
2617
CTWAINDS_Base.cpp
2617
CTWAINDS_Base.cpp
File diff suppressed because it is too large
Load Diff
649
CTWAINDS_Base.h
649
CTWAINDS_Base.h
|
@ -1,649 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright ?2007 TWAIN Working Group:
|
||||
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
|
||||
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
|
||||
* Ricoh Corporation, and Xerox Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the TWAIN Working Group nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @file CTWAINDS_Base.h
|
||||
* Base class describing a TWAIN Data Source.
|
||||
* @author TWAIN Working Group
|
||||
* @date April 2007
|
||||
*/
|
||||
|
||||
#ifndef __CTWAINBASE_H__
|
||||
#define __CTWAINBASE_H__
|
||||
|
||||
#include "CommonDS.h"
|
||||
|
||||
/**
|
||||
* possible States of the DS.
|
||||
* The five possible states of the Data Source Manager
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
dsState_Loaded = 3, /**< Source is loaded, but not open. */
|
||||
dsState_Open, /**< Source is open, and ready to: List & Negotiate Capabilities,
|
||||
* Request the Acquisition of data, and Close. */
|
||||
dsState_Enabled, /**< If UI is being used it is displayed. */
|
||||
dsState_XferReady, /**< Transfers are ready. */
|
||||
dsState_Xferring /**< Transfering data. */
|
||||
} DS_State;
|
||||
|
||||
/**
|
||||
* This is a TWAIN compliant base class. It contains all of the capabilities
|
||||
* and functions that are required to be a TWAIN compliant source. Simply
|
||||
* inherit this class and implement the pure virtual functions.
|
||||
* This basic version of a Data Source only supports connection of one
|
||||
* application at a time.
|
||||
*/
|
||||
class CTWAINDS_Base
|
||||
{
|
||||
public:
|
||||
CTWAINDS_Base();
|
||||
virtual ~CTWAINDS_Base();
|
||||
|
||||
/**
|
||||
* This is the same as the main DS_Entry function. Routes traffic
|
||||
* to the proper location.
|
||||
* @param[in] _pOrigin Identifies the source application of the message.
|
||||
* @param[in] _DG The Data Group.
|
||||
* @param[in] _DAT The Data Attribute Type.
|
||||
* @param[in] _MSG The message with respect to the Data Group and the Data Attribute Type.
|
||||
* @param[in,out] _pData A pointer to the data structure or variable identified
|
||||
* by the Data Attribute Type.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_UINT16 DS_Entry( pTW_IDENTITY _pOrigin,
|
||||
TW_UINT32 _DG,
|
||||
TW_UINT16 _DAT,
|
||||
TW_UINT16 _MSG,
|
||||
TW_MEMREF _pData);
|
||||
|
||||
/**
|
||||
* Fills _pStatus with the current condition code then resets the condition code.
|
||||
* @param[in] _MSG valid message for DAT_STATUS.
|
||||
* @param[out] _pStatus current condition code as pointer to TW_STATUS.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_status(TW_UINT16 _MSG,
|
||||
pTW_STATUS _pStatus);
|
||||
|
||||
/**
|
||||
* handles DAT_EVENT's
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[in] _pEvent a pointer to a TW_EVENT structure of the data.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_event(TW_UINT16 _MSG,
|
||||
pTW_EVENT _pEvent);
|
||||
|
||||
/**
|
||||
* handles DAT_IDENTITY requests.
|
||||
* @param[in] _pOrigin a pointer to a TW_IDENTITY of the sender of the message.
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[in,out] _pData pointer to a TW_IDENTITY structure to pass or retrieve data based on message.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_identity(pTW_IDENTITY _pOrigin,
|
||||
TW_UINT16 _MSG,
|
||||
pTW_IDENTITY _pData);
|
||||
|
||||
/**
|
||||
* handles DAT_PENDINGXFERS requests.
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[out] _pXfers a pointer to a TW_PENDINGXFERS structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_pendingxfers(TW_UINT16 _MSG,
|
||||
pTW_PENDINGXFERS _pXfers);
|
||||
|
||||
/**
|
||||
* handles DAT_CAPABILITY requests.
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[in] _pCap pointer to TW_CAPABILITY structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_capability(TW_UINT16 _MSG,
|
||||
pTW_CAPABILITY _pCap);
|
||||
|
||||
/**
|
||||
* handles DAT_USERINTERFACE requests.
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[in,out] _pData a pointer to a TW_USERINTERFACE structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_userinterface(TW_UINT16 _MSG,
|
||||
pTW_USERINTERFACE _pData);
|
||||
|
||||
/**
|
||||
* handles DAT_SETUPFILEXFER requests.
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[in] _pData a pointer to a TW_SETUPFILEXFER structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_setupfilexfer(TW_UINT16 _MSG,
|
||||
pTW_SETUPFILEXFER _pData);
|
||||
|
||||
/**
|
||||
* handles DAT_SETUPMEMXFER requests.
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[in] _pData a pointer to a TW_SETUPMEMXFER structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_setupmemxfer(TW_UINT16 _MSG,
|
||||
pTW_SETUPMEMXFER _pData);
|
||||
|
||||
/**
|
||||
* handles DAT_IMAGENATIVEXFER requests.
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[in] _pData a handle to the memory.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_imagenativexfer(TW_UINT16 _MSG,
|
||||
TW_HANDLE& _pData);
|
||||
|
||||
/**
|
||||
* handles DAT_IMAGEFILEXFER requests.
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_imagefilexfer(TW_UINT16 _MSG);
|
||||
|
||||
/**
|
||||
* handles DAT_IMAGEMEMXFER requests.
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[in] _pData a pointer to a TW_IMAGEMEMXFER structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_imagememxfer(TW_UINT16 _MSG,
|
||||
pTW_IMAGEMEMXFER _pData);
|
||||
|
||||
/**
|
||||
* handles DAT_IMAGELAYOUT requests.
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[in] _pData a pointer to a TW_IMAGELAYOUT structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_imagelayout(TW_UINT16 _MSG,
|
||||
pTW_IMAGELAYOUT _pData);
|
||||
|
||||
/**
|
||||
* Figures out what to do with the DAT_IMAGEINFO request.
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[in] _pImageInfo a pointer to a TW_IMAGEINFO structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_imageinfo(TW_UINT16 _MSG,
|
||||
pTW_IMAGEINFO _pImageInfo);
|
||||
|
||||
/**
|
||||
* Figures out what to do with the DAT_EXTIMAGEINFO request.
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[in] _pData a pointer to a TW_EXTIMAGEINFO structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_extimageinfo(TW_UINT16 _MSG,
|
||||
pTW_EXTIMAGEINFO _pData);
|
||||
|
||||
|
||||
/**
|
||||
* Figures out what to do with the DAT_ENTRYPOINT request.
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[in] _pEntryPoints a pointer to a TW_ENTRYPOINT structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_entrypoint(TW_UINT16 _MSG,
|
||||
pTW_ENTRYPOINT _pEntryPoints);
|
||||
|
||||
/**
|
||||
* Figures out what to do with the DAT_XFERGROUP request.
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[in] _pXferGroup a pointer to a TW_UINT32 value.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_xfergroup(TW_UINT16 _MSG,
|
||||
pTW_UINT32 _pXferGroup);
|
||||
|
||||
/**
|
||||
* Figures out what to do with the DAT_CUSTOMDSDATA request.
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[in] _pDSData a pointer to a TW_CUSTOMDSDATA structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 dat_customdsdata(TW_UINT16 _MSG,
|
||||
pTW_CUSTOMDSDATA _pDSData);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* @name Pure Virtuals
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fills the identity structure with our information.
|
||||
* Overload this function in derived classes to uniquely identify them selves.
|
||||
* @param[out] _idStruct our TW_IDENTITY information.
|
||||
*/
|
||||
virtual void fillIdentityStructure(TW_IDENTITY& _idStruct) = 0;
|
||||
|
||||
/**
|
||||
* Initialize the Datasource. Allocate memory for Capabilities.
|
||||
* Sets condition code if had problem.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 Initialize() = 0;
|
||||
|
||||
/**
|
||||
* Enable the Data Source.
|
||||
* Called when a DG_CONTROL / DAT_USERINTERFACE / MSG_ENABLEDS op is sent.
|
||||
* @param[in] _pData a pointer to a TW_USERINTERFACE structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 enableDS(pTW_USERINTERFACE _pData) = 0;
|
||||
|
||||
/**
|
||||
* Enable the Data Source in setup mode.
|
||||
* Called when a DG_CONTROL / DAT_USERINTERFACE / MSG_ENABLEDS op is sent.
|
||||
* @param[in] _pData a pointer to a TW_USERINTERFACE structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 enableDSOnly(pTW_USERINTERFACE _pData) = 0;
|
||||
|
||||
/**
|
||||
* Disable the Data Source.
|
||||
* Called when a DG_CONTROL / DAT_USERINTERFACE / MSG_DISABLEDS op is sent.
|
||||
* @param[in] _pData a pointer to a TW_USERINTERFACE structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 disableDS(pTW_USERINTERFACE _pData) = 0;
|
||||
|
||||
/**
|
||||
* Get image information.
|
||||
* Called when a DG_IMAGE / DAT_IMAGEINFO / MSG_GET op is sent.
|
||||
* -If in state 6, general info is provided about the image about to be transferred.
|
||||
* -If in state 7, specific info is provided about the current image just transferred.
|
||||
* @param[out] _pImageInfo a pointer to TW_IMAGEINFO structure to return image information.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 getImageInfo(pTW_IMAGEINFO _pImageInfo) = 0;
|
||||
|
||||
/**
|
||||
* Open the Data Source.
|
||||
* Called when a DG_CONTROL / DAT_IDENTITY / MSG_OPENDS op is sent.
|
||||
* @param[in] _pOrigin a pointer to TW_IDENTITY structure of the Application identity.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 openDS(pTW_IDENTITY _pOrigin) = 0;
|
||||
|
||||
/**
|
||||
* Close the Data Source.
|
||||
* Called when a DG_CONTROL / DAT_IDENTITY / MSG_CLOSEDS op is sent.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 closeDS() = 0;
|
||||
|
||||
/**
|
||||
* get data for memory transfer.
|
||||
* Called when a DG_CONTROL / DAT_SETUPMEMXFER / MSG_GET op is sent.
|
||||
* @param[in] _pData a pointer to TW_SETUPMEMXFER structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 getMemoryXfer(pTW_SETUPMEMXFER _pData) = 0;
|
||||
|
||||
/**
|
||||
* Process events.
|
||||
* Called when a DG_CONTROL / DAT_EVENT / MSG_PROCESSEVENT op is sent.
|
||||
* @param[in] _pEvent a pointer to TW_EVENT structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 processEvent(pTW_EVENT _pEvent) = 0;
|
||||
|
||||
/**
|
||||
* Stop currect transfer if not done. Single from application that application is
|
||||
* done with all data with current image.
|
||||
* Check to see if there is still documents or data remaining to transfer.
|
||||
* Called when a DG_CONTROL / DAT_PENDINGXFERS / MSG_ENDXFER op is sent.
|
||||
* @param[out] _pXfers a pointer to TW_PENDINGXFERS structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 endXfer(pTW_PENDINGXFERS _pXfers) = 0;
|
||||
|
||||
/**
|
||||
* Check to see if there is still documents or data remaining to transfer.
|
||||
* Called when a DG_CONTROL / DAT_PENDINGXFERS / MSG_GET op is sent.
|
||||
* @param[out] _pXfers a pointer to TW_PENDINGXFERS structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 getXfer(pTW_PENDINGXFERS _pXfers) = 0;
|
||||
|
||||
/**
|
||||
* Flush all pending transfers from the Source..
|
||||
* Called when a DG_CONTROL / DAT_PENDINGXFERS / MSG_RESET op is sent.
|
||||
* @param[out] _pXfers a pointer to TW_PENDINGXFERS structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 resetXfer(pTW_PENDINGXFERS _pXfers) = 0;
|
||||
|
||||
/**
|
||||
* Transfer image data from scanner to memory.
|
||||
* Called during one of the transfer methods.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 transfer() = 0;
|
||||
|
||||
// END Pure Virtuals
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* @name Capabilities
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Start the transfer of image data natively.
|
||||
* Called when a DG_IMAGE / DAT_IMAGENATIVEXFER / MSG_GET op is sent.
|
||||
* @param[out] _hData a handle to store the image locaton.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 transferNativeImage(TW_HANDLE &_hData);
|
||||
|
||||
/**
|
||||
* Return info about the file that the Source will write the acquired data into
|
||||
* Called when a DG_CONTROL / DAT_SETUPFILEXFER / MSG_GET op is sent.
|
||||
* @param[in] _pData a pointer to TW_SETUPFILEXFER structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 getFileXfer(pTW_SETUPFILEXFER _pData);
|
||||
|
||||
/**
|
||||
* Return the default file transfer information
|
||||
* Called when a DG_CONTROL / DAT_SETUPFILEXFER / MSG_GETDEFAULT op is sent.
|
||||
* @param[in] _pData a pointer to TW_SETUPFILEXFER structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 getDefaultFileXfer(pTW_SETUPFILEXFER _pData);
|
||||
|
||||
/**
|
||||
* Reset current file information to default values
|
||||
* Called when a DG_CONTROL / DAT_SETUPFILEXFER / MSG_RESET op is sent.
|
||||
* @param[in] _pData a pointer to TW_SETUPFILEXFER structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 resetFileXfer(pTW_SETUPFILEXFER _pData);
|
||||
|
||||
/**
|
||||
* Set file transfer information for next file transfer
|
||||
* Called when a DG_CONTROL / DAT_SETUPFILEXFER / MSG_SET op is sent.
|
||||
* @param[in] _pData a pointer to TW_SETUPFILEXFER structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 setFileXfer(pTW_SETUPFILEXFER _pData);
|
||||
|
||||
/**
|
||||
* Save image data to file.
|
||||
* Called when a DG_IMAGE / DAT_IMAGEFILEXFER / MSG_GET op is sent.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 saveImageFile();
|
||||
|
||||
/**
|
||||
* Transfer memory buffers.
|
||||
* Called when a DG_IMAGE / DAT_IMAGEMEMXFER / MSG_GET op is sent.
|
||||
* @param[out] _pData a pointer to TW_IMAGEMEMXFER structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 transferMemoryBuffers(pTW_IMAGEMEMXFER _pData);
|
||||
|
||||
/**
|
||||
* get the Internal Image format.
|
||||
* Called when a DG_IMAGE / DAT_IMAGENATIVEXFER / MSG_GET op is sent.
|
||||
* also used when creating a BMP for saving when DG_IMAGE / DAT_IMAGEFILEXFER / MSG_GET op is sent.
|
||||
* @param[out] _hImage a handle to store the image locaton.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 getDIBImage(TW_HANDLE &_hImage);
|
||||
#ifdef TWNDS_OS_APPLE
|
||||
/**
|
||||
* MAC only
|
||||
* get the Internal Image format.
|
||||
* Called when a DG_IMAGE / DAT_IMAGENATIVEXFER / MSG_GET op is sent.
|
||||
* also used when creating a BMP for saving when DG_IMAGE / DAT_IMAGEFILEXFER / MSG_GET op is sent.
|
||||
* @param[out] _hImage a handle to store the image locaton.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 getPICTImage(TW_HANDLE &_hPICTImage);
|
||||
#endif
|
||||
/**
|
||||
* Save the current image data as a BMP file
|
||||
* @return a valid TWRC_xxxx return code, TWRC_XFERDONE on success.
|
||||
*/
|
||||
TW_INT16 saveImageFileAsBMP();
|
||||
|
||||
/**
|
||||
* Save the current image data as a TIFF file
|
||||
* @return a valid TWRC_xxxx return code, TWRC_XFERDONE on success.
|
||||
*/
|
||||
TW_INT16 saveImageFileAsTIFF();
|
||||
|
||||
/**
|
||||
* Request the DSM that we are ready to send images.
|
||||
* @return true if successful.
|
||||
*/
|
||||
virtual bool DoXferReadyEvent();
|
||||
|
||||
/**
|
||||
* Request the DSM the most likly user clicks on the “OK?button on GUI.
|
||||
* @return true if successful.
|
||||
*/
|
||||
virtual bool DoCloseDSOkEvent();
|
||||
|
||||
/**
|
||||
* Request the DSM that the Source’s user interface be disabled.
|
||||
* @return true if successful.
|
||||
*/
|
||||
virtual bool DoCloseDSRequestEvent();
|
||||
|
||||
/**
|
||||
* Report to the DSM that a device event has occurred.
|
||||
* @return true if successful.
|
||||
*/
|
||||
virtual bool DoDeviceEvent();
|
||||
|
||||
/**
|
||||
* get the Internal Image format. For Linux Only
|
||||
* Called when a DG_IMAGE / DAT_IMAGENATIVEXFER / MSG_GET op is sent.
|
||||
* also used when creating a BMP for saving when DG_IMAGE / DAT_IMAGEFILEXFER / MSG_GET op is sent.
|
||||
* @param[out] _hImage a handle to store the image locaton.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 getTIFFImage(TW_HANDLE &_hImage);
|
||||
|
||||
// END Capabilities
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* @name Accessors
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the current condition code.
|
||||
* @return a valid TWCC_xxxxxx condition code.
|
||||
*/
|
||||
virtual TW_INT16 getConditionCode() const;
|
||||
|
||||
/**
|
||||
* Sets the current condition code.
|
||||
* @param[in] _cc a valid TWCC_xxxxxx condition code.
|
||||
*/
|
||||
virtual void setConditionCode(TW_INT16 _cc);
|
||||
|
||||
/**
|
||||
* Returns a pointer to our identity structure.
|
||||
* @return pointer to out TW_IDENTITY identity structure.
|
||||
*/
|
||||
pTW_IDENTITY getIdentity();
|
||||
|
||||
/**
|
||||
* Returns a pointer to the source application controlling us.
|
||||
* @return pointer to TW_IDENTITY identity structure.
|
||||
*/
|
||||
pTW_IDENTITY getApp();
|
||||
|
||||
/**
|
||||
* Returns the current state of the Data Source.
|
||||
* @return a DS_State of the current state.
|
||||
*/
|
||||
DS_State getState() { return m_CurrentState; }
|
||||
|
||||
/**
|
||||
* This is a template class that will actually operate on the capability.
|
||||
* It supports all valid CTWAINContainer types which are currently INTS, FIX32 and FRAME's.
|
||||
* @param[in] _MSG the message
|
||||
* @param[in] _pContainer the container type
|
||||
* @param[in] _pCap the capability
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
template<class TWAINContainerType>
|
||||
TW_INT16 handleCap(TW_UINT16 _MSG, TWAINContainerType* _pContainer, pTW_CAPABILITY _pCap);
|
||||
|
||||
/**
|
||||
* Return a CTWAINContainer class of the capability.
|
||||
* @param[in] _unCap the capability looking for
|
||||
* @return the capability if found
|
||||
*/
|
||||
virtual CTWAINContainer* findCapability(const TW_UINT16 _unCap);
|
||||
|
||||
/**
|
||||
* if the CTWAINContainer is dependend on another Capabiltiy or settings.
|
||||
* This function is used to get the data it needs.
|
||||
* @param[in] _pContainer the container
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 updatePreDependencies(CTWAINContainer* _pContainer);
|
||||
|
||||
/**
|
||||
* Validate the value being used to set a capability. Ranges and enums can be tested
|
||||
* by the capability but OneValues might have only some values that are acceptable.
|
||||
* Override this function in base class to support more capabilities
|
||||
* @param[in] Cap the Capability ID
|
||||
* @param[in] ConType the container type
|
||||
* @param[in] _pCap a pointer to BYTE. Pointer to Cap container
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 validateCapabilitySet(TW_UINT16 _Cap, TW_UINT16 _ConType, BYTE* _pContainer);
|
||||
|
||||
/**
|
||||
* Update Capability Container after the operation
|
||||
* Override this function in base class to support more capabilities
|
||||
* @param[in] _pCap the capability
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 updatePostContainer(pTW_CAPABILITY _pCap);
|
||||
/**
|
||||
* Update Capability Container before the operation
|
||||
* Override this function in base class to support more capabilities
|
||||
* @param[in] _pCap the capability
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 updatePreContainer(pTW_CAPABILITY _pCap);
|
||||
|
||||
/**
|
||||
* if the CTWAINContainer is dependend on another Capabiltiy.
|
||||
* This function is used to get the data it needs.
|
||||
* @param[in] MSG the message that was sent
|
||||
* @param[in] Cap the Capability that it was sent to
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
virtual TW_INT16 updatePostDependencies(TW_UINT16 MSG, TW_UINT16 Cap);
|
||||
|
||||
/**
|
||||
* Update the frame to bewithin the constrains of the scanners Phyisical
|
||||
* dimentions and minimum allowed sizes.
|
||||
* @param[in out] _frame the frame to update.
|
||||
* @return true if the frame is not change, false if changed.
|
||||
*/
|
||||
virtual bool ConstrainFrameToScanner(InternalFrame& _frame,bool &bConstrained);
|
||||
|
||||
/**
|
||||
* get the current unit and resolution. A helper function used by Unit dependent cap
|
||||
* @param[out] Unit the current unit value.
|
||||
* @param[out] Xres the current X resolution value.
|
||||
* @param[out] Yres the current Y resolution value.
|
||||
* @return a CTWAINContainer for the capability.
|
||||
*/
|
||||
TW_INT16 getCurrentUnits(int &Unit, float &Xres, float &Yres);
|
||||
|
||||
/**
|
||||
* Get Gustom DS data
|
||||
* @param[out] _pDSData a pointer to a TW_CUSTOMDSDATA structure.
|
||||
* @return a valid TWRC_xxxx return code, TWRC_SUCCESS on success.
|
||||
*/
|
||||
virtual TW_INT16 GetGustomDSData(pTW_CUSTOMDSDATA _pDSData);
|
||||
|
||||
/**
|
||||
* Set Gustom DS data
|
||||
* @param[in] _pDSData a pointer to a TW_CUSTOMDSDATA structure.
|
||||
* @return a valid TWRC_xxxx return code, TWRC_SUCCESS on success.
|
||||
*/
|
||||
virtual TW_INT16 SetGustomDSData(pTW_CUSTOMDSDATA _pDSData);
|
||||
|
||||
// END Accessors
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
static TW_IDENTITY m_TheIdentity; /**< default Identity */
|
||||
|
||||
protected:
|
||||
TWAINCapabilitiesMap m_IndependantCapMap; /**< Stores a list of all capacitites that each instance support. */
|
||||
|
||||
TW_INT16 m_DSConditionCode; /**< Current global condition. */
|
||||
TW_IDENTITY m_MyIdentity; /**< Detail information of our information.*/
|
||||
TW_IDENTITY m_App; /**< Detail information of the application source. */
|
||||
DS_State m_CurrentState; /**< Current state of the Data Source. */
|
||||
TW_STR255 m_CurFileExferName; /**< Current File Transfer Name. */
|
||||
TW_STR255 m_DefFileExferName; /**< Default File Transfer Name. */
|
||||
TW_IMAGEINFO m_ImageInfo; /**< Current Image Info data. */
|
||||
TW_UINT32 m_DocumentNumber; /**< Current Document Number */
|
||||
TW_UINT32 m_PageNumber; /**< Current Page Number */
|
||||
TW_PENDINGXFERS m_Xfers; /**< Number of Transfers remianing in this batch */
|
||||
DWORD m_nDestScanLine; /**< Current Scanline used for memory transfer */
|
||||
TW_HANDLE m_hImageData; /**< Handle to Current Image Data */
|
||||
|
||||
};
|
||||
|
||||
#endif // __CTWAINBASE_H__
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -1,279 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright ?2007 TWAIN Working Group:
|
||||
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
|
||||
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
|
||||
* Ricoh Corporation, and Xerox Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the TWAIN Working Group nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @file CTWAINDS_FreeImage.h
|
||||
* The main Data Source class.
|
||||
* This class is derived from the Base class describing a TWAIN DS.
|
||||
* @author TWAIN Working Group
|
||||
* @date April 2007
|
||||
*/
|
||||
#ifndef __CTWAINDS_FREEIMAGE_H__
|
||||
#define __CTWAINDS_FREEIMAGE_H__
|
||||
|
||||
#include "CTWAINDS_Base.h"
|
||||
#include "CScanner_FreeImage.h"
|
||||
#include "JsonConfig.h"
|
||||
|
||||
|
||||
#define CUSTCAP_LONGDOCUMENT CAP_CUSTOMBASE+1
|
||||
#define CUSTCAP_DOCS_IN_ADF CAP_CUSTOMBASE+2
|
||||
|
||||
#define kCUSTOMDSGUI "{A4FAF845-1383-4036-AEDC-17C3968188B4}"
|
||||
|
||||
const TW_GUID CustomDSGUI =
|
||||
{ 0xa4faf845, 0x1383, 0x4036, { 0xae, 0xdc, 0x17, 0xc3, 0x96, 0x81, 0x88, 0xb4 } };
|
||||
|
||||
typedef struct _CUST_DS_DATA_ELEMENT
|
||||
{
|
||||
DWORD dwSize;
|
||||
TW_UINT16 unCapID;
|
||||
TW_UINT16 unCapIdx;
|
||||
TW_UINT16 unItemType;
|
||||
TW_UINT16 unContType;
|
||||
DWORD dwVal[1];
|
||||
}CUST_DS_DATA_ELEMENT;
|
||||
|
||||
/**
|
||||
* This is the main DS class. It inherits the TWAIN base class, implements all
|
||||
* the pure virtual functions and manages all of the required capabilities
|
||||
*/
|
||||
class CTWAINDS_FreeImage : public CTWAINDS_Base
|
||||
{
|
||||
public:
|
||||
CTWAINDS_FreeImage(TW_IDENTITY AppID);
|
||||
~CTWAINDS_FreeImage();
|
||||
|
||||
/**
|
||||
* Fills the passed in identity structure with our information.
|
||||
* @param[in] _idStruct the TW_IDENTITY structure to fill
|
||||
*/
|
||||
void fillIdentityStructure(TW_IDENTITY& _idStruct);
|
||||
|
||||
/**
|
||||
* Initialize the Datasource. Allocate memory for Capabilities.
|
||||
* Sets condition code if had problem.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 Initialize();
|
||||
|
||||
/**
|
||||
* Get image information.
|
||||
* Implementation of base class pure virtual function.
|
||||
* Called when a DG_IMAGE / DAT_IMAGEINFO / MSG_GET op is sent.
|
||||
* -If in state 6, general info is provided about the image about to be transferred.
|
||||
* -If in state 7, specific info is provided about the current image just transferred.
|
||||
* @param[out] _pImageInfo a TW_IMAGEINFO structure to return image information.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 getImageInfo(pTW_IMAGEINFO _pImageInfo);
|
||||
|
||||
/**
|
||||
* Open the Data Source.
|
||||
* Implementation of base class pure virtual function.
|
||||
* Called when a DG_CONTROL / DAT_IDENTITY / MSG_OPENDS op is sent.
|
||||
* @param[in] _pOrigin a pointer to TW_IDENTITY structure of the Application identity.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 openDS(pTW_IDENTITY _pOrigin);
|
||||
|
||||
/**
|
||||
* Close the Data Source.
|
||||
* Implementation of base class pure virtual function.
|
||||
* Called when a DG_CONTROL / DAT_IDENTITY / MSG_CLOSEDS op is sent.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 closeDS();
|
||||
|
||||
/**
|
||||
* Process events.
|
||||
* Implementation of base class pure virtual function.
|
||||
* Called when a DG_CONTROL / DAT_EVENT / MSG_PROCESSEVENT op is sent.
|
||||
* @param[in] _pEvent a pointer to TW_EVENT structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 processEvent(pTW_EVENT _pEvent);
|
||||
|
||||
/**
|
||||
* Stop currect transfer if not done. Single from application that application is
|
||||
* done with all data with current image.
|
||||
* Check to see if there is still documents or data remaining to transfer.
|
||||
* Implementation of base class pure virtual function.
|
||||
* Called when a DG_CONTROL / DAT_PENDINGXFERS / MSG_ENDXFER op is sent.
|
||||
* @param[out] _pXfers a pointer to TW_PENDINGXFERS structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 endXfer(pTW_PENDINGXFERS _pXfers);
|
||||
|
||||
/**
|
||||
* Check to see if there is still documents or data remaining to transfer.
|
||||
* Called when a DG_CONTROL / DAT_PENDINGXFERS / MSG_GET op is sent.
|
||||
* @param[out] _pXfers a pointer to TW_PENDINGXFERS structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 getXfer(pTW_PENDINGXFERS _pXfers);
|
||||
|
||||
/**
|
||||
* Flush all pending transfers from the Source..
|
||||
* Called when a DG_CONTROL / DAT_PENDINGXFERS / MSG_RESET op is sent.
|
||||
* @param[out] _pXfers a pointer to TW_PENDINGXFERS structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 resetXfer(pTW_PENDINGXFERS _pXfers);
|
||||
|
||||
/**
|
||||
* Called by the base class when the data source is enabled.
|
||||
* @param[in] _pData contains info about if the UI should be shown etc.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 enableDS(pTW_USERINTERFACE _pData);
|
||||
|
||||
/**
|
||||
* Enable the Data Source in setup mode.
|
||||
* Called when a DG_CONTROL / DAT_USERINTERFACE / MSG_ENABLEDS op is sent.
|
||||
* @param[in] _pData a pointer to a TW_USERINTERFACE structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 enableDSOnly(pTW_USERINTERFACE _pData);
|
||||
|
||||
/**
|
||||
* Called by the base class when the data source is disabled.
|
||||
* @param[in] _pData a pointer to a TW_USERINTERFACE struct.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 disableDS(pTW_USERINTERFACE _pData);
|
||||
|
||||
|
||||
/**
|
||||
* handles DAT_IMAGELAYOUT requests
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[in] _pData a pointer to TW_IMAGELAYOUT structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 dat_imagelayout(TW_UINT16 _MSG, pTW_IMAGELAYOUT _pData);
|
||||
|
||||
/**
|
||||
* Figures out what to do with the DAT_EXTIMAGEINFO request.
|
||||
* @param[in] _MSG the message to handle.
|
||||
* @param[in] _pData a pointer to a TW_EXTIMAGEINFO structure.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 dat_extimageinfo(TW_UINT16 _MSG,
|
||||
pTW_EXTIMAGEINFO _pData);
|
||||
|
||||
/**
|
||||
* Called by the base class to when the application wants to get memory transfer data.
|
||||
* @param[in] _pData filled with buffer size data
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 getMemoryXfer(pTW_SETUPMEMXFER _pData);
|
||||
|
||||
/**
|
||||
* Transfer image data from scanner to memory.
|
||||
* Called during one of the transfer methods.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 transfer();
|
||||
|
||||
/**
|
||||
* Return a CTWAINContainer for requested capability.
|
||||
* @param[in] _unCap the ICAP_xxxx that is requested.
|
||||
* @return a CTWAINContainer for the capability.
|
||||
*/
|
||||
CTWAINContainer* findCapability(const TW_UINT16 _unCap);
|
||||
|
||||
/**
|
||||
* Request the DSM the most likly user clicks on the “OK?button on GUI.
|
||||
* @return true if successful.
|
||||
*/
|
||||
virtual bool DoCloseDSOkEvent();
|
||||
|
||||
/**
|
||||
* Updates the scanner from the current caps.
|
||||
* @return true if successful.
|
||||
*/
|
||||
bool updateScannerFromCaps();
|
||||
|
||||
/**
|
||||
* Convenience function that will get the proper ICAP_BITDEPTH container
|
||||
* @return CTWAINContainer BitDepth for current PixelType.
|
||||
*/
|
||||
CTWAINContainer* getICAP_BITDEPTH();
|
||||
|
||||
bool StartScanning(bool showUI=true);
|
||||
bool StopScanning();
|
||||
bool ReadCustomDSdata(stringstream &DsData);
|
||||
bool StoreCustomDSdata(stringstream &DsData);
|
||||
bool StoreCapInStream(stringstream &_DsData, TW_UINT16 _unCapID, TW_UINT16 _unCapIdx, TW_UINT16 unContType);
|
||||
bool ReadCapFromStream(stringstream &_DsData, TW_UINT16 _unCapID, TW_UINT16 _unCapIdx);
|
||||
|
||||
/**
|
||||
* Get Gustom DS data
|
||||
* @param[out] _pDSData a pointer to a TW_CUSTOMDSDATA structure.
|
||||
* @return a valid TWRC_xxxx return code, TWRC_SUCCESS on success.
|
||||
*/
|
||||
TW_INT16 GetGustomDSData(pTW_CUSTOMDSDATA _pDSData);
|
||||
|
||||
/**
|
||||
* Set Gustom DS data
|
||||
* @param[in] _pDSData a pointer to a TW_CUSTOMDSDATA structure.
|
||||
* @return a valid TWRC_xxxx return code, TWRC_SUCCESS on success.
|
||||
*/
|
||||
TW_INT16 SetGustomDSData(pTW_CUSTOMDSDATA _pDSData);
|
||||
|
||||
/**
|
||||
* Validate the value being used to set a capability. Ranges and enums can be tested
|
||||
* by the capability but OneValues might have only some values that are acceptable.
|
||||
* Override this function in base class to support more capabilities
|
||||
* @param[in] Cap the Capability ID
|
||||
* @param[in] ConType the container type
|
||||
* @param[in] _pCap a pointer to BYTE. Pointer to Cap container
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 validateCapabilitySet(TW_UINT16 _Cap, TW_UINT16 _ConType, BYTE* _pContainer);
|
||||
|
||||
bool UpdateCapsFromConfig(CONFIGPARAMS pConfig);
|
||||
std::string GetSerialNum();
|
||||
std::string GetFWVerison();
|
||||
bool IsImageQueueEmpty();
|
||||
bool StillRemainImages();
|
||||
protected:
|
||||
CScanner_FreeImage m_Scanner; /**< The main scanner. */
|
||||
|
||||
TWAINCapabilitiesMap_int m_BitDepthMap; /**< Capability for various Bit Depths */
|
||||
CTWAINContainerFrame *m_pICAP_FRAMES; /**< Capabiltiy for a FRAMES based container */
|
||||
TW_IDENTITY m_AppID;
|
||||
bool m_bCanceled;
|
||||
CTWAIN_UI *m_pGUI; /**< This is the main MFC UI dialog */
|
||||
bool bIndicators;
|
||||
BOOL b_created;
|
||||
};
|
||||
#endif // __CTWAINDS_FREEIMAGE_H__
|
|
@ -1,195 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright © 2007 TWAIN Working Group:
|
||||
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
|
||||
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
|
||||
* Ricoh Corporation, and Xerox Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the TWAIN Working Group nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @file CTWAINDS_Sample1.cpp
|
||||
* Reveals the main entry point for the DSM
|
||||
* @author TWAIN Working Group
|
||||
* @date April 2007
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
#include "CTWAINDS_Sample1.h"
|
||||
#include <list>
|
||||
#include "twain.h"
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Globals
|
||||
/**
|
||||
* gloabal pointer of the Data Source, for access to the main DS_Entry.
|
||||
*/
|
||||
typedef struct _DS_inst
|
||||
{
|
||||
TW_IDENTITY AppId;
|
||||
CTWAINDS_Base *pDS;
|
||||
}DS_inst;
|
||||
|
||||
typedef list<DS_inst> lstDS;
|
||||
lstDS g_lstDS;
|
||||
|
||||
#ifdef TWH_CMP_MSC
|
||||
/**
|
||||
* gloadbal Windows Instance handle for the DSM DLL...
|
||||
*/
|
||||
HINSTANCE g_hinstance = 0;
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// This is the main entry point. This function is dlsym'd by the DSM.
|
||||
|
||||
#ifdef TWH_CMP_MSC
|
||||
TW_UINT16 FAR PASCAL
|
||||
#else
|
||||
FAR PASCAL TW_UINT16
|
||||
#endif
|
||||
DS_Entry( pTW_IDENTITY _pOrigin,
|
||||
TW_UINT32 _DG,
|
||||
TW_UINT16 _DAT,
|
||||
TW_UINT16 _MSG,
|
||||
TW_MEMREF _pData)
|
||||
{
|
||||
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
||||
CTWAINDS_Base* pTWAINLayer = 0;
|
||||
if(_pOrigin)
|
||||
{
|
||||
lstDS::iterator llIter=g_lstDS.begin();
|
||||
for(;llIter!=g_lstDS.end();llIter++)
|
||||
{
|
||||
if((*llIter).AppId.Id==_pOrigin->Id)
|
||||
{
|
||||
pTWAINLayer=(*llIter).pDS;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Curently we are not open
|
||||
if( 0 == pTWAINLayer )
|
||||
{
|
||||
// Special case DSM can request to get identity information about
|
||||
// DS before it is open. In this special case, where the DS is not
|
||||
// open, we return this static Idenity.
|
||||
if( DG_CONTROL == _DG && DAT_IDENTITY == _DAT && MSG_GET == _MSG )
|
||||
{
|
||||
// Copy the ID assigned by the DSM eventhough the spec states
|
||||
// that the id will not be assigned until MSG_OPENDS
|
||||
CTWAINDS_Base::m_TheIdentity.Id = ((pTW_IDENTITY)_pData)->Id;
|
||||
memcpy( _pData, &CTWAINDS_Base::m_TheIdentity, sizeof(CTWAINDS_Base::m_TheIdentity) );
|
||||
|
||||
return TWRC_SUCCESS;
|
||||
}
|
||||
|
||||
// The DS is not open. If we get a request to close DS do not open
|
||||
// just to close, instead return that it is success closed.
|
||||
if( DG_CONTROL == _DG && DAT_IDENTITY == _DAT && MSG_CLOSEDS == _MSG )
|
||||
{
|
||||
return TWRC_SUCCESS;
|
||||
}
|
||||
|
||||
// Open the DS
|
||||
pTWAINLayer = new CTWAINDS_FreeImage(*_pOrigin);
|
||||
if( NULL == pTWAINLayer
|
||||
|| TWRC_SUCCESS != pTWAINLayer->Initialize())
|
||||
{
|
||||
// Failed to create the DS
|
||||
//setConditionCode(TWCC_LOWMEMORY);
|
||||
if(pTWAINLayer)
|
||||
{
|
||||
// Created but could not Initialize
|
||||
delete pTWAINLayer;
|
||||
}
|
||||
return TWRC_FAILURE;
|
||||
}
|
||||
DS_inst _DS;
|
||||
_DS.pDS = pTWAINLayer;
|
||||
_DS.AppId = *_pOrigin;
|
||||
g_lstDS.push_back(_DS);
|
||||
|
||||
}
|
||||
|
||||
// If we were not open before, we are now, so continue with the TWAIN call
|
||||
TW_INT16 result = pTWAINLayer->DS_Entry(_pOrigin, _DG, _DAT, _MSG, _pData);
|
||||
|
||||
/**
|
||||
* Special case - free memory if closing DS
|
||||
* @todo keep track of what apps are connecting to the ds and only
|
||||
* delete when count goes down to 0
|
||||
*/
|
||||
if( TWRC_SUCCESS == result &&
|
||||
DG_CONTROL == _DG && DAT_IDENTITY == _DAT && MSG_CLOSEDS == _MSG &&
|
||||
NULL != pTWAINLayer )
|
||||
{
|
||||
lstDS::iterator llIter=g_lstDS.begin();
|
||||
for(;llIter!=g_lstDS.end();)
|
||||
{
|
||||
if((*llIter).AppId.Id==_pOrigin->Id)
|
||||
{
|
||||
delete (*llIter).pDS;
|
||||
llIter = g_lstDS.erase(llIter);
|
||||
continue;
|
||||
}
|
||||
llIter++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//#ifdef TWH_CMP_MSC
|
||||
///**
|
||||
//* DllMain is only needed for Windows, and it's only needed to collect
|
||||
//* our instance handle, which is also our module handle. Don't ever
|
||||
//* put anything else in here, not even logging messages. It just isn't
|
||||
//* safe...
|
||||
//*/
|
||||
//BOOL WINAPI DllMain(HINSTANCE _hmodule,
|
||||
// DWORD _dwReasonCalled,
|
||||
// LPVOID)
|
||||
//{
|
||||
// switch (_dwReasonCalled)
|
||||
// {
|
||||
// case DLL_THREAD_ATTACH:
|
||||
// case DLL_THREAD_DETACH:
|
||||
// break;
|
||||
// case DLL_PROCESS_ATTACH:
|
||||
// g_hinstance = _hmodule;
|
||||
// break;
|
||||
// case DLL_PROCESS_DETACH:
|
||||
// unLoadDSMLib();
|
||||
// g_hinstance = 0;
|
||||
// break;
|
||||
// }
|
||||
// return(TRUE);
|
||||
//}
|
||||
//#elif (TWNDS_CMP == TWNDS_CMP_GNUGPP)
|
||||
// // Nothing for us to do...
|
||||
//#else
|
||||
// #error Sorry, we do not recognize this system...
|
||||
//#endif
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright ?2007 TWAIN Working Group:
|
||||
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
|
||||
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
|
||||
* Ricoh Corporation, and Xerox Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the TWAIN Working Group nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @file CTWAINDS_Sample1.h
|
||||
* Reveals the main entry point for the DSM
|
||||
* @author TWAIN Working Group
|
||||
* @date April 2007
|
||||
*/
|
||||
|
||||
#ifndef __CTWAINDS_SAMPLE1_H__
|
||||
#define __CTWAINDS_SAMPLE1_H__
|
||||
|
||||
#include "CTWAINDS_FreeImage.h"
|
||||
|
||||
/**
|
||||
* The main entry point - defined in twain.h
|
||||
FAR PASCAL TW_UINT16 DS_Entry( pTW_IDENTITY _pOrigin,
|
||||
TW_UINT32 _DG,
|
||||
TW_UINT16 _DAT,
|
||||
TW_UINT16 _MSG,
|
||||
TW_MEMREF _pData);
|
||||
*/
|
||||
|
||||
#endif //__CTWAINDS_SAMPLE1_H__
|
288
CTiffWriter.cpp
288
CTiffWriter.cpp
|
@ -1,288 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright ?2007 TWAIN Working Group:
|
||||
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
|
||||
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
|
||||
* Ricoh Corporation, and Xerox Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the TWAIN Working Group nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @file CTiffWriter.cpp
|
||||
* Write an image to disk as a tiff file.
|
||||
* @author JFL Peripheral Solutions Inc.
|
||||
* @date October 2007
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "CTiffWriter.h"
|
||||
#include <sstream>
|
||||
|
||||
CTiffWriter::CTiffWriter(const string& _filename,
|
||||
const long int _width,
|
||||
const long int _height,
|
||||
const int _bitsPerPixel,
|
||||
const unsigned long int _bytesPerRow)
|
||||
{
|
||||
m_pImageStream = 0;
|
||||
m_nOffset = 0;
|
||||
m_filename = _filename;
|
||||
|
||||
m_ImageWidth.TagID = kTIFF_TAG_IMGWIDTH;
|
||||
m_ImageWidth.DataType = kTIFF_TY_LONG;
|
||||
m_ImageWidth.DataCount = 1;
|
||||
m_ImageWidth.DataOffset = _width;
|
||||
|
||||
m_ImageLength.TagID = kTIFF_TAG_IMGLENGTH;
|
||||
m_ImageLength.DataType = kTIFF_TY_LONG;
|
||||
m_ImageLength.DataCount = 1;
|
||||
m_ImageLength.DataOffset = _height;
|
||||
|
||||
m_BitsPerSample.TagID = kTIFF_TAG_BITSPERSAMPLE;
|
||||
m_BitsPerSample.DataType = kTIFF_TY_SHORT;
|
||||
m_BitsPerSample.DataCount = 1;
|
||||
|
||||
if(24 == _bitsPerPixel)
|
||||
{
|
||||
m_BitsPerSample.DataOffset = 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_BitsPerSample.DataOffset = _bitsPerPixel;
|
||||
}
|
||||
|
||||
|
||||
m_Compression.TagID = kTIFF_TAG_COMPRESSION;
|
||||
m_Compression.DataType = kTIFF_TY_SHORT;
|
||||
m_Compression.DataCount = 1;
|
||||
m_Compression.DataOffset = 1;
|
||||
|
||||
m_PhotometricInterp.TagID = kTIFF_TAG_PHOTOMETRICINT;
|
||||
m_PhotometricInterp.DataType = kTIFF_TY_SHORT;
|
||||
m_PhotometricInterp.DataCount = 1;
|
||||
|
||||
if(24 == _bitsPerPixel)
|
||||
{
|
||||
m_PhotometricInterp.DataOffset = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_PhotometricInterp.DataOffset = 1;
|
||||
}
|
||||
|
||||
// -there is only one strip that contains all the row data, and it starts right after the header.
|
||||
// -There are always 12 tags being written for each tiff.
|
||||
m_StripOffsets.TagID = kTIFF_TAG_STRIPOFFSETS;
|
||||
m_StripOffsets.DataType = kTIFF_TY_SHORT;
|
||||
m_StripOffsets.DataCount = 1;
|
||||
m_StripOffsets.DataOffset = getSizeofHeader();
|
||||
|
||||
m_SamplesPerPixel.TagID = kTIFF_TAG_SAMPLESPERPIXEL;
|
||||
m_SamplesPerPixel.DataType = kTIFF_TY_SHORT;
|
||||
|
||||
if(24 == _bitsPerPixel)
|
||||
{
|
||||
m_SamplesPerPixel.DataCount = 1;
|
||||
m_SamplesPerPixel.DataOffset = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_SamplesPerPixel.DataCount = 1;
|
||||
m_SamplesPerPixel.DataOffset = 1;
|
||||
}
|
||||
|
||||
m_RowsPerStrip.TagID = kTIFF_TAG_ROWSPERSTRIP;
|
||||
m_RowsPerStrip.DataType = kTIFF_TY_LONG;
|
||||
m_RowsPerStrip.DataCount = 1;
|
||||
m_RowsPerStrip.DataOffset = _height;
|
||||
|
||||
m_StripByteCounts.TagID = kTIFF_TAG_STRIPBYTECOUNTS;
|
||||
m_StripByteCounts.DataType = kTIFF_TY_LONG;
|
||||
m_StripByteCounts.DataCount = 1;
|
||||
m_StripByteCounts.DataOffset = _bytesPerRow * _height;
|
||||
|
||||
m_XResolution.TagID = kTIFF_TAG_XRESOLUTION;
|
||||
m_XResolution.DataType = kTIFF_TY_RATIONAL;
|
||||
m_XResolution.DataCount = 1;
|
||||
m_XResolution.DataOffset = m_StripOffsets.DataOffset - sizeof(DWORD)*4; // fixed offset from the end of the header
|
||||
setXResolution(100, 1);
|
||||
|
||||
m_YResolution.TagID = kTIFF_TAG_YRESOLUTION;
|
||||
m_YResolution.DataType = kTIFF_TY_RATIONAL;
|
||||
m_YResolution.DataCount = 1;
|
||||
m_YResolution.DataOffset = m_StripOffsets.DataOffset - sizeof(DWORD)*2; // fixed offset from the end of the header
|
||||
setYResolution(100, 1);
|
||||
|
||||
m_ResolutionUnit.TagID = kTIFF_TAG_RESOLUTIONUNIT;
|
||||
m_ResolutionUnit.DataType = kTIFF_TY_SHORT;
|
||||
m_ResolutionUnit.DataCount = 1;
|
||||
m_ResolutionUnit.DataOffset = 2;
|
||||
}
|
||||
|
||||
CTiffWriter::~CTiffWriter()
|
||||
{
|
||||
if(0 != m_pImageStream)
|
||||
{
|
||||
if(m_pImageStream->is_open())
|
||||
{
|
||||
m_pImageStream->close();
|
||||
}
|
||||
delete m_pImageStream;
|
||||
}
|
||||
}
|
||||
|
||||
void CTiffWriter::setImageWidth(const long int _v)
|
||||
{
|
||||
m_ImageWidth.DataOffset = _v;
|
||||
}
|
||||
|
||||
void CTiffWriter::setImageHeight(const long int _v)
|
||||
{
|
||||
m_ImageLength.DataOffset = _v;
|
||||
}
|
||||
|
||||
void CTiffWriter::setBitsPerSample(const int _v)
|
||||
{
|
||||
m_BitsPerSample.DataOffset = _v;
|
||||
}
|
||||
|
||||
void CTiffWriter::setCompression(const int _v)
|
||||
{
|
||||
m_Compression.DataOffset = _v;
|
||||
}
|
||||
|
||||
void CTiffWriter::setPhotometricInterp(const int _v)
|
||||
{
|
||||
m_PhotometricInterp.DataOffset = _v;
|
||||
}
|
||||
|
||||
void CTiffWriter::setSamplesPerPixel(const int _v)
|
||||
{
|
||||
m_SamplesPerPixel.DataOffset = _v;
|
||||
}
|
||||
|
||||
void CTiffWriter::setXResolution(const int _numerator, const int _denominator)
|
||||
{
|
||||
m_xres[0] = _numerator;
|
||||
m_xres[1] = _denominator;
|
||||
}
|
||||
|
||||
void CTiffWriter::setYResolution(const int _numerator, const int _denominator)
|
||||
{
|
||||
m_yres[0] = _numerator;
|
||||
m_yres[1] = _denominator;
|
||||
}
|
||||
|
||||
void CTiffWriter::setBytesPerRow(const int _v)
|
||||
{
|
||||
m_StripByteCounts.DataOffset = _v * m_ImageLength.DataOffset;
|
||||
}
|
||||
|
||||
void CTiffWriter::GetImageHeader(stringstream &Header)
|
||||
{
|
||||
// write the header
|
||||
TIFFIFH hdr = {0x4949, 0x002a, sizeof(TIFFIFH)};
|
||||
Header.write(reinterpret_cast<char*>(&hdr), sizeof(TIFFIFH));
|
||||
|
||||
// write the Tags immediately after the header
|
||||
WORD numTags = 12;
|
||||
Header.write(reinterpret_cast<char*>(&numTags), sizeof(numTags));
|
||||
|
||||
const int nsize = sizeof(TIFFTag);
|
||||
|
||||
Header.write(reinterpret_cast<char*>(&m_ImageWidth), nsize);
|
||||
Header.write(reinterpret_cast<char*>(&m_ImageLength), nsize);
|
||||
Header.write(reinterpret_cast<char*>(&m_BitsPerSample), nsize);
|
||||
Header.write(reinterpret_cast<char*>(&m_Compression), nsize);
|
||||
Header.write(reinterpret_cast<char*>(&m_PhotometricInterp), nsize);
|
||||
Header.write(reinterpret_cast<char*>(&m_StripOffsets), nsize);
|
||||
Header.write(reinterpret_cast<char*>(&m_SamplesPerPixel), nsize);
|
||||
Header.write(reinterpret_cast<char*>(&m_RowsPerStrip), nsize);
|
||||
Header.write(reinterpret_cast<char*>(&m_StripByteCounts), nsize);
|
||||
Header.write(reinterpret_cast<char*>(&m_XResolution), nsize);
|
||||
Header.write(reinterpret_cast<char*>(&m_YResolution), nsize);
|
||||
Header.write(reinterpret_cast<char*>(&m_ResolutionUnit), nsize);
|
||||
|
||||
// end the header by setting the next image offset to null
|
||||
DWORD end = 0;
|
||||
Header.write(reinterpret_cast<char*>(&end), sizeof(end));
|
||||
|
||||
// write the X and Y resolutions
|
||||
Header.write(reinterpret_cast<char*>(&m_xres), sizeof(DWORD)*2);
|
||||
|
||||
Header.write(reinterpret_cast<char*>(&m_yres), sizeof(DWORD)*2);
|
||||
}
|
||||
|
||||
bool CTiffWriter::writeImageHeader()
|
||||
{
|
||||
// create the out stream if not done so already
|
||||
if(0 == m_pImageStream)
|
||||
{
|
||||
m_pImageStream = new ofstream();
|
||||
}
|
||||
|
||||
// open the stream. If already open, reset it
|
||||
if(m_pImageStream->is_open())
|
||||
{
|
||||
m_pImageStream->seekp(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pImageStream->open(m_filename.c_str(), ios_base::out|ios_base::binary|ios_base::trunc);
|
||||
}
|
||||
stringstream Header;
|
||||
GetImageHeader(Header);
|
||||
Header.seekp(0, ios_base::end);
|
||||
m_nOffset =(int) Header.tellp();
|
||||
Header.seekg(0, ios_base::beg);
|
||||
char *pData = new char[m_nOffset];
|
||||
Header.read(pData,m_nOffset);
|
||||
m_pImageStream->write(pData,m_nOffset);
|
||||
delete []pData;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CTiffWriter::WriteTIFFData(char *_pData, DWORD _nCount)
|
||||
{
|
||||
bool bret = false;
|
||||
|
||||
if(0 != m_pImageStream &&
|
||||
m_pImageStream->good())
|
||||
{
|
||||
m_pImageStream->seekp(m_nOffset);
|
||||
m_pImageStream->write(_pData, _nCount);
|
||||
m_nOffset += _nCount;
|
||||
bret = true;
|
||||
}
|
||||
|
||||
return bret;
|
||||
}
|
||||
|
||||
unsigned int CTiffWriter::getSizeofHeader()
|
||||
{
|
||||
// Header is as follows:
|
||||
// TIFFIFH + Num. of Tags + each tag + Xres Data (2 dwords) + Yres Data (2 dwords) + Next Image offset (1 dword)
|
||||
return sizeof(TIFFIFH)+sizeof(WORD)+sizeof(TIFFTag)*12+sizeof(DWORD)*5;
|
||||
}
|
240
CTiffWriter.h
240
CTiffWriter.h
|
@ -1,240 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright ?2007 TWAIN Working Group:
|
||||
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
|
||||
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
|
||||
* Ricoh Corporation, and Xerox Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the TWAIN Working Group nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @file CTiffWriter.h
|
||||
* Write an image to disk as a tiff file.
|
||||
* @author TWAIN Working Group
|
||||
* @date October 2007
|
||||
*/
|
||||
|
||||
#ifndef __TIFFWRITER_H__
|
||||
#define __TIFFWRITER_H__
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <windows.h>
|
||||
#else
|
||||
typedef uint16_t WORD;
|
||||
typedef uint32_t DWORD;
|
||||
#endif // _MSC_VER
|
||||
|
||||
#define TIFF_UNCOMPRESSED 1 /**< TIFF compression types */
|
||||
#define TIFF_CCITTGROUP3 3
|
||||
#define TIFF_CCITTGROUP4 4
|
||||
|
||||
// TIFF types
|
||||
#define kTIFF_TY_BYTE 1 /**< 8-bit unsigned int */
|
||||
#define kTIFF_TY_ASCII 2 /**< 8-bit byte that contains a 7-bit ASCII code; last byte must be binary 0 (NULL) */
|
||||
#define kTIFF_TY_SHORT 3 /**< 16-bit (2-byte) unsigned int */
|
||||
#define kTIFF_TY_LONG 4 /**< 32-bit (4-byte) unsigned int */
|
||||
#define kTIFF_TY_RATIONAL 5 /**< two LONGs; the first is the numerator of a fraction; the second, the denominator */
|
||||
|
||||
// these field types where introduced in TIFF 6.0
|
||||
#define kTIFF_TY_SBYTE 6 /**< 8-bit signed int */
|
||||
#define kTIFF_TY_UNDEFINED 7 /**< 8-bit byte that may contain anything, depending on the definition of the field */
|
||||
#define kTIFF_TY_SSHORT 8 /**< 16-bit (2-byte) signed int */
|
||||
#define kTIFF_TY_SLONG 9 /**< 32-bit (4-byte) signed int */
|
||||
#define kTIFF_TY_SRATIONAL 10 /**< two SLONG's; first is numerator of fraction, second is denominator */
|
||||
#define kTIFF_TY_FLOAT 11 /**< single precision (4-byte) IEEE format */
|
||||
#define kTIFF_TY_DOUBLE 12 /**< double precision (8-byte) IEEE format */
|
||||
|
||||
// TIFF Tags
|
||||
#define kTIFF_TAG_IMGWIDTH 0x0100 /**< Image width, short or long */
|
||||
#define kTIFF_TAG_IMGLENGTH 0x0101 /**< Image length, short or long */
|
||||
#define kTIFF_TAG_BITSPERSAMPLE 0x0102 /**< BitsPerSample, short */
|
||||
#define kTIFF_TAG_COMPRESSION 0x0103 /**< Compression, short */
|
||||
#define kTIFF_TAG_PHOTOMETRICINT 0x0106 /**< PhotometricInterpretation, short */
|
||||
#define kTIFF_TAG_STRIPOFFSETS 0x0111 /**< StripOffsets, short or long */
|
||||
#define kTIFF_TAG_SAMPLESPERPIXEL 0x0115 /**< Samples per pixel, short */
|
||||
#define kTIFF_TAG_ROWSPERSTRIP 0x0116 /**< RowsPerStrip, short or long */
|
||||
#define kTIFF_TAG_STRIPBYTECOUNTS 0x0117 /**< StripByteCounts, short or long */
|
||||
#define kTIFF_TAG_XRESOLUTION 0x011A /**< X Resolution, rational */
|
||||
#define kTIFF_TAG_YRESOLUTION 0x011B /**< Y Resolution, rational */
|
||||
#define kTIFF_TAG_RESOLUTIONUNIT 0x0128 /**< Resolution unit, short */
|
||||
#define kTIFF_TAG_COLORMAP 0x0140 /**< ColorMap, short, RGB order, black = 0,0,0, TWAIN supports max 256 entry pallette */
|
||||
|
||||
/**
|
||||
* TIFF Image File Header
|
||||
*/
|
||||
struct TIFFIFH
|
||||
{
|
||||
WORD Identifier;
|
||||
WORD Version;
|
||||
DWORD IFDOffset;
|
||||
};
|
||||
|
||||
/**
|
||||
* A TIFF Tag
|
||||
* If the actual value of the tag is less then a DWORD, then offset will contain
|
||||
* it, else offset is truly an offset to the value.
|
||||
*/
|
||||
struct TIFFTag
|
||||
{
|
||||
WORD TagID;
|
||||
WORD DataType;
|
||||
DWORD DataCount;
|
||||
DWORD DataOffset;
|
||||
};
|
||||
|
||||
/**
|
||||
* This is a class that will progressively write a TIFF image to a file.
|
||||
*/
|
||||
class CTiffWriter
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor for CTiffWriter. This is a class that will progressively
|
||||
* write a TIFF image to a file.
|
||||
* @param[in] _filename name of file to write to.
|
||||
* @param[in] _width image width.
|
||||
* @param[in] _height image height.
|
||||
* @param[in] _bitsPerPixel number of bits per each pixel.
|
||||
* @param[in] _bytesPerRow number of bytes per row of data.
|
||||
*/
|
||||
CTiffWriter(const string& _filename,
|
||||
const long int _width,
|
||||
const long int _height,
|
||||
const int _bitsPerPixel,
|
||||
const unsigned long int _bytesPerRow);
|
||||
|
||||
/**
|
||||
* Deconstructor for CTiffWriter.
|
||||
*/
|
||||
virtual ~CTiffWriter();
|
||||
|
||||
/**
|
||||
* Set the width of the image.
|
||||
* @param[in] _v the new image width
|
||||
*/
|
||||
void setImageWidth(const long int _v);
|
||||
|
||||
/**
|
||||
* Set the height of the image.
|
||||
* @param[in] _v the new image height
|
||||
*/
|
||||
void setImageHeight(const long int _v);
|
||||
|
||||
/**
|
||||
* Set the bits per sample of the image.
|
||||
* @param[in] _v the new bits per sample
|
||||
*/
|
||||
void setBitsPerSample(const int _v);
|
||||
|
||||
/**
|
||||
* Set the compression method to use.
|
||||
* @param[in] _v the new compression method
|
||||
*/
|
||||
void setCompression(const int _v);
|
||||
|
||||
/**
|
||||
* Set the Photometric Interpretation.
|
||||
* @param[in] _v the new Photometric Interpretation
|
||||
*/
|
||||
void setPhotometricInterp(const int _v);
|
||||
|
||||
/**
|
||||
* Set the number of samples per pixel of the image.
|
||||
* @param[in] _v the new samples per pixel
|
||||
*/
|
||||
void setSamplesPerPixel(const int _v);
|
||||
|
||||
/**
|
||||
* Set the x resolution of the image. Using type kTIFF_TY_RATIONAL (fraction)
|
||||
* @param[in] _numerator the numerator part of the fraction
|
||||
* @param[in] _denominator the denominator part of the fraction
|
||||
*/
|
||||
void setXResolution(const int _numerator, const int _denominator);
|
||||
|
||||
/**
|
||||
* Set the y resolution of the image. Using type kTIFF_TY_RATIONAL (fraction)
|
||||
* @param[in] _numerator the numerator part of the fraction
|
||||
* @param[in] _denominator the denominator part of the fraction
|
||||
*/
|
||||
void setYResolution(const int _numerator, const int _denominator);
|
||||
|
||||
/**
|
||||
* Set the Bytes per row of the image.
|
||||
* @param[in] _v the new bytes per row
|
||||
*/
|
||||
void setBytesPerRow(const int _v);
|
||||
|
||||
|
||||
/**
|
||||
* Write the prepaired image header to the file.
|
||||
* @return true for succes
|
||||
*/
|
||||
bool writeImageHeader();
|
||||
|
||||
/**
|
||||
* Write the data for the image to the file.
|
||||
* @param[in] _pData pointer to the image data
|
||||
* @param[in] _nCount number of bytes to write
|
||||
* @return true for success
|
||||
*/
|
||||
bool WriteTIFFData(char *_pData, DWORD _nCount);
|
||||
|
||||
/**
|
||||
* Return the size of the TIFF header for the image file.
|
||||
* @return the size of the header
|
||||
*/
|
||||
unsigned int getSizeofHeader();
|
||||
|
||||
void GetImageHeader(stringstream &Header);
|
||||
|
||||
protected:
|
||||
string m_filename; /**< Name and or path of file */
|
||||
int m_nOffset; /**< Current offset into file */
|
||||
|
||||
DWORD m_xres[2]; /**< The X resolution of the image */
|
||||
DWORD m_yres[2]; /**< The Y resolution of the image */
|
||||
|
||||
TIFFTag m_ImageWidth; /**< The image width in pixels */
|
||||
TIFFTag m_ImageLength; /**< The image height in pixels */
|
||||
TIFFTag m_BitsPerSample; /**< The number of Bits per sample */
|
||||
TIFFTag m_Compression; /**< The compression method to use */
|
||||
TIFFTag m_PhotometricInterp; /**< The Photometric Interpretation to use */
|
||||
TIFFTag m_StripOffsets; /**< The strip offset, where image data starts */
|
||||
TIFFTag m_SamplesPerPixel; /**< The number of channels (RGB, G, )*/
|
||||
TIFFTag m_RowsPerStrip; /**< The number of rows that make up each strip */
|
||||
TIFFTag m_StripByteCounts; /**< The size of each strip of image data */
|
||||
TIFFTag m_XResolution; /**< The offset to the X resolution */
|
||||
TIFFTag m_YResolution; /**< The offset to the Y resolution */
|
||||
TIFFTag m_ResolutionUnit; /**< The units of the Resolution */
|
||||
|
||||
ofstream* m_pImageStream; /**< The output stream to write the file to */
|
||||
};
|
||||
|
||||
#endif // __TIFFWRITER_H__
|
126
CTwainMutex.cpp
126
CTwainMutex.cpp
|
@ -1,126 +0,0 @@
|
|||
#include "stdafx.h"
|
||||
#include "CTwainMutex.h"
|
||||
|
||||
CTwainMutex::CTwainMutex(void)
|
||||
{
|
||||
m_hTwainMutex=NULL;
|
||||
m_bInited=FALSE;
|
||||
memset(m_sTwainMutex,0,sizeof(m_sTwainMutex));
|
||||
}
|
||||
|
||||
CTwainMutex::~CTwainMutex(void)
|
||||
{
|
||||
|
||||
if (m_hTwainMutex!=NULL)
|
||||
{
|
||||
CloseHandle(m_hTwainMutex);
|
||||
m_hTwainMutex=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL CTwainMutex::CreatTwainMutex(TCHAR *str_Mutex)
|
||||
{
|
||||
TCHAR mutexName[MAX_PATH]={0};
|
||||
DWORD error_code=0;
|
||||
HANDLE hMutex=NULL;
|
||||
BOOL b_ret=FALSE;
|
||||
if (m_hTwainMutex!=NULL)
|
||||
{
|
||||
return b_ret;
|
||||
}
|
||||
|
||||
_tcscpy(mutexName,str_Mutex);
|
||||
|
||||
hMutex=CreateMutex(NULL,FALSE,mutexName);
|
||||
if (hMutex!=NULL)
|
||||
{
|
||||
error_code=GetLastError();
|
||||
if (error_code==ERROR_ALREADY_EXISTS||error_code==ERROR_ACCESS_DENIED)
|
||||
{
|
||||
MessageBox(NULL,"设备已被其他程序占用,请关闭占用程序之后再重试!","提示",MB_OK|MB_ICONWARNING);
|
||||
b_ret=CloseHandle(hMutex);
|
||||
if (!b_ret)
|
||||
{
|
||||
MessageBox(NULL, TEXT("资源释放异常"), 0, MB_ICONWARNING);
|
||||
}
|
||||
hMutex=NULL;
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_hTwainMutex!=NULL)
|
||||
{
|
||||
b_ret=CloseHandle(m_hTwainMutex);
|
||||
if (!b_ret)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
m_hTwainMutex=NULL;
|
||||
}
|
||||
m_hTwainMutex=hMutex;
|
||||
b_ret=TRUE;
|
||||
}
|
||||
return b_ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox(NULL, TEXT("程序初始化错误"), 0, MB_ICONWARNING);
|
||||
}
|
||||
return b_ret;
|
||||
}
|
||||
|
||||
BOOL CTwainMutex::CheckExistTwainMutex(TCHAR* str_Mutex)
|
||||
{
|
||||
TCHAR szMutexName[MAX_PATH] = {0};
|
||||
DWORD error_code = 0;
|
||||
BOOL b_ret = FALSE;
|
||||
HANDLE hMutex = NULL;
|
||||
|
||||
if (m_hTwainMutex!=NULL)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
_tcscpy(szMutexName,str_Mutex);
|
||||
hMutex=CreateMutex(NULL,FALSE,szMutexName);
|
||||
if (hMutex!=NULL)
|
||||
{
|
||||
error_code=GetLastError();
|
||||
if (error_code==ERROR_ALREADY_EXISTS||error_code==ERROR_ACCESS_DENIED)
|
||||
{
|
||||
b_ret=CloseHandle(hMutex);
|
||||
hMutex=NULL;
|
||||
b_ret=TRUE;
|
||||
return b_ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
CloseHandle(hMutex);
|
||||
b_ret=FALSE;
|
||||
return b_ret;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
return b_ret;
|
||||
}
|
||||
|
||||
BOOL CTwainMutex::CloseTwainMutex()
|
||||
{
|
||||
BOOL b_ret=FALSE;
|
||||
if (m_hTwainMutex!=NULL)
|
||||
{
|
||||
b_ret=CloseHandle(m_hTwainMutex);
|
||||
|
||||
if (!b_ret)
|
||||
{
|
||||
MessageBox(NULL, TEXT("释放资源失败"), 0, MB_ICONWARNING);
|
||||
}
|
||||
m_hTwainMutex=NULL;
|
||||
return b_ret;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#include "stdafx.h"
|
||||
|
||||
class CTwainMutex
|
||||
{
|
||||
public:
|
||||
CTwainMutex(void);
|
||||
~CTwainMutex(void);
|
||||
public:
|
||||
BOOL CreatTwainMutex(TCHAR *str_Mutex);
|
||||
BOOL CheckExistTwainMutex(TCHAR *str_Mutex);
|
||||
BOOL CloseTwainMutex();
|
||||
private:
|
||||
HANDLE m_hTwainMutex;
|
||||
TCHAR m_sTwainMutex[MAX_PATH];
|
||||
BOOL m_bInited;
|
||||
};
|
|
@ -1,193 +0,0 @@
|
|||
#include "stdafx.h"
|
||||
#include "CUSBHotPlugged.h"
|
||||
|
||||
CUSBHotPlugged::CUSBHotPlugged()
|
||||
{
|
||||
//usbHotPlugged=this;
|
||||
isconnected=true;
|
||||
tHandle=NULL;
|
||||
hWnd=NULL;
|
||||
initThread();
|
||||
}
|
||||
|
||||
CUSBHotPlugged::~CUSBHotPlugged()
|
||||
{
|
||||
if (tHandle!=NULL)
|
||||
{
|
||||
PostThreadMessage(iThread,THRD_MESSAGE_EXIT,0,0);
|
||||
WaitForSingleObject(tHandle,1000);
|
||||
CloseHandle(tHandle);
|
||||
}
|
||||
if (hWnd!=NULL&&IsWindow(hWnd))
|
||||
{
|
||||
//PostQuitMessage(0);
|
||||
//SendMessage(hWnd,WM_CLOSE,);
|
||||
BOOL ret= UnregisterClass(CLASS_NAME,GetModuleHandle(NULL));
|
||||
BOOL ret1=DestroyWindow(hWnd);
|
||||
hWnd=NULL;
|
||||
int aa=-1;
|
||||
}
|
||||
}
|
||||
|
||||
bool CUSBHotPlugged::getIsConnected()
|
||||
{
|
||||
return isconnected;
|
||||
}
|
||||
|
||||
void CUSBHotPlugged::UpdateDevice(PDEV_BROADCAST_DEVICEINTERFACE pDevInf, WPARAM wParam)
|
||||
{
|
||||
CString szDevId = pDevInf->dbcc_name + 4;
|
||||
int idx = szDevId.ReverseFind(_T('#'));
|
||||
szDevId.Truncate(idx);
|
||||
szDevId.Replace(_T('#'), _T('\\'));
|
||||
szDevId.MakeUpper();
|
||||
|
||||
CString szClass;
|
||||
idx = szDevId.Find(_T('\\'));
|
||||
szClass = szDevId.Left(idx);
|
||||
|
||||
CString szTmp;
|
||||
if (DBT_DEVICEARRIVAL == wParam) \
|
||||
szTmp.Format(_T("Adding %s\r\n"), szDevId.GetBuffer());
|
||||
else
|
||||
szTmp.Format(_T("Removing %s\r\n"), szDevId.GetBuffer());
|
||||
|
||||
_tprintf(szTmp);
|
||||
}
|
||||
|
||||
LRESULT CUSBHotPlugged::DeviceChange(UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (DBT_DEVICEARRIVAL == wParam || DBT_DEVICEREMOVECOMPLETE == wParam)
|
||||
{
|
||||
PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR)lParam;
|
||||
PDEV_BROADCAST_DEVICEINTERFACE pDevInf;
|
||||
PDEV_BROADCAST_HANDLE pDevHnd;
|
||||
PDEV_BROADCAST_OEM pDevOem;
|
||||
PDEV_BROADCAST_PORT pDevPort;
|
||||
PDEV_BROADCAST_VOLUME pDevVolume;
|
||||
switch (pHdr->dbch_devicetype)
|
||||
{
|
||||
case DBT_DEVTYP_DEVICEINTERFACE:
|
||||
pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)pHdr;
|
||||
CUSBHotPlugged::UpdateDevice(pDevInf, wParam);
|
||||
break;
|
||||
|
||||
case DBT_DEVTYP_HANDLE:
|
||||
pDevHnd = (PDEV_BROADCAST_HANDLE)pHdr;
|
||||
break;
|
||||
|
||||
case DBT_DEVTYP_OEM:
|
||||
pDevOem = (PDEV_BROADCAST_OEM)pHdr;
|
||||
break;
|
||||
|
||||
case DBT_DEVTYP_PORT:
|
||||
pDevPort = (PDEV_BROADCAST_PORT)pHdr;
|
||||
break;
|
||||
|
||||
case DBT_DEVTYP_VOLUME:
|
||||
pDevVolume = (PDEV_BROADCAST_VOLUME)pHdr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK CUSBHotPlugged::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
case WM_PAINT:
|
||||
break;
|
||||
case WM_SIZE:
|
||||
break;
|
||||
case WM_DEVICECHANGE:
|
||||
return DeviceChange(message, wParam, lParam);
|
||||
}
|
||||
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
bool CUSBHotPlugged::CreateMessageOnlyWindow()
|
||||
{
|
||||
hWnd = CreateWindowEx(0, CLASS_NAME, _T(""), WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
NULL, // Parent window
|
||||
NULL, // Menu
|
||||
GetModuleHandle(NULL), // Instance handle
|
||||
NULL // Additional application data
|
||||
);
|
||||
|
||||
return hWnd != NULL;
|
||||
}
|
||||
|
||||
void CUSBHotPlugged::RegisterDeviceNotify()
|
||||
{
|
||||
HDEVNOTIFY hDevNotify;
|
||||
for (int i = 0; i < sizeof(GUID_DEVINTERFACE_LIST) / sizeof(GUID); i++)
|
||||
{
|
||||
DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
|
||||
ZeroMemory(&NotificationFilter, sizeof(NotificationFilter));
|
||||
NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
|
||||
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
|
||||
NotificationFilter.dbcc_classguid = GUID_DEVINTERFACE_LIST[i];
|
||||
hDevNotify = RegisterDeviceNotification(hWnd, &NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE);
|
||||
}
|
||||
}
|
||||
|
||||
DWORD CUSBHotPlugged::ThrdFunc(LPVOID lpParam)
|
||||
{
|
||||
|
||||
if (0 ==MyRegisterClass())
|
||||
return -1;
|
||||
|
||||
if (!CreateMessageOnlyWindow())
|
||||
return -1;
|
||||
|
||||
RegisterDeviceNotify();
|
||||
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
{
|
||||
if (msg.message == THRD_MESSAGE_EXIT)
|
||||
{
|
||||
//cout << "worker receive the exiting Message..." << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CUSBHotPlugged::initThread()
|
||||
{
|
||||
int ret=-1;
|
||||
if (tHandle==NULL)
|
||||
{
|
||||
tHandle=CreateThread(NULL, sizeof(CUSBHotPlugged),_usbhotPlugDetect, (LPVOID)this, 0L, &iThread);
|
||||
if (tHandle==NULL)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
ret=0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
DWORD WINAPI CUSBHotPlugged::_usbhotPlugDetect(LPVOID lp_param)
|
||||
{
|
||||
CUSBHotPlugged* This=(CUSBHotPlugged*) lp_param;
|
||||
return This->ThrdFunc(lp_param);
|
||||
}
|
||||
|
||||
ATOM CUSBHotPlugged::MyRegisterClass()
|
||||
{
|
||||
//CUSBHotPlugged* This=(CUSBHotPlugged*) lp_param;
|
||||
WNDCLASS wc = { 0 };
|
||||
wc.lpfnWndProc =WndProc;
|
||||
wc.hInstance = GetModuleHandle(NULL);
|
||||
wc.lpszClassName = CLASS_NAME;
|
||||
return RegisterClass(&wc);
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
#include "stdafx.h"
|
||||
#include <Windows.h>
|
||||
#include <tchar.h>
|
||||
#include <Dbt.h>
|
||||
#include <setupapi.h>
|
||||
#include <iostream>
|
||||
#include <atlstr.h>
|
||||
|
||||
#pragma comment (lib, "Kernel32.lib")
|
||||
#pragma comment (lib, "User32.lib")
|
||||
|
||||
#define THRD_MESSAGE_EXIT WM_USER + 1
|
||||
const _TCHAR CLASS_NAME[] = _T("Sample Window Class");
|
||||
|
||||
static const GUID GUID_DEVINTERFACE_LIST[] =
|
||||
{
|
||||
// GUID_DEVINTERFACE_USB_DEVICE
|
||||
{ 0xA5DCBF10, 0x6530, 0x11D2, { 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED } },
|
||||
// GUID_DEVINTERFACE_DISK
|
||||
{ 0x53f56307, 0xb6bf, 0x11d0, { 0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b } },
|
||||
// GUID_DEVINTERFACE_HID,
|
||||
{ 0x4D1E55B2, 0xF16F, 0x11CF, { 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } },
|
||||
// GUID_NDIS_LAN_CLASS
|
||||
{ 0xad498944, 0x762f, 0x11d0, { 0x8d, 0xcb, 0x00, 0xc0, 0x4f, 0xc3, 0x35, 0x8c } },
|
||||
// GUID_DEVINTERFACE_COMPORT
|
||||
{ 0x86e0d1e0, 0x8089, 0x11d0, { 0x9c, 0xe4, 0x08, 0x00, 0x3e, 0x30, 0x1f, 0x73 } },
|
||||
// GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR
|
||||
{ 0x4D36E978, 0xE325, 0x11CE, { 0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18 } },
|
||||
// GUID_DEVINTERFACE_PARALLEL
|
||||
{ 0x97F76EF0, 0xF883, 0x11D0, { 0xAF, 0x1F, 0x00, 0x00, 0xF8, 0x00, 0x84, 0x5C } },
|
||||
// GUID_DEVINTERFACE_PARCLASS
|
||||
{ 0x811FC6A5, 0xF728, 0x11D0, { 0xA5, 0x37, 0x00, 0x00, 0xF8, 0x75, 0x3E, 0xD1 } }
|
||||
};
|
||||
|
||||
class CUSBHotPlugged
|
||||
{
|
||||
public:
|
||||
CUSBHotPlugged();
|
||||
~CUSBHotPlugged();
|
||||
bool getIsConnected();
|
||||
protected:
|
||||
static void UpdateDevice(PDEV_BROADCAST_DEVICEINTERFACE pDevInf, WPARAM wParam);
|
||||
static LRESULT DeviceChange(UINT message, WPARAM wParam, LPARAM lParam);
|
||||
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
bool CreateMessageOnlyWindow();
|
||||
void RegisterDeviceNotify();
|
||||
DWORD ThrdFunc(LPVOID lpParam);
|
||||
int initThread();
|
||||
static DWORD WINAPI _usbhotPlugDetect(LPVOID lp_param);
|
||||
ATOM MyRegisterClass();
|
||||
private:
|
||||
bool isconnected;
|
||||
HANDLE tHandle;
|
||||
DWORD iThread;
|
||||
HWND hWnd;
|
||||
//CUSBHotPlugged* usbHotPlugged;
|
||||
};
|
272
Common.h
272
Common.h
|
@ -1,272 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright © 2007 TWAIN Working Group:
|
||||
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
|
||||
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
|
||||
* Ricoh Corporation, and Xerox Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the TWAIN Working Group nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @file Common.h
|
||||
* Common defines and typedefs used by the DS, App, and scanner
|
||||
* @author TWAIN Working Group
|
||||
* @date April 2007
|
||||
*/
|
||||
|
||||
#ifndef __COMMON_H__
|
||||
#define __COMMON_H__
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
|
||||
#define TWNDS_OS_WIN
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#define TWNDS_OS_APPLE
|
||||
#endif
|
||||
|
||||
#include "twain.h"
|
||||
|
||||
#ifdef TWH_CMP_GNU
|
||||
#if !(defined(TWNDS_OS_WIN) || defined(TWNDS_OS_APPLE))
|
||||
#define TWNDS_OS_LINUX
|
||||
#endif
|
||||
#include <wchar.h>
|
||||
#include <stdarg.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* These headers are available on all platforms...
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
/**
|
||||
* First off, figure out what compiler we're running and on which
|
||||
* platform we think we're running it. We assume that you're building
|
||||
* on the same platform you intend to run, so if you are cross compiling
|
||||
* you will likely have a bit of work to do here...
|
||||
*/
|
||||
|
||||
/**
|
||||
* Compilers we support...
|
||||
*/
|
||||
#define TWNDS_CMP_VISUALCPP 0x1001 // Preferably 2005+
|
||||
#define TWNDS_CMP_GNUGPP 0x1002 // Preferably v4.x+
|
||||
#define TWNDS_CMP_XCODE 0x1003 // Xcode
|
||||
|
||||
/**
|
||||
* If the user defines TWNDS_CMP in their make file or project,
|
||||
* then we'll assume they want to take responsibility for picking
|
||||
* how we'll build the system. At this point it seems like the
|
||||
* compiler definition is used to select which native library calls
|
||||
* we're dealing with, while the os definition is more about
|
||||
* where we'll expect to find stuff on the running system, like
|
||||
* directories...
|
||||
*/
|
||||
#ifndef TWNDS_CMP
|
||||
|
||||
// GNU g++
|
||||
#if defined(TWH_CMP_GNU) || defined(TWH_CMP_XCODE)
|
||||
#define TWNDS_CMP TWNDS_CMP_GNUGPP
|
||||
#define TWNDS_CMP_VERSION __GNUC__
|
||||
|
||||
#define kTWAIN_DSM_DIR "/usr/local/lib/"
|
||||
|
||||
// Visual Studio C++
|
||||
#elif defined(TWH_CMP_MSC)
|
||||
#define TWNDS_CMP TWNDS_CMP_VISUALCPP
|
||||
#define TWNDS_CMP_VERSION _MSC_VER
|
||||
// Not neccessary it is in Windows path
|
||||
#define kTWAIN_DSM_DIR ""
|
||||
|
||||
// Xcode
|
||||
#elif defined (TWH_CMP_XCODE)
|
||||
#define TWNDS_CMP TWNDS_CMP_XCODE
|
||||
#define TWNDS_CMP_VERSION
|
||||
|
||||
// ruh-roh...
|
||||
#else
|
||||
#error Sorry, we don't recognize this system...
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @def LOADLIBRARY(lib)
|
||||
* Call system loadibrary function. OS abstraction macro that tries to load a library.
|
||||
* @param lib path and name of library
|
||||
*
|
||||
* @def LOADFUNCTION(lib, func)
|
||||
* Call system GetProcAddress function. OS abstraction macro that tries to locate the addess of a funtion name.
|
||||
* @param lib path and name of library
|
||||
* @param func name of the funtion
|
||||
*
|
||||
* @def UNLOADLIBRARY(lib)
|
||||
* Call system FreeLibrary function. OS abstraction macro that tries to release the library.
|
||||
* @param lib library modual to unload
|
||||
*
|
||||
* @def UNLINK
|
||||
* OS abstraction macro that calls system _unlink function.
|
||||
*
|
||||
* @def READ
|
||||
* OS abstraction macro that calls system _read function.
|
||||
*
|
||||
* @def CLOSE
|
||||
* OS abstraction macro that calls system _close function.
|
||||
*
|
||||
* @def SNPRINTF
|
||||
* OS abstraction macro that calls system _snprintf function.
|
||||
*
|
||||
*/
|
||||
|
||||
#if (TWNDS_CMP == TWNDS_CMP_VISUALCPP)
|
||||
//#include "stdafx.h"
|
||||
#define DllExport __declspec( dllexport )
|
||||
#define LOADLIBRARY(lib) LoadLibraryA(lib)
|
||||
#define LOADFUNCTION(lib, func) GetProcAddress(lib, func)
|
||||
#define UNLOADLIBRARY(lib) FreeLibrary(lib)
|
||||
#define UNLINK _unlink
|
||||
#define READ _read
|
||||
#define CLOSE _close
|
||||
#define FILE_EXISTS(FILE_NAME) ((0xFFFFFFFF==GetFileAttributes(FILE_NAME))?FALSE:TRUE)
|
||||
#define PATH_SEPERATOR '\\'
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX _MAX_PATH
|
||||
#endif
|
||||
|
||||
#if (TWNDS_CMP_VERSION >= 1400)
|
||||
#define SNPRINTF _snprintf_s
|
||||
#define SSCANF sscanf_s
|
||||
#define FOPEN(pf,name,mode) (void)fopen_s(&pf,name,mode)
|
||||
#define _OPEN(pf,name,mode,share,perm) (void)_sopen_s(&pf,name,mode,share,perm)
|
||||
#else
|
||||
#define SSCANF sscanf
|
||||
#define SNPRINTF _snprintf
|
||||
#define FOPEN(pf,name,mode) pf=fopen(name,mode)
|
||||
#define _OPEN(pf,name,mode,share,perm) pf = _open(name,mode,share)
|
||||
#endif
|
||||
#define MAX(a, b) max(a,b)
|
||||
#define MIN(a, b) min(a,b)
|
||||
|
||||
#elif (TWNDS_CMP == TWNDS_CMP_GNUGPP)
|
||||
#define DllExport
|
||||
#define LOADLIBRARY(lib) dlopen(lib, RTLD_NOW)
|
||||
#define LOADFUNCTION(lib, func) dlsym(lib, func)
|
||||
#define UNLOADLIBRARY(lib) dlclose(lib)
|
||||
#define UNLINK unlink
|
||||
#define kTWAIN_DSM_DLL_NAME "libtwaindsm.so"
|
||||
#define READ read
|
||||
#define CLOSE close
|
||||
#define PATH_SEPERATOR '/'
|
||||
#define SNPRINTF snprintf
|
||||
#define SSCANF sscanf
|
||||
typedef void * HMODULE;
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define FILE_EXISTS(FILE_NAME) ((0 == access(FILE_NAME, R_OK))?TRUE:FALSE)
|
||||
#define FOPEN(pf,name,mode) (pf=fopen(name,mode))
|
||||
|
||||
#if !defined(TRUE)
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#include <inttypes.h>
|
||||
typedef uint16_t WORD;
|
||||
typedef uint32_t DWORD;
|
||||
|
||||
#else
|
||||
#error Sorry, we don't recognize this system...
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* We want to use secure string functions whenever possible, if g++
|
||||
* every includes a set I think it would be excellent to switch over
|
||||
* to it, but at least with Windows using them we stand a better
|
||||
* chance of finding boo-boos...
|
||||
*/
|
||||
#if (TWNDS_CMP == TWNDS_CMP_VISUALCPP) && (TWNDS_CMP_VERSION >= 1400)
|
||||
#define SSTRCPY(d,z,s) strncpy_s(d,z,s,_TRUNCATE)
|
||||
#define SSTRCAT(d,z,s) strncat_s(d,z,s,_TRUNCATE)
|
||||
#define SSTRNCPY(d,z,s,m) strncpy_s(d,z,s,m)
|
||||
#define SGETENV(d,z,n) ::GetEnvironmentVariable(n,d,z)
|
||||
inline int SSNPRINTF(char *d, size_t z, size_t c, const char *f,...)
|
||||
{
|
||||
int result;
|
||||
va_list valist;
|
||||
va_start(valist,f);
|
||||
result = _vsnprintf_s(d,z,c,f,valist);
|
||||
va_end(valist);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* These functions are insecure, but everybody has them, so we
|
||||
* don't need an else/error section like we use everywhere else...
|
||||
*/
|
||||
#else
|
||||
#define SSTRCPY(d,z,s) strcpy(d,s)
|
||||
#define SSTRCAT(d,z,s) strcat(d,s)
|
||||
#define SSTRNCPY(d,z,s,m) strncpy(d,s,m)
|
||||
#define SGETENV(d,z,n) strcpy(d,getenv(n)?getenv(n):"")
|
||||
inline int SSNPRINTF(char *d, size_t, size_t c, const char *f,...)
|
||||
{
|
||||
int result;
|
||||
va_list valist;
|
||||
va_start(valist,f);
|
||||
#if (TWNDS_CMP == TWNDS_CMP_VISUALCPP)
|
||||
result = _vsnprintf(d,c,f,valist);
|
||||
#elif (TWNDS_CMP == TWNDS_CMP_GNUGPP)
|
||||
result = vsnprintf(d,c,f,valist);
|
||||
#else
|
||||
#error Sorry, we don't recognize this system...
|
||||
#endif
|
||||
va_end(valist);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Determine the number of bytes needed for one line.
|
||||
*/
|
||||
#define BYTES_PERLINE(width, bpp) ((((int)(width)*(bpp))+7)/8)
|
||||
|
||||
/**
|
||||
* Determine the number of bytes needed rouned up to 4 byte alignment.
|
||||
*/
|
||||
#define BYTES_PERLINE_ALIGN4(width, bpp) (((((int)(width)*(bpp))+31)/32)*4)
|
||||
|
||||
|
||||
#endif // __COMMON_H__
|
||||
|
155
CommonDS.cpp
155
CommonDS.cpp
|
@ -1,155 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright ?2007 TWAIN Working Group:
|
||||
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
|
||||
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
|
||||
* Ricoh Corporation, and Xerox Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the TWAIN Working Group nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @file CommonDS.cpp
|
||||
* Utilities functions used by TWAIN Data Sources
|
||||
*
|
||||
* @author TWAIN Working Group
|
||||
* @date October 2007
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
#include "CommonDS.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
float ConvertUnits(float val, int fromUnits, int toUnits, float resolution)
|
||||
{
|
||||
double result = val; //assume we don't have to convert
|
||||
|
||||
if( fromUnits != toUnits ) //if we do have to convert
|
||||
{
|
||||
//see what we're converting from, and convert to inches
|
||||
switch(fromUnits)
|
||||
{
|
||||
case TWUN_INCHES:
|
||||
// nothing to do
|
||||
break;
|
||||
|
||||
case TWUN_CENTIMETERS:
|
||||
result = val / 2.54;
|
||||
break;
|
||||
|
||||
case TWUN_PICAS:
|
||||
result = val / 6.0;
|
||||
break;
|
||||
|
||||
case TWUN_POINTS:
|
||||
result = val / 72.0;
|
||||
break;
|
||||
|
||||
case TWUN_TWIPS:
|
||||
result = val / 1440.0;
|
||||
break;
|
||||
|
||||
case TWUN_PIXELS:
|
||||
if(resolution != 0)
|
||||
{
|
||||
result = val / resolution;
|
||||
}
|
||||
break;
|
||||
|
||||
case TWUN_1000INCHES:
|
||||
result = val / 1000.0;
|
||||
break;
|
||||
|
||||
default:
|
||||
// problem
|
||||
break;
|
||||
}
|
||||
|
||||
// We are now in inches
|
||||
// see what we're converting to, and convert the result to those units
|
||||
switch(toUnits)
|
||||
{
|
||||
case TWUN_INCHES:
|
||||
// nothing to do
|
||||
break;
|
||||
|
||||
case TWUN_CENTIMETERS:
|
||||
result *= 2.54;
|
||||
break;
|
||||
|
||||
case TWUN_PICAS:
|
||||
result *= 6.0;
|
||||
break;
|
||||
|
||||
case TWUN_POINTS:
|
||||
result *= 72.0;
|
||||
break;
|
||||
|
||||
case TWUN_TWIPS:
|
||||
result *= 1440.0;
|
||||
break;
|
||||
|
||||
case TWUN_PIXELS:
|
||||
result *= resolution;
|
||||
break;
|
||||
|
||||
case TWUN_1000INCHES:
|
||||
result *= 1000;
|
||||
break;
|
||||
|
||||
default:
|
||||
// problem
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (float)result; //return the result
|
||||
}
|
||||
|
||||
TW_FIX32 ConvertUnits(TW_FIX32 val, int fromUnits, int toUnits, float resolution)
|
||||
{
|
||||
TW_FIX32 result = val;
|
||||
if( fromUnits != toUnits ) //if we do have to convert
|
||||
{
|
||||
result = FloatToFIX32(ConvertUnits( FIX32ToFloat(val), fromUnits, toUnits, resolution));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
TW_FRAME ConvertUnits(TW_FRAME val, int fromUnits, int toUnits, float Xresolution, float Yresolution)
|
||||
{
|
||||
TW_FRAME result = val;
|
||||
if( fromUnits != toUnits ) //if we do have to convert
|
||||
{
|
||||
result.Left = ConvertUnits( val.Left, fromUnits, toUnits, Xresolution);
|
||||
result.Top = ConvertUnits( val.Top, fromUnits, toUnits, Yresolution);
|
||||
result.Right = ConvertUnits( val.Right, fromUnits, toUnits, Xresolution);
|
||||
result.Bottom = ConvertUnits( val.Bottom, fromUnits, toUnits, Yresolution);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
121
CommonDS.h
121
CommonDS.h
|
@ -1,121 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright ?2007 TWAIN Working Group:
|
||||
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
|
||||
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
|
||||
* Ricoh Corporation, and Xerox Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the TWAIN Working Group nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @file CommonDS.h
|
||||
* Common defines and typedefs used by the DS
|
||||
* @author TWAIN Working Group
|
||||
* @date April 2007
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __COMMONDS_H__
|
||||
#define __COMMONDS_H__
|
||||
|
||||
|
||||
#include "Common.h"
|
||||
#include "FreeImage.h"
|
||||
#include "CommonTWAIN.h"
|
||||
|
||||
#ifdef TWH_CMP_MSC
|
||||
#include "resource.h"
|
||||
#endif
|
||||
|
||||
#include "DSMInterface.h"
|
||||
#include "TWAINContainer.h"
|
||||
#include "TWAINContainerInt.h"
|
||||
#include "TWAINContainerFix32.h"
|
||||
#include "TWAINContainerFix32Range.h"
|
||||
#include "TWAINContainerBool.h"
|
||||
#include "TWAINContainerFrame.h"
|
||||
#include "TWAINContainerString.h"
|
||||
#include "CTiffWriter.h"
|
||||
|
||||
#include <map>
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* Base TWAIN Container
|
||||
*/
|
||||
typedef map<int, CTWAINContainer*> TWAINCapabilitiesMap;
|
||||
|
||||
/**
|
||||
* Int TWAIN Container
|
||||
*/
|
||||
typedef map<int, CTWAINContainerInt*> TWAINCapabilitiesMap_int;
|
||||
|
||||
/**
|
||||
* Fix32 TWAIN Container
|
||||
*/
|
||||
typedef map<int, CTWAINContainerFix32*> TWAINCapabilitiesMap_FIX32;
|
||||
|
||||
|
||||
/**
|
||||
* Our internal dimention we use to store data
|
||||
*/
|
||||
#define TWUN_1000INCHES 0x8000
|
||||
|
||||
/**
|
||||
* A commonly used conversion function for converting a dimention of one unit to a dimention of another unit.
|
||||
* converts the given value from fromUnits to toUnits; resolution is optional if pixels are not involved, and should be in dots-per-inch
|
||||
* @param[in] val the value in float to convert.
|
||||
* @param[in] fromUnits the original unit of the value.
|
||||
* @param[in] toUnits the result unit ot convert to
|
||||
* @param[in] resolution the resolution in dots per inch, used to express the unit. Required if one of the units is pixels.
|
||||
* @return the converted value as float
|
||||
*/
|
||||
float ConvertUnits(float val, int fromUnits, int toUnits, float resolution);
|
||||
|
||||
/**
|
||||
* A commonly used conversion function for converting a dimention of one unit to a dimention of another unit.
|
||||
* converts the given value from fromUnits to toUnits; resolution is optional if pixels are not involved, and should be in dots-per-inch
|
||||
* @param[in] val the value in TW_FIX32 to convert.
|
||||
* @param[in] fromUnits the original unit of the value.
|
||||
* @param[in] toUnits the result unit ot convert to
|
||||
* @param[in] resolution the resolution in dots per inch, used to express the unit. Required if one of the units is pixels.
|
||||
* @return the converted value as TW_FIX32
|
||||
*/
|
||||
TW_FIX32 ConvertUnits(TW_FIX32 val, int fromUnits, int toUnits, float resolution);
|
||||
|
||||
/**
|
||||
* A commonly used conversion function for converting a frame of one unit to a frame of another unit.
|
||||
* converts the given frame from fromUnits to toUnits; resolution is optional if pixels are not involved, and should be in dots-per-inch
|
||||
* @param[in] val the value as TW_FRAME to convert.
|
||||
* @param[in] fromUnits the original unit of the value.
|
||||
* @param[in] toUnits the result unit ot convert to
|
||||
* @param[in] Xresolution the X resolution in dots per inch, used to express the unit. Required if one of the units is pixels.
|
||||
* @param[in] Yresolution the Y resolution in dots per inch, used to express the unit. Required if one of the units is pixels.
|
||||
* @return the converted frame as TW_FRAME
|
||||
*/
|
||||
TW_FRAME ConvertUnits(TW_FRAME val, int fromUnits, int toUnits, float Xresolution, float Yresolution);
|
||||
|
||||
#endif // __COMMONDS_H__
|
||||
|
634
CommonTWAIN.cpp
634
CommonTWAIN.cpp
|
@ -1,634 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright ?2007 TWAIN Working Group:
|
||||
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
|
||||
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
|
||||
* Ricoh Corporation, and Xerox Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the TWAIN Working Group nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @file CommonTWAIN.cpp
|
||||
* Utilities functions used by TWAIN Data Sources
|
||||
*
|
||||
* @author TWAIN Working Group
|
||||
* @date October 2007
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "CommonTWAIN.h"
|
||||
|
||||
extern TW_HANDLE _DSM_Alloc(TW_UINT32 _size);
|
||||
extern TW_MEMREF _DSM_LockMemory(TW_HANDLE _hMemory);
|
||||
extern void _DSM_UnlockMemory(TW_HANDLE _hMemory);
|
||||
extern void _DSM_Free(TW_HANDLE _hMemory);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
TW_FIX32 FloatToFIX32 (float floater)
|
||||
{
|
||||
TW_FIX32 Fix32_value;
|
||||
TW_BOOL sign = (floater < 0)?TRUE:FALSE;
|
||||
TW_INT32 value = (TW_INT32) (floater * 65536.0 + (sign?(-0.5):0.5));
|
||||
Fix32_value.Whole = (TW_UINT16)(value >> 16);
|
||||
Fix32_value.Frac = (TW_UINT16)(value & 0x0000ffffL);
|
||||
return (Fix32_value);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
float FIX32ToFloat(const TW_FIX32& _fix32)
|
||||
{
|
||||
return float(_fix32.Whole) + float(_fix32.Frac / 65536.0);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool getCurrent(TW_CAPABILITY *pCap, TW_UINT32& val)
|
||||
{
|
||||
bool bret = false;
|
||||
|
||||
if(0 != pCap->hContainer)
|
||||
{
|
||||
if(TWON_ENUMERATION == pCap->ConType)
|
||||
{
|
||||
pTW_ENUMERATION pCapPT = (pTW_ENUMERATION)_DSM_LockMemory(pCap->hContainer);
|
||||
switch(pCapPT->ItemType)
|
||||
{
|
||||
case TWTY_INT32:
|
||||
val = (TW_INT32)((pTW_INT32)(&pCapPT->ItemList))[pCapPT->CurrentIndex];
|
||||
bret = true;
|
||||
break;
|
||||
|
||||
case TWTY_UINT32:
|
||||
val = (TW_INT32)((pTW_UINT32)(&pCapPT->ItemList))[pCapPT->CurrentIndex];
|
||||
bret = true;
|
||||
break;
|
||||
|
||||
case TWTY_INT16:
|
||||
val = (TW_INT32)((pTW_INT16)(&pCapPT->ItemList))[pCapPT->CurrentIndex];
|
||||
bret = true;
|
||||
break;
|
||||
|
||||
case TWTY_UINT16:
|
||||
val = (TW_INT32)((pTW_UINT16)(&pCapPT->ItemList))[pCapPT->CurrentIndex];
|
||||
bret = true;
|
||||
break;
|
||||
|
||||
case TWTY_INT8:
|
||||
val = (TW_INT32)((pTW_INT8)(&pCapPT->ItemList))[pCapPT->CurrentIndex];
|
||||
bret = true;
|
||||
break;
|
||||
|
||||
case TWTY_UINT8:
|
||||
val = (TW_INT32)((pTW_UINT8)(&pCapPT->ItemList))[pCapPT->CurrentIndex];
|
||||
bret = true;
|
||||
break;
|
||||
|
||||
case TWTY_BOOL:
|
||||
val = (TW_INT32)((pTW_BOOL)(&pCapPT->ItemList))[pCapPT->CurrentIndex];
|
||||
bret = true;
|
||||
break;
|
||||
|
||||
}
|
||||
_DSM_UnlockMemory(pCap->hContainer);
|
||||
}
|
||||
else if(TWON_ONEVALUE == pCap->ConType)
|
||||
{
|
||||
pTW_ONEVALUE pCapPT = (pTW_ONEVALUE)_DSM_LockMemory(pCap->hContainer);
|
||||
if(pCapPT->ItemType < TWTY_FIX32)
|
||||
{
|
||||
val = pCapPT->Item;
|
||||
bret = true;
|
||||
}
|
||||
_DSM_UnlockMemory(pCap->hContainer);
|
||||
}
|
||||
else if(TWON_RANGE == pCap->ConType)
|
||||
{
|
||||
pTW_RANGE pCapPT = (pTW_RANGE)_DSM_LockMemory(pCap->hContainer);
|
||||
if(pCapPT->ItemType < TWTY_FIX32)
|
||||
{
|
||||
val = pCapPT->CurrentValue;
|
||||
bret = true;
|
||||
}
|
||||
_DSM_UnlockMemory(pCap->hContainer);
|
||||
}
|
||||
}
|
||||
|
||||
return bret;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool getCurrent(TW_CAPABILITY *pCap, string& val)
|
||||
{
|
||||
bool bret = false;
|
||||
|
||||
if(0 != pCap->hContainer)
|
||||
{
|
||||
if(TWON_ENUMERATION == pCap->ConType)
|
||||
{
|
||||
pTW_ENUMERATION pCapPT = (pTW_ENUMERATION)_DSM_LockMemory(pCap->hContainer);
|
||||
switch(pCapPT->ItemType)
|
||||
{
|
||||
case TWTY_STR32:
|
||||
{
|
||||
pTW_STR32 pStr = &((pTW_STR32)(&pCapPT->ItemList))[pCapPT->CurrentIndex];
|
||||
// In case the Capability is not null terminated
|
||||
pStr[32] = 0;
|
||||
val = pStr;
|
||||
bret = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case TWTY_STR64:
|
||||
{
|
||||
pTW_STR64 pStr = &((pTW_STR64)(&pCapPT->ItemList))[pCapPT->CurrentIndex];
|
||||
// In case the Capability is not null terminated
|
||||
pStr[64] = 0;
|
||||
val = pStr;
|
||||
bret = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case TWTY_STR128:
|
||||
{
|
||||
pTW_STR128 pStr = &((pTW_STR128)(&pCapPT->ItemList))[pCapPT->CurrentIndex];
|
||||
// In case the Capability is not null terminated
|
||||
pStr[128] = 0;
|
||||
val = pStr;
|
||||
bret = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case TWTY_STR255:
|
||||
{
|
||||
pTW_STR255 pStr = &((pTW_STR255)(&pCapPT->ItemList))[pCapPT->CurrentIndex];
|
||||
// In case the Capability is not null terminated
|
||||
pStr[255] = 0;
|
||||
val = pStr;
|
||||
bret = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
_DSM_UnlockMemory(pCap->hContainer);
|
||||
}
|
||||
else if(TWON_ONEVALUE == pCap->ConType)
|
||||
{
|
||||
pTW_ONEVALUE pCapPT = (pTW_ONEVALUE)_DSM_LockMemory(pCap->hContainer);
|
||||
|
||||
switch(pCapPT->ItemType)
|
||||
{
|
||||
case TWTY_STR32:
|
||||
{
|
||||
pTW_STR32 pStr = ((pTW_STR32)(&pCapPT->Item));
|
||||
// In case the Capability is not null terminated
|
||||
pStr[32] = 0;
|
||||
val = pStr;
|
||||
bret = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case TWTY_STR64:
|
||||
{
|
||||
pTW_STR64 pStr = ((pTW_STR64)(&pCapPT->Item));
|
||||
// In case the Capability is not null terminated
|
||||
pStr[64] = 0;
|
||||
val = pStr;
|
||||
bret = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case TWTY_STR128:
|
||||
{
|
||||
pTW_STR128 pStr = ((pTW_STR128)(&pCapPT->Item));
|
||||
// In case the Capability is not null terminated
|
||||
pStr[128] = 0;
|
||||
val = pStr;
|
||||
bret = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case TWTY_STR255:
|
||||
{
|
||||
pTW_STR255 pStr = ((pTW_STR255)(&pCapPT->Item));
|
||||
// In case the Capability is not null terminated
|
||||
pStr[255] = 0;
|
||||
val = pStr;
|
||||
bret = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
_DSM_UnlockMemory(pCap->hContainer);
|
||||
}
|
||||
}
|
||||
|
||||
return bret;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool getCurrent(TW_CAPABILITY *pCap, TW_FIX32& val)
|
||||
{
|
||||
bool bret = false;
|
||||
|
||||
if(0 != pCap->hContainer)
|
||||
{
|
||||
if(TWON_ENUMERATION == pCap->ConType)
|
||||
{
|
||||
pTW_ENUMERATION_FIX32 pCapPT = (pTW_ENUMERATION_FIX32)_DSM_LockMemory(pCap->hContainer);
|
||||
|
||||
if(TWTY_FIX32 == pCapPT->ItemType)
|
||||
{
|
||||
val = pCapPT->ItemList[pCapPT->CurrentIndex];
|
||||
bret = true;
|
||||
}
|
||||
_DSM_UnlockMemory(pCap->hContainer);
|
||||
}
|
||||
else if(TWON_ONEVALUE == pCap->ConType)
|
||||
{
|
||||
pTW_ONEVALUE_FIX32 pCapPT = (pTW_ONEVALUE_FIX32)_DSM_LockMemory(pCap->hContainer);
|
||||
|
||||
if(TWTY_FIX32 == pCapPT->ItemType)
|
||||
{
|
||||
val = pCapPT->Item;
|
||||
bret = true;
|
||||
}
|
||||
_DSM_UnlockMemory(pCap->hContainer);
|
||||
}
|
||||
else if(TWON_RANGE == pCap->ConType)
|
||||
{
|
||||
pTW_RANGE pCapPT = (pTW_RANGE)_DSM_LockMemory(pCap->hContainer);
|
||||
if(TWTY_FIX32 == pCapPT->ItemType)
|
||||
{
|
||||
val = *(TW_FIX32*)&pCapPT->CurrentValue;
|
||||
bret = true;
|
||||
}
|
||||
_DSM_UnlockMemory(pCap->hContainer);
|
||||
}
|
||||
}
|
||||
|
||||
return bret;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool getCurrent(TW_CAPABILITY *pCap, TW_FRAME& frame)
|
||||
{
|
||||
bool bret = false;
|
||||
|
||||
if(0 != pCap->hContainer)
|
||||
{
|
||||
if(TWON_ENUMERATION == pCap->ConType)
|
||||
{
|
||||
pTW_ENUMERATION_FRAME pCapPT = (pTW_ENUMERATION_FRAME)_DSM_LockMemory(pCap->hContainer);
|
||||
|
||||
if(TWTY_FRAME == pCapPT->ItemType)
|
||||
{
|
||||
frame = pCapPT->ItemList[pCapPT->CurrentIndex];
|
||||
bret = true;
|
||||
}
|
||||
_DSM_UnlockMemory(pCap->hContainer);
|
||||
}
|
||||
else if(TWON_ONEVALUE == pCap->ConType)
|
||||
{
|
||||
pTW_ONEVALUE_FRAME pCapPT = (pTW_ONEVALUE_FRAME)_DSM_LockMemory(pCap->hContainer);
|
||||
|
||||
if(TWTY_FRAME == pCapPT->ItemType)
|
||||
{
|
||||
frame = pCapPT->Item;
|
||||
bret = true;
|
||||
}
|
||||
_DSM_UnlockMemory(pCap->hContainer);
|
||||
}
|
||||
}
|
||||
|
||||
return bret;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool GetItem(TW_CAPABILITY *pCap, TW_UINT32 item, TW_UINT32& val)
|
||||
{
|
||||
bool bret = false;
|
||||
|
||||
if(0 != pCap && 0 != pCap->hContainer)
|
||||
{
|
||||
if( TWON_ARRAY == pCap->ConType
|
||||
|| TWON_ENUMERATION == pCap->ConType )
|
||||
{
|
||||
TW_UINT8 *pData = NULL;
|
||||
unsigned int Count = 0;
|
||||
TW_UINT16 Type = 0;
|
||||
|
||||
if( TWON_ARRAY == pCap->ConType )
|
||||
{
|
||||
pTW_ARRAY pArray = (pTW_ARRAY)_DSM_LockMemory(pCap->hContainer);
|
||||
Count = pArray->NumItems;
|
||||
Type = pArray->ItemType;
|
||||
pData = &pArray->ItemList[0];
|
||||
}
|
||||
|
||||
if( TWON_ENUMERATION == pCap->ConType )
|
||||
{
|
||||
pTW_ENUMERATION pEnumeration = (pTW_ENUMERATION)_DSM_LockMemory(pCap->hContainer);
|
||||
Count = pEnumeration->NumItems;
|
||||
Type = pEnumeration->ItemType;
|
||||
pData = &pEnumeration->ItemList[0];
|
||||
}
|
||||
|
||||
if(item < Count)
|
||||
{
|
||||
switch(Type)
|
||||
{
|
||||
case TWTY_INT32:
|
||||
val = (int)((pTW_INT32)(pData))[item];
|
||||
bret = true;
|
||||
break;
|
||||
|
||||
case TWTY_UINT32:
|
||||
val = (int)((pTW_UINT32)(pData))[item];
|
||||
bret = true;
|
||||
break;
|
||||
|
||||
case TWTY_INT16:
|
||||
val = (int)((pTW_INT16)(pData))[item];
|
||||
bret = true;
|
||||
break;
|
||||
|
||||
case TWTY_UINT16:
|
||||
val = (int)((pTW_UINT16)(pData))[item];
|
||||
bret = true;
|
||||
break;
|
||||
|
||||
case TWTY_INT8:
|
||||
val = (int)((pTW_INT8)(pData))[item];
|
||||
bret = true;
|
||||
break;
|
||||
|
||||
case TWTY_UINT8:
|
||||
val = (int)((pTW_UINT8)(pData))[item];
|
||||
bret = true;
|
||||
break;
|
||||
|
||||
case TWTY_BOOL:
|
||||
val = (int)((pTW_BOOL)(pData))[item];
|
||||
bret = true;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
_DSM_UnlockMemory(pCap->hContainer);
|
||||
}
|
||||
}
|
||||
|
||||
return bret;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool GetItem(TW_CAPABILITY *pCap, TW_UINT32 item, string& val)
|
||||
{
|
||||
bool bret = false;
|
||||
|
||||
if(0 != pCap && 0 != pCap->hContainer)
|
||||
{
|
||||
if( TWON_ARRAY == pCap->ConType
|
||||
|| TWON_ENUMERATION == pCap->ConType )
|
||||
{
|
||||
TW_UINT8 *pData = NULL;
|
||||
unsigned int Count = 0;
|
||||
TW_UINT16 Type = 0;
|
||||
|
||||
if( TWON_ARRAY == pCap->ConType )
|
||||
{
|
||||
pTW_ARRAY pArray = (pTW_ARRAY)_DSM_LockMemory(pCap->hContainer);
|
||||
Count = pArray->NumItems;
|
||||
Type = pArray->ItemType;
|
||||
pData = &pArray->ItemList[0];
|
||||
}
|
||||
|
||||
if( TWON_ENUMERATION == pCap->ConType )
|
||||
{
|
||||
pTW_ENUMERATION pEnumeration = (pTW_ENUMERATION)_DSM_LockMemory(pCap->hContainer);
|
||||
Count = pEnumeration->NumItems;
|
||||
Type = pEnumeration->ItemType;
|
||||
pData = &pEnumeration->ItemList[0];
|
||||
}
|
||||
|
||||
if(item < Count)
|
||||
{
|
||||
switch(Type)
|
||||
{
|
||||
case TWTY_STR32:
|
||||
{
|
||||
pTW_STR32 pStr = &((pTW_STR32)(pData))[item];
|
||||
// In case the Capability is not null terminated
|
||||
pStr[32] = 0;
|
||||
val = pStr;
|
||||
bret = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case TWTY_STR64:
|
||||
{
|
||||
pTW_STR64 pStr = &((pTW_STR64)(pData))[item];
|
||||
// In case the Capability is not null terminated
|
||||
pStr[64] = 0;
|
||||
val = pStr;
|
||||
bret = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case TWTY_STR128:
|
||||
{
|
||||
pTW_STR128 pStr = &((pTW_STR128)(pData))[item];
|
||||
// In case the Capability is not null terminated
|
||||
pStr[128] = 0;
|
||||
val = pStr;
|
||||
bret = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case TWTY_STR255:
|
||||
{
|
||||
pTW_STR255 pStr = &((pTW_STR255)(pData))[item];
|
||||
// In case the Capability is not null terminated
|
||||
pStr[255] = 0;
|
||||
val = pStr;
|
||||
bret = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
_DSM_UnlockMemory(pCap->hContainer);
|
||||
}
|
||||
}
|
||||
|
||||
return bret;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool GetItem(TW_CAPABILITY *pCap, TW_UINT32 item, TW_FIX32& val)
|
||||
{
|
||||
bool bret = false;
|
||||
|
||||
if(0 != pCap && 0 != pCap->hContainer)
|
||||
{
|
||||
if( TWON_ARRAY == pCap->ConType
|
||||
|| TWON_ENUMERATION == pCap->ConType )
|
||||
{
|
||||
TW_FIX32 *pData = NULL;
|
||||
unsigned int Count = 0;
|
||||
TW_UINT16 Type = 0;
|
||||
|
||||
if( TWON_ARRAY == pCap->ConType )
|
||||
{
|
||||
pTW_ARRAY_FIX32 pArray = (pTW_ARRAY_FIX32)_DSM_LockMemory(pCap->hContainer);
|
||||
Count = pArray->NumItems;
|
||||
Type = pArray->ItemType;
|
||||
pData = &pArray->ItemList[0];
|
||||
}
|
||||
|
||||
if( TWON_ENUMERATION == pCap->ConType )
|
||||
{
|
||||
pTW_ENUMERATION_FIX32 pEnumeration = (pTW_ENUMERATION_FIX32)_DSM_LockMemory(pCap->hContainer);
|
||||
Count = pEnumeration->NumItems;
|
||||
Type = pEnumeration->ItemType;
|
||||
pData = &pEnumeration->ItemList[0];
|
||||
}
|
||||
|
||||
if(item < Count && Type == TWTY_FIX32)
|
||||
{
|
||||
val = pData[item];
|
||||
bret = true;
|
||||
}
|
||||
_DSM_UnlockMemory(pCap->hContainer);
|
||||
}
|
||||
}
|
||||
|
||||
return bret;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool GetItem(TW_CAPABILITY *pCap, TW_UINT32 item, TW_FRAME& val)
|
||||
{
|
||||
bool bret = false;
|
||||
|
||||
if(0 != pCap && 0 != pCap->hContainer)
|
||||
{
|
||||
if( TWON_ARRAY == pCap->ConType
|
||||
|| TWON_ENUMERATION == pCap->ConType )
|
||||
{
|
||||
TW_FRAME *pData = NULL;
|
||||
unsigned int Count = 0;
|
||||
TW_UINT16 Type = 0;
|
||||
|
||||
if( TWON_ARRAY == pCap->ConType )
|
||||
{
|
||||
pTW_ARRAY_FRAME pArray = (pTW_ARRAY_FRAME)_DSM_LockMemory(pCap->hContainer);
|
||||
Count = pArray->NumItems;
|
||||
Type = pArray->ItemType;
|
||||
pData = &pArray->ItemList[0];
|
||||
}
|
||||
|
||||
if( TWON_ENUMERATION == pCap->ConType )
|
||||
{
|
||||
pTW_ENUMERATION_FRAME pEnumeration = (pTW_ENUMERATION_FRAME)_DSM_LockMemory(pCap->hContainer);
|
||||
Count = pEnumeration->NumItems;
|
||||
Type = pEnumeration->ItemType;
|
||||
pData = &pEnumeration->ItemList[0];
|
||||
}
|
||||
|
||||
if(item < Count && Type == TWTY_FRAME)
|
||||
{
|
||||
val = pData[item];
|
||||
bret = true;
|
||||
}
|
||||
_DSM_UnlockMemory(pCap->hContainer);
|
||||
}
|
||||
}
|
||||
|
||||
return bret;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
int getTWTYsize(TW_UINT16 ItemType)
|
||||
{
|
||||
int TypeSize = 0;
|
||||
|
||||
switch(ItemType)
|
||||
{
|
||||
case TWTY_INT8:
|
||||
TypeSize = sizeof(TW_INT8);
|
||||
break;
|
||||
case TWTY_INT16:
|
||||
TypeSize = sizeof(TW_INT16);
|
||||
break;
|
||||
case TWTY_INT32:
|
||||
TypeSize = sizeof(TW_INT32);
|
||||
break;
|
||||
case TWTY_UINT8:
|
||||
TypeSize = sizeof(TW_UINT8);
|
||||
break;
|
||||
case TWTY_UINT16:
|
||||
TypeSize = sizeof(TW_UINT16);
|
||||
break;
|
||||
case TWTY_UINT32:
|
||||
TypeSize = sizeof(TW_UINT32);
|
||||
break;
|
||||
case TWTY_BOOL:
|
||||
TypeSize = sizeof(TW_BOOL);
|
||||
break;
|
||||
case TWTY_FIX32:
|
||||
TypeSize = sizeof(TW_FIX32);
|
||||
break;
|
||||
case TWTY_FRAME:
|
||||
TypeSize = sizeof(TW_FRAME);
|
||||
break;
|
||||
case TWTY_STR32:
|
||||
TypeSize = sizeof(TW_STR32);
|
||||
break;
|
||||
case TWTY_STR64:
|
||||
TypeSize = sizeof(TW_STR64);
|
||||
break;
|
||||
case TWTY_STR128:
|
||||
TypeSize = sizeof(TW_STR128);
|
||||
break;
|
||||
case TWTY_STR255:
|
||||
TypeSize = sizeof(TW_STR255);
|
||||
break;
|
||||
case TWTY_STR1024:
|
||||
TypeSize = sizeof(TW_STR1024);
|
||||
break;
|
||||
case TWTY_UNI512:
|
||||
TypeSize = sizeof(TW_UNI512);
|
||||
break;
|
||||
case TWTY_HANDLE:
|
||||
TypeSize = sizeof(TW_HANDLE);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return TypeSize;
|
||||
}
|
475
CommonTWAIN.h
475
CommonTWAIN.h
|
@ -1,475 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright © 2007 TWAIN Working Group:
|
||||
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
|
||||
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
|
||||
* Ricoh Corporation, and Xerox Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the TWAIN Working Group nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @file CommonTWAIN.h
|
||||
* Common defines and typedefs used by the DS
|
||||
* @author TWAIN Working Group
|
||||
* @date April 2007
|
||||
*/
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
#include <string>
|
||||
#ifndef __COMMONTWAIN_H__
|
||||
#define __COMMONTWAIN_H__
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef struct _TW_GUID {
|
||||
unsigned long Data1;
|
||||
unsigned short Data2;
|
||||
unsigned short Data3;
|
||||
unsigned char Data4[ 8 ];
|
||||
} TW_GUID;
|
||||
/**
|
||||
* @def kTWAIN_DSM_DLL_NAME
|
||||
* File name of the DSM library.
|
||||
*/
|
||||
|
||||
#ifdef TWH_CMP_MSC
|
||||
#ifdef TWH_64BIT
|
||||
#define kTWAIN_DSM_DLL_NAME "TWAINDSM.dll"
|
||||
#else
|
||||
#define kTWAIN_DSM_DLL_NAME "TWAINDSM.dll"
|
||||
#endif // #ifdef TWH_64BIT
|
||||
#elif defined(TWH_CMP_GNU)
|
||||
#define kTWAIN_DSM_DLL_NAME "libtwaindsm.so"
|
||||
#else
|
||||
#error Sorry, we don't recognize this system...
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A commonly used conversion function for converting float to TW_FIX32.
|
||||
* @param[in] floater the float value to change to TW_FIX32
|
||||
* @return the value as TW_FIX32
|
||||
*/
|
||||
TW_FIX32 FloatToFIX32 (float floater);
|
||||
|
||||
/**
|
||||
* A commonly used conversion function for converting TW_FIX32 to float.
|
||||
* @param[in] _fix32 the TW_FIX32 value to change to float
|
||||
* @return the value as float
|
||||
*/
|
||||
float FIX32ToFloat(const TW_FIX32& _fix32);
|
||||
|
||||
|
||||
/* Set the packing: this occurs before any structures are defined */
|
||||
#ifdef TWH_CMP_MSC
|
||||
#pragma pack (push, before_twain)
|
||||
#pragma pack (2)
|
||||
#elif defined(TWH_CMP_GNU)
|
||||
#pragma pack (push, before_twain)
|
||||
#ifdef __APPLE__
|
||||
//#pragma pack (4)
|
||||
#else
|
||||
#pragma pack (2)
|
||||
#endif
|
||||
#elif defined(TWH_CMP_BORLAND)
|
||||
#pragma option -a2
|
||||
#endif
|
||||
|
||||
// The following structures combinations are implimented and found in the TWAIN specifications
|
||||
// BOOL INT8 INT16 INT32 UINT8 UINT16 UINT32 STR32 STR64 STR128 STR255 STR1024 UNI512 FIX32 FRAME
|
||||
// OneValue x x x x x x x x x x
|
||||
// Array x x x x x x
|
||||
// Enumeration x x x x x x x x
|
||||
// Range x x x x x
|
||||
|
||||
/**
|
||||
* TW_ONEVALUE that holds a TW_FIX32 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_FIX32 */
|
||||
#ifdef __APPLE__
|
||||
TW_UINT16 Dummy;
|
||||
#endif
|
||||
TW_FIX32 Item; /**< TW_FIX32 value being passed */
|
||||
} TW_ONEVALUE_FIX32, FAR * pTW_ONEVALUE_FIX32; /**< Pointer to TW_ONEVALUE that holds a TW_FIX32 item */
|
||||
|
||||
/**
|
||||
* TW_ONEVALUE that holds a TW_STR32 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_STR32 */
|
||||
TW_STR32 Item; /**< TW_STR32 value being passed */
|
||||
} TW_ONEVALUE_STR32, FAR * pTW_ONEVALUE_STR32; /**< Pointer to TW_ONEVALUE that holds a TW_STR32 item */
|
||||
|
||||
/**
|
||||
* TW_ONEVALUE that holds a TW_STR64 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_STR64 */
|
||||
TW_STR64 Item; /**< TW_STR32 value being passed */
|
||||
} TW_ONEVALUE_STR64, FAR * pTW_ONEVALUE_STR64; /**< Pointer to TW_ONEVALUE that holds a TW_STR32 item */
|
||||
|
||||
/**
|
||||
* TW_ONEVALUE that holds a TW_STR128 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_STR128 */
|
||||
TW_STR128 Item; /**< TW_STR128 value being passed */
|
||||
} TW_ONEVALUE_STR128, FAR * pTW_ONEVALUE_STR128; /**< Pointer to TW_ONEVALUE that holds a TW_STR128 item */
|
||||
|
||||
/**
|
||||
* TW_ONEVALUE that holds a TW_STR255 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_STR255 */
|
||||
TW_STR255 Item; /**< TW_STR255 value being passed */
|
||||
} TW_ONEVALUE_STR255, FAR * pTW_ONEVALUE_STR255; /**< Pointer to TW_ONEVALUE that holds a TW_STR255 item */
|
||||
|
||||
|
||||
/**
|
||||
* TW_ONEVALUE that holds a TW_FRAME item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_FRAME */
|
||||
#ifdef __APPLE__
|
||||
TW_UINT16 Dummy;
|
||||
#endif
|
||||
TW_FRAME Item; /**< TW_FRAME structure being passed */
|
||||
} TW_ONEVALUE_FRAME, FAR * pTW_ONEVALUE_FRAME; /**< Pointer to TW_ONEVALUE that holds a TW_FRAME item */
|
||||
|
||||
/**
|
||||
* TW_ARRAY that holds a TW_UINT8 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_UINT8 */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_UINT8 ItemList[1]; /**< Array of TW_UINT8 structures starts here */
|
||||
} TW_ARRAY_UINT8, FAR * pTW_ARRAY_UINT8; /**< Pointer to TW_ARRAY that holds a TW_UINT8 item */
|
||||
|
||||
/**
|
||||
* TW_ARRAY that holds a TW_UINT16 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_UINT16 */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_UINT16 ItemList[1]; /**< Array of TW_UINT16 structures starts here */
|
||||
} TW_ARRAY_UINT16, FAR * pTW_ARRAY_UINT16; /**< Pointer to TW_ARRAY that holds a TW_UINT16 item */
|
||||
|
||||
/**
|
||||
* TW_ARRAY that holds a TW_UINT32 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_UINT32 */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_UINT32 ItemList[1]; /**< Array of TW_UINT32 structures starts here */
|
||||
} TW_ARRAY_UINT32, FAR * pTW_ARRAY_UINT32; /**< Pointer to TW_ARRAY that holds a TW_UINT32 item */
|
||||
|
||||
/**
|
||||
* TW_ARRAY that holds a TW_STR32 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_STR32 */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_STR32 ItemList[1]; /**< Array of TW_STR32 structures starts here */
|
||||
} TW_ARRAY_STR32, FAR * pTW_ARRAY_STR32; /**< Pointer to TW_ARRAY that holds a TW_STR32 item */
|
||||
|
||||
/**
|
||||
* TW_ARRAY that holds a TW_FIX32 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_FIX32 */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_FIX32 ItemList[1]; /**< Array of TW_FIX32 structures starts here */
|
||||
} TW_ARRAY_FIX32, FAR * pTW_ARRAY_FIX32; /**< Pointer to TW_ARRAY that holds a TW_FIX32 item */
|
||||
|
||||
/**
|
||||
* TW_ARRAY that holds a TW_FRAME item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_FRAME */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_FRAME ItemList[1]; /**< Array of TW_FRAME structures starts here */
|
||||
} TW_ARRAY_FRAME, FAR * pTW_ARRAY_FRAME; /**< Pointer to TW_ARRAY that holds a TW_FRAME item */
|
||||
|
||||
/**
|
||||
* TW_ENUMERATION that holds a TW_BOOL item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_BOOL */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_UINT32 CurrentIndex; /**< Current value is in ItemList[CurrentIndex] */
|
||||
TW_UINT32 DefaultIndex; /**< Powerup value is in ItemList[DefaultIndex] */
|
||||
TW_BOOL ItemList[1]; /**< Array of ItemType values starts here */
|
||||
} TW_ENUMERATION_BOOL, FAR * pTW_ENUMERATION_BOOL; /**< Pointer to TW_ENUMERATION that holds an array TW_BOOL items */
|
||||
|
||||
/**
|
||||
* TW_ENUMERATION that holds a TW_INT16 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_INT16 */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_UINT32 CurrentIndex; /**< Current value is in ItemList[CurrentIndex] */
|
||||
TW_UINT32 DefaultIndex; /**< Powerup value is in ItemList[DefaultIndex] */
|
||||
TW_INT16 ItemList[1]; /**< Array of ItemType values starts here */
|
||||
} TW_ENUMERATION_INT16, FAR * pTW_ENUMERATION_INT16;/**< Pointer to TW_ENUMERATION that holds an array TW_INT16 items */
|
||||
|
||||
/**
|
||||
* TW_ENUMERATION that holds a TW_INT32 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_INT32 */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_UINT32 CurrentIndex; /**< Current value is in ItemList[CurrentIndex] */
|
||||
TW_UINT32 DefaultIndex; /**< Powerup value is in ItemList[DefaultIndex] */
|
||||
TW_INT32 ItemList[1]; /**< Array of ItemType values starts here */
|
||||
} TW_ENUMERATION_INT32, FAR * pTW_ENUMERATION_INT32;/**< Pointer to TW_ENUMERATION that holds an array TW_UINT32 items */
|
||||
|
||||
/**
|
||||
* TW_ENUMERATION that holds a TW_UINT16 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_UINT16 */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_UINT32 CurrentIndex; /**< Current value is in ItemList[CurrentIndex] */
|
||||
TW_UINT32 DefaultIndex; /**< Powerup value is in ItemList[DefaultIndex] */
|
||||
TW_UINT16 ItemList[1]; /**< Array of ItemType values starts here */
|
||||
} TW_ENUMERATION_UINT16, FAR * pTW_ENUMERATION_UINT16;/**< Pointer to TW_ENUMERATION that holds an array TW_UINT16 items */
|
||||
|
||||
/**
|
||||
* TW_ENUMERATION that holds a TW_UINT32 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_UINT32 */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_UINT32 CurrentIndex; /**< Current value is in ItemList[CurrentIndex] */
|
||||
TW_UINT32 DefaultIndex; /**< Powerup value is in ItemList[DefaultIndex] */
|
||||
TW_UINT32 ItemList[1]; /**< Array of ItemType values starts here */
|
||||
} TW_ENUMERATION_UINT32, FAR * pTW_ENUMERATION_UINT32;/**< Pointer to TW_ENUMERATION that holds an array TW_UINT32 items */
|
||||
|
||||
/**
|
||||
* TW_ENUMERATION that holds a TW_STR32 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_STR32 */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_UINT32 CurrentIndex; /**< Current value is in ItemList[CurrentIndex] */
|
||||
TW_UINT32 DefaultIndex; /**< Powerup value is in ItemList[DefaultIndex] */
|
||||
TW_STR32 ItemList[1]; /**< Array of ItemType values starts here */
|
||||
} TW_ENUMERATION_STR32, FAR * pTW_ENUMERATION_STR32;/**< Pointer to TW_ENUMERATION that holds an array TW_STR32 items */
|
||||
|
||||
/**
|
||||
* TW_ENUMERATION that holds a TW_STR64 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_STR64 */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_UINT32 CurrentIndex; /**< Current value is in ItemList[CurrentIndex] */
|
||||
TW_UINT32 DefaultIndex; /**< Powerup value is in ItemList[DefaultIndex] */
|
||||
TW_STR64 ItemList[1]; /**< Array of ItemType values starts here */
|
||||
} TW_ENUMERATION_STR64, FAR * pTW_ENUMERATION_STR64;/**< Pointer to TW_ENUMERATION that holds an array TW_STR32 items */
|
||||
|
||||
/**
|
||||
* TW_ENUMERATION that holds a TW_STR128 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_STR128 */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_UINT32 CurrentIndex; /**< Current value is in ItemList[CurrentIndex] */
|
||||
TW_UINT32 DefaultIndex; /**< Powerup value is in ItemList[DefaultIndex] */
|
||||
TW_STR128 ItemList[1]; /**< Array of ItemType values starts here */
|
||||
} TW_ENUMERATION_STR128, FAR * pTW_ENUMERATION_STR128;/**< Pointer to TW_ENUMERATION that holds an array TW_STR32 items */
|
||||
|
||||
/**
|
||||
* TW_ENUMERATION that holds a TW_STR255 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_STR255 */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_UINT32 CurrentIndex; /**< Current value is in ItemList[CurrentIndex] */
|
||||
TW_UINT32 DefaultIndex; /**< Powerup value is in ItemList[DefaultIndex] */
|
||||
TW_STR255 ItemList[1]; /**< Array of ItemType values starts here */
|
||||
} TW_ENUMERATION_STR255, FAR * pTW_ENUMERATION_STR255;/**< Pointer to TW_ENUMERATION that holds an array TW_STR255 items */
|
||||
|
||||
/**
|
||||
* TW_ENUMERATION that holds a TW_FIX32 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_FIX32 */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_UINT32 CurrentIndex; /**< Current value is in ItemList[CurrentIndex] */
|
||||
TW_UINT32 DefaultIndex; /**< Powerup value is in ItemList[DefaultIndex] */
|
||||
TW_FIX32 ItemList[1]; /**< Array of ItemType values starts here */
|
||||
} TW_ENUMERATION_FIX32, FAR * pTW_ENUMERATION_FIX32;/**< Pointer to TW_ENUMERATION that holds an array TW_FIX32 items */
|
||||
|
||||
/**
|
||||
* TW_ENUMERATION that holds a TW_FRAME item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType; /**< Assigned TWAIN Type TWTY_FRAME */
|
||||
TW_UINT32 NumItems; /**< How many items in ItemList */
|
||||
TW_UINT32 CurrentIndex; /**< Current value is in ItemList[CurrentIndex] */
|
||||
TW_UINT32 DefaultIndex; /**< Powerup value is in ItemList[DefaultIndex] */
|
||||
TW_FRAME ItemList[1]; /**< Array of TW_FRAME structures starts here */
|
||||
} TW_ENUMERATION_FRAME, FAR * pTW_ENUMERATION_FRAME;/**< Pointer to TW_ENUMERATION that holds a TW_FRAME item */
|
||||
|
||||
/**
|
||||
* TW_RANGE that holds a TW_FIX32 item
|
||||
*/
|
||||
typedef struct {
|
||||
TW_UINT16 ItemType;
|
||||
#ifdef __APPLE__
|
||||
TW_UINT16 Dummy;
|
||||
#endif
|
||||
TW_FIX32 MinValue; /* Starting value in the range. */
|
||||
TW_FIX32 MaxValue; /* Final value in the range. */
|
||||
TW_FIX32 StepSize; /* Increment from MinValue to MaxValue. */
|
||||
TW_FIX32 DefaultValue; /* Power-up value. */
|
||||
TW_FIX32 CurrentValue; /* The value that is currently in effect. */
|
||||
} TW_RANGE_FIX32, FAR * pTW_RANGE_FIX32; /**< Pointer to TW_RANGE that holds an array TW_FIX32 items */
|
||||
|
||||
/* Restore the previous packing alignment: this occurs after all structures are defined */
|
||||
#ifdef TWH_CMP_MSC
|
||||
#pragma pack (pop, before_twain)
|
||||
#elif defined(TWH_CMP_GNU)
|
||||
#pragma pack (pop, before_twain)
|
||||
#elif defined(TWH_CMP_BORLAND)
|
||||
#pragma option ña.
|
||||
//#elif defined(TWH_CMP_XCODE)
|
||||
// #if PRAGMA_STRUCT_ALIGN
|
||||
// #pragma options align=reset
|
||||
// #elif PRAGMA_STRUCT_PACKPUSH
|
||||
// #pragma pack (pop)
|
||||
// #elif PRAGMA_STRUCT_PACK
|
||||
// #pragma pack()
|
||||
// #endif
|
||||
#endif
|
||||
|
||||
#ifdef TWH_CMP_GNU
|
||||
#pragma pack(1)
|
||||
|
||||
/**
|
||||
* Structure contains information about the type, size, and layout of a file
|
||||
* that contains a DIB.
|
||||
*/
|
||||
typedef struct tagBITMAPFILEHEADER
|
||||
{
|
||||
WORD bfType; /**< Specifies the file type, must be BM. */
|
||||
DWORD bfSize; /**< Specifies the size, in bytes, of the bitmap file. */
|
||||
WORD bfReserved1; /**< Reserved; must be zero. */
|
||||
WORD bfReserved2; /**< Reserved; must be zero. */
|
||||
DWORD bfOffBits; /**< Specifies the offset, in bytes, from the beginning of
|
||||
the BITMAPFILEHEADER structure to the bitmap bits. */
|
||||
} BITMAPFILEHEADER;
|
||||
|
||||
#pragma pack() // reset
|
||||
#endif // TWH_CMP_GNU
|
||||
|
||||
|
||||
/**
|
||||
* Get the current value from a Capability as a TW_UINT32.
|
||||
* @param[in] pCap a pointer to the capability to retrieve the current value
|
||||
* @param[out] val the value retrieved from the capability
|
||||
* @return true if successful
|
||||
*/
|
||||
bool getCurrent(TW_CAPABILITY *pCap, TW_UINT32& val);
|
||||
|
||||
/**
|
||||
* Get the current value from a Capability as a string for capabilities of
|
||||
* types TWTY_STR32, TWTY_STR64, TWTY_STR128, and TWTY_STR256
|
||||
* @param[in] pCap a pointer to the capability to retrieve the current value
|
||||
* @param[out] val the value retrieved from the capability
|
||||
* @return true if successful
|
||||
*/
|
||||
bool getCurrent(TW_CAPABILITY *pCap, string& val);
|
||||
|
||||
/**
|
||||
* Get the current value from a Capability as a TW_FIX32.
|
||||
* @param[in] pCap a pointer to the capability to retrieve the current value
|
||||
* @param[out] val the value retrieved from the capability
|
||||
* @return true if successful
|
||||
*/
|
||||
bool getCurrent(TW_CAPABILITY *pCap, TW_FIX32& val);
|
||||
|
||||
/**
|
||||
* Get the current value from a Capability as a TW_FRAME.
|
||||
* @param[in] pCap a pointer to the capability to retrieve the current value
|
||||
* @param[out] val the value retrieved from the capability
|
||||
* @return true if successful
|
||||
*/
|
||||
bool getCurrent(TW_CAPABILITY *pCap, TW_FRAME& val);
|
||||
|
||||
/**
|
||||
* Get an item value from an array of values from a TW_ENUMERATION or TW_ARRAY
|
||||
* type Capability as a TW_UINT32.
|
||||
* @param[in] pCap a pointer to the capability to retrieve the value
|
||||
* @pCount[in] item the 0 based location in the array to retrieve the item.
|
||||
* @param[out] val the value retrieved from the capability
|
||||
* @return true if successful. false if no value returned
|
||||
*/
|
||||
bool GetItem(TW_CAPABILITY *pCap, TW_UINT32 item, TW_UINT32& val);
|
||||
|
||||
/**
|
||||
* Get an item value from an array of values from a TW_ENUMERATION or TW_ARRAY
|
||||
* containing types TWTY_STR32, TWTY_STR64, TWTY_STR128, and TWTY_STR256
|
||||
* @param[in] pCap a pointer to the capability to retrieve the value
|
||||
* @pCount[in] item the 0 based location in the array to retrieve the item.
|
||||
* @param[out] val the value retrieved from the capability
|
||||
* @return true if successful. false if no value returned
|
||||
*/
|
||||
bool GetItem(TW_CAPABILITY *pCap, TW_UINT32 item, string& val);
|
||||
|
||||
/**
|
||||
* Get an item value from an array of values from a TW_ENUMERATION or TW_ARRAY
|
||||
* containing type TWTY_FIX32
|
||||
* @param[in] pCap a pointer to the capability to retrieve the value
|
||||
* @pCount[in] item the 0 based location in the array to retrieve the item.
|
||||
* @param[out] val the value retrieved from the capability
|
||||
* @return true if successful. false if no value returned
|
||||
*/
|
||||
bool GetItem(TW_CAPABILITY *pCap, TW_UINT32 item, TW_FIX32& val);
|
||||
|
||||
/**
|
||||
* Get an item value from an array of values from a TW_ENUMERATION or TW_ARRAY
|
||||
* containing type TWTY_FRAME
|
||||
* @param[in] pCap a pointer to the capability to retrieve the value
|
||||
* @pCount[in] item the 0 based location in the array to retrieve the item.
|
||||
* @param[out] val the value retrieved from the capability
|
||||
* @return true if successful. false if no value returned
|
||||
*/
|
||||
bool GetItem(TW_CAPABILITY *pCap, TW_UINT32 item, TW_FRAME& val);
|
||||
|
||||
/**
|
||||
* Get the size of TWAIN type
|
||||
* @param[in] ItemType the TWAIN type to return the size for
|
||||
* @return the size of the type returned
|
||||
*/
|
||||
int getTWTYsize(TW_UINT16 ItemType);
|
||||
|
||||
#endif // __COMMONTWAIN_H__
|
||||
|
297
DSMInterface.cpp
297
DSMInterface.cpp
|
@ -1,297 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright <EFBFBD> 2007 TWAIN Working Group:
|
||||
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
|
||||
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
|
||||
* Ricoh Corporation, and Xerox Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the TWAIN Working Group nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @file DSMInterface.cpp
|
||||
* Common defines and typedefs used for accessing DSM for Twain Data Sources.
|
||||
* @author TWAIN Working Group
|
||||
* @date April 2007
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "DSMInterface.h"
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* gloabal pointer to the Data Source Manager
|
||||
*/
|
||||
HMODULE gpDSM = 0;
|
||||
|
||||
/**
|
||||
* gloabal pointer to the Data Source Manager's Entry point
|
||||
* - cleared & init'd in @see LoadDSMLib
|
||||
*/
|
||||
TW_ENTRYPOINT g_DSM_Entry =
|
||||
{
|
||||
0,// TW_UINT32 Size;
|
||||
0,// DSMENTRYPROC DSM_Entry;
|
||||
0,// DSM_MEMALLOCATE DSM_MemAllocate;
|
||||
0,// DSM_MEMFREE DSM_MemFree;
|
||||
0,// DSM_MEMLOCK DSM_MemLock;
|
||||
0 // DSM_MEMUNLOCK DSM_MemUnlock;
|
||||
};
|
||||
|
||||
#ifdef TWH_CMP_GNU
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#ifdef TWNDS_OS_APPLE
|
||||
// #include "CarbonCore/MacMemory.h"
|
||||
#include <Carbon/Carbon.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This is the same as the main DS_Entry function. Routes traffic
|
||||
* to the proper location.
|
||||
* @param[in] _pOrigin Identifies the source DS for the message.
|
||||
* @param[in] _pDest Identifies the destination application for the message.
|
||||
* @param[in] _DG The Data Group.
|
||||
* @param[in] _DAT The Data Attribute Type.
|
||||
* @param[in] _MSG The message with respect to the Data Group and the Data Attribute Type.
|
||||
* @param[in,out] _pData A pointer to the data structure or variable identified
|
||||
* by the Data Attribute Type.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_UINT16 _DSM_Entry( pTW_IDENTITY _pOrigin,
|
||||
pTW_IDENTITY _pDest,
|
||||
TW_UINT32 _DG,
|
||||
TW_UINT16 _DAT,
|
||||
TW_UINT16 _MSG,
|
||||
TW_MEMREF _pData)
|
||||
{
|
||||
TW_UINT16 ret = TWRC_FAILURE;
|
||||
|
||||
// With DSM2 we do not need to load the DSM. We should have recieved
|
||||
// Message with the entry points that we use.
|
||||
// On windows with DSM1(twain_32.dll) we will need to first laod the dll
|
||||
// then find the entry point First check to see if you have an entry point.
|
||||
// On Mac we will use the dynamicaly linked at build time dll.
|
||||
|
||||
if(0 == g_DSM_Entry.DSM_Entry)
|
||||
{
|
||||
// We do not already have the entry point for regisry callback
|
||||
|
||||
#ifdef TWNDS_OS_APPLE
|
||||
// This should only happen if not being called by the DSM2
|
||||
// Other words only on Mac with an older DSM
|
||||
// So we use the old dll
|
||||
g_DSM_Entry.DSM_Entry = DSM_Entry;
|
||||
// ret = DSM_Entry(_pOrigin, _pDest, _DG, _DAT, _MSG, _pData);
|
||||
|
||||
#elif defined (TWH_CMP_MSC)
|
||||
|
||||
// This should only happen if not being called by the DSM2
|
||||
// Other words only on Windows with an older DSM
|
||||
// So we load the old dll
|
||||
char DSMName[MAX_PATH];
|
||||
|
||||
memset(DSMName, 0, MAX_PATH*sizeof(char));
|
||||
|
||||
if(GetWindowsDirectory (DSMName, MAX_PATH)==0)
|
||||
{
|
||||
DSMName[0]=0;
|
||||
}
|
||||
#if (TWNDS_CMP_VERSION >= 1400)
|
||||
if (DSMName[strlen(DSMName)-1] != '\\')
|
||||
{
|
||||
strcat_s(DSMName,MAX_PATH, "\\");
|
||||
}
|
||||
strcat_s (DSMName,MAX_PATH, "TWAIN_32.dll");
|
||||
#else
|
||||
if (DSMName[strlen(DSMName)-1] != '\\')
|
||||
{
|
||||
strcat(DSMName, "\\");
|
||||
}
|
||||
strcat(DSMName, "TWAIN_32.dll");
|
||||
#endif
|
||||
|
||||
if((0 == gpDSM) && !LoadDSMLib(DSMName))
|
||||
{
|
||||
cerr << "Could not load the DSM" << endl;
|
||||
return TWRC_FAILURE;
|
||||
}
|
||||
#endif // TWNDS_OS_APPLE & TWH_CMP_MSC
|
||||
}
|
||||
|
||||
if(0 == g_DSM_Entry.DSM_Entry)
|
||||
{
|
||||
cerr << "No Entry Point for DSM_Entry" << endl;
|
||||
return TWRC_FAILURE;
|
||||
}
|
||||
|
||||
// If we did not have an enty point before we do now.
|
||||
ret = g_DSM_Entry.DSM_Entry(_pOrigin, _pDest, _DG, _DAT, _MSG, _pData);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
bool LoadDSMLib(char* _pszLibName)
|
||||
{
|
||||
// check if already opened
|
||||
if(0 != gpDSM)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
memset(&g_DSM_Entry, 0, sizeof(TW_ENTRYPOINT));
|
||||
|
||||
#ifdef TWH_CMP_GNU
|
||||
char *error;
|
||||
#endif //TWH_CMP_GNU
|
||||
|
||||
if((gpDSM=LOADLIBRARY(_pszLibName)) != 0)
|
||||
{
|
||||
if((g_DSM_Entry.DSM_Entry=(DSMENTRYPROC)LOADFUNCTION(gpDSM, "DSM_Entry")) == 0)
|
||||
{
|
||||
#ifdef TWH_CMP_MSC // dlsym returning NULL is not an error on Unix
|
||||
cerr << "Error - Could not find DSM_Entry function in DSM: " << _pszLibName << endl;
|
||||
return false;
|
||||
#endif //TWH_CMP_MSC
|
||||
}
|
||||
#ifdef TWH_CMP_GNU
|
||||
if ((error = dlerror()) != 0)
|
||||
{
|
||||
cerr << "App - dlsym: " << error << endl;
|
||||
return false;
|
||||
}
|
||||
#endif //TWH_CMP_GNU
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "Error - Could not load DSM: " << _pszLibName << endl;
|
||||
#ifdef TWH_CMP_GNU
|
||||
cerr << "App - dlopen: " << dlerror() << endl;
|
||||
#endif //TWH_CMP_GNU
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
void unLoadDSMLib()
|
||||
{
|
||||
if(gpDSM)
|
||||
{
|
||||
memset(&g_DSM_Entry, 0, sizeof(TW_ENTRYPOINT));
|
||||
UNLOADLIBRARY(gpDSM);
|
||||
gpDSM = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
void setEntryPoints(pTW_ENTRYPOINT _pEntryPoints)
|
||||
{
|
||||
if(_pEntryPoints)
|
||||
{
|
||||
g_DSM_Entry = *_pEntryPoints;
|
||||
}
|
||||
else
|
||||
{
|
||||
memset(&g_DSM_Entry, 0, sizeof(TW_ENTRYPOINT));
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// The following functions are defined in the DSM2,
|
||||
// For backwards compatibiltiy on windows call the default function
|
||||
TW_HANDLE _DSM_Alloc(TW_UINT32 _size)
|
||||
{
|
||||
if(g_DSM_Entry.DSM_MemAllocate)
|
||||
{
|
||||
return g_DSM_Entry.DSM_MemAllocate(_size);
|
||||
}
|
||||
|
||||
#ifdef TWH_CMP_MSC
|
||||
return ::GlobalAlloc(GPTR, _size);
|
||||
#elif defined (TWNDS_OS_APPLE)
|
||||
return NewHandle(_size);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void _DSM_Free(TW_HANDLE _hMemory)
|
||||
{
|
||||
if(g_DSM_Entry.DSM_MemFree)
|
||||
{
|
||||
return g_DSM_Entry.DSM_MemFree(_hMemory);
|
||||
}
|
||||
|
||||
#ifdef TWH_CMP_MSC
|
||||
::GlobalFree(_hMemory);
|
||||
#elif defined (TWNDS_OS_APPLE)
|
||||
DisposeHandle(_hMemory);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
TW_MEMREF _DSM_LockMemory(TW_HANDLE _hMemory)
|
||||
{
|
||||
if(g_DSM_Entry.DSM_MemLock)
|
||||
{
|
||||
return g_DSM_Entry.DSM_MemLock(_hMemory);
|
||||
}
|
||||
|
||||
#ifdef TWH_CMP_MSC
|
||||
return (TW_MEMREF)::GlobalLock(_hMemory);
|
||||
#elif defined (TWNDS_OS_APPLE)
|
||||
return (TW_MEMREF)(*_hMemory);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
void _DSM_UnlockMemory(TW_HANDLE _hMemory)
|
||||
{
|
||||
if(g_DSM_Entry.DSM_MemUnlock)
|
||||
{
|
||||
return g_DSM_Entry.DSM_MemUnlock(_hMemory);
|
||||
}
|
||||
|
||||
#ifdef TWH_CMP_MSC
|
||||
::GlobalUnlock(_hMemory);
|
||||
#elif defined (TWNDS_OS_APPLE)
|
||||
// do nothing
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
125
DSMInterface.h
125
DSMInterface.h
|
@ -1,125 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright ?2007 TWAIN Working Group:
|
||||
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
|
||||
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
|
||||
* Ricoh Corporation, and Xerox Corporation.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the TWAIN Working Group nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* @file DSMInterface.h
|
||||
* Common defines and typedefs used for accessing DSM for TWAIN Data Sources.
|
||||
* @author TWAIN Working Group
|
||||
* @date April 2007
|
||||
*/
|
||||
|
||||
#ifndef __DSMINTERFACE_H__
|
||||
#define __DSMINTERFACE_H__
|
||||
|
||||
#include "CommonDS.h"
|
||||
|
||||
/**
|
||||
* Load the DSM library.
|
||||
* @param[in] the name of the DSM library to open
|
||||
* @return true if success.
|
||||
*/
|
||||
bool LoadDSMLib(char* _pszLibName);
|
||||
|
||||
/**
|
||||
* Unload the DSM library.
|
||||
*/
|
||||
void unLoadDSMLib();
|
||||
|
||||
/**
|
||||
* Initialize and register the entry point into the DSM.
|
||||
* @param[in] _pOrigin Identifies the source module of the message. This could
|
||||
* identify an Application, a Source, or the Source Manager.
|
||||
*
|
||||
* @param[in] _pDest Identifies the destination module for the message.
|
||||
* This could identify an application or a data source.
|
||||
* If this is NULL, the message goes to the Source Manager.
|
||||
*
|
||||
* @param[in] _DG The Data Group.
|
||||
* Example: DG_IMAGE.
|
||||
*
|
||||
* @param[in] _DAT The Data Attribute Type.
|
||||
* Example: DAT_IMAGEMEMXFER.
|
||||
*
|
||||
* @param[in] _MSG The message. Messages are interpreted by the destination module
|
||||
* with respect to the Data Group and the Data Attribute Type.
|
||||
* Example: MSG_GET.
|
||||
*
|
||||
* @param[in,out] _pData A pointer to the data structure or variable identified
|
||||
* by the Data Attribute Type.
|
||||
* Example: (TW_MEMREF)&ImageMemXfer
|
||||
* where ImageMemXfer is a TW_IMAGEMEMXFER structure.
|
||||
*
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
* Example: TWRC_SUCCESS.
|
||||
*/
|
||||
TW_UINT16 _DSM_Entry( pTW_IDENTITY _pOrigin,
|
||||
pTW_IDENTITY _pDest,
|
||||
TW_UINT32 _DG,
|
||||
TW_UINT16 _DAT,
|
||||
TW_UINT16 _MSG,
|
||||
TW_MEMREF _pData);
|
||||
|
||||
|
||||
/**
|
||||
* Set up the EntryPoints for memory and callback
|
||||
* @param[in] _pEntryPoints the structure for the entrypoints.
|
||||
*/
|
||||
void setEntryPoints(pTW_ENTRYPOINT _pEntryPoints);
|
||||
|
||||
/**
|
||||
* Allocate global memory
|
||||
* @param[in] _size of memory to allocate.
|
||||
* @return TW_HANDLE to the memory allocated.
|
||||
*/
|
||||
TW_HANDLE _DSM_Alloc(TW_UINT32 _size);
|
||||
|
||||
/**
|
||||
* Free previously allocated global memory
|
||||
* @param[in] _hMemory TW_HANDLE to the memory needing free.
|
||||
*/
|
||||
void _DSM_Free(TW_HANDLE _hMemory);
|
||||
|
||||
/**
|
||||
* Lock global memory from being updated by others. return a pointer to the
|
||||
* memory so we can update it.
|
||||
* @param[in] _hMemory TW_HANDLE to the memory to update.
|
||||
* @return TW_MEMREF pointer to the memory.
|
||||
*/
|
||||
TW_MEMREF _DSM_LockMemory(TW_HANDLE _hMemory);
|
||||
|
||||
/**
|
||||
* Unlock global memory after locking. to allow updating by others.
|
||||
* @param[in] _hMemory TW_HANDLE to memory returned by _DSM_Alloc
|
||||
*/
|
||||
void _DSM_UnlockMemory(TW_HANDLE _hMemory);
|
||||
|
||||
|
||||
#endif // __DSMINTERFACE_H__
|
BIN
FeederPaper.cpp
BIN
FeederPaper.cpp
Binary file not shown.
BIN
FeederPaper.h
BIN
FeederPaper.h
Binary file not shown.
553
GDevice.cpp
553
GDevice.cpp
|
@ -1,553 +0,0 @@
|
|||
#include "stdafx.h"
|
||||
#include "GDevice.h"
|
||||
#include "IUsb.h"
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <string.h>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include "StopWatch.h"
|
||||
#include "device_common.h"
|
||||
#include "GScan200.h"
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#define DSP_CODE_ADDR 0
|
||||
#define USER_ADDR 0x4000
|
||||
|
||||
using namespace std;
|
||||
//class GScan200;
|
||||
|
||||
|
||||
GDevice::GDevice(std::shared_ptr<IUsb> usb)
|
||||
{
|
||||
m_bScan = false;
|
||||
m_bListen = false;
|
||||
m_usb = usb;
|
||||
event_call = NULL;
|
||||
image_call = NULL;
|
||||
m_imagecall_userdata = NULL;
|
||||
m_eventcall_userdata = NULL;
|
||||
m_threadInt = NULL;
|
||||
m_threadrecv = NULL;
|
||||
m_run = false;
|
||||
}
|
||||
|
||||
GDevice::~GDevice()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
bool GDevice::open()
|
||||
{
|
||||
if (is_open())
|
||||
return true;
|
||||
|
||||
if (m_usb && m_usb->open()) {
|
||||
m_usb->set_timeout(1000);
|
||||
init_cam();
|
||||
m_bListen = true;
|
||||
m_bScan = true;
|
||||
|
||||
if (m_threadInt) {
|
||||
m_bListen = false;
|
||||
m_threadInt->join();
|
||||
}
|
||||
|
||||
if (m_threadrecv) {
|
||||
m_bScan = false;
|
||||
m_threadrecv->join();
|
||||
}
|
||||
m_bListen = true;
|
||||
m_bScan = true;
|
||||
m_threadInt = std::shared_ptr<std::thread>(new std::thread(&GDevice::Int_main, this));
|
||||
m_threadrecv = std::shared_ptr<std::thread>(new std::thread(&GDevice::recv_main, this));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void GDevice::close()
|
||||
{
|
||||
if (m_usb.get() && m_usb->is_open()) {
|
||||
m_usb->set_timeout(100);
|
||||
stop();
|
||||
|
||||
if (m_threadInt && m_threadInt->joinable()) {
|
||||
m_bListen = false;
|
||||
this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
XdPrint("closing m_threadInt\n");
|
||||
m_threadInt->join();
|
||||
m_threadInt = NULL;
|
||||
XdPrint("close m_threadInt\n");
|
||||
}
|
||||
|
||||
if (m_threadrecv && m_threadrecv->joinable()) {
|
||||
m_bScan = false;
|
||||
image_indexs.ShutDown();
|
||||
XdPrint("closing m_threadrecv\n");
|
||||
m_threadrecv->join();
|
||||
m_threadrecv = NULL;
|
||||
XdPrint("close m_threadrecv\n");
|
||||
}
|
||||
m_usb->close();
|
||||
XdPrint("close m_usb\n");
|
||||
}
|
||||
}
|
||||
|
||||
bool GDevice::is_open()
|
||||
{
|
||||
if (m_usb.get())
|
||||
return m_usb->is_open();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GDevice::start(image_callback callfunc, void* userdata)
|
||||
{
|
||||
if (is_run())
|
||||
return false;
|
||||
|
||||
image_call = callfunc;
|
||||
m_imagecall_userdata = userdata;
|
||||
MotorSetting ms;
|
||||
ms.value = read_reg(MOTOR_BOARD, 0x00);
|
||||
ms.scan_enable = 0;
|
||||
write_reg(MOTOR_BOARD, 0x00, ms.value);
|
||||
ms.scan_enable = 1;
|
||||
write_reg(MOTOR_BOARD, 0x00, ms.value);
|
||||
m_run = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void GDevice::set_event_call(event_callback callfunc, void* userdata)
|
||||
{
|
||||
m_eventcall_userdata = userdata;
|
||||
event_call = callfunc;
|
||||
}
|
||||
|
||||
void GDevice::stop()
|
||||
{
|
||||
set_option(Cam_Options::scanner_stop_motor, 0);
|
||||
}
|
||||
|
||||
int GDevice::is_run()
|
||||
{
|
||||
return m_run;
|
||||
}
|
||||
|
||||
void GDevice::reset()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static std::string read_all_from(std::string path)
|
||||
{
|
||||
int t;
|
||||
FILE* file = fopen(path.c_str(), "rb");
|
||||
fseek(file, 0, SEEK_END);
|
||||
t = ftell(file);
|
||||
std::string buf(t, 0);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
fread((void*)buf.c_str(), t, 1, file);
|
||||
fclose(file);
|
||||
return buf;
|
||||
}
|
||||
|
||||
void GDevice::write_dsp_fw(std::string path)
|
||||
{
|
||||
std::string buf = read_all_from(path);
|
||||
write_flash(DSP_CODE_ADDR, (void*)buf.c_str(), buf.size());
|
||||
}
|
||||
|
||||
void GDevice::write_pid(unsigned short pid)
|
||||
{
|
||||
write_flash(PID_ADDR, &pid, sizeof(pid));
|
||||
}
|
||||
|
||||
unsigned short GDevice::read_pid()
|
||||
{
|
||||
unsigned short pid;
|
||||
read_flash(PID_ADDR, &pid, sizeof(pid));
|
||||
return pid;
|
||||
}
|
||||
|
||||
|
||||
void GDevice::write_devname(std::string name)
|
||||
{
|
||||
if (name.size() > 64)
|
||||
return;
|
||||
|
||||
write_flash(DEVNAME_ADDR, (void*)name.c_str(), name.size());
|
||||
}
|
||||
|
||||
std::string GDevice::read_devname()
|
||||
{
|
||||
char devname[65] = {0};
|
||||
read_flash(DEVNAME_ADDR, devname, sizeof(devname) - 1);
|
||||
return devname;
|
||||
}
|
||||
|
||||
bool GDevice::write_flash(unsigned int addr, void* data, int size)
|
||||
{
|
||||
unsigned int writeAddr = addr;
|
||||
int writed = 0;
|
||||
int writing = 0;
|
||||
while (writed < size) {
|
||||
writing = min(crtlBufferSize, size - writed);
|
||||
writeAddr = addr + writed;
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(m_mtxCtrl);
|
||||
m_usb->control_msg(to_device, flash_access, ((Reg2Short*)&writeAddr)->short2, ((Reg2Short*)&writeAddr)->short1, writing, (unsigned char*)data + writed);
|
||||
}
|
||||
writed += writing;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GDevice::read_flash(unsigned int addr, void* data, int size)
|
||||
{
|
||||
unsigned int readAddr = addr;
|
||||
int readed = 0;
|
||||
int reading = 0;
|
||||
while (readed < size) {
|
||||
reading = min(crtlBufferSize, size - readed);
|
||||
readAddr = addr + readed;
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(m_mtxCtrl);
|
||||
m_usb->control_msg(from_device, flash_access, ((Reg2Short*)&readAddr)->short2, ((Reg2Short*)&readAddr)->short1, reading, (unsigned char*)data + readed);
|
||||
}
|
||||
readed += reading;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const int int_buffer_size = 1024;
|
||||
int index_count = 0;
|
||||
static void write_log(std::string fullname, std::string log)
|
||||
{
|
||||
std::string savepath;
|
||||
savepath = fullname;
|
||||
std::ofstream ofs(savepath, std::ios::app);
|
||||
|
||||
SYSTEMTIME sys;
|
||||
GetLocalTime(&sys);
|
||||
ofs << sys.wYear << "/" << sys.wMonth << "/" << sys.wDay << " " << sys.wHour << ":" << sys.wMinute << ":" << sys.wSecond << ":" << sys.wMilliseconds << " " << log << std::endl;
|
||||
}
|
||||
int image_index_c = 0;
|
||||
void GDevice::recv_main()
|
||||
{
|
||||
const double timeout_ratio = (1000.0 / (15.0 * 1024 * 1024)); //!< s / Mbyte
|
||||
int image_index = 0;
|
||||
int buffer_size = 0;
|
||||
int b_buffer_size = 0;
|
||||
int f_buffer_size = 0;
|
||||
unsigned char* bbuf = 0;
|
||||
unsigned char* fbuf = 0;
|
||||
unsigned char* buf;
|
||||
int buffer_reading = 0;
|
||||
int buffer_readed = 0;
|
||||
const int read_timeout = 5000;
|
||||
std::vector<unsigned char> image_data;
|
||||
StopWatch sw;
|
||||
while (m_bScan) {
|
||||
image_index = image_indexs.Take();
|
||||
if (!image_indexs.IsShutDown() && image_index >= 0)
|
||||
{
|
||||
buffer_reading = 0;
|
||||
buffer_readed = 0;
|
||||
buffer_size = frame_size(image_index);
|
||||
image_data.resize(buffer_size * 2 + int_buffer_size);
|
||||
buf = image_data.data() + int_buffer_size;
|
||||
|
||||
sw.reset();
|
||||
while (sw.elapsed_ms() < read_timeout) {
|
||||
while (DataOn() && sw.elapsed_ms() < read_timeout);
|
||||
read_frame(image_index, buffer_readed);
|
||||
buffer_reading = max(0, buffer_size - buffer_readed);
|
||||
buffer_reading = read_data(buf + buffer_readed, buffer_reading, (int)(buffer_reading * timeout_ratio));
|
||||
if (buffer_reading > 0)
|
||||
buffer_readed += buffer_reading;
|
||||
|
||||
if (buffer_readed >= buffer_size) {
|
||||
write_log("d:\\1.txt", std::to_string(image_index_c) + " time1 = " + std::to_string(sw.elapsed_ms()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
image_index_c++;
|
||||
if (buffer_readed != buffer_size)
|
||||
{
|
||||
write_log("d:\\1.txt", std::to_string(image_index_c) + " error readed:" + std::to_string(buffer_readed) + " per read:" + std::to_string(buffer_size) + " time = " + std::to_string(sw.elapsed_ms()));
|
||||
}
|
||||
else {
|
||||
write_log("d:\\1.txt", std::to_string(image_index_c) + " get" + " time = " + std::to_string(sw.elapsed_ms()));
|
||||
}
|
||||
|
||||
b_buffer_size = 0;
|
||||
f_buffer_size = 0;
|
||||
bbuf = buf - int_buffer_size;
|
||||
fbuf = buf + buffer_size;
|
||||
for (int i = 0; i < (buffer_size / int_buffer_size); i++)
|
||||
{
|
||||
if (buf[(i + 1) * int_buffer_size - 1] == 0)
|
||||
{
|
||||
memcpy(bbuf + b_buffer_size, buf + i * int_buffer_size, int_buffer_size - 1);
|
||||
b_buffer_size += (int_buffer_size - 1);
|
||||
}
|
||||
else if (buf[(i + 1) * int_buffer_size - 1] == 255)
|
||||
{
|
||||
memcpy(fbuf + f_buffer_size, buf + i * int_buffer_size, int_buffer_size - 1);
|
||||
f_buffer_size += (int_buffer_size - 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (image_call)
|
||||
{
|
||||
if ((bbuf != NULL && b_buffer_size > 0)&&(fbuf != NULL && f_buffer_size > 0))
|
||||
{
|
||||
image_call(bbuf, b_buffer_size, fbuf, f_buffer_size, m_imagecall_userdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GDevice::Int_main()
|
||||
{
|
||||
unsigned int int_buffer[4];
|
||||
int size = 0;
|
||||
while (m_bListen) {
|
||||
size = m_usb->read_int(int_buffer, sizeof(int_buffer));
|
||||
if (size >= 16)
|
||||
{
|
||||
if (int_buffer[2] != 0)
|
||||
{
|
||||
image_indexs.Put(int_buffer[1]);
|
||||
}
|
||||
MotorStatus* ms = (MotorStatus*)int_buffer;
|
||||
|
||||
//int ret = get_option(Cam_Options::scanner_scan_status);
|
||||
//XdPrint("scanner_scan_status %d \n",ret);
|
||||
//if (!ret)//电机板工作中
|
||||
//{
|
||||
// XdPrint("scanner stoped 1\n");
|
||||
// ((GScan200*)m_eventcall_userdata)->set_scan_status(false);//停止或异常停止时,通知图像处理线程扫描仪已停止
|
||||
// m_run = false;
|
||||
// XdPrint("scanner stoped 2\n");
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// XdPrint("scanner is scanning \n");
|
||||
//}
|
||||
//if (ms->value && 0x7fe) {
|
||||
// if(m_eventcall_userdata){
|
||||
//
|
||||
// }
|
||||
|
||||
//}
|
||||
if (event_call)
|
||||
{
|
||||
//0x3fe ==>b 1111 1111 10 异常位高有效时
|
||||
if (ms->value & 0x3fe) {
|
||||
((GScan200*)m_eventcall_userdata)->set_scan_status(false);
|
||||
event_call(ms->value, m_eventcall_userdata);
|
||||
m_run = false;
|
||||
XdPrint("scanner have error stoped \n");
|
||||
}
|
||||
}
|
||||
}
|
||||
int ret = get_option(Cam_Options::scanner_scan_status);
|
||||
if (m_run&&!ret)//电机板工作中
|
||||
{
|
||||
XdPrint("scanner stoped 1\n");
|
||||
((GScan200*)m_eventcall_userdata)->set_scan_status(false);//停止或异常停止时,通知图像处理线程扫描仪已停止
|
||||
m_run = false;
|
||||
XdPrint("scanner stoped 2\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GDevice::init_cam()
|
||||
{
|
||||
}
|
||||
|
||||
int GDevice::read_data(void* data, int length, int timeout)
|
||||
{
|
||||
int readed = 0;
|
||||
int reading = 0;
|
||||
StopWatch sw;
|
||||
while (readed < length && sw.elapsed_ms() < timeout) {
|
||||
reading = max(0, min(length - readed, buffer_size));
|
||||
reading = m_usb->read_bulk((unsigned char*)data + readed, reading);
|
||||
if (reading > 0) {
|
||||
readed += reading;
|
||||
}
|
||||
}
|
||||
return readed;
|
||||
}
|
||||
|
||||
void GDevice::read_frame(int index, int offset)
|
||||
{
|
||||
write_reg(3, index, offset);
|
||||
}
|
||||
|
||||
int GDevice::frame_size(int index)
|
||||
{
|
||||
return read_reg(3, index);
|
||||
}
|
||||
|
||||
int GDevice::read_reg(int type, int addr)
|
||||
{
|
||||
int value;
|
||||
std::lock_guard<std::mutex> lck(m_mtxCtrl);
|
||||
m_usb->control_msg(from_device, regs_access, type, addr, sizeof(value), &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
void GDevice::write_reg(int type, int addr, int value)
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(m_mtxCtrl);
|
||||
m_usb->control_msg(to_device, regs_access, type, addr, sizeof(value), &value);
|
||||
}
|
||||
|
||||
void GDevice::set_option(Cam_Options option, unsigned int value)
|
||||
{
|
||||
unsigned int val = 0;
|
||||
switch (option)
|
||||
{
|
||||
case scanner_config:
|
||||
write_reg(USERDEFINE, ModeParam, value);
|
||||
break;
|
||||
case scanner_scan_skrew:
|
||||
val = read_reg(MOTOR_BOARD, 0x00);
|
||||
((MotorSetting*)& val)->skew_enable = value;
|
||||
write_reg(MOTOR_BOARD, 0x00, val);
|
||||
break;
|
||||
case scanner_stample_enable:
|
||||
val = read_reg(MOTOR_BOARD, 0x00);
|
||||
((MotorSetting*)& val)->staple_enable = value;
|
||||
write_reg(MOTOR_BOARD, 0x00, val);
|
||||
break;
|
||||
case scanner_doublePape_enable:
|
||||
val = read_reg(MOTOR_BOARD, 0x00);
|
||||
((MotorSetting*)& val)->double_paper = value;
|
||||
write_reg(MOTOR_BOARD, 0x00, val);
|
||||
break;
|
||||
case scanner_stop_motor:
|
||||
val = read_reg(MOTOR_BOARD, 0x00);
|
||||
((MotorSetting*)& val)->scan_enable = value;
|
||||
write_reg(MOTOR_BOARD, 0x00, val);
|
||||
break;
|
||||
case scanner_error_clean:
|
||||
val = read_reg(MOTOR_BOARD, 0x00);
|
||||
((MotorSetting*)& val)->error_clean = value;
|
||||
write_reg(MOTOR_BOARD, 0x00, val);
|
||||
break;
|
||||
case scanner_Init_Status:
|
||||
val = read_reg(MOTOR_BOARD, 0x00);
|
||||
((MotorSetting*)& val)->status_init = value;
|
||||
write_reg(MOTOR_BOARD, 0x00, val);
|
||||
break;
|
||||
case scanner_IIC_Config:
|
||||
val = read_reg(MOTOR_BOARD, 0x00);
|
||||
((MotorSetting*)& val)->iic_config = value;
|
||||
write_reg(MOTOR_BOARD, 0x00, val);
|
||||
break;
|
||||
case scanner_Speed_Config:
|
||||
val = read_reg(MOTOR_BOARD, 0x00);
|
||||
((MotorSetting*)& val)->speed_set_enable = value;
|
||||
write_reg(MOTOR_BOARD, 0x00, val);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int GDevice::get_option(Cam_Options option)
|
||||
{
|
||||
int value = 0;
|
||||
switch (option)
|
||||
{
|
||||
case scanner_cover_status:
|
||||
value = read_reg(1, 0x01);
|
||||
value = ((MotorStatus*)& value)->open_machine;
|
||||
break;
|
||||
case scanner_pick_paper_stauts:
|
||||
value = read_reg(1, 0x01);
|
||||
value = ((MotorStatus*)& value)->pick_failed;
|
||||
break;
|
||||
case scanner_jam_stauts:
|
||||
value = read_reg(1, 0x01);
|
||||
value = ((MotorStatus*)& value)->stop_jam;
|
||||
break;
|
||||
case scanner_paper_count:
|
||||
value = read_reg(1, 0x02);
|
||||
value = ((MotorMode*)& value)->scan_num;
|
||||
break;
|
||||
case scanner_double_paper:
|
||||
value = read_reg(1, 0x01);
|
||||
value= ((MotorStatus*)& value)->double_paper;
|
||||
break;
|
||||
case scanner_staple_state:
|
||||
value = read_reg(1, 0x01);
|
||||
value = ((MotorStatus*)& value)->staple;
|
||||
break;
|
||||
case scanner_skrew_state:
|
||||
value = read_reg(1, 0x01);
|
||||
value = ((MotorStatus*)& value)->papertilted;
|
||||
break;
|
||||
case scanner_paper_have:
|
||||
value = read_reg(MOTOR_BOARD, 0x02);
|
||||
value = ((Motor_Mode*)& value)->feeding_paper_ready;
|
||||
break;
|
||||
case scanner_scan_status:
|
||||
value = read_reg(MOTOR_BOARD, 0x02);
|
||||
value = ((Motor_Mode*)& value)->scan_status;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
std::vector<Cam_Options> GDevice::support_options()
|
||||
{
|
||||
std::set<Cam_Options> options;
|
||||
options.insert(Cam_Options::scanner_exposure_blue);
|
||||
options.insert(Cam_Options::scanner_exposure_gray);
|
||||
options.insert(Cam_Options::scanner_exposure_red);
|
||||
|
||||
return std::vector<Cam_Options>(options.begin(), options.end());
|
||||
}
|
||||
|
||||
void GDevice::pick_paper(void)
|
||||
{
|
||||
MotorSetting ms;
|
||||
ms.value = read_reg(MOTOR_BOARD, 0x00);
|
||||
ms.pick_paper = 0;
|
||||
write_reg(MOTOR_BOARD, 0x00, ms.value);
|
||||
ms.pick_paper = 1;
|
||||
write_reg(MOTOR_BOARD, 0x00, ms.value);
|
||||
}
|
||||
|
||||
void GDevice::trigger_scan(void)
|
||||
{
|
||||
ScanTriger st;
|
||||
st.value = 0;
|
||||
write_reg(MAIN_BOARD, 0x02, st.value);
|
||||
st.triger = 1;
|
||||
write_reg(MAIN_BOARD, 0x02, st.value);
|
||||
}
|
||||
|
||||
bool GDevice::DataOn()
|
||||
{
|
||||
return read_reg(USERDEFINE, IMAGEREGS);
|
||||
}
|
88
GDevice.h
88
GDevice.h
|
@ -1,88 +0,0 @@
|
|||
#pragma once
|
||||
#include "IGDevice.h"
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include "BlockingQueue.h"
|
||||
#include <string>
|
||||
|
||||
class IUsb;
|
||||
class GDevice : public IGDevice
|
||||
{
|
||||
public:
|
||||
GDevice(std::shared_ptr<IUsb> usb);
|
||||
virtual ~GDevice();
|
||||
// ͨ¹ý IGDevice ¼Ì³Ð
|
||||
virtual bool open() override;
|
||||
virtual void close() override;
|
||||
virtual bool is_open() override;
|
||||
bool start(image_callback callfunc, void* userdata);
|
||||
void set_event_call(event_callback event_callfunc, void* userdata);
|
||||
virtual void stop() override;
|
||||
virtual int is_run() override;
|
||||
virtual void reset() override;
|
||||
|
||||
void write_dsp_fw(std::string path);
|
||||
|
||||
void write_devname(std::string name);
|
||||
std::string read_devname();
|
||||
|
||||
void write_reg(int type, int addr, int value);
|
||||
int read_reg(int type, int addr);
|
||||
|
||||
bool write_flash(unsigned int addr, void* data, int size);
|
||||
bool read_flash(unsigned int addr, void* data, int size);
|
||||
|
||||
void trigger_scan(void);
|
||||
|
||||
void write_pid(unsigned short pid);
|
||||
unsigned short read_pid();
|
||||
|
||||
private:
|
||||
void recv_main();
|
||||
void Int_main();
|
||||
|
||||
void init_cam();
|
||||
|
||||
int read_data(void* data, int lenght, int timeout);
|
||||
void read_frame(int index, int offset);
|
||||
int frame_size(int index);
|
||||
|
||||
|
||||
|
||||
|
||||
void pick_paper(void);
|
||||
|
||||
bool DataOn();
|
||||
|
||||
std::shared_ptr<IUsb> m_usb;
|
||||
const int buffer_size = 1204 * 1024;
|
||||
const int crtlBufferSize = 512;
|
||||
volatile bool m_bScan;
|
||||
volatile bool m_bListen;
|
||||
|
||||
std::shared_ptr<std::thread> m_threadInt;
|
||||
std::shared_ptr<std::thread> m_threadrecv;
|
||||
std::mutex m_mtxInt;
|
||||
std::mutex m_mtxCtrl;
|
||||
image_callback image_call;
|
||||
event_callback event_call;
|
||||
const int to_device = 0x40;
|
||||
const int from_device = 0xc0;
|
||||
const int regs_access = 0x0c;
|
||||
const int flash_access = 0x04;
|
||||
|
||||
const int regs_req = 0x0c;
|
||||
|
||||
BlockingQueue<int> image_indexs;
|
||||
|
||||
void* m_imagecall_userdata;
|
||||
void* m_eventcall_userdata;
|
||||
volatile bool m_run;
|
||||
|
||||
|
||||
// ͨ¹ý IGDevice ¼Ì³Ð
|
||||
virtual void set_option(Cam_Options option,unsigned int value) override;
|
||||
virtual int get_option(Cam_Options option) override;
|
||||
virtual std::vector<Cam_Options> support_options() override;
|
||||
};
|
|
@ -1,19 +0,0 @@
|
|||
#include "stdafx.h"
|
||||
#include "GDeviceLists.h"
|
||||
#include "UsbScanEx.h"
|
||||
#include "GDevice.h"
|
||||
|
||||
|
||||
std::list<std::shared_ptr<IGDevice>> HGDeviceLists::FindAll()
|
||||
{
|
||||
std::list<std::shared_ptr<IGDevice>> cameraLists;
|
||||
|
||||
// std::list<std::shared_ptr<IUsb>> usbs = CyUsbList::find_vid_pid(0x04b4, 0x1004);
|
||||
std::list<std::shared_ptr<IUsb>> usbs = UsbScan_List::find_vid_pid(0x064b, 0x7823);
|
||||
|
||||
|
||||
for (auto i = usbs.begin(); i != usbs.end(); i++)
|
||||
cameraLists.push_back(std::shared_ptr<IGDevice>(new GDevice(*i)));
|
||||
|
||||
return cameraLists;
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
#pragma once
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
|
||||
class IGDevice;
|
||||
|
||||
class HGDeviceLists
|
||||
{
|
||||
public:
|
||||
static std::list<std::shared_ptr<IGDevice>> FindAll();
|
||||
};
|
189
GScan200.cpp
189
GScan200.cpp
|
@ -1,189 +0,0 @@
|
|||
#include "stdafx.h"
|
||||
#include "GScan200.h"
|
||||
#include "GDeviceLists.h"
|
||||
#include "IGDevice.h"
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include "twain.h"
|
||||
#include "config_new.h"
|
||||
#include "device_common.h"
|
||||
#include "GDevice.h"
|
||||
|
||||
GScan200::GScan200()
|
||||
{
|
||||
}
|
||||
|
||||
GScan200::~GScan200()
|
||||
{
|
||||
if (!error_msg.IsShutDown())
|
||||
error_msg.ShutDown();
|
||||
XdPrint("closed GScan200\n");
|
||||
}
|
||||
|
||||
void GScan200::open(int vid, int pid)
|
||||
{
|
||||
auto devs = HGDeviceLists::FindAll();
|
||||
if(!devs.empty()){
|
||||
m_dev = *(devs.begin());
|
||||
m_dev->open();
|
||||
}
|
||||
}
|
||||
|
||||
int GScan200::aquire_image(cv::Mat& image)
|
||||
{
|
||||
while (true) {
|
||||
if (m_dev && Get_IsImageQueueEmpty()) {
|
||||
DoEvents();
|
||||
if (!is_scan())
|
||||
{
|
||||
if (error_msg.Size()>0)
|
||||
{
|
||||
return error_msg.Take();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (m_pImages.valid()) {
|
||||
image = popMat();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL GScan200::IsConnected()
|
||||
{
|
||||
return m_dev && m_dev->is_open();
|
||||
}
|
||||
|
||||
std::string GScan200::GetFWVersion()
|
||||
{
|
||||
if (fwVersion.empty()) {
|
||||
fwVersion.resize(8);
|
||||
((GDevice*)(m_dev.get()))->read_flash(FWVERSION_ADDR, (void*)(fwVersion.data()), FLASH_FWVERSION_ADDR_SIZE);
|
||||
}
|
||||
return fwVersion;
|
||||
}
|
||||
|
||||
std::string GScan200::GetSerialNum()
|
||||
{
|
||||
if (SerialNum.empty()) {
|
||||
SerialNum.resize(12);
|
||||
((GDevice*)(m_dev.get()))->read_flash(SERIAL_ADDR, (void*)(SerialNum.data()), FLASH_SERIAL_ADDR_SIZE);
|
||||
}
|
||||
return SerialNum;
|
||||
}
|
||||
|
||||
bool GScan200::is_scan()
|
||||
{
|
||||
return m_dev && m_dev->is_run();
|
||||
}
|
||||
|
||||
BOOL GScan200::Get_Scanner_PaperOn()
|
||||
{
|
||||
return m_dev->get_option(Cam_Options::scanner_paper_have);
|
||||
}
|
||||
|
||||
void GScan200::config_params(SFreeImage& params)
|
||||
{
|
||||
config_new cfn(params);
|
||||
unsigned int cfg_value=cfn.GetData();
|
||||
m_dev->set_option(Cam_Options::scanner_config, cfg_value);
|
||||
m_pImages.setparam(params);
|
||||
}
|
||||
|
||||
void GScan200::Scanner_StartScan(UINT16 count)
|
||||
{
|
||||
m_dev->start(image_call_s, this);
|
||||
m_dev->set_event_call(event_call_g200, this);
|
||||
m_pImages.SetScanningStatus(true);
|
||||
}
|
||||
|
||||
void GScan200::Stop_scan()
|
||||
{
|
||||
m_dev->stop();
|
||||
}
|
||||
|
||||
void GScan200::ResetScanner()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool GScan200::Get_IsImageQueueEmpty()
|
||||
{
|
||||
return m_pImages.empty();
|
||||
}
|
||||
|
||||
void GScan200::reset()
|
||||
{
|
||||
if (m_dev) {
|
||||
m_dev->stop();
|
||||
this_thread::sleep_for(chrono::milliseconds(200));
|
||||
m_pImages.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void GScan200::setdecodepixtype(int twpixtype)
|
||||
{
|
||||
pixType = (twpixtype == TWPT_RGB) ? TJPF_BGR : TJPF_GRAY;
|
||||
}
|
||||
|
||||
UINT32 GScan200::get_ErrorCode()
|
||||
{
|
||||
return UINT32();
|
||||
}
|
||||
|
||||
void GScan200::Set_ErrorCode(UINT32 value)
|
||||
{
|
||||
error_msg.Clear();
|
||||
}
|
||||
|
||||
int GScan200::get_scanned_num()
|
||||
{
|
||||
int scanned_count = 0;
|
||||
((GDevice*)(m_dev.get()))->read_flash(CONT_ADDR, &scanned_count, FLASH_CONT_ADDR_SIZE);
|
||||
return scanned_count;
|
||||
}
|
||||
|
||||
void GScan200::set_scan_status(bool isscan)
|
||||
{
|
||||
m_pImages.SetScanningStatus(isscan);
|
||||
}
|
||||
|
||||
void GScan200::image_call_s(void* fdata, int fsize, void* bdata, int bsize, void* userdata)
|
||||
{
|
||||
GScan200* This = (GScan200*)userdata;
|
||||
This->image_call(fdata, fsize, bdata, bsize);
|
||||
}
|
||||
|
||||
void GScan200::event_call_g200(int error_value, void* userdata)
|
||||
{
|
||||
GScan200* This = (GScan200*)userdata;
|
||||
if (!This->error_msg.IsShutDown())
|
||||
{
|
||||
MotorStatus ms;
|
||||
ms.value = error_value;
|
||||
if (ms.double_paper == 1) { This->error_msg.Put(DETECT_DOUBLE_FEED); };//error_msg.Put(DETECT_DOUBLE_FEED);
|
||||
if (ms.open_machine == 1) { This->error_msg.Put(OPEN_COVER); };//error_msg.Put(OPEN_COVER);
|
||||
if (ms.m1_paper_sin == 1) { This->error_msg.Put(NO_FEED); };//error_msg.Put(NO_FEED);
|
||||
if (ms.pick_failed == 1) { This->error_msg.Put(FEED_IN_ERROR); };//error_msg.Put(FEED_IN_ERROR);
|
||||
if (ms.stop_jam == 1) { This->error_msg.Put(PAPER_JAM); };//error_msg.Put(PAPER_JAM);
|
||||
if (ms.staple == 1) { This->error_msg.Put(DETECT_STAPLE); };//error_msg.Put(DETECT_STAPLE);
|
||||
if (ms.scan_mode_change == 1) { This->error_msg.Put(DETECT_STAPLE); };//error_msg.Put(DETECT_STAPLE);
|
||||
if (ms.papertilted == 1) { This->error_msg.Put(PAPER_SKEW); };//error_msg.Put(PAPER_SKEW);
|
||||
}
|
||||
}
|
||||
|
||||
void GScan200::image_call(void* fdata, int fsize, void* bdata, int bsize)
|
||||
{
|
||||
if (fdata && fsize && bdata && bsize)
|
||||
{
|
||||
cv::Mat fmat(1, fsize, CV_8UC1, fdata);
|
||||
cv::Mat bmat(1, bsize, CV_8UC1, bdata);
|
||||
std::vector<cv::Mat> mats;
|
||||
mats.push_back(fmat.clone());
|
||||
mats.push_back(bmat.clone());
|
||||
m_pImages.pushMat(JpegBuffer(mats, pixType, 0));
|
||||
}
|
||||
}
|
36
GScan200.h
36
GScan200.h
|
@ -1,36 +0,0 @@
|
|||
#pragma once
|
||||
#include "gscn_drv.h"
|
||||
#include <memory>
|
||||
|
||||
class IGDevice;
|
||||
|
||||
class GScan200 : public IGScan, GScn_Drv
|
||||
{
|
||||
public:
|
||||
GScan200();
|
||||
virtual ~GScan200();
|
||||
virtual void open(int vid, int pid) override;
|
||||
virtual int aquire_image(cv::Mat &image) override;
|
||||
virtual BOOL IsConnected() override;
|
||||
virtual std::string GetFWVersion() override;
|
||||
virtual std::string GetSerialNum() override;
|
||||
virtual bool is_scan() override;
|
||||
virtual BOOL Get_Scanner_PaperOn() override;
|
||||
virtual void config_params(SFreeImage ¶ms) override;
|
||||
virtual void Scanner_StartScan(UINT16 count) override;
|
||||
virtual void Stop_scan() override;
|
||||
virtual void ResetScanner() override;
|
||||
virtual bool Get_IsImageQueueEmpty() override;
|
||||
virtual void reset() override;
|
||||
virtual void setdecodepixtype(int twpixtype) override;
|
||||
virtual UINT32 get_ErrorCode() override;
|
||||
virtual void Set_ErrorCode(UINT32 value) override;
|
||||
virtual int get_scanned_num() override;
|
||||
void set_scan_status(bool isscan);
|
||||
private:
|
||||
static void image_call_s(void *fdata, int fsize, void *bdata, int bsize, void *userdata);
|
||||
static void event_call_g200(int error_value, void* userdata);
|
||||
void image_call(void *fdata, int fsize, void *bdata, int bsize);
|
||||
BlockingQueue<int> error_msg;
|
||||
std::shared_ptr<IGDevice> m_dev;
|
||||
};
|
351
GScanO200.cpp
351
GScanO200.cpp
|
@ -1,351 +0,0 @@
|
|||
#include "stdafx.h"
|
||||
#include "GScanO200.h"
|
||||
#include "UsbScanEx.h"
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include "twain.h"
|
||||
#include "UsbScanEx.h"
|
||||
#include "StopWatch.h"
|
||||
|
||||
GScanO200::GScanO200()
|
||||
{
|
||||
}
|
||||
|
||||
GScanO200::~GScanO200()
|
||||
{
|
||||
if (m_threadUsb && m_threadUsb->joinable()) {
|
||||
devState = DEV_STOP;
|
||||
m_threadUsb->join();
|
||||
m_threadUsb.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void GScanO200::open(int vid, int pid)
|
||||
{
|
||||
auto usbs = UsbScan_List::find_vid_pid(vid, pid);
|
||||
|
||||
if (!usbs.empty()) {
|
||||
m_usb = *usbs.begin();
|
||||
m_usb->open();
|
||||
}
|
||||
}
|
||||
|
||||
int GScanO200::aquire_image(cv::Mat& image)
|
||||
{
|
||||
StopWatch sw;
|
||||
sw.reset();
|
||||
double timeout;
|
||||
while (true)
|
||||
{
|
||||
if (Get_IsImageQueueEmpty())
|
||||
{
|
||||
DoEvents();
|
||||
if (sw.elapsed_s() > 15.00)
|
||||
{
|
||||
if (m_threadUsb && m_threadUsb->joinable()) {
|
||||
devState = DEV_STOP;
|
||||
m_threadUsb->join();
|
||||
m_threadUsb.reset();
|
||||
}
|
||||
m_pImages.release_img_prc_thread();//释放图像处理线程
|
||||
Stop_scan();//停止扫描
|
||||
ResetScanner();
|
||||
return HARDWARE_ERROR;
|
||||
}
|
||||
|
||||
if (!is_scan())
|
||||
{
|
||||
if (devState == DEV_WRONG)
|
||||
{
|
||||
return get_ErrorCode();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (m_pImages.valid())
|
||||
{
|
||||
image = popMat();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOL GScanO200::IsConnected()
|
||||
{
|
||||
return m_usb && m_usb->is_connected();
|
||||
}
|
||||
|
||||
std::string GScanO200::GetFWVersion()
|
||||
{
|
||||
if (m_usb&&m_usb->is_connected())
|
||||
{
|
||||
lock_guard< mutex> lock(m_imgLocker);
|
||||
if (fwVersion.empty()) {
|
||||
fwVersion = " ";
|
||||
USBCB cmd= { GET_FW_VERSION,8,0,};
|
||||
m_usb->write_bulk(&cmd, sizeof(cmd));
|
||||
m_usb->read_bulk(&fwVersion[0], 8);
|
||||
}
|
||||
return fwVersion;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string GScanO200::GetSerialNum()
|
||||
{
|
||||
if (m_usb->is_connected())
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(m_imgLocker);
|
||||
if (SerialNum.empty())
|
||||
{
|
||||
SerialNum = " ";
|
||||
USBCB usbcb = { GET_SERIAL,12,0 };
|
||||
m_usb->write_bulk(&usbcb, sizeof(usbcb));
|
||||
m_usb->read_bulk(&SerialNum[0], 12);
|
||||
}
|
||||
return SerialNum;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
bool GScanO200::is_scan()
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(m_imgLocker);
|
||||
return devState == DEV_ISRUNNING;
|
||||
}
|
||||
|
||||
BOOL GScanO200::Get_Scanner_PaperOn()
|
||||
{
|
||||
if (!m_usb->is_open())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
USBCB usbcb = { GET_PAPER_STATUS ,0,0 };
|
||||
std::lock_guard<std::mutex> lck(m_imgLocker);
|
||||
m_usb->write_bulk(&usbcb, sizeof(usbcb));
|
||||
m_usb->read_bulk(&usbcb, sizeof(usbcb));
|
||||
return usbcb.u32_Data != 0;
|
||||
}
|
||||
|
||||
void GScanO200::config_params(SFreeImage& params)
|
||||
{
|
||||
if (m_usb->is_connected())
|
||||
{
|
||||
hgConfigClass cfg(params);
|
||||
UINT32 cfgdata = cfg.GetData();
|
||||
USBCB usbcb = { CONFIGURED_DATA,cfgdata,0 };
|
||||
m_usb->write_bulk(&usbcb, sizeof(USBCB));
|
||||
setdecodepixtype(params.m_HardWareParams.PixType);
|
||||
m_pImages.setparam(params);
|
||||
}
|
||||
}
|
||||
|
||||
void GScanO200::Scanner_StartScan(UINT16 count)
|
||||
{
|
||||
if (m_usb->is_connected())
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(m_imgLocker);
|
||||
USBCB usbcb = { START_COMMAND,(UINT32)count ,0 };
|
||||
m_usb->write_bulk(&usbcb, sizeof(usbcb));
|
||||
if (m_threadUsb && m_threadUsb->joinable()) {
|
||||
m_threadUsb->join();
|
||||
}
|
||||
m_threadUsb.reset(new std::thread(&GScanO200::usbmain, this));
|
||||
m_pImages.SetScanningStatus(true);
|
||||
m_pImages.run();
|
||||
}
|
||||
}
|
||||
|
||||
void GScanO200::Stop_scan()
|
||||
{
|
||||
if (!m_usb->is_connected())
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lck(m_imgLocker);
|
||||
USBCB usbcb = { STOP ,0,0 };
|
||||
m_usb->write_bulk(&usbcb, sizeof(usbcb));
|
||||
}
|
||||
|
||||
void GScanO200::ResetScanner()
|
||||
{
|
||||
if (!m_usb->is_connected())
|
||||
return;
|
||||
|
||||
std::lock_guard<std::mutex> lck(m_imgLocker);
|
||||
USBCB usbcb = { INIT_HARDWARE_SYS ,0,0 };
|
||||
m_usb->write_bulk(&usbcb, sizeof(usbcb));
|
||||
}
|
||||
|
||||
bool GScanO200::Get_IsImageQueueEmpty()
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(m_imgLocker);
|
||||
return m_pImages.empty();
|
||||
}
|
||||
|
||||
void GScanO200::reset()
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(m_imgLocker);
|
||||
while (!m_pImages.empty())
|
||||
{
|
||||
m_pImages.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void GScanO200::setdecodepixtype(int twpixtype)
|
||||
{
|
||||
if (twpixtype == TWPT_RGB)
|
||||
pixType = TJPF_BGR;
|
||||
else
|
||||
pixType = TJPF_GRAY;
|
||||
}
|
||||
|
||||
UINT32 GScanO200::get_ErrorCode()
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(m_imgLocker);
|
||||
return Error_Code;
|
||||
}
|
||||
|
||||
void GScanO200::Set_ErrorCode(UINT32 value)
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(m_imgLocker);
|
||||
Error_Code = value;
|
||||
}
|
||||
|
||||
int GScanO200::get_scanned_num()
|
||||
{
|
||||
if (!m_usb->is_connected())
|
||||
return -1;
|
||||
|
||||
std::lock_guard<std::mutex> lck(m_imgLocker);
|
||||
USBCB usbcb = { GET_SCANN_NUM ,0,0 };
|
||||
m_usb->write_bulk(&usbcb, sizeof(usbcb));
|
||||
return usbcb.u32_Count;
|
||||
}
|
||||
|
||||
DWORD GScanO200::usbmain()
|
||||
{
|
||||
cv::Mat imgData;
|
||||
cv::Mat bufferF;
|
||||
cv::Mat bufferB;
|
||||
devState = DEV_ISRUNNING;
|
||||
while (devState == DEV_ISRUNNING)
|
||||
{
|
||||
if (!m_usb->is_connected())
|
||||
{
|
||||
this_thread::sleep_for(chrono::milliseconds(200));
|
||||
continue;
|
||||
}
|
||||
USBCB usbcb = Get_Scanner_Status();
|
||||
switch (usbcb.u32_Data)
|
||||
{
|
||||
case HAVE_IMAGE:
|
||||
{
|
||||
int totalNum = usbcb.u32_Count;
|
||||
DWORD transferCount = 0;
|
||||
imgData = Get_Img_Data(totalNum);
|
||||
if (imgData.empty()) { //!< transfer data error
|
||||
Stop_scan();
|
||||
}
|
||||
|
||||
bufferF = cv::Mat(imgData.rows, imgData.cols, CV_8UC1);
|
||||
bufferB = cv::Mat(imgData.rows, imgData.cols, CV_8UC1);
|
||||
int j = 0;
|
||||
int k = 0;
|
||||
for (int i = 0; i < totalNum / 1024; i++)
|
||||
{
|
||||
if (imgData.data[1023 + i * 1024] == 0)
|
||||
{
|
||||
j++;
|
||||
memcpy(&(bufferB.data[(j - 1) * 1023]), &(imgData.data[(j + k - 1) * 1024]), 1023);
|
||||
}
|
||||
else if (imgData.data[1023 + i * 1024] == 255)
|
||||
{
|
||||
k++;
|
||||
memcpy(&(bufferF.data[(k - 1) * 1023]), &(imgData.data[(j + k - 1) * 1024]), 1023);
|
||||
}
|
||||
}
|
||||
vector<cv::Mat> mats;
|
||||
mats.push_back(bufferB);
|
||||
mats.push_back(bufferF);
|
||||
pushMat(JpegBuffer(mats, pixType, 0));
|
||||
imgData.release();
|
||||
bufferB.release();
|
||||
bufferF.release();
|
||||
Pop_Image();
|
||||
break;
|
||||
}
|
||||
case STOP_SCAN:
|
||||
{
|
||||
m_pImages.SetScanningStatus(false);
|
||||
devState = DEV_STOP;
|
||||
break;
|
||||
}
|
||||
case COUNT_MODE:
|
||||
case NO_FEED:
|
||||
case OPEN_COVER:
|
||||
case FEED_IN_ERROR:
|
||||
case PAPER_JAM:
|
||||
case DETECT_DOUBLE_FEED:
|
||||
case DETECT_STAPLE:
|
||||
case PAPER_SKEW:
|
||||
case HARDWARE_ERROR:
|
||||
case PC_SCAN_BUSY_or_ERROR:
|
||||
m_pImages.SetScanningStatus(false);
|
||||
Set_ErrorCode(usbcb.u32_Data);
|
||||
devState = DEV_WRONG;
|
||||
break;
|
||||
case NORMAL:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
this_thread::sleep_for(chrono::milliseconds(20));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
USBCB GScanO200::Get_Scanner_Status()
|
||||
{
|
||||
if (!m_usb->is_connected())
|
||||
{
|
||||
USBCB errorType = { NO_COMMAND ,PC_SCAN_BUSY_or_ERROR ,0 };
|
||||
return errorType;
|
||||
}
|
||||
USBCB usbcb = { GET_DSP_STATUS ,0,0 };
|
||||
m_usb->write_bulk(&usbcb, sizeof(usbcb));
|
||||
m_usb->read_bulk(&usbcb, sizeof(usbcb));
|
||||
return usbcb;
|
||||
}
|
||||
|
||||
cv::Mat GScanO200::Get_Img_Data(int bufferSize)
|
||||
{
|
||||
cv::Mat iData(1, bufferSize, CV_8UC1);
|
||||
StopWatch sw;
|
||||
int readed = 0;
|
||||
while (readed < bufferSize && sw.elapsed_ms() < 3000){
|
||||
USBCB usbcb = { GET_IMAGE,0,(UINT32)bufferSize };
|
||||
m_usb->write_bulk(&usbcb, sizeof(usbcb));
|
||||
readed = m_usb->read_bulk(iData.data, bufferSize);
|
||||
}
|
||||
|
||||
if (sw.elapsed_ms() > 3000)
|
||||
return cv::Mat();
|
||||
|
||||
return iData;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void GScanO200::Pop_Image()
|
||||
{
|
||||
if (!m_usb->is_open())
|
||||
{
|
||||
return;
|
||||
}
|
||||
USBCB usbcb = { POP_IMAGE ,0,0 };
|
||||
m_usb->write_bulk(&usbcb, sizeof(usbcb));
|
||||
}
|
38
GScanO200.h
38
GScanO200.h
|
@ -1,38 +0,0 @@
|
|||
#pragma once
|
||||
#include "gscn_drv.h"
|
||||
#include <memory>
|
||||
|
||||
|
||||
class GScanO200 : public IGScan, GScn_Drv
|
||||
{
|
||||
public:
|
||||
GScanO200();
|
||||
virtual ~GScanO200();
|
||||
// ͨ¹ý IGScan ¼Ì³Ð
|
||||
virtual void open(int vid, int pid) override;
|
||||
virtual int aquire_image(cv::Mat& image) override;
|
||||
virtual BOOL IsConnected() override;
|
||||
virtual std::string GetFWVersion() override;
|
||||
virtual std::string GetSerialNum() override;
|
||||
virtual bool is_scan() override;
|
||||
virtual BOOL Get_Scanner_PaperOn() override;
|
||||
virtual void config_params(SFreeImage& params) override;
|
||||
virtual void Scanner_StartScan(UINT16 count) override;
|
||||
virtual void Stop_scan() override;
|
||||
virtual void ResetScanner() override;
|
||||
virtual bool Get_IsImageQueueEmpty() override;
|
||||
virtual void reset() override;
|
||||
virtual void setdecodepixtype(int twpixtype) override;
|
||||
virtual UINT32 get_ErrorCode() override;
|
||||
virtual void Set_ErrorCode(UINT32 value) override;
|
||||
virtual int get_scanned_num() override;
|
||||
private:
|
||||
DWORD usbmain();
|
||||
USBCB Get_Scanner_Status();
|
||||
cv::Mat Get_Img_Data(int buffersize);
|
||||
void Pop_Image();
|
||||
|
||||
std::shared_ptr<IUsb> m_usb;
|
||||
std::unique_ptr<thread> m_threadUsb;
|
||||
};
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 96 KiB |
10
IConfig.h
10
IConfig.h
|
@ -1,10 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
class IConfig
|
||||
{
|
||||
public:
|
||||
IConfig(void) {};
|
||||
virtual ~IConfig(void) {};
|
||||
virtual unsigned int GetData() = 0;
|
||||
};
|
||||
|
54
IGDevice.h
54
IGDevice.h
|
@ -1,54 +0,0 @@
|
|||
#pragma once
|
||||
#include <vector>
|
||||
|
||||
|
||||
typedef void(*image_callback)(void*, int, void*, int, void*);
|
||||
typedef void(*event_callback)(int, void*);
|
||||
|
||||
enum Cam_Options {
|
||||
scanner_config, //!< color, gray
|
||||
scanner_exposure_gray,
|
||||
scanner_exposure_green,
|
||||
scanner_exposure_blue,
|
||||
scanner_exposure_red,
|
||||
scanner_status,
|
||||
scanner_ad_gain,
|
||||
scanner_ad_offset,
|
||||
scanner_cover_status, //是否关闭盖子
|
||||
scanner_pick_paper_stauts, //是否搓纸失败
|
||||
scanner_jam_stauts, //是否卡纸
|
||||
scanner_paper_count, //扫描计数值
|
||||
scanner_trigger_scan, //触发扫描
|
||||
scanner_staple_state, //有无订书钉
|
||||
scanner_skrew_state, //歪斜状态
|
||||
scanner_paper_have, //有无纸张
|
||||
scanner_double_paper, //双张检测
|
||||
scanner_scan_triger,//扫描状态,1停止扫描,0正在扫描
|
||||
scanner_scan_skrew, //歪斜检测开关,1开,0关
|
||||
scanner_stample_enable, //订书钉检测使能,0:default;1:订书钉检测使能
|
||||
scanner_doublePape_enable,//双张检测使能
|
||||
scanner_stop_motor, //停止电机
|
||||
scanner_error_clean ,//异常清除
|
||||
scanner_Init_Status, //状态初始化使能
|
||||
scanner_IIC_Config, //IIC配置使能
|
||||
scanner_Speed_Config, //速度配置使能
|
||||
scanner_scan_status
|
||||
};
|
||||
|
||||
class IGDevice
|
||||
{
|
||||
public:
|
||||
virtual ~IGDevice() {}
|
||||
virtual bool open() = 0;
|
||||
virtual void close() = 0;
|
||||
virtual bool is_open() = 0;
|
||||
virtual bool start(image_callback imagecall= NULL, void* userdata = NULL) = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual int is_run() = 0;
|
||||
virtual void reset() = 0;
|
||||
virtual void set_event_call(event_callback event_callfunc, void* userdata) = 0;
|
||||
virtual void set_option(Cam_Options option, unsigned int value) = 0;
|
||||
virtual int get_option(Cam_Options option) = 0;
|
||||
virtual std::vector<Cam_Options> support_options() = 0;
|
||||
};
|
||||
|
15
IUsb.h
15
IUsb.h
|
@ -1,15 +0,0 @@
|
|||
#pragma once
|
||||
class IUsb
|
||||
{
|
||||
public:
|
||||
virtual ~IUsb() {}
|
||||
virtual bool open() = 0;
|
||||
virtual bool close() = 0;
|
||||
virtual bool is_open() = 0;
|
||||
virtual bool is_connected() = 0;
|
||||
virtual void set_timeout(int timeout) = 0;
|
||||
virtual int read_bulk(void* data, int len) = 0;
|
||||
virtual int write_bulk(void* data, int len) = 0;
|
||||
virtual int read_int(void* data, int len) = 0;
|
||||
virtual int control_msg(int rtype, int req, int value, int index, int len, void* data) = 0;
|
||||
};
|
|
@ -1,8 +0,0 @@
|
|||
#ifndef IMAGE_APPLY_HEADER_H
|
||||
#define IMAGE_APPLY_HEADER_H
|
||||
|
||||
#include "ImageApply.h"
|
||||
#include "ImageApplyAdjustColors.h"
|
||||
|
||||
|
||||
#endif
|
|
@ -1,209 +0,0 @@
|
|||
#include "StdAfx.h"
|
||||
#include "ImageMatQueue.h"
|
||||
#include "PublicFunc.h"
|
||||
#include "filetools.h"
|
||||
#include "ImageProcess/ImageApplyHeaders.h"
|
||||
#include "ImageMultiOutput.h"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
#define DECODE_COLOR_BGR 1
|
||||
#define DECODE_GRAY 6
|
||||
|
||||
ImageMatQueue::ImageMatQueue(void)
|
||||
: bRun(false), iscanning(false)
|
||||
{
|
||||
bRun = true;
|
||||
at_prced_image_remains = 0;
|
||||
atm_orgin_image_remains = 0;
|
||||
m_threadProc.reset(new thread(&ImageMatQueue::proc, this));
|
||||
}
|
||||
|
||||
void ImageMatQueue::run()
|
||||
{
|
||||
}
|
||||
|
||||
ImageMatQueue::~ImageMatQueue(void)
|
||||
{
|
||||
m_pImages.ShutDown();
|
||||
m_images.ShutDown();
|
||||
if (m_threadProc) {
|
||||
bRun = false;
|
||||
at_prced_image_remains = 0;
|
||||
atm_orgin_image_remains = 0;
|
||||
XdPrint("closeing m_threadProc\n");
|
||||
m_threadProc->join();
|
||||
m_threadProc = NULL;
|
||||
XdPrint("closed m_threadProc\n");
|
||||
}
|
||||
}
|
||||
|
||||
void ImageMatQueue::pushMat(JpegBuffer& data)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mtxJB);
|
||||
m_pImages.Put(data);
|
||||
atm_orgin_image_remains++;
|
||||
}
|
||||
static int outnum =0;
|
||||
cv::Mat ImageMatQueue::popMat()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mtxJB);
|
||||
cv::Mat mat = _popMat();
|
||||
XdPrint("dequeue image %d \n", outnum++);
|
||||
at_prced_image_remains--;
|
||||
return mat;
|
||||
}
|
||||
|
||||
bool ImageMatQueue::valid()
|
||||
{
|
||||
return (at_prced_image_remains != 0);
|
||||
}
|
||||
|
||||
void ImageMatQueue::clear()
|
||||
{
|
||||
m_images.Clear();
|
||||
m_pImages.Clear();
|
||||
at_prced_image_remains = 0;
|
||||
atm_orgin_image_remains = 0;
|
||||
}
|
||||
|
||||
void ImageMatQueue::setparam(SFreeImage param)
|
||||
{
|
||||
scanParam = param;
|
||||
m_iaList.clear();
|
||||
if (param.m_bAutoDiscardBlank || param.m_bAutoDiscardBlankInvoice)
|
||||
m_iaList.push_back(shared_ptr<CImageApply>(new CImageApplyDiscardBlank(param.m_bAutoDiscardBlank ? true : false)));
|
||||
|
||||
{
|
||||
CSize fixedSize = papersize.GetPaperSize(param.m_HardWareParams.PaperType, 200.0f);
|
||||
m_iaList.push_back(shared_ptr<CImageApply>(new CImageApplyAutoCrop(param.m_bAutoCrop, param.m_bFillBlackRect, param.m_bAutoDeskew, cv::Size(fixedSize.cx, fixedSize.cy))));
|
||||
}
|
||||
|
||||
if (param.m_nPixelType != 0) //sharpen
|
||||
m_iaList.push_back(shared_ptr<CImageApply>(new CImageApplySharpen()));
|
||||
|
||||
if (param.m_nFilter)
|
||||
m_iaList.push_back(shared_ptr<CImageApply>(new CImageApplyChannel(param.m_nFilter)));
|
||||
|
||||
if (param.m_fBrightness != 0 || param.m_fContrast != 0 || param.m_fGamma != 1.0)
|
||||
m_iaList.push_back(shared_ptr<CImageApply>(new CImageApplyAdjustColors(param.m_fBrightness, param.m_fContrast, param.m_fGamma)));
|
||||
|
||||
if (param.m_fXResolution != 200.0)
|
||||
{
|
||||
CSize dSize = papersize.GetPaperSize(param.m_HardWareParams.PaperType, param.m_fXResolution);
|
||||
CImageApplyResize* apply = new CImageApplyResize();
|
||||
apply->setType(CImageApplyResize::DSIZE);
|
||||
apply->setDSize(cv::Size(dSize.cx, dSize.cy));
|
||||
m_iaList.push_back(shared_ptr< CImageApply>(apply));
|
||||
}
|
||||
|
||||
if (param.m_wRotation != 0 || param.m_bBackRotate180)
|
||||
m_iaList.push_back(shared_ptr<CImageApply>(new CImageApplyRotation(param.m_wRotation, param.m_bBackRotate180)));
|
||||
}
|
||||
|
||||
cv::Mat ImageMatQueue::_popMat()
|
||||
{
|
||||
return m_images.Take();
|
||||
}
|
||||
|
||||
void ImageMatQueue::EnqueueMat(cv::Mat &mat)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_Locker);
|
||||
m_images.Put(mat);
|
||||
at_prced_image_remains++;
|
||||
}
|
||||
|
||||
void ImageMatQueue::PaniusCount()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_Locker);
|
||||
atm_orgin_image_remains--;
|
||||
}
|
||||
|
||||
void ImageMatQueue::SetScanningStatus(bool isscannning)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mtxscan);
|
||||
iscanning = isscannning;
|
||||
}
|
||||
|
||||
void ImageMatQueue::release_img_prc_thread()
|
||||
{
|
||||
if (m_threadProc) {
|
||||
bRun = false;
|
||||
at_prced_image_remains = 0;
|
||||
atm_orgin_image_remains = 0;
|
||||
m_threadProc->join();
|
||||
m_threadProc = NULL;
|
||||
iscanning = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ImageMatQueue::empty()
|
||||
{
|
||||
bool ret= ((atm_orgin_image_remains == 0 &&
|
||||
at_prced_image_remains == 0) && (!iscanning));
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int index=0;
|
||||
void ImageMatQueue::proc()
|
||||
{
|
||||
JpegBuffer jb;
|
||||
while (bRun) {
|
||||
if (m_pImages.Size() <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
jb = m_pImages.Take();
|
||||
if (!m_pImages.IsShutDown() && !jb.empty()) {
|
||||
vector<cv::Mat> mats = jb.getMats();
|
||||
//if (scanParam.m_OutHole.EnOutHole && mats.size() == 2){ //确保能够获取正反两面图
|
||||
// if (!mats[0].empty() && !mats[1].empty())
|
||||
// ImageOutHole().puncture(mats[0], mats[1], 50.0, scanParam.m_OutHole.OutHoleRatio / 100.0, 50);
|
||||
//}
|
||||
|
||||
for (int i = 0; i < mats.size(); 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < mats.size(); i++) {
|
||||
//if (!scanParam.m_bDuplex && i == 1) {
|
||||
// mats[i].release();
|
||||
// break;
|
||||
//}
|
||||
|
||||
if (!mats[i].empty()){
|
||||
EnqueueMat(mats[i]);
|
||||
XdPrint("enqueue image %d \n", index++);
|
||||
}
|
||||
}
|
||||
|
||||
//if (scanParam.m_bMultiOutput)
|
||||
//{
|
||||
// for (int i = 0; i < mats.size(); i++)
|
||||
// {
|
||||
// ImageMultiOutput m_mlt;
|
||||
// Mat m_filterMat = m_mlt.GetMultiFilterMat(mats[i], 2);
|
||||
// if (!m_filterMat.empty()) {
|
||||
// if (!scanParam.m_bDuplex && i == 1) {
|
||||
// mats[i].release();
|
||||
// break;
|
||||
// }
|
||||
|
||||
// if (!m_filterMat.empty())
|
||||
// EnqueueMat(m_filterMat);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
PaniusCount();
|
||||
}
|
||||
jb = JpegBuffer();
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
#pragma once
|
||||
//#include <boost\thread\win32\mfc_thread_init.hpp>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <opencv2\opencv.hpp>
|
||||
#include "JpegBuffer.h"
|
||||
#include <queue>
|
||||
#include "ImageProcess/ImageApplyHeaders.h"
|
||||
#include "PublicFunc.h"
|
||||
#include "BlockingQueue.h"
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
#include "PaperSize.h"
|
||||
#include <memory>
|
||||
|
||||
class ImageMatQueue
|
||||
{
|
||||
public:
|
||||
ImageMatQueue(void);
|
||||
virtual ~ImageMatQueue(void);
|
||||
|
||||
void pushMat(JpegBuffer& data);
|
||||
cv::Mat popMat();
|
||||
bool empty();
|
||||
bool valid();
|
||||
void clear();
|
||||
void setparam(SFreeImage param);
|
||||
void run();
|
||||
public:
|
||||
void SetScanningStatus(bool isscannning);
|
||||
void release_img_prc_thread();
|
||||
private:
|
||||
void proc();
|
||||
cv::Mat _popMat();
|
||||
void EnqueueMat(cv::Mat &mat);
|
||||
void PaniusCount();
|
||||
BlockingQueue<cv::Mat> m_images;
|
||||
BlockingQueue<JpegBuffer> m_pImages;
|
||||
std::mutex m_Locker;
|
||||
std::mutex m_mtxJB;
|
||||
std::mutex m_mtxscan;
|
||||
std::unique_ptr<thread> m_threadProc;
|
||||
volatile bool bRun;
|
||||
bool isduplex;
|
||||
std::atomic<int> at_prced_image_remains;
|
||||
std::atomic<int> atm_orgin_image_remains;
|
||||
SFreeImage scanParam;
|
||||
bool iscanning;
|
||||
PaperSize papersize;
|
||||
std::vector<std::shared_ptr<CImageApply>> m_iaList;
|
||||
};
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
#include "StdAfx.h"
|
||||
#include "ImageMultiOutput.h"
|
||||
|
||||
|
||||
ImageMultiOutput::ImageMultiOutput(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ImageMultiOutput::~ImageMultiOutput(void)
|
||||
{
|
||||
}
|
||||
|
||||
//void ImageMultiOutput::apply(cv::Mat& pDib,int side)
|
||||
//{
|
||||
// //throw std::logic_error("The method or operation is not implemented.");
|
||||
//}
|
||||
|
||||
cv::Mat ImageMultiOutput::GetMultiFilterMat(cv::Mat &src,int channel)
|
||||
{
|
||||
return FilterColor(src,channel);
|
||||
}
|
||||
|
||||
cv::Mat ImageMultiOutput::FilterColor(cv::Mat image,short channel)
|
||||
{
|
||||
cv::Mat dstImage(image.rows,image.cols,CV_8UC1);
|
||||
|
||||
//int pixelSize = image.depth();
|
||||
int channels = image.channels();
|
||||
if(channel > channels -1){
|
||||
return dstImage;
|
||||
}
|
||||
if ( ( channel == 3 ) && ( channels != 4 ) && ( channels != 8 ))
|
||||
{
|
||||
return dstImage;
|
||||
}
|
||||
if ( channels <= 4 )
|
||||
{
|
||||
int srcOffset = image.step - image.cols* channels ;
|
||||
int dstOffset = dstImage.step - dstImage.cols;
|
||||
unsigned char* src = image.data;
|
||||
unsigned char* dst = dstImage.data;
|
||||
src += channel;
|
||||
|
||||
for ( int y = 0; y < image.rows; y++ )
|
||||
{
|
||||
for ( int x = 0; x < image.cols; x++, src += channels , dst++ )
|
||||
{
|
||||
unsigned short pix = *src;
|
||||
if(pix >=130){
|
||||
pix = 255;
|
||||
}
|
||||
*dst = pix;
|
||||
}
|
||||
src += srcOffset;
|
||||
dst += dstOffset;
|
||||
}
|
||||
}
|
||||
return dstImage;
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
#pragma once
|
||||
#include "ImageProcess/ImageApply.h"
|
||||
|
||||
class ImageMultiOutput
|
||||
{
|
||||
public:
|
||||
ImageMultiOutput(void);
|
||||
~ImageMultiOutput(void);
|
||||
|
||||
cv::Mat GetMultiFilterMat(cv::Mat &src,int channel);
|
||||
private:
|
||||
cv::Mat FilterColor(cv::Mat image,short channel);
|
||||
|
||||
};
|
||||
|
BIN
ImageProcess.cpp
BIN
ImageProcess.cpp
Binary file not shown.
BIN
ImageProcess.h
BIN
ImageProcess.h
Binary file not shown.
|
@ -1,9 +0,0 @@
|
|||
#include "ImageApply.h"
|
||||
|
||||
CImageApply::CImageApply(void)
|
||||
{
|
||||
}
|
||||
|
||||
CImageApply::~CImageApply(void)
|
||||
{
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
#ifndef IMAGE_APPLY_H
|
||||
#define IMAGE_APPLY_H
|
||||
|
||||
#include "../stdafx.h"
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
#if defined(LOG)
|
||||
#include "filetools.h"
|
||||
#endif
|
||||
|
||||
class CImageApply
|
||||
{
|
||||
public:
|
||||
CImageApply(void);
|
||||
virtual ~CImageApply(void);
|
||||
|
||||
virtual void apply(cv::Mat& pDib,int side) = 0;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<CImageApply> ImageApplyPtr;
|
||||
|
||||
#endif //!IMAGE_APPLY_H
|
|
@ -1,79 +0,0 @@
|
|||
#include "ImageApplyAdjustColors.h"
|
||||
|
||||
CImageApplyAdjustColors::CImageApplyAdjustColors(void)
|
||||
: m_brightness(0)
|
||||
, m_contrast(0)
|
||||
, m_gamma(1.0f)
|
||||
, lut(1, 256, CV_8UC1)
|
||||
{
|
||||
update_lutData();
|
||||
}
|
||||
|
||||
CImageApplyAdjustColors::CImageApplyAdjustColors(int brightness, int contrast, float gamma)
|
||||
: lut(1, 256, CV_8UC1)
|
||||
{
|
||||
setAdjustColors(brightness, contrast, gamma);
|
||||
}
|
||||
|
||||
CImageApplyAdjustColors::~CImageApplyAdjustColors(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CImageApplyAdjustColors::apply(cv::Mat& pDib,int side)
|
||||
{
|
||||
if (m_brightness != 0 || m_contrast != 0 || m_gamma != 1.0)
|
||||
cv::LUT(pDib, lut, pDib);
|
||||
}
|
||||
|
||||
void CImageApplyAdjustColors::setAdjustColors(int brightness, int contrast, float gamma)
|
||||
{
|
||||
setBrightness(brightness);
|
||||
setContrast(contrast);
|
||||
setGamma(gamma);
|
||||
update_lutData();
|
||||
}
|
||||
|
||||
void CImageApplyAdjustColors::setBrightness(int brightness)
|
||||
{
|
||||
m_brightness = cv::max(-255, cv::min(brightness, 255));
|
||||
update_lutData();
|
||||
}
|
||||
|
||||
void CImageApplyAdjustColors::setContrast(int contrast)
|
||||
{
|
||||
m_contrast = cv::max(-127, cv::min(contrast, 127));
|
||||
update_lutData();
|
||||
}
|
||||
|
||||
void CImageApplyAdjustColors::setGamma(float gamma)
|
||||
{
|
||||
m_gamma = cv::max(0.1f, cv::min(gamma, 5.0f));
|
||||
update_lutData();
|
||||
}
|
||||
|
||||
void CImageApplyAdjustColors::update_lutData()
|
||||
{
|
||||
unsigned char* ptr = lut.data;
|
||||
|
||||
if (m_gamma != 1.0f)
|
||||
{
|
||||
float g = 1.0f / m_gamma;
|
||||
for (int i = 0; i < 256; i++)
|
||||
ptr[i] = static_cast<unsigned char>(cv::min(255, static_cast<int>(cv::pow(i / 255.0f, g) * 255.0f + 0.5f)));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
//update contrast
|
||||
if (i < 128)
|
||||
ptr[i] = static_cast<unsigned char>(cv::max(0, cv::min(i - m_contrast, 127)));
|
||||
else
|
||||
ptr[i] = static_cast<unsigned char>(cv::max(127, cv::min(i + m_contrast, 255)));
|
||||
|
||||
//update brightness
|
||||
ptr[i] = static_cast<unsigned char>(cv::max(0, cv::min(ptr[i] + m_brightness, 255)));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
#ifndef IMAGE_APPLY_ADJUST_COLOR_H
|
||||
#define IMAGE_APPLY_ADJUST_COLOR_H
|
||||
|
||||
#include "ImageApply.h"
|
||||
|
||||
class CImageApplyAdjustColors : public CImageApply
|
||||
{
|
||||
public:
|
||||
|
||||
CImageApplyAdjustColors(void);
|
||||
|
||||
CImageApplyAdjustColors(int brightness, int contrast, float gamma);
|
||||
|
||||
virtual ~CImageApplyAdjustColors(void);
|
||||
|
||||
virtual void apply(cv::Mat& pDib, int side);
|
||||
|
||||
void setAdjustColors(int brightness, int contrast, float gamma);
|
||||
|
||||
int getContrast() { return m_contrast; }
|
||||
|
||||
int getBrightness() { return m_brightness; }
|
||||
|
||||
double getGamma() { return m_gamma; }
|
||||
|
||||
void setBrightness(int brightness);
|
||||
|
||||
void setContrast(int contrast);
|
||||
|
||||
void setGamma(float gamma);
|
||||
|
||||
private:
|
||||
|
||||
void update_lutData();
|
||||
|
||||
private:
|
||||
|
||||
int m_brightness;
|
||||
int m_contrast;
|
||||
float m_gamma;
|
||||
cv::Mat lut;
|
||||
};
|
||||
|
||||
#endif // !IMAGE_APPLY_ADJUST_COLOR_H
|
||||
|
||||
|
|
@ -1,165 +0,0 @@
|
|||
#include "ImageApplyAutoCrop.h"
|
||||
#include "ImageProcess_Public.h"
|
||||
|
||||
#define RE 8
|
||||
|
||||
CImageApplyAutoCrop::CImageApplyAutoCrop(bool isCrop, bool isFillBlank, bool isDesaskew, cv::Size size)
|
||||
: m_isCrop(isCrop)
|
||||
, m_isFillBlank(isFillBlank)
|
||||
, m_isDesaskew(isDesaskew)
|
||||
, m_fixedSize(size)
|
||||
, m_threshold(35)
|
||||
, m_noise(7)
|
||||
, m_indent(5)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CImageApplyAutoCrop::~CImageApplyAutoCrop()
|
||||
{
|
||||
}
|
||||
|
||||
void CImageApplyAutoCrop::apply(cv::Mat & pDib, int side)
|
||||
{
|
||||
if (!m_isCrop && !m_isFillBlank && !m_isDesaskew) return;
|
||||
cv::Mat src = pDib;
|
||||
cv::Mat dst;
|
||||
cv::Mat src_resize;
|
||||
cv::resize(src, src_resize, cv::Size(src.cols / RE, src.rows / RE));
|
||||
cv::Mat scale_mat;
|
||||
cv::Mat thre(src_resize.size(), CV_8UC1);
|
||||
hg::threshold_Mat(src_resize, thre, m_threshold);
|
||||
|
||||
cv::Mat element = getStructuringElement(cv::MORPH_RECT, cv::Size(m_noise, m_noise));
|
||||
cv::morphologyEx(thre, thre, cv::MORPH_OPEN, element);
|
||||
|
||||
std::vector<cv::Vec4i> hierarchy;
|
||||
std::vector<std::vector<cv::Point>> contours;
|
||||
|
||||
hg::findContours(thre, contours, hierarchy, cv::RETR_EXTERNAL);
|
||||
std::vector<cv::Point> maxContour = hg::getMaxContour(contours, hierarchy);
|
||||
|
||||
for (cv::Point& item : maxContour)
|
||||
{
|
||||
item.x = item.x * RE + RE / 2;
|
||||
item.y = item.y * RE + RE / 2;
|
||||
}
|
||||
|
||||
if (maxContour.size() == 0)
|
||||
{
|
||||
thre.release();
|
||||
return;
|
||||
}
|
||||
thre.release();
|
||||
dst.release();
|
||||
|
||||
cv::RotatedRect rect = hg::getBoundingRect(maxContour);
|
||||
|
||||
hg::convexHull(maxContour, maxContour);
|
||||
|
||||
cv::Rect bounding_rect = rect.boundingRect();
|
||||
|
||||
if (m_isCrop)
|
||||
if (m_isDesaskew)
|
||||
dst = cv::Mat::zeros(cv::Size(rect.size), src.type());
|
||||
else
|
||||
{
|
||||
cv::Rect bounding_rect_clone = bounding_rect;
|
||||
bounding_rect.x = cv::max(0, bounding_rect_clone.x);
|
||||
bounding_rect.y = cv::max(0, bounding_rect_clone.y);
|
||||
bounding_rect.width = cv::min(src.cols, bounding_rect_clone.x + bounding_rect_clone.width) - bounding_rect.x;
|
||||
bounding_rect.height = cv::min(src.rows, bounding_rect_clone.y + bounding_rect_clone.height) - bounding_rect.y;
|
||||
dst = src(bounding_rect).clone();
|
||||
}
|
||||
else
|
||||
if (m_isFillBlank)
|
||||
dst = src.clone();
|
||||
else
|
||||
dst = cv::Mat(src.rows, src.cols, src.type());
|
||||
|
||||
cv::Mat warp_mat;
|
||||
if (m_isDesaskew)
|
||||
{
|
||||
cv::Point2f dstTri[3];
|
||||
cv::Point2f srcTri[4];
|
||||
rect.points(srcTri);
|
||||
|
||||
for (cv::Point2f& p : srcTri)
|
||||
p.y /= 1.5f;
|
||||
|
||||
if (m_isCrop)
|
||||
{
|
||||
dstTri[0] = cv::Point2f(0, rect.size.height - 1);
|
||||
dstTri[1] = cv::Point2f(0, 0);
|
||||
dstTri[2] = cv::Point2f(rect.size.width - 1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
float left = (src.cols - rect.size.width) / 2;
|
||||
float right = left + rect.size.width - 1;
|
||||
float top = (src.rows - rect.size.height) / 2;
|
||||
float bottom = top + rect.size.height - 1;
|
||||
dstTri[0] = cv::Point2f(left, bottom);
|
||||
dstTri[1] = cv::Point2f(left, top);
|
||||
dstTri[2] = cv::Point2f(right, top);
|
||||
}
|
||||
|
||||
cv::Size dSize = m_isCrop ? cv::Size(static_cast<int>(rect.size.width),
|
||||
static_cast<int>(rect.size.height)) : dst.size();
|
||||
bounding_rect.width = dSize.width;
|
||||
bounding_rect.height = dSize.height;
|
||||
|
||||
warp_mat = cv::getAffineTransform(srcTri, dstTri);
|
||||
cv::warpAffine(src, dst, warp_mat, dSize);
|
||||
}
|
||||
|
||||
if (m_isFillBlank)
|
||||
{
|
||||
if (m_isDesaskew)
|
||||
for (cv::Point& item : maxContour)
|
||||
item = hg::warpPoint(item, warp_mat);
|
||||
else
|
||||
{
|
||||
if (m_isCrop)
|
||||
{
|
||||
cv::Point offset = bounding_rect.tl();
|
||||
for (cv::Point& item : maxContour)
|
||||
item -= offset;
|
||||
}
|
||||
}
|
||||
|
||||
hg::polyIndent(maxContour, m_indent);
|
||||
hg::fillBlackBackGround(dst, maxContour);
|
||||
}
|
||||
|
||||
if (!m_isCrop)
|
||||
{
|
||||
cv::Rect fixed_roi;
|
||||
if (m_fixedSize.width > dst.cols)
|
||||
{
|
||||
fixed_roi.x = 0;
|
||||
fixed_roi.width = dst.cols;
|
||||
}
|
||||
else
|
||||
{
|
||||
fixed_roi.x = (dst.cols - m_fixedSize.width) / 2;
|
||||
fixed_roi.width = m_fixedSize.width;
|
||||
}
|
||||
|
||||
if (m_fixedSize.height > dst.rows)
|
||||
{
|
||||
fixed_roi.y = 0;
|
||||
fixed_roi.height = dst.rows;
|
||||
}
|
||||
else
|
||||
{
|
||||
fixed_roi.y = (dst.rows - m_fixedSize.height) / 2;
|
||||
fixed_roi.height = m_fixedSize.height;
|
||||
}
|
||||
|
||||
dst = dst(fixed_roi);
|
||||
}
|
||||
|
||||
pDib.release();
|
||||
pDib = dst;
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
#ifndef IMAGE_APPLY_AUTO_CROP_H
|
||||
#define IMAGE_APPLY_AUTO_CROP_H
|
||||
|
||||
#include "ImageApply.h"
|
||||
|
||||
class CImageApplyAutoCrop : public CImageApply
|
||||
{
|
||||
public:
|
||||
CImageApplyAutoCrop(bool isCrop,bool isFillBlank,bool isDesaskew,cv::Size size);
|
||||
|
||||
virtual ~CImageApplyAutoCrop();
|
||||
|
||||
virtual void apply(cv::Mat& pDib, int side);
|
||||
|
||||
bool isAutoCrop() { return m_isCrop; }
|
||||
|
||||
bool isFillBlank() { return m_isFillBlank; }
|
||||
|
||||
bool isDesaskew() { return m_isDesaskew; }
|
||||
|
||||
double threshold() { return m_threshold; }
|
||||
|
||||
int noise() { return m_noise; }
|
||||
|
||||
int indent() { return m_indent; }
|
||||
|
||||
cv::Size fixedSize() { return m_fixedSize; }
|
||||
|
||||
void setAutoCrop(bool enabled) { m_isCrop = enabled; }
|
||||
|
||||
void setFillBlank(bool enabled) { m_isFillBlank = enabled; }
|
||||
|
||||
void setDesaskew(bool enabled) { m_isDesaskew = enabled; }
|
||||
|
||||
void setThreshold(double value) { m_threshold = value; }
|
||||
|
||||
void setNoise(int value) { m_noise = value; }
|
||||
|
||||
void setIndent(int value) { m_indent = value; }
|
||||
|
||||
void setFixedSize(cv::Size size) { m_fixedSize = size; }
|
||||
|
||||
private:
|
||||
bool m_isCrop;
|
||||
bool m_isFillBlank;
|
||||
bool m_isDesaskew;
|
||||
|
||||
double m_threshold;
|
||||
int m_noise;
|
||||
int m_indent;
|
||||
cv::Size m_fixedSize;
|
||||
|
||||
};
|
||||
|
||||
#endif // !IMAGE_APPLY_AUTO_CROP_H
|
||||
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
#include "ImageApplyBWBinaray.h"
|
||||
|
||||
CImageApplyBWBinaray::CImageApplyBWBinaray()
|
||||
: m_threshold(127)
|
||||
, m_type(THRESH_BINARY)
|
||||
, m_blockSize(25)
|
||||
, m_constant(5)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CImageApplyBWBinaray::~CImageApplyBWBinaray(void)
|
||||
{
|
||||
}
|
||||
|
||||
void CImageApplyBWBinaray::apply(cv::Mat& pDib,int side)
|
||||
{
|
||||
if (pDib.channels() == 3)
|
||||
cv::cvtColor(pDib, pDib, cv::COLOR_BGR2GRAY);
|
||||
|
||||
switch (m_type)
|
||||
{
|
||||
case THRESH_BINARY:
|
||||
cv::threshold(pDib, pDib, m_threshold, 255, CV_THRESH_BINARY);
|
||||
break;
|
||||
case THRESH_OTSU:
|
||||
cv::threshold(pDib, pDib, m_threshold, 255, CV_THRESH_OTSU);
|
||||
break;
|
||||
case ADAPTIVE_GAUSSIAN:
|
||||
cv::adaptiveThreshold(pDib, pDib, 255, cv::ADAPTIVE_THRESH_GAUSSIAN_C, CV_THRESH_BINARY, m_blockSize, m_constant);
|
||||
break;
|
||||
case ADAPTIVE_MEAN:
|
||||
cv::adaptiveThreshold(pDib, pDib, 255, cv::ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY, m_blockSize, m_constant);
|
||||
break;
|
||||
case ERROR_DIFFUSION:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
#ifndef IMAGE_APPLY_BW_BINARAY_H
|
||||
#define IMAGE_APPLY_BW_BINARAY_H
|
||||
|
||||
#include "ImageApply.h"
|
||||
|
||||
|
||||
class CImageApplyBWBinaray:public CImageApply
|
||||
{
|
||||
public:
|
||||
|
||||
enum ThresholdType
|
||||
{
|
||||
THRESH_BINARY,
|
||||
THRESH_OTSU,
|
||||
|
||||
ADAPTIVE_GAUSSIAN,
|
||||
ADAPTIVE_MEAN,
|
||||
|
||||
ERROR_DIFFUSION
|
||||
};
|
||||
|
||||
CImageApplyBWBinaray();
|
||||
|
||||
virtual ~CImageApplyBWBinaray(void);
|
||||
|
||||
virtual void apply(cv::Mat& pDib,int side);
|
||||
|
||||
double getThreshold() { return m_threshold; }
|
||||
|
||||
ThresholdType getThresholdType() { return m_type; }
|
||||
|
||||
int getBlockSize() { return m_blockSize; }
|
||||
|
||||
double getConstant() { return m_constant; }
|
||||
|
||||
void setThreshold(double value) { m_threshold = value; }
|
||||
|
||||
void setThresholdType(ThresholdType type) { m_type = type; }
|
||||
|
||||
void setBlockSize(int value) { m_blockSize = value; }
|
||||
|
||||
void setConstant(double value) { m_constant = value; }
|
||||
|
||||
private:
|
||||
double m_threshold;
|
||||
|
||||
ThresholdType m_type;
|
||||
|
||||
int m_blockSize;
|
||||
|
||||
double m_constant;
|
||||
};
|
||||
|
||||
#endif //!IMAGE_APPLY_BW_BINARAY_H
|
||||
|
|
@ -1,184 +0,0 @@
|
|||
#include "ImageApplyChannel.h"
|
||||
|
||||
CImageApplyChannel::CImageApplyChannel(int index)
|
||||
: m_cmIndex(index)
|
||||
{
|
||||
colorTable=NULL;
|
||||
if (index>3)
|
||||
{
|
||||
short channal=m_cmIndex==4?2:(m_cmIndex==5?1:0);
|
||||
InitColorTable(channal);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CImageApplyChannel::~CImageApplyChannel(void)
|
||||
{
|
||||
if (colorTable!=NULL)
|
||||
{
|
||||
free(colorTable);
|
||||
}
|
||||
}
|
||||
|
||||
void CImageApplyChannel::apply(cv::Mat& pDib,int side)
|
||||
{
|
||||
//FileTools::write_log("D:\\1.txt", "Exit CImageChannel apply");
|
||||
if (m_cmIndex>0&&m_cmIndex<4)
|
||||
{
|
||||
if (m_cmIndex <= pDib.channels())
|
||||
{
|
||||
//0通道为B分量,1通道为G分量,2通道为R分量
|
||||
//m_cmIndex 1 除红 2 除绿 3 除蓝
|
||||
//2除红,1除绿,0除蓝
|
||||
//std::vector<cv::Mat> mats;
|
||||
//cv::split(pDib, mats);
|
||||
//int rmIndex=m_cmIndex==1?2:(m_cmIndex==2?1:0);
|
||||
//pDib = mats[rmIndex];
|
||||
pDib=FilterColor(pDib,m_cmIndex==1?2:(m_cmIndex==2?1:0));
|
||||
//FileTools::write_log("D:\\1.txt", "Exit CImageChannel FilterColor apply");
|
||||
}
|
||||
}
|
||||
else if(m_cmIndex>=4&&m_cmIndex<=6)
|
||||
{
|
||||
short channal=m_cmIndex==4?2:(m_cmIndex==5?1:0);
|
||||
pDib=colorEnhancement(pDib,channal);
|
||||
//FileTools::write_log("D:\\1.txt", "Exit CImageChannel colorEnhancement apply");
|
||||
}
|
||||
//FileTools::write_log("D:\\1.txt", "Exit CImageChannel apply");
|
||||
}
|
||||
|
||||
void CImageApplyChannel::setCH(int channel)
|
||||
{
|
||||
m_cmIndex = channel;
|
||||
}
|
||||
|
||||
int CImageApplyChannel::getCH()
|
||||
{
|
||||
return m_cmIndex;
|
||||
}
|
||||
|
||||
|
||||
void CImageApplyChannel::RGBtoHSV(double r, double g, double b, double &h, double &s, double &v)
|
||||
{
|
||||
double min, max, delta;
|
||||
min = ( (r<g ? r:g) < b ) ?(r<g ? r:g):b;
|
||||
max = ( (r>g ? r:g) > b ) ? (r>g ? r:g): b ;
|
||||
v = max; // v
|
||||
delta = max - min;
|
||||
if (max != 0)
|
||||
{
|
||||
s = delta / max; // s
|
||||
}
|
||||
else
|
||||
{
|
||||
// r = g = b = 0
|
||||
// s = 0, v is undefined
|
||||
s = 0;
|
||||
h = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (r == max)
|
||||
{
|
||||
h = (g - b) / delta; // between yellow & magenta
|
||||
}
|
||||
else if (g == max)
|
||||
{
|
||||
h = 2 + (b - r) / delta; // between cyan & yellow
|
||||
}
|
||||
else
|
||||
{
|
||||
h = 4 + (r - g) / delta; // between magenta & cyan
|
||||
}
|
||||
h *= 60; // degrees
|
||||
if (h < 0)
|
||||
{
|
||||
h += 360;
|
||||
}
|
||||
}
|
||||
|
||||
void CImageApplyChannel::InitColorTable(short channel)
|
||||
{
|
||||
//colorTable=new unsigned char();
|
||||
colorTable=(unsigned char *)malloc(sizeof(unsigned char)*256*256*256);
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
for (int j = 0; j < 256; j++)
|
||||
{
|
||||
for (int k = 0; k < 256; k++)
|
||||
{
|
||||
if (channel == 2) //红色增强
|
||||
{
|
||||
*(colorTable + i * 256 * 256 + j * 256 + k )= (unsigned char)(0 + 0.833 * j + 0.167 * k);//0.833 * j + 0.167 * k
|
||||
}
|
||||
else if (channel == 1) //绿色增强
|
||||
{
|
||||
*(colorTable + i * 256 * 256 + j * 256 + k ) = (unsigned char)(0.731 * i + 0 + 0.268 * k);
|
||||
}
|
||||
else if (channel == 0) //蓝色增强
|
||||
{
|
||||
*(colorTable + i * 256 * 256 + j * 256 + k ) = (unsigned char)(0.337 * i + 0.663 * j + 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cv::Mat CImageApplyChannel::colorEnhancement(cv::Mat image,short channel)
|
||||
{
|
||||
cv::Mat grayImage(image.rows,image.cols,CV_8UC1);
|
||||
if (channel>3)
|
||||
{
|
||||
return grayImage;
|
||||
}
|
||||
|
||||
unsigned char * dstData = grayImage.data;
|
||||
unsigned char * srcData = image.data;
|
||||
for(int r = 0; r < image.rows; r++)
|
||||
{
|
||||
for (int c = 0; c < image.cols; c++)
|
||||
{
|
||||
*(dstData + r * grayImage.step + c ) = colorTable[*(srcData + r * image.step + c * 3 + 2 ) * 256 * 256 + *(srcData + r * image.step + c * 3 + 1 ) * 256+ *(srcData + r * image.step + c * 3 )];
|
||||
}
|
||||
}
|
||||
return grayImage;
|
||||
|
||||
}
|
||||
|
||||
cv::Mat CImageApplyChannel::FilterColor(cv::Mat image,short channel)
|
||||
{
|
||||
cv::Mat dstImage(image.rows,image.cols,CV_8UC1);
|
||||
|
||||
//int pixelSize = image.depth();
|
||||
int channels = image.channels();
|
||||
if(channel > channels -1){
|
||||
return dstImage;
|
||||
}
|
||||
if ( ( channel == 3 ) && ( channels != 4 ) && ( channels != 8 ))
|
||||
{
|
||||
return dstImage;
|
||||
}
|
||||
if ( channels <= 4 )
|
||||
{
|
||||
int srcOffset = image.step - image.cols* channels ;
|
||||
int dstOffset = dstImage.step - dstImage.cols;
|
||||
unsigned char* src = image.data;
|
||||
unsigned char* dst = dstImage.data;
|
||||
src += channel;
|
||||
|
||||
for ( int y = 0; y < image.rows; y++ )
|
||||
{
|
||||
for ( int x = 0; x < image.cols; x++, src += channels , dst++ )
|
||||
{
|
||||
unsigned short pix = *src;
|
||||
if(pix >=130){
|
||||
pix = 255;
|
||||
}
|
||||
*dst = pix;
|
||||
}
|
||||
src += srcOffset;
|
||||
dst += dstOffset;
|
||||
}
|
||||
}
|
||||
return dstImage;
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
#ifndef IMAGE_APPLY_CHANNEL_H
|
||||
#define IMAGE_APPLY_CHANNEL_H
|
||||
|
||||
#include "imageapply.h"
|
||||
|
||||
class CImageApplyChannel : public CImageApply
|
||||
{
|
||||
public:
|
||||
CImageApplyChannel(int index);
|
||||
virtual ~CImageApplyChannel(void);
|
||||
|
||||
virtual void apply(cv::Mat& pDib,int side);
|
||||
void setCH(int channel);
|
||||
int getCH();
|
||||
|
||||
private:
|
||||
void RGBtoHSV(double r, double g, double b, double &h, double &s, double &v);
|
||||
void InitColorTable(short channel);
|
||||
cv::Mat colorEnhancement(cv::Mat image,short channel);
|
||||
cv::Mat FilterColor(cv::Mat image,short channel);
|
||||
int m_cmIndex;
|
||||
unsigned char * colorTable;
|
||||
};
|
||||
|
||||
#endif // !IMAGE_APPLY_CHANNEL_H
|
|
@ -1,18 +0,0 @@
|
|||
#include "ImageApplyCrop.h"
|
||||
|
||||
CImageApplyCrop::CImageApplyCrop(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CImageApplyCrop::~CImageApplyCrop(void)
|
||||
{
|
||||
}
|
||||
|
||||
void CImageApplyCrop::apply(cv::Mat& pDib,int side)
|
||||
{
|
||||
if (m_roi.x < 0 || m_roi.y < 0 || m_roi.br().x >= pDib.cols || m_roi.br().y >= pDib.rows || m_roi.width == 0 || m_roi.height == 0)
|
||||
return;
|
||||
|
||||
pDib = pDib(m_roi).clone();
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
#ifndef IMAGE_APPLY_CROP_H
|
||||
#define IMAGE_APPLY_CROP_H
|
||||
|
||||
#include "imageapply.h"
|
||||
|
||||
class CImageApplyCrop : public CImageApply
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
CImageApplyCrop(void);
|
||||
|
||||
virtual ~CImageApplyCrop(void);
|
||||
|
||||
virtual void apply(cv::Mat& pDib,int side);
|
||||
|
||||
cv::Rect getROI() { return m_roi; }
|
||||
|
||||
void setROI(const cv::Rect& rect) { m_roi = rect; }
|
||||
|
||||
private:
|
||||
|
||||
cv::Rect m_roi;
|
||||
};
|
||||
|
||||
#endif // !IMAGE_APPLY_CROP_H
|
|
@ -1,216 +0,0 @@
|
|||
#include "ImageApplyDiscardBlank.h"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
int CImageApplyDiscardBlank::ProcessRectR(Mat & image, RotatedRect & rotatedRect, vector<Point>& maxContour, double scale, double thresh, int blobAreaSize)
|
||||
{
|
||||
Mat gray;
|
||||
int blockCount = 0;
|
||||
if (image.channels() == 3)
|
||||
{
|
||||
if (scale != 1.0f)
|
||||
{
|
||||
Size ResImgSiz = Size(image.cols*scale, image.rows*scale);
|
||||
resize(image, gray, cv::Size(), scale, scale, 0);
|
||||
cvtColor(gray, gray, CV_BGR2GRAY);
|
||||
}
|
||||
else
|
||||
{
|
||||
cvtColor(image, gray, CV_BGR2GRAY);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scale != 1.0f)
|
||||
{
|
||||
resize(image, gray, cv::Size(), scale, scale, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
gray = image;
|
||||
}
|
||||
}
|
||||
Mat threshold_img;
|
||||
threshold(gray, threshold_img, thresh, 255.0, CV_THRESH_BINARY);
|
||||
vector<vector<Point>> contours;
|
||||
std::vector<Vec4i> h1;
|
||||
GetContours(threshold_img, contours, h1, CV_CHAIN_APPROX_SIMPLE);
|
||||
threshold_img.release();
|
||||
|
||||
if (contours.size() == 0)
|
||||
{
|
||||
return blockCount;
|
||||
}
|
||||
|
||||
vector<Point2f> list_com;
|
||||
for (int i = 0; i < contours.size(); i++)
|
||||
{
|
||||
double area = contourArea(contours[i]);
|
||||
if (area > blobAreaSize)
|
||||
{
|
||||
blockCount++;
|
||||
for (int j = 0; j < contours[i].size(); j++)
|
||||
{
|
||||
list_com.push_back(contours[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (list_com.size() == 0)
|
||||
{
|
||||
return blockCount;
|
||||
}
|
||||
|
||||
rotatedRect = minAreaRect(list_com);
|
||||
rotatedRect.center.x /= (float)scale;
|
||||
rotatedRect.center.y /= (float)scale;
|
||||
rotatedRect.size.width /= (float)scale;
|
||||
rotatedRect.size.height /= (float)scale;
|
||||
|
||||
if (rotatedRect.angle < -45.0f)
|
||||
{
|
||||
rotatedRect.angle += 90.0f;
|
||||
float l_temp = rotatedRect.size.width;
|
||||
rotatedRect.size.width = rotatedRect.size.height;
|
||||
rotatedRect.size.height = l_temp;
|
||||
}
|
||||
|
||||
vector<int> hull(list_com.size());
|
||||
convexHull(list_com, hull);
|
||||
|
||||
for (int i = 0; i < hull.size(); i++)
|
||||
{
|
||||
Point temp = list_com[hull[i]];
|
||||
int x = (int)(temp.x / scale);
|
||||
int y = (int)(temp.y / scale);
|
||||
maxContour.push_back(Point(x, y));
|
||||
}
|
||||
|
||||
return blockCount;
|
||||
}
|
||||
|
||||
bool CImageApplyDiscardBlank:: Scalar_LE(cv::Scalar& val1, cv::Scalar& val2)
|
||||
{
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
if(val1[i] > val2[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
CImageApplyDiscardBlank::CImageApplyDiscardBlank(bool isnormal)
|
||||
: devTh (10, 10, 10, 10), dSize(200),isNormalDiscard(isnormal)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CImageApplyDiscardBlank::~CImageApplyDiscardBlank(void)
|
||||
{
|
||||
}
|
||||
|
||||
void CImageApplyDiscardBlank::setIntensity(int val)
|
||||
{
|
||||
val = max(min(20, val), 2);
|
||||
devTh = cv::Scalar(val, val, val, val);
|
||||
}
|
||||
|
||||
void CImageApplyDiscardBlank::setMinArea(int val)
|
||||
{
|
||||
dSize = max(min(500, val), 100);
|
||||
}
|
||||
|
||||
void CImageApplyDiscardBlank::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 CImageApplyDiscardBlank::getRoiMat(cv::Mat& image)
|
||||
{
|
||||
int gap = 100;
|
||||
RotatedRect rect;
|
||||
vector<Point> contour;
|
||||
double scale = 0.25;
|
||||
double thresh = 50;
|
||||
int blobSize = 200;
|
||||
int edgeWidth = 10;
|
||||
ProcessRectR(image, rect, contour, scale, thresh, blobSize);
|
||||
cv::Rect rect2 = rect.boundingRect();
|
||||
cv::Rect inRect = rect2 & Rect(0, 0, image.cols, image.rows);
|
||||
gap = max(inRect.width - rect.size.width, inRect.height -rect.size.height)+100;
|
||||
inRect = cv::Rect(inRect.x+ gap, inRect.y + gap, inRect.width -gap*2, inRect.height-gap*2);
|
||||
return image(inRect);
|
||||
}
|
||||
|
||||
void CImageApplyDiscardBlank::apply(cv::Mat& pDib,int side)
|
||||
{
|
||||
//FileTools::write_log("D:\\1.txt", "enter CImageProcDiscardBlank apply");
|
||||
setIntensity(isNormalDiscard?8:20);
|
||||
setMinArea(isNormalDiscard?200:300);
|
||||
|
||||
cv::Scalar mean;
|
||||
cv::Scalar dev;
|
||||
cv::Mat image = getRoiMat(pDib);
|
||||
cv::Rect rect;
|
||||
cv::Rect imRect(0, 0, image.cols, image.rows);
|
||||
for(int i = 0; i < image.cols; i+= dSize)
|
||||
{
|
||||
for(int j = 0; j < image.rows; j+= dSize)
|
||||
{
|
||||
rect = cv::Rect(i, j,dSize, dSize) & imRect;
|
||||
if(rect != cv::Rect())
|
||||
{
|
||||
cv::meanStdDev (image(rect) , mean, dev);
|
||||
if(!Scalar_LE(dev, devTh))
|
||||
{
|
||||
m_res = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
m_res = true;
|
||||
if (m_res)
|
||||
pDib.release();
|
||||
//FileTools::write_log("D:\\1.txt", "exit CImageProcDiscardBlank apply");
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
#ifndef IMAGE_APPLY_DISCARD_BLANK_H
|
||||
#define IMAGE_APPLY_DISCARD_BLANK_H
|
||||
|
||||
#include "ImageApply.h"
|
||||
|
||||
class CImageApplyDiscardBlank : public CImageApply
|
||||
{
|
||||
public:
|
||||
CImageApplyDiscardBlank(bool isnormal=true);
|
||||
virtual ~CImageApplyDiscardBlank(void);
|
||||
|
||||
virtual void apply(cv::Mat& pDib,int side);
|
||||
|
||||
private:
|
||||
void setIntensity(int val);
|
||||
void setMinArea(int val);
|
||||
int ProcessRectR(cv::Mat & image, cv::RotatedRect & rotatedRect, std::vector<cv::Point>& maxContour, double scale, double thresh, int blobAreaSize);
|
||||
bool Scalar_LE(cv::Scalar& val1, cv::Scalar& val2);
|
||||
void GetContours(const cv::Mat& src, std::vector<std::vector<cv::Point>>& contours, std::vector<cv::Vec4i>& hierarchy, int retr = cv::RETR_CCOMP);
|
||||
private:
|
||||
int dSize;
|
||||
|
||||
bool m_res;
|
||||
cv::Scalar devTh;
|
||||
|
||||
bool isNormalDiscard;
|
||||
cv::Mat getRoiMat(cv::Mat& pDib);
|
||||
};
|
||||
|
||||
#endif // !IMAGE_APPLY_DISCARD_BLANK_H
|
|
@ -1,18 +0,0 @@
|
|||
#ifndef IMAGE_APPLY_HEADER_H
|
||||
#define IMAGE_APPLY_HEADER_H
|
||||
|
||||
#include "../stdafx.h"
|
||||
#include "ImageApply.h"
|
||||
#include "ImageApplyAdjustColors.h"
|
||||
#include "ImageApplyAutoCrop.h"
|
||||
#include "ImageApplyBWBinaray.h"
|
||||
#include "ImageApplyChannel.h"
|
||||
#include "ImageApplyCrop.h"
|
||||
#include "ImageApplyDiscardBlank.h"
|
||||
#include "ImageApplyOutHole.h"
|
||||
#include "ImageApplyResize.h"
|
||||
#include "ImageApplyRotation.h"
|
||||
#include "ImageApplySharpen.h"
|
||||
#include "ImageApplyTextOrientation.h"
|
||||
|
||||
#endif
|
|
@ -1,204 +0,0 @@
|
|||
#include "ImageApplyOutHole.h"
|
||||
#include "ImageProcess_Public.h"
|
||||
|
||||
ImageOutHole::ImageOutHole(void)
|
||||
{
|
||||
}
|
||||
|
||||
ImageOutHole::~ImageOutHole(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ImageOutHole::puncture(cv::Mat& front, cv::Mat& back, double threshold, float edgeScale, float borderSize, bool isDoubleFaces)
|
||||
{
|
||||
//二值化正反面图像
|
||||
threshold = std::min(std::max(threshold, 1.0), 254.0);
|
||||
cv::Mat front_thre, back_thre;
|
||||
hg::threshold_Mat(front, front_thre, threshold);
|
||||
hg::threshold_Mat(back, back_thre, threshold);
|
||||
|
||||
//反面二值化图像水平翻转
|
||||
cv::flip(back_thre, back_thre, 1); //1:Horizontal
|
||||
|
||||
//正反面图像寻边
|
||||
std::vector<std::vector<cv::Point>> contours_front, contours_back;
|
||||
std::vector<cv::Vec4i> b1_front, b1_back;
|
||||
hg::findContours(front_thre.clone(), contours_front, b1_front, cv::RETR_EXTERNAL);
|
||||
hg::findContours(back_thre.clone(), contours_back, b1_back, cv::RETR_EXTERNAL);
|
||||
|
||||
//提取正反面图像最大轮廓
|
||||
std::vector<cv::Point> maxContour_front = hg::getMaxContour(contours_front, b1_front);
|
||||
std::vector<cv::Point> maxContour_back = hg::getMaxContour(contours_back, b1_back);
|
||||
|
||||
cv::RotatedRect rrect_front = hg::getBoundingRect(maxContour_front); //提取正面最大轮廓的最小外接矩形
|
||||
cv::RotatedRect rrect_back = hg::getBoundingRect(maxContour_back); //提取反面最大轮廓的最小外接矩形
|
||||
|
||||
//提取正反面图像重叠部分区域
|
||||
cv::Rect roi_front, roi_back;
|
||||
cv::RotatedRect mask_rotatedRect;
|
||||
getRoi(rrect_front, rrect_back, cv::Size(front.cols, front.rows), roi_front, roi_back, mask_rotatedRect);
|
||||
|
||||
cv::Mat roiMat_front(front_thre, roi_front); //在正面二值图像中截取重叠部分
|
||||
cv::Mat roiMat_back(back_thre, roi_back); //在反面二值图像中截取重叠部分
|
||||
|
||||
//正反面二值图像做或运算,真正镂空区域保留0,其他地方填充为255
|
||||
//为了避免孔洞彻底贯穿纸边,认为绘制纸张轮廓,确保所有孔洞为封闭图形,不会与背景粘连。
|
||||
cv::Mat mask;
|
||||
bitwise_or(roiMat_front, roiMat_back, mask); //或运算,正反面二值图像重叠
|
||||
|
||||
//二值图像重叠图像颜色取反,膨胀,提取轮廓
|
||||
std::vector<std::vector<cv::Point>> contours_mask;
|
||||
std::vector<cv::Vec4i> b1_mask;
|
||||
bitwise_not(mask, mask);
|
||||
|
||||
dilate(mask, mask, cv::Mat(), cv::Point(-1, -1), 3, cv::BORDER_CONSTANT, cv::Scalar(255)); //膨胀算法,增大孔洞连通区域面积
|
||||
|
||||
polylines(mask, hg::getVertices(mask_rotatedRect), true, cv::Scalar(0), 15); //绘制纸张矩形边缘
|
||||
|
||||
hg::findContours(mask.clone(), contours_mask, b1_mask, cv::RETR_TREE); //提取重叠图像轮廓
|
||||
|
||||
//过滤非孔洞的联通区域
|
||||
std::vector<std::vector<cv::Point>> hole_contours = filterPoly(contours_mask, b1_mask, mask_rotatedRect, edgeScale, borderSize);
|
||||
for (int i = 0; i < hole_contours.size(); i++)
|
||||
cv::drawContours(mask, hole_contours, i, cv::Scalar(127), 2);
|
||||
|
||||
for (size_t i = 0; i < hole_contours.size(); i++)
|
||||
{
|
||||
cv::Scalar color = getBackGroudColor(front(roi_front), hole_contours[i]);
|
||||
cv::Mat temp = front(roi_front);
|
||||
hg::fillPoly(temp, hole_contours[i], color);
|
||||
}
|
||||
|
||||
if (isDoubleFaces)
|
||||
{
|
||||
int width_ = roi_back.width;
|
||||
roi_back.x = back.cols - roi_back.width - roi_back.x; //因为之前反面图像翻转,所以现在ROI也要进行相应翻转
|
||||
for (size_t i = 0; i < hole_contours.size(); i++)
|
||||
{
|
||||
std::vector<cv::Point> hole_contour;
|
||||
for (size_t j = 0; j < hole_contours[i].size(); j++)
|
||||
hole_contour.push_back(cv::Point(width_ - hole_contours[i][j].x - 1, hole_contours[i][j].y));
|
||||
|
||||
cv::Scalar color = getBackGroudColor(back(roi_back), hole_contour);
|
||||
cv::Mat temp = back(roi_back);
|
||||
hg::fillPoly(temp, hole_contour, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ImageOutHole::getRoi(cv::RotatedRect rrect_front, cv::RotatedRect rrect_back, cv::Size srcSize,
|
||||
cv::Rect& roi_front, cv::Rect& roi_back, cv::RotatedRect& mask_rotatedRect)
|
||||
{
|
||||
cv::Size size(static_cast<int>(rrect_front.size.width + rrect_back.size.width) / 2, static_cast<int>(rrect_front.size.height + rrect_back.size.height) / 2);
|
||||
float angle = (rrect_front.angle + rrect_back.angle) / 2;
|
||||
|
||||
rrect_front.size = rrect_back.size = size;
|
||||
rrect_front.angle = rrect_back.angle = angle;
|
||||
|
||||
roi_front = rrect_front.boundingRect();
|
||||
roi_back = rrect_back.boundingRect();
|
||||
|
||||
if (roi_front.width != roi_back.width || roi_front.height != roi_back.height)
|
||||
{
|
||||
roi_front.height = roi_back.height;
|
||||
roi_front.width = roi_back.width;
|
||||
}
|
||||
|
||||
cv::Point offset(0, 0);
|
||||
int top = std::min(roi_front.y, roi_back.y);
|
||||
if (top < 0)
|
||||
{
|
||||
roi_front.y -= top;
|
||||
roi_back.y -= top;
|
||||
roi_front.height += top;
|
||||
roi_back.height += top;
|
||||
offset.y += top;
|
||||
}
|
||||
|
||||
int left = std::min(roi_front.x, roi_back.x);
|
||||
if (left < 0)
|
||||
{
|
||||
roi_front.x -= left;
|
||||
roi_back.x -= left;
|
||||
roi_front.width += left;
|
||||
roi_back.width += left;
|
||||
offset.x += left;
|
||||
}
|
||||
|
||||
int right = std::max(roi_front.x + roi_front.width, roi_back.x + roi_back.width);
|
||||
if (right >= srcSize.width)
|
||||
{
|
||||
roi_front.width -= (right - srcSize.width + 1);
|
||||
roi_back.width -= (right - srcSize.width + 1);
|
||||
}
|
||||
|
||||
int bottom = std::max(roi_front.y + roi_front.height, roi_back.y + roi_back.height);
|
||||
if (bottom >= srcSize.height)
|
||||
{
|
||||
roi_front.height -= (bottom - srcSize.height + 1);
|
||||
roi_back.height -= (bottom - srcSize.height + 1);
|
||||
}
|
||||
|
||||
mask_rotatedRect.center = cv::Point((roi_front.width + offset.x) / 2, (roi_front.height + offset.y) / 2);
|
||||
mask_rotatedRect.size = size;
|
||||
mask_rotatedRect.angle = angle;
|
||||
}
|
||||
|
||||
std::vector<std::vector<cv::Point>> ImageOutHole::filterPoly(std::vector<std::vector<cv::Point>>& contours, const std::vector<cv::Vec4i>& m,
|
||||
cv::RotatedRect roi, float edgeScale, float areaThreshold)
|
||||
{
|
||||
edgeScale = std::min(0.49f, std::max(edgeScale, 0.0f));
|
||||
cv::RotatedRect roi2(roi.center, cv::Size(static_cast<int>(roi.size.width * (1 - edgeScale * 2)),
|
||||
static_cast<int>(roi.size.height * (1 - edgeScale * 2))), roi.angle);
|
||||
|
||||
std::vector<cv::Point> vertices_roi1 = hg::getVertices(roi);
|
||||
std::vector<cv::Point> vertices_roi2 = hg::getVertices(roi2);
|
||||
|
||||
std::vector<std::vector<cv::Point>> hole_contours;
|
||||
for (size_t i = 0, length = contours.size(); i < length; i++)
|
||||
{
|
||||
if (m[i][2] != -1) continue;
|
||||
|
||||
cv::RotatedRect rrect = hg::getBoundingRect(contours[i]);
|
||||
if (rrect.size.width > areaThreshold || rrect.size.height > areaThreshold) continue;
|
||||
|
||||
bool enabled = true;
|
||||
for (size_t j = 0, count = contours[i].size(); j < count; j++)
|
||||
{
|
||||
cv::Point p(contours[i][j]);
|
||||
double temp1 = pointPolygonTest(vertices_roi1, p, false); //判断是否在纸张内 1:内;0:上;-1:外
|
||||
double temp2 = pointPolygonTest(vertices_roi2, p, false); //判断是否在边缘区域内 1:内;0:上;-1:外
|
||||
//如果在纸张外,或者边缘内,视为非孔洞
|
||||
if (temp1 < 0 || temp2 > 0)
|
||||
{
|
||||
enabled = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (enabled)
|
||||
hole_contours.push_back(contours[i]);
|
||||
}
|
||||
return hole_contours;
|
||||
}
|
||||
|
||||
cv::Scalar ImageOutHole::getBackGroudColor(const cv::Mat &image, const std::vector<cv::Point> pixelPoints)
|
||||
{
|
||||
if (pixelPoints.empty()) return cv::Scalar(255, 255, 255);
|
||||
|
||||
int channels = image.channels();
|
||||
|
||||
int temp[3] = { 0 };
|
||||
for (size_t i = 0, length = pixelPoints.size(); i < length; ++i)
|
||||
{
|
||||
int x = cv::min(cv::max(0, pixelPoints[i].x), image.cols - 1);
|
||||
int y = cv::min(cv::max(0, pixelPoints[i].y), image.rows - 1);
|
||||
|
||||
const unsigned char* ptr = image.ptr(y, x);
|
||||
for (int j = 0; j < channels; ++j)
|
||||
temp[j] += ptr[j];
|
||||
}
|
||||
|
||||
return cv::Scalar(temp[0] / pixelPoints.size(), temp[1] / pixelPoints.size(), temp[2] / pixelPoints.size());
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
#ifndef IMAGE_APPLY_OUT_HOLE_H
|
||||
#define IMAGE_APPLY_OUT_HOLE_H
|
||||
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include <vector>
|
||||
|
||||
class ImageOutHole
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
ImageOutHole(void);
|
||||
|
||||
~ImageOutHole(void);
|
||||
|
||||
public:
|
||||
|
||||
void puncture(cv::Mat& front, cv::Mat& back, double threshold, float edgeScale, float borderSize, bool isDoubleFaces = true);
|
||||
|
||||
private:
|
||||
|
||||
void getRoi(cv::RotatedRect rrect_front, cv::RotatedRect rrect_back, cv::Size srcSize, cv::Rect& roi_front,
|
||||
cv::Rect& roi_back, cv::RotatedRect& mask_rotatedRect);
|
||||
|
||||
std::vector<std::vector<cv::Point> > filterPoly(std::vector<std::vector<cv::Point>>& contours, const std::vector<cv::Vec4i> &m, cv::RotatedRect roi,
|
||||
float edgeScale, float areaThreshold);
|
||||
|
||||
cv::Scalar getBackGroudColor(const cv::Mat& image, const std::vector<cv::Point> pixelPoints);
|
||||
};
|
||||
|
||||
#endif // !IMAGE_APPLY_OUT_HOLE_H
|
|
@ -1,22 +0,0 @@
|
|||
#include "ImageApplyResize.h"
|
||||
|
||||
CImageApplyResize::CImageApplyResize()
|
||||
: m_fx(1.0)
|
||||
, m_fy(1.0)
|
||||
, m_type(RATIO)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CImageApplyResize::~CImageApplyResize(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void CImageApplyResize::apply(cv::Mat& pDib,int side)
|
||||
{
|
||||
if (m_type == RATIO)
|
||||
cv::resize(pDib, pDib, cv::Size(0, 0), m_fx, m_fy);
|
||||
else
|
||||
cv::resize(pDib, pDib, m_dSize);
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
#ifndef IMAGE_APPLY_RESIZE_H
|
||||
#define IMAGE_APPLY_RESIZE_H
|
||||
|
||||
#include "imageapply.h"
|
||||
|
||||
class CImageApplyResize : public CImageApply
|
||||
{
|
||||
public:
|
||||
|
||||
enum ResizeType
|
||||
{
|
||||
RATIO,
|
||||
DSIZE
|
||||
};
|
||||
|
||||
public:
|
||||
CImageApplyResize();
|
||||
|
||||
virtual ~CImageApplyResize(void);
|
||||
|
||||
virtual void apply(cv::Mat& pDib,int side);
|
||||
|
||||
double getFX() { return m_fx; }
|
||||
|
||||
double getFY() { return m_fy; }
|
||||
|
||||
cv::Size getDSize() { return m_dSize; }
|
||||
|
||||
ResizeType getType() { return m_type; }
|
||||
|
||||
void setFX(double value) { m_fx = value; }
|
||||
|
||||
void setFY(double value) { m_fy = value; }
|
||||
|
||||
void setDSize(const cv::Size& size) { m_dSize = size; }
|
||||
|
||||
void setType(ResizeType type) { m_type = type; }
|
||||
|
||||
private:
|
||||
double m_fx;
|
||||
double m_fy;
|
||||
cv::Size m_dSize;
|
||||
ResizeType m_type;
|
||||
};
|
||||
|
||||
#endif // !IMAGE_APPLY_RESIZE_H
|
|
@ -1,59 +0,0 @@
|
|||
#include "ImageApplyRotation.h"
|
||||
|
||||
CImageApplyRotation::CImageApplyRotation(int index_of_orentation, bool m_bBackRotate)
|
||||
: m_nRotation(index_of_orentation), m_BackRotate(m_bBackRotate)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CImageApplyRotation::~CImageApplyRotation()
|
||||
{
|
||||
}
|
||||
|
||||
void CImageApplyRotation::setRotationFlip(int flip)
|
||||
{
|
||||
m_nRotation = flip;
|
||||
}
|
||||
|
||||
int CImageApplyRotation::getRotetion()
|
||||
{
|
||||
return m_nRotation;
|
||||
}
|
||||
|
||||
void CImageApplyRotation::apply(cv::Mat & pDib, int side)
|
||||
{
|
||||
//FileTools::write_log("D:\\1.txt", "enter CImageRotation apply");
|
||||
if (m_nRotation == 4)//自动文本方向识别
|
||||
{
|
||||
}
|
||||
else if (m_BackRotate&&side == 1)//背面旋转180
|
||||
{
|
||||
if (m_nRotation != 2)//旋转180度
|
||||
{
|
||||
if (m_nRotation == 1 || m_nRotation == 3)//90° -90°
|
||||
{
|
||||
transpose(pDib, pDib);
|
||||
flip(pDib, pDib, m_nRotation == 1 ? 0 : 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
flip(pDib, pDib, 0);
|
||||
flip(pDib, pDib, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else //zh
|
||||
{
|
||||
if (m_nRotation == 1 || m_nRotation == 3)//90° -90°
|
||||
{
|
||||
transpose(pDib, pDib);
|
||||
flip(pDib, pDib, m_nRotation == 1 ? 1 : 0);
|
||||
}
|
||||
else if (m_nRotation == 2)
|
||||
{
|
||||
flip(pDib, pDib, 0);
|
||||
flip(pDib, pDib, 1);
|
||||
}
|
||||
}
|
||||
//FileTools::write_log("D:\\1.txt", "exit CImageRotation apply");
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
#ifndef IMAGE_APPLY_ROTATION_H
|
||||
#define IMAGE_APPLY_ROTATION_H
|
||||
|
||||
#include "ImageApply.h"
|
||||
|
||||
class CImageApplyRotation : public CImageApply
|
||||
{
|
||||
enum RotationType
|
||||
{
|
||||
ROTATE_90_CLOCKWISE,
|
||||
ROTATE_180,
|
||||
ROTATE_90_COUNTERCLOCKWISE
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
CImageApplyRotation(int index_of_orentation,bool m_bBackRotate=false);
|
||||
|
||||
virtual ~CImageApplyRotation();
|
||||
|
||||
void setRotationFlip(int flip);
|
||||
|
||||
int getRotetion();
|
||||
|
||||
// ͨ¹ý CImageApply ¼Ì³Ð
|
||||
virtual void apply(cv::Mat & pDib,int side) override;
|
||||
|
||||
private:
|
||||
int m_nRotation;
|
||||
bool m_BackRotate;
|
||||
int side;
|
||||
};
|
||||
|
||||
#endif // !IMAGE_APPLY_ROTATION_H
|
|
@ -1,17 +0,0 @@
|
|||
#include "ImageApplySharpen.h"
|
||||
|
||||
CImageApplySharpen::CImageApplySharpen()
|
||||
: kernel(5, 5, CV_32FC1)
|
||||
{
|
||||
float kernel_data[] = { -0.1f, 0, 0, 0, -0.1f, 0, 0, 0, 0, 0, 0, 0, 1.5f, 0, 0, 0, 0, 0, 0, 0, -0.1f, 0, 0, 0, -0.1f };
|
||||
memcpy(kernel.data, kernel_data, sizeof(float) * 25);
|
||||
}
|
||||
|
||||
CImageApplySharpen::~CImageApplySharpen()
|
||||
{
|
||||
}
|
||||
|
||||
void CImageApplySharpen::apply(cv::Mat & pDib, int side)
|
||||
{
|
||||
cv::filter2D(pDib, pDib, pDib.depth(), kernel);
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
#ifndef IMAGE_APPLY_SHARPEN_H
|
||||
#define IMAGE_APPLY_SHARPEN_H
|
||||
|
||||
#include "ImageApply.h"
|
||||
|
||||
class CImageApplySharpen : public CImageApply
|
||||
{
|
||||
public:
|
||||
CImageApplySharpen();
|
||||
|
||||
virtual ~CImageApplySharpen();
|
||||
|
||||
virtual void apply(cv::Mat& pDib, int side);
|
||||
private:
|
||||
cv::Mat kernel;
|
||||
};
|
||||
|
||||
#endif // !IMAGE_APPLY_SHARPEN_H
|
|
@ -1,10 +0,0 @@
|
|||
#include "ImageApplyTextOrientation.h"
|
||||
|
||||
ImageApplyTextOrientation::ImageApplyTextOrientation()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ImageApplyTextOrientation::~ImageApplyTextOrientation()
|
||||
{
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
#ifndef IMAGE_APPLY_TEXT_ORIENTATION_H
|
||||
#define IMAGE_APPLY_TEXT_ORIENTATION_H
|
||||
|
||||
#include "ImageApply.h"
|
||||
|
||||
class ImageApplyTextOrientation
|
||||
{
|
||||
public:
|
||||
ImageApplyTextOrientation();
|
||||
~ImageApplyTextOrientation();
|
||||
};
|
||||
|
||||
#endif // !IMAGE_APPLY_TEXT_ORIENTATION_H
|
||||
|
|
@ -1,289 +0,0 @@
|
|||
#include "ImageProcess_Public.h"
|
||||
|
||||
namespace hg
|
||||
{
|
||||
void convexHull(const std::vector<cv::Point>& src, std::vector<cv::Point>& dst, bool clockwise)
|
||||
{
|
||||
CvMemStorage* storage = cvCreateMemStorage(); //
|
||||
CvSeq* ptseq = cvCreateSeq(CV_SEQ_KIND_GENERIC | CV_32SC2, sizeof(CvContour), sizeof(CvPoint), storage); //ptseqstorage
|
||||
|
||||
//
|
||||
for (const cv::Point& item : src)
|
||||
{
|
||||
CvPoint p;
|
||||
p.x = item.x;
|
||||
p.y = item.y;
|
||||
cvSeqPush(ptseq, &p);
|
||||
}
|
||||
|
||||
//¦Ìhullstorage
|
||||
CvSeq* hull = cvConvexHull2(ptseq, nullptr, clockwise ? CV_CLOCKWISE : CV_COUNTER_CLOCKWISE, 0);
|
||||
|
||||
//dst
|
||||
dst.clear();
|
||||
int hullCount = hull->total;
|
||||
for (int i = 0; i < hullCount; i++)
|
||||
dst.push_back(**CV_GET_SEQ_ELEM(CvPoint*, hull, i));
|
||||
|
||||
//storage
|
||||
cvReleaseMemStorage(&storage);
|
||||
}
|
||||
|
||||
#define R_COLOR 255
|
||||
void fillBlackBackGround(cv::Mat& src, std::vector<cv::Point> points)
|
||||
{
|
||||
uint index_top = 0;
|
||||
uint index_bottom = 0;
|
||||
for (size_t i = 0, length = points.size(); i < length; i++)
|
||||
{
|
||||
if (points[i].y < points[index_top].y)
|
||||
index_top = i;
|
||||
if (points[i].y > points[index_bottom].y)
|
||||
index_bottom = i;
|
||||
}
|
||||
|
||||
std::vector<cv::Point> edge_left;
|
||||
uint temp = index_top;
|
||||
while (temp != index_bottom)
|
||||
{
|
||||
edge_left.push_back(points[temp]);
|
||||
temp = (temp + points.size() - 1) % points.size();
|
||||
}
|
||||
edge_left.push_back(points[index_bottom]);
|
||||
|
||||
std::vector<cv::Point> edge_right;
|
||||
temp = index_top;
|
||||
while (temp != index_bottom)
|
||||
{
|
||||
edge_right.push_back(points[temp]);
|
||||
temp = (temp + points.size() + 1) % points.size();
|
||||
}
|
||||
edge_right.push_back(points[index_bottom]);
|
||||
|
||||
std::vector<int> left_edge;
|
||||
std::vector<int> left_ede_y;
|
||||
for (size_t i = 0, length = edge_left.size() - 1; i < length; i++)
|
||||
{
|
||||
int y_top = edge_left[i].y;
|
||||
int x_top = edge_left[i].x;
|
||||
int y_bottom = edge_left[i + 1].y;
|
||||
int x_bottom = edge_left[i + 1].x;
|
||||
for (int y = y_top; y < y_bottom; y++)
|
||||
if (y_top != y_bottom && y < src.rows)
|
||||
{
|
||||
left_edge.push_back(((x_bottom - x_top) * y + x_top * y_bottom - x_bottom * y_top) / (y_bottom - y_top));
|
||||
left_ede_y.push_back(y);
|
||||
}
|
||||
}
|
||||
size_t step = src.step;
|
||||
unsigned char* ptr = src.data + static_cast<uint>(edge_left[0].y) * step;
|
||||
for (size_t i = 0, length = cv::min(left_edge.size(), static_cast<size_t>(src.rows)); i < length; i++)
|
||||
{
|
||||
int offset = left_edge[i];
|
||||
if (offset < src.cols - 1 && offset > 0)
|
||||
memset(ptr + i * step, R_COLOR, static_cast<size_t>((offset + 1) * src.channels()));
|
||||
}
|
||||
std::vector<int> right_edge;
|
||||
std::vector<int> right_edge_y;
|
||||
for (size_t i = 0, length = edge_right.size() - 1; i < length; i++)
|
||||
{
|
||||
int y_top = edge_right[i].y;
|
||||
int x_top = edge_right[i].x;
|
||||
int y_bottom = edge_right[i + 1].y;
|
||||
int x_bottom = edge_right[i + 1].x;
|
||||
for (int y = y_top; y < y_bottom; y++)
|
||||
if (y_top != y_bottom && y < src.rows)
|
||||
{
|
||||
right_edge.push_back(((x_bottom - x_top) * y + x_top * y_bottom - x_bottom * y_top) / (y_bottom - y_top));
|
||||
right_edge_y.push_back(y);
|
||||
}
|
||||
}
|
||||
|
||||
ptr = src.data + static_cast<uint>(edge_right[0].y) * step;
|
||||
for (size_t i = 0, length = cv::min(right_edge.size(), static_cast<size_t>(src.rows)); i < length; i++)
|
||||
{
|
||||
int offset = right_edge[i];
|
||||
if (offset < src.cols - 1 && offset > 0)
|
||||
memset(ptr + i * step + offset * src.channels(), R_COLOR, step - static_cast<size_t>(offset * src.channels()));
|
||||
}
|
||||
|
||||
if (edge_left[0].y > 0)
|
||||
memset(src.data, R_COLOR, static_cast<size_t>(edge_left[0].y) * step);
|
||||
|
||||
if (edge_left.back().y < src.rows - 1)
|
||||
memset(src.data + static_cast<size_t>(edge_left.back().y) * step, R_COLOR,
|
||||
static_cast<size_t>(src.rows - edge_left.back().y) * step);
|
||||
}
|
||||
|
||||
void fillPoly(cv::Mat & image, const std::vector<cv::Point>& contours, const cv::Scalar & color)
|
||||
{
|
||||
size_t count = contours.size();
|
||||
cv::Point * points = new cv::Point[count];
|
||||
for (size_t i = 0; i < count; i++)
|
||||
points[i] = contours[i];
|
||||
|
||||
const cv::Point* pointss[1] = { points };
|
||||
int npts[1];
|
||||
npts[0] = static_cast<int>(count);
|
||||
|
||||
cv::fillPoly(image, pointss, npts, 1, color);
|
||||
|
||||
delete[] points;
|
||||
}
|
||||
|
||||
void findContours(const cv::Mat& src, std::vector<std::vector<cv::Point>>& contours, std::vector<cv::Vec4i>& hierarchy, int retr, int method, cv::Point offset)
|
||||
{
|
||||
CvMat c_image = src;
|
||||
cv::MemStorage storage(cvCreateMemStorage());
|
||||
CvSeq* _ccontours = nullptr;
|
||||
cvFindContours(&c_image, storage, &_ccontours, sizeof(CvContour), retr, method, CvPoint(offset));
|
||||
|
||||
if (!_ccontours)
|
||||
{
|
||||
contours.clear();
|
||||
return;
|
||||
}
|
||||
cv::Seq<CvSeq*> all_contours(cvTreeToNodeSeq(_ccontours, sizeof(CvSeq), storage));
|
||||
size_t total = all_contours.size();
|
||||
contours.resize(total);
|
||||
|
||||
cv::SeqIterator<CvSeq*> it = all_contours.begin();
|
||||
for (size_t i = 0; i < total; i++, ++it)
|
||||
{
|
||||
CvSeq* c = *it;
|
||||
reinterpret_cast<CvContour*>(c)->color = static_cast<int>(i);
|
||||
int count = c->total;
|
||||
int* data = new int[static_cast<size_t>(count * 2)];
|
||||
cvCvtSeqToArray(c, data);
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
contours[i].push_back(cv::Point(data[j * 2], data[j * 2 + 1]));
|
||||
}
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
hierarchy.resize(total);
|
||||
it = all_contours.begin();
|
||||
for (size_t i = 0; i < total; i++, ++it)
|
||||
{
|
||||
CvSeq* c = *it;
|
||||
int h_next = c->h_next ? reinterpret_cast<CvContour*>(c->h_next)->color : -1;
|
||||
int h_prev = c->h_prev ? reinterpret_cast<CvContour*>(c->h_prev)->color : -1;
|
||||
int v_next = c->v_next ? reinterpret_cast<CvContour*>(c->v_next)->color : -1;
|
||||
int v_prev = c->v_prev ? reinterpret_cast<CvContour*>(c->v_prev)->color : -1;
|
||||
hierarchy[i] = cv::Vec4i(h_next, h_prev, v_next, v_prev);
|
||||
}
|
||||
|
||||
storage.release();
|
||||
}
|
||||
|
||||
cv::RotatedRect getBoundingRect(const std::vector<cv::Point>& contour)
|
||||
{
|
||||
if (contour.empty()) return {};
|
||||
|
||||
cv::RotatedRect rect = minAreaRect(contour);
|
||||
if (rect.angle < -45)
|
||||
{
|
||||
rect.angle += 90;
|
||||
float temp = rect.size.width;
|
||||
rect.size.width = rect.size.height;
|
||||
rect.size.height = temp;
|
||||
}
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
std::vector<cv::Point> getMaxContour(const std::vector<std::vector<cv::Point>>& contours, const std::vector<cv::Vec4i>& hierarchy)
|
||||
{
|
||||
std::vector<cv::Point> maxContour;
|
||||
if (contours.size() < 1) return {};
|
||||
|
||||
for (size_t i = 0, length = hierarchy.size(); i < length; i++)
|
||||
if (hierarchy[i][3] == -1)
|
||||
for (const auto &item : contours[i])
|
||||
maxContour.push_back(item);
|
||||
|
||||
return maxContour;
|
||||
}
|
||||
|
||||
std::vector<cv::Point> getVertices(const cv::RotatedRect& rect)
|
||||
{
|
||||
cv::Point2f box[4];
|
||||
rect.points(box);
|
||||
std::vector<cv::Point> points;
|
||||
for (int i = 0; i < 4; i++)
|
||||
points.push_back(cv::Point(box[i]));
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
void polyIndent(std::vector<cv::Point>& points, float indent)
|
||||
{
|
||||
static cv::Point zero(0, 0);
|
||||
cv::Point center = getBoundingRect(points).center;
|
||||
for (cv::Point& item : points)
|
||||
{
|
||||
cv::Point vec = item - center;
|
||||
if (vec != zero)
|
||||
{
|
||||
int length = vec.x * vec.x + vec.y * vec.y;
|
||||
float x = cv::sqrt(static_cast<float>(vec.x * vec.x / length)) * indent;
|
||||
float y = cv::sqrt(static_cast<float>(vec.y * vec.y / length)) * indent;
|
||||
|
||||
if (vec.x < 0) x *= -1.0f;
|
||||
if (vec.y < 0) y *= -1.0f;
|
||||
|
||||
item.x -= static_cast<int>(x);
|
||||
item.y -= static_cast<int>(y);
|
||||
}
|
||||
}
|
||||
|
||||
hg::convexHull(points, points);
|
||||
}
|
||||
|
||||
cv::Mat transforColor(const cv::Mat& src)
|
||||
{
|
||||
if (src.channels() == 1) return src.clone();
|
||||
|
||||
std::vector<cv::Mat> channels(3);
|
||||
cv::split(src, channels);
|
||||
|
||||
cv::Mat temp, dst;
|
||||
bitwise_or(channels[0], channels[1], temp);
|
||||
bitwise_or(channels[2], temp, dst);
|
||||
temp.release();
|
||||
|
||||
for (cv::Mat& index : channels)
|
||||
index.release();
|
||||
return dst;
|
||||
}
|
||||
|
||||
void threshold_Mat(const cv::Mat& src, cv::Mat& dst, double thre)
|
||||
{
|
||||
if (src.channels() == 3)
|
||||
{
|
||||
#if 0
|
||||
if (cl_res.context)
|
||||
transforColor_threshold_opencl(src, dst, static_cast<uchar>(thre));
|
||||
else
|
||||
#endif
|
||||
{
|
||||
cv::Mat gray = transforColor(src);
|
||||
cv::threshold(gray, dst, thre, 255, cv::THRESH_BINARY);
|
||||
gray.release();
|
||||
}
|
||||
}
|
||||
else
|
||||
cv::threshold(src, dst, thre, 255, cv::THRESH_BINARY);
|
||||
}
|
||||
|
||||
cv::Point warpPoint(cv::Point p, const cv::Mat& warp_mat)
|
||||
{
|
||||
double src_data[3] = { static_cast<double>(p.x), static_cast<double>(p.y), 1 };
|
||||
cv::Mat src(3, 1, warp_mat.type(), src_data); //warp_mat.type() == CV_64FC1
|
||||
|
||||
cv::Mat dst = warp_mat * src;
|
||||
double* ptr = reinterpret_cast<double*>(dst.data);
|
||||
return cv::Point(static_cast<int>(ptr[0]), static_cast<int>(ptr[1]));
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
#ifndef IMAGE_PROCESS_PUBLIC_H
|
||||
#define IMAGE_PROCESS_PUBLIC_H
|
||||
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace hg
|
||||
{
|
||||
void convexHull(const std::vector<cv::Point>& src, std::vector<cv::Point>& dst, bool clockwise = false);
|
||||
|
||||
void fillBlackBackGround(cv::Mat& src, std::vector<cv::Point> points);
|
||||
|
||||
void fillPoly(cv::Mat& image, const std::vector<cv::Point>& contours, const cv::Scalar& color);
|
||||
|
||||
void findContours(const cv::Mat& src, std::vector<std::vector<cv::Point>>& contours, std::vector<cv::Vec4i>& hierarchy,
|
||||
int retr = cv::RETR_LIST, int method = cv::CHAIN_APPROX_SIMPLE, cv::Point offset = cv::Point(0, 0));
|
||||
|
||||
cv::RotatedRect getBoundingRect(const std::vector<cv::Point>& contour);
|
||||
|
||||
std::vector<cv::Point> getMaxContour(const std::vector<std::vector<cv::Point>>& contours, const std::vector<cv::Vec4i>& hierarchy);
|
||||
|
||||
std::vector<cv::Point> getVertices(const cv::RotatedRect& rect);
|
||||
|
||||
void polyIndent(std::vector<cv::Point>& points, float indent);
|
||||
|
||||
void threshold_Mat(const cv::Mat& src, cv::Mat& dst, double thre);
|
||||
|
||||
cv::Mat transforColor(const cv::Mat& src);
|
||||
|
||||
cv::Point warpPoint(cv::Point p, const cv::Mat& warp_mat);
|
||||
}
|
||||
|
||||
#endif // !IMAGE_PROCESS_C_H
|
|
@ -1,75 +0,0 @@
|
|||
#include "stdafx.h"
|
||||
#include "ImageTranferBW.h"
|
||||
|
||||
using namespace cv;
|
||||
ImageTranferBW::ImageTranferBW(cv::Mat & mat)
|
||||
{
|
||||
threshold(mat, mat, 200, 255, CV_THRESH_BINARY);
|
||||
|
||||
float kernel_data[] = { -0.1f, 0, 0, 0, -0.1f, 0, 0, 0, 0, 0, 0, 0, 1.5f, 0, 0, 0, 0, 0, 0, 0, -0.1f, 0, 0, 0, -0.1f };
|
||||
Mat kernel(5, 5, CV_32FC1, kernel_data);
|
||||
filter2D(mat, mat, mat.depth(), kernel);
|
||||
|
||||
m_width = mat.cols;
|
||||
m_height = mat.rows;
|
||||
|
||||
//!< Éú³ÉͼÏñ
|
||||
m_buffer = new unsigned char[height()*step()];
|
||||
memset(m_buffer, 0, height()*step());
|
||||
unsigned char* binary = m_buffer;
|
||||
int n_lineByte = (m_width + 7) >> 3;
|
||||
unsigned char * imageData = mat.data;
|
||||
unsigned char temp;
|
||||
for (int row = 0; row < m_height; row++)
|
||||
{
|
||||
for (int col = 0; col < m_width; col++)
|
||||
{
|
||||
int pos = col % 8;
|
||||
int pix = *(imageData + row * mat.step1() + col);
|
||||
temp = 1 << (7 - pos);
|
||||
if (pix == 255)
|
||||
{
|
||||
*(binary + row * m_lineByte + col / 8) |= temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(binary + row * m_lineByte + col / 8) &= (~temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImageTranferBW::~ImageTranferBW()
|
||||
{
|
||||
if (m_buffer != NULL)
|
||||
{
|
||||
delete[] m_buffer;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char * ImageTranferBW::getLineBits(int line/* = 0*/)
|
||||
{
|
||||
return m_buffer + step()*line;
|
||||
}
|
||||
|
||||
int ImageTranferBW::step()
|
||||
{
|
||||
int n_lineByte = (m_width + 7) >> 3;
|
||||
m_lineByte = ((n_lineByte * 8 + 31) >> 5) << 2;
|
||||
return m_lineByte;
|
||||
}
|
||||
|
||||
int ImageTranferBW::bpp()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ImageTranferBW::width()
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
int ImageTranferBW::height()
|
||||
{
|
||||
return m_height;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
#pragma once
|
||||
#include "ImageTransfer.h"
|
||||
|
||||
class ImageTranferBW :
|
||||
public ImageTransfer
|
||||
{
|
||||
public:
|
||||
ImageTranferBW(cv::Mat &mat);
|
||||
~ImageTranferBW();
|
||||
|
||||
// ͨ¹ý ImageTransfer ¼Ì³Ð
|
||||
virtual unsigned char * getLineBits(int line = 0) override;
|
||||
virtual int step() override;
|
||||
virtual int bpp() override;
|
||||
virtual int width() override;
|
||||
virtual int height() override;
|
||||
private:
|
||||
unsigned char* m_buffer;
|
||||
int m_width;
|
||||
int m_height;
|
||||
int m_lineByte;
|
||||
};
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
#include "stdafx.h"
|
||||
#include "ImageTranferMat.h"
|
||||
|
||||
ImageTranferMat::ImageTranferMat(cv::Mat & mat):m_mat(mat) {}
|
||||
|
||||
ImageTranferMat::~ImageTranferMat(){}
|
||||
|
||||
unsigned char * ImageTranferMat::getLineBits(int line/* = 0*/)
|
||||
{
|
||||
return m_mat.ptr<BYTE>(line);
|
||||
}
|
||||
|
||||
int ImageTranferMat::step()
|
||||
{
|
||||
return m_mat.step1();
|
||||
}
|
||||
|
||||
int ImageTranferMat::bpp()
|
||||
{
|
||||
return m_mat.elemSize() * 8;
|
||||
}
|
||||
|
||||
int ImageTranferMat::width()
|
||||
{
|
||||
return m_mat.cols;
|
||||
}
|
||||
|
||||
int ImageTranferMat::height()
|
||||
{
|
||||
return m_mat.rows;
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
#pragma once
|
||||
#include "ImageTransfer.h"
|
||||
class ImageTranferMat :
|
||||
public ImageTransfer
|
||||
{
|
||||
public:
|
||||
ImageTranferMat(cv::Mat &mat);
|
||||
virtual ~ImageTranferMat();
|
||||
|
||||
|
||||
|
||||
// ͨ¹ý ImageTransfer ¼Ì³Ð
|
||||
virtual unsigned char * getLineBits(int line = 0) override;
|
||||
|
||||
virtual int step() override;
|
||||
|
||||
virtual int bpp() override;
|
||||
|
||||
virtual int width() override;
|
||||
|
||||
virtual int height() override;
|
||||
private:
|
||||
cv::Mat m_mat;
|
||||
|
||||
};
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
#pragma once
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
class ImageTransfer
|
||||
{
|
||||
public:
|
||||
ImageTransfer() {}
|
||||
virtual ~ImageTransfer() {}
|
||||
|
||||
virtual unsigned char* getLineBits(int line = 0) = 0;
|
||||
virtual int step() = 0;
|
||||
virtual int bpp() = 0;
|
||||
virtual int width() = 0;
|
||||
virtual int height() = 0;
|
||||
};
|
BIN
IndicatorDlg.cpp
BIN
IndicatorDlg.cpp
Binary file not shown.
BIN
IndicatorDlg.h
BIN
IndicatorDlg.h
Binary file not shown.
|
@ -1,87 +0,0 @@
|
|||
#include "StdAfx.h"
|
||||
#include "JpegBuffer.h"
|
||||
#include "jpeglib.h"
|
||||
#include "twain.h"
|
||||
//#include "filetools.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
JpegBuffer::JpegBuffer(cv::Mat buffer, int color_type,int side,int mFilter)
|
||||
{
|
||||
this->m_buffer = buffer;
|
||||
this->m_color_type=color_type;
|
||||
this->m_side=side;
|
||||
this->m_mFilter=mFilter;
|
||||
}
|
||||
|
||||
JpegBuffer::JpegBuffer(std::vector<cv::Mat> mats, int color_type, int mFilter)
|
||||
{
|
||||
matdatas = mats;
|
||||
this->m_color_type = color_type;
|
||||
this->m_mFilter = mFilter;
|
||||
}
|
||||
|
||||
JpegBuffer::JpegBuffer()
|
||||
{
|
||||
this->m_buffer = cv::Mat();
|
||||
this->m_color_type = 2;
|
||||
this->m_side = 0;
|
||||
this->m_mFilter = 0;
|
||||
}
|
||||
|
||||
|
||||
JpegBuffer::~JpegBuffer(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
unsigned char* JpegBuffer::getBuffer()
|
||||
{
|
||||
return m_buffer.data;
|
||||
}
|
||||
|
||||
cv::Mat JpegBuffer::buffer()
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
int JpegBuffer::getSize()
|
||||
{
|
||||
return m_buffer.cols;
|
||||
}
|
||||
|
||||
|
||||
cv::Mat JpegBuffer::getMat( int pixType)
|
||||
{
|
||||
JpegLib jl;
|
||||
cv::Mat image = jl.decode(m_buffer, pixType);
|
||||
return image.clone();
|
||||
}
|
||||
|
||||
std::vector<cv::Mat> JpegBuffer::getMats()
|
||||
{
|
||||
std::vector<cv::Mat> retmats;
|
||||
for (int i = 0; i < matdatas.size(); i++)
|
||||
{
|
||||
JpegLib jl;
|
||||
cv::Mat image = jl.decode(matdatas[i], m_color_type);
|
||||
retmats.push_back(image.clone());
|
||||
image.release();
|
||||
}
|
||||
return retmats;
|
||||
}
|
||||
|
||||
int JpegBuffer::getMFilter()
|
||||
{
|
||||
return m_mFilter;
|
||||
}
|
||||
|
||||
int JpegBuffer::getSide()
|
||||
{
|
||||
return m_side;
|
||||
}
|
||||
|
||||
bool JpegBuffer::empty()
|
||||
{
|
||||
return matdatas.empty();
|
||||
}
|
29
JpegBuffer.h
29
JpegBuffer.h
|
@ -1,29 +0,0 @@
|
|||
#pragma once
|
||||
#include <opencv2\opencv.hpp>
|
||||
//#include "jpeglib.h"
|
||||
|
||||
class JpegBuffer
|
||||
{
|
||||
public:
|
||||
JpegBuffer(cv::Mat buffer,int color_type=6,int side=0,int mFilter=0);
|
||||
JpegBuffer(std::vector<cv::Mat> mats, int color_type = 6,int mFilter = 0);
|
||||
JpegBuffer();
|
||||
virtual ~JpegBuffer(void);
|
||||
|
||||
unsigned char* getBuffer();
|
||||
cv::Mat buffer();
|
||||
int getSize();
|
||||
cv::Mat getMat( int pixType);
|
||||
std::vector<cv::Mat> getMats();
|
||||
int getMFilter();
|
||||
int getSide();
|
||||
bool empty();
|
||||
|
||||
private:
|
||||
|
||||
cv::Mat m_buffer;
|
||||
std::vector<cv::Mat> matdatas;
|
||||
int m_color_type;
|
||||
int m_side;
|
||||
int m_mFilter;
|
||||
};
|
458
JsonConfig.cpp
458
JsonConfig.cpp
|
@ -1,458 +0,0 @@
|
|||
#include "StdAfx.h"
|
||||
#include "JsonConfig.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <stdio.h>
|
||||
#include <sstream>
|
||||
#include "CJsonObject.hpp"
|
||||
|
||||
JsonConfig::JsonConfig(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
JsonConfig::~JsonConfig(void)
|
||||
{
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* 保存配置参数 */
|
||||
/************************************************************************/
|
||||
void JsonConfig::WriteToJson(PCONFIGPARAMS pConfigItem,const std::string fileNames,bool isConfigItem)
|
||||
{
|
||||
|
||||
neb::CJsonObject outJson;
|
||||
|
||||
outJson.AddEmptySubObject("Config");//header
|
||||
outJson["Config"].Add(PIXTYPE,(int)(pConfigItem->Pixtype));
|
||||
outJson["Config"].Add(PAPARSIZE,(int)(pConfigItem->PaperSize));
|
||||
outJson["Config"].Add(AUTOCROP,(bool)(pConfigItem->EnAutoCrop),false);
|
||||
outJson["Config"].Add(RESOLUTION,(int)(pConfigItem->Resolution));
|
||||
outJson["Config"].Add(DUPLEX,(int)(pConfigItem->Duplex));
|
||||
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(AUTOCONTRAST,(bool)(pConfigItem->EnAutoContrast),false);
|
||||
outJson["Config"].Add(CONTRAST,(int)(pConfigItem->Contrast));
|
||||
outJson["Config"].Add(GAMMA,(int)(pConfigItem->Gamma));
|
||||
|
||||
outJson["Config"].Add(FILTERTYPE,(int)(pConfigItem->Filter));
|
||||
outJson["Config"].Add(AUTODESCREW,(bool)(pConfigItem->EnAutoDescrew),false);
|
||||
outJson["Config"].Add(FILLBLACK,(bool)(pConfigItem->EnFillBlack),false);
|
||||
outJson["Config"].Add(MULTIOUTPUT,(bool)(pConfigItem->EnMultiOutPutR),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(BINDINGDETECT,(bool)(pConfigItem->EnBindingDetect),false);
|
||||
outJson["Config"].Add(SCANCOUNT,(int)(pConfigItem->ScanCount));
|
||||
outJson["Config"].Add(DOCORIENTATION,(int)(pConfigItem->Orentation));
|
||||
outJson["Config"].Add(BACKROTATE180,(bool)(pConfigItem->EnBackRotate180),false);
|
||||
outJson["Config"].Add(SCREWDETECT,(bool)(pConfigItem->EnScrewDetect),false);
|
||||
outJson["Config"].Add(SCREWLEVEL,(int)(pConfigItem->ScrewDetectLevel));
|
||||
if (isConfigItem)
|
||||
{
|
||||
outJson["Config"].Add(ITEMCAPTION,(string)(pConfigItem->Caption));
|
||||
outJson["Config"].Add(SAVEPATH,(string)(pConfigItem->SavePath));
|
||||
}
|
||||
std::ofstream os;
|
||||
os.open(fileNames.c_str());
|
||||
os<<outJson.ToFormattedString();
|
||||
os.close();
|
||||
}
|
||||
|
||||
void JsonConfig::WriteJsonData(const std::string fileName)
|
||||
{
|
||||
//Json::Reader reader;
|
||||
//Json::Value root;
|
||||
//std::ifstream is;
|
||||
//is.open(fileName.c_str(),std::ios::binary);
|
||||
//if (reader.parse(is,root))
|
||||
//{
|
||||
//
|
||||
//}
|
||||
}
|
||||
|
||||
//PCONFIGPARAMS JsonConfig::ReadJsonFromFile(const char* fileNames)
|
||||
//{
|
||||
//}
|
||||
|
||||
void JsonConfig::WriteJsonArrayToFile(std::vector<CONFIGPARAMS> cfgArray,const std::string filename)
|
||||
{
|
||||
//Json::StyledWriter sw;
|
||||
neb::CJsonObject root;
|
||||
root.AddEmptySubObject("Config");
|
||||
root["Config"].AddEmptySubArray(PIXTYPE);
|
||||
root["Config"].AddEmptySubArray(PAPARSIZE);
|
||||
root["Config"].AddEmptySubArray(AUTOCROP);
|
||||
root["Config"].AddEmptySubArray(RESOLUTION);
|
||||
root["Config"].AddEmptySubArray(DUPLEX);
|
||||
root["Config"].AddEmptySubArray(DISCARBLANK);
|
||||
root["Config"].AddEmptySubArray(DISCARBLANKVINCE);
|
||||
|
||||
root["Config"].AddEmptySubArray(BRIGHTNESS);
|
||||
root["Config"].AddEmptySubArray(AUTOCONTRAST);
|
||||
root["Config"].AddEmptySubArray(CONTRAST);
|
||||
root["Config"].AddEmptySubArray(GAMMA);
|
||||
|
||||
root["Config"].AddEmptySubArray(FILTERTYPE);
|
||||
root["Config"].AddEmptySubArray(AUTODESCREW);
|
||||
root["Config"].AddEmptySubArray(FILLBLACK);
|
||||
root["Config"].AddEmptySubArray(MULTIOUTPUT);
|
||||
root["Config"].AddEmptySubArray(OUTHOLE);
|
||||
root["Config"].AddEmptySubArray(OUTHOLERATIO);
|
||||
|
||||
root["Config"].AddEmptySubArray(ULTRADETECT);
|
||||
root["Config"].AddEmptySubArray(BINDINGDETECT);
|
||||
root["Config"].AddEmptySubArray(SCANCOUNT);
|
||||
root["Config"].AddEmptySubArray(DOCORIENTATION);
|
||||
root["Config"].AddEmptySubArray(BACKROTATE180);
|
||||
root["Config"].AddEmptySubArray(SCREWDETECT);
|
||||
root["Config"].AddEmptySubArray(SCREWLEVEL);
|
||||
|
||||
root["Config"].AddEmptySubArray(ITEMCAPTION);
|
||||
root["Config"].AddEmptySubArray(SAVEPATH);
|
||||
for (int i=0;i<cfgArray.size();i++)
|
||||
{
|
||||
root["Config"][PIXTYPE].Add(cfgArray[i].Pixtype);
|
||||
root["Config"][PAPARSIZE].Add(cfgArray[i].PaperSize);
|
||||
root["Config"][AUTOCROP].Add(i,cfgArray[i].EnAutoCrop);
|
||||
root["Config"][RESOLUTION].Add(cfgArray[i].Resolution);
|
||||
root["Config"][DUPLEX].Add(cfgArray[i].Duplex);
|
||||
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"][AUTOCONTRAST].Add(i,cfgArray[i].EnAutoContrast);
|
||||
root["Config"][CONTRAST].Add(cfgArray[i].Contrast);
|
||||
root["Config"][GAMMA].Add(cfgArray[i].Gamma);
|
||||
|
||||
root["Config"][FILTERTYPE].Add(cfgArray[i].Filter);
|
||||
root["Config"][AUTODESCREW].Add(i,cfgArray[i].EnAutoDescrew);
|
||||
root["Config"][FILLBLACK].Add(i,cfgArray[i].EnFillBlack);
|
||||
root["Config"][MULTIOUTPUT].Add(i,cfgArray[i].EnMultiOutPutR);
|
||||
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"][BINDINGDETECT].Add(i,cfgArray[i].EnBindingDetect);
|
||||
root["Config"][SCANCOUNT].Add(cfgArray[i].ScanCount);
|
||||
root["Config"][DOCORIENTATION].Add(cfgArray[i].Orentation);
|
||||
root["Config"][BACKROTATE180].Add(i,cfgArray[i].EnBackRotate180);
|
||||
root["Config"][SCREWDETECT].Add(i,cfgArray[i].EnScrewDetect);
|
||||
root["Config"][SCREWLEVEL].Add(cfgArray[i].ScrewDetectLevel);
|
||||
|
||||
if (cfgArray[i].Caption.c_str()!=NULL)
|
||||
{
|
||||
root["Config"][ITEMCAPTION].Add(cfgArray[i].Caption);
|
||||
}
|
||||
if (cfgArray[i].SavePath.c_str()!=NULL)
|
||||
{
|
||||
root["Config"][SAVEPATH].Add(cfgArray[i].SavePath);
|
||||
}
|
||||
}
|
||||
std::ofstream os;
|
||||
os.open(filename.c_str());
|
||||
os<<root.ToFormattedString();
|
||||
os.close();
|
||||
}
|
||||
|
||||
CONFIGPARAMS JsonConfig::ReadDefaultConfig()
|
||||
{
|
||||
TCHAR szIniFile[MAX_PATH] = { 0 };
|
||||
SHGetSpecialFolderPath(NULL, szIniFile, CSIDL_LOCAL_APPDATA, TRUE);
|
||||
_tcscat(szIniFile, HUAGAO_SCAN);
|
||||
_tcscat(szIniFile,TWAIN_INIPATH);
|
||||
_tcscat(szIniFile, TEXT("\\"));
|
||||
_tcscat(szIniFile, TWAIN_JSON_NAME);
|
||||
std::string s_default(szIniFile);
|
||||
vector<CONFIGPARAMS> vc;
|
||||
vc=ReadJsonArrayFromFile(s_default.c_str());
|
||||
if (vc.size()!=0)
|
||||
{
|
||||
return vc[0];
|
||||
}
|
||||
return GetDefaultConfigParams();
|
||||
}
|
||||
|
||||
bool JsonConfig::DeleteJsonFile(std::string path)
|
||||
{
|
||||
return (remove(path.c_str()));
|
||||
}
|
||||
|
||||
std::vector<CONFIGPARAMS> JsonConfig::ReadJsonArrayFromFile(const std::string filename)
|
||||
{
|
||||
std::vector<CONFIGPARAMS> re;
|
||||
FILE* file=fopen(filename.c_str(),"rb");
|
||||
if (!file)
|
||||
{
|
||||
return re;
|
||||
}
|
||||
fseek(file,0,SEEK_END);
|
||||
long size=ftell(file);
|
||||
fseek(file,0,SEEK_SET);
|
||||
std::string text;
|
||||
char* buffer=new char[size+1];
|
||||
buffer[size]=0;
|
||||
if (!fread(buffer,1,size,file)==(unsigned long)size)
|
||||
{
|
||||
return re;
|
||||
}
|
||||
text=buffer;
|
||||
fclose(file);
|
||||
delete []buffer;
|
||||
re=parseJsonFromString(text);
|
||||
return re;
|
||||
}
|
||||
|
||||
CONFIGPARAMS JsonConfig::GetDefaultConfigParams()
|
||||
{
|
||||
CONFIGPARAMS params;
|
||||
params.Pixtype=1;//灰度
|
||||
params.PaperSize=11;//A3
|
||||
params.EnAutoCrop=FALSE;//自动裁切
|
||||
params.Resolution=200;//200dpi
|
||||
params.Duplex=1;//双面
|
||||
params.EnDiscardBlank=FALSE;//自动丢弃空白页
|
||||
params.EnDiscardBlankVince=FALSE;
|
||||
|
||||
params.Brightness=0;//亮度
|
||||
params.EnAutoContrast=FALSE;//自动对比度
|
||||
params.Contrast=0;//对比度
|
||||
params.Gamma=10;//伽玛值
|
||||
|
||||
params.Filter=0;//除色 无
|
||||
params.EnFillBlack=FALSE;//不填黑框
|
||||
params.EnAutoDescrew=TRUE;//不自动纠偏
|
||||
params.EnMultiOutPutR=FALSE;//不多流输出除红
|
||||
params.EnOutHole=FALSE;//不去除孔洞
|
||||
params.OutHoleRatio=10;//默认值0.10
|
||||
|
||||
params.EnUltrasonicDetect=TRUE;//超声检测开关 开
|
||||
params.EnBindingDetect=FALSE;//装订检测开关 开
|
||||
params.ScanCount=-1;//扫描张数
|
||||
params.Orentation=0;//旋转方向0度
|
||||
params.EnBackRotate180=FALSE;//背面旋转180度 不旋转
|
||||
params.EnScrewDetect=TRUE;//歪斜检测 开
|
||||
params.ScrewDetectLevel=3;//歪斜检测等级 3级
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<CONFIGPARAMS> JsonConfig::parseJsonFromString(const std::string str)
|
||||
{
|
||||
|
||||
neb::CJsonObject root(str);
|
||||
vector<CONFIGPARAMS> vcConfig;
|
||||
|
||||
int size=0;
|
||||
neb::CJsonObject itmPaparSize;
|
||||
root["Config"].Get(PAPARSIZE,itmPaparSize);
|
||||
size=itmPaparSize.GetArraySize();
|
||||
if (size>0)
|
||||
{
|
||||
neb::CJsonObject itmPixType;
|
||||
root["Config"].Get(PIXTYPE,itmPixType);
|
||||
neb::CJsonObject itmAutoCrop;
|
||||
root["Config"].Get(AUTOCROP,itmAutoCrop);
|
||||
neb::CJsonObject itmRes;
|
||||
root["Config"].Get(RESOLUTION,itmRes);
|
||||
neb::CJsonObject itmDulpex;
|
||||
root["Config"].Get(DUPLEX,itmDulpex);
|
||||
neb::CJsonObject itmDiscardBlk;
|
||||
root["Config"].Get(DISCARBLANK,itmDiscardBlk);
|
||||
neb::CJsonObject itmDiscardBlkVince;
|
||||
root["Config"].Get(DISCARBLANKVINCE,itmDiscardBlkVince);
|
||||
|
||||
neb::CJsonObject itmBrtnes;
|
||||
root["Config"].Get(BRIGHTNESS,itmBrtnes);
|
||||
neb::CJsonObject itmAutoCrnt;
|
||||
root["Config"].Get(AUTOCONTRAST,itmAutoCrnt);
|
||||
neb::CJsonObject itmContrast;
|
||||
root["Config"].Get(CONTRAST,itmContrast);
|
||||
neb::CJsonObject itmGamma;
|
||||
root["Config"].Get(GAMMA,itmGamma);
|
||||
|
||||
neb::CJsonObject itmFilter;
|
||||
root["Config"].Get(FILTERTYPE,itmFilter);
|
||||
neb::CJsonObject itmAutoDescrew;
|
||||
root["Config"].Get(AUTODESCREW,itmAutoDescrew);
|
||||
neb::CJsonObject itmFillBlack;
|
||||
root["Config"].Get(FILLBLACK,itmFillBlack);
|
||||
neb::CJsonObject itmMultiOutput;
|
||||
root["Config"].Get(MULTIOUTPUT,itmMultiOutput);
|
||||
neb::CJsonObject itmOutHole;
|
||||
root["Config"].Get(OUTHOLE,itmOutHole);
|
||||
neb::CJsonObject itmOutHoleRatio;
|
||||
root["Config"].Get(OUTHOLERATIO,itmOutHoleRatio);
|
||||
|
||||
neb::CJsonObject itmUltDetect;
|
||||
root["Config"].Get(ULTRADETECT,itmUltDetect);
|
||||
neb::CJsonObject itmBingdingDetect;
|
||||
root["Config"].Get(BINDINGDETECT,itmBingdingDetect);
|
||||
neb::CJsonObject itmScanCount;
|
||||
root["Config"].Get(SCANCOUNT,itmScanCount);
|
||||
neb::CJsonObject itmDocOrientation;
|
||||
root["Config"].Get(DOCORIENTATION,itmDocOrientation);
|
||||
neb::CJsonObject itmBackRotate;
|
||||
root["Config"].Get(BACKROTATE180,itmBackRotate);
|
||||
neb::CJsonObject itmScrewDetct;
|
||||
root["Config"].Get(SCREWDETECT,itmScrewDetct);
|
||||
neb::CJsonObject itmScrewLevel;
|
||||
root["Config"].Get(SCREWLEVEL,itmScrewLevel);
|
||||
|
||||
neb::CJsonObject itmCaption;
|
||||
if (!root["Config"][ITEMCAPTION].IsEmpty())
|
||||
{
|
||||
root["Config"].Get(ITEMCAPTION,itmCaption);
|
||||
}
|
||||
neb::CJsonObject itmSavePtah;
|
||||
if (!root["Config"][SAVEPATH].IsEmpty())
|
||||
{
|
||||
root["Config"].Get(SAVEPATH,itmSavePtah);
|
||||
}
|
||||
for (int i=0;i<size;i++)
|
||||
{
|
||||
CONFIGPARAMS cfp;
|
||||
int i_value;
|
||||
bool b_value;
|
||||
std::string s_value;
|
||||
|
||||
itmPixType.Get(i,i_value);
|
||||
cfp.Pixtype=i_value;
|
||||
itmPaparSize.Get(i,i_value);
|
||||
cfp.PaperSize=i_value;
|
||||
itmAutoCrop.Get(i,b_value);
|
||||
cfp.EnAutoCrop=b_value;
|
||||
itmRes.Get(i,i_value);
|
||||
cfp.Resolution=i_value;
|
||||
itmDulpex.Get(i,i_value);
|
||||
cfp.Duplex=i_value;
|
||||
itmDiscardBlk.Get(i,b_value);
|
||||
cfp.EnDiscardBlank=b_value;
|
||||
itmDiscardBlkVince.Get(i,b_value);
|
||||
cfp.EnDiscardBlankVince=b_value;
|
||||
|
||||
itmBrtnes.Get(i,i_value);
|
||||
cfp.Brightness=i_value;
|
||||
itmAutoCrnt.Get(i,b_value);
|
||||
cfp.EnAutoContrast=b_value;
|
||||
itmContrast.Get(i,i_value);
|
||||
cfp.Contrast=i_value;
|
||||
itmGamma.Get(i,i_value);
|
||||
cfp.Gamma=i_value;
|
||||
|
||||
itmFilter.Get(i,i_value);
|
||||
cfp.Filter=i_value;
|
||||
itmAutoDescrew.Get(i,b_value);
|
||||
cfp.EnAutoDescrew=b_value;
|
||||
itmFillBlack.Get(i,b_value);
|
||||
cfp.EnFillBlack=b_value;
|
||||
itmMultiOutput.Get(i,b_value);
|
||||
cfp.EnMultiOutPutR=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);
|
||||
cfp.EnUltrasonicDetect=b_value;
|
||||
itmBingdingDetect.Get(i,b_value);
|
||||
cfp.EnBindingDetect=b_value;
|
||||
itmScanCount.Get(i,i_value);
|
||||
cfp.ScanCount=i_value;
|
||||
itmDocOrientation.Get(i,i_value);
|
||||
cfp.Orentation=i_value;
|
||||
itmBackRotate.Get(i,b_value);
|
||||
cfp.EnBackRotate180=b_value;
|
||||
itmScrewDetct.Get(i,b_value);
|
||||
cfp.EnScrewDetect=b_value;
|
||||
itmScrewLevel.Get(i,i_value);
|
||||
cfp.ScrewDetectLevel=i_value;
|
||||
|
||||
if (!root["Config"][ITEMCAPTION].IsEmpty())
|
||||
{
|
||||
itmCaption.Get(i,s_value);
|
||||
cfp.Caption=s_value;
|
||||
}
|
||||
if (!root["Config"][SAVEPATH].IsEmpty())
|
||||
{
|
||||
itmSavePtah.Get(i,s_value);
|
||||
cfp.SavePath=s_value;
|
||||
}
|
||||
vcConfig.push_back(cfp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CONFIGPARAMS cfp;
|
||||
int index;
|
||||
bool bvalue;
|
||||
std::string svalue;
|
||||
|
||||
root["Config"].Get(PIXTYPE,index);
|
||||
cfp.Pixtype=index;
|
||||
root["Config"].Get(PAPARSIZE,index);
|
||||
cfp.PaperSize=index;
|
||||
root["Config"].Get(AUTOCROP,bvalue);
|
||||
cfp.EnAutoCrop=bvalue;
|
||||
root["Config"].Get(RESOLUTION,index);
|
||||
cfp.Resolution=index;
|
||||
root["Config"].Get(DUPLEX,index);
|
||||
cfp.Duplex=index;
|
||||
root["Config"].Get(DISCARBLANK,bvalue);
|
||||
cfp.EnDiscardBlank=bvalue;
|
||||
root["Config"].Get(DISCARBLANKVINCE,bvalue);
|
||||
cfp.EnDiscardBlankVince=bvalue;
|
||||
|
||||
root["Config"].Get(BRIGHTNESS,index);
|
||||
cfp.Brightness=index;
|
||||
root["Config"].Get(AUTOCONTRAST,bvalue);
|
||||
cfp.EnAutoContrast=bvalue;
|
||||
root["Config"].Get(CONTRAST,index);
|
||||
cfp.Contrast=index;
|
||||
root["Config"].Get(GAMMA,index);
|
||||
cfp.Gamma=index;
|
||||
|
||||
root["Config"].Get(FILTERTYPE,index);
|
||||
cfp.Filter=index;
|
||||
root["Config"].Get(AUTODESCREW,bvalue);
|
||||
cfp.EnAutoCrop=bvalue;
|
||||
root["Config"].Get(FILLBLACK,bvalue);
|
||||
cfp.EnFillBlack=bvalue;
|
||||
root["Config"].Get(MULTIOUTPUT,bvalue);
|
||||
cfp.EnMultiOutPutR=bvalue;
|
||||
root["Config"].Get(OUTHOLE,bvalue);
|
||||
cfp.EnOutHole=bvalue;
|
||||
root["Config"].Get(OUTHOLERATIO,index);
|
||||
cfp.OutHoleRatio=index;
|
||||
|
||||
root["Config"].Get(ULTRADETECT,bvalue);
|
||||
cfp.EnUltrasonicDetect=bvalue;
|
||||
root["Config"].Get(BINDINGDETECT,bvalue);
|
||||
cfp.EnBindingDetect=bvalue;
|
||||
root["Config"].Get(SCANCOUNT,index);
|
||||
cfp.ScanCount=index;
|
||||
root["Config"].Get(DOCORIENTATION,index);
|
||||
cfp.Orentation=index;
|
||||
root["Config"].Get(BACKROTATE180,bvalue);
|
||||
cfp.EnBackRotate180=bvalue;
|
||||
root["Config"].Get(SCREWDETECT,bvalue);
|
||||
cfp.EnScrewDetect=bvalue;
|
||||
root["Config"].Get(SCREWLEVEL,index);
|
||||
cfp.ScrewDetectLevel=index;
|
||||
|
||||
if (!root["Config"][ITEMCAPTION].IsEmpty())
|
||||
{
|
||||
root["Config"].Get(ITEMCAPTION,svalue);
|
||||
cfp.Caption=svalue;
|
||||
}
|
||||
if (!root["Config"][SAVEPATH].IsEmpty())
|
||||
{
|
||||
root["Config"].Get(SAVEPATH,svalue);
|
||||
cfp.SavePath=svalue;
|
||||
}
|
||||
vcConfig.push_back(cfp);
|
||||
}
|
||||
return vcConfig;
|
||||
}
|
24
JsonConfig.h
24
JsonConfig.h
|
@ -1,24 +0,0 @@
|
|||
#pragma once
|
||||
#include "PublicFunc.h"
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class JsonConfig
|
||||
{
|
||||
public:
|
||||
JsonConfig(void);
|
||||
~JsonConfig(void);
|
||||
public:
|
||||
void WriteToJson(PCONFIGPARAMS pConfigItem,const std::string fileName,bool isConfigItem=true);
|
||||
//PCONFIGPARAMS ReadJsonFromFile(const char* fileNames);
|
||||
void WriteJsonData(const std::string fileName);
|
||||
void WriteJsonArrayToFile(std::vector<CONFIGPARAMS> cfgArray,const std::string filename);
|
||||
CONFIGPARAMS ReadDefaultConfig();
|
||||
bool DeleteJsonFile(std::string path);
|
||||
std::vector<CONFIGPARAMS> ReadJsonArrayFromFile(const std::string filename);
|
||||
CONFIGPARAMS GetDefaultConfigParams();
|
||||
private:
|
||||
std::vector<CONFIGPARAMS> parseJsonFromString(const std::string str) ;
|
||||
};
|
||||
|
126
MFC_UI.cpp
126
MFC_UI.cpp
|
@ -1,126 +0,0 @@
|
|||
#include "stdafx.h"
|
||||
#include "MFC_UI.h"
|
||||
#include "TwainUIDlg.h"
|
||||
#include "IndicatorDlg.h"
|
||||
#include "hugaotwainds.h"
|
||||
#include "Resource.h"
|
||||
|
||||
extern ChugaotwaindsApp theApp;
|
||||
|
||||
void DeleteWnd(CDialog* pWnd)
|
||||
{
|
||||
if (pWnd && pWnd->GetSafeHwnd())
|
||||
{
|
||||
pWnd->DestroyWindow();
|
||||
delete pWnd;
|
||||
}
|
||||
}
|
||||
|
||||
MFC_UI::MFC_UI(CTWAINDS_FreeImage *pDS)
|
||||
: CTWAIN_UI(pDS)
|
||||
, m_pChildWnd(0, DeleteWnd)
|
||||
, m_pDlg(0, DeleteWnd)
|
||||
, m_pIndicator(0, DeleteWnd)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
MFC_UI::~MFC_UI()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
if (nRes)
|
||||
{
|
||||
return nRes;
|
||||
}
|
||||
if (bSetup)
|
||||
{
|
||||
Data.ShowUI = 1;
|
||||
}
|
||||
|
||||
if (Data.ShowUI == 0 && !bIndicators)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (Data.hParent)
|
||||
{
|
||||
m_pChildWnd = std::unique_ptr<CDialog, void(*)(CDialog*)>(new CDialog(), DeleteWnd);
|
||||
m_pChildWnd->Create(IDD_DIALOGBACK, CWnd::FromHandle((HWND)Data.hParent));
|
||||
long ll = GetWindowLong(m_pChildWnd->GetSafeHwnd(), GWL_STYLE);
|
||||
SetWindowLong(m_pChildWnd->GetSafeHwnd(), GWL_STYLE, WS_CHILD | ll);
|
||||
SetParent(m_pChildWnd->GetSafeHwnd(), (HWND)Data.hParent);
|
||||
}
|
||||
|
||||
if (Data.ShowUI)
|
||||
{
|
||||
m_pDlg.reset(new TwainUIDlg(this, m_pChildWnd.get()));
|
||||
m_pDlg->Create(IDD_DIALOG_TWAINUI, m_pChildWnd.get());
|
||||
m_pDlg->SetDlgItemText(IDC_CONFIRM,bSetup ? _T("È·¶¨") : _T("ɨÃè"));
|
||||
|
||||
if (m_pDlg) {
|
||||
m_pDlg->ShowWindow(SW_SHOWNORMAL);
|
||||
}
|
||||
else {
|
||||
ret = TWRC_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void MFC_UI::DestroyTWAINGUI()
|
||||
{
|
||||
m_pIndicator.reset();
|
||||
m_pDlg.reset();
|
||||
m_pChildWnd.reset();
|
||||
|
||||
CTWAIN_UI::DestroyTWAINGUI();
|
||||
}
|
||||
|
||||
|
||||
void MFC_UI::UpdateProgress(bool bShow, unsigned char ucProgress, unsigned int unPageNo, string strProgressTitle)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int MFC_UI::MyMessageBox(string strMessage, string strTitle, unsigned int unIconID)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
bool MFC_UI::processEvent(pTW_EVENT _pEvent)
|
||||
{
|
||||
if (m_pDlg)
|
||||
{
|
||||
if (IsDialogMessage(m_pDlg->m_hWnd, (LPMSG)(((pTW_EVENT)_pEvent)->pEvent)))
|
||||
{
|
||||
m_pDlg->SendMessage(_pEvent->TWMessage);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void MFC_UI::ShowIndicators()
|
||||
{
|
||||
if (m_bIndicators) {
|
||||
m_pIndicator.reset(new IndicatorDlg(this));
|
||||
m_pIndicator->Create(IDD_DIALOG_INDICATOR,m_pDlg ? m_pDlg.get() : m_pChildWnd.get());
|
||||
m_pIndicator->ShowWindow(SW_SHOWNORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
void MFC_UI::DestroyIndicators()
|
||||
{
|
||||
m_pIndicator.reset();
|
||||
}
|
42
MFC_UI.h
42
MFC_UI.h
|
@ -1,42 +0,0 @@
|
|||
#pragma once
|
||||
#include "CTWAINDS_FreeImage.h"
|
||||
#include "TWAIN_UI.h"
|
||||
#include <memory>
|
||||
class TwainUIDlg;
|
||||
class CWnd;
|
||||
class IndicatorDlg;
|
||||
class ChugaotwaindsApp;
|
||||
|
||||
class MFC_UI :
|
||||
public CTWAIN_UI
|
||||
{
|
||||
public:
|
||||
MFC_UI(CTWAINDS_FreeImage *pDS);
|
||||
~MFC_UI();
|
||||
|
||||
/**
|
||||
* Will show the TWAIN GUI
|
||||
* @param[in] _pData contains info about if the UI should be shown etc.
|
||||
* @return a valid TWRC_xxxx return code.
|
||||
*/
|
||||
TW_INT16 DisplayTWAINGUI(TW_USERINTERFACE Data, bool bSetup, bool bIndicators);
|
||||
|
||||
/**
|
||||
* Close the user interface for TWAIN
|
||||
*/
|
||||
void DestroyTWAINGUI();
|
||||
void UpdateProgress(bool bShow, unsigned char ucProgress, unsigned int unPageNo, string strProgressTitle);
|
||||
unsigned int MyMessageBox(string strMessage, string strTitle, unsigned int unIconID);
|
||||
bool processEvent(pTW_EVENT _pEvent);
|
||||
|
||||
private:
|
||||
std::unique_ptr<CDialog, void(*)(CDialog*)> m_pChildWnd;
|
||||
std::unique_ptr<CDialog, void(*)(CDialog*)> m_pDlg;
|
||||
std::unique_ptr<CDialog, void(*)(CDialog*)> m_pIndicator;
|
||||
ChugaotwaindsApp* m_app;
|
||||
|
||||
// ͨ¹ý CTWAIN_UI ¼Ì³Ð
|
||||
virtual void ShowIndicators() override;
|
||||
virtual void DestroyIndicators() override;
|
||||
};
|
||||
|
52
MutexEx.h
52
MutexEx.h
|
@ -1,52 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
//对临界区同样进行封装
|
||||
class CMyCriticalSection
|
||||
{
|
||||
public:
|
||||
CMyCriticalSection()
|
||||
{
|
||||
InitializeCriticalSection(&m_cSection);
|
||||
}
|
||||
|
||||
void Lock()
|
||||
{
|
||||
EnterCriticalSection(&m_cSection);
|
||||
}
|
||||
|
||||
void UnLock()
|
||||
{
|
||||
LeaveCriticalSection(&m_cSection);
|
||||
}
|
||||
|
||||
|
||||
//利用析构函数删除临界区对象
|
||||
virtual ~CMyCriticalSection()
|
||||
{
|
||||
DeleteCriticalSection(&m_cSection);
|
||||
}
|
||||
private:
|
||||
CRITICAL_SECTION m_cSection;
|
||||
};
|
||||
|
||||
class CCriticalSectionAutoLock
|
||||
{
|
||||
public:
|
||||
//利用构造函数上锁,即进去临界区
|
||||
CCriticalSectionAutoLock(CMyCriticalSection *mySection)
|
||||
:pCMySection(mySection)
|
||||
{
|
||||
pCMySection->Lock();
|
||||
}
|
||||
|
||||
//利用析构函数解锁,即离开临界区
|
||||
virtual ~CCriticalSectionAutoLock()
|
||||
{
|
||||
pCMySection->UnLock();
|
||||
}
|
||||
private:
|
||||
CMyCriticalSection *pCMySection;
|
||||
};
|
||||
|
||||
|
227
PaperSize.cpp
227
PaperSize.cpp
|
@ -1,227 +0,0 @@
|
|||
#include "stdafx.h"
|
||||
#include "PaperSize.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
PaperSize::PaperSize()
|
||||
{
|
||||
InitPaperMap();
|
||||
}
|
||||
|
||||
|
||||
PaperSize::~PaperSize()
|
||||
{
|
||||
}
|
||||
|
||||
void PaperSize::InitPaperMap()
|
||||
{
|
||||
//×ÔÊÊÓ¦
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)90, 50.0), CSize(594, 898)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)90, 75), CSize(892, 1347)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)90, 100), CSize(1189, 1795)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)90, 150), CSize(1784, 2693)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)90, 200), CSize(2338, 3307)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)90, 240), CSize(2854, 4308)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)90, 300), CSize(3567, 5385)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)90, 400), CSize(4756, 7180)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)90, 600), CSize(7134, 10770)));
|
||||
|
||||
//A3
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A3, 50), CSize(585, 827)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A3, 75), CSize(877, 1240)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A3, 100), CSize(1169, 1653)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A3, 150), CSize(1753, 2480)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A3, 200), CSize(2338, 3307)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A3, 240), CSize(2806, 3968)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A3, 300), CSize(3507, 4960)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A3, 400), CSize(4677, 6614)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A3, 600), CSize(7015, 9921)));
|
||||
|
||||
//A4
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4, 50), CSize(413, 585)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4, 75), CSize(620, 877)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4, 100), CSize(826, 1169)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4, 150), CSize(1240, 1753)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4, 200), CSize(1653, 2338)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4, 240), CSize(1984, 2806)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4, 300), CSize(2480, 3507)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4, 400), CSize(3307, 4677)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4, 600), CSize(4960, 7015)));
|
||||
|
||||
//A4R
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4R, 50), CSize(585, 413)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4R, 75), CSize(877, 620)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4R, 100), CSize(1169, 826)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4R, 150), CSize(1753, 1240)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4R, 200), CSize(2338, 1653)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4R, 240), CSize(2806, 1984)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4R, 300), CSize(3507, 2480)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4R, 400), CSize(4677, 3307)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A4R, 600), CSize(7015, 4960)));
|
||||
|
||||
//A5
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5, 50), CSize(291, 413)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5, 75), CSize(437, 620)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5, 100), CSize(582, 826)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5, 150), CSize(874, 1240)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5, 200), CSize(1165, 1653)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5, 240), CSize(1398, 1984)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5, 300), CSize(1748, 2480)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5, 400), CSize(2330, 3307)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5, 600), CSize(3496, 4960)));
|
||||
|
||||
//A5R
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5R, 50), CSize(413, 291)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5R, 75), CSize(620, 437)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5R, 100), CSize(826, 582)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5R, 150), CSize(1240, 874)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5R, 200), CSize(1653, 1165)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5R, 240), CSize(1984, 1398)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5R, 300), CSize(2480, 1748)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5R, 400), CSize(3307, 2330)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A5R, 600), CSize(4960, 3496)));
|
||||
|
||||
//A6
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6, 50), CSize(207, 291)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6, 75), CSize(310, 437)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6, 100), CSize(413, 582)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6, 150), CSize(620, 874)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6, 200), CSize(826, 1165)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6, 240), CSize(992, 1398)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6, 300), CSize(1240, 1748)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6, 400), CSize(1653, 2330)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6, 600), CSize(2480, 3496)));
|
||||
|
||||
//A6R
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6R, 50), CSize(291, 207)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6R, 75), CSize(437, 310)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6R, 100), CSize(582, 413)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6R, 150), CSize(874, 620)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6R, 200), CSize(1165, 826)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6R, 240), CSize(1398, 992)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6R, 300), CSize(1748, 1240)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6R, 400), CSize(2330, 1653)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(A6R, 600), CSize(3496, 2480)));
|
||||
|
||||
//³¤Îĸ壬2±¶A3
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)91, 50), CSize(585, 1653)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)91, 75), CSize(877, 2480)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)91, 100), CSize(1169, 1653 * 2)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)91, 150), CSize(1753, 2480 * 2)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)91, 200), CSize(2338, 3307 * 2)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)91, 240), CSize(2806, 3968 * 2)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)91, 300), CSize(3507, 4960 * 2)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)91, 400), CSize(4677, 6614 * 2)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>((TwSS)91, 600), CSize(7015, 9921 * 2)));
|
||||
|
||||
//B4
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B4, 50), CSize(506, 717)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B4, 75), CSize(759, 1075)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B4, 100), CSize(1011, 1433)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B4, 150), CSize(1517, 2149)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B4, 200), CSize(2023, 2866)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B4, 240), CSize(2428, 3439)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B4, 300), CSize(3035, 4299)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B4, 400), CSize(4047, 5732)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B4, 600), CSize(6070, 8598)));
|
||||
|
||||
//B5
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5, 50), CSize(358, 506)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5, 75), CSize(537, 759)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5, 100), CSize(716, 1011)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5, 150), CSize(1074, 1517)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5, 200), CSize(1433, 2023)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5, 240), CSize(1719, 2428)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5, 300), CSize(2149, 3035)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5, 400), CSize(2866, 4047)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5, 600), CSize(4299, 6070)));
|
||||
|
||||
//B5R
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5R, 50), CSize(506, 358)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5R, 75), CSize(759, 537)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5R, 100), CSize(1011, 716)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5R, 150), CSize(1517, 1075)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5R, 200), CSize(2023, 1433)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5R, 240), CSize(2428, 1719)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5R, 300), CSize(3035, 2149)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5R, 400), CSize(4047, 2866)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B5R, 600), CSize(6070, 4299)));
|
||||
|
||||
//B6
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6, 50), CSize(252, 358)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6, 75), CSize(378, 537)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6, 100), CSize(503, 716)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6, 150), CSize(755, 1074)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6, 200), CSize(1007, 1433)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6, 240), CSize(1209, 1719)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6, 300), CSize(1511, 2149)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6, 400), CSize(2015, 2866)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6, 600), CSize(3023, 4299)));
|
||||
|
||||
//B6R
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6R, 50), CSize(358, 252)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6R, 75), CSize(537, 378)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6R, 100), CSize(716, 503)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6R, 150), CSize(1074, 755)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6R, 200), CSize(1433, 1007)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6R, 240), CSize(1719, 1209)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6R, 300), CSize(2149, 1511)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6R, 400), CSize(2866, 2015)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(B6R, 600), CSize(4299, 3023)));
|
||||
|
||||
//DOUBLE LETTER
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(DOUBLELetter, 50), CSize(550, 850)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(DOUBLELetter, 75), CSize(825, 1275)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(DOUBLELetter, 100), CSize(1100, 1700)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(DOUBLELetter, 150), CSize(1650, 2550)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(DOUBLELetter, 200), CSize(2200, 3400)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(DOUBLELetter, 240), CSize(2640, 4080)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(DOUBLELetter, 300), CSize(3300, 5100)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(DOUBLELetter, 400), CSize(4400, 6800)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(DOUBLELetter, 600), CSize(6600, 10200)));
|
||||
|
||||
//LETTER
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetter, 50), CSize(425, 550)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetter, 75), CSize(638, 825)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetter, 100), CSize(850, 1100)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetter, 150), CSize(1275, 1650)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetter, 200), CSize(1700, 2200)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetter, 240), CSize(2040, 2640)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetter, 300), CSize(2550, 3300)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetter, 400), CSize(3400, 4400)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetter, 600), CSize(5100, 6600)));
|
||||
|
||||
//LETTERR
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetterR, 50), CSize(550, 425)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetterR, 75), CSize(825, 638)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetterR, 100), CSize(1100, 850)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetterR, 150), CSize(1650, 1275)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetterR, 200), CSize(2200, 1700)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetterR, 240), CSize(2640, 2040)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetterR, 300), CSize(3300, 2550)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetterR, 400), CSize(4400, 3400)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLetterR, 600), CSize(6600, 5100)));
|
||||
|
||||
//LETTERR
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLegal, 50), CSize(425, 700)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLegal, 75), CSize(638, 1050)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLegal, 100), CSize(850, 1400)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLegal, 150), CSize(1275, 2100)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLegal, 200), CSize(1700, 2800)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLegal, 240), CSize(2040, 3360)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLegal, 300), CSize(2550, 4200)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLegal, 400), CSize(3400, 5600)));
|
||||
dpiDct.insert(pair<pair<TwSS, float>, CSize>(pair<TwSS, float>(USLegal, 600), CSize(5100, 8400)));
|
||||
}
|
||||
|
||||
CSize PaperSize::GetPaperSize(DWORD paperType, float dpi)
|
||||
{
|
||||
CSize retSize;
|
||||
map<pair<TwSS, float>, CSize>::iterator iter;
|
||||
iter = dpiDct.find(pair<TwSS, float>((TwSS)paperType, dpi));
|
||||
if (iter != dpiDct.end()) {
|
||||
retSize = (*iter).second;
|
||||
return retSize;
|
||||
}
|
||||
return CSize(2338, 3307);
|
||||
}
|
85
PaperSize.h
85
PaperSize.h
|
@ -1,85 +0,0 @@
|
|||
#pragma once
|
||||
#include <map>
|
||||
|
||||
class PaperSize
|
||||
{
|
||||
public:
|
||||
PaperSize();
|
||||
~PaperSize();
|
||||
enum TwSS : unsigned short
|
||||
{
|
||||
None = 0,
|
||||
A4Letter = 1,
|
||||
A4 = 1,
|
||||
B5Letter = 2,
|
||||
JISB5 = 2,
|
||||
B5 = 2,
|
||||
USLetter = 3,
|
||||
USLegal = 4,
|
||||
A5 = 5,
|
||||
B4 = 6,
|
||||
ISOB4 = 6,
|
||||
B6 = 7,
|
||||
ISOB6 = 7,
|
||||
USLedger = 9,
|
||||
USExecutive = 10,
|
||||
A3 = 11,
|
||||
B3 = 12,
|
||||
ISOB3 = 12,
|
||||
A6 = 13,
|
||||
C4 = 14,
|
||||
C5 = 15,
|
||||
C6 = 16,
|
||||
_4A0 = 17,
|
||||
_2A0 = 18,
|
||||
A0 = 19,
|
||||
A1 = 20,
|
||||
A2 = 21,
|
||||
A7 = 22,
|
||||
A8 = 23,
|
||||
A9 = 24,
|
||||
A10 = 25,
|
||||
ISOB0 = 26,
|
||||
ISOB1 = 27,
|
||||
ISOB2 = 28,
|
||||
ISOB5 = 29,
|
||||
ISOB7 = 30,
|
||||
ISOB8 = 31,
|
||||
ISOB9 = 32,
|
||||
ISOB10 = 33,
|
||||
JISB0 = 34,
|
||||
JISB1 = 35,
|
||||
JISB2 = 36,
|
||||
JISB3 = 37,
|
||||
JISB4 = 38,
|
||||
JISB6 = 39,
|
||||
JISB7 = 40,
|
||||
JISB8 = 41,
|
||||
JISB9 = 42,
|
||||
JISB10 = 43,
|
||||
C0 = 44,
|
||||
C1 = 45,
|
||||
C2 = 46,
|
||||
C3 = 47,
|
||||
C7 = 48,
|
||||
C8 = 49,
|
||||
C9 = 50,
|
||||
C10 = 51,
|
||||
USStatement = 52,
|
||||
BusinessCard = 53,
|
||||
A4R = 60,
|
||||
A5R = 61,
|
||||
A6R = 62,
|
||||
B5R = 70,
|
||||
B6R = 71,
|
||||
USLetterR = 80,
|
||||
DOUBLELetter = 81,
|
||||
AUTO = 90
|
||||
};
|
||||
private:
|
||||
void InitPaperMap();
|
||||
std::map<std::pair<TwSS, float>, CSize> dpiDct;
|
||||
public:
|
||||
CSize GetPaperSize(DWORD paperType, float dpi);
|
||||
};
|
||||
|
617
PublicFunc.cpp
617
PublicFunc.cpp
|
@ -1,617 +0,0 @@
|
|||
#include "stdafx.h"
|
||||
#include "PublicFunc.h"
|
||||
//#include "UI_INI.h"
|
||||
//#include "DirectshowCaptureVideo.h"
|
||||
//#include "DirectshowCaptureVideoUvc.h"
|
||||
//#include "WatermarkDataType.h"
|
||||
//#include "SupperDevType.h"
|
||||
#include "CTwainMutex.h"
|
||||
#include <io.h>
|
||||
|
||||
|
||||
|
||||
BOOL g_b_show_ui_flg = FALSE;
|
||||
|
||||
//WATER_PRO g_st_water_pro = {0};
|
||||
BOOL g_add_water_flg = FALSE;
|
||||
DWORD g_dw_white_bright_count = 40000;
|
||||
|
||||
//CDirectshowCaptureVideoUvc g_dc_uvc_video;
|
||||
BOOL g_b_use_uvc_dev = FALSE;
|
||||
TWAIN_IMAGE_DATA_INFO g_st_twain_bmp_info = {0};
|
||||
BOOL g_b_brigth_show_flg = TRUE;
|
||||
HWND g_hwnd_dlg = NULL;
|
||||
|
||||
//CDirectshowCaptureVideo g_dc_video;
|
||||
|
||||
TCHAR* GetUserCustomFilePath(HWND hWin, TCHAR* lpFilePath, TCHAR *lp_head_text )
|
||||
{
|
||||
if ( lpFilePath == NULL )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BROWSEINFO bi = {0};
|
||||
TCHAR szBuffer[MAX_PATH] = {0};
|
||||
|
||||
memset(&bi, 0, sizeof(BROWSEINFO));
|
||||
|
||||
|
||||
bi.hwndOwner = hWin;
|
||||
bi.pszDisplayName = GetExistFileDir(lpFilePath);
|
||||
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_SHAREABLE | BIF_USENEWUI | BIF_RETURNFSANCESTORS ;
|
||||
|
||||
LPITEMIDLIST pIDList = NULL;
|
||||
LPMALLOC lpMalloc = NULL;
|
||||
//m_pUI_INI->GetMessageBoxStr(szBuffer, sizeof(szBuffer), 1041);
|
||||
//bi.lpszTitle = szBuffer;//1041=请选择文件存储路径
|
||||
bi.lpszTitle = lp_head_text;//TEXT("请选择新建文件夹");
|
||||
bi.lpfn = (BFFCALLBACK)BrowserCallbackProc; //回调函数
|
||||
bi.lParam = (LPARAM)lpFilePath; //回调函数的使用的参数,用来设定默认路径
|
||||
|
||||
pIDList = SHBrowseForFolder(&bi);
|
||||
if ( pIDList != NULL )
|
||||
{
|
||||
SHGetPathFromIDList(pIDList, lpFilePath);
|
||||
}
|
||||
if ( SHGetMalloc( &lpMalloc ) )
|
||||
{
|
||||
return NULL; //释放内存
|
||||
}
|
||||
if ( pIDList == NULL )
|
||||
{
|
||||
return NULL; //释放内存
|
||||
}
|
||||
lpMalloc->Free(pIDList);
|
||||
lpMalloc->Release();
|
||||
pIDList = NULL;
|
||||
lpMalloc = NULL;
|
||||
//_tcscpy(lpFilePath, szBuffer2);
|
||||
return lpFilePath;
|
||||
}
|
||||
|
||||
TCHAR* GetCurExeFilePath(HINSTANCE hInstance, TCHAR* lpPath, DWORD dwSize)
|
||||
{
|
||||
INT nRet = 0x0L;
|
||||
TCHAR *p = NULL;
|
||||
if ( lpPath == NULL || dwSize == 0 )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
nRet = GetModuleFileName(hInstance, lpPath, dwSize);
|
||||
if (nRet > 0)
|
||||
{
|
||||
p = _tcsrchr(lpPath, TEXT('\\'));
|
||||
if ( p != NULL )
|
||||
{
|
||||
*(p+1) = TEXT('\0');
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return lpPath;
|
||||
}
|
||||
|
||||
TCHAR* GetExistFileDir(TCHAR* p_file_path)
|
||||
{
|
||||
WIN32_FIND_DATA wfd = {0};
|
||||
LPSTR p_test = NULL;
|
||||
HANDLE hFindFile = INVALID_HANDLE_VALUE;
|
||||
|
||||
if ( p_file_path == NULL )
|
||||
return NULL;
|
||||
|
||||
hFindFile = FindFirstFile(p_file_path, &wfd);
|
||||
if (hFindFile != NULL)
|
||||
{
|
||||
FindClose(hFindFile);
|
||||
hFindFile= INVALID_HANDLE_VALUE;
|
||||
}
|
||||
if ( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
|
||||
{
|
||||
return p_file_path;
|
||||
}
|
||||
|
||||
p_test = _tcsrchr(p_file_path, '\\');
|
||||
if ( p_test != NULL )
|
||||
{
|
||||
*p_test = 0;
|
||||
return GetExistFileDir(p_file_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
DWORD CALLBACK BrowserCallbackProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch(uMsg)
|
||||
{
|
||||
case BFFM_INITIALIZED: //LPARAM(TEXT("D:\\test_adf_project"))
|
||||
SendMessage(hWnd, BFFM_SETSELECTION, TRUE, lParam); //lpData就是上一个函数的 info.lParam ,也就是默认路径
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL CheckAndCreateFileDir(TCHAR* p_file_path, BOOL flg)
|
||||
{
|
||||
TCHAR szTmp[MAX_PATH] = {0};
|
||||
WIN32_FIND_DATA wfd = {0};
|
||||
INT len = 0;
|
||||
INT pos = 0;
|
||||
BOOL bFlg = FALSE;
|
||||
HANDLE hFindFile = INVALID_HANDLE_VALUE;
|
||||
|
||||
if ( p_file_path == NULL )
|
||||
return FALSE;
|
||||
|
||||
if ( *p_file_path >= 'a' && *p_file_path <= 'z' || *p_file_path >= 'A' && *p_file_path <= 'Z')
|
||||
{
|
||||
if ( *(p_file_path+1) != ':' && *(p_file_path+2) != '\\')
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
if ( _access(p_file_path, 0) == 0)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if ( !flg )
|
||||
return FALSE;
|
||||
|
||||
if ( CreateDirectory(p_file_path, NULL) )
|
||||
return TRUE;
|
||||
|
||||
_tcscpy(szTmp, p_file_path);
|
||||
|
||||
len = (INT)_tcslen(szTmp);
|
||||
|
||||
bFlg = FALSE;
|
||||
while(len)
|
||||
{
|
||||
if ( *(szTmp+len-1) == '\\' )
|
||||
{
|
||||
bFlg = TRUE;
|
||||
break;
|
||||
}
|
||||
len--;
|
||||
}
|
||||
if ( bFlg )
|
||||
{
|
||||
*(szTmp+len-1) = 0;
|
||||
CheckAndCreateFileDir(szTmp, flg);
|
||||
return CreateDirectory(p_file_path, NULL);
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CheckDiskFreeBitM(HWND hWin, TCHAR *p_disk_name, DWORD dw_min_bit_m)
|
||||
{
|
||||
TCHAR *p = NULL;
|
||||
TCHAR sz_root_path_name[MAX_PATH + 1] = {0};
|
||||
INT len = 0;
|
||||
|
||||
DWORD dwTotalDiskSpace = 0;
|
||||
DWORD dwFreeDiskSpace = 0;
|
||||
DWORD dwUsedDiskSpace = 0;
|
||||
|
||||
ULARGE_INTEGER uiFreeBytesAvailableToCaller;
|
||||
ULARGE_INTEGER uiTotalNumberOfBytes;
|
||||
ULARGE_INTEGER uiTotalNumberOfFreeBytes;
|
||||
|
||||
UINT un_ret = 0;
|
||||
if ( p_disk_name == NULL )
|
||||
return FALSE;
|
||||
|
||||
len = _tcslen(p_disk_name);
|
||||
if ( len > MAX_PATH )
|
||||
{
|
||||
len = MAX_PATH;
|
||||
}
|
||||
|
||||
memcpy(sz_root_path_name, p_disk_name, (size_t)len);
|
||||
|
||||
p = _tcsstr(sz_root_path_name, "\\");
|
||||
if ( p == NULL )
|
||||
{
|
||||
if ( len == 2 )
|
||||
{
|
||||
if ( !((sz_root_path_name[0] >= 'A' && sz_root_path_name[0] <= 'Z' || sz_root_path_name[0] >= 'a' && sz_root_path_name[0] <= 'z') && sz_root_path_name[1]== ':') )
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
if ( p != NULL )
|
||||
*(p+1) = 0;
|
||||
un_ret = GetDriveType(sz_root_path_name);
|
||||
if ( un_ret == 0 || un_ret == 1)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(GetDiskFreeSpaceEx(sz_root_path_name, &uiFreeBytesAvailableToCaller, &uiTotalNumberOfBytes, &uiTotalNumberOfFreeBytes))
|
||||
{
|
||||
//dwTotalDiskSpace = (DWORD)(uiTotalNumberOfBytes.QuadPart / 1024 / 1024);
|
||||
dwFreeDiskSpace = (DWORD)(uiFreeBytesAvailableToCaller.QuadPart >> 20);
|
||||
//dwUsedDiskSpace = dwTotalDiskSpace - dwFreeDiskSpace;
|
||||
if ( dwFreeDiskSpace < dw_min_bit_m )
|
||||
{
|
||||
//ShowErrorStr(hWin, 1101);//1101=磁盘空间不足
|
||||
MyMessageBox( TEXT("磁盘分区可用空间不足"), 0, MB_ICONWARNING);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MyMessageBox( TEXT("磁盘分区可用空间不足"), 0, MB_ICONWARNING);
|
||||
//GetErrorMessage(NULL, 0, FALSE);
|
||||
return FALSE;
|
||||
}
|
||||
//ShowErrorStr(hWin, 1101);//1101=磁盘空间不足
|
||||
//return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
HBITMAP SetButtonStaticBkBmp(HINSTANCE hInst, HWND hWin, UINT id, UINT iamge_id)
|
||||
{
|
||||
|
||||
UINT ctr_msg = 0;
|
||||
UINT str_iamge_type = 0;
|
||||
HBITMAP hBitmap = NULL;
|
||||
HBITMAP hOldBitmap = NULL;
|
||||
//BS_ICON BS_BITMAP
|
||||
//SS_BITMAP|SS_CENTERIMAGE SS_ICON
|
||||
|
||||
LONG ctr_s = 0;
|
||||
ctr_s = GetWindowLong(GetDlgItem(hWin, id), GWL_STYLE);
|
||||
|
||||
ctr_msg = STM_SETIMAGE;
|
||||
ctr_s |= SS_BITMAP | SS_CENTERIMAGE | SS_RIGHT;
|
||||
|
||||
hBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(iamge_id));
|
||||
|
||||
if ( hBitmap == NULL )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SetWindowLong(GetDlgItem(hWin, id), GWL_STYLE, ctr_s);
|
||||
hOldBitmap = (HBITMAP)SendDlgItemMessage(hWin, id, ctr_msg, IMAGE_BITMAP, (LPARAM)hBitmap);
|
||||
if ( hOldBitmap != NULL )
|
||||
{
|
||||
DeleteObject(hOldBitmap);
|
||||
hOldBitmap = NULL;
|
||||
}
|
||||
DeleteObject(hBitmap);
|
||||
hBitmap = NULL;
|
||||
return hBitmap;
|
||||
}
|
||||
|
||||
|
||||
VOID FreeTwainFileListMem()
|
||||
{
|
||||
if ( g_st_twain_bmp_info.p_wifl != NULL )
|
||||
{
|
||||
free(g_st_twain_bmp_info.p_wifl);
|
||||
g_st_twain_bmp_info.p_wifl = NULL;
|
||||
}
|
||||
|
||||
//if ( g_st_twain_bmp_info.st_bmp_info.p_image_data != NULL )
|
||||
//{
|
||||
// free(g_st_twain_bmp_info.st_bmp_info.p_image_data);
|
||||
// g_st_twain_bmp_info.st_bmp_info.p_image_data = NULL;
|
||||
//}
|
||||
//memset(&g_st_twain_bmp_info, 0, sizeof(TWAIN_IMAGE_DATA_INFO));
|
||||
}
|
||||
|
||||
BOOL MallocTwainFileListMem()
|
||||
{
|
||||
if ( g_st_twain_bmp_info.p_wifl == NULL )
|
||||
{
|
||||
memset(&g_st_twain_bmp_info, 0, sizeof(TWAIN_IMAGE_DATA_INFO));
|
||||
}
|
||||
else if ( g_st_twain_bmp_info.n_wifl_count != 0 && g_st_twain_bmp_info.p_wifl == NULL )
|
||||
{
|
||||
memset(&g_st_twain_bmp_info, 0, sizeof(TWAIN_IMAGE_DATA_INFO));
|
||||
}
|
||||
|
||||
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_LOCAL_APPDATA, TRUE) )
|
||||
{
|
||||
INT len = _tcslen(g_st_twain_bmp_info.sz_path_dir);
|
||||
if ( len > 0 )
|
||||
{
|
||||
//if ( g_st_twain_bmp_info.sz_path_dir[len -1] != '\\' )
|
||||
// _tcscat(g_st_twain_bmp_info.sz_path_dir, TEXT("\\"));
|
||||
//_tcscat(g_st_twain_bmp_info.sz_path_dir, TWAIN_DATA_PATH);
|
||||
//CheckAndCreateFileDir(g_st_twain_bmp_info.sz_path_dir, TRUE);
|
||||
}
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
if ( g_st_twain_bmp_info.p_wifl == NULL )
|
||||
{
|
||||
g_st_twain_bmp_info.p_wifl = (PTWAIN_IMAGE_FILE_LIST)malloc(sizeof(TWAIN_IMAGE_FILE_LIST)* (g_st_twain_bmp_info.n_wifl_count + 20));
|
||||
if ( g_st_twain_bmp_info.p_wifl != NULL )
|
||||
{
|
||||
memset(g_st_twain_bmp_info.p_wifl, 0, sizeof(TWAIN_IMAGE_FILE_LIST)* (g_st_twain_bmp_info.n_wifl_count + 20));
|
||||
g_st_twain_bmp_info.n_wifl_count += 20;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
PTWAIN_IMAGE_FILE_LIST p_wifl = (PTWAIN_IMAGE_FILE_LIST)malloc(sizeof(TWAIN_IMAGE_FILE_LIST)* (g_st_twain_bmp_info.n_wifl_count + 20));
|
||||
if ( g_st_twain_bmp_info.p_wifl != NULL )
|
||||
{
|
||||
memset(p_wifl, 0, sizeof(TWAIN_IMAGE_FILE_LIST)* (g_st_twain_bmp_info.n_wifl_count + 20));
|
||||
memcpy(p_wifl, g_st_twain_bmp_info.p_wifl, sizeof(TWAIN_IMAGE_FILE_LIST)* g_st_twain_bmp_info.n_wifl_cur_count );
|
||||
g_st_twain_bmp_info.n_wifl_count += 20;
|
||||
free(g_st_twain_bmp_info.p_wifl);
|
||||
g_st_twain_bmp_info.p_wifl = p_wifl;
|
||||
p_wifl = NULL;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WriteTwianImageData(TCHAR *p_file_path, PBYTE p_data, DWORD dw_size)
|
||||
{
|
||||
DWORD dw_write_size = 0;
|
||||
|
||||
if ( p_file_path == NULL || p_data == NULL )
|
||||
return FALSE;
|
||||
if ( _msize(p_data) < dw_size )
|
||||
return FALSE;
|
||||
|
||||
DeleteFile(p_file_path);
|
||||
HANDLE h_file = CreateFile(p_file_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, NULL, NULL);
|
||||
if ( h_file == INVALID_HANDLE_VALUE )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
BOOL b_flg = WriteFile(h_file, p_data, dw_size, &dw_write_size,0);
|
||||
if ( !b_flg || dw_size != dw_write_size )
|
||||
{
|
||||
b_flg = FALSE;
|
||||
}
|
||||
CloseHandle(h_file);
|
||||
h_file = INVALID_HANDLE_VALUE;
|
||||
if ( !b_flg )
|
||||
{
|
||||
DeleteFile(p_file_path);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
DWORD ReadTwianImageData(TCHAR *p_file_path)
|
||||
{
|
||||
if ( p_file_path == NULL )
|
||||
return 0;
|
||||
|
||||
DWORD dw_size = 0;
|
||||
|
||||
HANDLE h_file = CreateFile(p_file_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
|
||||
if ( h_file == INVALID_HANDLE_VALUE )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
dw_size = GetFileSize(h_file, 0);
|
||||
if ( dw_size == 0 )
|
||||
{
|
||||
CloseHandle(h_file);
|
||||
return 0;
|
||||
}
|
||||
//if ( g_st_twain_bmp_info.st_bmp_info.p_image_data != NULL )
|
||||
//{
|
||||
// free(g_st_twain_bmp_info.st_bmp_info.p_image_data);
|
||||
// g_st_twain_bmp_info.st_bmp_info.p_image_data = NULL;
|
||||
//}
|
||||
//DWORD dw_read_size = 0;
|
||||
//g_st_twain_bmp_info.st_bmp_info.p_image_data = (PBYTE)malloc(dw_size);
|
||||
//if ( g_st_twain_bmp_info.st_bmp_info.p_image_data == NULL )
|
||||
//{
|
||||
// CloseHandle(h_file);
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
//BOOL b_flg = ReadFile(h_file, ////g_st_twain_bmp_info.st_bmp_info.p_image_data, dw_size, /&dw_read_size,/ 0);
|
||||
////CloseHandle(h_file);
|
||||
//h_file = INVALID_HANDLE_VALUE;
|
||||
//if ( !b_flg || dw_size != dw_read_size)
|
||||
//{
|
||||
// //free(g_st_twain_bmp_info.st_bmp_info.p_image_data);
|
||||
// dw_size = 0;
|
||||
//}
|
||||
//else
|
||||
// DeleteFile(p_file_path);
|
||||
|
||||
return dw_size;
|
||||
}
|
||||
|
||||
|
||||
std::string UtfToString(std::string strValue)
|
||||
{
|
||||
int nwLen = ::MultiByteToWideChar(CP_ACP, 0, strValue.c_str(), -1, NULL, 0);
|
||||
wchar_t * pwBuf = new wchar_t[nwLen + 1];//加上末尾'\0'
|
||||
ZeroMemory(pwBuf, nwLen * 2 + 2);
|
||||
::MultiByteToWideChar(CP_ACP, 0, strValue.c_str(), strValue.length(), pwBuf, nwLen);
|
||||
int nLen = ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, NULL, NULL, NULL, NULL);
|
||||
char * pBuf = new char[nLen + 1];
|
||||
ZeroMemory(pBuf, nLen + 1);
|
||||
::WideCharToMultiByte(CP_UTF8, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL);
|
||||
std::string retStr(pBuf);
|
||||
delete []pwBuf;
|
||||
delete []pBuf;
|
||||
pwBuf = NULL;
|
||||
pBuf = NULL;
|
||||
return retStr;
|
||||
}
|
||||
|
||||
|
||||
std::string StringToUtf(std::string strValue)
|
||||
{
|
||||
int nwLen = MultiByteToWideChar(CP_UTF8, 0, strValue.c_str(), -1, NULL, 0);
|
||||
wchar_t * pwBuf = new wchar_t[nwLen + 1];//加上末尾'\0'
|
||||
memset(pwBuf, 0, nwLen * 2 + 2);
|
||||
MultiByteToWideChar(CP_UTF8, 0, strValue.c_str(), strValue.length(), pwBuf, nwLen);
|
||||
int nLen = WideCharToMultiByte(CP_ACP, 0, pwBuf, -1, NULL, NULL, NULL, NULL);
|
||||
char * pBuf = new char[nLen + 1];
|
||||
memset(pBuf, 0, nLen + 1);
|
||||
WideCharToMultiByte(CP_ACP, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL);
|
||||
std::string retStr = pBuf;
|
||||
delete []pBuf;
|
||||
delete []pwBuf;
|
||||
return retStr;
|
||||
}
|
||||
|
||||
DWORD MyMessageBox(TCHAR *p_str, TCHAR *p_str2, DWORD dw_id)
|
||||
{
|
||||
if ( p_str2 == NULL )
|
||||
{
|
||||
return MessageBox(g_hwnd_dlg, p_str, TEXT("test")/*g_p_cur_supper_sdti->sz_type_str*/, dw_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
return MessageBox(g_hwnd_dlg, p_str, p_str2, dw_id);
|
||||
}
|
||||
}
|
||||
|
||||
CTwainMutex g_sys_mutex;
|
||||
BOOL g_not_user_sineng_dev = true;
|
||||
BOOL g_InitSysMutexRun()
|
||||
{
|
||||
//return g_sys_mutex.InitRunMutexId(COMPANY_NAME PRODUCT_NAME);
|
||||
return true;
|
||||
//return g_sys_mutex.CreatTwainMutex(SCANNERNAME);
|
||||
}
|
||||
|
||||
BOOL g_InitSysMutexScanRun(DWORD dwPid, DWORD dwUid)
|
||||
{
|
||||
//return g_sys_mutex.InitScanRunMutexId(COMPANY_NAME PRODUCT_NAME, dwPid, dwUid);
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL g_CloseSysMutexRun()
|
||||
{
|
||||
//return g_sys_mutex.CloseAllScnDocA3Mutex();
|
||||
return g_sys_mutex.CloseTwainMutex();
|
||||
}
|
||||
|
||||
BOOL g_CloseOneSysMutexRun()
|
||||
{
|
||||
//return g_sys_mutex.CloseScnDocA3Mutex((SCN_MUTEX_TYPE)smt);
|
||||
return true;
|
||||
//return g_sys_mutex.CloseTwainMutex();
|
||||
}
|
||||
|
||||
BOOL g_CheckSysMutex()
|
||||
{
|
||||
//return g_sys_mutex.CheckScnDocA3Mutex((SCN_MUTEX_TYPE)smt);
|
||||
return true;
|
||||
return g_sys_mutex.CheckExistTwainMutex(SCANNERNAME);
|
||||
}
|
||||
|
||||
BOOL g_CreateSysMutex()
|
||||
{
|
||||
//return g_sys_mutex.CreateScnDocA3Mutex((SCN_MUTEX_TYPE)smt);
|
||||
//return true;
|
||||
return g_sys_mutex.CreatTwainMutex(SCANNERNAME);
|
||||
}
|
||||
|
||||
RGBQUAD g_default_map[256] = {0};
|
||||
|
||||
BOOL ReadDefaultMap()
|
||||
{
|
||||
int i = 0;
|
||||
for ( i = 0; i < 256; i++ )
|
||||
{
|
||||
g_default_map[i].rgbBlue = g_default_map[i].rgbGreen = g_default_map[i].rgbRed = i;
|
||||
}
|
||||
|
||||
TCHAR sz_path[MAX_PATH] = {0};
|
||||
bool nRet = GetModuleFileName(AfxGetApp()->m_hInstance, sz_path, sizeof(sz_path));
|
||||
if (nRet > 0)
|
||||
{
|
||||
TCHAR *p = _tcsrchr(sz_path, TEXT('\\'));
|
||||
if ( p != NULL )
|
||||
{
|
||||
*(p+1) = TEXT('\0');
|
||||
}
|
||||
else
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
_tcscat(sz_path, TEXT("default.map"));
|
||||
HANDLE hfile = CreateFile(sz_path, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, NULL, NULL);
|
||||
if ( hfile != INVALID_HANDLE_VALUE )
|
||||
{
|
||||
DWORD dw_write = 0;
|
||||
ReadFile(hfile, g_default_map, sizeof(g_default_map), &dw_write, NULL);
|
||||
if ( dw_write != sizeof(g_default_map) )
|
||||
{
|
||||
nRet = false;
|
||||
}
|
||||
CloseHandle(hfile);
|
||||
}
|
||||
return nRet;
|
||||
}
|
||||
|
||||
float GetContrast(int level)
|
||||
{
|
||||
float ret=0.0;
|
||||
switch (level)
|
||||
{
|
||||
case -3:
|
||||
ret=-1000.0;
|
||||
break;
|
||||
case -2:
|
||||
ret=-666.0;
|
||||
break;
|
||||
case -1:
|
||||
ret=-333.0;
|
||||
break;
|
||||
case 1:
|
||||
ret=333.0;
|
||||
break;
|
||||
case 2:
|
||||
ret=666.0;
|
||||
break;
|
||||
case 3:
|
||||
ret=1000.0;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
VOID XdPrint(_TCHAR* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
_TCHAR buf[256];
|
||||
_vstprintf(buf, format, args);
|
||||
OutputDebugString(buf);
|
||||
va_end(args);
|
||||
}
|
366
PublicFunc.h
366
PublicFunc.h
|
@ -1,366 +0,0 @@
|
|||
#ifndef PUBLICFUNC_H_
|
||||
#define PUBLICFUNC_H_
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <string>
|
||||
|
||||
//#include "UI_INI.h"
|
||||
//#include "DirectshowCaptureVideo.h"
|
||||
//#include "DirectshowCaptureVideoUvc.h"
|
||||
using namespace std;
|
||||
|
||||
/************************************
|
||||
**扫描参数,json格式保存参数名称**
|
||||
*************************************/
|
||||
#define PIXTYPE "iPixType"
|
||||
#define PAPARSIZE "iPaparSize"
|
||||
#define AUTOCROP "bAuotCrop"
|
||||
#define RESOLUTION "iResolution"
|
||||
#define DUPLEX "iDuplex"
|
||||
#define DISCARBLANK "bDiscardBlank"
|
||||
#define DISCARBLANKVINCE "bDiscardBlankVince"
|
||||
#define FLOD "bFlod"
|
||||
#define BRIGHTNESS "iBrightness"
|
||||
#define AUTOCONTRAST "bAutoContrast"
|
||||
#define CONTRAST "iContrast"
|
||||
#define GAMMA "dGamma"
|
||||
#define FILTERTYPE "iFilter"
|
||||
#define FILLBLACK "bFillBlcak"
|
||||
#define AUTODESCREW "bAutoDescrew"
|
||||
#define ULTRADETECT "bUltrasonicDetect"
|
||||
#define BINDINGDETECT "bBindingDetect"
|
||||
#define SCANCOUNT "ScanCount"
|
||||
#define DOCORIENTATION "bOrientation"
|
||||
#define BACKROTATE180 "iBackRotate180"
|
||||
#define SCREWDETECT "bScrewDetect"
|
||||
#define SCREWLEVEL "iScrewLevel"
|
||||
#define ITEMCAPTION "Caption"
|
||||
#define SAVEPATH "SavePath"
|
||||
#define MULTIOUTPUT "iMultiOutPut"
|
||||
#define OUTHOLE "bOutHole"
|
||||
#define OUTHOLERATIO "iOutHoleRatio"
|
||||
|
||||
/******************
|
||||
**参数保存结构体**
|
||||
*******************/
|
||||
struct tagCONFIGPARAMS
|
||||
{
|
||||
/*基本选项卡参数*/
|
||||
INT Pixtype;
|
||||
INT PaperSize;
|
||||
BOOL EnAutoCrop;
|
||||
INT Resolution;
|
||||
INT Duplex;
|
||||
BOOL EnDiscardBlank;
|
||||
BOOL EnDiscardBlankVince;
|
||||
BOOL EnFlod;
|
||||
/*亮度对比度选项卡参数*/
|
||||
INT Brightness;
|
||||
BOOL EnAutoContrast;
|
||||
INT Contrast;
|
||||
INT Gamma;
|
||||
|
||||
/*图像处理选项卡参数*/
|
||||
INT Filter;
|
||||
BOOL EnFillBlack;
|
||||
BOOL EnAutoDescrew;
|
||||
//BOOL EnMulti
|
||||
BOOL EnOutHole;
|
||||
INT OutHoleRatio;
|
||||
BOOL EnMultiOutPutR;
|
||||
|
||||
/*送纸部分选项卡参数*/
|
||||
BOOL EnUltrasonicDetect;
|
||||
BOOL EnBindingDetect;
|
||||
INT ScanCount;
|
||||
INT Orentation;
|
||||
BOOL EnBackRotate180;
|
||||
BOOL EnScrewDetect;
|
||||
INT ScrewDetectLevel;
|
||||
|
||||
/*保存信息*/
|
||||
std::string Caption;
|
||||
std::string SavePath;
|
||||
};
|
||||
|
||||
typedef tagCONFIGPARAMS CONFIGPARAMS,*PCONFIGPARAMS;
|
||||
|
||||
struct tagCONFIGINFO
|
||||
{
|
||||
std::string Caption;
|
||||
std::string SavePath;
|
||||
};
|
||||
|
||||
typedef struct tagCONFIGINFO CONFIGINFO,*PCONFIGINFO;
|
||||
|
||||
struct tagOutHole
|
||||
{
|
||||
BOOL EnOutHole;
|
||||
INT OutHoleRatio;
|
||||
};
|
||||
|
||||
typedef tagOutHole OutHole,*pOutHole;
|
||||
|
||||
struct tagHARDWAREPARAMS
|
||||
{
|
||||
DWORD PaperType;
|
||||
DWORD PixType;
|
||||
FLOAT Resolution;
|
||||
BOOL DoubleFeederOn;
|
||||
BOOL StapleDetectOn;
|
||||
BOOL SkrewDetectOn;
|
||||
DWORD SkrewDetectLevel;
|
||||
};
|
||||
|
||||
typedef tagHARDWAREPARAMS HARDWAREPARAMS, *PHARDWAREPARAMS;
|
||||
|
||||
struct SFreeImage
|
||||
{
|
||||
WORD m_nPaperSource; /**< the current paper source ADF or Flatbed*/
|
||||
bool m_bDuplex; /**< True to use duplex false for simplex, ignored if flatbed*/
|
||||
WORD m_nPixelType; /**< type of pixels to transfer image as */
|
||||
int m_nRight; /**< frame right edge */
|
||||
int m_nBottom; /**< frame bottom edge */
|
||||
int m_nLeft; /**< frame left edge */
|
||||
int m_nTop; /**< frame top edge */
|
||||
float m_fXResolution; /**< horizontal resolution */
|
||||
float m_fYResolution; /**< vertical resolution */
|
||||
float m_fGamma; /**< Gamma */
|
||||
float m_fContrast; /**< Contrast */
|
||||
float m_fBrightness; /**< Brightness */
|
||||
float m_fThreshold; /**< Threshold */
|
||||
//int m_nPaparType /**< 纸张类型*/
|
||||
//后加
|
||||
BOOL m_bAutoContrast; /**< 自动对比度*/
|
||||
bool m_bAutoCrop; /**< 自动裁切*/
|
||||
bool m_bAutoDiscardBlank; /**< 自动丢弃空白页通用*/
|
||||
bool m_bAutoDiscardBlankInvoice;/**自动丢弃空白页发票*/
|
||||
bool m_bAutoDeskew; /**< 自动纠偏*/
|
||||
bool m_bMultiOutput; /*多流输出*/
|
||||
WORD m_nFilter; /**< 除色*/
|
||||
bool m_bFillBlackRect; /**< 填黑框*/
|
||||
UINT16 m_wScanCount; /**< 扫描张数*/
|
||||
WORD m_wRotation; /**< 旋转方向*/
|
||||
bool m_bBackRotate180; /**< 背面旋转180*/
|
||||
HARDWAREPARAMS m_HardWareParams; /**< 硬件扫描参数*/
|
||||
OutHole m_OutHole;
|
||||
};
|
||||
|
||||
typedef struct tag_USBCB {
|
||||
UINT32 u32_CMD;
|
||||
UINT32 u32_Data;
|
||||
UINT32 u32_Count;
|
||||
}USBCB, *PUSBCB;
|
||||
|
||||
//u32_CMD
|
||||
enum tagUsbKeyWords :UINT32
|
||||
{
|
||||
//无命令
|
||||
NO_COMMAND = 0,
|
||||
//获取dsp 状态
|
||||
GET_DSP_STATUS = 1,
|
||||
//取图
|
||||
GET_IMAGE = 2,
|
||||
//销毁DSP中驻存的图
|
||||
POP_IMAGE = 3,
|
||||
//开始扫描命令
|
||||
START_COMMAND = 4,
|
||||
//停止扫描命令
|
||||
STOP = 5,
|
||||
//获取扫描仪扫描模式
|
||||
GET_SCAN_MODE = 6,
|
||||
//获取固件版本号
|
||||
GET_FW_VERSION = 7,
|
||||
//返回PC端的状态
|
||||
SEND_STATUS_PC = 8,
|
||||
//下发扫描配置参数
|
||||
CONFIGURED_DATA = 9,
|
||||
//下发固件信息
|
||||
SEND_FW = 10,
|
||||
//获取扫描参数
|
||||
GET_CONFIG_DATA = 11,
|
||||
//获取扫描总张数
|
||||
GET_SCANN_NUM = 12,
|
||||
//获取有无纸的状态
|
||||
GET_PAPERFEEDER_STATUS = 13,
|
||||
//DSP初始化
|
||||
INIT_HARDWARE_SYS = 14,
|
||||
//获取有无纸的状态
|
||||
GET_PAPER_STATUS = 0x0d,
|
||||
//下发元器件配置参数(灰度,LED R曝光时间)
|
||||
SEND_COMPONENTS_GR = 15,
|
||||
//下发元器件配置参数(LED G/B曝光时间)
|
||||
SEND_COMPONENTS_GB = 16,
|
||||
//下发扫描模式
|
||||
SEND_SCAN_MODE = 17,
|
||||
//开始进行平场矫正
|
||||
START_FLAT = 18,
|
||||
//停止平场矫正
|
||||
STOP_FLAT = 19,
|
||||
//下发200dpi彩色平场矫正参数
|
||||
SEND_200_COLOR_FLAT_DATA = 20,
|
||||
//下发300dpi彩色平场矫正参数
|
||||
SEND_300_COLOR_FLAT_DATA = 21,
|
||||
//获取200dpi彩色平场矫正参数
|
||||
GET_200_COLOR_FLAT_DATA = 22,
|
||||
//获取300dpi彩色平场矫正参数
|
||||
GET_300_COLOR_FLAT_DATA = 23,
|
||||
//下发200dpi灰度平场校正参数
|
||||
SEND_200_GRAY_FLAT_DATA = 24,
|
||||
//下发300dpi灰度平场校正参数
|
||||
SEND_300_GRAY_FLAT_DATA = 25,
|
||||
//获取200DPI灰度平场校正参数
|
||||
GET_200_GRAY_FLAT_DATA = 26,
|
||||
//获取300DPI灰度平场校正参数
|
||||
GET_300_GRAY_FLAT_DATA = 27,
|
||||
//下发序列号命令
|
||||
SEND_SERIAL = 28,
|
||||
//获取序列号命令
|
||||
GET_SERIAL = 29
|
||||
};
|
||||
|
||||
typedef enum tagUsbKeyWords UsbKeyWords, *PUsbKeyWords;
|
||||
//u32_Data
|
||||
enum tagUsbSupported
|
||||
{
|
||||
//停止扫描
|
||||
SCAN_STOP = -2,
|
||||
//异常
|
||||
HAVE_ERROR = -1,
|
||||
//正常状态
|
||||
NORMAL = 0,
|
||||
//开盖
|
||||
OPEN_COVER = 1,
|
||||
// 无纸
|
||||
NO_FEED = 2,
|
||||
// 搓纸失败
|
||||
FEED_IN_ERROR = 4,
|
||||
// 卡纸
|
||||
PAPER_JAM = 8,
|
||||
// 检测到双张
|
||||
DETECT_DOUBLE_FEED = 16,
|
||||
// 检测到订书钉
|
||||
DETECT_STAPLE = 32,
|
||||
// 纸张倾斜
|
||||
PAPER_SKEW = 64,
|
||||
// 自动模式
|
||||
AUTO_SCAN_MODE = 65,
|
||||
// 手动模式
|
||||
MANAUL_SCAN_MODE = 66,
|
||||
// 计数模式
|
||||
COUNT_MODE = 67,
|
||||
// 硬件错误
|
||||
HARDWARE_ERROR = 68,
|
||||
// FPGA崩溃
|
||||
FPGA_ERROR = 68,
|
||||
// 开始
|
||||
START_SCAN = 69,
|
||||
//停止
|
||||
STOP_SCAN = 70,
|
||||
//有图
|
||||
HAVE_IMAGE = 71,
|
||||
// 更新扫描参数
|
||||
UPDATE_SCAN_PARAMETER = 72,
|
||||
// PC繁忙或出错
|
||||
PC_SCAN_BUSY_or_ERROR = 73
|
||||
};
|
||||
|
||||
typedef enum tagUsbSupported UsbSupported, *PUsbSupported;
|
||||
|
||||
|
||||
#define CAPTION_LEN 256
|
||||
#define TWAIN_IMAGE_FILE_LIST_NAME TEXT(".dat")
|
||||
|
||||
#ifndef malloc_my
|
||||
#define malloc_my malloc
|
||||
#endif
|
||||
|
||||
typedef struct tagTWAIN_IMAGE_FILE_LIST
|
||||
{
|
||||
INT n_item;//
|
||||
TCHAR sz_path[MAX_PATH];
|
||||
DWORD dw_color_bit;
|
||||
DWORD dw_width;
|
||||
DWORD dw_height;
|
||||
DWORD dw_dpi;
|
||||
DWORD dw_image_size;
|
||||
BOOL b_del_flg;//文件时是否删除, 传送一个删除一个
|
||||
}TWAIN_IMAGE_FILE_LIST,FAR*PTWAIN_IMAGE_FILE_LIST;
|
||||
|
||||
|
||||
typedef struct tagTWAIN_IMAGE_DATA_INFO
|
||||
{
|
||||
BOOL b_lock_flg;//是否在使用中
|
||||
//BOOL b_flg;
|
||||
TCHAR sz_path_dir[MAX_PATH];//文件目录
|
||||
//IMAGE_BMP_INFO st_bmp_info;//图像信息
|
||||
PTWAIN_IMAGE_FILE_LIST p_wifl;
|
||||
INT n_wifl_count;//内存大小
|
||||
INT n_wifl_cur_count;//当前使用内存个数
|
||||
INT n_wifl_cur_pos;//当前传送内存位置
|
||||
|
||||
}TWAIN_IMAGE_DATA_INFO, FAR*PTWAIN_IMAGE_DATA_INFO;
|
||||
|
||||
DWORD ReadTwianImageData(TCHAR *p_file_path);
|
||||
BOOL WriteTwianImageData(TCHAR *p_file_path, PBYTE p_data, DWORD dw_size);
|
||||
BOOL MallocTwainFileListMem();
|
||||
VOID FreeTwainFileListMem();
|
||||
|
||||
//取得用户自定义目录,参数 窗口句柄,当前目录, 显示在浏览对话框上的字符串
|
||||
TCHAR* GetUserCustomFilePath(HWND hWin, LPSTR lpFilePath, TCHAR *lp_head_text = NULL);
|
||||
//取得当前模块的文件路径, 参数,模块实列举并, 文件路径, 字符串的长度
|
||||
TCHAR* GetCurExeFilePath(HINSTANCE hInstance, TCHAR* lpPath, DWORD dwSize);
|
||||
//取得路径中已经存在的路径,并返回
|
||||
TCHAR* GetExistFileDir(TCHAR* p_file_path);
|
||||
//回调函数,取得用户自定义的文件路径
|
||||
DWORD CALLBACK BrowserCallbackProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ;
|
||||
|
||||
std::string UtfToString(std::string strValue);
|
||||
|
||||
std::string StringToUtf(std::string strValue);
|
||||
//检查,创建文件夹, 参数 文件路径, = 真,创建p_file_path不寻在文件路径
|
||||
BOOL CheckAndCreateFileDir(TCHAR* p_file_path, BOOL flg);
|
||||
|
||||
BOOL CheckDiskFreeBitM(HWND hWin, TCHAR *p_disk_name, DWORD dw_min_bit_m);
|
||||
HBITMAP SetButtonStaticBkBmp(HINSTANCE hInst, HWND hWin, UINT id, UINT iamge_id);
|
||||
DWORD MyMessageBox(TCHAR *p_str, TCHAR *p_str2, DWORD dw_id);
|
||||
|
||||
|
||||
extern TWAIN_IMAGE_DATA_INFO g_st_twain_bmp_info;
|
||||
|
||||
//extern CDirectshowCaptureVideo g_dc_video;
|
||||
extern BOOL g_b_show_ui_flg;
|
||||
|
||||
//extern WATER_PRO g_st_water_pro;
|
||||
extern BOOL g_add_water_flg;
|
||||
extern DWORD g_dw_white_bright_count;
|
||||
|
||||
//extern CDirectshowCaptureVideoUvc g_dc_uvc_video;
|
||||
extern BOOL g_b_use_uvc_dev ;
|
||||
extern BOOL g_b_brigth_show_flg;
|
||||
|
||||
extern HWND g_hwnd_dlg;
|
||||
|
||||
//extern CSysMutex g_sys_mutex;
|
||||
|
||||
typedef enum tagSYS_MUTEX_TYPE
|
||||
{
|
||||
SYSMUTEX_APP_RUN_TYPE,// ok
|
||||
SYSMUTEX_TWAIN_RUN_TYPE,
|
||||
SYSMUTEX_APP_SCANNER_RUN_TYPE,
|
||||
SYSMUTEX_TWAIN_SCANNER_RUN_TYPE
|
||||
}SYS_MUTEX_TYPE, FAR* PSYS_MUTEX_TYPE;
|
||||
|
||||
BOOL g_InitSysMutexRun();
|
||||
BOOL g_InitSysMutexScanRun(DWORD dwPid, DWORD dwUid);
|
||||
BOOL g_CloseSysMutexRun();
|
||||
BOOL g_CloseOneSysMutexRun();
|
||||
BOOL g_CreateSysMutex();
|
||||
BOOL g_CheckSysMutex();
|
||||
float GetContrast(int level);
|
||||
VOID XdPrint(_TCHAR* format, ...);
|
||||
extern BOOL g_not_user_sineng_dev;
|
||||
extern RGBQUAD g_default_map[256];
|
||||
|
||||
BOOL ReadDefaultMap();
|
||||
#endif
|
|
@ -1,91 +0,0 @@
|
|||
// SaveConfigDlg.cpp : 实现文件
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "hugaotwainds.h"
|
||||
#include "SaveConfigDlg.h"
|
||||
#include "afxdialogex.h"
|
||||
//#include "UI_INI.h"
|
||||
#include "TwainUIDlg.h"
|
||||
//#include "JsonConfig.h"
|
||||
#include <io.h>
|
||||
|
||||
|
||||
// SaveConfigDlg 对话框
|
||||
|
||||
IMPLEMENT_DYNAMIC(SaveConfigDlg, CDialog)
|
||||
|
||||
//extern CUI_INI* m_pUI_INI;
|
||||
SaveConfigDlg::SaveConfigDlg(CWnd* pParent /*=NULL*/)
|
||||
: CDialog(IDD_DIALOGSAVECONFIG, pParent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SaveConfigDlg::~SaveConfigDlg()
|
||||
{
|
||||
}
|
||||
|
||||
void SaveConfigDlg::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(SaveConfigDlg, CDialog)
|
||||
ON_BN_CLICKED(IDOK, &SaveConfigDlg::OnBnClickedOk)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
// SaveConfigDlg 消息处理程序
|
||||
|
||||
|
||||
void SaveConfigDlg::OnBnClickedOk()
|
||||
{
|
||||
TwainUIDlg* m_Parent=(TwainUIDlg*)GetParent();
|
||||
CONFIGPARAMS citem={0};
|
||||
m_Parent->UpDateScanParam(&citem,false);
|
||||
CString m_sName;
|
||||
GetDlgItemTextA(IDC_EDITSAVENAME,m_sName);
|
||||
TCHAR szIniFile[MAX_PATH] = { 0 };
|
||||
INT length=m_sName.GetLength();
|
||||
//INT length=10;
|
||||
if (length>0&&length<50)
|
||||
{
|
||||
char invalid_FileChars[8]={'/','\\',':','*',' ?','<', '>','|'};
|
||||
for(short j=0;j<8;j++)
|
||||
{
|
||||
m_sName.Remove(invalid_FileChars[j]);
|
||||
}
|
||||
if (m_sName.IsEmpty())
|
||||
{
|
||||
MessageBox(_TEXT("请避免输入非法字符('/','\\',':','*',' ?','<', '>','|')!"),_TEXT("提示"),MB_OK|MB_ICONWARNING
|
||||
);
|
||||
return;
|
||||
}
|
||||
SHGetSpecialFolderPath(NULL, szIniFile, CSIDL_LOCAL_APPDATA, TRUE);
|
||||
_tcscat(szIniFile,HUAGAO_SCAN);
|
||||
_tcscat(szIniFile, TWAIN_DATA_PATH);
|
||||
citem.Caption=m_sName;
|
||||
_tcscat(szIniFile,(_TEXT("/")+m_sName+_TEXT(".json")));
|
||||
std::string s_savePath(szIniFile);
|
||||
citem.SavePath=s_savePath;
|
||||
//((CListBox*)(m_Parent->GetDlgItem(IDC_LSTCONFIG)))->AddString(m_sName);
|
||||
m_sName.ReleaseBuffer();
|
||||
JsonConfig cfg;
|
||||
cfg.WriteToJson(&citem,s_savePath,true);
|
||||
m_Parent->UpdateListConfig();
|
||||
CDialog::OnOK();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (length==0)
|
||||
{
|
||||
MessageBox(_TEXT("请输入保存项名称"),_TEXT("提示"));
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox(_TEXT("最多只允许输入50个字符,请重新输入"),_TEXT("提示"));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
#pragma once
|
||||
//#include "UI_INI.h"
|
||||
// SaveConfigDlg 对话框
|
||||
|
||||
class SaveConfigDlg : public CDialog
|
||||
{
|
||||
DECLARE_DYNAMIC(SaveConfigDlg)
|
||||
|
||||
public:
|
||||
SaveConfigDlg(CWnd* pParent = NULL); // 标准构造函数
|
||||
virtual ~SaveConfigDlg();
|
||||
|
||||
// 对话框数据
|
||||
#ifdef AFX_DESIGN_TIME
|
||||
enum { IDD = IDD_DIALOGSAVECONFIG };
|
||||
#endif
|
||||
|
||||
protected:
|
||||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
public:
|
||||
afx_msg void OnBnClickedOk();
|
||||
|
||||
private:
|
||||
CWnd* m_Parent;
|
||||
};
|
34
StopWatch.h
34
StopWatch.h
|
@ -1,34 +0,0 @@
|
|||
#pragma once
|
||||
#include <chrono>
|
||||
|
||||
class StopWatch
|
||||
{
|
||||
public:
|
||||
StopWatch() {
|
||||
_start = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_start = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
double elapsed_s() {
|
||||
return std::chrono::duration<double>(std::chrono::steady_clock::now() - _start).count();
|
||||
}
|
||||
|
||||
double elapsed_ms() {
|
||||
return std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - _start).count();
|
||||
}
|
||||
|
||||
double elapsed_us() {
|
||||
return std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - _start).count();
|
||||
}
|
||||
|
||||
double elapsed_ns() {
|
||||
return std::chrono::duration<double, std::nano>(std::chrono::steady_clock::now() - _start).count();
|
||||
}
|
||||
|
||||
private:
|
||||
std::chrono::steady_clock::time_point _start;
|
||||
};
|
||||
|
|
@ -1,247 +0,0 @@
|
|||
#include "stdafx.h"
|
||||
#include "SupperScanImageMTF.h"
|
||||
#include "math.h"
|
||||
|
||||
CSupperScanImageMTF::CSupperScanImageMTF(void)
|
||||
{
|
||||
memset(&st_im, 0, sizeof(IMAGE_MTF));
|
||||
blank_bk = NULL;
|
||||
cur_image = NULL;
|
||||
}
|
||||
|
||||
CSupperScanImageMTF::~CSupperScanImageMTF(void)
|
||||
{
|
||||
memset(&st_im, 0, sizeof(IMAGE_MTF));
|
||||
delete[]blank_bk[0];
|
||||
delete[]blank_bk;
|
||||
delete[]cur_image[0];
|
||||
delete[]cur_image;
|
||||
}
|
||||
/// <summary>
|
||||
/// return the state of the image whether it is blank.
|
||||
/// </summary>
|
||||
bool CSupperScanImageMTF::GetImageBlankFlag()
|
||||
{
|
||||
return is_blank;
|
||||
}
|
||||
/// <summary>
|
||||
/// Initialize the information needed to estimate an image.
|
||||
/// set the size of the image, the starting coordinate.
|
||||
/// set the parameters related to the dafault values(10,10,1.0,76).
|
||||
/// If the initialization finished,return true and the b_init_image_info_flg will be set to true;
|
||||
/// otherwise return false.
|
||||
/// </summary>
|
||||
/// <param name="n_image_width","n_image_height"> the width ,height of the input image.</param>
|
||||
/// <param name=" n_start_x"," n_start_y">the starting position on the width and the height direction.</param>
|
||||
bool CSupperScanImageMTF::InitMTFImageInfo(INT n_image_width, INT n_image_height, INT n_start_x, INT n_start_y)
|
||||
{
|
||||
if (st_im.b_init_image_info_flg)
|
||||
return TRUE;
|
||||
if (n_image_width < 0 || n_image_height < 0 || n_start_x < 0 || n_start_y < 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if ((n_image_width - n_start_x) < width_half_count * 2 || (n_image_height - n_start_y) < height_half_count * 2)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
memset(&st_im, 0, sizeof(IMAGE_MTF));
|
||||
st_im.st_image_size.n_image_height = n_image_height;
|
||||
st_im.st_image_size.n_image_width = n_image_width;
|
||||
st_im.st_image_size.n_image_start_x = n_start_x;
|
||||
st_im.st_image_size.n_image_start_y = n_start_y;
|
||||
FLOAT f_x = (n_image_width - n_start_x)*1.0F / (width_half_count * 2);
|
||||
FLOAT f_y = (n_image_height - n_start_y)*1.0F / (height_half_count * 2);
|
||||
st_im.n_mtf_image_width = (INT)f_x;
|
||||
st_im.n_mtf_image_height = (INT)f_y;
|
||||
|
||||
//SetSkipBlankPara(10, 10, 1, 76);
|
||||
|
||||
st_im.b_init_image_info_flg = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// estimate the input image whehter it is blank or not
|
||||
/// set the size of the image, the starting coordinate;
|
||||
/// set the parameters(INT w_half_count, INT h_half_count, INT f_range, INT thres) needed to estimate
|
||||
/// an image blank to the dafault values(10,10,1.0,76).
|
||||
/// allocate space for the two-dimensional array which will contain the computed variances of each region of the input image.
|
||||
/// allocate space for the two-dimensional array which will contain the computed variances of each region of a blank image.
|
||||
/// initialize both of the two arrays to 0.0.
|
||||
/// </summary>
|
||||
/// <param name="n_image_width"> the width of the input image.</param>
|
||||
/// <param name="n_image_height">the height of the input image.</param>
|
||||
/// <param name=" n_start_x">the starting position on the width direction .</param>
|
||||
/// <param name=" n_start_y">the start position on the height direction.</param>
|
||||
bool CSupperScanImageMTF::IsImageBlank(PBYTE p_image_data, INT n_image_width, INT n_image_height, DWORD dw_bit_color)
|
||||
{
|
||||
bool blank = false;
|
||||
if (p_image_data == NULL && n_image_width != st_im.st_image_size.n_image_height && n_image_height != st_im.st_image_size.n_image_width)
|
||||
return blank;
|
||||
if (!st_im.b_init_image_info_flg) {
|
||||
return blank;
|
||||
}
|
||||
INT n_w = 0;
|
||||
INT n_h = 0;
|
||||
INT n_x = 0;
|
||||
INT n_y = 0;
|
||||
DWORD dw_all_r = 0;
|
||||
DWORD dw_all_g = 0;
|
||||
DWORD dw_all_b = 0;
|
||||
INT f_r_average = 0.0F;
|
||||
INT f_g_average = 0.0F;
|
||||
INT f_b_average = 0.0F;
|
||||
DWORD dw_src_image_line_bytes = (n_image_width * dw_bit_color + 31) / 32 * 4;
|
||||
|
||||
if (dw_bit_color >= 8 && dw_bit_color % 8 == 0 && dw_bit_color != 16)
|
||||
{
|
||||
DWORD dw_bit_pixel = dw_bit_color >> 3;
|
||||
DWORD dwMTF_RECT_HEIGHT = n_image_height / (height_half_count * 2);
|
||||
DWORD dwMTF_RECT_WIDTH = n_image_width / (width_half_count * 2);
|
||||
PBYTE p_data_ls = NULL;
|
||||
DWORD dw_data_pos_h_ls = 0;
|
||||
DWORD dw_data_pos_w_ls = 0;
|
||||
for (n_h = 0; n_h < height_half_count * 2; n_h++)
|
||||
{
|
||||
for (n_w = 0; n_w < width_half_count * 2; n_w++)
|
||||
{
|
||||
dw_all_r = 0;
|
||||
dw_all_g = 0;
|
||||
dw_all_b = 0;
|
||||
p_data_ls = p_image_data + n_h * dwMTF_RECT_HEIGHT * dw_src_image_line_bytes + n_w * dwMTF_RECT_WIDTH * dw_bit_pixel;
|
||||
dw_data_pos_h_ls = 0;
|
||||
for (n_y = 0; n_y < dwMTF_RECT_HEIGHT; n_y++)
|
||||
{
|
||||
dw_data_pos_w_ls = 0;
|
||||
for (n_x = 0; n_x < dwMTF_RECT_WIDTH; n_x++)
|
||||
{
|
||||
if (dw_bit_pixel == 1) {
|
||||
dw_all_g += *(p_data_ls + dw_data_pos_h_ls + dw_data_pos_w_ls);
|
||||
}
|
||||
else {
|
||||
dw_all_b += *(p_data_ls + dw_data_pos_h_ls + dw_data_pos_w_ls + 0);
|
||||
dw_all_g += *(p_data_ls + dw_data_pos_h_ls + dw_data_pos_w_ls + 1);
|
||||
dw_all_r += *(p_data_ls + dw_data_pos_h_ls + dw_data_pos_w_ls + 2);
|
||||
}
|
||||
dw_data_pos_w_ls += dw_bit_pixel;
|
||||
}
|
||||
dw_data_pos_h_ls += dw_src_image_line_bytes;
|
||||
}
|
||||
if (dw_bit_pixel == 1) {
|
||||
f_r_average = f_g_average = f_b_average = dw_all_g / (dwMTF_RECT_HEIGHT * dwMTF_RECT_WIDTH);
|
||||
}
|
||||
else {
|
||||
f_b_average = dw_all_b / (dwMTF_RECT_HEIGHT * dwMTF_RECT_WIDTH);
|
||||
f_g_average = dw_all_g / (dwMTF_RECT_HEIGHT * dwMTF_RECT_WIDTH);
|
||||
f_r_average = dw_all_r / (dwMTF_RECT_HEIGHT * dwMTF_RECT_WIDTH);
|
||||
}
|
||||
dw_all_r = 0;
|
||||
dw_all_g = 0;
|
||||
dw_all_b = 0;
|
||||
p_data_ls = p_image_data + n_h * dwMTF_RECT_HEIGHT * dw_src_image_line_bytes + n_w * dwMTF_RECT_WIDTH * dw_bit_pixel;
|
||||
dw_data_pos_h_ls = 0;
|
||||
DWORD dw_tmp = 0x0L;
|
||||
for (n_y = 0; n_y < dwMTF_RECT_HEIGHT; n_y++)
|
||||
{
|
||||
dw_data_pos_w_ls = 0;
|
||||
for (n_x = 0; n_x < dwMTF_RECT_WIDTH; n_x++)
|
||||
{
|
||||
if (dw_bit_pixel == 1) {
|
||||
dw_tmp = *(p_data_ls + dw_data_pos_h_ls + dw_data_pos_w_ls) - f_g_average;
|
||||
dw_all_g += (DWORD)dw_tmp * dw_tmp;
|
||||
}
|
||||
else {
|
||||
dw_tmp = *(p_data_ls + dw_data_pos_h_ls + dw_data_pos_w_ls + 0) - f_b_average;
|
||||
dw_all_b += dw_tmp * dw_tmp;
|
||||
dw_tmp = *(p_data_ls + dw_data_pos_h_ls + dw_data_pos_w_ls + 1) - f_g_average;
|
||||
dw_all_g += dw_tmp * dw_tmp;
|
||||
dw_tmp = *(p_data_ls + dw_data_pos_h_ls + dw_data_pos_w_ls + 2) - f_r_average;
|
||||
dw_all_r += dw_tmp * dw_tmp;
|
||||
}
|
||||
dw_data_pos_w_ls += dw_bit_pixel;
|
||||
}
|
||||
dw_data_pos_h_ls += dw_src_image_line_bytes;
|
||||
}
|
||||
if (dw_bit_pixel == 1) {
|
||||
cur_image[n_w][n_h].f_r_mtf = cur_image[n_w][n_h].f_g_mtf = cur_image[n_w][n_h].f_b_mtf = (INT)sqrt((dw_all_g*1.0F) / (dwMTF_RECT_HEIGHT * dwMTF_RECT_WIDTH - 1));
|
||||
}
|
||||
else {
|
||||
cur_image[n_w][n_h].f_r_mtf = (INT)sqrt((dw_all_r*1.0F) / (dwMTF_RECT_HEIGHT * dwMTF_RECT_WIDTH - 1));
|
||||
cur_image[n_w][n_h].f_g_mtf = (INT)sqrt((dw_all_g*1.0F) / (dwMTF_RECT_HEIGHT * dwMTF_RECT_WIDTH - 1));
|
||||
cur_image[n_w][n_h].f_b_mtf = (INT)sqrt((dw_all_b*1.0F) / (dwMTF_RECT_HEIGHT * dwMTF_RECT_WIDTH - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return blank;
|
||||
}
|
||||
st_im.n_cur_precent_rect_count = 0;
|
||||
for (n_w = 0; n_w < width_half_count * 2; n_w++)
|
||||
{
|
||||
for (n_h = 0; n_h < height_half_count * 2; n_h++)
|
||||
{
|
||||
if (CMP_FLOAT_RANGLE(blank_bk[n_w][n_h].f_r_mtf, float_range, cur_image[n_w][n_h].f_r_mtf) && \
|
||||
CMP_FLOAT_RANGLE(blank_bk[n_w][n_h].f_g_mtf, float_range, cur_image[n_w][n_h].f_g_mtf) && \
|
||||
CMP_FLOAT_RANGLE(blank_bk[n_w][n_h].f_b_mtf, float_range, cur_image[n_w][n_h].f_b_mtf))
|
||||
{
|
||||
st_im.n_cur_precent_rect_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
st_im.n_cur_precent_rect_count = (INT)((st_im.n_cur_precent_rect_count)*1.0F / (height_half_count * width_half_count * 4) * 100);
|
||||
if (st_im.n_cur_precent_rect_count >= threshold)//±³¾°
|
||||
{
|
||||
blank = true;
|
||||
is_blank = blank;
|
||||
}
|
||||
return blank;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the parameters needed to estimate whether an image is blank or not.
|
||||
/// allocate space for the two two-dimensional array which will contain the computed variances of each region of the input image and a blank image respectively.
|
||||
/// initialize both of the two arrays to 0.0.
|
||||
/// If the setting finished,return true; otherwise return false.
|
||||
/// </summary>
|
||||
/// <param name=" w_half_count","h_half_count"> half of the number of blocks divided on the width and height of the input image.</param>
|
||||
/// <param name="f_range">the float range of variance compared with 0,because the variances of regions of an blank image are all 0.</param>
|
||||
/// <param name="thres">the percent of regions whose variance is in the floating range.</param>
|
||||
bool CSupperScanImageMTF::SetSkipBlankPara(INT w_half_count, INT h_half_count, INT f_range, INT thres) {
|
||||
if (w_half_count <= 0 || w_half_count >= (st_im.st_image_size.n_image_width >> 1) || h_half_count <= 0 || h_half_count >= st_im.st_image_size.n_image_height >> 1) {
|
||||
return FALSE;
|
||||
}
|
||||
if (f_range < 0 || thres < 0 || thres >100) {
|
||||
return FALSE;
|
||||
}
|
||||
this->width_half_count = w_half_count;
|
||||
this->height_half_count = h_half_count;
|
||||
this->float_range = f_range;
|
||||
this->threshold = thres;
|
||||
if (blank_bk != NULL) {
|
||||
delete[]blank_bk[0];
|
||||
delete[]blank_bk;
|
||||
}
|
||||
if (cur_image != NULL) {
|
||||
delete[]cur_image[0];
|
||||
delete[]cur_image;
|
||||
}
|
||||
blank_bk = new IMAGE_RECT_MTF *[width_half_count * 2];//±³¾°mtf
|
||||
cur_image = new IMAGE_RECT_MTF *[width_half_count * 2];//µ±Ç°Ö¡µÄMTF
|
||||
blank_bk[0] = new IMAGE_RECT_MTF[width_half_count *height_half_count * 4];
|
||||
cur_image[0] = new IMAGE_RECT_MTF[width_half_count *height_half_count * 4];
|
||||
for (int i = 1; i < width_half_count * 2; ++i) {
|
||||
blank_bk[i] = blank_bk[i - 1] + height_half_count * 2;
|
||||
cur_image[i] = cur_image[i - 1] + height_half_count * 2;
|
||||
}
|
||||
IMAGE_RECT_MTF bk = { 0.0f, 0.0f, 0.0f };
|
||||
for (int i = 0; i < width_half_count * 2; ++i) {
|
||||
for (int j = 0; j < height_half_count * 2; ++j) {
|
||||
blank_bk[i][j] = bk;
|
||||
cur_image[i][j] = bk;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue