1.修复TWAINUI 点击× 关闭窗体是异常问题;

2.针对长文稿300DPI对折功能,做了功能可用性限制;
3.修复对接科大讯飞软件时,无法调用驱动问题;
This commit is contained in:
lovelyyoung 2020-05-16 09:59:44 +08:00
parent a11f063bf4
commit 562491e08d
16 changed files with 709 additions and 1020 deletions

View File

@ -136,6 +136,7 @@ void CBasicPage::OnBnClickedBtnabout()
void CBasicPage::OnCbnSelchangeCmbcolortype()
{
// TODO: 在此添加控件通知处理程序代码
updateCmbDuplex(TRUE);
m_dataChange();
}
@ -148,7 +149,7 @@ void CBasicPage::OnCbnSelchangeCmbss()
{
sleIndex = 0;
}
updateCmbDuplex(TRUE);
m_dataChange();
}
@ -156,6 +157,7 @@ void CBasicPage::OnCbnSelchangeCmbss()
void CBasicPage::OnCbnSelchangeCmbreslution()
{
// TODO: 在此添加控件通知处理程序代码
updateCmbDuplex(TRUE);
}
@ -168,6 +170,7 @@ void CBasicPage::OnCbnSelchangeCmbduplex()
//DevnMax = index == 2 ? 200 : 300;
m_dataChange();
//}
updateCmbDuplex(TRUE);
}
//跳过空白页设置页面
@ -188,3 +191,22 @@ void CBasicPage::SetScannerInfo(std::string hdVersion, std::string serialNum)
m_hdVersion = hdVersion;
m_serialNum = serialNum;
}
void CBasicPage::updateCmbDuplex(BOOL insert)
{
//m_cmBoxDuplex->GetCurSel();
int tmp_colorindex=m_cmBoxColorMode->GetCurSel();
int tmp_paperindex = m_cmBoxSS->GetCurSel();
int tmp_duplexindex = m_cmBoxDuplex->GetCurSel();
int tmp_resindex = m_cmBoxResultion->GetCurSel();
int totalcount = m_cmBoxDuplex->GetCount();
if (tmp_colorindex == 0 && tmp_paperindex >= 18 && tmp_resindex == 4) {
m_cmBoxDuplex->DeleteString(4);
m_cmBoxDuplex->SetCurSel(1);
}
else {
if (totalcount != 5) {
m_cmBoxDuplex->InsertString(4, TEXT("对折"));
}
}
}

View File

@ -23,7 +23,7 @@ public:
afx_msg void OnCbnSelchangeCmbss();
afx_msg void OnCbnSelchangeCmbreslution();
afx_msg void OnCbnSelchangeCmbduplex();
void updateCmbDuplex(BOOL insert);
public:
int AreaNum;
int DevnMax;

View File

