diff --git a/doc/webservice/新版websdk接口说明.doc b/doc/webservice/新版websdk接口说明.doc
index de62a812..e7783df0 100644
Binary files a/doc/webservice/新版websdk接口说明.doc and b/doc/webservice/新版websdk接口说明.doc differ
diff --git a/modules/imgfmt/HGGif.cpp b/modules/imgfmt/HGGif.cpp
index 4f45bc81..fb421cf3 100644
--- a/modules/imgfmt/HGGif.cpp
+++ b/modules/imgfmt/HGGif.cpp
@@ -72,6 +72,7 @@ struct HGGifWriterImpl
{
int savedCount = m_gifFile->ImageCount;
SavedImage* savedImages = m_gifFile->SavedImages;
+
//关闭GIF并释放相关存储。
EGifSpew(m_gifFile);
@@ -84,12 +85,15 @@ struct HGGifWriterImpl
}
if (sp->RasterBits != NULL)
- free((char*)sp->RasterBits);
+ {
+ free(sp->RasterBits);
+ sp->RasterBits = NULL;
+ }
GifFreeExtensions(&sp->ExtensionBlockCount, &sp->ExtensionBlocks);
}
- free((char*)savedImages);
+ free(savedImages);
savedImages = NULL;
}
}
@@ -475,6 +479,7 @@ HGResult HGAPI HGImgFmt_CloseGifReader(HGGifReader reader)
static HGResult LoadGifImage(HGGifReaderImpl* gifReaderImpl, HGUInt &interval)
{
assert(NULL != gifReaderImpl);
+ interval = 0;
int transColor = -1;
unsigned int loopCount = 0;
diff --git a/sdk/webservice/ManagerV2.cpp b/sdk/webservice/ManagerV2.cpp
index 0cd16bbc..ae95beb1 100644
--- a/sdk/webservice/ManagerV2.cpp
+++ b/sdk/webservice/ManagerV2.cpp
@@ -1147,6 +1147,53 @@ namespace ver_2
return ret;
}
+ int ManagerV2::LocalImageClip(const std::string& imagePath, int x, int y, int width, int height,
+ bool temp, std::string& outImagePath, std::string& errInfo)
+ {
+ outImagePath.clear();
+ errInfo = "错误";
+
+ if (imagePath.empty() || x < 0 || y < 0 || width <= 0 || height <= 0)
+ return -1;
+
+ int ret = -1;
+ HGImage image = NULL;
+ HGImgFmt_LoadImage(imagePath.c_str(), 0, NULL, 0, HGBASE_IMGORIGIN_TOP, &image);
+ if (NULL != image)
+ {
+ HGImageRoi roi;
+ roi.left = x;
+ roi.top = y;
+ roi.right = roi.left + width;
+ roi.bottom = roi.top + height;
+
+ if (HGBASE_ERR_OK == HGBase_SetImageROI(image, &roi))
+ {
+ HGImage image2 = NULL;
+ if (HGBASE_ERR_OK == HGBase_CloneImage(image, 0, 0, &image2))
+ {
+ if (0 == SaveImage(image2, temp, outImagePath))
+ {
+ if (!temp)
+ {
+ m_saveFilePathList.push_back(outImagePath);
+ RestoreSaveFilePathList(m_saveFilePathList);
+ }
+
+ errInfo.clear();
+ ret = 0;
+ }
+
+ HGBase_DestroyImage(image2);
+ }
+ }
+
+ HGBase_DestroyImage(image);
+ }
+
+ return ret;
+ }
+
int ManagerV2::InitDevice(std::string& errInfo)
{
errInfo = "错误";
diff --git a/sdk/webservice/ManagerV2.h b/sdk/webservice/ManagerV2.h
index efb3f9fe..d985947f 100644
--- a/sdk/webservice/ManagerV2.h
+++ b/sdk/webservice/ManagerV2.h
@@ -176,6 +176,9 @@ namespace ver_2
int x, int y, int width, int height, bool temp, std::string& outImagePath, std::string& errInfo);
// 图像方向校正
int LocalImageDirectionCorrect(const std::string& imagePath, bool temp, std::string& outImagePath, std::string& errInfo);
+ // 裁剪图像
+ int LocalImageClip(const std::string& imagePath, int x, int y, int width, int height,
+ bool temp, std::string& outImagePath, std::string& errInfo);
// 设备初始化
int InitDevice(std::string& errInfo);
diff --git a/sdk/webservice/WSUser.cpp b/sdk/webservice/WSUser.cpp
index 0c9b43c8..8a258f60 100644
--- a/sdk/webservice/WSUser.cpp
+++ b/sdk/webservice/WSUser.cpp
@@ -285,6 +285,10 @@ namespace ver_2
{
ImageDirectionCorrect(json, func);
}
+ else if ("local_image_clip" == func || "base64_image_clip" == func || "image_clip" == func)
+ {
+ ImageClip(json, func);
+ }
else if ("upload_local_file" == func)
{
UploadLocalFile(json);
@@ -2091,6 +2095,88 @@ namespace ver_2
}
}
+ void WSUser::ImageClip(cJSON* json, const std::string& func)
+ {
+ assert(NULL != json);
+
+ int x = GetJsonIntValue(json, "x");
+ int y = GetJsonIntValue(json, "y");
+ int width = GetJsonIntValue(json, "width");
+ int height = GetJsonIntValue(json, "height");
+ bool find = false;
+ bool localSave = GetJsonBoolValue(json, "local_save", &find);
+ if (!find)
+ localSave = true;
+
+ std::string imagePath;
+ if ("image_clip" == func)
+ {
+ int imageIndex = GetJsonIntValue(json, "image_index");
+ std::string errInfo2;
+ GetManager()->SaveImage(imageIndex, true, imagePath, errInfo2);
+ }
+ else if ("local_image_clip" == func)
+ {
+ imagePath = Utf8ToStdString(GetJsonStringValue(json, "image_path"));
+ }
+ else if ("base64_image_clip" == func)
+ {
+ std::string imageBase64 = GetJsonStringValue(json, "image_base64");
+ std::string errInfo2;
+ GetManager()->SaveLocalImage(imageBase64, true, imagePath, errInfo2);
+ }
+
+ std::string outImagePath;
+ std::string errInfo;
+ int ret = GetManager()->LocalImageClip(imagePath, x, y, width, height, !localSave, outImagePath, errInfo);
+
+ if ("image_clip" == func || "base64_image_clip" == func)
+ {
+ HGBase_DeleteFile(imagePath.c_str());
+ }
+
+ 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);
+
+ cJSON* retJson = cJSON_CreateObject();
+ if (NULL != retJson)
+ {
+ cJSON_AddItemToObject(retJson, "func", cJSON_CreateString(func.c_str()));
+ if (findIden)
+ cJSON_AddItemToObject(retJson, "iden", cJSON_CreateString(iden.c_str()));
+ cJSON_AddItemToObject(retJson, "ret", cJSON_CreateNumber(ret));
+ if (0 != ret)
+ cJSON_AddItemToObject(retJson, "err_info", cJSON_CreateString(StdStringToUtf8(errInfo).c_str()));
+ else
+ {
+ if (localSave)
+ cJSON_AddItemToObject(retJson, "image_path", cJSON_CreateString(StdStringToUtf8(outImagePath).c_str()));
+ else
+ HGBase_DeleteFile(outImagePath.c_str());
+
+ if (getBase64)
+ cJSON_AddItemToObject(retJson, "image_base64", cJSON_CreateString(outImageBase64.c_str()));
+ }
+
+ char* resp = cJSON_Print(retJson);
+ if (NULL != resp)
+ {
+ SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
+ free(resp);
+ }
+
+ cJSON_Delete(retJson);
+ }
+ }
+
void WSUser::InitDevice(cJSON* json)
{
assert(NULL != json);
diff --git a/sdk/webservice/WSUser.h b/sdk/webservice/WSUser.h
index a0be68f5..1a879ed6 100644
--- a/sdk/webservice/WSUser.h
+++ b/sdk/webservice/WSUser.h
@@ -48,6 +48,7 @@ namespace ver_2
void ImageAddWatermark(cJSON* json, const std::string& func);
void ImageDecontamination(cJSON* json, const std::string& func);
void ImageDirectionCorrect(cJSON* json, const std::string& func);
+ void ImageClip(cJSON* json, const std::string& func);
void InitDevice(cJSON* json);
void DeinitDevice(cJSON* json);
diff --git a/test/webservice/demo.html b/test/webservice/demo.html
index 6f7a4813..853791fb 100644
--- a/test/webservice/demo.html
+++ b/test/webservice/demo.html
@@ -97,6 +97,12 @@
myCanvas.src = message['image_base64'];
alert(msg.data);
}
+ else if ("local_image_clip" == message['func'])
+ {
+ var myCanvas = document.getElementById("myCanvas");
+ myCanvas.src = message['image_base64'];
+ alert(msg.data);
+ }
else if ("init_device" == message['func'])
{
alert(msg.data);
@@ -316,6 +322,12 @@
myCanvas.src = message['image_base64'];
alert(msg.data);
}
+ else if ("image_clip" == message['func'])
+ {
+ var myCanvas = document.getElementById("myCanvas");
+ myCanvas.src = message['image_base64'];
+ alert(msg.data);
+ }
}
}
}
@@ -483,6 +495,20 @@
}));
}
+ function LocalImageClip()
+ {
+ socket.send(JSON.stringify({
+ 'func':'local_image_clip',
+ 'image_path':'D:\\1.jpg',
+ 'x':100,
+ 'y':50,
+ 'width':200,
+ 'height':600,
+ 'local_save':false,
+ 'get_base64':true
+ }));
+ }
+
function InitDevice()
{
socket.send(JSON.stringify({
@@ -818,6 +844,20 @@
}));
}
+ function ImageClip()
+ {
+ socket.send(JSON.stringify({
+ 'func':'image_clip',
+ 'image_index':0,
+ 'x':100,
+ 'y':50,
+ 'width':200,
+ 'height':600,
+ 'local_save':false,
+ 'get_base64':true
+ }));
+ }
+
window.onload = function()
{
var myimg = document.getElementById("myCanvas");
@@ -863,6 +903,7 @@
+
@@ -905,6 +946,7 @@
+