#ifndef RGA_COLOR_TRANSFER_H #define RGA_COLOR_TRANSFER_H #include #include #include #include #include typedef struct Rga_Buffer { unsigned char *pBuffer{nullptr}; // Buffer address int accFenceFd{0}; // Fence file descriptor for releasing the buffer int releaseFenceFd{0}; // Fence file descriptor for acquiring the buffer int nSrcFormt; // Source image format rga_buffer_handle_t hSrc; // Source image buffer handle rga_buffer_t SrcImg; // Source image buffer structure int nWidth; // Image width int nHeight; // Image height uint32_t nType; // Image format bool RegisterResource(unsigned char *pBuffer, int nWidth, int nHeight, uint32_t nType) { if (pBuffer == nullptr) return false; im_handle_param_t srcParam; srcParam.width = nWidth; srcParam.height = nHeight; srcParam.format = nType; hSrc = importbuffer_virtualaddr(pBuffer, &srcParam); SrcImg = wrapbuffer_handle(hSrc, nWidth, nHeight, nType); this->nWidth = nWidth; this->nHeight = nHeight; this->nType = nType; this->pBuffer = pBuffer; return true; } void ReleaseResource() { if (releaseFenceFd != 0) { imsync(releaseFenceFd); releaseFenceFd = 0; } int ret = 0; ret = releasebuffer_handle(hSrc); if (ret != 0) { printf("releasebuffer_handle failed, ret = %d\n", ret); } accFenceFd = 0; } } RGA_BUFFER, *PRGA_BUFFER; class RgaColorTransfer { public: RgaColorTransfer(); ~RgaColorTransfer(); static RgaColorTransfer *getInstance() { if (m_instance == nullptr) { m_instance = new RgaColorTransfer(); } return m_instance; } void setSrc(void *pbuffer, int nWidth, int nHeight, uint32_t nType) { if (m_Src != nullptr) m_Src->ReleaseResource(); m_Src->RegisterResource((unsigned char *)pbuffer, nWidth, nHeight, nType); } void setDst(void *pbuffer, int nWidth, int nHeight, uint32_t nType) { if (m_Dst != nullptr) m_Dst->ReleaseResource(); m_Dst->RegisterResource((unsigned char *)pbuffer, nWidth, nHeight, nType); } bool copyBuffer(cv::Rect srcRect, cv::Rect dstRect); bool transfer(int nType); bool resizeImage(cv::Rect srcRect, cv::Rect dstRect); void ReleaseResource(); private: static RgaColorTransfer *m_instance; // 单例模式的实例 PRGA_BUFFER m_Src; PRGA_BUFFER m_Dst; int m_releaseFenceFd; int m_accFenceFd; }; int resize_image(void *src_buf, int src_width, int src_height, void *dst_buf, int dst_width, int dst_height); #endif // RGA_COLOR_TRANSFER_H