@ -1,288 +0,0 @@
/***************************************************************************
* Copyright ?2007 TWAIN Working Group:
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
* Ricoh Corporation, and Xerox Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the TWAIN Working Group nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
***************************************************************************/
/**
* @file CTiffWriter.cpp
* Write an image to disk as a tiff file.
* @author JFL Peripheral Solutions Inc.
* @date October 2007
*/
#include "stdafx.h"
#include "CTiffWriter.h"
#include <sstream>
CTiffWriter::CTiffWriter(const string& _filename,
const long int _width,
const long int _height,
const int _bitsPerPixel,
const unsigned long int _bytesPerRow)
{
m_pImageStream = 0;
m_nOffset = 0;
m_filename = _filename;
m_ImageWidth.TagID = kTIFF_TAG_IMGWIDTH;
m_ImageWidth.DataType = kTIFF_TY_LONG;
m_ImageWidth.DataCount = 1;
m_ImageWidth.DataOffset = _width;
m_ImageLength.TagID = kTIFF_TAG_IMGLENGTH;
m_ImageLength.DataType = kTIFF_TY_LONG;
m_ImageLength.DataCount = 1;
m_ImageLength.DataOffset = _height;
m_BitsPerSample.TagID = kTIFF_TAG_BITSPERSAMPLE;
m_BitsPerSample.DataType = kTIFF_TY_SHORT;
m_BitsPerSample.DataCount = 1;
if(24 == _bitsPerPixel)
{
m_BitsPerSample.DataOffset = 8;
}
else
{
m_BitsPerSample.DataOffset = _bitsPerPixel;
}
m_Compression.TagID = kTIFF_TAG_COMPRESSION;
m_Compression.DataType = kTIFF_TY_SHORT;
m_Compression.DataCount = 1;
m_Compression.DataOffset = 1;
m_PhotometricInterp.TagID = kTIFF_TAG_PHOTOMETRICINT;
m_PhotometricInterp.DataType = kTIFF_TY_SHORT;
m_PhotometricInterp.DataCount = 1;
if(24 == _bitsPerPixel)
{
m_PhotometricInterp.DataOffset = 2;
}
else
{
m_PhotometricInterp.DataOffset = 1;
}
// -there is only one strip that contains all the row data, and it starts right after the header.
// -There are always 12 tags being written for each tiff.
m_StripOffsets.TagID = kTIFF_TAG_STRIPOFFSETS;
m_StripOffsets.DataType = kTIFF_TY_SHORT;
m_StripOffsets.DataCount = 1;
m_StripOffsets.DataOffset = getSizeofHeader();
m_SamplesPerPixel.TagID = kTIFF_TAG_SAMPLESPERPIXEL;
m_SamplesPerPixel.DataType = kTIFF_TY_SHORT;
if(24 == _bitsPerPixel)
{
m_SamplesPerPixel.DataCount = 1;
m_SamplesPerPixel.DataOffset = 3;
}
else
{
m_SamplesPerPixel.DataCount = 1;
m_SamplesPerPixel.DataOffset = 1;
}
m_RowsPerStrip.TagID = kTIFF_TAG_ROWSPERSTRIP;
m_RowsPerStrip.DataType = kTIFF_TY_LONG;
m_RowsPerStrip.DataCount = 1;
m_RowsPerStrip.DataOffset = _height;
m_StripByteCounts.TagID = kTIFF_TAG_STRIPBYTECOUNTS;
m_StripByteCounts.DataType = kTIFF_TY_LONG;
m_StripByteCounts.DataCount = 1;
m_StripByteCounts.DataOffset = _bytesPerRow * _height;
m_XResolution.TagID = kTIFF_TAG_XRESOLUTION;
m_XResolution.DataType = kTIFF_TY_RATIONAL;
m_XResolution.DataCount = 1;
m_XResolution.DataOffset = m_StripOffsets.DataOffset - sizeof(DWORD)*4; // fixed offset from the end of the header
setXResolution(100, 1);
m_YResolution.TagID = kTIFF_TAG_YRESOLUTION;
m_YResolution.DataType = kTIFF_TY_RATIONAL;
m_YResolution.DataCount = 1;
m_YResolution.DataOffset = m_StripOffsets.DataOffset - sizeof(DWORD)*2; // fixed offset from the end of the header
setYResolution(100, 1);
m_ResolutionUnit.TagID = kTIFF_TAG_RESOLUTIONUNIT;
m_ResolutionUnit.DataType = kTIFF_TY_SHORT;
m_ResolutionUnit.DataCount = 1;
m_ResolutionUnit.DataOffset = 2;
}
CTiffWriter::~CTiffWriter()
{
if(0 != m_pImageStream)
{
if(m_pImageStream->is_open())
{
m_pImageStream->close();
}
delete m_pImageStream;
}
}
void CTiffWriter::setImageWidth(const long int _v)
{
m_ImageWidth.DataOffset = _v;
}
void CTiffWriter::setImageHeight(const long int _v)
{
m_ImageLength.DataOffset = _v;
}
void CTiffWriter::setBitsPerSample(const int _v)
{
m_BitsPerSample.DataOffset = _v;
}
void CTiffWriter::setCompression(const int _v)
{
m_Compression.DataOffset = _v;
}
void CTiffWriter::setPhotometricInterp(const int _v)
{
m_PhotometricInterp.DataOffset = _v;
}
void CTiffWriter::setSamplesPerPixel(const int _v)
{
m_SamplesPerPixel.DataOffset = _v;
}
void CTiffWriter::setXResolution(const int _numerator, const int _denominator)
{
m_xres[0] = _numerator;
m_xres[1] = _denominator;
}
void CTiffWriter::setYResolution(const int _numerator, const int _denominator)
{
m_yres[0] = _numerator;
m_yres[1] = _denominator;
}
void CTiffWriter::setBytesPerRow(const int _v)
{
m_StripByteCounts.DataOffset = _v * m_ImageLength.DataOffset;
}
void CTiffWriter::GetImageHeader(stringstream &Header)
{
// write the header
TIFFIFH hdr = {0x4949, 0x002a, sizeof(TIFFIFH)};
Header.write(reinterpret_cast<char*>(&hdr), sizeof(TIFFIFH));
// write the Tags immediately after the header
WORD numTags = 12;
Header.write(reinterpret_cast<char*>(&numTags), sizeof(numTags));
const int nsize = sizeof(TIFFTag);
Header.write(reinterpret_cast<char*>(&m_ImageWidth), nsize);
Header.write(reinterpret_cast<char*>(&m_ImageLength), nsize);
Header.write(reinterpret_cast<char*>(&m_BitsPerSample), nsize);
Header.write(reinterpret_cast<char*>(&m_Compression), nsize);
Header.write(reinterpret_cast<char*>(&m_PhotometricInterp), nsize);
Header.write(reinterpret_cast<char*>(&m_StripOffsets), nsize);
Header.write(reinterpret_cast<char*>(&m_SamplesPerPixel), nsize);
Header.write(reinterpret_cast<char*>(&m_RowsPerStrip), nsize);
Header.write(reinterpret_cast<char*>(&m_StripByteCounts), nsize);
Header.write(reinterpret_cast<char*>(&m_XResolution), nsize);
Header.write(reinterpret_cast<char*>(&m_YResolution), nsize);
Header.write(reinterpret_cast<char*>(&m_ResolutionUnit), nsize);
// end the header by setting the next image offset to null
DWORD end = 0;
Header.write(reinterpret_cast<char*>(&end), sizeof(end));
// write the X and Y resolutions
Header.write(reinterpret_cast<char*>(&m_xres), sizeof(DWORD)*2);
Header.write(reinterpret_cast<char*>(&m_yres), sizeof(DWORD)*2);
}
bool CTiffWriter::writeImageHeader()
{
// create the out stream if not done so already
if(0 == m_pImageStream)
{
m_pImageStream = new ofstream();
}
// open the stream. If already open, reset it
if(m_pImageStream->is_open())
{
m_pImageStream->seekp(0);
}
else
{
m_pImageStream->open(m_filename.c_str(), ios_base::out|ios_base::binary|ios_base::trunc);
}
stringstream Header;
GetImageHeader(Header);
Header.seekp(0, ios_base::end);
m_nOffset =(int) Header.tellp();
Header.seekg(0, ios_base::beg);
char *pData = new char[m_nOffset];
Header.read(pData,m_nOffset);
m_pImageStream->write(pData,m_nOffset);
delete []pData;
return true;
}
bool CTiffWriter::WriteTIFFData(char *_pData, DWORD _nCount)
{
bool bret = false;
if(0 != m_pImageStream &&
m_pImageStream->good())
{
m_pImageStream->seekp(m_nOffset);
m_pImageStream->write(_pData, _nCount);
m_nOffset += _nCount;
bret = true;
}
return bret;
}
unsigned int CTiffWriter::getSizeofHeader()
{
// Header is as follows:
// TIFFIFH + Num. of Tags + each tag + Xres Data (2 dwords) + Yres Data (2 dwords) + Next Image offset (1 dword)
return sizeof(TIFFIFH)+sizeof(WORD)+sizeof(TIFFTag)*12+sizeof(DWORD)*5;
}

