1.更换编译器为VS2017,跟换opencv版本为3.4.6
2.调整线程退出方式 3.修复最后一场图像图像数据从usb读上来之后,可能未传图到应用层问题 4.重构Twain代码,分层更明确
This commit is contained in:
parent
155ee06586
commit
cb374c3235
|
@ -5,6 +5,10 @@
|
|||
#endif // !_USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include "PublicFunc.h"
|
||||
#include "filetools.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
CAutoCrop::CAutoCrop( bool bFill,bool bautoDeScrew, bool bCrop,SIZE dstsize,SIZE originSize,int tw_pixType)
|
||||
:m_bAutoDescrew(bautoDeScrew), m_bCrop(bCrop), m_bFill(bFill),m_dstSize(dstsize),m_originSize(originSize),tw_pixType(tw_pixType)
|
||||
|
@ -25,6 +29,7 @@ void CAutoCrop::apply(cv::Mat & dib,int side)
|
|||
//double thresh = 70;
|
||||
//int blobSize = 200;
|
||||
//int edgeWidth =5;
|
||||
//FileTools::write_log("D:\\1.txt", "Enter autocrop apply");
|
||||
int flags=RC_INVALID;
|
||||
if (m_bCrop)
|
||||
{
|
||||
|
@ -71,54 +76,10 @@ void CAutoCrop::apply(cv::Mat & dib,int side)
|
|||
rectCrop.height=m_originSize.cy;
|
||||
}
|
||||
|
||||
//szActual.width=m_dstSize.cx;
|
||||
//szActual.height=m_dstSize.cy;
|
||||
|
||||
//szOrg.width=m_originSize.cx;
|
||||
//szOrg.height=m_originSize.cy;
|
||||
|
||||
|
||||
//rectCrop.x = (dib.cols- szOrg.width) / 2 ;
|
||||
//rectCrop.y = 0;
|
||||
//rectCrop.width = szOrg.width;
|
||||
//rectCrop.height = szOrg.height;
|
||||
Rect rectImage(0, 0, dib.cols, dib.rows);
|
||||
|
||||
//Size CropOrg = (rectCrop & rectImage).size ();
|
||||
dib = dib(rectCrop);
|
||||
}
|
||||
//imwrite("1.bmp",dib);
|
||||
#if 0
|
||||
ProcessRect(dib, rect, contour, scale, thresh, blobSize);
|
||||
//XdPrint("Begin m_bFill \n");
|
||||
if (m_bFill)
|
||||
{
|
||||
fillBlack(dib, contour,edgeWidth);
|
||||
//XdPrint("m_bFill \n");
|
||||
}
|
||||
|
||||
if (m_bAutoDescrew)//自动纠偏
|
||||
{
|
||||
//XdPrint("m_bAutoDescrew strart\n");
|
||||
RotateImage(dib,rect,m_bCrop,m_bFill);//自动纠偏和自动裁切或自动纠偏 不自动裁切
|
||||
//XdPrint("m_bAutoDescrew end\n");
|
||||
}
|
||||
|
||||
if (m_bCrop&&!m_bAutoDescrew)//自动裁切 但不纠偏
|
||||
{
|
||||
vector<Point> vec(contour);
|
||||
Rect rectOut=boundingRect(vec);
|
||||
Mat temp=dib(rectOut);
|
||||
dib=temp.clone();
|
||||
temp.release();
|
||||
}
|
||||
|
||||
if (!m_bCrop)
|
||||
{
|
||||
dib=FixedCut(dib,side);
|
||||
//XdPrint("m_bCrop \n");
|
||||
}
|
||||
#endif // false
|
||||
//FileTools::write_log("D:\\1.txt", "Exit autocrop apply");
|
||||
}
|
||||
static int i=0;
|
||||
void CAutoCrop::setFill(bool val)
|
||||
|
@ -141,287 +102,6 @@ bool CAutoCrop::getCrop()
|
|||
return m_bCrop;
|
||||
}
|
||||
|
||||
#if 0
|
||||
Point2f CAutoCrop::RotateP2P(Point2f p, Point2f center, double Angle)
|
||||
{
|
||||
double h = Angle * M_PI / 180;
|
||||
float x = (p.x - center.x) * (float)cos(h) - (p.y - center.y) * (float)sin(h) + center.x;
|
||||
float y = (p.y - center.y) * (float)cos(h) + (p.x - center.x) * (float)sin(h) + center.y;
|
||||
return Point2f(x, y);
|
||||
}
|
||||
|
||||
void CAutoCrop::RotateImage(Mat & image, RotatedRect rotatedRect, bool bCrop,bool fillBlack)
|
||||
{
|
||||
Point2f center(image.cols / 2, image.rows / 2);
|
||||
Mat rot = getRotationMatrix2D(center, rotatedRect.angle, 1);
|
||||
RotatedRect rotated = RotatedRect(center, image.size(), -rotatedRect.angle);
|
||||
Rect bbox = rotated.boundingRect();
|
||||
Scalar sc;
|
||||
if (fillBlack)
|
||||
{
|
||||
warpAffine(image, image, rot, bbox.size(), CV_INTER_LINEAR,0,image.channels()==3?Scalar(255,255,255):Scalar(255));//CV_INTER_NN
|
||||
}
|
||||
else
|
||||
{
|
||||
warpAffine(image, image, rot, bbox.size(), CV_INTER_LINEAR,0,Scalar(0));//CV_INTER_NN
|
||||
}
|
||||
|
||||
if(!bCrop)
|
||||
return;
|
||||
|
||||
Point2f box[4];
|
||||
vector<Point2f > vec;
|
||||
rotatedRect.points(box);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
box[i] = RotateP2P(box[i], center, -rotatedRect.angle);
|
||||
vec.push_back(box[i]);
|
||||
}
|
||||
|
||||
RotatedRect rec = minAreaRect(vec);
|
||||
Rect roi = rec.boundingRect();
|
||||
Rect rectIm(0, 0, image.cols, image.rows);
|
||||
roi = roi & rectIm;
|
||||
image = image(roi);
|
||||
}
|
||||
|
||||
int CAutoCrop::ProcessRect(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
|
||||
{
|
||||
if (scale != 1.0f)
|
||||
{
|
||||
resize(image, gray, cv::Size(), scale, scale, 0);
|
||||
}
|
||||
}
|
||||
Mat threshold_img;
|
||||
threshold(gray, threshold_img, thresh, 255.0, CV_THRESH_BINARY);
|
||||
vector<vector<Point>> contours;
|
||||
vector<Vec4i> h1;
|
||||
GetContours(threshold_img, contours,h1,CV_RETR_EXTERNAL);
|
||||
|
||||
threshold_img.release();
|
||||
if (contours.size() == 0)
|
||||
{
|
||||
return blockCount;
|
||||
}
|
||||
|
||||
vector<Point> 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;
|
||||
}
|
||||
|
||||
void CAutoCrop::fillBlack(cv::Mat & dib, std::vector<cv::Point>& contour, int edge)
|
||||
{
|
||||
Mat mask(dib.rows, dib.cols, CV_8UC1);
|
||||
if (contour.size() < 3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
mask.setTo(255);
|
||||
|
||||
fillConvexPoly(mask, contour, Scalar(0));//填充轮廓构成的凸多边形
|
||||
Mat dilateKer = getStructuringElement(MORPH_RECT, Size(3, 3));
|
||||
dilate(mask, mask, dilateKer, Point(-1, -1), edge, BORDER_CONSTANT);//向内腐蚀灰边的宽度
|
||||
//imwrite("mask1.bmp",mask);
|
||||
dilateKer.release();
|
||||
cv::vector<cv::vector<Point>> contours;
|
||||
cv::vector<Vec4i> h1;
|
||||
GetContours(mask, contours, h1,CV_RETR_LIST);//向内腐蚀后的轮廓
|
||||
//XdPrint("GetContours after");
|
||||
mask.release();
|
||||
|
||||
//vector<Point> temp=contours.at(0);
|
||||
//const Point* pnt[1]={&temp[0]};
|
||||
//int numofPoints=(int)temp.size();
|
||||
//for (int i=0;i<contours.size();i++)
|
||||
//{
|
||||
// for (int j=0;j<contours[i].size();j++)
|
||||
// {
|
||||
// XdPrint(" X: %d Y: %d \n",contours[i][j].x,contours[i][j].y);
|
||||
// }
|
||||
//}
|
||||
MyFillPoly(dib,contours,cv::Scalar::all(255));
|
||||
}
|
||||
|
||||
Mat CAutoCrop::AutomaticDeskew(Mat image,int thres,float scale)
|
||||
{
|
||||
RotatedRect rotatedRect;
|
||||
vector<Point> contour;
|
||||
RotateImage(image, rotatedRect);
|
||||
//XdPrint("AutomaticDeskew");
|
||||
return image;
|
||||
}
|
||||
|
||||
Mat CAutoCrop::FixedCut(Mat image,int side)
|
||||
{
|
||||
Size szActual;
|
||||
szActual.width=m_dstSize.cx;
|
||||
szActual.height=m_dstSize.cy;
|
||||
Size szOrg;
|
||||
szOrg.width=m_originSize.cx;
|
||||
szOrg.height=m_originSize.cy;
|
||||
|
||||
Rect rectCrop;
|
||||
rectCrop.x = (image.cols- szOrg.width) / 2 ;
|
||||
rectCrop.y = 0;
|
||||
rectCrop.width = szOrg.width;
|
||||
rectCrop.height = szOrg.height;
|
||||
Rect rectImage(0, 0, image.cols, image.rows);
|
||||
if (side != 0)
|
||||
{
|
||||
rectCrop.y = 143; //调整反面
|
||||
}else
|
||||
{
|
||||
rectCrop.y = 73; //调整正面
|
||||
}
|
||||
Size CropOrg = (rectCrop & rectImage).size ();
|
||||
Mat roi = image(rectCrop);
|
||||
//XdPrint("FixedCut");
|
||||
return roi;
|
||||
}
|
||||
|
||||
//void CAutoCrop::fillrect(InputOutputArray img, InputArrayOfArrays pts, const Scalar& color, int lineType, int shift, Point offset)
|
||||
//{
|
||||
// int i, ncontours = (int)pts.total();
|
||||
// if( ncontours == 0 )
|
||||
// return;
|
||||
// AutoBuffer<Point*> _ptsptr(ncontours);
|
||||
// AutoBuffer<int> _npts(ncontours);
|
||||
// Point** ptsptr = _ptsptr.data();
|
||||
// int* npts = _npts.data();
|
||||
//
|
||||
// for( i = 0; i < ncontours; i++ )
|
||||
// {
|
||||
// Mat p = pts.getMat(i);
|
||||
// CV_Assert(p.checkVector(2, CV_32S) >= 0);
|
||||
// ptsptr[i] = p.ptr<Point>();
|
||||
// npts[i] = p.rows*p.cols*p.channels()/2;
|
||||
// }
|
||||
// fillPoly(img, (const Point**)ptsptr, npts, (int)ncontours, color, lineType, shift, offset);
|
||||
//}
|
||||
|
||||
int CAutoCrop::range(int low, int up, int value)
|
||||
{
|
||||
if (low > up)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value < low)
|
||||
{
|
||||
return low;
|
||||
}
|
||||
|
||||
if (value > up)
|
||||
{
|
||||
return up;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void CAutoCrop::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);
|
||||
}
|
||||
}
|
||||
#endif // false
|
||||
|
||||
|
||||
void CAutoCrop::sharpen(Mat& mat)
|
||||
{
|
||||
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 };
|
||||
|
@ -745,8 +425,7 @@ cv::Mat CAutoCrop::transforColor(const Mat& src)
|
|||
{
|
||||
return src.clone();
|
||||
}
|
||||
|
||||
vector<Mat> channels(3);
|
||||
Mat channels[3];
|
||||
split(src, channels);
|
||||
|
||||
Mat temp, dst;
|
||||
|
@ -758,7 +437,7 @@ cv::Mat CAutoCrop::transforColor(const Mat& src)
|
|||
//{
|
||||
// index.release();
|
||||
//}
|
||||
for (int i=0;i < channels.size();i++)
|
||||
for (int i=0;i < 3;i++)
|
||||
{
|
||||
channels[i].release();
|
||||
}
|
||||
|
@ -798,7 +477,8 @@ void CAutoCrop::MyConvexHull(const vector<Point>& src, vector<Point>& dst, bool
|
|||
}
|
||||
|
||||
//ÊÍ·Åstorage
|
||||
cvClearMemStorage(storage);
|
||||
//cvClearMemStorage(storage);
|
||||
cvReleaseMemStorage(&storage);
|
||||
}
|
||||
|
||||
vector<Point> getMaxContour(const vector<vector<Point>>& contours, const vector<Vec4i>& hierarchy)
|
|
@ -0,0 +1,48 @@
|
|||
#pragma once
|
||||
#include "ImageApply.h"
|
||||
|
||||
class CAutoCrop : public CImageApply
|
||||
{
|
||||
public:
|
||||
CAutoCrop( bool bFill = true,bool bautoDeScrew = true,bool bCrop = true,SIZE dstsize = CSize(0, 0),SIZE originsize=CSize(0,0),int tw_pixType=2);
|
||||
virtual ~CAutoCrop();
|
||||
|
||||
void apply(cv::Mat& dib,int side);
|
||||
|
||||
void setFill(bool val);
|
||||
bool getFill();
|
||||
|
||||
void setCrop(bool val);
|
||||
bool getCrop();
|
||||
|
||||
private:
|
||||
enum RC_TYPE {
|
||||
RC_INVALID = 0x0,
|
||||
RC_ROTATED = 0x1,
|
||||
RC_CUT = 0x2,
|
||||
RC_BLACK_BACKGROUD = 0x4,
|
||||
RC_SHARPING = 0x8
|
||||
};
|
||||
|
||||
void sharpen(cv::Mat& Mat);
|
||||
cv::Point2f warpPoint(cv::Point p, const cv::Mat& warp_Mat);
|
||||
void rotated_and_cut(cv::Mat &src, cv::Mat& dst,int flags,double threshold,int noise,int indent);
|
||||
void fillBlackBackGround(cv::Mat& src, std::vector<cv::Point> points, float indent);
|
||||
void polyIndent(std::vector<cv::Point>& points, float indent);
|
||||
void fill_poly(cv::Mat& src, const std::vector<std::vector<cv::Point>>& contours, const cv::Scalar& color, int lineType = 8, int shift = 0, cv::Point offset = cv::Point());
|
||||
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);
|
||||
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));
|
||||
void threshold_Mat(const cv::Mat& src, cv::Mat& dst, double thre, int noise);
|
||||
cv::Mat transforColor(const cv::Mat& src);
|
||||
void MyConvexHull(const std::vector<cv::Point>& src, std::vector<cv::Point>& dst, bool clockwise = false);
|
||||
|
||||
bool m_bCrop;
|
||||
bool m_bFill;
|
||||
bool m_bAutoDescrew;
|
||||
SIZE m_dstSize;
|
||||
SIZE m_originSize;
|
||||
int tw_pixType;
|
||||
};
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
#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;
|
||||
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();
|
||||
}
|
||||
};
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,153 @@
|
|||
/*******************************************************************************
|
||||
* 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_ */
|
|
@ -0,0 +1,409 @@
|
|||
/***************************************************************************
|
||||
* 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 "gscn_drv.h"
|
||||
#include "PublicFunc.h"
|
||||
#include "AutoCrop.h"
|
||||
#include "ImageAdjustColors.h"
|
||||
#include "ImageChannel.h"
|
||||
#include "ImageApplyResize.h"
|
||||
#include "ImageRotation.h"
|
||||
#include "ImageProcDiscardBlank.h"
|
||||
#include "filetools.h"
|
||||
#include "hugaotwainds.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;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
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_drv.open(0x064B, 0x7823);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
CScanner_FreeImage::~CScanner_FreeImage()
|
||||
{
|
||||
}
|
||||
|
||||
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_drv.Get_IsImageQueueEmpty() != 0)
|
||||
{
|
||||
g_drv.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_drv.config_params(*(getSetting()));
|
||||
g_drv.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_drv.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_drv.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_drv.Get_Scanner_PaperOn();
|
||||
return rtn;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool CScanner_FreeImage::getDeviceOnline() const
|
||||
{
|
||||
return g_drv.IsConnected();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
std::string CScanner_FreeImage::getSerialNum() const
|
||||
{
|
||||
return g_drv.GetSerialNum();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
std::string CScanner_FreeImage::getFWVersion() const
|
||||
{
|
||||
return g_drv.GetFWVersion();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
bool CScanner_FreeImage::StopScan()
|
||||
{
|
||||
bool ret = true;
|
||||
g_drv.Stop_scan();
|
||||
int retry_times = 0;
|
||||
while (g_drv.is_scan())
|
||||
{
|
||||
if (retry_times > 10)//超过500ms还没停止则跳出 不进行DoCloseDSRequestEvent()
|
||||
{
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
Sleep(50);
|
||||
retry_times++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool CScanner_FreeImage::isPaperOn() //const
|
||||
{
|
||||
return g_drv.Get_Scanner_PaperOn();
|
||||
}
|
||||
|
||||
bool CScanner_FreeImage::isImageQueueEmpty()
|
||||
{
|
||||
bool ret;
|
||||
if (!g_drv.is_scan() && g_drv.Get_IsImageQueueEmpty() && (g_drv.get_ErrorCode() == 0))
|
||||
ret = true;
|
||||
else
|
||||
ret = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool CScanner_FreeImage::stillhaveImage()
|
||||
{
|
||||
return g_drv.Get_IsImageQueueEmpty();
|
||||
}
|
||||
|
|
@ -48,6 +48,9 @@
|
|||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <map>
|
||||
#include "ImageTransfer.h"
|
||||
#include "ImageTranferBW.h"
|
||||
#include "ImageTranferMat.h"
|
||||
|
||||
using namespace std;
|
||||
/**
|
||||
|
@ -112,67 +115,7 @@ using namespace std;
|
|||
* The FreeImage scanner data structure. This data is passed back and forth between the scanner class and driver.
|
||||
*
|
||||
*/
|
||||
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;
|
||||
};
|
||||
|
||||
class CImageProc;
|
||||
class CImageApply;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
class twainImage;
|
||||
|
||||
/**
|
||||
* The FreeImage scanner. The software scanner using FreeImage.
|
||||
|
@ -243,7 +186,7 @@ public:
|
|||
* IF empty loads again for next time.
|
||||
* @return true if paper in feeder else return false.
|
||||
*/
|
||||
bool isFeederLoaded();
|
||||
bool isFeederLoaded() const;
|
||||
|
||||
/**
|
||||
* Return status of the device is online or not.
|
||||
|
@ -251,13 +194,15 @@ public:
|
|||
*/
|
||||
bool getDeviceOnline() const;
|
||||
|
||||
bool isPaperOn() 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;};
|
||||
|
@ -290,27 +235,19 @@ protected:
|
|||
|
||||
|
||||
protected:
|
||||
//FIBITMAP *m_pDIB; /**< Pointer to current scanned image */
|
||||
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_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;
|
||||
//twainImage m_matDib_c;
|
||||
|
||||
private:
|
||||
bool can_updateList;
|
||||
void UpdateList(bool canUpdate=true);
|
||||
void InitMSGMap();
|
||||
std::vector<std::shared_ptr<CImageApply>> m_iaList;
|
||||
|
||||
std::shared_ptr<ImageTransfer> m_imageTrans;
|
||||
std::map<UINT32,std::string> ntcMsg;
|
||||
};
|
||||
|
||||
#endif // __CSCANNER_H__
|
||||
|
||||
//extern IndicatorDlg* m_pIndicator;
|
|
@ -88,6 +88,7 @@ CTWAINDS_Base::~CTWAINDS_Base()
|
|||
_DSM_Free(m_hImageData);
|
||||
m_hImageData = 0;
|
||||
}
|
||||
//FileTools::write_log("1.txt", "~CTWAINDS_Base");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
|
@ -103,19 +103,18 @@ TW_IDENTITY CTWAINDS_Base::m_TheIdentity =
|
|||
#ifdef __APPLE__
|
||||
"\p"
|
||||
#endif
|
||||
"HUAGOSCAN Hi-5130 TWAIN" // TW_STR32 ProductName; Product name, e.g. "ScanJet Plus"
|
||||
"HUAGOSCAN Hi-5100 TWAIN" // TW_STR32 ProductName; Product name, e.g. "ScanJet Plus"
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
CTWAINDS_FreeImage::CTWAINDS_FreeImage(TW_IDENTITY AppID) :
|
||||
m_pICAP_FRAMES(0)
|
||||
{
|
||||
b_created=g_CreateSysMutex();
|
||||
b_created = g_CreateSysMutex();
|
||||
m_AppID = AppID;
|
||||
// Setup our identity
|
||||
fillIdentityStructure(*getIdentity());
|
||||
m_pGUI = CreateUI(this);
|
||||
isDestroyed=false;
|
||||
}
|
||||
|
||||
bool CTWAINDS_FreeImage::StoreCapInStream(stringstream &_DsData, TW_UINT16 _unCapID, TW_UINT16 _unCapIdx, TW_UINT16 unContType)
|
||||
|
@ -446,7 +445,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
|
|||
|| !pnCap->Add(0x8021)//歪斜程度
|
||||
|| !pnCap->Add(CAP_DOUBLEFEEDDETECTION)//双张检测
|
||||
|| !pnCap->Add(0x8090)//装订检测
|
||||
||!pnCap->Add(0x8091)//自动丢弃空白页(发票)
|
||||
|| !pnCap->Add(0x8091)//自动丢弃空白页(发票)
|
||||
|
||||
)
|
||||
{
|
||||
|
@ -477,7 +476,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
|
|||
|
||||
m_IndependantCapMap[ICAP_UNITS] = new CTWAINContainerInt(ICAP_UNITS, TWTY_UINT16, TWON_ENUMERATION);
|
||||
if (NULL == (pnCap = dynamic_cast<CTWAINContainerInt*>(m_IndependantCapMap[ICAP_UNITS]))
|
||||
|| !pnCap->Add(TWUN_INCHES,true)
|
||||
|| !pnCap->Add(TWUN_INCHES, true)
|
||||
|| !pnCap->Add(TWUN_PIXELS)
|
||||
|| !pnCap->Add(TWUN_CENTIMETERS)
|
||||
|| !pnCap->Add(TWUN_PICAS)
|
||||
|
@ -910,23 +909,23 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
|
|||
//扫描仪序列号
|
||||
m_IndependantCapMap[CAP_SERIALNUMBER] = new CTWAINContainerString(CAP_SERIALNUMBER, TWTY_STR255, TWON_ONEVALUE, TWQC_GETS);
|
||||
if (NULL == (pstrCap = dynamic_cast<CTWAINContainerString*>(m_IndependantCapMap[CAP_SERIALNUMBER]))
|
||||
|| !pstrCap->Add("G20018000000", true))//m_Scanner.getSerialNum()
|
||||
{
|
||||
cerr << "Could not create CAP_SERIALNUMBER" << endl;
|
||||
setConditionCode(TWCC_LOWMEMORY);
|
||||
return TWRC_FAILURE;
|
||||
}
|
||||
|| !pstrCap->Add("G20018000000", true))//m_Scanner.getSerialNum()
|
||||
{
|
||||
cerr << "Could not create CAP_SERIALNUMBER" << endl;
|
||||
setConditionCode(TWCC_LOWMEMORY);
|
||||
return TWRC_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
//扫描仪固件版本号
|
||||
m_IndependantCapMap[0x8025] = new CTWAINContainerString(0x8025, TWTY_STR255, TWON_ONEVALUE, TWQC_GETS);
|
||||
if (NULL == (pstrCap = dynamic_cast<CTWAINContainerString*>(m_IndependantCapMap[0x8025]))
|
||||
|| !pstrCap->Add("51000000", true))
|
||||
{
|
||||
cerr << "Could not create Get FWVersion" << endl;
|
||||
setConditionCode(TWCC_LOWMEMORY);
|
||||
return TWRC_FAILURE;
|
||||
}
|
||||
|| !pstrCap->Add("51000000", true))
|
||||
{
|
||||
cerr << "Could not create Get FWVersion" << endl;
|
||||
setConditionCode(TWCC_LOWMEMORY);
|
||||
return TWRC_FAILURE;
|
||||
}
|
||||
|
||||
//自动裁切
|
||||
m_IndependantCapMap[ICAP_AUTOMATICCROPUSESFRAME] = new CTWAINContainerBool(ICAP_AUTOMATICCROPUSESFRAME, (m_AppID.SupportedGroups&DF_APP2) != 0, TWQC_ALL);
|
||||
|
@ -966,11 +965,11 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
|
|||
if (NULL == (pbCap = dynamic_cast<CTWAINContainerBool*>(m_IndependantCapMap[0x8004]))
|
||||
|| !pbCap->Add(TRUE)
|
||||
|| !pbCap->Add(FALSE, true))
|
||||
{
|
||||
{
|
||||
cerr << "Could not create ICAP_AUTODISCARDBLANKPAGES" << endl;
|
||||
setConditionCode(TWCC_LOWMEMORY);
|
||||
return TWRC_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
//自动颜色识别
|
||||
m_IndependantCapMap[ICAP_AUTOMATICCOLORENABLED] = new CTWAINContainerBool(ICAP_AUTOMATICCOLORENABLED, (m_AppID.SupportedGroups&DF_APP2) != 0, TWQC_ALL);
|
||||
|
@ -1006,7 +1005,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
|
|||
}
|
||||
|
||||
//除色与颜色增强
|
||||
m_IndependantCapMap[ICAP_FILTER] = new CTWAINContainerInt(ICAP_FILTER, TWTY_UINT16,TWON_ONEVALUE);
|
||||
m_IndependantCapMap[ICAP_FILTER] = new CTWAINContainerInt(ICAP_FILTER, TWTY_UINT16, TWON_ONEVALUE);
|
||||
if (NULL == (pnCap = dynamic_cast<CTWAINContainerInt*>(m_IndependantCapMap[ICAP_FILTER]))
|
||||
|| !pnCap->Add(0, true)//不除色
|
||||
|| !pnCap->Add(1)//除红色
|
||||
|
@ -1023,7 +1022,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
|
|||
}
|
||||
|
||||
//背面旋转180
|
||||
m_IndependantCapMap[0x8005] = new CTWAINContainerBool(0x8005,TWON_ONEVALUE, TWQC_ALL);
|
||||
m_IndependantCapMap[0x8005] = new CTWAINContainerBool(0x8005, TWON_ONEVALUE, TWQC_ALL);
|
||||
if (NULL == (pbCap = dynamic_cast<CTWAINContainerBool*>(m_IndependantCapMap[0x8005]))
|
||||
|| !pbCap->Add(TRUE)
|
||||
|| !pbCap->Add(FALSE, true))
|
||||
|
@ -1034,7 +1033,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
|
|||
}
|
||||
|
||||
//去除穿孔
|
||||
m_IndependantCapMap[0x8018] = new CTWAINContainerBool(0x8018,TWON_ONEVALUE, TWQC_ALL);
|
||||
m_IndependantCapMap[0x8018] = new CTWAINContainerBool(0x8018, TWON_ONEVALUE, TWQC_ALL);
|
||||
if (NULL == (pbCap = dynamic_cast<CTWAINContainerBool*>(m_IndependantCapMap[0x8018]))
|
||||
|| !pbCap->Add(TRUE)
|
||||
|| !pbCap->Add(FALSE, true))
|
||||
|
@ -1045,7 +1044,7 @@ TW_INT16 CTWAINDS_FreeImage::Initialize()
|
|||
}
|
||||
|
||||
//去除穿孔占幅面比例
|
||||
fRange.fCurrentValue =10.0f;
|
||||
fRange.fCurrentValue = 10.0f;
|
||||
fRange.fMaxValue = 50.0f;
|
||||
fRange.fMinValue = 1.0f;
|
||||
fRange.fStepSize = 1.0f;
|
||||
|
@ -1136,6 +1135,7 @@ CTWAINDS_FreeImage::~CTWAINDS_FreeImage()
|
|||
m_pICAP_FRAMES = 0;
|
||||
|
||||
g_CloseSysMutexRun();//关闭互斥锁
|
||||
//FileTools::write_log("1.txt", "~CTWAINDS_FreeImage");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1214,7 +1214,7 @@ TW_INT16 CTWAINDS_FreeImage::getImageInfo(pTW_IMAGEINFO _pImageInfo)
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
TW_INT16 CTWAINDS_FreeImage::openDS(pTW_IDENTITY _pOrigin)
|
||||
{
|
||||
if (b_created==FALSE)
|
||||
if (b_created == FALSE)
|
||||
{
|
||||
return TWRC_FAILURE;
|
||||
}
|
||||
|
@ -1256,30 +1256,18 @@ TW_INT16 CTWAINDS_FreeImage::openDS(pTW_IDENTITY _pOrigin)
|
|||
m_CurrentState = dsState_Open;
|
||||
}
|
||||
JsonConfig js;
|
||||
CONFIGPARAMS configParams=js.ReadDefaultConfig();
|
||||
bool ss= UpdateCapsFromConfig(configParams);
|
||||
CONFIGPARAMS configParams = js.ReadDefaultConfig();
|
||||
bool ss = UpdateCapsFromConfig(configParams);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
TW_INT16 CTWAINDS_FreeImage::closeDS()
|
||||
{
|
||||
// check if ok to return success
|
||||
// Must be in state 4
|
||||
//if (!isDestroyed)//m_CurrentState==dsState_Enabled
|
||||
//{
|
||||
//m_pGUI->DestroyTWAINGUI();
|
||||
//XdPrint("closeDS m_pGUI->DestroyTWAINGUI() \n");
|
||||
//// // allow the scanners caps to be writeable again because we are moving back
|
||||
//// // to state 4. If this source had a UI, it would be lowered at this time.
|
||||
//m_Scanner.Unlock();
|
||||
//m_CurrentState = dsState_Open;
|
||||
//isDestroyed=true;
|
||||
//}
|
||||
//else
|
||||
if(dsState_Open != m_CurrentState)
|
||||
{
|
||||
if (dsState_Open != m_CurrentState)
|
||||
{
|
||||
setConditionCode(TWCC_SEQERROR);
|
||||
//FileTools::write_log("1.txt", "~CTWAINDS_FreeImage closeDS dsState_Open != m_CurrentState");
|
||||
return TWRC_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -1292,7 +1280,7 @@ TW_INT16 CTWAINDS_FreeImage::closeDS()
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
TW_INT16 CTWAINDS_FreeImage::enableDS(pTW_USERINTERFACE _pData)
|
||||
{
|
||||
if (b_created==FALSE)//Twain被其他程序占用
|
||||
if (b_created == FALSE)//Twain被其他程序占用
|
||||
{
|
||||
return TWRC_FAILURE;
|
||||
}
|
||||
|
@ -1300,7 +1288,7 @@ TW_INT16 CTWAINDS_FreeImage::enableDS(pTW_USERINTERFACE _pData)
|
|||
if (dsState_Open != m_CurrentState)
|
||||
{
|
||||
setConditionCode(TWCC_SEQERROR);
|
||||
//FileTools::write_log("D:/1.txt","enableDS dsState_Open != m_CurrentState");
|
||||
//FileTools::write_log("1.txt", "~CTWAINDS_FreeImage enableDS dsState_Open != m_CurrentState");
|
||||
return TWRC_FAILURE;
|
||||
}
|
||||
m_CurrentState = dsState_Enabled;
|
||||
|
@ -1314,7 +1302,7 @@ TW_INT16 CTWAINDS_FreeImage::enableDS(pTW_USERINTERFACE _pData)
|
|||
//{
|
||||
// pnCap->GetCurrent(Count);
|
||||
//}
|
||||
//m_Xfers.Count = Count;
|
||||
m_Xfers.Count = -1;
|
||||
//stringstream ss;
|
||||
//ss<<m_Xfers.Count;
|
||||
//string sout=ss.str();
|
||||
|
@ -1364,7 +1352,7 @@ TW_INT16 CTWAINDS_FreeImage::enableDS(pTW_USERINTERFACE _pData)
|
|||
cerr << "ds: There was an error while trying to get scanner to acquire image" << endl;
|
||||
m_CurrentState = dsState_Open;
|
||||
setConditionCode(TWCC_SEQERROR);
|
||||
//FileTools::write_log("D:/1.txt","enableDS !StartScanning()");
|
||||
//FileTools::write_log("1.txt","enableDS !StartScanning()");
|
||||
return TWRC_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -1372,7 +1360,7 @@ TW_INT16 CTWAINDS_FreeImage::enableDS(pTW_USERINTERFACE _pData)
|
|||
{
|
||||
m_CurrentState = dsState_Open;
|
||||
setConditionCode(TWCC_SEQERROR);
|
||||
//FileTools::write_log("D:/1.txt","enableDS !DoXferReadyEvent()");
|
||||
//FileTools::write_log("1.txt", "~CTWAINDS_FreeImage DoXferReadyEvent dsState_Open != m_CurrentState");
|
||||
return TWRC_FAILURE;
|
||||
}
|
||||
}
|
||||
|
@ -1428,15 +1416,11 @@ TW_INT16 CTWAINDS_FreeImage::disableDS(pTW_USERINTERFACE _pData)
|
|||
{
|
||||
if (dsState_Enabled != m_CurrentState)
|
||||
{
|
||||
//FileTools::write_log("D:/1.txt"," disableDS dsState_Enabled != m_CurrentState");
|
||||
//FileTools::write_log("1.txt", "~CTWAINDS_FreeImage disableDS dsState_Open != m_CurrentState");
|
||||
setConditionCode(TWCC_SEQERROR);
|
||||
return TWRC_FAILURE;
|
||||
}
|
||||
//if (!isDestroyed)
|
||||
//{
|
||||
m_pGUI->DestroyTWAINGUI();
|
||||
// isDestroyed=true;
|
||||
//}
|
||||
m_pGUI->DestroyTWAINGUI();
|
||||
|
||||
|
||||
// allow the scanners caps to be writeable again because we are moving back
|
||||
|
@ -1448,7 +1432,7 @@ TW_INT16 CTWAINDS_FreeImage::disableDS(pTW_USERINTERFACE _pData)
|
|||
// There is no UI in this text interface so there is nothing
|
||||
// to do here.
|
||||
m_CurrentState = dsState_Open;
|
||||
XdPrint(" disableDS !\n");
|
||||
//FileTools::write_log("1.txt", "~CTWAINDS_FreeImage disableDS m_CurrentState = dsState_Open");
|
||||
return TWRC_SUCCESS;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1575,34 +1559,31 @@ TW_INT16 CTWAINDS_FreeImage::processEvent(pTW_EVENT _pEvent)
|
|||
TW_INT16 CTWAINDS_FreeImage::transfer()
|
||||
{
|
||||
TW_INT16 twrc = TWRC_SUCCESS;
|
||||
//if (bIndicators)
|
||||
//{
|
||||
// m_pGUI->UpdateProgress(true,' ',0,"");
|
||||
//}
|
||||
|
||||
getImageInfo(&m_ImageInfo);
|
||||
if (m_bCanceled)
|
||||
{
|
||||
m_bCanceled = false;
|
||||
return TWRC_CANCEL;
|
||||
}
|
||||
//if (m_bCanceled)
|
||||
//{
|
||||
// m_bCanceled = false;
|
||||
// return TWRC_CANCEL;
|
||||
//}
|
||||
if (dsState_XferReady != m_CurrentState)
|
||||
{
|
||||
setConditionCode(TWCC_SEQERROR);
|
||||
return TWRC_FAILURE;
|
||||
}
|
||||
m_nDestScanLine = 0;
|
||||
static int xfer=0;
|
||||
//static int xfer = 0;
|
||||
|
||||
//This is for know image size.
|
||||
if (m_ImageInfo.ImageWidth > 0 && m_ImageInfo.ImageLength > 0)
|
||||
{
|
||||
//DWORD nDestBytesPerRow = BYTES_PERLINE(m_ImageInfo.ImageWidth, m_ImageInfo.BitsPerPixel);
|
||||
//DWORD nImageSize = nDestBytesPerRow * m_ImageInfo.ImageLength;
|
||||
//DWORD nDestBytesPerRow = BYTES_PERLINE(m_ImageInfo.ImageWidth, m_ImageInfo.BitsPerPixel);
|
||||
//DWORD nImageSize = nDestBytesPerRow * m_ImageInfo.ImageLength;
|
||||
|
||||
DWORD nDestBytesPerRow = BYTES_PERLINE(m_ImageInfo.ImageWidth, m_ImageInfo.BitsPerPixel);
|
||||
DWORD nDestBytesPerRow = BYTES_PERLINE(m_ImageInfo.ImageWidth, m_ImageInfo.BitsPerPixel);
|
||||
|
||||
//XdPrint("nDestBytesPerRow = %d, BitsPerPixel= %d , m_ImageInfo.ImageWidth = %d\n", nDestBytesPerRow, m_ImageInfo.BitsPerPixel, m_ImageInfo.ImageWidth);
|
||||
DWORD nImageSize = nDestBytesPerRow * m_ImageInfo.ImageLength;
|
||||
//XdPrint("nDestBytesPerRow = %d, BitsPerPixel= %d , m_ImageInfo.ImageWidth = %d\n", nDestBytesPerRow, m_ImageInfo.BitsPerPixel, m_ImageInfo.ImageWidth);
|
||||
DWORD nImageSize = nDestBytesPerRow * m_ImageInfo.ImageLength;
|
||||
//If we had a previous image then get rid of it.
|
||||
if (m_hImageData)
|
||||
{
|
||||
|
@ -1634,8 +1615,7 @@ TW_INT16 CTWAINDS_FreeImage::transfer()
|
|||
pImageData += dwReceived;
|
||||
|
||||
nImageSize -= dwReceived;
|
||||
}
|
||||
while (nImageSize > 0 && twrc == TWRC_SUCCESS);
|
||||
} while (nImageSize > 0 && twrc == TWRC_SUCCESS);
|
||||
|
||||
_DSM_UnlockMemory(m_hImageData);
|
||||
}
|
||||
|
@ -1658,10 +1638,6 @@ TW_INT16 CTWAINDS_FreeImage::transfer()
|
|||
//////////////////////////////////////////////////////////////////////////////
|
||||
TW_INT16 CTWAINDS_FreeImage::endXfer(pTW_PENDINGXFERS _pXfers)
|
||||
{
|
||||
//static int aa=0;
|
||||
//XdPrint("inter times %d\n",aa);
|
||||
//aa++;
|
||||
//FileTools::write_log("D:/1.txt"," 1");
|
||||
TW_INT16 twrc = TWRC_SUCCESS;
|
||||
if (!(dsState_XferReady == m_CurrentState ||
|
||||
dsState_Xferring == m_CurrentState))
|
||||
|
@ -1674,20 +1650,18 @@ TW_INT16 CTWAINDS_FreeImage::endXfer(pTW_PENDINGXFERS _pXfers)
|
|||
--m_Xfers.Count;
|
||||
}
|
||||
|
||||
bool rs=m_Scanner.isImageQueueEmpty();
|
||||
//XdPrint("empty %d \n",rs==true?1:0);
|
||||
bool rs = m_Scanner.isImageQueueEmpty();
|
||||
if (rs)
|
||||
{
|
||||
m_Xfers.Count = 0;
|
||||
//FileTools::write_log("D:/1.txt"," rs: m_Xfers.Count==0");
|
||||
}
|
||||
|
||||
if (m_bCanceled)
|
||||
{
|
||||
m_bCanceled = false;
|
||||
m_Xfers.Count = 0;
|
||||
//FileTools::write_log("D:/1.txt"," m_bCanceled: m_Xfers.Count==0");
|
||||
XdPrint("m_Scanner.isImageQueueEmpty() \n");
|
||||
}
|
||||
|
||||
//if (m_bCanceled)
|
||||
//{
|
||||
// m_bCanceled = false;
|
||||
// m_Xfers.Count = 0;
|
||||
//}
|
||||
if (0 != m_Xfers.Count)
|
||||
{
|
||||
// Check to see if autofeed is turned on if so automaticly go get next image.
|
||||
|
@ -1703,15 +1677,7 @@ TW_INT16 CTWAINDS_FreeImage::endXfer(pTW_PENDINGXFERS _pXfers)
|
|||
// image in pre-emption of the app asking for it
|
||||
if (!m_Scanner.acquireImage(false))
|
||||
{
|
||||
if (m_Scanner.isImageQueueEmpty())
|
||||
{
|
||||
m_Xfers.Count = 0;
|
||||
//MessageBox(NULL,"_pXfers ==0 ","1",MB_OK);
|
||||
//FileTools::write_log("D:/1.txt"," (m_Scanner.isImageQueueEmpty: m_Xfers.Count==0");
|
||||
//cerr << "ds: There was an error while prepping the image for scanning" << endl;
|
||||
//setConditionCode(TWCC_BUMMER);
|
||||
//twrc = TWRC_FAILURE;
|
||||
}
|
||||
m_Xfers.Count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1739,7 +1705,7 @@ TW_INT16 CTWAINDS_FreeImage::endXfer(pTW_PENDINGXFERS _pXfers)
|
|||
if (bIndicators)
|
||||
{
|
||||
//FileTools::write_log("D:/1.txt"," (bIndicators: HIDDEN");
|
||||
m_pGUI->UpdateProgress(false,'0',0,"0");
|
||||
m_pGUI->UpdateProgress(false, '0', 0, "0");
|
||||
}
|
||||
}
|
||||
return twrc;
|
||||
|
@ -1759,7 +1725,7 @@ TW_INT16 CTWAINDS_FreeImage::getXfer(pTW_PENDINGXFERS _pXfers)
|
|||
if (_pXfers == 0)
|
||||
{
|
||||
setConditionCode(TWCC_BADVALUE);
|
||||
// Did everyting but return the currect count.
|
||||
//FileTools::write_log("1.txt", "getXfer _pXfers == 0");
|
||||
return TWRC_CHECKSTATUS;
|
||||
}
|
||||
|
||||
|
@ -1790,7 +1756,8 @@ TW_INT16 CTWAINDS_FreeImage::resetXfer(pTW_PENDINGXFERS _pXfers)
|
|||
|
||||
*_pXfers = m_Xfers;
|
||||
|
||||
m_Scanner.StopScan();//扫描仪停止并清空图像队列
|
||||
m_Scanner.StopScan();//扫描仪停止
|
||||
m_Scanner.resetScanner();//清空原图队列与已处理的图像队列
|
||||
return twrc;
|
||||
}
|
||||
|
||||
|
@ -1814,7 +1781,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pnCap->SetCurrent(pConfig.Pixtype);
|
||||
bret = pnCap->SetCurrent(pConfig.Pixtype);
|
||||
}
|
||||
|
||||
if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_SUPPORTEDSIZES))))
|
||||
|
@ -1824,7 +1791,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pnCap->SetCurrent(pConfig.PaperSize);
|
||||
bret = pnCap->SetCurrent(pConfig.PaperSize);
|
||||
}
|
||||
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(CAP_DUPLEXENABLED))))
|
||||
|
@ -1834,7 +1801,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->SetCurrent(pConfig.Duplex==0? FALSE:TRUE);
|
||||
bret = pbCap->SetCurrent(pConfig.Duplex == 0 ? FALSE : TRUE);
|
||||
}
|
||||
|
||||
if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_ORIENTATION))))
|
||||
|
@ -1844,7 +1811,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pnCap->SetCurrent(pConfig.Orentation==4?TWOR_AUTOTEXT:pConfig.Orentation);
|
||||
bret = pnCap->SetCurrent(pConfig.Orentation == 4 ? TWOR_AUTOTEXT : pConfig.Orentation);
|
||||
}
|
||||
|
||||
if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_FILTER))))
|
||||
|
@ -1854,7 +1821,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pnCap->SetCurrent(pConfig.Filter);
|
||||
bret = pnCap->SetCurrent(pConfig.Filter);
|
||||
}
|
||||
|
||||
if (0 == (pfCap = dynamic_cast<CTWAINContainerFix32*>(findCapability(ICAP_XRESOLUTION))))
|
||||
|
@ -1865,7 +1832,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
else
|
||||
{
|
||||
//pfCap->SetCurrent(pConfig->wDPI);
|
||||
bret=pfCap->SetCurrent((float)pConfig.Resolution);
|
||||
bret = pfCap->SetCurrent((float)pConfig.Resolution);
|
||||
}
|
||||
|
||||
// Y resolution the same.
|
||||
|
@ -1877,7 +1844,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
else
|
||||
{
|
||||
//pfCap->SetCurrent(pConfig->wDPI);
|
||||
bret=pfCap->SetCurrent(pConfig.Resolution);
|
||||
bret = pfCap->SetCurrent(pConfig.Resolution);
|
||||
}
|
||||
|
||||
if (0 == (pfRCap = dynamic_cast<CTWAINContainerFix32Range*>(findCapability(ICAP_CONTRAST))))
|
||||
|
@ -1887,8 +1854,8 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
}
|
||||
else
|
||||
{
|
||||
float value_Contrast=GetContrast(pConfig.Contrast);
|
||||
bret=pfRCap->SetCurrent(value_Contrast);
|
||||
float value_Contrast = GetContrast(pConfig.Contrast);
|
||||
bret = pfRCap->SetCurrent(value_Contrast);
|
||||
}
|
||||
|
||||
if (0 == (pfRCap = dynamic_cast<CTWAINContainerFix32Range*>(findCapability(ICAP_BRIGHTNESS))))
|
||||
|
@ -1898,7 +1865,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pfRCap->SetCurrent(pConfig.Brightness);
|
||||
bret = pfRCap->SetCurrent(pConfig.Brightness);
|
||||
}
|
||||
// Y resolution the same.
|
||||
if (0 == (pfRCap = dynamic_cast<CTWAINContainerFix32Range*>(findCapability(ICAP_GAMMA))))
|
||||
|
@ -1908,32 +1875,32 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pfRCap->SetCurrent(pConfig.Gamma/10.0);
|
||||
bret = pfRCap->SetCurrent(pConfig.Gamma / 10.0);
|
||||
}
|
||||
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(ICAP_AUTOMATICCROPUSESFRAME))))
|
||||
{
|
||||
cerr << "Could not get ICAP_AUTOMATICCROPUSESFRAME" << endl;
|
||||
bret=bret = false;
|
||||
bret = bret = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool temp = (pConfig.PaperSize) == 90;
|
||||
bret=pbCap->SetCurrent(temp);
|
||||
bret = pbCap->SetCurrent(temp);
|
||||
|
||||
}
|
||||
|
||||
//填充黑框
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8004))))
|
||||
{
|
||||
{
|
||||
cerr << "Could not get ICAP_AUTOMATICCROPUSESFRAME" << endl;
|
||||
bret = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->SetCurrent(pConfig.EnFillBlack);
|
||||
{
|
||||
bret = pbCap->SetCurrent(pConfig.EnFillBlack);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(ICAP_AUTODISCARDBLANKPAGES))))
|
||||
{
|
||||
|
@ -1943,7 +1910,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
else
|
||||
{
|
||||
bool temp = (pConfig.Duplex) == 2;
|
||||
bret=pbCap->SetCurrent(temp);
|
||||
bret = pbCap->SetCurrent(temp);
|
||||
}
|
||||
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8091))))
|
||||
|
@ -1954,7 +1921,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
else
|
||||
{
|
||||
bool temp = (pConfig.Duplex) == 3;
|
||||
bret=pbCap->SetCurrent(temp);
|
||||
bret = pbCap->SetCurrent(temp);
|
||||
}
|
||||
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(ICAP_AUTOMATICDESKEW))))
|
||||
|
@ -1964,7 +1931,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->SetCurrent(pConfig.EnAutoDescrew);
|
||||
bret = pbCap->SetCurrent(pConfig.EnAutoDescrew);
|
||||
}
|
||||
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8005))))//背面旋转180
|
||||
|
@ -1974,7 +1941,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->SetCurrent(pConfig.EnBackRotate180);
|
||||
bret = pbCap->SetCurrent(pConfig.EnBackRotate180);
|
||||
}
|
||||
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8006))))//歪斜检测
|
||||
|
@ -1984,17 +1951,17 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->SetCurrent(pConfig.EnScrewDetect);
|
||||
bret = pbCap->SetCurrent(pConfig.EnScrewDetect);
|
||||
}
|
||||
|
||||
if (0==(pbCap=dynamic_cast<CTWAINContainerBool*>(findCapability((CAP_DOUBLEFEEDDETECTION)))))
|
||||
{
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability((CAP_DOUBLEFEEDDETECTION)))))
|
||||
{
|
||||
cerr << "Could not get CAP_DOUBLEFEEDDETECTION" << endl;
|
||||
bret = false;
|
||||
bret = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->SetCurrent(pConfig.EnUltrasonicDetect);
|
||||
bret = pbCap->SetCurrent(pConfig.EnUltrasonicDetect);
|
||||
}
|
||||
|
||||
//歪斜检测等级
|
||||
|
@ -2005,7 +1972,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pfRCap->SetCurrent(pConfig.ScrewDetectLevel);
|
||||
bret = pfRCap->SetCurrent(pConfig.ScrewDetectLevel);
|
||||
}
|
||||
|
||||
//装订检测
|
||||
|
@ -2016,35 +1983,35 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->SetCurrent(pConfig.EnBindingDetect);
|
||||
bret = pbCap->SetCurrent(pConfig.EnBindingDetect);
|
||||
}
|
||||
|
||||
//扫描张数
|
||||
if (0==(pnCap=dynamic_cast<CTWAINContainerInt*>(findCapability(CAP_XFERCOUNT))))
|
||||
if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(CAP_XFERCOUNT))))
|
||||
{
|
||||
//XdPrint("updateScannerFromCaps CAP_XFERCOUNT Error");
|
||||
bret = false;
|
||||
bret = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bret=pnCap->SetCurrent(pConfig.ScanCount);
|
||||
bret = pnCap->SetCurrent(pConfig.ScanCount);
|
||||
}
|
||||
|
||||
//去除穿孔
|
||||
if (0==(pbCap=dynamic_cast<CTWAINContainerBool*>(findCapability(0x8018))))
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8018))))
|
||||
{
|
||||
bret = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
pbCap->SetCurrent(pConfig.EnOutHole?true:false);
|
||||
int aa=2;
|
||||
pbCap->SetCurrent(pConfig.EnOutHole ? true : false);
|
||||
//int aa=2;
|
||||
}
|
||||
|
||||
//去除穿孔占幅面比例
|
||||
if (0==(pfRCap=dynamic_cast<CTWAINContainerFix32Range*>(findCapability(0x8092))))
|
||||
if (0 == (pfRCap = dynamic_cast<CTWAINContainerFix32Range*>(findCapability(0x8092))))
|
||||
{
|
||||
bret=false;
|
||||
bret = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2052,7 +2019,7 @@ bool CTWAINDS_FreeImage::UpdateCapsFromConfig(CONFIGPARAMS pConfig)
|
|||
}
|
||||
|
||||
//多流除红
|
||||
if (0==(pbCap=dynamic_cast<CTWAINContainerBool*>(findCapability(0x8026))))
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8026))))
|
||||
{
|
||||
bret = false;
|
||||
}
|
||||
|
@ -2079,6 +2046,11 @@ bool CTWAINDS_FreeImage::IsImageQueueEmpty()
|
|||
return m_Scanner.isImageQueueEmpty();
|
||||
}
|
||||
|
||||
bool CTWAINDS_FreeImage::StillRemainImages()
|
||||
{
|
||||
return m_Scanner.stillhaveImage();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
||||
{
|
||||
|
@ -2106,10 +2078,10 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pnCap->GetCurrent(nVal);
|
||||
bret = pnCap->GetCurrent(nVal);
|
||||
settings->m_nPixelType = nVal;
|
||||
|
||||
if (nVal==2)
|
||||
if (nVal == 2)
|
||||
{
|
||||
settings->m_HardWareParams.PixType = TWPT_RGB;
|
||||
}
|
||||
|
@ -2126,7 +2098,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pnCap->GetCurrent(nVal);
|
||||
bret = pnCap->GetCurrent(nVal);
|
||||
settings->m_HardWareParams.PaperType = nVal;
|
||||
}
|
||||
|
||||
|
@ -2137,20 +2109,20 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->GetCurrent(bVal);
|
||||
bret = pbCap->GetCurrent(bVal);
|
||||
settings->m_bDuplex = bVal;
|
||||
}
|
||||
|
||||
if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_ORIENTATION))))
|
||||
{
|
||||
{
|
||||
cerr << "Could not get ICAP_PIXELTYPE" << endl;
|
||||
bret = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bret=pnCap->GetCurrent(nVal);
|
||||
settings->m_wRotation = nVal==TWOR_AUTOTEXT?4:nVal;;
|
||||
}
|
||||
{
|
||||
bret = pnCap->GetCurrent(nVal);
|
||||
settings->m_wRotation = nVal == TWOR_AUTOTEXT ? 4 : nVal;;
|
||||
}
|
||||
|
||||
if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(ICAP_FILTER))))
|
||||
{
|
||||
|
@ -2159,11 +2131,11 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pnCap->GetCurrent(nVal);
|
||||
bret = pnCap->GetCurrent(nVal);
|
||||
settings->m_nFilter = nVal;
|
||||
if (nVal!=0)
|
||||
if (nVal != 0)
|
||||
{
|
||||
m_Scanner.m_HardWareParams.PixType=TWPT_RGB;
|
||||
m_Scanner.m_HardWareParams.PixType = TWPT_RGB;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2175,7 +2147,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pfCap->GetCurrent(fVal);
|
||||
bret = pfCap->GetCurrent(fVal);
|
||||
settings->m_fXResolution = fVal;
|
||||
settings->m_HardWareParams.Resolution = 200;
|
||||
}
|
||||
|
@ -2188,7 +2160,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pfCap->GetCurrent(fVal);
|
||||
bret = pfCap->GetCurrent(fVal);
|
||||
settings->m_fYResolution = fVal;
|
||||
}
|
||||
|
||||
|
@ -2199,7 +2171,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pfRCap->GetCurrent(fVal);
|
||||
bret = pfRCap->GetCurrent(fVal);
|
||||
settings->m_fContrast = fVal;
|
||||
}
|
||||
|
||||
|
@ -2210,7 +2182,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pfRCap->GetCurrent(fVal);
|
||||
bret = pfRCap->GetCurrent(fVal);
|
||||
settings->m_fBrightness = fVal;
|
||||
}
|
||||
// Y resolution the same.
|
||||
|
@ -2221,7 +2193,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pfRCap->GetCurrent(fVal);
|
||||
bret = pfRCap->GetCurrent(fVal);
|
||||
settings->m_fGamma = fVal;
|
||||
}
|
||||
|
||||
|
@ -2232,7 +2204,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->GetCurrent(bVal);
|
||||
bret = pbCap->GetCurrent(bVal);
|
||||
settings->m_bAutoCrop = bVal;
|
||||
}
|
||||
|
||||
|
@ -2244,9 +2216,9 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->GetCurrent(bVal);
|
||||
settings->m_bFillBlackRect=bVal;
|
||||
}
|
||||
bret = pbCap->GetCurrent(bVal);
|
||||
settings->m_bFillBlackRect = bVal;
|
||||
}
|
||||
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(ICAP_AUTODISCARDBLANKPAGES))))
|
||||
{
|
||||
|
@ -2255,7 +2227,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->GetCurrent(bVal);
|
||||
bret = pbCap->GetCurrent(bVal);
|
||||
settings->m_bAutoDiscardBlank = bVal;
|
||||
}
|
||||
|
||||
|
@ -2267,30 +2239,30 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->GetCurrent(bVal);
|
||||
bret = pbCap->GetCurrent(bVal);
|
||||
settings->m_bAutoDiscardBlankInvoice = bVal;
|
||||
}
|
||||
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(ICAP_AUTOMATICDESKEW))))
|
||||
{
|
||||
{
|
||||
cerr << "Could not get ICAP_AUTOMATICDESKEW" << endl;
|
||||
bret = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->GetCurrent(bVal);
|
||||
{
|
||||
bret = pbCap->GetCurrent(bVal);
|
||||
settings->m_bAutoDeskew = bVal;
|
||||
}
|
||||
}
|
||||
|
||||
if (0==(pbCap=dynamic_cast<CTWAINContainerBool*>(findCapability(CAP_DOUBLEFEEDDETECTION))))
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(CAP_DOUBLEFEEDDETECTION))))
|
||||
{
|
||||
cerr << "Could not get CAP_DOUBLEFEEDDETECTION" << endl;
|
||||
bret = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bret= pbCap->GetCurrent(bVal);
|
||||
settings->m_HardWareParams.DoubleFeederOn=bVal;
|
||||
bret = pbCap->GetCurrent(bVal);
|
||||
settings->m_HardWareParams.DoubleFeederOn = bVal;
|
||||
}
|
||||
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8005))))//背面旋转180
|
||||
|
@ -2300,7 +2272,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->GetCurrent(bVal);
|
||||
bret = pbCap->GetCurrent(bVal);
|
||||
settings->m_bBackRotate180 = bVal;
|
||||
}
|
||||
|
||||
|
@ -2311,7 +2283,7 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->GetCurrent(bVal);
|
||||
bret = pbCap->GetCurrent(bVal);
|
||||
settings->m_HardWareParams.SkrewDetectOn = bVal;
|
||||
}
|
||||
|
||||
|
@ -2323,8 +2295,8 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pfRCap->GetCurrent(fVal);
|
||||
settings->m_HardWareParams.SkrewDetectLevel= fVal;
|
||||
bret = pfRCap->GetCurrent(fVal);
|
||||
settings->m_HardWareParams.SkrewDetectLevel = fVal;
|
||||
}
|
||||
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8090))))//装订检测
|
||||
|
@ -2334,60 +2306,65 @@ bool CTWAINDS_FreeImage::updateScannerFromCaps()
|
|||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->GetCurrent(bVal);
|
||||
bret = pbCap->GetCurrent(bVal);
|
||||
settings->m_HardWareParams.StapleDetectOn = bVal;
|
||||
}
|
||||
|
||||
if (0==(pnCap=dynamic_cast<CTWAINContainerInt*>(findCapability(CAP_XFERCOUNT))))
|
||||
if (0 == (pnCap = dynamic_cast<CTWAINContainerInt*>(findCapability(CAP_XFERCOUNT))))
|
||||
{
|
||||
//XdPrint("updateScannerFromCaps CAP_XFERCOUNT Error");
|
||||
}
|
||||
else
|
||||
{
|
||||
bret=pnCap->GetCurrent(nVal);
|
||||
m_Xfers.Count=nVal;
|
||||
bool bVal=settings->m_bDuplex;
|
||||
//settings->m_wScanCount = 0;
|
||||
settings->m_wScanCount = bVal?nVal/2:nVal;
|
||||
//XdPrint("updateScannerFromCaps CAP_XFERCOUNT :%d \n", settings->m_wScanCount);
|
||||
bret = pnCap->GetCurrent(nVal);
|
||||
//m_Xfers.Count=nVal;
|
||||
bool bVal = settings->m_bDuplex;
|
||||
if (nVal == -1)
|
||||
settings->m_wScanCount = nVal;
|
||||
else
|
||||
{
|
||||
if (settings->m_bMultiOutput)
|
||||
nVal /= 2;
|
||||
settings->m_wScanCount = bVal ? nVal / 2 : nVal;
|
||||
}
|
||||
}
|
||||
|
||||
//去除穿孔
|
||||
if (0==(pbCap=dynamic_cast<CTWAINContainerBool*>(findCapability(0x8018))))
|
||||
{
|
||||
bret=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->GetCurrent(bVal);
|
||||
settings->m_OutHole.EnOutHole=bVal;
|
||||
if (bVal)
|
||||
{
|
||||
settings->m_bDuplex=true;
|
||||
}
|
||||
}
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8018))))
|
||||
{
|
||||
bret = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bret = pbCap->GetCurrent(bVal);
|
||||
settings->m_OutHole.EnOutHole = bVal;
|
||||
//if (bVal)
|
||||
//{
|
||||
// settings->m_bDuplex=true;
|
||||
//}
|
||||
}
|
||||
|
||||
//去除穿孔占幅面比例
|
||||
if (0==(pfRCap=dynamic_cast<CTWAINContainerFix32Range*>(findCapability(0x8092))))
|
||||
{
|
||||
bret=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
pfRCap->GetCurrent(fVal);
|
||||
settings->m_OutHole.OutHoleRatio=(int)fVal;
|
||||
}
|
||||
//去除穿孔占幅面比例
|
||||
if (0 == (pfRCap = dynamic_cast<CTWAINContainerFix32Range*>(findCapability(0x8092))))
|
||||
{
|
||||
bret = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
pfRCap->GetCurrent(fVal);
|
||||
settings->m_OutHole.OutHoleRatio = (int)fVal;
|
||||
}
|
||||
|
||||
//多流除红
|
||||
if (0==(pbCap=dynamic_cast<CTWAINContainerBool*>(findCapability(0x8026))))
|
||||
{
|
||||
bret=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bret=pbCap->GetCurrent(bVal);
|
||||
settings->m_bMultiOutput=bVal;
|
||||
}
|
||||
//多流除红
|
||||
if (0 == (pbCap = dynamic_cast<CTWAINContainerBool*>(findCapability(0x8026))))
|
||||
{
|
||||
bret = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bret = pbCap->GetCurrent(bVal);
|
||||
settings->m_bMultiOutput = bVal;
|
||||
}
|
||||
return bret;
|
||||
}
|
||||
|
||||
|
@ -2691,7 +2668,7 @@ TW_INT16 CTWAINDS_FreeImage::dat_extimageinfo(TW_UINT16 _MSG, pTW_EXTIMAGEINFO _
|
|||
//_pData->Info->
|
||||
//_pData->Info=info;
|
||||
//return TWRC_SUCCESS;
|
||||
|
||||
|
||||
setConditionCode(TWCC_CAPUNSUPPORTED);
|
||||
return TWRC_SUCCESS;
|
||||
}
|
||||
|
@ -2811,21 +2788,20 @@ bool CTWAINDS_FreeImage::StartScanning(bool showUI)
|
|||
// Update the scanner with the latest negotiated caps
|
||||
if (!updateScannerFromCaps())
|
||||
{
|
||||
//XdPrint("Update updateScannerFromCaps() Error");
|
||||
//FileTools::write_log("1.txt", "StartScanning() !updateScannerFromCaps()");
|
||||
setConditionCode(TWCC_BADVALUE);
|
||||
return false;
|
||||
}
|
||||
if (bIndicators)
|
||||
{
|
||||
m_pGUI->UpdateProgress(true,'0',0,"0");
|
||||
//indi.ShowWindow(SW_SHOWNORMAL);
|
||||
m_pGUI->UpdateProgress(true, '0', 0, "0");
|
||||
}
|
||||
bool ret=m_Scanner.acquireImage();
|
||||
bool ret = m_Scanner.acquireImage();
|
||||
if (bIndicators)
|
||||
{
|
||||
if (!ret)
|
||||
{
|
||||
m_pGUI->UpdateProgress(false,'0',0,"0");
|
||||
m_pGUI->UpdateProgress(false, '0', 0, "0");
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -2834,6 +2810,6 @@ bool CTWAINDS_FreeImage::StartScanning(bool showUI)
|
|||
|
||||
bool CTWAINDS_FreeImage::StopScanning()
|
||||
{
|
||||
m_bCanceled=true;
|
||||
return m_Scanner.StopScan();
|
||||
m_bCanceled = true;
|
||||
return m_Scanner.StopScan();
|
||||
}
|
|
@ -42,7 +42,7 @@
|
|||
#include "CTWAINDS_Base.h"
|
||||
#include "CScanner_FreeImage.h"
|
||||
#include "JsonConfig.h"
|
||||
//#include "IndicatorDlg.h"
|
||||
|
||||
|
||||
#define CUSTCAP_LONGDOCUMENT CAP_CUSTOMBASE+1
|
||||
#define CUSTCAP_DOCS_IN_ADF CAP_CUSTOMBASE+2
|
||||
|
@ -264,6 +264,7 @@ public:
|
|||
std::string GetSerialNum();
|
||||
std::string GetFWVerison();
|
||||
bool IsImageQueueEmpty();
|
||||
bool StillRemainImages();
|
||||
protected:
|
||||
CScanner_FreeImage m_Scanner; /**< The main scanner. */
|
||||
|
||||
|
@ -274,6 +275,5 @@ protected:
|
|||
CTWAIN_UI *m_pGUI; /**< This is the main MFC UI dialog */
|
||||
bool bIndicators;
|
||||
BOOL b_created;
|
||||
bool isDestroyed;
|
||||
};
|
||||
#endif // __CTWAINDS_FREEIMAGE_H__
|
Before Width: | Height: | Size: 96 KiB After Width: | Height: | Size: 96 KiB |
|
@ -2,7 +2,6 @@
|
|||
#include "ImageAdjustColors.h"
|
||||
|
||||
|
||||
|
||||
CImageAdjustColors::CImageAdjustColors(void)
|
||||
{
|
||||
lut.create(1, 256, CV_8UC1);
|
||||
|
@ -25,7 +24,9 @@ void CImageAdjustColors::apply(cv::Mat& pDib,int side)
|
|||
if (m_fBrightness != 0|| m_fContrast != 0|| m_fGamma != 1.0)
|
||||
{
|
||||
//MessageBox(NULL,"Inter","Error",MB_OK);
|
||||
//FileTools::write_log("D:\\1.txt", "Enter CImageAdjustColors apply");
|
||||
cv::LUT(pDib, lut, pDib);
|
||||
//FileTools::write_log("D:\\1.txt", "Exit CImageAdjustColors apply");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,6 +37,33 @@ void CImageAdjustColors::setAdjustColors(float fBrightness, float fContrast, flo
|
|||
m_fGamma = fGamma;
|
||||
updata();
|
||||
}
|
||||
int CImageAdjustColors::getContrast()
|
||||
{
|
||||
return m_fContrast;
|
||||
}
|
||||
int CImageAdjustColors::getBrightness()
|
||||
{
|
||||
return m_fBrightness;
|
||||
}
|
||||
double CImageAdjustColors::getGamma()
|
||||
{
|
||||
return m_fGamma;
|
||||
}
|
||||
void CImageAdjustColors::setContrast(int contrast)
|
||||
{
|
||||
m_fContrast = cv::max(-127, cv::min(contrast, 127));
|
||||
updata();
|
||||
}
|
||||
void CImageAdjustColors::setBrightness(int brightness)
|
||||
{
|
||||
m_fBrightness = cv::max(-255, cv::min(brightness, 255));
|
||||
updata();
|
||||
}
|
||||
void CImageAdjustColors::setGamma(double gamma)
|
||||
{
|
||||
m_fGamma = cv::max(0.1, cv::min(gamma, 5.0));
|
||||
updata();
|
||||
}
|
||||
void CImageAdjustColors::MapToMap(byte* mapsIn, byte* mapsOut)
|
||||
{
|
||||
for (int i = 0; i < 256; i++)
|
|
@ -12,6 +12,18 @@ public:
|
|||
|
||||
void setAdjustColors(float fBrightness, float fContrast, float fGamma);
|
||||
|
||||
int getContrast();
|
||||
|
||||
int getBrightness();
|
||||
|
||||
double getGamma();
|
||||
|
||||
void setContrast(int contrast);
|
||||
|
||||
void setBrightness(int brightness);
|
||||
|
||||
void setGamma(double gamma);
|
||||
|
||||
private:
|
||||
class Range
|
||||
{
|
|
@ -1,10 +1,8 @@
|
|||
#pragma once
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
//class twainImage;
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "filetools.h"
|
||||
|
||||
class CImageApply
|
||||
{
|
|
@ -21,6 +21,11 @@ cv::Size CImageApplyCrop::getSize()
|
|||
return m_size;
|
||||
}
|
||||
|
||||
cv::Point CImageApplyCrop::getOrg()
|
||||
{
|
||||
return m_org;
|
||||
}
|
||||
|
||||
void CImageApplyCrop::setSize(cv::Size size)
|
||||
{
|
||||
m_size=size;
|
|
@ -14,11 +14,12 @@ CImageApplyResize::~CImageApplyResize(void)
|
|||
|
||||
void CImageApplyResize::apply(cv::Mat& pDib,int side)
|
||||
{
|
||||
//imwrite("o.bmp",pDib);
|
||||
//FileTools::write_log("D:\\1.txt", "Enter CImageApplyResize apply");
|
||||
if(autoCut)
|
||||
{
|
||||
if (m_dpi != m_orgDpi)
|
||||
{
|
||||
//FileTools::write_log("D:\\1.txt", "Exit CImageApplyResize autoCut m_dpi != m_orgDpi apply");
|
||||
float ratio = m_dpi / m_orgDpi;
|
||||
cv::resize(pDib, pDib, cv::Size(0, 0), ratio, ratio);
|
||||
//XdPrint("1");
|
||||
|
@ -29,6 +30,7 @@ void CImageApplyResize::apply(cv::Mat& pDib,int side)
|
|||
cv::Size dst(dstSize.cx,dstSize.cy);
|
||||
cv::resize(pDib,pDib,dst,0,0);
|
||||
}
|
||||
//FileTools::write_log("D:\\1.txt", "Exit CImageApplyResize apply");
|
||||
}
|
||||
|
||||
float CImageApplyResize::getDpi()
|
|
@ -25,6 +25,7 @@ CImageChannel::~CImageChannel(void)
|
|||
|
||||
void CImageChannel::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())
|
||||
|
@ -37,14 +38,16 @@ void CImageChannel::apply(cv::Mat& pDib,int side)
|
|||
//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 CImageChannel::setCH(int channel)
|
|
@ -0,0 +1,231 @@
|
|||
#include "StdAfx.h"
|
||||
#include "ImageMatQueue.h"
|
||||
#include "PublicFunc.h"
|
||||
#include "filetools.h"
|
||||
#include "ImageOutHole.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),
|
||||
can_multi_outputR(false)
|
||||
{
|
||||
m_threadProc = NULL;
|
||||
at_prced_image_remains = 0;
|
||||
atm_orgin_image_remains = 0;
|
||||
}
|
||||
|
||||
void ImageMatQueue::run()
|
||||
{
|
||||
if (m_threadProc)
|
||||
{
|
||||
bRun = false;
|
||||
at_prced_image_remains = 0;
|
||||
atm_orgin_image_remains = 0;
|
||||
m_threadProc->join();
|
||||
delete m_threadProc;
|
||||
m_threadProc = NULL;
|
||||
}
|
||||
bRun = true;
|
||||
at_prced_image_remains = 0;
|
||||
atm_orgin_image_remains = 0;
|
||||
m_threadProc = new thread(&ImageMatQueue::proc, this);
|
||||
}
|
||||
|
||||
ImageMatQueue::~ImageMatQueue(void)
|
||||
{
|
||||
if (m_threadProc)
|
||||
{
|
||||
bRun = false;
|
||||
at_prced_image_remains = 0;
|
||||
atm_orgin_image_remains = 0;
|
||||
m_threadProc->join();
|
||||
delete m_threadProc;
|
||||
m_threadProc = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void ImageMatQueue::pushMat(JpegBuffer& data)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mtxJB);
|
||||
m_pImages.Put(data);
|
||||
atm_orgin_image_remains++;
|
||||
}
|
||||
|
||||
cv::Mat ImageMatQueue::popMat()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mtxJB);
|
||||
cv::Mat mat = _popMat();
|
||||
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 CImageProcDiscardBlank(param.m_bAutoDiscardBlank ? true : false)));
|
||||
}
|
||||
bool m_bAutoCrop = false;
|
||||
if (param.m_HardWareParams.PaperType == 90)
|
||||
m_bAutoCrop = true;
|
||||
|
||||
m_iaList.push_back(shared_ptr<CImageApply>(new CAutoCrop(param.m_bFillBlackRect, param.m_bAutoDeskew, param.m_bAutoCrop, papersize.GetPaperSize(param.m_HardWareParams.PaperType, param.m_fXResolution), papersize.GetPaperSize(param.m_HardWareParams.PaperType, 200.0), param.m_nPixelType)));
|
||||
|
||||
if (param.m_nFilter)
|
||||
{
|
||||
m_iaList.push_back(shared_ptr<CImageApply>(new CImageChannel(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 CImageAdjustColors(param.m_fBrightness, param.m_fContrast, param.m_fGamma)));
|
||||
}
|
||||
if (param.m_fXResolution != 200.0)
|
||||
{
|
||||
m_iaList.push_back(shared_ptr< CImageApply>(new CImageApplyResize(200.0, param.m_fXResolution, param.m_bAutoCrop, papersize.GetPaperSize(param.m_HardWareParams.PaperType, param.m_fXResolution))));
|
||||
}
|
||||
|
||||
if (param.m_wRotation != 0 || param.m_bBackRotate180)
|
||||
{
|
||||
m_iaList.push_back(shared_ptr<CImageApply>(new CImageRotation(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_Locker);
|
||||
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();
|
||||
delete m_threadProc;
|
||||
m_threadProc = NULL;
|
||||
iscanning = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ImageMatQueue::empty()
|
||||
{
|
||||
return ((atm_orgin_image_remains == 0 &&
|
||||
at_prced_image_remains == 0) && (!iscanning));
|
||||
}
|
||||
|
||||
void ImageMatQueue::proc()
|
||||
{
|
||||
while (bRun)
|
||||
{
|
||||
this_thread::sleep_for(chrono::milliseconds(5));
|
||||
{
|
||||
if (m_pImages.Size() != 0)//m_images.Size() == 0 &&
|
||||
{
|
||||
vector<cv::Mat> mats = m_pImages.Take().getMats();
|
||||
if (scanParam.m_OutHole.EnOutHole&& mats.size() == 2)//确保能够获取正反两面图
|
||||
{
|
||||
ImageOutHole outhole;
|
||||
if (!mats[0].empty() && !mats[1].empty())
|
||||
{
|
||||
outhole.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]);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
#pragma once
|
||||
//#include <boost\thread\win32\mfc_thread_init.hpp>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <opencv2\opencv.hpp>
|
||||
#include "JpegBuffer.h"
|
||||
#include <queue>
|
||||
#include "ImageApply.h"
|
||||
#include "PublicFunc.h"
|
||||
#include "BlockingQueue.h"
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
#include "PaperSize.h"
|
||||
#include "AutoCrop.h"
|
||||
#include "ImageAdjustColors.h"
|
||||
#include "ImageApplyResize.h"
|
||||
#include "ImageChannel.h"
|
||||
#include "ImageProcDiscardBlank.h"
|
||||
#include "ImageRotation.h"
|
||||
|
||||
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;
|
||||
thread* m_threadProc;
|
||||
volatile bool bRun;
|
||||
bool can_multi_outputR;
|
||||
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;
|
||||
};
|
||||
|
|
@ -6,6 +6,9 @@
|
|||
#include "opencv/cv.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
ImageOutHole::ImageOutHole(void)
|
||||
{
|
||||
}
|
||||
|
@ -18,6 +21,7 @@ ImageOutHole::~ImageOutHole(void)
|
|||
void ImageOutHole::puncture(Mat& front, Mat& back, double threshold, float edgeScale, double areaThreshold)
|
||||
{
|
||||
//¶þÖµ»¯Õý·´ÃæͼÏñ
|
||||
//FileTools::write_log("D:\\1.txt", "enter ImageOutHole apply");
|
||||
threshold = min(max(threshold, 1.0), 254.0);
|
||||
Mat front_thre = threshold_mat(front, threshold);
|
||||
Mat back_thre = threshold_mat(back, threshold);
|
||||
|
@ -93,6 +97,7 @@ void ImageOutHole::puncture(Mat& front, Mat& back, double threshold, float edgeS
|
|||
imwrite("111.jpg", front);
|
||||
imwrite("222.jpg", back);
|
||||
#endif
|
||||
//FileTools::write_log("D:\\1.txt", "Exit ImageOutHole apply");
|
||||
}
|
||||
|
||||
cv::Mat ImageOutHole::threshold_mat(const Mat& src, double threshold)
|
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
#include "ImageApply.h"
|
||||
#include <vector>
|
||||
|
||||
class ImageOutHole
|
||||
{
|
||||
public:
|
||||
ImageOutHole(void);
|
||||
~ImageOutHole(void);
|
||||
public:
|
||||
void puncture(cv::Mat& front, cv::Mat& back, double threshold, float edgeScale, double areaThreshold);
|
||||
private:
|
||||
cv::Mat threshold_mat(const cv::Mat& src, double threshold);
|
||||
void findContours22(const cv::Mat& src, std::vector<std::vector<cv::Point>>& contours, std::vector<cv::Vec4i>& hierarchy, int retr = cv::RETR_CCOMP, int method = cv::CHAIN_APPROX_SIMPLE, cv::Point offset = cv::Point(0, 0));
|
||||
std::vector<cv::Point> getMaxContour(const std::vector<std::vector<cv::Point>>& contours, const std::vector<cv::Vec4i>& hierarchy, int areaThreshold = 20000);
|
||||
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);
|
||||
cv::Point rotatedPoint(cv::Point p, cv::Point center, double angle);
|
||||
std::vector<cv::Point> getVertices(cv::RotatedRect rect);
|
||||
void filterPoly(const cv::Mat& mask, std::vector<std::vector<cv::Point>>& contours, cv::RotatedRect roi, float edgeScale, double areaThreshold);
|
||||
void fillPuncture(cv::Mat& src, const cv::Mat& mask, cv::Rect roi);
|
||||
};
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
#include "ImageProcDiscardBlank.h"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
int CImageProcDiscardBlank::ProcessRectR(Mat & image, RotatedRect & rotatedRect, vector<Point>& maxContour, double scale, double thresh, int blobAreaSize)
|
||||
{
|
||||
|
@ -34,7 +35,7 @@ int CImageProcDiscardBlank::ProcessRectR(Mat & image, RotatedRect & rotatedRect,
|
|||
Mat threshold_img;
|
||||
threshold(gray, threshold_img, thresh, 255.0, CV_THRESH_BINARY);
|
||||
vector<vector<Point>> contours;
|
||||
cv::vector<Vec4i> h1;
|
||||
std::vector<Vec4i> h1;
|
||||
GetContours(threshold_img, contours, h1, CV_CHAIN_APPROX_SIMPLE);
|
||||
threshold_img.release();
|
||||
|
||||
|
@ -184,6 +185,7 @@ cv::Mat CImageProcDiscardBlank::getRoiMat(cv::Mat& image)
|
|||
|
||||
void CImageProcDiscardBlank::apply(cv::Mat& pDib,int side)
|
||||
{
|
||||
//FileTools::write_log("D:\\1.txt", "enter CImageProcDiscardBlank apply");
|
||||
setIntensity(isNormalDiscard?8:20);
|
||||
setMinArea(isNormalDiscard?200:300);
|
||||
|
||||
|
@ -211,4 +213,5 @@ void CImageProcDiscardBlank::apply(cv::Mat& pDib,int side)
|
|||
m_res = true;
|
||||
if (m_res)
|
||||
pDib.release();
|
||||
//FileTools::write_log("D:\\1.txt", "exit CImageProcDiscardBlank apply");
|
||||
}
|
|
@ -1,10 +1,6 @@
|
|||
#pragma once
|
||||
#include "ImageApply.h"
|
||||
#include <math.h>
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include "opencv/cv.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
using namespace cv;
|
||||
|
||||
class CImageProcDiscardBlank :
|
||||
public CImageApply
|
||||
|
@ -18,9 +14,9 @@ public:
|
|||
private:
|
||||
void setIntensity(int val);
|
||||
void setMinArea(int val);
|
||||
int ProcessRectR(Mat & image, RotatedRect & rotatedRect, vector<Point>& maxContour, double scale, double thresh, int blobAreaSize);
|
||||
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 Mat& src, cv::vector<cv::vector<Point>>& contours, cv::vector<Vec4i>& hierarchy, int retr = RETR_CCOMP);
|
||||
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;
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
#include "StdAfx.h"
|
||||
#include "ImageRotation.h"
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
CImageRotation::CImageRotation(int index_of_orentation, bool m_bBackRotate) :m_nRotation(index_of_orentation), m_BackRotate(m_bBackRotate)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CImageRotation::~CImageRotation()
|
||||
{
|
||||
}
|
||||
|
||||
void CImageRotation::setRotationFlip(int flip)
|
||||
{
|
||||
m_nRotation = flip;
|
||||
}
|
||||
|
||||
int CImageRotation::getRotetion()
|
||||
{
|
||||
return m_nRotation;
|
||||
}
|
||||
|
||||
void CImageRotation::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");
|
||||
}
|
|
@ -6,7 +6,8 @@ class CImageRotation :
|
|||
public:
|
||||
CImageRotation(int index_of_orentation,bool m_bBackRotate=false);
|
||||
virtual ~CImageRotation();
|
||||
|
||||
void setRotationFlip(int flip);
|
||||
int getRotetion();
|
||||
// 通过 CImageApply 继承
|
||||
virtual void apply(cv::Mat & pDib,int side) override;
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
#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;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
#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;
|
||||
};
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#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;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#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;
|
||||
|
||||
};
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
#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;
|
||||
};
|
Binary file not shown.
|
@ -14,6 +14,21 @@ JpegBuffer::JpegBuffer(cv::Mat buffer, int color_type,int side,int mFilter)
|
|||
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)
|
||||
{
|
||||
|
@ -38,34 +53,24 @@ int JpegBuffer::getSize()
|
|||
|
||||
cv::Mat JpegBuffer::getMat( int pixType)
|
||||
{
|
||||
static int inddd = 0;
|
||||
JpegLib jl;
|
||||
cv::Mat image = jl.decode(m_buffer, pixType);
|
||||
//CString string;
|
||||
//string.Format("d:\\aa%d.jpg", inddd++ );
|
||||
//cv::imwrite(string.GetString(), image);
|
||||
//FileTools::write_log("D:/1.txt",)
|
||||
//StopWatch sw;
|
||||
//sw.start();
|
||||
//cv::InputArray arr(m_buffer);
|
||||
//
|
||||
//cv::Mat image=imdecode(arr,m_color_type==TWPT_RGB?CV_LOAD_IMAGE_COLOR:CV_LOAD_IMAGE_GRAYSCALE);
|
||||
//cv::imwrite("0.bmp",image);
|
||||
//sw.stop();
|
||||
//sw.time_run();
|
||||
//char str[256];
|
||||
//sprintf(str, "%lf", sw.time_run());
|
||||
//string res=str;
|
||||
//FileTools::write_log("D:/1.txt",res);
|
||||
//0 ÕýÃæ 1·´Ãæ
|
||||
//if (!backRotate&&(m_side==0||m_side==1))
|
||||
//{
|
||||
// cv::Rect rect(0, m_side == 0 ? 0 : gap, image.cols,(image.rows-gap));
|
||||
// image = image(rect);
|
||||
//}
|
||||
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;
|
|
@ -5,17 +5,22 @@
|
|||
class JpegBuffer
|
||||
{
|
||||
public:
|
||||
JpegBuffer(cv::Mat buffer,int color_type=2,int side=0,int mFilter=0);
|
||||
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();
|
||||
private:
|
||||
|
||||
cv::Mat m_buffer;
|
||||
std::vector<cv::Mat> matdatas;
|
||||
int m_color_type;
|
||||
int m_side;
|
||||
int m_mFilter;
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
#include "PublicFunc.h"
|
||||
#include <vector>
|
||||
#include <json.h>
|
||||
|
||||
using namespace std;
|
||||
|
|
@ -12,8 +12,8 @@ MFC_UI::MFC_UI(CTWAINDS_FreeImage *pDS)
|
|||
{
|
||||
m_pDlg = NULL;
|
||||
m_pChildWnd = NULL;
|
||||
indicator=NULL;
|
||||
indicatorCreated=false;
|
||||
indicator = NULL;
|
||||
indicatorCreated = false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,7 +24,7 @@ MFC_UI::~MFC_UI()
|
|||
|
||||
TW_INT16 MFC_UI::DisplayTWAINGUI(TW_USERINTERFACE Data, bool bSetup, bool bIndicators)
|
||||
{
|
||||
TW_INT16 ret=TWRC_SUCCESS;
|
||||
TW_INT16 ret = TWRC_SUCCESS;
|
||||
TW_INT16 nRes = CTWAIN_UI::DisplayTWAINGUI(Data, bSetup, bIndicators);
|
||||
if (nRes)
|
||||
{
|
||||
|
@ -42,9 +42,9 @@ TW_INT16 MFC_UI::DisplayTWAINGUI(TW_USERINTERFACE Data, bool bSetup, bool bIndic
|
|||
|
||||
if (Data.hParent)
|
||||
{
|
||||
if (m_pChildWnd==NULL)
|
||||
if (m_pChildWnd == NULL)
|
||||
{
|
||||
CDialog* dlg =new CDialog();
|
||||
CDialog* dlg = new CDialog();
|
||||
dlg->Create(IDD_DIALOGBACK);
|
||||
m_pChildWnd = dlg;
|
||||
theApp.m_pMainWnd = m_pChildWnd;
|
||||
|
@ -57,11 +57,11 @@ TW_INT16 MFC_UI::DisplayTWAINGUI(TW_USERINTERFACE Data, bool bSetup, bool bIndic
|
|||
}
|
||||
|
||||
if (Data.ShowUI)
|
||||
{
|
||||
if (m_pDlg==NULL)
|
||||
{
|
||||
if (m_pDlg == NULL)
|
||||
{
|
||||
m_pDlg = new TwainUIDlg(this, m_pChildWnd);
|
||||
m_pDlg->Create(IDD_DIALOG_TWAINUI, m_pChildWnd);
|
||||
m_pDlg->Create(IDD_DIALOG_TWAINUI, m_pChildWnd);
|
||||
}
|
||||
if (!bSetup)
|
||||
{
|
||||
|
@ -76,23 +76,22 @@ TW_INT16 MFC_UI::DisplayTWAINGUI(TW_USERINTERFACE Data, bool bSetup, bool bIndic
|
|||
if (m_pDlg)
|
||||
{
|
||||
m_pDlg->ShowWindow(SW_SHOWNORMAL);
|
||||
SetWindowPos(m_pDlg->m_hWnd,HWND_TOPMOST,500,500,0,0,SWP_NOSIZE|SWP_NOMOVE);
|
||||
//m_pDlg->BringWindowToTop();
|
||||
SetWindowPos(m_pDlg->m_hWnd, HWND_TOPMOST, 500, 500, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret=TWRC_FAILURE;
|
||||
ret = TWRC_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (bIndicators)
|
||||
{
|
||||
if (indicator==NULL)
|
||||
if (indicator == NULL)
|
||||
{
|
||||
indicator=new IndicatorDlg(this,Data.ShowUI?m_pDlg:m_pChildWnd);
|
||||
indicator = new IndicatorDlg(this, Data.ShowUI ? m_pDlg : m_pChildWnd);
|
||||
}
|
||||
showUI=Data.ShowUI;
|
||||
showUI = Data.ShowUI;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -102,22 +101,22 @@ TW_INT16 MFC_UI::DisplayTWAINGUI(TW_USERINTERFACE Data, bool bSetup, bool bIndic
|
|||
void MFC_UI::DestroyTWAINGUI()
|
||||
{
|
||||
CTWAIN_UI::DestroyTWAINGUI();
|
||||
if (indicator!=NULL)
|
||||
if (indicator != NULL)
|
||||
{
|
||||
indicator->DestroyWindow();
|
||||
delete indicator;
|
||||
indicator=NULL;
|
||||
indicatorCreated=false;
|
||||
indicator = NULL;
|
||||
indicatorCreated = false;
|
||||
}
|
||||
|
||||
if (m_pDlg!=NULL)
|
||||
if (m_pDlg != NULL)
|
||||
{
|
||||
m_pDlg->DestroyWindow();
|
||||
delete m_pDlg;
|
||||
m_pDlg = NULL;
|
||||
}
|
||||
|
||||
if (m_pChildWnd!=NULL)
|
||||
if (m_pChildWnd != NULL)
|
||||
{
|
||||
m_pChildWnd->DestroyWindow();
|
||||
delete m_pChildWnd;
|
||||
|
@ -126,17 +125,17 @@ void MFC_UI::DestroyTWAINGUI()
|
|||
}
|
||||
|
||||
|
||||
void MFC_UI::UpdateProgress(bool bShow, unsigned char ucProgress, unsigned int unPageNo, string strProgressTitle)
|
||||
void MFC_UI::UpdateProgress(bool bShow, unsigned char ucProgress, unsigned int unPageNo, string strProgressTitle)
|
||||
{
|
||||
if (indicator==NULL)
|
||||
if (indicator == NULL)
|
||||
{
|
||||
indicator=new IndicatorDlg(this,NULL);
|
||||
indicator = new IndicatorDlg(this, NULL);
|
||||
}
|
||||
|
||||
if (!indicatorCreated)
|
||||
if (!indicatorCreated)
|
||||
{
|
||||
indicator->Create(IDD_DIALOG_INDICATOR,m_pChildWnd);//m_pChildWnd
|
||||
indicatorCreated=true;
|
||||
indicator->Create(IDD_DIALOG_INDICATOR, m_pChildWnd);//m_pChildWnd
|
||||
indicatorCreated = true;
|
||||
}
|
||||
|
||||
if (bShow)
|
||||
|
@ -147,21 +146,21 @@ void MFC_UI::UpdateProgress(bool bShow, unsigned char ucProgress, unsigned int
|
|||
{
|
||||
indicator->DestroyWindow();
|
||||
delete indicator;
|
||||
indicator=NULL;
|
||||
indicatorCreated=false;
|
||||
indicator = NULL;
|
||||
indicatorCreated = false;
|
||||
}
|
||||
//indicator->ShowWindow(bShow?SW_SHOWNORMAL:SW_HIDE);
|
||||
if (m_pDlg)
|
||||
{
|
||||
m_pDlg->EnableWindow(bShow?FALSE:TRUE);
|
||||
m_pDlg->EnableWindow(bShow ? FALSE : TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int MFC_UI::MyMessageBox(string strMessage, string strTitle, unsigned int unIconID)
|
||||
{
|
||||
//QMessageBox msgBox(QMessageBox::NoIcon, strTitle.c_str(), strMessage.c_str());
|
||||
if (m_pChildWnd!=NULL)
|
||||
{
|
||||
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);
|
||||
|
@ -169,13 +168,13 @@ unsigned int MFC_UI::MyMessageBox(string strMessage, string strTitle, unsigned i
|
|||
|
||||
bool MFC_UI::processEvent(pTW_EVENT _pEvent)
|
||||
{
|
||||
if(m_pDlg)
|
||||
if (m_pDlg)
|
||||
{
|
||||
if (IsDialogMessage(m_pDlg->m_hWnd, (LPMSG)(((pTW_EVENT)_pEvent)->pEvent)))
|
||||
{
|
||||
m_pDlg->SendMessage(_pEvent->TWMessage);
|
||||
//XdPrint("_pEvent->TWMessage %d\n",_pEvent->TWMessage);
|
||||
return TRUE;
|
||||
m_pDlg->SendMessage(_pEvent->TWMessage);
|
||||
//XdPrint("_pEvent->TWMessage %d\n",_pEvent->TWMessage);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
|
@ -0,0 +1,227 @@
|
|||
#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);
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
#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);
|
||||
};
|
||||
|
|
@ -101,6 +101,51 @@ struct tagOutHole
|
|||
|
||||
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;
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue