twain2/hugaotwainds/CScanner_FreeImage.h

319 lines
10 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

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

/***************************************************************************
* Copyright ?2007 TWAIN Working Group:
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
* Ricoh Corporation, and Xerox Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the TWAIN Working Group nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
***************************************************************************/
/**
* @file CScanner_FreeImage.h
* Defines a scanner.
* Create a virtual scanner.
* @author TWAIN Working Group
* @date April 2007
*/
#ifndef __CSCANNER_H__
#define __CSCANNER_H__
#include "Common.h"
#include "twain.h"
#include <vector>
#include "gscn_drv.h"
#include <memory>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <map>
using namespace std;
/**
* This is a virtual scanner. The virtual scanner is used by the data source
* to try and somewhat simulate some real hardware interaction.
* - It acquires the same image each time from an image file on the hard disk.
* - It uses the FreeImage library to apply transforms to the base image.
*
* For simulation purposes the virtual Scanner is set up with the
* following specifications:
*
* - Scanner Types
* - ADF(Automatic Document Feeder)
* - Flatbed
*
* - Image sensors
* - CCD x 3 ( Front / Back / Flatbed )
*
* - Scanning area Minimum
* - ADF - A8 @ 127g/m2 paper
* - Flatbed - unlimited
*
* - Scanning area Maximum
* - ADF - Legal paper
* - Flatbed - A4 letter paper
*
* - Internal Optical Resolution
* - 600dpi
*
* - Output Resolution
* - Binary - 50, 100, 150, 200, 300, 400, 500, & 600
* - Grayscale - 50, 100, 150, 200, 300, 400, 500, & 600
* - Color - 50, 100, 150, 200, 300, 400, 500, & 600
*
* - Internal Bit Depth
* - 8 bits per color
*
* - Output Bit Depth
* - Binary - 1 bits
* - Grayscale - 8 bits
* - Color - 8 bits per color
*
* - Halftone Patterns
* - Dither /error diffusion
*
* - compression: JPEG, and FAX4 (CCITT G4)
*
*/
// Defines used by Scanner FreeImage class to set and get attributes of the vurtual scanner.
/**
* The FreeImage scanner define for PaperSource is ADF
*/
#define SFI_PAPERSOURCE_ADF 0
/**
* The FreeImage scanner define for PaperSource is Flatbed
*/
#define SFI_PAPERSOURCE_FB 1
/**
* The FreeImage scanner data structure. This data is passed back and forth between the scanner class and driver.
*
*/
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 /**< ֽ<><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
//<2F><><EFBFBD><EFBFBD>
BOOL m_bAutoContrast; /**< <20>Զ<EFBFBD><D4B6>Աȶ<D4B1>*/
bool m_bAutoCrop; /**< <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>*/
bool m_bAutoDiscardBlank; /**< <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>հ<EFBFBD>ҳͨ<D2B3><CDA8>*/
bool m_bAutoDiscardBlankInvoice;/**<2A>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>հ<EFBFBD>ҳ<EFBFBD><D2B3>Ʊ*/
bool m_bAutoDeskew; /**< <20>Զ<EFBFBD><D4B6><EFBFBD>ƫ*/
bool m_bMultiOutput; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
WORD m_nFilter; /**< <20><>ɫ*/
WORD m_nEnhance_color; /**< <20><>ɫ<EFBFBD><C9AB>ǿ*/
bool m_bFillBlackRect; /**< <20><><EFBFBD>ڿ<EFBFBD>*/
UINT16 m_wScanCount; /**< ɨ<><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
WORD m_wRotation; /**< <20><>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>*/
bool m_bBackRotate180; /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת180*/
HARDWAREPARAMS m_HardWareParams; /**< Ӳ<><D3B2>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
OutHole m_OutHole;
bool is_autotext; /**< <20>Զ<EFBFBD><D4B6>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><CAB6>*/
};
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.
*
*/
class CScanner_FreeImage : public SFreeImage
{
public:
/**
* Constructor for CScanner_FreeImage.
*/
CScanner_FreeImage();
/**
* Deconstructor for CScanner_FreeImage.
*/
~CScanner_FreeImage();
/**
* Resets the scanner to factory default settings.
* Sets the scanners caps back to defaults.
* @return true if successfully reset.
*/
bool resetScanner();
/**
* Get a scan line and put it into the _ImageXfer, fill values in _ImageXfer.
* @param[out] pTransferBuffer a pointer to an array of bytes to store the image data
* @param[in] dwRead the number of bytes to read from scanner
* @param[out] dwReceived the actual number of bytes transfered
* @return true if successful
*/
bool getScanStrip(BYTE *pTransferBuffer, DWORD dwRead, DWORD &dwReceived);
/**
* Sets all the scanners capabilities to read only.
*/
void Lock(void) {m_bReadOnly = true;}
/**
* Sets all the scanners capabilities to read and write.
*/
void Unlock(void) {m_bReadOnly = false;}
/**
* Retrieves the image to scan from disk into memory.
* @return true if image was loaded into memory successfully.
*/
bool acquireImage(bool bscan = true);
////////////////
// Accessors
/**
* get the current settings
* @return the current scanner settngs
*/
SFreeImage* getSetting() const;
/**
* set the current settings
* @param[in] settings the new settings for the scanner
*/
//void setSetting(SFreeImage settings);
/**
* Determine if there is paper sitting in the feeder.
* IF empty loads again for next time.
* @return true if paper in feeder else return false.
*/
bool isFeederLoaded();
/**
* Return status of the device is online or not.
* @return true if online.
*/
bool getDeviceOnline() const;
bool isPaperOn() const;
/* get scannner hardware version*/
std::string getSerialNum() const;
std::string getFWVersion() const;
bool isImageQueueEmpty();
short GetMaxPagesInADF(void){return m_nMaxDocCount;}
void SetMaxPagesInADF(short nVal){m_nMaxDocCount = nVal;};
bool StopScan();
WORD m_nSourceWidth; /**< Width of image in FreeImage */
WORD m_nSourceHeight; /**< Height of image in FreeImage */
protected:
/**
* Return the number of documents sitting in the feeder.
* This number can be set with enviroment varible kGETENV_XFERCOUNT "CAP_XFERCOUNT"
* this is so we can tell when the feeder is empty
* - If CAP_XFERCOUNT is not set will return 1.
* - if < 0 will return random number.
* @return default number of documents.
*/
short getDocumentCount() const;
/**
* Transform the image according to the caps set by the application.
* @return true if successful
*/
bool preScanPrep();
protected:
//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_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;