332 lines
7.4 KiB
C++
332 lines
7.4 KiB
C++
#include "HGScannerLib.h"
|
||
#include "base/HGInc.h"
|
||
#include "base/HGImage.h"
|
||
#include "imgfmt/HGImgFmt.h"
|
||
#include "imgproc/HGOCR.h"
|
||
#include "HGString.h"
|
||
#include "HGLibDeviceImpl.hpp"
|
||
|
||
#pragma pack(push)
|
||
#pragma pack(4)
|
||
struct HGLibSaveImageParam_V1
|
||
{
|
||
HGUInt size; /* 结构体大小 */
|
||
HGUInt jpegQuality; /* jpeg下有效, 0-100 */
|
||
HGUInt tiffCompression; /* tiff下有效, HGLIB_TIFFCOMPRESSION_* */
|
||
HGUInt tiffJpegQuality; /* tiff且HGLIB_TIFFCOMPRESSION_JPEG下有效, 0-100 */
|
||
HGBool ocr; /* 是否OCR,pdf和ofd格式有效 */
|
||
};
|
||
#pragma pack(pop)
|
||
|
||
HGLibImage HGAPI HGLib_LoadImage(const HGChar* filePath)
|
||
{
|
||
if (NULL == filePath)
|
||
{
|
||
return NULL;
|
||
}
|
||
|
||
HGImage image = NULL;
|
||
HGImgFmt_LoadImage(Utf8ToStdString(filePath).c_str(), 0, NULL, 0, HGBASE_IMGORIGIN_TOP, &image);
|
||
return (HGLibImage)image;
|
||
}
|
||
|
||
HGByte* HGAPI HGLib_GetImageData(HGLibImage image)
|
||
{
|
||
if (NULL == image)
|
||
{
|
||
return NULL;
|
||
}
|
||
|
||
HGByte* data = NULL;
|
||
HGBase_GetImageData((HGImage)image, &data);
|
||
return data;
|
||
}
|
||
|
||
HGBool HGAPI HGLib_GetImageInfo(HGLibImage image, HGLibImageInfo* imageInfo)
|
||
{
|
||
if (NULL == image || NULL == imageInfo)
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
HGImageInfo imgInfo;
|
||
if (HGBASE_ERR_OK != HGBase_GetImageInfo((HGImage)image, &imgInfo))
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
imageInfo->width = imgInfo.width;
|
||
imageInfo->height = imgInfo.height;
|
||
imageInfo->type = imgInfo.type;
|
||
imageInfo->origin = imgInfo.origin;
|
||
imageInfo->widthStep = imgInfo.widthStep;
|
||
return HGTRUE;
|
||
}
|
||
|
||
HGBool HGAPI HGLib_SaveImage(HGLibImage image, const HGChar* savePath, const HGLibSaveImageParam* saveParam)
|
||
{
|
||
if (NULL == image || NULL == savePath)
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
HGUInt fmtType = 0;
|
||
HGImgFmt_GetImgFmtTypeFromFileName(Utf8ToStdString(savePath).c_str(), &fmtType);
|
||
if (fmtType < HGIMGFMT_TYPE_JPEG || fmtType > HGIMGFMT_TYPE_GIF)
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
if (NULL == saveParam)
|
||
{
|
||
return (HGBASE_ERR_OK == HGImgFmt_SaveImage((HGImage)image, fmtType, NULL, Utf8ToStdString(savePath).c_str()));
|
||
}
|
||
|
||
if (saveParam->size == sizeof(HGLibSaveImageParam_V1))
|
||
{
|
||
const HGLibSaveImageParam_V1* saveParamV1 = (const HGLibSaveImageParam_V1*)saveParam;
|
||
if ((HGIMGFMT_TYPE_PDF == fmtType || HGIMGFMT_TYPE_OFD == fmtType) && saveParamV1->ocr)
|
||
{
|
||
HGOCRMgr ocrMgr = NULL;
|
||
HGImgProc_CreateOCRMgr(0, &ocrMgr);
|
||
if (NULL == ocrMgr)
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
HGBool ret = (HGBASE_ERR_OK == HGImgProc_ImageOCRToFile(ocrMgr, (HGImage)image, 0, Utf8ToStdString(savePath).c_str()));
|
||
HGImgProc_DestroyOCRMgr(ocrMgr);
|
||
return ret;
|
||
}
|
||
|
||
HGImgFmtSaveInfo saveInfo;
|
||
saveInfo.jpegQuality = saveParamV1->jpegQuality;
|
||
saveInfo.tiffCompression = 0;
|
||
if (HGLIB_TIFFCOMPRESSION_NONE == saveParamV1->tiffCompression)
|
||
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_NONE;
|
||
else if (HGLIB_TIFFCOMPRESSION_CCITTFAX4 == saveParamV1->tiffCompression)
|
||
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4;
|
||
else if (HGLIB_TIFFCOMPRESSION_LZW == saveParamV1->tiffCompression)
|
||
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_LZW;
|
||
else if (HGLIB_TIFFCOMPRESSION_JPEG == saveParamV1->tiffCompression)
|
||
saveInfo.tiffCompression = HGIMGFMT_TIFFCOMP_JPEG;
|
||
saveInfo.tiffJpegQuality = saveParamV1->tiffJpegQuality;
|
||
|
||
return (HGBASE_ERR_OK == HGImgFmt_SaveImage((HGImage)image, fmtType, &saveInfo, Utf8ToStdString(savePath).c_str()));
|
||
}
|
||
|
||
return HGFALSE;
|
||
}
|
||
|
||
HGBool HGAPI HGLib_ReleaseImage(HGLibImage image)
|
||
{
|
||
if (NULL == image)
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
HGBase_DestroyImage((HGImage)image);
|
||
return HGTRUE;
|
||
}
|
||
|
||
HGBool HGAPI HGLib_InitDevice(HGLibDeviceHotPlugEventFunc func, HGPointer param)
|
||
{
|
||
return HGLibDeviceImpl::Init(func, param);
|
||
}
|
||
|
||
HGBool HGAPI HGLib_DeinitDevice()
|
||
{
|
||
return HGLibDeviceImpl::Deinit();
|
||
}
|
||
|
||
HGChar** HGAPI HGLib_GetDeviceNameList()
|
||
{
|
||
return HGLibDeviceImpl::GetNameList();
|
||
}
|
||
|
||
HGBool HGAPI HGLib_ReleaseDeviceNameList(HGChar** deviceName)
|
||
{
|
||
return HGLibDeviceImpl::ReleaseNameList(deviceName);
|
||
}
|
||
|
||
HGLibDevice HGAPI HGLib_OpenDevice(const HGChar* deviceName)
|
||
{
|
||
return (HGLibDevice)HGLibDeviceImpl::Open(deviceName);
|
||
}
|
||
|
||
HGBool HGAPI HGLib_CloseDevice(HGLibDevice device)
|
||
{
|
||
if (NULL == device)
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
|
||
return deviceImpl->Close();
|
||
}
|
||
|
||
HGBool HGAPI HGLib_GetDeviceSN(HGLibDevice device, HGChar* sn, HGUInt maxLen)
|
||
{
|
||
if (NULL == device)
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
|
||
return deviceImpl->GetSN(sn, maxLen);
|
||
}
|
||
|
||
HGBool HGAPI HGLib_GetDeviceFWVersion(HGLibDevice device, HGChar* fwVersion, HGUInt maxLen)
|
||
{
|
||
if (NULL == device)
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
|
||
return deviceImpl->GetFWVersion(fwVersion, maxLen);
|
||
}
|
||
|
||
HGBool HGAPI HGLib_SetDeviceParam(HGLibDevice device, HGUInt option, const HGVoid* data)
|
||
{
|
||
if (NULL == device)
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
|
||
return deviceImpl->SetParam(option, data);
|
||
}
|
||
|
||
HGLibDeviceParamGroup* HGAPI HGLib_GetDeviceParamGroupList(HGLibDevice device, HGUInt* count)
|
||
{
|
||
if (NULL == device)
|
||
{
|
||
return NULL;
|
||
}
|
||
|
||
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
|
||
return deviceImpl->GetParamGroupList(count);
|
||
}
|
||
|
||
HGLibDeviceParam* HGAPI HGLib_GetDeviceParam(HGLibDevice device, HGUInt option)
|
||
{
|
||
if (NULL == device)
|
||
{
|
||
return NULL;
|
||
}
|
||
|
||
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
|
||
return deviceImpl->GetParam(option);
|
||
}
|
||
|
||
HGBool HGAPI HGLib_ReleaseDeviceParamGroupList(HGLibDeviceParamGroup* paramGroup, HGUInt count)
|
||
{
|
||
return HGLibDeviceImpl::ReleaseParamGroupList(paramGroup, count);
|
||
}
|
||
|
||
HGBool HGAPI HGLib_ReleaseDeviceParam(HGLibDeviceParam* param)
|
||
{
|
||
return HGLibDeviceImpl::ReleaseParam(param);
|
||
}
|
||
|
||
HGBool HGAPI HGLib_ResetDeviceParam(HGLibDevice device)
|
||
{
|
||
if (NULL == device)
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
|
||
return deviceImpl->ResetParam();
|
||
}
|
||
|
||
HGBool HGAPI HGLib_DeviceIsPaperOn(HGLibDevice device)
|
||
{
|
||
if (NULL == device)
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
|
||
return deviceImpl->IsPaperOn();
|
||
}
|
||
|
||
HGInt HGAPI HGLib_GetDeviceStatus(HGLibDevice device)
|
||
{
|
||
if (NULL == device)
|
||
{
|
||
return -1;
|
||
}
|
||
|
||
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
|
||
return deviceImpl->GetStatus();
|
||
}
|
||
|
||
HGBool HGAPI HGLib_DeviceRestart(HGLibDevice device)
|
||
{
|
||
if (NULL == device)
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
|
||
return deviceImpl->Restart();
|
||
}
|
||
|
||
HGBool HGAPI HGLib_DeviceShutDown(HGLibDevice device)
|
||
{
|
||
if (NULL == device)
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
|
||
return deviceImpl->ShutDown();
|
||
}
|
||
|
||
HGBool HGAPI HGLib_StartDeviceScan(HGLibDevice device, HGLibDeviceScanEventFunc eventFunc, HGPointer eventParam,
|
||
HGLibDeviceScanImageFunc imageFunc, HGPointer imageParam)
|
||
{
|
||
if (NULL == device)
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
|
||
return deviceImpl->StartScan(eventFunc, eventParam, imageFunc, imageParam);
|
||
}
|
||
|
||
HGBool HGAPI HGLib_StopDeviceScan(HGLibDevice device)
|
||
{
|
||
if (NULL == device)
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
|
||
return deviceImpl->StopScan();
|
||
}
|
||
|
||
HGBool HGAPI HGLib_StopDeviceScanAsyn(HGLibDevice device)
|
||
{
|
||
if (NULL == device)
|
||
{
|
||
return HGFALSE;
|
||
}
|
||
|
||
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
|
||
return deviceImpl->StopScanAsyn();
|
||
}
|
||
|
||
HGInt HGAPI HGLib_GetDeviceOperateCode(HGLibDevice device)
|
||
{
|
||
if (NULL == device)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
HGLibDeviceImpl* deviceImpl = (HGLibDeviceImpl*)device;
|
||
return deviceImpl->GetOperateCode();
|
||
}
|