From e74e0aeba69e62e22bc63192ea311d8218241545 Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@qq.com> Date: Wed, 15 Jun 2022 09:50:21 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=B0=B4=E5=8D=B0=E4=B8=8D?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=B8=AD=E6=96=87=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/imgproc/CvxText.cpp | 19 +++++++++++-------- modules/imgproc/CvxText.hpp | 2 +- modules/imgproc/HGImgProc.cpp | 33 ++++++++++++++++----------------- modules/imgproc/HGImgProc.h | 31 ++++++++++++++++++++++++++++--- sdk/webservice/ManagerV2.cpp | 20 ++++++++++++++++++-- sdk/webservice/WSUser.cpp | 4 ++-- test/webservice/demo.html | 2 +- 7 files changed, 77 insertions(+), 34 deletions(-) diff --git a/modules/imgproc/CvxText.cpp b/modules/imgproc/CvxText.cpp index e70001ba..0c6c65d6 100644 --- a/modules/imgproc/CvxText.cpp +++ b/modules/imgproc/CvxText.cpp @@ -138,9 +138,9 @@ HGResult CvxText::DrawString(HGImage image, const HGChar* text, HGColor color, H #endif { #if defined(HG_CMP_MSC) - DrawChar(image, pUnicode[i], locationX + vPos[i].left, locationY + vPos[i].top, color, fontSize, bold, italic); + DrawChar(image, pUnicode[i], color, locationX + vPos[i].left, locationY + vPos[i].top, fontSize, bold, italic); #else - DrawChar(image, pUnicodeEx[i], locationX + vPos[i].left, locationY + vPos[i].top, color, fontSize, bold, italic); + DrawChar(image, pUnicodeEx[i], color, locationX + vPos[i].left, locationY + vPos[i].top, fontSize, bold, italic); #endif ++i; } @@ -149,17 +149,18 @@ HGResult CvxText::DrawString(HGImage image, const HGChar* text, HGColor color, H if (underline) { - HGImgProc_ImageDrawLine(image, locationX, locationY + height - 1, locationX + width, locationY + height - 1, 1, color); + HGImgProc_ImageDrawLine(image, locationX, locationY + height - 1, + locationX + width, locationY + height - 1, color, 1, HGIMGPROC_LINETYPE_SOLID); } if (strikeout) { if (underline) HGImgProc_ImageDrawLine(image, locationX, locationY + (height - 1) / 2, - locationX + width, locationY + (height - 1) / 2, 1, color); + locationX + width, locationY + (height - 1) / 2, color, 1, HGIMGPROC_LINETYPE_SOLID); else HGImgProc_ImageDrawLine(image, locationX, locationY + height / 2, - locationX + width, locationY + height / 2, 1, color); + locationX + width, locationY + height / 2, color, 1, HGIMGPROC_LINETYPE_SOLID); } return HGBASE_ERR_OK; @@ -243,7 +244,7 @@ void CvxText::MeasureChar(HGUInt wc, HGUInt fontSize, HGBool bold, HGBool italic { FT_Matrix matrix; matrix.xx = 0x10000L; - matrix.xy = 0.5f * 0x10000L; + matrix.xy = 0.4f * 0x10000L; matrix.yx = 0; matrix.yy = 0x10000L; FT_Outline_Transform(&m_face->glyph->outline, &matrix); @@ -336,9 +337,11 @@ void CvxText::GetStringLocation(const HGChar* text, HGUInt fontSize, HGBool bold } } -void CvxText::DrawChar(HGImage image, HGUInt wc, HGInt x, HGInt y, HGColor color, HGUInt fontSize, HGBool bold, HGBool italic) +void CvxText::DrawChar(HGImage image, HGUInt wc, HGColor color, HGInt x, HGInt y, HGUInt fontSize, HGBool bold, HGBool italic) { assert(NULL != m_face); + assert(NULL != image); + assert(0 != fontSize); FT_Set_Pixel_Sizes(m_face, fontSize, fontSize); FT_UInt glyph_index = FT_Get_Char_Index(m_face, wc); @@ -358,7 +361,7 @@ void CvxText::DrawChar(HGImage image, HGUInt wc, HGInt x, HGInt y, HGColor color { FT_Matrix matrix; matrix.xx = 0x10000L; - matrix.xy = 0.5f * 0x10000L; + matrix.xy = 0.4f * 0x10000L; matrix.yx = 0; matrix.yy = 0x10000L; FT_Outline_Transform(&m_face->glyph->outline, &matrix); diff --git a/modules/imgproc/CvxText.hpp b/modules/imgproc/CvxText.hpp index 7ac854c5..ba231669 100644 --- a/modules/imgproc/CvxText.hpp +++ b/modules/imgproc/CvxText.hpp @@ -24,7 +24,7 @@ private: void MeasureChar(HGUInt wc, HGUInt fontSize, HGBool bold, HGBool italic, FT_BBox& acbox); void GetStringLocation(const HGChar* text, HGUInt fontSize, HGBool bold, HGBool underline, HGBool italic, HGBool strikeout, HGUInt &width, HGUInt &height, std::vector &vPos); - void DrawChar(HGImage image, HGUInt wc, HGInt x, HGInt y, HGColor color, HGUInt fontSize, HGBool bold, HGBool italic); + void DrawChar(HGImage image, HGUInt wc, HGColor color, HGInt x, HGInt y, HGUInt fontSize, HGBool bold, HGBool italic); private: FT_Library m_library; diff --git a/modules/imgproc/HGImgProc.cpp b/modules/imgproc/HGImgProc.cpp index e0ac9307..b054250e 100644 --- a/modules/imgproc/HGImgProc.cpp +++ b/modules/imgproc/HGImgProc.cpp @@ -366,32 +366,23 @@ HGResult HGAPI HGImgProc_ImageBlankCheck(HGImage image, const HGImgBlankCheckPar return HGBASE_ERR_OK; } -HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt x2, HGInt y2, HGUInt lineWidth, HGColor color) +HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt x2, HGInt y2, + HGColor color, HGUInt width, HGUInt type) { - if (NULL == image || 0 == lineWidth) + if (NULL == image || 0 == width || type < HGIMGPROC_LINETYPE_SOLID || type > HGIMGPROC_LINETYPE_DASH) { return HGBASE_ERR_INVALIDARG; } HGImageInfo imgInfo; HGBase_GetImageInfo(image, &imgInfo); - uint32_t type = imgInfo.type; - - HGByte* data = NULL; - HGBase_GetImageData(image, &data); - - HGImageRoi roi; - HGBase_GetImageROI(image, &roi); - HGUInt roiWidth = roi.right - roi.left; - HGUInt roiHeight = roi.bottom - roi.top; - - if (HGBASE_IMGTYPE_BINARY == type || HGBASE_IMGTYPE_GRAY == type) + if (HGBASE_IMGTYPE_BINARY == imgInfo.type || HGBASE_IMGTYPE_GRAY == imgInfo.type) { HGImage imageTmp = NULL; HGResult ret = HGBase_CloneImage(image, HGBASE_IMGTYPE_RGB, 0, &imageTmp); if (HGBASE_ERR_OK == ret) { - ret = HGImgProc_ImageDrawLine(imageTmp, x1, y1, x2, y2, lineWidth, color); + ret = HGImgProc_ImageDrawLine(imageTmp, x1, y1, x2, y2, color, width, type); if (HGBASE_ERR_OK == ret) { ret = HGBase_CopyImage(imageTmp, image); @@ -403,8 +394,16 @@ HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt return ret; } + HGByte* data = NULL; + HGBase_GetImageData(image, &data); + + HGImageRoi roi; + HGBase_GetImageROI(image, &roi); + HGUInt roiWidth = roi.right - roi.left; + HGUInt roiHeight = roi.bottom - roi.top; + uint32_t channels = 3; - if (HGBASE_IMGTYPE_BGRA == type || HGBASE_IMGTYPE_RGBA == type) + if (HGBASE_IMGTYPE_BGRA == imgInfo.type || HGBASE_IMGTYPE_RGBA == imgInfo.type) channels = 4; uint8_t* p = data + roi.top * imgInfo.widthStep + roi.left * channels; @@ -423,14 +422,14 @@ HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt HGUInt r = HG_GETCOLOR_R(color); HGUInt g = HG_GETCOLOR_G(color); HGUInt b = HG_GETCOLOR_B(color); - if (HGBASE_IMGTYPE_BGR == type || HGBASE_IMGTYPE_BGRA == type) + if (HGBASE_IMGTYPE_BGR == imgInfo.type || HGBASE_IMGTYPE_BGRA == imgInfo.type) { r = HG_GETCOLOR_B(color); g = HG_GETCOLOR_G(color); b = HG_GETCOLOR_R(color); } - cvLine(pImg, cvPoint(x1, y1), cvPoint(x2, y2), cvScalar(r, g, b), lineWidth); + cvLine(pImg, cvPoint(x1, y1), cvPoint(x2, y2), cvScalar(r, g, b), width); cvReleaseImageHeader(&pImg); return HGBASE_ERR_OK; } diff --git a/modules/imgproc/HGImgProc.h b/modules/imgproc/HGImgProc.h index 0de566a3..e4949567 100644 --- a/modules/imgproc/HGImgProc.h +++ b/modules/imgproc/HGImgProc.h @@ -11,16 +11,30 @@ /* 双线性插值 */ #define HGIMGPROC_INTERPOTYPE_LINEAR 2L -/* 水印位置 */ +/* 线条类型-实线 */ +#define HGIMGPROC_LINETYPE_SOLID 1L +/* 线条类型-虚线 */ +#define HGIMGPROC_LINETYPE_DASH 2L + +/* 水印位置-左侧 */ #define HGIMGPROC_WMPOSTYPE_LEFT 1L +/* 水印位置-上侧 */ #define HGIMGPROC_WMPOSTYPE_TOP 2L +/* 水印位置-右侧 */ #define HGIMGPROC_WMPOSTYPE_RIGHT 3L +/* 水印位置-下侧 */ #define HGIMGPROC_WMPOSTYPE_BOTTOM 4L +/* 水印位置-左上 */ #define HGIMGPROC_WMPOSTYPE_LEFTTOP 5L +/* 水印位置-右上 */ #define HGIMGPROC_WMPOSTYPE_RIGHTTOP 6L +/* 水印位置-左下 */ #define HGIMGPROC_WMPOSTYPE_LEFTBOTTOM 7L +/* 水印位置-右下 */ #define HGIMGPROC_WMPOSTYPE_RIGHTBOTTOM 8L +/* 水印位置-中间 */ #define HGIMGPROC_WMPOSTYPE_CENTER 9L +/* 水印位置-自定义 */ #define HGIMGPROC_WMPOSTYPE_LOCATION 10L /* 自动裁剪参数 */ @@ -112,9 +126,20 @@ HGEXPORT HGResult HGAPI HGImgProc_ImageAutoCrop(HGImage image, HGBool autoCrop, */ HGEXPORT HGResult HGAPI HGImgProc_ImageBlankCheck(HGImage image, const HGImgBlankCheckParam *param, HGBool *blank); -/* 画线 +/* 图像画线 +* 1) image: in, 图像句柄 +* 2) x1: in, 第一个点x坐标 +* 3) y1: in, 第一个点y坐标 +* 4) x2: in, 第二个点x坐标 +* 5) y2: in, 第二个点y坐标 +* 6) color: in, 颜色 +* 7) width: in, 线宽 +* 8) type: in, 表示线类型, 参见HGIMGPROC_LINETYPE_* +* 说明: +* 1) 操作的只是图像的ROI区域 */ -HGEXPORT HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt x2, HGInt y2, HGUInt lineWidth, HGColor color); +HGEXPORT HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt x2, HGInt y2, + HGColor color, HGUInt width, HGUInt type); /* 添加图像水印 * 1) image: in, 图像句柄 diff --git a/sdk/webservice/ManagerV2.cpp b/sdk/webservice/ManagerV2.cpp index 8de96b46..b4cea796 100644 --- a/sdk/webservice/ManagerV2.cpp +++ b/sdk/webservice/ManagerV2.cpp @@ -3602,6 +3602,22 @@ namespace ver_2 FindClose(hFind); #else + DIR* dir = opendir(m_bindFolder.c_str()); + if (NULL != dir) + { + struct dirent* dire = NULL; + while (dire = readdir(dir)) + { + char fileName[256]; + sprintf(fileName, "%s%s", m_bindFolder.c_str(), dire->d_name); + if (!IS_DIR(fileName)) + { + HGBase_DeleteFile(fileName); + } + } + + closedir(dir); + } #endif } @@ -3743,9 +3759,9 @@ namespace ver_2 char destName[256]; sprintf(destName, fmt, m_bindFolder.c_str(), m_bindNameBase + tables[i].idx - value, tables[i].format.c_str()); #if defined(HG_CMP_MSC) - MoveFileA(fileName, destName); + MoveFileA(fileName, destName); #else - rename(fileName, destName); + rename(fileName, destName); #endif } } diff --git a/sdk/webservice/WSUser.cpp b/sdk/webservice/WSUser.cpp index c7bd66b6..704a5e70 100644 --- a/sdk/webservice/WSUser.cpp +++ b/sdk/webservice/WSUser.cpp @@ -1775,7 +1775,7 @@ namespace ver_2 assert(NULL != json); std::string imagePath = Utf8ToStdString(GetJsonStringValue(json, "image_path")); - std::string text = GetJsonStringValue(json, "text"); + std::string text = Utf8ToStdString(GetJsonStringValue(json, "text")); bool find; std::string textColor = GetJsonStringValue(json, "text_color", &find); @@ -4129,7 +4129,7 @@ namespace ver_2 assert(NULL != json); int imageIndex = GetJsonIntValue(json, "image_index"); - std::string text = GetJsonStringValue(json, "text"); + std::string text = Utf8ToStdString(GetJsonStringValue(json, "text")); bool find; std::string textColor = GetJsonStringValue(json, "text_color", &find); diff --git a/test/webservice/demo.html b/test/webservice/demo.html index fc413688..927c1878 100644 --- a/test/webservice/demo.html +++ b/test/webservice/demo.html @@ -369,7 +369,7 @@ socket.send(JSON.stringify({ 'func':'local_image_add_watermark', 'image_path':'D:\\1.jpg', - 'text':'1234567890', + 'text':'扫描仪,1234qwer', 'text_color':'#FF0000', 'text_pos':'right_top', 'font_size':60,