From 3fdee485d0f5afa3c1959c91b9dc1d3b97a7f1ce Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@qq.com> Date: Fri, 10 Jun 2022 11:54:00 +0800 Subject: [PATCH] =?UTF-8?q?websdk:=20=20=201=EF=BC=89=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E5=9C=A8=E7=81=AB=E7=8B=90=E4=B8=8A=E9=9D=A2=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E4=B8=8D=E6=88=90=E5=8A=9F=E7=9A=84=E9=97=AE=E9=A2=98=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20=202=EF=BC=89=E5=AE=9E=E7=8E=B0=E7=BC=A9?= =?UTF-8?q?=E7=95=A5=E5=9B=BE=E7=9A=84=E5=9B=BE=E5=83=8F=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sdk/webservice/ManagerV2.cpp | 237 +++++++++++++++++-- sdk/webservice/ManagerV2.h | 1 + sdk/webservice/WSUser.cpp | 438 ++++++++++++++++++++++++++++++++++- sdk/webservice/WSUser.h | 5 + sdk/webservice/main.cpp | 23 +- test/webservice/demo.html | 84 ++++++- 6 files changed, 756 insertions(+), 32 deletions(-) diff --git a/sdk/webservice/ManagerV2.cpp b/sdk/webservice/ManagerV2.cpp index d7e89148..db9fa5b8 100644 --- a/sdk/webservice/ManagerV2.cpp +++ b/sdk/webservice/ManagerV2.cpp @@ -2184,29 +2184,178 @@ namespace ver_2 int ManagerV2::MergeImage(const std::vector& 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 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& 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 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& 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& imageIndexList, std::string& outZipPath, std::string& errInfo) { - return -1; + outZipPath.clear(); + errInfo = "错误"; + + if (NULL == m_sqlite) + return -1; + + std::vector 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; diff --git a/sdk/webservice/ManagerV2.h b/sdk/webservice/ManagerV2.h index 13bd21dc..824f3af1 100644 --- a/sdk/webservice/ManagerV2.h +++ b/sdk/webservice/ManagerV2.h @@ -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); diff --git a/sdk/webservice/WSUser.cpp b/sdk/webservice/WSUser.cpp index 618e3b85..55406a37 100644 --- a/sdk/webservice/WSUser.cpp +++ b/sdk/webservice/WSUser.cpp @@ -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 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 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 outImagePathList; + std::string errInfo; + int ret = GetManager()->SplitImage(imageIndex, mode, location, outImagePathList, errInfo); + + std::vector 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 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; + } } \ No newline at end of file diff --git a/sdk/webservice/WSUser.h b/sdk/webservice/WSUser.h index d0df206e..79045e96 100644 --- a/sdk/webservice/WSUser.h +++ b/sdk/webservice/WSUser.h @@ -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; diff --git a/sdk/webservice/main.cpp b/sdk/webservice/main.cpp index faa6b42f..b5afb8b3 100644 --- a/sdk/webservice/main.cpp +++ b/sdk/webservice/main.cpp @@ -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(); + } } } diff --git a/test/webservice/demo.html b/test/webservice/demo.html index 7ff19f98..d10a734d 100644 --- a/test/webservice/demo.html +++ b/test/webservice/demo.html @@ -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 @@ - + @@ -599,6 +674,11 @@ + + + + +