View File

@ -1,240 +0,0 @@
/***************************************************************************
* Copyright ?2007 TWAIN Working Group:
* Adobe Systems Incorporated, AnyDoc Software Inc., Eastman Kodak Company,
* Fujitsu Computer Products of America, JFL Peripheral Solutions Inc.,
* Ricoh Corporation, and Xerox Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the TWAIN Working Group nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY TWAIN Working Group ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL TWAIN Working Group BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
***************************************************************************/
/**
* @file CTiffWriter.h
* Write an image to disk as a tiff file.
* @author TWAIN Working Group
* @date October 2007
*/
#ifndef __TIFFWRITER_H__
#define __TIFFWRITER_H__
#include <string>
#include <fstream>
using namespace std;
#ifdef _MSC_VER
#include <windows.h>
#else
typedef uint16_t WORD;
typedef uint32_t DWORD;
#endif // _MSC_VER
#define TIFF_UNCOMPRESSED 1 /**< TIFF compression types */
#define TIFF_CCITTGROUP3 3
#define TIFF_CCITTGROUP4 4
// TIFF types
#define kTIFF_TY_BYTE 1 /**< 8-bit unsigned int */
#define kTIFF_TY_ASCII 2 /**< 8-bit byte that contains a 7-bit ASCII code; last byte must be binary 0 (NULL) */
#define kTIFF_TY_SHORT 3 /**< 16-bit (2-byte) unsigned int */
#define kTIFF_TY_LONG 4 /**< 32-bit (4-byte) unsigned int */
#define kTIFF_TY_RATIONAL 5 /**< two LONGs; the first is the numerator of a fraction; the second, the denominator */
// these field types where introduced in TIFF 6.0
#define kTIFF_TY_SBYTE 6 /**< 8-bit signed int */
#define kTIFF_TY_UNDEFINED 7 /**< 8-bit byte that may contain anything, depending on the definition of the field */
#define kTIFF_TY_SSHORT 8 /**< 16-bit (2-byte) signed int */
#define kTIFF_TY_SLONG 9 /**< 32-bit (4-byte) signed int */
#define kTIFF_TY_SRATIONAL 10 /**< two SLONG's; first is numerator of fraction, second is denominator */
#define kTIFF_TY_FLOAT 11 /**< single precision (4-byte) IEEE format */
#define kTIFF_TY_DOUBLE 12 /**< double precision (8-byte) IEEE format */
// TIFF Tags
#define kTIFF_TAG_IMGWIDTH 0x0100 /**< Image width, short or long */
#define kTIFF_TAG_IMGLENGTH 0x0101 /**< Image length, short or long */
#define kTIFF_TAG_BITSPERSAMPLE 0x0102 /**< BitsPerSample, short */
#define kTIFF_TAG_COMPRESSION 0x0103 /**< Compression, short */
#define kTIFF_TAG_PHOTOMETRICINT 0x0106 /**< PhotometricInterpretation, short */
#define kTIFF_TAG_STRIPOFFSETS 0x0111 /**< StripOffsets, short or long */
#define kTIFF_TAG_SAMPLESPERPIXEL 0x0115 /**< Samples per pixel, short */
#define kTIFF_TAG_ROWSPERSTRIP 0x0116 /**< RowsPerStrip, short or long */
#define kTIFF_TAG_STRIPBYTECOUNTS 0x0117 /**< StripByteCounts, short or long */
#define kTIFF_TAG_XRESOLUTION 0x011A /**< X Resolution, rational */
#define kTIFF_TAG_YRESOLUTION 0x011B /**< Y Resolution, rational */
#define kTIFF_TAG_RESOLUTIONUNIT 0x0128 /**< Resolution unit, short */
#define kTIFF_TAG_COLORMAP 0x0140 /**< ColorMap, short, RGB order, black = 0,0,0, TWAIN supports max 256 entry pallette */
/**
* TIFF Image File Header
*/
struct TIFFIFH
{
WORD Identifier;
WORD Version;
DWORD IFDOffset;
};
/**
* A TIFF Tag
* If the actual value of the tag is less then a DWORD, then offset will contain
* it, else offset is truly an offset to the value.
*/
struct TIFFTag
{
WORD TagID;
WORD DataType;
DWORD DataCount;
DWORD DataOffset;
};
/**
* This is a class that will progressively write a TIFF image to a file.
*/
class CTiffWriter
{
public:
/**
* Constructor for CTiffWriter. This is a class that will progressively
* write a TIFF image to a file.
* @param[in] _filename name of file to write to.
* @param[in] _width image width.
* @param[in] _height image height.
* @param[in] _bitsPerPixel number of bits per each pixel.
* @param[in] _bytesPerRow number of bytes per row of data.
*/
CTiffWriter(const string& _filename,
const long int _width,
const long int _height,
const int _bitsPerPixel,
const unsigned long int _bytesPerRow);
/**
* Deconstructor for CTiffWriter.
*/
virtual ~CTiffWriter();
/**
* Set the width of the image.
* @param[in] _v the new image width
*/
void setImageWidth(const long int _v);
/**
* Set the height of the image.
* @param[in] _v the new image height
*/
void setImageHeight(const long int _v);
/**
* Set the bits per sample of the image.
* @param[in] _v the new bits per sample
*/
void setBitsPerSample(const int _v);
/**
* Set the compression method to use.
* @param[in] _v the new compression method
*/
void setCompression(const int _v);
/**
* Set the Photometric Interpretation.
* @param[in] _v the new Photometric Interpretation
*/
void setPhotometricInterp(const int _v);
/**
* Set the number of samples per pixel of the image.
* @param[in] _v the new samples per pixel
*/
void setSamplesPerPixel(const int _v);
/**
* Set the x resolution of the image. Using type kTIFF_TY_RATIONAL (fraction)
* @param[in] _numerator the numerator part of the fraction
* @param[in] _denominator the denominator part of the fraction
*/
void setXResolution(const int _numerator, const int _denominator);
/**
* Set the y resolution of the image. Using type kTIFF_TY_RATIONAL (fraction)
* @param[in] _numerator the numerator part of the fraction
* @param[in] _denominator the denominator part of the fraction
*/
void setYResolution(const int _numerator, const int _denominator);
/**
* Set the Bytes per row of the image.
* @param[in] _v the new bytes per row
*/
void setBytesPerRow(const int _v);
/**
* Write the prepaired image header to the file.
* @return true for succes
*/
bool writeImageHeader();
/**
* Write the data for the image to the file.
* @param[in] _pData pointer to the image data
* @param[in] _nCount number of bytes to write
* @return true for success
*/
bool WriteTIFFData(char *_pData, DWORD _nCount);
/**
* Return the size of the TIFF header for the image file.
* @return the size of the header
*/
unsigned int getSizeofHeader();
void GetImageHeader(stringstream &Header);
protected:
string m_filename; /**< Name and or path of file */
int m_nOffset; /**< Current offset into file */
DWORD m_xres[2]; /**< The X resolution of the image */
DWORD m_yres[2]; /**< The Y resolution of the image */
TIFFTag m_ImageWidth; /**< The image width in pixels */
TIFFTag m_ImageLength; /**< The image height in pixels */
TIFFTag m_BitsPerSample; /**< The number of Bits per sample */
TIFFTag m_Compression; /**< The compression method to use */
TIFFTag m_PhotometricInterp; /**< The Photometric Interpretation to use */
TIFFTag m_StripOffsets; /**< The strip offset, where image data starts */
TIFFTag m_SamplesPerPixel; /**< The number of channels (RGB, G, )*/
TIFFTag m_RowsPerStrip; /**< The number of rows that make up each strip */
TIFFTag m_StripByteCounts; /**< The size of each strip of image data */
TIFFTag m_XResolution; /**< The offset to the X resolution */
TIFFTag m_YResolution; /**< The offset to the Y resolution */
TIFFTag m_ResolutionUnit; /**< The units of the Resolution */
ofstream* m_pImageStream; /**< The output stream to write the file to */
};
#endif // __TIFFWRITER_H__

