| | |
| | | #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>
|
| | |
|
| | | #ifdef ENABLE_WTEXT
|
| | | #include "CvUtil/CvxText.h"
|
| | | #endif
|
| | |
|
| | | PLPLType::PLPLType(const char* _val_s)
|
| | | {
|
| | | for (int i = 0; i < sizeof(val_s); i++)
|
| | | val_s[i] = _val_s[i];
|
| | | }
|
| | |
|
| | | PLPLType::PLPLType(const wchar_t* _val_s)
|
| | | {
|
| | |
| | |
|
| | | PLPLContext::~PLPLContext()
|
| | | {
|
| | | delete (CvxText*)cvxText;
|
| | | #ifdef ENABLE_WTEXT
|
| | | delete (CvxText*)cvxText;
|
| | | cvxText = nullptr;
|
| | | #endif
|
| | | }
|
| | |
|
| | | struct PL_Paint_Internal
|
| | |
| | | in->config = *config;
|
| | | }
|
| | |
|
| | | if(in->config.plplCtx->cvxText != nullptr)
|
| | | #ifdef ENABLE_WTEXT
|
| | | if(in->config.plplCtx->cvxText != nullptr)
|
| | | {
|
| | | delete (CvxText*)in->config.plplCtx->cvxText;
|
| | | }
|
| | | |
| | | if(in->config.fontPath.empty())
|
| | | {
|
| | | LOG_ERROR << "fontPath is null!" << LOG_ENDL;
|
| | | return false;
|
| | | }
|
| | | else if (in->config.fontPath == " ")
|
| | |
|
| | | if(!in->config.fontPath.empty())
|
| | | {
|
| | | CvxText* cvxText = new CvxText(in->config.fontPath.c_str());
|
| | | in->config.plplCtx->cvxText = cvxText;
|
| | |
| | | CvScalar font = cvScalar(40, 1, 0.2, 1);
|
| | | cvxText->setFont(0, &font);
|
| | | }
|
| | | #endif
|
| | |
|
| | | return true;
|
| | | }
|
| | |
| | | return true;
|
| | | }
|
| | |
|
| | | bool plplDraw_Rect_RGB565(PLPLContext* plplCtx, MB_Frame* paintMb, int& paramOffset)
|
| | | {
|
| | | int LTX = plplCtx->params[paramOffset + 0].val_i;
|
| | | int LTY = plplCtx->params[paramOffset + 1].val_i;
|
| | | int RBX = plplCtx->params[paramOffset + 2].val_i;
|
| | | int RBY = plplCtx->params[paramOffset + 3].val_i;
|
| | | paramOffset += 4;
|
| | |
|
| | | int src_width = paintMb->width;
|
| | | int src_height = paintMb->height;
|
| | | uint8_t* src_rgb = (uint8_t*)(paintMb->buffer);
|
| | | cv::Mat rgbMat(cv::Size(src_width, src_height), CV_16UC1, src_rgb);
|
| | |
|
| | | // void rectangle(Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int lineType=8, int shift=0)
|
| | |
|
| | | const uint16_t RGB565 = plplCtx->color_front.toY();
|
| | | cv::rectangle(rgbMat, cv::Point(LTX, LTY), cv::Point(RBX, RBY), CV_RGB(RGB565, RGB565, RGB565), 4);
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | bool plplDraw_Text_YUV420(PLPLContext* plplCtx, MB_Frame* paintMb, int& paramOffset)
|
| | | {
|
| | | return false;
|
| | |
| | |
|
| | | bool plplDraw_WText_NV12(PLPLContext* plplCtx, MB_Frame* paintMb, int& paramOffset)
|
| | | {
|
| | | #ifdef ENABLE_WTEXT
|
| | | int LTX = plplCtx->params[paramOffset + 0].val_i;
|
| | | int LTY = plplCtx->params[paramOffset + 1].val_i;
|
| | | const char* WTXT = plplCtx->params[paramOffset + 2].val_s;
|
| | |
| | | cvText->putText(uvMat, (const wchar_t*)WTXT, cv::Point(MH_SUBSAMPLE1(LTX, 2), MH_SUBSAMPLE1(LTY, 2)), CV_RGB(UV, UV, UV)); // L"中文ABCDabcd"
|
| | |
|
| | | return true;
|
| | | #else
|
| | | return false;
|
| | | #endif
|
| | | }
|
| | |
|
| | | bool plplExecutor_YUV(PL_Paint_Internal *in)
|
| | |
| | | ret = plplDraw_Rect_YUV420(plplCtx, paintMb, paramOffset);
|
| | | else if (paintMb->type == MB_Frame::MBFT_NV12)
|
| | | ret = plplDraw_Rect_NV12(plplCtx, paintMb, paramOffset);
|
| | | else if (paintMb->type == MB_Frame::MBFT_RGB565)
|
| | | ret = plplDraw_Rect_RGB565(plplCtx, paintMb, paramOffset);
|
| | | else
|
| | | ret = false;
|
| | | break;
|
| | |
| | | ret = plplDraw_Text_YUV420(plplCtx, paintMb, paramOffset);
|
| | | else if (paintMb->type == MB_Frame::MBFT_NV12)
|
| | | ret = plplDraw_Text_NV12(plplCtx, paintMb, paramOffset);
|
| | | //else if (paintMb->type == MB_Frame::MBFT_RGB565)
|
| | | // ret = plplDraw_Text_RGB565(plplCtx, paintMb, paramOffset);
|
| | | else
|
| | | ret = false;
|
| | | break;
|
| | |
|
| | | case PLPLC_WTEXT:
|
| | | //WTEXT LTX,LTY,"STR"
|
| | | if (paintMb->type == MB_Frame::MBFT_NV12)
|
| | | if (paintMb->type == MB_Frame::MBFT_NV12)
|
| | | ret = plplDraw_WText_NV12(plplCtx, paintMb, paramOffset);
|
| | | //else if (paintMb->type == MB_Frame::MBFT_RGB565)
|
| | | // ret = plplDraw_WText_RGB565(plplCtx, paintMb, paramOffset);
|
| | | else
|
| | | ret = false;
|
| | | break;
|
| | |
| | | return ret;
|
| | | }
|
| | |
|
| | | /*static*/ bool PL_Paint::pay_breaker_MBFT_YUV(const PipeMaterial* pm, void* args)
|
| | | /*static*/ bool PL_Paint::pay_breaker_MBFT(const PipeMaterial* pm, void* args)
|
| | | {
|
| | | PL_Paint_Internal* in = (PL_Paint_Internal*)args;
|
| | |
|
| | | if (pm->type != PipeMaterial::PMT_FRAME)
|
| | | {
|
| | | LOG_ERROR << "Only support PMT_FRAME" << LOG_ENDL;
|
| | | return false;
|
| | | }
|
| | | |
| | | if (pm->buffer == nullptr)
|
| | | return false;
|
| | | |
| | | MB_Frame* frame = (MB_Frame*)pm->buffer;
|
| | | if (frame->type != MB_Frame::MBFT_YUV420 && frame->type != MB_Frame::MBFT_NV12)
|
| | | {
|
| | | LOG_ERROR << "Only support MBFT_YUV420 and MBFT_NV12" << LOG_ENDL;
|
| | | in->payError = true;
|
| | | return false;
|
| | | }
|
| | | MB_Frame* frame = (MB_Frame*)pm->buffer;
|
| | |
|
| | | in->lastMbfBuffOrigin.type = frame->type;
|
| | | in->lastMbfBuffOrigin.buffer = frame->buffer;
|
| | |
| | | {
|
| | | PL_Paint_Internal* in = (PL_Paint_Internal*)internal;
|
| | | in->payError = true;
|
| | | pm.breake(PipeMaterial::PMT_FRAME, MB_Frame::MBFT_YUV420, PL_Paint::pay_breaker_MBFT_YUV, in);
|
| | | pm.breake(PipeMaterial::PMT_FRAME, MB_Frame::MBFT_NV12, PL_Paint::pay_breaker_MBFT_YUV, in);
|
| | |
|
| | | //#todo support RGB
|
| | | |
| | | if (pm.type != PipeMaterial::PMT_FRAME)
|
| | | {
|
| | | LOG_ERROR << "Only support PMT_FRAME" << LOG_ENDL;
|
| | | return false;
|
| | | }
|
| | |
|
| | | if (pm.buffer == nullptr)
|
| | | return false;
|
| | |
|
| | | MB_Frame* frame = (MB_Frame*)pm.buffer;
|
| | | switch(frame->type)
|
| | | {
|
| | | case MB_Frame::MBFT_YUV420:
|
| | | case MB_Frame::MBFT_NV12:
|
| | | case MB_Frame::MBFT_RGB565:
|
| | | pm.breake(PipeMaterial::PMT_FRAME, MB_Frame::MBFT_RGB565, PL_Paint::pay_breaker_MBFT, in);
|
| | | return !(in->payError);
|
| | | default:
|
| | | LOG_ERROR << "Only support MBFT_YUV420 / MBFT_NV12 / MBFT_RGB565" << LOG_ENDL;
|
| | | in->payError = true;
|
| | | break;
|
| | | }
|
| | |
|
| | | return !(in->payError);
|
| | | }
|
| | |
|