/*************************************************************************** * 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 "FreeImage.h" #include "twain.h" #include "gscn_drv.h" //#include "IndicatorDlg.h" #include #include #include #include #include /** * 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 /**< 纸张类型*/ //后加 BOOL m_bAutoContrast; /**< 自动对比度*/ bool m_bAutoCrop; /**< 自动裁切*/ bool m_bAutoDiscardBlank; /**< 自动丢弃空白页通用*/ bool m_bAutoDiscardBlankInvoice;/**自动丢弃空白页发票*/ bool m_bAutoDeskew; /**< 自动纠偏*/ WORD m_nFilter; /**< 除色*/ bool m_bFillBlackRect; /**< 填黑框*/ UINT16 m_wScanCount; /**< 扫描张数*/ WORD m_wRotation; /**< 旋转方向*/ bool m_bBackRotate180; /**< 背面旋转180*/ HARDWAREPARAMS m_HardWareParams; /**< 硬件扫描参数*/ }; 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); std::vector> m_iaList; std::shared_ptr m_imageTrans; }; #endif // __CSCANNER_H__ //extern IndicatorDlg* m_pIndicator;