#pragma once #include "base/HGDef.h" #include "base/HGInc.h" #include "base/HGLock.h" #include "base/HGImage.h" #include "base/HGMsgPump.h" #include "base/HGEvent.h" #include "sane/sane_ex.h" #include "sane/sane_option_definitions.h" #include "Manager.h" #include "Msg.h" #include #include namespace ver_2 { enum { SANEEVENT_ARRIVE = 1L, SANEEVENT_REMOVE, SANEEVENT_STATUS, SANEEVENT_WORKING, SANEEVENT_FINISH, SANEEVENT_ERROR }; struct GlobalConfig { 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, }; GlobalConfig() { imageJpegQuality = 0; imageTiffJpegQuality = 0; uploadHttpPort = 0; uploadFtpPort = 0; } // 文件保存 std::string fileSavePath; std::string fileNamePrefix; std::string fileNameMode; // 图像保存 std::string imageFormat; int imageJpegQuality; std::string imageTiffCompression; int imageTiffJpegQuality; // 上传 std::string uploadHttpHost; unsigned short uploadHttpPort; std::string uploadHttpPath; std::string uploadFtpUser; std::string uploadFtpPassword; std::string uploadFtpHost; unsigned short uploadFtpPort; }; struct DeviceParam { 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, }; DeviceParam() { Reset(); } void Reset() { 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; } // 颜色模式 std::vector colorModeList; std::string colorMode; // 扫描页面 std::vector pageModeList; std::string pageMode; // 分辨率 std::vector resolutionList; int resolution; // 亮度 int brightnessMin; int brightnessMax; int brightness; // 对比度 int contrastMin; int contrastMax; int contrast; // 伽马 double gammaMin; double gammaMax; double gamma; // 纸张尺寸 std::vector paperSizeList; std::string paperSize; double paperSizeWidth; double paperSizeHeight; // 手动裁剪 bool paperCutEnabled; double paperCutLeft; double paperCutTop; double paperCutRight; double paperCutBottom; // 是否纠偏 bool autoCrop; }; typedef void (*SaneEvent)(int code, const char *str, bool err, void* param); typedef void (*SaneImageCallback)(const char* path, void* param); class ManagerV2 : public Manager { public: ManagerV2(HGMsgPump msgPump); virtual ~ManagerV2(); // 关闭设备 void CloseDev(const CloseDevParam* param); // 扫描完成 void ScanFinish(const ScanFinishParam* param); // 设置回调 void SetSaneEvent(SaneEvent event, void* param); void SetSaneImageCallback(SaneImageCallback func, void* param); // 清理回调 void ResetSaneEvent(); void ResetSaneImageCallback(); // 设置全局配置 int SetGlobalConfig(const GlobalConfig& cfg, HGUInt mask, std::string &errInfo); // 获取全局配置 int GetGlobalConfig(GlobalConfig& cfg, std::string& errInfo); // 加载本地图像 int LoadLocalImage(const std::string& imagePath, std::string& imgBase64, std::string& errInfo); // 保存本地图像 int SaveLocalImage(const std::string& imgBase64, std::string& imagePath, std::string& errInfo); // 删除本地文件 int DeleteLocalFile(const std::string& filePath, std::string& errInfo); // 清理全局文件保存目录 int ClearGlobalFileSavePath(std::string& errInfo); // 合成本地图像 int MergeLocalImage(const std::vector& imagePathList, const std::string& mode, const std::string& align, int interval, std::string& outImagePath, std::string& errInfo); // 本地合成多张图像 int LocalMakeMultiImage(const std::vector& imagePathList, const std::string& format, const std::string& tiffCompression, int tiffJpegQuality, std::string& outImagePath, std::string& errInfo); // 拆分本地图像 int SplitLocalImage(const std::string& imagePath, const std::string& mode, int location, std::vector& outImagePathList, std::string& errInfo); // 本地生成压缩文件 int LocalMakeZipFile(const std::vector& filePathList, std::string& outZipPath, std::string& errInfo); // 本地图像纠偏 int LocalImageDeskew(const std::string& imagePath, std::string& outImagePath, std::string& errInfo); // 上传文件 int UploadLocalFile(const std::string& filePath, const std::string& mode, const std::string& remoteFilePath, std::string& errInfo); // 设备初始化 int InitDevice(std::string& errInfo); // 设备反初始化 int DeinitDevice(std::string& errInfo); // 获取设备列表 int GetDeviceNameList(std::vector &deviceNameList, std::string& errInfo); // 打开设备 int OpenDevice(const std::string& deviceName, std::string& errInfo); // 关闭设备 int CloseDevice(std::string& errInfo); // 设置设备参数 int SetDeviceParam(const DeviceParam& param, HGUInt mask, std::string& errInfo); // 获取设备参数 int GetDeviceParam(DeviceParam& param, std::string& errInfo); // 获取当前设备名 int GetCurrDeviceName(std::string& deviceName, std::string& errInfo); // 开始扫描 int StartScan(std::string& errInfo); // 停止扫描 int StopScan(std::string& errInfo); private: 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); static double GetCfgDoubleValue(const std::string& app, const std::string& key, double def); 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); static bool SetCfgDoubleValue(const std::string& app, const std::string& key, double val); static bool SetCfgBoolValue(const std::string& app, const std::string& key, bool val); static int LoadBase64(const std::string& fileName, std::string& base64); static int SaveBase64(const std::string& base64, const std::string& fileName); 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); std::string GetFilePath(const std::string& suffix); int SaveImage(HGImage image, std::string &imagePath); static void LoadSaveFilePathList(std::vector &savePathList); static void RestoreSaveFilePathList(const std::vector& savePathList); 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); static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param); private: HGLock m_lock; GlobalConfig m_globalCfg; std::vector m_saveFilePathList; SaneEvent m_saneEvent; void* m_saneParam; SaneImageCallback m_saneImageCallback; void* m_saneImageParam; bool m_initDevice; std::vector m_devNameList; bool m_openDevice; SANE_Handle m_devHandle; std::string m_devName; DeviceParam m_devParam; bool m_scanning; HGEvent m_scanEvent; }; }