123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #ifndef RGA_COLOR_TRANSFER_H
- #define RGA_COLOR_TRANSFER_H
- #include <rga/RgaApi.h>
- #include <rga/im2d.hpp>
- #include <rga/RgaUtils.h>
- #include <rga/RgaMutex.h>
- #include <opencv4/opencv2/opencv.hpp>
- 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
|