2022-05-24 02:01:36 +00:00
|
|
|
|
#pragma once
|
2022-05-23 10:29:23 +00:00
|
|
|
|
|
|
|
|
|
#include "base/HGDef.h"
|
|
|
|
|
#include "base/HGInc.h"
|
|
|
|
|
#include "base/HGLock.h"
|
|
|
|
|
#include "base/HGImage.h"
|
|
|
|
|
#include "base/HGMsgPump.h"
|
2022-06-01 10:36:22 +00:00
|
|
|
|
#include "base/HGEvent.h"
|
2022-05-23 10:29:23 +00:00
|
|
|
|
#include "sane/sane_ex.h"
|
|
|
|
|
#include "sane/sane_option_definitions.h"
|
|
|
|
|
#include "Manager.h"
|
|
|
|
|
#include "Msg.h"
|
|
|
|
|
#include <string>
|
2022-05-23 11:01:52 +00:00
|
|
|
|
#include <vector>
|
2022-05-23 10:29:23 +00:00
|
|
|
|
|
|
|
|
|
namespace ver_2
|
|
|
|
|
{
|
2022-05-30 11:01:23 +00:00
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
SANEEVENT_ARRIVE = 1L,
|
|
|
|
|
SANEEVENT_REMOVE,
|
|
|
|
|
SANEEVENT_STATUS,
|
|
|
|
|
SANEEVENT_WORKING,
|
|
|
|
|
SANEEVENT_FINISH,
|
|
|
|
|
SANEEVENT_ERROR
|
|
|
|
|
};
|
|
|
|
|
|
2022-05-23 10:29:23 +00:00
|
|
|
|
struct GlobalConfig
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
fileSavePathMask = 0x00000001,
|
|
|
|
|
fileNamePrefixMask = 0x00000002,
|
|
|
|
|
fileNameModeMask = 0x00000004,
|
|
|
|
|
imageFormatMask = 0x00000008,
|
|
|
|
|
imageJpegQualityMask = 0x00000010,
|
|
|
|
|
imageTiffCompressionMask = 0x00000020,
|
|
|
|
|
imageTiffJpegQualityMask = 0x00000040,
|
|
|
|
|
uploadHttpHostMask = 0x00000080,
|
|
|
|
|
uploadHttpPortMask = 0x00000100,
|
|
|
|
|
uploadHttpPathMask = 0x00000200,
|
|
|
|
|
uploadFtpUserMask = 0x00000400,
|
|
|
|
|
uploadFtpPasswordMask = 0x00000800,
|
|
|
|
|
uploadFtpHostMask = 0x00001000,
|
|
|
|
|
uploadFtpPortMask = 0x00002000,
|
|
|
|
|
};
|
|
|
|
|
|
2022-05-30 11:01:23 +00:00
|
|
|
|
GlobalConfig()
|
|
|
|
|
{
|
|
|
|
|
imageJpegQuality = 0;
|
|
|
|
|
imageTiffJpegQuality = 0;
|
|
|
|
|
uploadHttpPort = 0;
|
|
|
|
|
uploadFtpPort = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 文件保存
|
2022-05-23 10:29:23 +00:00
|
|
|
|
std::string fileSavePath;
|
|
|
|
|
std::string fileNamePrefix;
|
|
|
|
|
std::string fileNameMode;
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 图像保存
|
2022-05-23 10:29:23 +00:00
|
|
|
|
std::string imageFormat;
|
|
|
|
|
int imageJpegQuality;
|
|
|
|
|
std::string imageTiffCompression;
|
|
|
|
|
int imageTiffJpegQuality;
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 上传
|
2022-05-23 10:29:23 +00:00
|
|
|
|
std::string uploadHttpHost;
|
|
|
|
|
unsigned short uploadHttpPort;
|
|
|
|
|
std::string uploadHttpPath;
|
|
|
|
|
std::string uploadFtpUser;
|
|
|
|
|
std::string uploadFtpPassword;
|
|
|
|
|
std::string uploadFtpHost;
|
|
|
|
|
unsigned short uploadFtpPort;
|
|
|
|
|
};
|
|
|
|
|
|
2022-05-30 11:01:23 +00:00
|
|
|
|
struct DeviceParam
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
colorModeMask = 0x00000001,
|
|
|
|
|
pageModeMask = 0x00000002,
|
|
|
|
|
resolutionMask = 0x00000004,
|
|
|
|
|
brightnessMask = 0x00000008,
|
|
|
|
|
contrastMask = 0x00000010,
|
|
|
|
|
gammaMask = 0x00000020,
|
|
|
|
|
paperSizeMask = 0x00000040,
|
|
|
|
|
paperCutEnabledMask = 0x00000080,
|
|
|
|
|
paperCutLeftMask = 0x00000100,
|
|
|
|
|
paperCutTopMask = 0x00000200,
|
|
|
|
|
paperCutRightMask = 0x00000400,
|
|
|
|
|
paperCutBottomMask = 0x00000800,
|
|
|
|
|
autoCropMask = 0x00001000,
|
|
|
|
|
};
|
|
|
|
|
|
2022-05-30 11:01:23 +00:00
|
|
|
|
DeviceParam()
|
|
|
|
|
{
|
|
|
|
|
Reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Reset()
|
|
|
|
|
{
|
2022-06-06 10:51:34 +00:00
|
|
|
|
colorModeList.clear();
|
|
|
|
|
colorMode.clear();
|
|
|
|
|
pageModeList.clear();
|
|
|
|
|
pageMode.clear();
|
|
|
|
|
resolutionList.clear();
|
|
|
|
|
resolution = 0;
|
|
|
|
|
brightnessMin = 0;
|
|
|
|
|
brightnessMax = 0;
|
|
|
|
|
brightness = 0;
|
|
|
|
|
contrastMin = 0;
|
|
|
|
|
contrastMax = 0;
|
|
|
|
|
contrast = 0;
|
|
|
|
|
gammaMin = 0;
|
|
|
|
|
gammaMax = 0;
|
|
|
|
|
gamma = 0;
|
|
|
|
|
paperSizeList.clear();
|
|
|
|
|
paperSize.clear();
|
|
|
|
|
paperSizeWidth = 0;
|
|
|
|
|
paperSizeHeight = 0;
|
|
|
|
|
paperCutEnabled = false;
|
|
|
|
|
paperCutLeft = 0;
|
|
|
|
|
paperCutTop = 0;
|
|
|
|
|
paperCutRight = 0;
|
|
|
|
|
paperCutBottom = 0;
|
|
|
|
|
autoCrop = false;
|
2022-05-30 11:01:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 颜色模式
|
|
|
|
|
std::vector<std::string> colorModeList;
|
|
|
|
|
std::string colorMode;
|
|
|
|
|
// 扫描页面
|
|
|
|
|
std::vector<std::string> pageModeList;
|
|
|
|
|
std::string pageMode;
|
|
|
|
|
// 分辨率
|
|
|
|
|
std::vector<int> resolutionList;
|
|
|
|
|
int resolution;
|
|
|
|
|
// 亮度
|
|
|
|
|
int brightnessMin;
|
|
|
|
|
int brightnessMax;
|
|
|
|
|
int brightness;
|
|
|
|
|
// 对比度
|
|
|
|
|
int contrastMin;
|
|
|
|
|
int contrastMax;
|
|
|
|
|
int contrast;
|
|
|
|
|
// 伽马
|
2022-06-06 10:51:34 +00:00
|
|
|
|
double gammaMin;
|
|
|
|
|
double gammaMax;
|
|
|
|
|
double gamma;
|
2022-05-30 11:01:23 +00:00
|
|
|
|
// 纸张尺寸
|
|
|
|
|
std::vector<std::string> paperSizeList;
|
2022-06-06 10:51:34 +00:00
|
|
|
|
std::string paperSize;
|
|
|
|
|
double paperSizeWidth;
|
|
|
|
|
double paperSizeHeight;
|
2022-05-30 11:01:23 +00:00
|
|
|
|
// 手动裁剪
|
|
|
|
|
bool paperCutEnabled;
|
2022-06-06 10:51:34 +00:00
|
|
|
|
double paperCutLeft;
|
|
|
|
|
double paperCutTop;
|
|
|
|
|
double paperCutRight;
|
|
|
|
|
double paperCutBottom;
|
2022-05-30 11:01:23 +00:00
|
|
|
|
// 是否纠偏
|
|
|
|
|
bool autoCrop;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef void (*SaneEvent)(int code, const char *str, bool err, void* param);
|
|
|
|
|
typedef void (*SaneImageCallback)(const char* path, void* param);
|
|
|
|
|
|
2022-05-23 10:29:23 +00:00
|
|
|
|
class ManagerV2 : public Manager
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ManagerV2(HGMsgPump msgPump);
|
|
|
|
|
virtual ~ManagerV2();
|
|
|
|
|
|
2022-06-01 10:36:22 +00:00
|
|
|
|
// 关闭设备
|
|
|
|
|
void CloseDev(const CloseDevParam* param);
|
2022-06-06 11:34:54 +00:00
|
|
|
|
// 扫描完成
|
|
|
|
|
void ScanFinish(const ScanFinishParam* param);
|
2022-06-01 10:36:22 +00:00
|
|
|
|
|
2022-05-30 11:01:23 +00:00
|
|
|
|
// 设置回调
|
|
|
|
|
void SetSaneEvent(SaneEvent event, void* param);
|
|
|
|
|
void SetSaneImageCallback(SaneImageCallback func, void* param);
|
|
|
|
|
// 清理回调
|
|
|
|
|
void ResetSaneEvent();
|
|
|
|
|
void ResetSaneImageCallback();
|
2022-05-23 10:29:23 +00:00
|
|
|
|
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 设置全局配置
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int SetGlobalConfig(const GlobalConfig& cfg, HGUInt mask, std::string &errInfo);
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 获取全局配置
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int GetGlobalConfig(GlobalConfig& cfg, std::string& errInfo);
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 加载本地图像
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int LoadLocalImage(const std::string& imagePath, std::string& imgBase64, std::string& errInfo);
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 保存本地图像
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int SaveLocalImage(const std::string& imgBase64, std::string& imagePath, std::string& errInfo);
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 删除本地文件
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int DeleteLocalFile(const std::string& filePath, std::string& errInfo);
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 清理全局文件保存目录
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int ClearGlobalFileSavePath(std::string& errInfo);
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 合成本地图像
|
2022-05-23 11:01:52 +00:00
|
|
|
|
int MergeLocalImage(const std::vector<std::string>& imagePathList, const std::string& mode,
|
2022-06-06 10:51:34 +00:00
|
|
|
|
const std::string& align, int interval, std::string& outImagePath, std::string& errInfo);
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 本地合成多张图像
|
2022-05-23 11:01:52 +00:00
|
|
|
|
int LocalMakeMultiImage(const std::vector<std::string>& imagePathList, const std::string& format,
|
2022-06-06 10:51:34 +00:00
|
|
|
|
const std::string& tiffCompression, int tiffJpegQuality, std::string& outImagePath, std::string& errInfo);
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 拆分本地图像
|
2022-05-23 11:01:52 +00:00
|
|
|
|
int SplitLocalImage(const std::string& imagePath, const std::string& mode, int location,
|
2022-06-06 10:51:34 +00:00
|
|
|
|
std::vector<std::string>& outImagePathList, std::string& errInfo);
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 本地生成压缩文件
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int LocalMakeZipFile(const std::vector<std::string>& filePathList, std::string& outZipPath, std::string& errInfo);
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 本地图像纠偏
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int LocalImageDeskew(const std::string& imagePath, std::string& outImagePath, std::string& errInfo);
|
2022-05-24 02:01:36 +00:00
|
|
|
|
// 上传文件
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int UploadLocalFile(const std::string& filePath, const std::string& mode, const std::string& remoteFilePath, std::string& errInfo);
|
2022-05-23 10:29:23 +00:00
|
|
|
|
|
2022-05-30 11:01:23 +00:00
|
|
|
|
// 设备初始化
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int InitDevice(std::string& errInfo);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
// 设备反初始化
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int DeinitDevice(std::string& errInfo);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
// 获取设备列表
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int GetDeviceNameList(std::vector<std::string> &deviceNameList, std::string& errInfo);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
// 打开设备
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int OpenDevice(const std::string& deviceName, std::string& errInfo);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
// 关闭设备
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int CloseDevice(std::string& errInfo);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
// 设置设备参数
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int SetDeviceParam(const DeviceParam& param, HGUInt mask, std::string& errInfo);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
// 获取设备参数
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int GetDeviceParam(DeviceParam& param, std::string& errInfo);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
// 获取当前设备名
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int GetCurrDeviceName(std::string& deviceName, std::string& errInfo);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
// 开始扫描
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int StartScan(std::string& errInfo);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
// 停止扫描
|
2022-06-06 10:51:34 +00:00
|
|
|
|
int StopScan(std::string& errInfo);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
|
2022-05-23 10:29:23 +00:00
|
|
|
|
private:
|
2022-05-23 11:01:52 +00:00
|
|
|
|
static std::string GetCfgStringValue(const std::string& app, const std::string& key, const std::string& def);
|
|
|
|
|
static int GetCfgIntValue(const std::string& app, const std::string& key, int def);
|
2022-06-06 10:51:34 +00:00
|
|
|
|
static double GetCfgDoubleValue(const std::string& app, const std::string& key, double def);
|
2022-05-23 11:01:52 +00:00
|
|
|
|
static bool GetCfgBoolValue(const std::string& app, const std::string& key, bool def);
|
|
|
|
|
static bool SetCfgStringValue(const std::string& app, const std::string& key, const std::string& val);
|
|
|
|
|
static bool SetCfgIntValue(const std::string& app, const std::string& key, int val);
|
2022-06-06 10:51:34 +00:00
|
|
|
|
static bool SetCfgDoubleValue(const std::string& app, const std::string& key, double val);
|
2022-05-23 11:01:52 +00:00
|
|
|
|
static bool SetCfgBoolValue(const std::string& app, const std::string& key, bool val);
|
2022-06-06 10:51:34 +00:00
|
|
|
|
|
2022-05-23 11:01:52 +00:00
|
|
|
|
static int LoadBase64(const std::string& fileName, std::string& base64);
|
|
|
|
|
static int SaveBase64(const std::string& base64, const std::string& fileName);
|
2022-06-01 10:36:22 +00:00
|
|
|
|
static int HttpUpload(const std::string &host, int port, const std::string &path,
|
|
|
|
|
const std::string& filePath, const std::string& remoteFilePath);
|
|
|
|
|
static int FtpUpload(const std::string& user, const std::string& password, const std::string& host, int port,
|
|
|
|
|
const std::string& filePath, const std::string& remoteFilePath);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
std::string GetFilePath(const std::string& suffix);
|
2022-06-01 10:36:22 +00:00
|
|
|
|
int SaveImage(HGImage image, std::string &imagePath);
|
|
|
|
|
static void LoadSaveFilePathList(std::vector<std::string> &savePathList);
|
|
|
|
|
static void RestoreSaveFilePathList(const std::vector<std::string>& savePathList);
|
2022-06-06 10:51:34 +00:00
|
|
|
|
static void LoadDeviceParam(const std::string &devName, DeviceParam &devParam);
|
|
|
|
|
static void RestoreDeviceParam(const std::string& devName, const DeviceParam& devParam);
|
|
|
|
|
static int SetParamToDevice(SANE_Handle hdev, const DeviceParam& devParam, HGUInt mask);
|
|
|
|
|
static int GetParamFromDevice(SANE_Handle hdev, DeviceParam& devParam);
|
2022-05-30 11:01:23 +00:00
|
|
|
|
static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param);
|
2022-05-23 10:29:23 +00:00
|
|
|
|
|
|
|
|
|
private:
|
2022-05-30 11:01:23 +00:00
|
|
|
|
HGLock m_lock;
|
|
|
|
|
GlobalConfig m_globalCfg;
|
|
|
|
|
std::vector<std::string> m_saveFilePathList;
|
|
|
|
|
SaneEvent m_saneEvent;
|
|
|
|
|
void* m_saneParam;
|
|
|
|
|
SaneImageCallback m_saneImageCallback;
|
|
|
|
|
void* m_saneImageParam;
|
|
|
|
|
|
|
|
|
|
bool m_initDevice;
|
|
|
|
|
std::vector<std::string> m_devNameList;
|
|
|
|
|
bool m_openDevice;
|
|
|
|
|
SANE_Handle m_devHandle;
|
|
|
|
|
std::string m_devName;
|
|
|
|
|
DeviceParam m_devParam;
|
|
|
|
|
bool m_scanning;
|
2022-06-01 10:36:22 +00:00
|
|
|
|
HGEvent m_scanEvent;
|
2022-05-23 10:29:23 +00:00
|
|
|
|
};
|
|
|
|
|
}
|