parent
069ad15078
commit
3fdee485d0
|
@ -2184,29 +2184,178 @@ namespace ver_2
|
|||
int ManagerV2::MergeImage(const std::vector<int>& imageIndexList, const std::string& mode,
|
||||
const std::string& align, int interval, std::string& outImagePath, std::string& errInfo)
|
||||
{
|
||||
return -1;
|
||||
outImagePath.clear();
|
||||
errInfo = "错误";
|
||||
|
||||
if (NULL == m_sqlite)
|
||||
return -1;
|
||||
|
||||
std::vector<std::string> imagePathList;
|
||||
|
||||
bool ok = true;
|
||||
for (int i = 0; i < (int)imageIndexList.size(); ++i)
|
||||
{
|
||||
HGChar imagePath[256];
|
||||
HGBase_GetTmpFileName(NULL, imagePath, 256);
|
||||
if (0 != SaveImage(imageIndexList[i], imagePath))
|
||||
{
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
|
||||
imagePathList.push_back(imagePath);
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
for (int i = 0; i < (int)imagePathList.size(); ++i)
|
||||
{
|
||||
HGBase_DeleteFile(imagePathList[i].c_str());
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = MergeLocalImage(imagePathList, mode, align, interval, outImagePath, errInfo);
|
||||
|
||||
for (int i = 0; i < (int)imagePathList.size(); ++i)
|
||||
{
|
||||
HGBase_DeleteFile(imagePathList[i].c_str());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ManagerV2::MakeMultiImage(const std::vector<int>& imageIndexList, const std::string& format,
|
||||
const std::string& tiffCompression, int tiffJpegQuality, std::string& outImagePath, std::string& errInfo)
|
||||
{
|
||||
return -1;
|
||||
outImagePath.clear();
|
||||
errInfo = "错误";
|
||||
|
||||
if (NULL == m_sqlite)
|
||||
return -1;
|
||||
|
||||
std::vector<std::string> imagePathList;
|
||||
|
||||
bool ok = true;
|
||||
for (int i = 0; i < (int)imageIndexList.size(); ++i)
|
||||
{
|
||||
HGChar imagePath[256];
|
||||
HGBase_GetTmpFileName(NULL, imagePath, 256);
|
||||
if (0 != SaveImage(imageIndexList[i], imagePath))
|
||||
{
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
|
||||
imagePathList.push_back(imagePath);
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
for (int i = 0; i < (int)imagePathList.size(); ++i)
|
||||
{
|
||||
HGBase_DeleteFile(imagePathList[i].c_str());
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = LocalMakeMultiImage(imagePathList, format, tiffCompression, tiffJpegQuality, outImagePath, errInfo);
|
||||
|
||||
for (int i = 0; i < (int)imagePathList.size(); ++i)
|
||||
{
|
||||
HGBase_DeleteFile(imagePathList[i].c_str());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ManagerV2::SplitImage(int imageIndex, const std::string& mode, int location, std::vector<std::string>& outImagePathList,
|
||||
std::string& errInfo)
|
||||
{
|
||||
return -1;
|
||||
outImagePathList.clear();
|
||||
errInfo.clear();
|
||||
|
||||
if (NULL == m_sqlite)
|
||||
return -1;
|
||||
|
||||
HGChar imagePath[256];
|
||||
HGBase_GetTmpFileName(NULL, imagePath, 256);
|
||||
if (0 != SaveImage(imageIndex, imagePath))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = SplitLocalImage(imagePath, mode, location, outImagePathList, errInfo);
|
||||
|
||||
HGBase_DeleteFile(imagePath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ManagerV2::MakeZipFile(const std::vector<int>& imageIndexList, std::string& outZipPath, std::string& errInfo)
|
||||
{
|
||||
return -1;
|
||||
outZipPath.clear();
|
||||
errInfo = "错误";
|
||||
|
||||
if (NULL == m_sqlite)
|
||||
return -1;
|
||||
|
||||
std::vector<std::string> imagePathList;
|
||||
|
||||
bool ok = true;
|
||||
for (int i = 0; i < (int)imageIndexList.size(); ++i)
|
||||
{
|
||||
HGChar imagePath[256];
|
||||
HGBase_GetTmpFileName(NULL, imagePath, 256);
|
||||
if (0 != SaveImage(imageIndexList[i], imagePath))
|
||||
{
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
|
||||
imagePathList.push_back(imagePath);
|
||||
}
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
for (int i = 0; i < (int)imagePathList.size(); ++i)
|
||||
{
|
||||
HGBase_DeleteFile(imagePathList[i].c_str());
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = LocalMakeZipFile(imagePathList, outZipPath, errInfo);
|
||||
|
||||
for (int i = 0; i < (int)imagePathList.size(); ++i)
|
||||
{
|
||||
HGBase_DeleteFile(imagePathList[i].c_str());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ManagerV2::ImageDeskew(int imageIndex, std::string& outImagePath, std::string& errInfo)
|
||||
{
|
||||
return -1;
|
||||
outImagePath.clear();
|
||||
errInfo.clear();
|
||||
|
||||
if (NULL == m_sqlite)
|
||||
return -1;
|
||||
|
||||
HGChar imagePath[256];
|
||||
HGBase_GetTmpFileName(NULL, imagePath, 256);
|
||||
if (0 != SaveImage(imageIndex, imagePath))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = LocalImageDeskew(imagePath, outImagePath, errInfo);
|
||||
|
||||
HGBase_DeleteFile(imagePath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string ManagerV2::GetCfgStringValue(const std::string& app, const std::string& key, const std::string& def)
|
||||
|
@ -2481,18 +2630,32 @@ namespace ver_2
|
|||
HGBase_CreateDir(m_globalCfg.fileSavePath.c_str());
|
||||
|
||||
char filePath[256] = { 0 };
|
||||
if ("random" == m_globalCfg.fileNameMode)
|
||||
while (1)
|
||||
{
|
||||
HGChar uuid[256];
|
||||
HGBase_GetUuid(uuid, 256);
|
||||
sprintf(filePath, "%s%s%s.%s", m_globalCfg.fileSavePath.c_str(), m_globalCfg.fileNamePrefix.c_str(), uuid, suffix.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
HGTimeInfo timeInfo;
|
||||
HGBase_GetLocalTime(&timeInfo);
|
||||
sprintf(filePath, "%s%s%04d%02d%02d%02d%02d%02d%03d.%s", m_globalCfg.fileSavePath.c_str(), m_globalCfg.fileNamePrefix.c_str(), timeInfo.year,
|
||||
timeInfo.month, timeInfo.day, timeInfo.hour, timeInfo.minute, timeInfo.second, timeInfo.milliseconds, suffix.c_str());
|
||||
if ("random" == m_globalCfg.fileNameMode)
|
||||
{
|
||||
HGChar uuid[256];
|
||||
HGBase_GetUuid(uuid, 256);
|
||||
sprintf(filePath, "%s%s%s.%s", m_globalCfg.fileSavePath.c_str(), m_globalCfg.fileNamePrefix.c_str(), uuid, suffix.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
HGTimeInfo timeInfo;
|
||||
HGBase_GetLocalTime(&timeInfo);
|
||||
sprintf(filePath, "%s%s%04d%02d%02d%02d%02d%02d%03d.%s", m_globalCfg.fileSavePath.c_str(), m_globalCfg.fileNamePrefix.c_str(), timeInfo.year,
|
||||
timeInfo.month, timeInfo.day, timeInfo.hour, timeInfo.minute, timeInfo.second, timeInfo.milliseconds, suffix.c_str());
|
||||
}
|
||||
|
||||
#if defined(HG_CMP_MSC)
|
||||
DWORD attr = GetFileAttributesA(filePath);
|
||||
if (INVALID_FILE_ATTRIBUTES == attr)
|
||||
break;
|
||||
#else
|
||||
struct stat buf;
|
||||
int result = stat(lineContent, &buf);
|
||||
if (0 != result)
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
return filePath;
|
||||
|
@ -2582,7 +2745,9 @@ namespace ver_2
|
|||
if (INVALID_FILE_ATTRIBUTES != attr && 0 == (FILE_ATTRIBUTE_DIRECTORY & attr))
|
||||
savePathList.push_back(lineContent);
|
||||
#else
|
||||
if (0 == access(lineContent, R_OK))
|
||||
struct stat buf;
|
||||
int result = stat(lineContent, &buf);
|
||||
if (0 == result && 0 == (S_IFDIR & buf.st_mode))
|
||||
savePathList.push_back(lineContent);
|
||||
#endif
|
||||
}
|
||||
|
@ -2940,6 +3105,44 @@ namespace ver_2
|
|||
return 0;
|
||||
}
|
||||
|
||||
int ManagerV2::SaveImage(int imageIndex, const std::string& imagePath)
|
||||
{
|
||||
if (NULL == m_sqlite)
|
||||
return -1;
|
||||
|
||||
int rc = -1;
|
||||
|
||||
sqlite3_stmt* stmt = NULL;
|
||||
char sql[256];
|
||||
sprintf(sql, "select * from 'table_%s'", m_currBatchId.c_str());
|
||||
int ret = sqlite3_prepare(m_sqlite, sql, -1, &stmt, NULL);
|
||||
assert(0 == ret);
|
||||
|
||||
ret = sqlite3_step(stmt);
|
||||
while (SQLITE_ROW == ret)
|
||||
{
|
||||
int idx = sqlite3_column_int(stmt, 1);
|
||||
if (idx == imageIndex)
|
||||
{
|
||||
const void* imgData = sqlite3_column_blob(stmt, 4);
|
||||
int imgSize = sqlite3_column_bytes(stmt, 4);
|
||||
|
||||
if (SaveToFile((const HGByte*)imgData, imgSize, imagePath))
|
||||
{
|
||||
rc = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
ret = sqlite3_step(stmt);
|
||||
}
|
||||
|
||||
ret = sqlite3_finalize(stmt);
|
||||
assert(0 == ret);
|
||||
return rc;
|
||||
}
|
||||
|
||||
HGByte* ManagerV2::LoadImageFromPath(const std::string& imagePath, HGUInt& size, std::string& format)
|
||||
{
|
||||
size = 0;
|
||||
|
|
|
@ -319,6 +319,7 @@ namespace ver_2
|
|||
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);
|
||||
int SaveImage(int imageIndex, const std::string& imagePath);
|
||||
|
||||
static HGByte* LoadImageFromPath(const std::string& imagePath, HGUInt& size, std::string& format);
|
||||
static HGByte* LoadImageFromBase64(const std::string& imageBase64, HGUInt& size, std::string& format);
|
||||
|
|
|
@ -392,6 +392,26 @@ namespace ver_2
|
|||
{
|
||||
ImageBookSort(json);
|
||||
}
|
||||
else if ("merge_image" == func)
|
||||
{
|
||||
MergeImage(json);
|
||||
}
|
||||
else if ("make_multi_image" == func)
|
||||
{
|
||||
MakeMultiImage(json);
|
||||
}
|
||||
else if ("split_image" == func)
|
||||
{
|
||||
SplitImage(json);
|
||||
}
|
||||
else if ("make_zip_file" == func)
|
||||
{
|
||||
MakeZipFile(json);
|
||||
}
|
||||
else if ("image_deskew" == func)
|
||||
{
|
||||
ImageDeskew(json);
|
||||
}
|
||||
|
||||
cJSON_Delete(json);
|
||||
}
|
||||
|
@ -888,7 +908,7 @@ namespace ver_2
|
|||
HttpHead::AnalysisHead(head, requestMethod, requestURIPath, requestURIQueryInfos,
|
||||
requestURIFragment, httpVersion, headInfos);
|
||||
|
||||
if ("Upgrade" != HttpHead::GetValue(headInfos, "Connection"))
|
||||
if (std::string::npos == HttpHead::GetValue(headInfos, "Connection").find("Upgrade"))
|
||||
return false;
|
||||
if ("websocket" != HttpHead::GetValue(headInfos, "Upgrade"))
|
||||
return false;
|
||||
|
@ -1598,16 +1618,14 @@ namespace ver_2
|
|||
if (findIden)
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "split_local_image", iden.c_str(), ret, pathList.c_str(),
|
||||
base64List.c_str());
|
||||
sprintf(resp, fmt.c_str(), "split_local_image", iden.c_str(), ret, pathList.c_str(), base64List.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "split_local_image", iden.c_str(), ret, pathList.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "split_local_image", ret, pathList.c_str(),
|
||||
base64List.c_str());
|
||||
sprintf(resp, fmt.c_str(), "split_local_image", ret, pathList.c_str(), base64List.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "split_local_image", ret, pathList.c_str());
|
||||
}
|
||||
|
@ -3389,4 +3407,414 @@ namespace ver_2
|
|||
|
||||
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||
}
|
||||
|
||||
void WSUser::MergeImage(cJSON* json)
|
||||
{
|
||||
assert(NULL != json);
|
||||
|
||||
std::vector<int> imageIndexList = GetJsonIntListValue(json, "image_index_list");
|
||||
|
||||
bool find = false;
|
||||
std::string mode = GetJsonStringValue(json, "mode", &find);
|
||||
if (!find)
|
||||
mode = "horz";
|
||||
std::string align = GetJsonStringValue(json, "align", &find);
|
||||
if (!find)
|
||||
align = "center";
|
||||
int interval = GetJsonIntValue(json, "interval", &find);
|
||||
if (!find)
|
||||
interval = 0;
|
||||
|
||||
std::string outImagePath;
|
||||
std::string errInfo;
|
||||
int ret = GetManager()->MergeImage(imageIndexList, mode, align, interval, outImagePath, errInfo);
|
||||
|
||||
std::string outImageBase64;
|
||||
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
||||
if (0 == ret && getBase64)
|
||||
{
|
||||
std::string errInfo2;
|
||||
GetManager()->LoadLocalImage(outImagePath, outImageBase64, errInfo2);
|
||||
}
|
||||
|
||||
bool findIden = false;
|
||||
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
||||
|
||||
std::string fmt;
|
||||
fmt += "{\"func\":\"%s\", ";
|
||||
if (findIden)
|
||||
fmt += "\"iden\":\"%s\", ";
|
||||
if (0 != ret)
|
||||
{
|
||||
fmt += "\"ret\":%d, ";
|
||||
fmt += "\"err_info\":\"%s\"}";
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt += "\"ret\":%d, ";
|
||||
if (getBase64)
|
||||
{
|
||||
fmt += "\"image_path\":\"%s\", ";
|
||||
fmt += "\"image_base64\":\"%s\"}";
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt += "\"image_path\":\"%s\"}";
|
||||
}
|
||||
}
|
||||
|
||||
char* resp = new char[1024 + outImageBase64.size()];
|
||||
if (0 != ret)
|
||||
{
|
||||
if (findIden)
|
||||
sprintf(resp, fmt.c_str(), "merge_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "merge_image", ret, StdStringToUtf8(errInfo).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (findIden)
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "merge_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
||||
outImageBase64.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "merge_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "merge_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
||||
outImageBase64.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "merge_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||
delete[] resp;
|
||||
}
|
||||
|
||||
void WSUser::MakeMultiImage(cJSON* json)
|
||||
{
|
||||
assert(NULL != json);
|
||||
|
||||
std::vector<int> imageIndexList = GetJsonIntListValue(json, "image_index_list");
|
||||
|
||||
bool find = false;
|
||||
std::string format = GetJsonStringValue(json, "format", &find);
|
||||
if (!find)
|
||||
format = "tif";
|
||||
std::string tiffCompression = GetJsonStringValue(json, "tiff_compression", &find);
|
||||
if (!find)
|
||||
tiffCompression = "lzw";
|
||||
int tiffJpegQuality = GetJsonIntValue(json, "tiff_jpeg_quality", &find);
|
||||
if (!find)
|
||||
tiffJpegQuality = 80;
|
||||
|
||||
std::string outImagePath;
|
||||
std::string errInfo;
|
||||
int ret = GetManager()->MakeMultiImage(imageIndexList, format, tiffCompression, tiffJpegQuality, outImagePath, errInfo);
|
||||
|
||||
std::string outImageBase64;
|
||||
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
||||
if (0 == ret && getBase64)
|
||||
{
|
||||
std::string errInfo2;
|
||||
GetManager()->LoadLocalImage(outImagePath, outImageBase64, errInfo2);
|
||||
}
|
||||
|
||||
bool findIden = false;
|
||||
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
||||
|
||||
std::string fmt;
|
||||
fmt += "{\"func\":\"%s\", ";
|
||||
if (findIden)
|
||||
fmt += "\"iden\":\"%s\", ";
|
||||
if (0 != ret)
|
||||
{
|
||||
fmt += "\"ret\":%d, ";
|
||||
fmt += "\"err_info\":\"%s\"}";
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt += "\"ret\":%d, ";
|
||||
if (getBase64)
|
||||
{
|
||||
fmt += "\"image_path\":\"%s\", ";
|
||||
fmt += "\"image_base64\":\"%s\"}";
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt += "\"image_path\":\"%s\"}";
|
||||
}
|
||||
}
|
||||
|
||||
char* resp = new char[1024 + outImageBase64.size()];
|
||||
if (0 != ret)
|
||||
{
|
||||
if (findIden)
|
||||
sprintf(resp, fmt.c_str(), "make_multi_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "make_multi_image", ret, StdStringToUtf8(errInfo).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (findIden)
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "make_multi_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
||||
outImageBase64.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "make_multi_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "make_multi_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
||||
outImageBase64.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "make_multi_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||
delete[] resp;
|
||||
}
|
||||
|
||||
void WSUser::SplitImage(cJSON* json)
|
||||
{
|
||||
assert(NULL != json);
|
||||
|
||||
int imageIndex = GetJsonIntValue(json, "image_index");
|
||||
|
||||
bool find = false;
|
||||
std::string mode = GetJsonStringValue(json, "mode", &find);
|
||||
if (!find)
|
||||
mode = "horz";
|
||||
int location = GetJsonIntValue(json, "location", &find);
|
||||
if (!find)
|
||||
location = 0;
|
||||
|
||||
std::vector<std::string> outImagePathList;
|
||||
std::string errInfo;
|
||||
int ret = GetManager()->SplitImage(imageIndex, mode, location, outImagePathList, errInfo);
|
||||
|
||||
std::vector<std::string> outImageBase64List;
|
||||
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
||||
if (0 == ret && getBase64)
|
||||
{
|
||||
for (int i = 0; i < (int)outImagePathList.size(); ++i)
|
||||
{
|
||||
std::string outImageBase64;
|
||||
std::string errInfo2;
|
||||
GetManager()->LoadLocalImage(outImagePathList[i], outImageBase64, errInfo2);
|
||||
outImageBase64List.push_back(outImageBase64);
|
||||
}
|
||||
}
|
||||
|
||||
bool findIden = false;
|
||||
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
||||
|
||||
std::string fmt;
|
||||
fmt += "{\"func\":\"%s\", ";
|
||||
if (findIden)
|
||||
fmt += "\"iden\":\"%s\", ";
|
||||
if (0 != ret)
|
||||
{
|
||||
fmt += "\"ret\":%d, ";
|
||||
fmt += "\"err_info\":\"%s\"}";
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt += "\"ret\":%d, ";
|
||||
if (getBase64)
|
||||
{
|
||||
fmt += "\"image_path_list\":%s, ";
|
||||
fmt += "\"image_base64_list\":%s}";
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt += "\"image_path_list\":%s}";
|
||||
}
|
||||
}
|
||||
|
||||
std::string pathList = "[";
|
||||
for (int i = 0; i < (int)outImagePathList.size(); ++i)
|
||||
{
|
||||
pathList += "\"";
|
||||
pathList += StdStringToUtf8(strToJson(outImagePathList[i]));
|
||||
pathList += "\"";
|
||||
if (i != (int)outImagePathList.size() - 1)
|
||||
{
|
||||
pathList += ", ";
|
||||
}
|
||||
}
|
||||
pathList += "]";
|
||||
|
||||
std::string base64List = "[";
|
||||
for (int i = 0; i < (int)outImageBase64List.size(); ++i)
|
||||
{
|
||||
base64List += "\"";
|
||||
base64List += outImageBase64List[i];
|
||||
base64List += "\"";
|
||||
if (i != (int)outImageBase64List.size() - 1)
|
||||
{
|
||||
base64List += ", ";
|
||||
}
|
||||
}
|
||||
base64List += "]";
|
||||
|
||||
char* resp = new char[1024 + base64List.size()];
|
||||
if (0 != ret)
|
||||
{
|
||||
if (findIden)
|
||||
sprintf(resp, fmt.c_str(), "split_image", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "split_image", ret, StdStringToUtf8(errInfo).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (findIden)
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "split_image", iden.c_str(), ret, pathList.c_str(), base64List.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "split_image", iden.c_str(), ret, pathList.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "split_image", ret, pathList.c_str(), base64List.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "split_image", ret, pathList.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||
delete[] resp;
|
||||
}
|
||||
|
||||
void WSUser::MakeZipFile(cJSON* json)
|
||||
{
|
||||
assert(NULL != json);
|
||||
|
||||
std::vector<int> imageIndexList = GetJsonIntListValue(json, "image_index_list");
|
||||
|
||||
std::string outZipPath;
|
||||
std::string errInfo;
|
||||
int ret = GetManager()->MakeZipFile(imageIndexList, outZipPath, errInfo);
|
||||
|
||||
bool findIden = false;
|
||||
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
||||
|
||||
std::string fmt;
|
||||
fmt += "{\"func\":\"%s\", ";
|
||||
if (findIden)
|
||||
fmt += "\"iden\":\"%s\", ";
|
||||
if (0 != ret)
|
||||
{
|
||||
fmt += "\"ret\":%d, ";
|
||||
fmt += "\"err_info\":\"%s\"}";
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt += "\"ret\":%d, ";
|
||||
fmt += "\"zip_path\":\"%s\"}";
|
||||
}
|
||||
|
||||
char resp[1024] = { 0 };
|
||||
if (0 != ret)
|
||||
{
|
||||
if (findIden)
|
||||
sprintf(resp, fmt.c_str(), "make_zip_file", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "make_zip_file", ret, StdStringToUtf8(errInfo).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (findIden)
|
||||
sprintf(resp, fmt.c_str(), "make_zip_file", iden.c_str(), ret, StdStringToUtf8(strToJson(outZipPath)).c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "make_zip_file", ret, StdStringToUtf8(strToJson(outZipPath)).c_str());
|
||||
}
|
||||
|
||||
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||
}
|
||||
|
||||
void WSUser::ImageDeskew(cJSON* json)
|
||||
{
|
||||
assert(NULL != json);
|
||||
|
||||
int imageIndex = GetJsonIntValue(json, "image_index");
|
||||
|
||||
std::string outImagePath;
|
||||
std::string errInfo;
|
||||
int ret = GetManager()->ImageDeskew(imageIndex, outImagePath, errInfo);
|
||||
|
||||
std::string outImageBase64;
|
||||
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
||||
if (0 == ret && getBase64)
|
||||
{
|
||||
std::string errInfo2;
|
||||
GetManager()->LoadLocalImage(outImagePath, outImageBase64, errInfo2);
|
||||
}
|
||||
|
||||
bool findIden = false;
|
||||
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
||||
|
||||
std::string fmt;
|
||||
fmt += "{\"func\":\"%s\", ";
|
||||
if (findIden)
|
||||
fmt += "\"iden\":\"%s\", ";
|
||||
if (0 != ret)
|
||||
{
|
||||
fmt += "\"ret\":%d, ";
|
||||
fmt += "\"err_info\":\"%s\"}";
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt += "\"ret\":%d, ";
|
||||
if (getBase64)
|
||||
{
|
||||
fmt += "\"image_path\":\"%s\", ";
|
||||
fmt += "\"image_base64\":\"%s\"}";
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt += "\"image_path\":\"%s\"}";
|
||||
}
|
||||
}
|
||||
|
||||
char* resp = new char[1024 + outImageBase64.size()];
|
||||
if (0 != ret)
|
||||
{
|
||||
if (findIden)
|
||||
sprintf(resp, fmt.c_str(), "image_deskew", iden.c_str(), ret, StdStringToUtf8(errInfo).c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "image_deskew", ret, StdStringToUtf8(errInfo).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (findIden)
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "image_deskew", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
||||
outImageBase64.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "image_deskew", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "image_deskew", ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
||||
outImageBase64.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "image_deskew", ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||
delete[] resp;
|
||||
}
|
||||
}
|
|
@ -76,6 +76,11 @@ namespace ver_2
|
|||
void ModifyImageByLocal(cJSON* json);
|
||||
void MoveImage(cJSON* json);
|
||||
void ImageBookSort(cJSON* json);
|
||||
void MergeImage(cJSON* json);
|
||||
void MakeMultiImage(cJSON* json);
|
||||
void SplitImage(cJSON* json);
|
||||
void MakeZipFile(cJSON* json);
|
||||
void ImageDeskew(cJSON* json);
|
||||
|
||||
private:
|
||||
std::string m_initDeviceIden;
|
||||
|
|
|
@ -28,20 +28,27 @@ static void ThreadFunc(HGThread thread, HGPointer param)
|
|||
ver_1::HttpServer httpServer(msgPump, &manager);
|
||||
ver_1::SockIoServer sockIoServer(msgPump, &manager);
|
||||
|
||||
httpServer.Open(18999);
|
||||
sockIoServer.Open(28999);
|
||||
HGBase_RunMsgPump(msgPump, ver_1::HGMsgPumpCallback, NULL);
|
||||
sockIoServer.Close();
|
||||
httpServer.Close();
|
||||
if (httpServer.Open(18999))
|
||||
{
|
||||
if (sockIoServer.Open(28999))
|
||||
{
|
||||
HGBase_RunMsgPump(msgPump, ver_1::HGMsgPumpCallback, NULL);
|
||||
sockIoServer.Close();
|
||||
}
|
||||
|
||||
httpServer.Close();
|
||||
}
|
||||
}
|
||||
else // 使用V2版本接口
|
||||
{
|
||||
ver_2::ManagerV2 manager(msgPump);
|
||||
ver_2::WSServer wsServer(msgPump, &manager);
|
||||
|
||||
wsServer.Open(38999);
|
||||
HGBase_RunMsgPump(msgPump, ver_2::HGMsgPumpCallback, NULL);
|
||||
wsServer.Close();
|
||||
if (wsServer.Open(38999))
|
||||
{
|
||||
HGBase_RunMsgPump(msgPump, ver_2::HGMsgPumpCallback, NULL);
|
||||
wsServer.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -229,6 +229,29 @@
|
|||
{
|
||||
alert(msg.data);
|
||||
}
|
||||
else if ("merge_image" == message['func'])
|
||||
{
|
||||
var myCanvas = document.getElementById("myCanvas");
|
||||
myCanvas.src = message['image_base64'];
|
||||
}
|
||||
else if ("make_multi_image" == message['func'])
|
||||
{
|
||||
alert(msg.data);
|
||||
}
|
||||
else if ("split_image" == message['func'])
|
||||
{
|
||||
var myCanvas = document.getElementById("myCanvas");
|
||||
myCanvas.src = message['image_base64_list'][0];
|
||||
}
|
||||
else if ("make_zip_file" == message['func'])
|
||||
{
|
||||
alert(msg.data);
|
||||
}
|
||||
else if ("image_deskew" == message['func'])
|
||||
{
|
||||
var myCanvas = document.getElementById("myCanvas");
|
||||
myCanvas.src = message['image_base64'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -521,7 +544,7 @@
|
|||
{
|
||||
socket.send(JSON.stringify({
|
||||
'func':'move_image',
|
||||
'image_index_list':[1],
|
||||
'image_index_list':[2],
|
||||
'target':0
|
||||
}));
|
||||
}
|
||||
|
@ -533,6 +556,58 @@
|
|||
}));
|
||||
}
|
||||
|
||||
function MergeImage()
|
||||
{
|
||||
socket.send(JSON.stringify({
|
||||
'func':'merge_image',
|
||||
'image_index_list':[0, 1, 2],
|
||||
'mode':'horz',
|
||||
'align':'center',
|
||||
'interval':20,
|
||||
'get_base64':true
|
||||
}));
|
||||
}
|
||||
|
||||
function MakeMultiImage()
|
||||
{
|
||||
socket.send(JSON.stringify({
|
||||
'func':'make_multi_image',
|
||||
'image_index_list':[0, 1, 2],
|
||||
'format':'tif',
|
||||
'tiff_compression':'jpeg',
|
||||
'tiff_jpeg_quality':60,
|
||||
'get_base64':true
|
||||
}));
|
||||
}
|
||||
|
||||
function SplitImage()
|
||||
{
|
||||
socket.send(JSON.stringify({
|
||||
'func':'split_image',
|
||||
'image_index':0,
|
||||
'mode':'horz',
|
||||
'location':500,
|
||||
'get_base64':true
|
||||
}));
|
||||
}
|
||||
|
||||
function MakeZipFile()
|
||||
{
|
||||
socket.send(JSON.stringify({
|
||||
'func':'make_zip_file',
|
||||
'image_index_list':[0, 1, 2]
|
||||
}));
|
||||
}
|
||||
|
||||
function ImageDeskew()
|
||||
{
|
||||
socket.send(JSON.stringify({
|
||||
'func':'image_deskew',
|
||||
'image_index':0,
|
||||
'get_base64':true
|
||||
}));
|
||||
}
|
||||
|
||||
window.onload = function()
|
||||
{
|
||||
var myimg = document.getElementById("myCanvas");
|
||||
|
@ -579,7 +654,7 @@
|
|||
<input type="button" value="关闭设备" onclick="CloseDevice()" />
|
||||
<input type="button" value="设置设备参数" onclick="SetDeviceParam()" />
|
||||
<input type="button" value="获取设备参数" onclick="GetDeviceParam()" />
|
||||
<input type="button" value="获取当前摄像头名称" onclick="GetCurrDevName()" />
|
||||
<input type="button" value="获取当前设备名称" onclick="GetCurrDevName()" />
|
||||
<input type="button" value="开始扫描" onclick="StartScan()" />
|
||||
<input type="button" value="停止扫描" onclick="StopScan()" />
|
||||
<input type="button" value="获取批次名称列表" onclick="GetBatchIdList()" />
|
||||
|
@ -599,6 +674,11 @@
|
|||
<input type="button" value="用本地图像修改图像" onclick="ModifyImageByLocal()" />
|
||||
<input type="button" value="移动图像" onclick="MoveImage()" />
|
||||
<input type="button" value="图像书籍排序" onclick="ImageBookSort()" />
|
||||
<input type="button" value="合成图像" onclick="MergeImage()" />
|
||||
<input type="button" value="合成多张图像" onclick="MakeMultiImage()" />
|
||||
<input type="button" value="拆分图像" onclick="SplitImage()" />
|
||||
<input type="button" value="生成压缩文件" onclick="MakeZipFile()" />
|
||||
<input type="button" value="图像纠偏" onclick="ImageDeskew()" />
|
||||
<br />
|
||||
<br />
|
||||
<img id="myCanvas" width='640' height='480' style="background-color: black; float: left;"/>
|
||||
|
|
Loading…
Reference in New Issue