View File

@ -86,6 +86,7 @@ BEGIN_MESSAGE_MAP(CTwainUI, CDialogEx)
ON_BN_CLICKED(IDC_BTNDELETCONFIG, &CTwainUI::OnBnClickedBtndeletconfig)
ON_BN_CLICKED(IDC_BTNRECOVERYCONFIG, &CTwainUI::OnBnClickedBtnrecoveryconfig)
ON_LBN_SELCHANGE(IDC_LSTCONFIG, &CTwainUI::OnLbnSelchangeLstconfig)
ON_WM_CLOSE()
END_MESSAGE_MAP()
@ -117,15 +118,9 @@ void CTwainUI::OnBnClickedConfirm()
vc.push_back(configItem);
std::string savepath = TCHAR2STRING1(szIniFile);
js.WriteJsonArrayToFile(vc, savepath);
if (str_caption.Compare(_T("扫描")) == 0)//内容为扫描时
{
m_glue.m_scan(*settings);
}
else
{
m_glue.m_cancel();
}
}
void CTwainUI::OnBnClickedBtndefault()
@ -207,20 +202,13 @@ void CTwainUI::UpdateUI(CONFIGPARAMS configParams)
m_pageFeedPaper->GetDlgItem(IDC_EDSCANNUM)->EnableWindow(TRUE);
m_pageFeedPaper->m_radioGroupScanMode = 1;
int tempcount = configParams.ScanCount;
//if (configParams.Duplex == 0)
//{
// tempcount = configParams.ScanCount;
//}
//else
//{
// tempcount = configParams.ScanCount / 2;
//}
CString csCount;
csCount.Format(_T("%d"), tempcount);
m_pageFeedPaper->GetDlgItem(IDC_EDSCANNUM)->SetWindowText(csCount);
}
m_pageFeedPaper->UpdateData(FALSE);
m_pageBasic->updateCmbDuplex(TRUE);
}
int CTwainUI::getResolutionIndex(int resolution)
@ -469,9 +457,10 @@ void CTwainUI::UpdateUi()
if (enableback)
{
((CButton*)(m_pageFeedPaper->GetDlgItem(IDC_CKBACKROTATION)))->SetCheck(!enableback);
if (dupindex == 4)
if (dupindex == 4) {
((CButton*)m_pageImageProc->GetDlgItem(IDC_CKAUTODESKREW))->SetCheck(dupindex == 4 ? TRUE : FALSE);
}
}
((CButton*)m_pageImageProc->GetDlgItem(IDC_CKAUTODESKREW))->EnableWindow(!(dupindex == 4));
m_pageFeedPaper->GetDlgItem(IDC_CKBACKROTATION)->EnableWindow(!enableback);
m_pageImageProc->GetDlgItem(IDC_SLDOUTHOLE)->EnableWindow(((CButton*)m_pageImageProc->GetDlgItem(IDC_CKREMOVEHOLE))->GetCheck()==TRUE);
@ -600,3 +589,10 @@ void CTwainUI::OnLbnSelchangeLstconfig()
}
}
}
void CTwainUI::OnClose()
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
m_glue.m_cancel();
}

