RGA (Raster Graphic Acceleration Unit)是一个独立的2D硬件加速器,可用于加速点/线绘制,执行图像缩放、旋转、bitBlt、alpha混合等常见的2D图形操作。
瑞芯微官方示例
https://github.com/airockchip/librga/tree/main/samples
#define LOG_NDEBUG 0
#undef LOG_TAG
#define LOG_TAG "rga_copy_demo"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <linux/stddef.h>
#include "RgaUtils.h"
#include "im2d.hpp"
#include "utils.h"
#define LOCAL_FILE_PATH "/data"
int main() {
int ret = 0;
int src_width, src_height, src_format;
int dst_width, dst_height, dst_format;
char *src_buf, *dst_buf;
int src_buf_size, dst_buf_size;
rga_buffer_t src_img, dst_img;
rga_buffer_handle_t src_handle, dst_handle;
memset(&src_img, 0, sizeof(src_img));
memset(&dst_img, 0, sizeof(dst_img));
src_width = 1280;
src_height = 720;
src_format = RK_FORMAT_RGBA_8888;
dst_width = 1280;
dst_height = 720;
dst_format = RK_FORMAT_RGBA_8888;
src_buf_size = src_width * src_height * get_bpp_from_format(src_format);
dst_buf_size = dst_width * dst_height * get_bpp_from_format(dst_format);
src_buf = (char *)malloc(src_buf_size);
dst_buf = (char *)malloc(dst_buf_size);
/* fill image data */
if (0 != read_image_from_file(src_buf, LOCAL_FILE_PATH, src_width, src_height, src_format, 0)) {
printf("src image read err\n");
draw_rgba(src_buf, src_width, src_height);
}
memset(dst_buf, 0x80, dst_buf_size);
src_handle = importbuffer_virtualaddr(src_buf, src_buf_size);
dst_handle = importbuffer_virtualaddr(dst_buf, dst_buf_size);
if (src_handle == 0 || dst_handle == 0) {
printf("importbuffer failed!\n");
goto release_buffer;
}
src_img = wrapbuffer_handle(src_handle, src_width, src_height, src_format);
dst_img = wrapbuffer_handle(dst_handle, dst_width, dst_height, dst_format);
ret = imcheck(src_img, dst_img, {}, {});
if (IM_STATUS_NOERROR != ret) {
printf("%d, check error! %s", __LINE__, imStrError((IM_STATUS)ret));
return -1;
}
ret = imcopy(src_img, dst_img);
if (ret == IM_STATUS_SUCCESS) {
printf("%s running success!\n", LOG_TAG);
} else {
printf("%s running failed, %s\n", LOG_TAG, imStrError((IM_STATUS)ret));
goto release_buffer;
}
printf("output [0x%x, 0x%x, 0x%x, 0x%x]\n", dst_buf[0], dst_buf[1], dst_buf[2], dst_buf[3]);
write_image_to_file(dst_buf, LOCAL_FILE_PATH, dst_width, dst_height, dst_format, 0);
release_buffer:
if (src_handle)
releasebuffer_handle(src_handle);
if (dst_handle)
releasebuffer_handle(dst_handle);
if (src_buf)
free(src_buf);
if (dst_buf)
free(dst_buf);
return ret;
}