twain3.0/huagao/Device/PublicFunc.h

309 lines
9.5 KiB
C
Raw Permalink Normal View History

#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 namespace std;
/************************************
**ɨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>json<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>**
*************************************/
//<!<21><><EFBFBD><EFBFBD>ѡ<EFBFBD>
const std::string PIXTYPE = "iPixType";
const std::string AUTOMATICCOLOR = "iautomaticcolor";
const std::string AUTOMATICCOLORTYPR = "iautomaticcolortype";
const std::string PAPARSIZE = "iPaparSize";
const std::string ENSIZECHECK = "iEnSizeCheck";
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 SWITCHFRONTBACK = "bSwitchFrontBack";
//<!<21><><EFBFBD>ȶԱȶ<D4B1>ѡ<EFBFBD>
const std::string AUTOCONTRAST = "bAutoContrast";
const std::string BRIGHTNESS = "iBrightness";
const std::string CONTRAST = "iContrast";
const std::string GAMMA_ = "dGamma";
//<!ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>
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 OUTHOLE = "bOutHole";
const std::string OUTHOLERATIO = "iOutHoleRatio";
const std::string DETACHNOISE = "detachnoise";
const std::string DETACHNOISEVALUE = "detachnoisevalue";
const std::string HSVCORRECT = "bHsvCorrect";
//<!<21><>ֽѡ<D6BD>
const std::string ULTRADETECT = "bUltrasonicDetect";
const std::string BINDINGDETECT = "bBindingDetect";
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 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";
/******************
**<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>**
*******************/
typedef struct tagCONFIGPARAMS
{
/*<2A><><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EEBFA8><EFBFBD><EFBFBD>*/
int Pixtype;
int PaperSize;
bool EnSizeCheck;
bool EnAutoCrop;
int Resolution;
int Duplex;
bool EnDiscardBlank;
bool EnDiscardBlankVince;
int DBlank_AreaNum;
int DBlank_DevnMax;
bool EnFlod;
bool EnSwitchFrontBack;
/*<2A><><EFBFBD>ȶԱȶ<D4B1>ѡ<EFBFBD><EFBFBD><EEBFA8><EFBFBD><EFBFBD>*/
float Brightness;
bool EnAutoContrast;
float Contrast;
float Gamma;
/*ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EEBFA8><EFBFBD><EFBFBD>*/
int Filter;
int Sharpen;
bool EnFillBlack;
bool EnAutoDescrew;
bool EnOutHole;
int OutHoleRatio;
bool EnMultiOutPutR;
bool EnHsvCorrect;
/*<2A><>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EEBFA8><EFBFBD><EFBFBD>*/
bool EnUltrasonicDetect;
bool EnBindingDetect;
int ScanCount;
int Orentation;
bool EnBackRotate180;
bool EnScrewDetect;
int ScrewDetectLevel;
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ*/
std::string Caption;
std::string SavePath;
}CONFIGPARAMS, * PCONFIGPARAMS;
typedef struct tagCONFIGINFO
{
std::string Caption;
std::string SavePath;
}CONFIGINFO, * PCONFIGINFO;
typedef struct tagFillHole
{
byte is_fillhole;
int fillholeratio;
}FillHole;
typedef struct tagDetachNoise
{
byte is_detachnoise;
int detachnoise;
}DetachNoise;
typedef struct tagHARDWAREPARAMS
{
byte capturepixtype;
byte en_doublefeed;
byte en_stapledetect;
byte en_skrewdetect;
byte skrewdetectlevel;
}HardwareCaps;
typedef struct Scan_Rect {
int width;
int height;
int x;
int y;
}ScanRect;
enum PaperAlign :byte {
Rot0 = 0,
Rot270 = 3,
AutoTextOrientation = 5
};
typedef enum Enchace_Color :short {
2020-09-21 01:25:46 +00:00
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
{
byte papertype; /**< the current paper source ADF or Flatbed*/
PaperAlign paperAlign;
byte en_sizecheck; /**< <20>ߴ<EFBFBD><DFB4><EFBFBD><EFBFBD><EFBFBD>*/
float imageRotateDegree;
byte is_duplex; /**< True to use duplex false for simplex, ignored if flatbed*/
byte en_fold;
int pixtype; /**< type of pixels to transfer image as */
int automaticcolor; /**<<3C><>ɫ<EFBFBD>Ԅ<EFBFBD><D484>R<EFBFBD>e*/
int automaticcolortype; /**<<3C><>ɫ<EFBFBD>Ԅ<EFBFBD><D484>R<EFBFBD>e<EFBFBD><65><EFBFBD>Dz<EFBFBD>ɫ<EFBFBD>ς<EFBFBD><CF82><EFBFBD><EFBFBD><EFBFBD>*/
//ScanRect scanrect;
float resolution_dst; /**< horizontal resolution */
float resolution_native;
float gamma; /**< Gamma */
float contrast; /**< Contrast */
float brightness; /**< Brightness */
float threshold; /**< Threshold */
byte is_autocontrast; /**< <20>Զ<EFBFBD><D4B6>Աȶ<D4B1>*/
byte is_autocrop; /**< <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>*/
byte is_autodiscradblank_normal; /**< <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>հ<EFBFBD>ҳͨ<D2B3><CDA8>*/
int discardblank_percent; /**<<3C><><EFBFBD><EFBFBD><EFBFBD>հ<EFBFBD>ҳ<EFBFBD><D2B3>ֵ*/
byte is_autodiscradblank_vince;/**<2A>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>հ<EFBFBD>ҳ<EFBFBD><D2B3>Ʊ*/
byte is_switchfrontback; /**<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
byte autodescrew; /**< <20>Զ<EFBFBD><D4B6><EFBFBD>ƫ*/
byte multi_output_red; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
byte hsvcorrect; /**<<3C><><EFBFBD><EFBFBD><E2BFA8><EFBFBD><EFBFBD>*/
byte filter; /**< <20><>ɫ*/
byte sharpen;
byte enhance_color; /**< <20><>ɫ<EFBFBD><C9AB>ǿ*/
byte fillbackground; /**< <20><><EFBFBD>ڿ<EFBFBD>*/
bool is_convex; /**< <20><><EFBFBD>ڿ<EFBFBD>ģʽ<C4A3><CABD>trueΪ͹<CEAA><CDB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䣬falseΪ<65><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>䣬Ĭ<E4A3AC><C4AC>true*/
int noise; /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><D8A3>ܹ<EFBFBD><DCB9><EFBFBD><EFBFBD><EFBFBD>noise<73><65><EFBFBD>ȵı<C8B5><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƹ<EFBFBD><C6B8>ţ<EFBFBD>Ĭ<EFBFBD><C4AC>40*/
int indent; /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD>ߺڵ<DFBA><DAB5><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>̽<EFBFBD><CCBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>indent<6E><74><EFBFBD>أ<EFBFBD>Ĭ<EFBFBD><C4AC>5*/
int AutoCrop_threshold; /**< <20>Զ<EFBFBD><D4B6>ü<EFBFBD><C3BC><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ȡֵ<C8A1><D6B5>Χ(0, 255)<29><>Ĭ<EFBFBD><C4AC>40*/
unsigned short scannum; /**< ɨ<><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
byte is_backrotate180; /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת180*/
byte is_dogeardetection; /**<<3C>۽Ǽ<DBBD><C7BC><EFBFBD>*/
HardwareCaps hardwarecaps; /**< Ӳ<><D3B2>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
FillHole fillhole;
DetachNoise detachnoise; /**< <20>ڰ׽<DAB0><D7BD><EFBFBD>*/
byte is_autotext; /**< <20>Զ<EFBFBD><D4B6>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><CAB6>*/
std::string Caption;
std::string SavePath;
};
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
};
enum G400_DPI {
G400_D300 = 0,
G400_D200,
G400_D600
};
#define CAPTION_LEN 256
#define TWAIN_IMAGE_FILE_LIST_NAME TEXT(".dat")
#ifndef malloc_my
#define malloc_my malloc
#endif
//ȡ<>õ<EFBFBD>ǰģ<C7B0><C4A3><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7>, <20><><EFBFBD><EFBFBD><><C4A3>ʵ<EFBFBD>оٲ<D0BE>, <20>ļ<EFBFBD>·<EFBFBD><C2B7>, <20>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>
TCHAR* GetCurExeFilePath(HINSTANCE hInstance, TCHAR* lpPath, DWORD dwSize);
//ȡ<><C8A1>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ڵ<EFBFBD>·<EFBFBD><C2B7>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TCHAR* GetExistFileDir(TCHAR* p_file_path);
//<2F>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><><C8A1><EFBFBD>û<EFBFBD><C3BB>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7>
DWORD CALLBACK BrowserCallbackProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ;
BOOL isFolderExist(char* folder);
int32_t createDirectory(char* directoryPath);
std::string UtfToString(std::string strValue);
std::string StringToUtf(std::string strValue);
//<2F><><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>, <20><><EFBFBD><EFBFBD> <20>ļ<EFBFBD>·<EFBFBD><C2B7>, = <20><>,<2C><><EFBFBD><EFBFBD>p_file_path<74><68>Ѱ<EFBFBD><D1B0><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7>
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);
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