View File

@ -165,4 +165,6 @@ protected:
std::vector<CONFIGINFO> getConfigFiles();
std::unique_ptr<GScanCap> settings;
std::string m_confirmtitle;
public:
afx_msg void OnClose();
};

View File

@ -199,6 +199,31 @@ typedef struct Paper_Status {
}
}PaperStatus;
enum G400_PaperSize {
G400_A3 = 0,
G400_A4,
G400_A4R,
G400_A5,
G400_A5R,
G400_A6,
G400_A6R,
G400_B4,
G400_B5,
G400_B5R,
G400_B6,
G400_B6R,
G400_DOUBLELETTER,
G400_LEGAL,
G400_LETTER,
G400_LETTERR,
G400_LONGLETTER
};
enum G400_DPI {
G400_D300 = 0,
G400_D200,
G400_D600
};
#define CAPTION_LEN 256
#define TWAIN_IMAGE_FILE_LIST_NAME TEXT(".dat")

View File

@ -172,7 +172,7 @@ int UsbScanEx::read_bulk(void* data, int len)
}
break;
default:
int a = 0;
//writelog("Usb read_bulk error code ID: " + std::to_string(error_code));
break;
}
}
@ -212,7 +212,7 @@ int UsbScanEx::write_bulk(void* data, int len)
}
break;
default:
int a = 0;
//writelog("Usb write_bulk error code ID: " + std::to_string(errorcode));
break;
}
}

View File

@ -7,7 +7,7 @@
#include <memory>
#include <list>
#include "IUsb.h"
#include "PublicFunc.h"
#pragma pack(1)
struct tag_usb_pipe

View File

@ -4,6 +4,7 @@
hgConfigClass::hgConfigClass(GScanCap param)
{
m_param = { 0 };
PaperStatus ps = { param.papertype,param.paperAlign };
m_param.paper = ContainspaperTypesKey(ps) ? SupPaperTyps[ps] : 0;
m_param.color = ContainsPixTypeKey(param.hardwarecaps.capturepixtype) ? SupPixelTypes[param.hardwarecaps.capturepixtype] : 2;
@ -47,3 +48,8 @@ bool hgConfigClass::ContainsResolutionKey(float key)
}
return false;
}
unsigned int hgConfigClass::GetData()
{
return m_param.value;
}

View File

