123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- #include "RgaColorTransfer.h"
- // static member initialization
- RgaColorTransfer* RgaColorTransfer::m_instance = nullptr;
- RgaColorTransfer::RgaColorTransfer()
- {
- m_Src = new RGA_BUFFER;
- m_Dst = new RGA_BUFFER;
- }
- RgaColorTransfer::~RgaColorTransfer()
- {
- ReleaseResource();
- }
- bool RgaColorTransfer::copyBuffer(cv::Rect srcRect, cv::Rect dstRect)
- {
- if (!m_Src || !m_Dst)
- return false;
- int ret = 0;
- im_rect srcRectRga = { srcRect.x, srcRect.y, srcRect.width, srcRect.height };
- im_rect dstRectRga = { dstRect.x, dstRect.y, dstRect.width, dstRect.height };
- ret = imcheck(m_Src->SrcImg, m_Dst->SrcImg, srcRectRga, dstRectRga);
- if (ret != 0)
- {
- printf("imcheck failed, ret = %d\n", ret);
- return false;
- }
- // Use improcess to perform the copy operation between the source and destination buffers.
- ret = improcess(m_Src->SrcImg,m_Dst->SrcImg,{},srcRectRga,dstRectRga,{},IM_ASYNC);
-
- if (ret != 0)
- {
- printf("improcess failed, ret = %d\n", ret);
- return false;
- }
- return true;
- }
- bool RgaColorTransfer::transfer(int nType)
- {
- if (!m_Src || !m_Dst)
- return false;
- int ret = 0;
- ret = imcvtcolor(m_Src->SrcImg, m_Dst->SrcImg,m_Src->nType,m_Dst->nType);
- if (ret != 0)
- {
- printf("imcvtcolor failed, ret = %d\n", ret);
- return false;
- }
- return true;
- }
- bool RgaColorTransfer::resizeImage(cv::Rect srcRect, cv::Rect dstRect)
- {
- if(!m_Src || !m_Dst)
- return false;
-
- if(m_Src->nWidth == 0 || m_Src->nHeight == 0 || m_Dst->nWidth == 0 || m_Dst->nHeight == 0)
- return false;
- if(m_Src->nWidth == m_Dst->nWidth && m_Src->nHeight == m_Dst->nHeight)
- return true;
- int ret = 0;
- double fx = (double)dstRect.width / (double)srcRect.width;
- double fy = (double)dstRect.height / (double)srcRect.height;
- ret = imresize(m_Src->SrcImg, m_Dst->SrcImg,fx,fy,INTER_LINEAR,IM_SYNC);
- if(ret != 0)
- {
- printf("imresize failed, ret = %d\n", ret);
- return false;
- }
- return true;
- }
- void RgaColorTransfer::ReleaseResource()
- {
- if (m_Src)
- {
- m_Src->ReleaseResource();
- delete m_Src;
- m_Src = nullptr;
- }
- if (m_Dst)
- {
- m_Dst->ReleaseResource();
- delete m_Dst;
- m_Dst = nullptr;
- }
- }
- int resize_image(void * src_buf, int src_width, int src_height, void * dst_buf, int dst_width, int dst_height)
- {
- int ret;
- rga_info_t src_info;
- rga_info_t dst_info;
- // Initialize source image information
- memset(&src_info, 0, sizeof(rga_info_t));
- src_info.fd = -1;
- src_info.virAddr = src_buf;
- src_info.mmuFlag = 1;
- rga_set_rect(&src_info.rect, 0, 0, src_width, src_height, src_width, src_height, RK_FORMAT_RGB_888);
- // Initialize destination image information
- memset(&dst_info, 0, sizeof(rga_info_t));
- dst_info.fd = -1;
- dst_info.virAddr = dst_buf;
- dst_info.mmuFlag = 1;
- rga_set_rect(&dst_info.rect, 0, 0, dst_width, dst_height, dst_width, dst_height, RK_FORMAT_RGB_888);
- // Perform the resize operation
- ret = c_RkRgaBlit(&src_info, &dst_info, NULL);
- if (ret) {
- printf("RGA resize failed: %d\n", ret);
- return ret;
- }
- return 0;
- }
|