From 9eb5228f00ff356ac0128abfbb1c85a6abceeca7 Mon Sep 17 00:00:00 2001
From: chenke <chenke@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期三, 19 七月 2017 15:39:47 +0800
Subject: [PATCH] 图像缩放模块,中文字体支持模块。

---
 RtspFace/PL_Paint.cpp |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/RtspFace/PL_Paint.cpp b/RtspFace/PL_Paint.cpp
index fdf3170..daaca0d 100644
--- a/RtspFace/PL_Paint.cpp
+++ b/RtspFace/PL_Paint.cpp
@@ -2,7 +2,7 @@
 #include "MaterialBuffer.h"
 #include "logger.h"
 #include "MediaHelper.h"
-
+#include "CvUtil/CvxText.h"
 #include <string.h> // for memcpy
 #include <opencv2/core/mat.hpp>
 #include <opencv2/imgproc.hpp>
@@ -16,7 +16,7 @@
 	PipeMaterial pmList[2];
 	MB_Frame lastMbfBuffOrigin;
 	MB_Frame lastMbfBuffCopy;
-	
+
 	bool payError;
 
 	PL_Paint_Internal() : 
@@ -43,12 +43,13 @@
 		PipeMaterial _pm;
 		pmList[0] = _pm;
 		pmList[1] = _pm;
-		
+
 		MB_Frame _lastMbfBuff;
 		lastMbfBuffOrigin = _lastMbfBuff;
 		lastMbfBuffCopy = _lastMbfBuff;
-		
+
 		payError = true;
+
 	}
 };
 
@@ -78,6 +79,20 @@
 		in->config = *config;
 	}
 
+    if(in->config.fontPath.empty())
+    {
+        LOG_ERROR << "fontPath is null!" << LOG_ENDL;
+        return false;
+    }
+    if(in->config.plplCtx->cvxText != nullptr)
+    {
+        delete(in->config.plplCtx->cvxText);
+    }
+    CvxText* cvxText =new CvxText(in->config.fontPath.c_str());
+    in->config.plplCtx->cvxText = cvxText;
+    cvxText->setBackColor(cvScalar(128, 33, 14));
+    CvScalar font = cvScalar(40,1,0.2,1);
+    cvxText->setFont(0, &font);
 	return true;
 }
 
@@ -160,10 +175,31 @@
 	const uint16_t Y =  plplCtx->color_front.toY();
 	const uint16_t UV = plplCtx->color_front.toUV();
 
-    cv::putText(yMat, TXT, cv::Point(LTX, LTY), CV_FONT_HERSHEY_COMPLEX, 2, CV_RGB(Y, Y, Y));
-    cv::putText(uvMat, TXT, cv::Point(MH_SUBSAMPLE1(LTX, 2), MH_SUBSAMPLE1(LTY, 2)), CV_FONT_HERSHEY_COMPLEX, 1, CV_RGB(UV, UV, UV));
+    cv::putText(yMat, TXT, cv::Point(LTX, LTY), CV_FONT_HERSHEY_COMPLEX, 1, CV_RGB(Y, Y, Y));
+    cv::putText(uvMat, TXT, cv::Point(MH_SUBSAMPLE1(LTX, 2), MH_SUBSAMPLE1(LTY, 2)), CV_FONT_HERSHEY_COMPLEX, 0.5, CV_RGB(UV, UV, UV));
 }
+bool plplDraw_WText_NV12(PLPLContext* plplCtx, MB_Frame* paintMb, int& paramOffset)
+{
+    int LTX = plplCtx->params[paramOffset + 0].val_i;
+    int LTY = plplCtx->params[paramOffset + 1].val_i;
+    const char* TXT = plplCtx->params[paramOffset + 2].val_s;
+    paramOffset += 3;
 
+    int src_width = paintMb->width;
+    int src_height = paintMb->height;
+    uint8_t* src_y = (uint8_t*)(paintMb->buffer);
+    uint8_t* src_uv = (uint8_t*)(src_y + (src_height * src_width));
+    cv::Mat yMat(cv::Size(src_width, src_height), CV_8UC1, src_y);
+    cv::Mat uvMat(cv::Size(MH_SUBSAMPLE1(src_width, 2), MH_SUBSAMPLE1(src_height, 2)), CV_16UC1, src_uv);
+
+    // void rectangle(Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int lineType=8, int shift=0)
+
+    const uint16_t Y =  plplCtx->color_front.toY();
+    const uint16_t UV = plplCtx->color_front.toUV();
+    CvxText* cvText = (CvxText*)plplCtx->cvxText;
+    cvText->putText(yMat, L"涓枃ABCDabcd", cv::Point(LTX, LTY), CV_RGB(Y, Y, Y));
+    cvText->putText(uvMat, L"涓枃ABCDabcd", cv::Point(MH_SUBSAMPLE1(LTX, 2),MH_SUBSAMPLE1(LTY, 2)), CV_RGB(UV, UV, UV));
+}
 bool plplExecutor_YUV(PL_Paint_Internal *in)
 {
     MB_Frame* paintMb = &(in->lastMbfBuffOrigin);
@@ -250,6 +286,14 @@
 				else
 					ret = false;
                 break;
+
+            case PLPLC_WTEXT:
+                //TEXT LTX,LTY,"STR"
+                if (paintMb->type == MB_Frame::MBFT_NV12)
+                    ret = plplDraw_WText_NV12(plplCtx, paintMb, paramOffset);
+                else
+                    ret = false;
+                break;
         }
     }
 

--
Gitblit v1.8.0