@ -13,7 +13,10 @@ class hgConfigClass:public IConfig
{
public:
hgConfigClass(GScanCap param);
// 通过 IConfig 继承
virtual unsigned int GetData() override;
private:
ConfigParam m_param;
enum Config_Scanner
{
cfStaple,

View File

@ -50,11 +50,13 @@ void CImageApplyAutoCrop::apply(cv::Mat& pDib, int side)
cv::Mat scale_mat;
cv::Mat thre(src_resize.size(), CV_8UC1);
hg::threshold_Mat(src_resize, thre, m_threshold);
src_resize.release();
if (m_noise > RE)
{
cv::Mat element = getStructuringElement(cv::MORPH_RECT, cv::Size(m_noise / RE, m_noise / RE));
cv::morphologyEx(thre, thre, cv::MORPH_OPEN, element);
element.release();
}
std::vector<cv::Vec4i> hierarchy;
std::vector<std::vector<cv::Point>> contours;
@ -106,8 +108,9 @@ void CImageApplyAutoCrop::apply(cv::Mat& pDib, int side)
hierarchy.clear();
contours.clear();
maxContour.clear();
hg::findContours(thre_dst, contours, hierarchy, cv::RETR_EXTERNAL);
thre_dst.release();
maxContour = hg::getMaxContour(contours, hierarchy);
if (m_isConvexHull)
hg::convexHull(maxContour, maxContour);

View File

@ -21,6 +21,7 @@
#include <list>
#include <map>
#include "Device/JsonConfig.h"
#include "opencv2/opencv.hpp"
//custom define caps enum
@ -60,10 +61,10 @@ using namespace std::placeholders;
TWPP_ENTRY_MFC(HuagaoDs)
static constexpr const Identity srcIdent(
Version(3, 3, Language::English, Country::CzechRepublic, "v3.3.1.6"),
Version(3, 3, Language::English, Country::China, "v3.3.2.1"),
DataGroup::Image,
"宁波华高信息科技有限公司",
"G200 Series",
"HUAGOSCAN TWAIN",
"G300 Series",
"HUAGOSCAN TWAIN"
#if defined(_MSC_VER)
""
@ -148,7 +149,8 @@ Result HuagaoDs::call(const Identity& origin, DataGroup dg, Dat dat, Msg msg, vo
try {
// we can override almost anything from SourceFromThis, even the top-most source instance call
return Base::call(origin, dg, dat, msg, data);
} catch (const CapabilityException&){
}
catch (const CapabilityException&) {
return badValue();
}
}
@ -321,10 +323,37 @@ Result HuagaoDs::eventProcess(const Identity&, Event& event){
guiTwain->SendMessage((UINT)(event.message()));
}
event.setMessage(Msg::Null);
return { ReturnCode::NotDsEvent, ConditionCode::Success };
}
//add------------------设置jpg图像dpi---------------------------
void HuagaoDs::SetResoluton(const char* path, int resolution)
{
FILE* file = fopen(path, "rb+");
if (!file)
return;
//获取文件大小
int len = _filelength(_fileno(file));
char* buf = new char[len];
fread(buf, sizeof(char), len, file);
char* pResolution = (char*)&resolution;
//设置使用图片密度单位
buf[0x0D] = 1;
//水平密度,水平分辨率
buf[0x0E] = pResolution[1];
buf[0x0F] = pResolution[0];
//垂直密度,垂直分辨率
buf[0x10] = pResolution[1];
buf[0x11] = pResolution[0];
fseek(file, 0, SEEK_SET);
//将数据写入文件,覆盖原始数据,让修改生效
fwrite(buf, sizeof(char), len, file);
fclose(file);
}
Result HuagaoDs::identityOpenDs(const Identity&) {
//writelog("identityOpenDs");
bmpData.resize(sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER));
BITMAPINFOHEADER& bmInfo = *((BITMAPINFOHEADER*)header());
bmInfo.biHeight = 2000;
@ -336,6 +365,12 @@ Result HuagaoDs::identityOpenDs(const Identity&){
MessageBox(NULL, _T("未找到扫描仪!请检查电源或者USB连接线是否接通!"), _T("提示"), MB_SYSTEMMODAL | MB_OK | MB_ICONINFORMATION);
return checkDeviceOnline();
}
hMutex = CreateMutex(NULL, FALSE, _T("LookitApp"));
if (GetLastError() == ERROR_ALREADY_EXISTS) { //如果已经存在同名的Mutex会得到这个错误.
CloseHandle(hMutex);
MessageBox(NULL, _T("设备已被其他程序占用,请关闭占用程序之后再重试!"), _T(" "), MB_OK);
return seqError();
}
// init caps
// there are caps a minimal source must support
@ -393,6 +428,7 @@ Result HuagaoDs::identityOpenDs(const Identity&){
m_query[CapType::ICompression] = msgSupportGetAllSetReset;
m_caps[CapType::ICompression] = std::bind(enmGetSetConst<Compression>, _1, _2, Compression::None);
m_query[CapType::IBitDepth] = msgSupportGetAllSetReset;
m_caps[CapType::IBitDepth] = std::bind(enmGetSetConst<UInt16>, _1, _2, UInt16(header()->biBitCount));
@ -439,6 +475,33 @@ Result HuagaoDs::identityOpenDs(const Identity&){
return capBadOperation();
}
};
//add------------------jpeg质量等级---------------------
m_query[CapType::IJpegQuality] = msgSupportGetAllSetReset;
m_caps[CapType::IJpegQuality] = [this](Msg msg, Capability& data)->Result {
switch (msg) {
case Msg::Get:
case Msg::GetCurrent:
data = Capability::createOneValue<UInt16>(CapType::IJpegQuality, (UInt16)m_jpegQuality);
return success();
case Msg::Reset:
m_jpegQuality = 80;
return success();
case Msg::GetDefault:
data = Capability::createOneValue<UInt16>(CapType::IJpegQuality, 80);
return success();
case Msg::Set: {
auto mech = data.currentItem<CapType::IJpegQuality>();
if ((int)mech < 0 || (int)mech > 100)
return capBadOperation();
m_jpegQuality = (int)mech;
return success();
}
default:
return capBadOperation();
}
};
m_query[CapType::IUnits] = msgSupportGetAllSetReset;
m_caps[CapType::IUnits] = std::bind(enmGetSetConst<Unit>, _1, _2, Unit::Inches);
@ -448,7 +511,7 @@ Result HuagaoDs::identityOpenDs(const Identity&){
switch (msg) {
case Msg::Get:
data = Capability::createEnumeration<CapType::IXferMech>(
{XferMech::Native, XferMech::Memory}, m_capXferMech == XferMech::Native ? 0 : 1, 0);
{ XferMech::Native, XferMech::Memory, XferMech::File}, m_capXferMech == XferMech::Native ? 0 : (m_capXferMech == XferMech::Memory ? 1 : 2), 0);
return success();
case Msg::Reset:
@ -464,10 +527,11 @@ Result HuagaoDs::identityOpenDs(const Identity&){
case Msg::Set: {
auto mech = data.currentItem<CapType::IXferMech>();
if (mech == XferMech::Native || mech == XferMech::Memory){
if (mech == XferMech::Native || mech == XferMech::Memory|| mech == XferMech::File) {
m_capXferMech = mech;
return success();
} else {
}
else {
return badValue();
}
}
@ -710,28 +774,12 @@ Result HuagaoDs::identityOpenDs(const Identity&){
m_query[CapType::PaperDetectable] = msgSupportGetAll;
m_caps[CapType::PaperDetectable] = std::bind(enmGet<Bool>, _1, _2, Bool(true));
m_query[CapType::FeederEnabled] = msgSupportGetAllSetReset;
m_query[CapType::FeederEnabled] = msgSupportGetAll;
m_caps[CapType::FeederEnabled] = [this](Msg msg, Capability& data) -> Result {
switch (msg) {
case Msg::Get:
data = Capability::createEnumeration<CapType::FeederEnabled>(
{ Bool(), Bool(true) }, Bool(m_bFeederEnabled));
return success();
case Msg::GetCurrent:
data = Capability::createOneValue<CapType::FeederEnabled>(m_bFeederEnabled);
return success();
case Msg::Reset:
case Msg::GetDefault:
data = Capability::createOneValue<CapType::FeederEnabled>(true);
m_bFeederEnabled = true;
return success();
case Msg::Set: {
auto feederen = data.currentItem<CapType::FeederEnabled>();
m_bFeederEnabled = feederen;
return success();
}
default:
return capBadOperation();
}
@ -802,11 +850,14 @@ Result HuagaoDs::identityOpenDs(const Identity&){
m_query[CapType::IImageFileFormat] = msgSupportGetAllSetReset;
m_caps[CapType::IImageFileFormat] = [this](Msg msg, Capability& data) -> Result {
switch (msg) {
case Msg::Get:
case Msg::Get: {
UInt32 capindex = 0;
if (m_capImageFileFormat == ImageFileFormat::Tiff) capindex = 1;
if (m_capImageFileFormat == ImageFileFormat::Jfif) capindex = 2;
data = Capability::createEnumeration<CapType::IImageFileFormat>(
{ ImageFileFormat::Bmp, ImageFileFormat::Tiff}, m_capImageFileFormat == ImageFileFormat::Bmp? 0 : 1, 0);
{ ImageFileFormat::Bmp, ImageFileFormat::Tiff,ImageFileFormat::Jfif}, capindex, 0);
return success();
}
case Msg::Reset:
m_capImageFileFormat = ImageFileFormat::Bmp;
// fallthrough
@ -820,7 +871,9 @@ Result HuagaoDs::identityOpenDs(const Identity&){
case Msg::Set: {
auto mech = data.currentItem<CapType::IImageFileFormat>();
if (mech == ImageFileFormat::Bmp || mech == ImageFileFormat::Tiff) {
if (mech == ImageFileFormat::Bmp ||
mech == ImageFileFormat::Tiff ||
mech == ImageFileFormat::Jfif) {
m_capImageFileFormat = mech;
return success();
}
@ -828,7 +881,6 @@ Result HuagaoDs::identityOpenDs(const Identity&){
return badValue();
}
}
default:
return capBadOperation();
}
@ -840,7 +892,7 @@ Result HuagaoDs::identityOpenDs(const Identity&){
switch (msg) {
case Msg::Get:
data = Capability::createEnumeration<CapType::IAutomaticDeskew>(
{ Bool(), Bool(true) }, Bool(m_scanparam->autodescrew));
{ Bool(), Bool(true) }, Bool(m_scanparam->autodescrew == 0 ? false : true));
return success();
case Msg::Reset:
m_scanparam->autodescrew = true;
@ -1443,6 +1495,13 @@ Result HuagaoDs::identityOpenDs(const Identity&){
Result HuagaoDs::identityCloseDs(const Identity&) {
// no need to explicitly release any resources if using RAII
// TWPP will free the whole source on its own after this method
//writelog("identityCloseDs");
if (hMutex)
{
ReleaseMutex(hMutex);
CloseHandle(hMutex);
}
guiIndicator.reset();
guiTwain.reset();
guiBridge.reset();
@ -1457,6 +1516,8 @@ Result HuagaoDs::pendingXfersGet(const Identity&, PendingXfers& data){
Result HuagaoDs::pendingXfersEnd(const Identity&, PendingXfers& data) {
//!< end xfer if set count 0
if (bmpData.size() > 0)
bmpData.clear();
int ret = scanner->aquire_bmpdata(bmpData);
if (ret != 0) {
scanner->Set_ErrorCode(0);
@ -1468,7 +1529,6 @@ Result HuagaoDs::pendingXfersEnd(const Identity&, PendingXfers& data){
if (guiTwain.get()) {
((CTwainUI*)(guiTwain.get()))->EnableID_OKorID_Cancel(true);
}
}
else {
m_pendingXfers = 1;
@ -1507,7 +1567,7 @@ Result HuagaoDs::userInterfaceDisable(const Identity&, UserInterface& ui){
Result HuagaoDs::userInterfaceEnable(const Identity&, UserInterface& ui) {
m_pendingXfers = 1;
m_memXferYOff = 0;
//writelog("userInterfaceEnable");
if (!ui.showUi()) {
// this is an exception when we want to set state explicitly, notifyXferReady can be called only in enabled state
// with hidden UI, the usual workflow DsState::Enabled -> notifyXferReady() -> DsState::XferReady is a single step
@ -1645,6 +1705,7 @@ Result HuagaoDs::imageMemXferGet(const Identity& origin, ImageMemXfer& data){
if (m_memXferYOff >= static_cast<UInt32>(std::abs(dib->biHeight))) {
m_pendingXfers = 0;
m_memXferYOff = 0;
return { ReturnCode::XferDone, ConditionCode::Success };
}
@ -1654,7 +1715,7 @@ Result HuagaoDs::imageMemXferGet(const Identity& origin, ImageMemXfer& data){
static int xtfer = 0;
#endif
Result HuagaoDs::imageNativeXferGet(const Identity&, ImageNativeXfer& data){
Result HuagaoDs::imageNativeXferGet(const Identity& id, ImageNativeXfer& data) {
if (!m_pendingXfers) {
return seqError();
}
@ -1681,6 +1742,86 @@ Twpp::Result HuagaoDs::pendingXfersStopFeeder(const Identity& origin, PendingXfe
return success();
}
Twpp::Result HuagaoDs::setupFileXferGet(const Twpp::Identity& origin, Twpp::SetupFileXfer& data)
{
data.setFilePath(m_fileXfer.filePath());
data.setFormat(m_fileXfer.format());
return success();
}
Twpp::Result HuagaoDs::setupFileXferGetDefault(const Twpp::Identity& origin, Twpp::SetupFileXfer& data)
{
Str255 str("HGTwain.bmp");
data.setFilePath(str);
data.setFormat(ImageFileFormat::Bmp);
return success();
}
Twpp::Result HuagaoDs::setupFileXferSet(const Twpp::Identity& origin, Twpp::SetupFileXfer& data)
{
m_fileXfer.setFilePath(data.filePath());
m_fileXfer.setFormat(data.format());
return success();
}
Twpp::Result HuagaoDs::setupFileXferReset(const Twpp::Identity& origin, Twpp::SetupFileXfer& data)
{
m_fileXfer.setFormat(Twpp::ImageFileFormat::Bmp);
std::string templateName = "HG";
char* tempPath = mktemp((char*)templateName.c_str());
if (tempPath) {
Str255 str;
str.setData(tempPath, strlen(tempPath));
m_fileXfer.setFilePath(str);
return success();
}
return badProtocol();
}
Twpp::Result HuagaoDs::imageFileXferGet(const Twpp::Identity& origin)
{
if (!m_pendingXfers)
return seqError();
string filename = m_fileXfer.filePath().string();
switch (m_fileXfer.format())
{
case ImageFileFormat::Bmp: {
FILE* pfile = fopen(filename.c_str(), "wb");
if (pfile) {
if (bmpData.size() > 0) {
fwrite(bmpData.data(), 1, bmpData.size(), pfile);
fclose(pfile);
return success();
}
}
return Result(ReturnCode::Failure, ConditionCode::BadValue);
}
break;
case ImageFileFormat::Tiff:
case ImageFileFormat::Jfif: {
BITMAPINFOHEADER& bmpinfo = *((BITMAPINFOHEADER*)header());
int decodetype;
if (bmpinfo.biBitCount == 24)
decodetype = cv::IMREAD_COLOR;
else
decodetype = cv::IMREAD_GRAYSCALE;
cv::Mat ims = cv::imdecode(bmpData, decodetype);
std::vector<int> compression_params;
compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
compression_params.push_back(m_jpegQuality);
cv::imwrite(filename, ims, compression_params);
return success();
}
break;
default:
break;
}
return badProtocol();
}
Twpp::Result HuagaoDs::showTwainUI(Twpp::UserInterface& ui, bool bUiOnly)
{
// as a minimal source, we do not support GUI that just saves settings
@ -1867,6 +2008,10 @@ Twpp::Result HuagaoDs::startScan()
return checkDeviceOnline();
scanner->ResetScanner();
#ifndef G200
scanner->clear_hwerror();
#endif //
scanner->config_params(*m_scanparam);
if (m_bIndicator) {
//!< cancel button push

View File

@ -55,8 +55,15 @@ protected:
virtual Twpp::Result imageMemXferGet(const Twpp::Identity& origin, Twpp::ImageMemXfer& data) override;
virtual Twpp::Result imageNativeXferGet(const Twpp::Identity& origin, Twpp::ImageNativeXfer& data) override;
virtual Twpp::Result pendingXfersStopFeeder(const Twpp::Identity& origin, Twpp::PendingXfers& data) override;
virtual Twpp::Result call(const Twpp::Identity& origin, Twpp::DataGroup dg, Twpp::Dat dat, Twpp::Msg msg, void* data) override;
virtual Twpp::Result imageFileXferGet(const Twpp::Identity& origin) override;
//virtual Twpp::Result pendingXfersStopFeeder(const Twpp::Identity& origin, Twpp::PendingXfers& data) override;
virtual Twpp::Result setupFileXferGet(const Twpp::Identity& origin, Twpp::SetupFileXfer& data) override;
virtual Twpp::Result setupFileXferGetDefault(const Twpp::Identity& origin, Twpp::SetupFileXfer& data) override;
virtual Twpp::Result setupFileXferSet(const Twpp::Identity& origin, Twpp::SetupFileXfer& data) override;
virtual Twpp::Result setupFileXferReset(const Twpp::Identity& origin, Twpp::SetupFileXfer& data) override;
virtual Twpp::Result call(const Twpp::Identity& origin, Twpp::DataGroup dg, Twpp::Dat dat, Twpp::Msg msg, void* data) override;
static void SetResoluton(const char* path, int resolution);
private:
Twpp::Result showTwainUI(Twpp::UserInterface& data, bool bUiOnly = false);
Twpp::Result startScan();
@ -72,6 +79,7 @@ private:
std::unordered_map<Twpp::CapType, std::function<Twpp::Result(Twpp::Msg msg, Twpp::Capability& data)>> m_caps;
std::unordered_map<Twpp::CapType, Twpp::MsgSupport> m_query;
Twpp::SetupFileXfer m_fileXfer;
Twpp::UInt32 m_memXferYOff = 0;
Twpp::UInt16 m_pendingXfers = 0;
@ -79,6 +87,8 @@ private:
Twpp::Fix32 m_brightness = 0.0f;
Twpp::XferMech m_capXferMech = Twpp::XferMech::Native;
Twpp::PixelType m_capPixelType = Twpp::PixelType::Rgb;
unsigned short m_jpegQuality = 80;
bool m_bIndicator = true;
bool m_bFeederEnabled = true;
bool m_bAutoFeed = true;
@ -86,7 +96,7 @@ private:
std::vector<unsigned char> bmpData;
std::unique_ptr<GScanCap> m_scanparam;
HANDLE hMutex;
};

View File

@ -64,6 +64,8 @@ SOURCES += huagaods.cpp \
Device/cJSON.cpp \
Device/CJsonObject.cpp \
Device/JsonConfig.cpp \
Device/GetMemoryUsage.cpp \
Device/G400ScanConfig.cpp \
ImageProcess/ImageApply.cpp \
ImageProcess/ImageApplyAdjustColors.cpp \
ImageProcess/ImageApplyAutoCrop.cpp \
@ -77,6 +79,7 @@ SOURCES += huagaods.cpp \
ImageProcess/ImageApplySharpen.cpp \
ImageProcess/ImageProcess_Public.cpp \
ImageProcess/ImageApplyConcatenation.cpp \
G400ScanConfig.cpp \
Sliders.cpp \
SmartEdit.cpp \
TabCtrlSSL.cpp \
@ -109,12 +112,14 @@ HEADERS += huagaods.hpp \
Device/UsbScanEx.h \
Device/config_new.h \
Device/device_common.h \
Device/GetMemoryUsage.h \
Device/GScan.h \
Device/scn_config.h \
Device/filetools.h \
Device/cJSON.h \
Device/JsonConfig.h \
Device/CJsonObject.hpp \
Device/G400ScanConfig.h \
ImageProcess/ImageApply.h \
ImageProcess/ImageApplyAdjustColors.h \
ImageProcess/ImageApplyAutoCrop.h \

Binary file not shown.