twain3.0/huagao/Device/PublicFunc.h

469 lines
15 KiB
C++
Raw 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.

#ifndef PUBLICFUNC_H_
#define PUBLICFUNC_H_
#include "stdafx.h"
#include <string>
#include <direct.h>
#include <io.h>
#include <Windows.h>
#include <fstream>
#define BYTES_PERLINE_ALIGN4(width, bpp) (((((int)(width)*(bpp))+31)/32)*4)
#define BYTES_PERLINE(width, bpp) ((((int)(width)*(bpp))+7)/8)
using byte = unsigned char;
using std::string;
/************************************
**扫描参数json格式保存参数名称**
*************************************/
const std::string CONFIG = "Config";
//<!基本选项卡
const std::string PIXTYPE = "iPixType";
const std::string AUTOMATICCOLOR = "bAutoMaticColorDetece";
const std::string AUTOMATICCOLORTYPR = "iAutoMaticColorDeteceType";
#ifdef UV
const std::string ENUVMODEL = "bUVmodel";
#endif
const std::string PAPARSIZE = "iPaparSize";
const std::string ENSIZECHECK = "iEnSizeCheck";
const std::string ENFIXEDPAPER = "bEnFixedPaper";
const std::string PAPERALIGN = "iPaperAlign";
const std::string RESOLUTION = "iResolution";
const std::string DUPLEX = "iDuplex";
const std::string DISCARBLANK = "bDiscardBlank";
const std::string DISCARBLANKVINCE = "bDiscardBlankVince";
const std::string DISCARBLANK_VALUE = "discardblank_percent";
const std::string DB_AREANUM = "iAreaNum";
const std::string DB_DEVNMAX = "iDevnMax";
const std::string FLOD = "bFlod";
const std::string AUTOCROP = "bAuotCrop";
const std::string HIGH_IMAGE_QUALITY = "bHighimagequality";
const std::string SWITCHFRONTBACK = "bSwitchFrontBack";
const std::string SPLIT = "bSplit";
//<!亮度对比度选项卡
const std::string AUTOCONTRAST = "bAutoContrast";
const std::string BRIGHTNESS = "iBrightness";
const std::string CONTRAST = "iContrast";
const std::string GAMMA_ = "dGamma";
//<!图像处理选项卡
const std::string CROPMODEL = "bcropmodel";
const std::string FILTERTYPE = "iFilter";
const std::string ENHANCECOLOR = "iEnhance";
const std::string SHARPENTYPE = "iSharpen";
const std::string FILLBLACK = "bFillBlcak";
const std::string AUTODESCREW = "bAutoDescrew";
const std::string MULTIOUTPUT = "iMultiOutPut";
const std::string EN_MULTIOUT = "bMultiOut";
const std::string MULTIOUTTYPE = "iMultiOut";
const std::string OUTHOLE = "bOutHole";
const std::string OUTHOLERATIO = "iOutHoleRatio";
const std::string OUTHOLERATIOUP = "iOutHoleRatioup";
const std::string OUTHOLERATIODOWN = "iOutHoleRatiodown";
const std::string OUTHOLERATIOLEFT = "iOutHoleRatioleft";
const std::string OUTHOLERATIORIGHT = "iOutHoleRatioright";
const std::string EN_OUTHOLERATIOUP = "bOutHoleRatioup";
const std::string EN_OUTHOLERATIODOWN = "bOutHoleRatiodown";
const std::string EN_OUTHOLERATIOLEFT = "bOutHoleRatioleft";
const std::string EN_OUTHOLERATIORIGHT = "bOutHoleRatioright";
const std::string DETACHNOISE = "detachnoise";
const std::string DETACHNOISEVALUE = "detachnoisevalue";
const std::string FADEBACK = "bfadeback";
const std::string FADEBACKRANGE = "fadebackvalue";
const std::string HSVCORRECT = "bHsvCorrect";
//<!送纸选项卡
const std::string ULTRADETECT = "bUltrasonicDetect";
const std::string BINDINGDETECT = "bBindingDetect";
const std::string AUTOPAPER = "bautopaper";
const std::string SCANCOUNT = "ScanCount";
const std::string DOCORIENTATION = "bOrientation";
const std::string AUTO_TEXT = "bAutoText";
const std::string BACKROTATE180 = "iBackRotate180";
const std::string DOGEAR_DETECTION = "dogeardetection";
const std::string DOGEAR_DISTANCE = "idogeardistance";
const std::string SCREWDETECT = "bScrewDetect";
const std::string SCREWLEVEL = "iScrewLevel";
const std::string ITEMCAPTION = "Caption";
const std::string SAVEPATH = "SavePath";
const std::string ISCONVEX = "isConvex";
const std::string INDENT = "Indent";
const std::string AUTOCROP_THRESHOLD = "AutoCrop_Threshold";
const std::string NOISE = "Noise";
const std::string LOWPOWERMODE = "ilowpowermode";
//twain 弹框配置等参数
const std::string ROLLERMSGDATE = "RollerMsgDate";
const std::string PRINTFCAPABILITY = "PrintfCapability";
#pragma pack(push)
#pragma pack(4)
/******************
**参数保存结构体**
*******************/
typedef struct tagCONFIGPARAMS
{
/*基本选项卡参数*/
int Pixtype;
int PaperSize;
bool EnSizeCheck;
bool EnAutoCrop;
#ifdef UV
bool EnUVModel;
#endif
int Resolution;
int Duplex;
bool EnDiscardBlank;
bool EnDiscardBlankVince;
int DBlank_AreaNum;
int DBlank_DevnMax;
bool EnFlod;
bool EnSwitchFrontBack;
byte LowPowerMode;
/*亮度对比度选项卡参数*/
float Brightness;
bool EnAutoContrast;
float Contrast;
float Gamma;
/*图像处理选项卡参数*/
int Filter;
int Sharpen;
bool EnFillBlack;
bool EnAutoDescrew;
bool EnOutHole;
int OutHoleRatio;
bool EnMultiOutPutR;
bool EnHsvCorrect;
/*送纸部分选项卡参数*/
bool EnUltrasonicDetect;
bool EnBindingDetect;
int ScanCount;
int Orentation;
bool EnBackRotate180;
bool EnScrewDetect;
int ScrewDetectLevel;
/*保存信息*/
std::string Caption;
std::string SavePath;
}CONFIGPARAMS, * PCONFIGPARAMS;
typedef struct tagCONFIGINFO
{
std::string Caption;
std::string SavePath;
}CONFIGINFO, * PCONFIGINFO;
typedef struct tagFillHole
{
uint8_t is_fillhole;
int fillholeratio;
}FillHole;
typedef struct tagDetachNoise
{
byte is_detachnoise;
int detachnoise;
}DetachNoise;
enum LowPowerMode :unsigned int {
Min_None = 0,
Min_5,
Min_10,
Min_20,
Min_30,
Min_60,
Min_120,
Min_240
};
typedef struct tagHARDWAREPARAMS
{
byte capturepixtype;
byte en_doublefeed;
byte en_stapledetect;
byte en_skrewdetect;
byte skrewdetectlevel;
byte is_autopaper;
LowPowerMode lowpowermode;
#ifdef UV
byte en_uv;
#endif
}HardwareCaps;
typedef struct tagSkew_Detection {
uint8_t enable;
int level;
}SkewDetection;
typedef struct Scan_Rect {
int width;
int height;
int x;
int y;
}ScanRect;
enum PaperAlign :unsigned char {
Rot0 = 0,
Rot270 = 3,
AutoTextOrientation = 5
};
typedef enum Enchace_Color :short {
Enhance_None=0,
Enhance_Red,
Enhance_Green,
Enhance_Blue
}EnchaceColor;
typedef enum SharpenBlur :short {
Sharpen_None,
Sharpen_Normal,
Sharpen_More,
Sharpen_Blur,
Sharpen_Blur_More
}SharpenBlur;
struct GScanCap
{
uint8_t papertype; /**< the current paper source ADF or Flatbed*/
PaperAlign paperAlign;
bool en_fixedpaper; /**< 敦南固定幅面扫描*/
uint8_t en_sizecheck; /**< 尺寸检测*/
float imageRotateDegree;
uint8_t is_duplex; /**< True to use duplex false for simplex, ignored if flatbed*/
uint8_t en_fold; /**<对折*/
int pixtype; /**< type of pixels to transfer image as */
int automaticcolor; /**<顔色自動識別*/
int automaticcolortype; /**<顔色自動識別后非彩色上傳類型*/
//ScanRect scanrect;
float resolution_dst; /**< horizontal resolution */
float resolution_native;
float gamma; /**< Gamma */
float contrast; /**< Contrast */
float brightness; /**< Brightness */
float threshold; /**< Threshold */
bool fadeback; /**< 除底色*/
int fadeback_range; /**< 除底色范围*/
uint8_t is_autocontrast; /**< 自动对比度*/
uint8_t is_autocrop; /**< 自动裁切*/
bool normalCrop; /**<传统模式自动裁切*/
bool is_split; /**< 图像拆分*/
bool is_high_imagequality; /**< 画质优先*/
uint8_t is_autodiscradblank_normal; /**< 自动丢弃空白页通用*/
int discardblank_percent; /**<跳过空白页阀值*/
uint8_t is_autodiscradblank_vince; /**自动丢弃空白页发票*/
uint8_t is_switchfrontback; /**交换正反面*/
uint8_t autodescrew; /**< 自动纠偏*/
uint8_t multi_output_red; /*多流输出除红*/
bool en_multi_output; /**< 多流输出*/
int8_t multioutput;
uint8_t hsvcorrect; /**<答题卡除红*/
uint8_t filter; /**< 除色*/
uint8_t sharpen;
uint8_t enhance_color; /**< 颜色增强*/
uint8_t fillbackground; /**< 填黑框*/
bool is_convex; /**< 填黑框模式true为凸多边形填充false为凹多边形填充默认true*/
int noise; /**< 除噪像素能够消除noise宽度的背景竖条纹干扰默认40*/
int indent; /**< 轮廓缩进裁剪、纠偏或者黑底填充时对探索到的纸张轮廓进行缩进indent像素默认5*/
int AutoCrop_threshold; /**< 自动裁剪二值化阈值,取值范围(0, 255)默认40*/
unsigned short scannum; /**< 扫描张数*/
uint8_t is_backrotate180; /**< 背面旋转180*/
uint8_t is_dogeardetection; /**<折角检测*/
uint32_t dogeardistance; /**<折角检测范围*/
HardwareCaps hardwarecaps; /**< 硬件扫描参数*/
FillHole fillhole;
DetachNoise detachnoise; /**< 黑白降噪*/
uint8_t is_autotext; /**< 自动文本方向识别*/
int fillholeratio_up;
int fillholeratio_down;
int fillholeratio_left;
int fillholeratio_right;
bool en_fillholeratio_up;
bool en_fillholeratio_down;
bool en_fillholeratio_left;
bool en_fillholeratio_right;
std::string Caption;
std::string SavePath;
};
typedef struct tagCrop_Rect
{
int enable;
int x; /*****自定义裁切区域左上角x坐标*/
int y; /*****自定义裁切区域左上角y坐标*/
int width; /*****自定义裁切区域宽度*******/
int height; /*****自定义裁切区域高度*******/
}CropRect;
typedef enum tagMulti_Output {
Unused = -1,
All,
ColorGray,
ColorBw,
GrayBw
}MultiOutput;
struct GScanCap_3399
{
uint8_t papertype; /**< the current paper source ADF or Flatbed*/
PaperAlign paperAlign;
uint8_t en_sizecheck; /**< 尺寸检测*/
float imageRotateDegree;
uint8_t is_duplex; /**< True to use duplex false for simplex, ignored if flatbed*/
uint8_t en_fold; /**<对折*/
int pixtype; /**< type of pixels to transfer image as */
int automaticcolor; /**<顔色自動識別*/
int automaticcolortype; /**<顔色自動識別后非彩色上傳類型*/
//ScanRect scanrect;
float resolution_dst; /**< horizontal resolution */
float resolution_native;
float gamma; /**< Gamma */
float contrast; /**< Contrast */
float brightness; /**< Brightness */
float threshold; /**< Threshold */
uint8_t is_autocontrast; /**< 自动对比度*/
uint8_t is_autocrop; /**< 自动裁切*/
uint8_t is_autodiscradblank_normal; /**< 自动丢弃空白页通用*/
int discardblank_percent; /**<跳过空白页阀值*/
uint8_t is_autodiscradblank_vince;/**自动丢弃空白页发票*/
uint8_t is_switchfrontback; /**交换正反面*/
uint8_t autodescrew; /**< 自动纠偏*/
uint8_t multi_output_red; /*多流输出*/
uint8_t hsvcorrect; /**<答题卡除红*/
uint8_t filter; /**< 除色*/
uint8_t sharpen;
uint8_t enhance_color; /**< 颜色增强*/
uint8_t fillbackground; /**< 填黑框*/
bool is_convex; /**< 填黑框模式true为凸多边形填充false为凹多边形填充默认true*/
int noise; /**< 除噪像素能够消除noise宽度的背景竖条纹干扰默认40*/
int indent; /**< 轮廓缩进裁剪、纠偏或者黑底填充时对探索到的纸张轮廓进行缩进indent像素默认5*/
int AutoCrop_threshold; /**< 自动裁剪二值化阈值,取值范围(0, 255)默认40*/
unsigned short scannum; /**< 扫描张数*/
uint8_t is_backrotate180; /**< 背面旋转180*/
uint8_t is_dogeardetection; /**<折角检测*/
HardwareCaps hardwarecaps; /**< 硬件扫描参数*/
FillHole fillhole;
DetachNoise detachnoise; /**< 黑白降噪*/
uint8_t is_autotext; /**< 自动文本方向识别*/
bool isfillcolor; /**< 自动裁切颜色填充>*/
int refuseInflow; /**< 防止渗透>*/
int colorCorrection; /**< 色彩校正>*/
int removeMorr; /**< 去除摩尔纹>*/
int errorExtention; /**< 错误扩散>*/
int textureRemove; /**< 除网纹>*/
int splitImage; /**< 图像拆分>*/
CropRect cropRect; /**< 自定义裁切>*/
MultiOutput multiOutput; /**< 多流输出>*/
bool normalCrop; /**< 自动裁切深色样张>*/
uint32_t dogeardistabce; /**< 折角检测理论顶点到实际轮廓最新距离>*/
bool fadeback; /**< 除底色>*/
int fadebackrange; /**< 除底色范围>*/
bool isuploadexceptionimage; /**< 是否上传双张报错后的异常图像>*/
int fillholeratio_up; /**< 穿孔移除上下左右范围>*/
int fillholeratio_down;
int fillholeratio_left;
int fillholeratio_right;
uint32_t reserve[1024]; /**< 预留4096字节做协议扩展*/
};
typedef struct Paper_Status {
Paper_Status(unsigned int paper, unsigned int orentate) :Paper(paper), Orentate(orentate) {}
Paper_Status():Paper(0), Orentate(0){}
unsigned int Paper;
unsigned int Orentate;
friend bool operator<(const struct Paper_Status& a, const struct Paper_Status& b) {
if (a.Paper < b.Paper ||
(a.Paper == b.Paper && a.Orentate < b.Orentate)) {
return true;
}
return false;
}
}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=17,
};
enum G400_DPI {
G400_D300 = 0,
G400_D200,
G400_D600
};
#pragma pack(pop)
#define CAPTION_LEN 256
#define TWAIN_IMAGE_FILE_LIST_NAME TEXT(".dat")
#ifndef malloc_my
#define malloc_my malloc
#endif
//取得当前模块的文件路径, 参数,模块实列举并, 文件路径, 字符串的长度
TCHAR* GetCurExeFilePath(HINSTANCE hInstance, TCHAR* lpPath, DWORD dwSize);
//取得路径中已经存在的路径,并返回
TCHAR* GetExistFileDir(TCHAR* p_file_path);
//回调函数,取得用户自定义的文件路径
DWORD CALLBACK BrowserCallbackProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ;
BOOL isFolderExist(char* folder);
BOOL isFileExist(std::string folder);
int32_t createDirectory(char* directoryPath);
std::string UtfToString(std::string strValue);
std::string StringToUtf(std::string strValue);
//检查,创建文件夹, 参数 文件路径, = 真,创建p_file_path不寻在文件路径
BOOL CheckAndCreateFileDir(TCHAR* p_file_path, BOOL flg);
BOOL CheckDiskFreeBitM(HWND hWin, TCHAR *p_disk_name, DWORD dw_min_bit_m);
HBITMAP SetButtonStaticBkBmp(HINSTANCE hInst, HWND hWin, UINT id, UINT iamge_id);
void writelog(std::string msg);
std::string TCHAR2STRING(TCHAR* STR);
float GetContrast(int level);
char* GBKToUTF8(const char* chGBK);
int GetMappingBrightnessValue(float in);
int GetMappingContrastValue(float in);
int GetContrastLevel(float contrast);
CString GetHidedlgPath();
string getOSInfo();
string getManufactureID();
string getCpuType();
string getMemoryInfo();
void GetDiskInfo(DWORD& dwNum, CString chDriveInfo[]);
static VOID XdPrint(_TCHAR* format, ...) {
va_list args;
va_start(args, format);
_TCHAR buf[256];
_vstprintf(buf, format, args);
OutputDebugString(buf);
va_end(args);
}
#endif