HOME
Shop
  • English
  • 简体中文
HOME
Shop
  • English
  • 简体中文
  • Product Series

    • FPGA+ARM

      • GM-3568JHF

        • Introduction

          • GM-3568JHF Introduction
        • Quick Start

          • Preface
          • Environment Setup
          • Compilation Notes
          • Flashing Guide
          • Debugging Tools
          • Software Update
          • Viewing System Information
          • Test Commands
          • Application Compilation
          • Source Code Access
        • Peripherals & Interfaces

          • USB
          • Display and Touch
          • Ethernet
          • WIFI
          • Bluetooth
          • TF-Card
          • Audio
          • Serial Port
          • CAN
          • RTC
        • Application Development

          • UART Read/Write Demo
          • Key Detection Demo
          • LED Blink Demo
          • MIPI Screen Detection Demo
          • Read USB Device Information Demo
          • FAN Detection Demo
          • FPGA FSPI Communication Demo
          • FPGA DMA Read/Write Demo
          • GPS Debugging Demo
          • Ethernet Test Demo
          • RS485 Read/Write Demo
          • FPGA I2C Read/Write Demo
          • PN532 NFC Card-Reading Demo
          • TF Card Read/Write Demo
        • QT Development

          • ARM64 Cross-Compiler Environment Setup
          • Adding a QT Program to Boot Auto-Start
        • RKNN_NPU Development

          • RK3568 NPU Overview
          • Development Environment Setup
          • Run the Official YOLOv5 Example
        • FPGA Development

          • ARM and FPGA Communication
          • FPGA Development Manual
        • Others

          • Modifying the Root Filesystem
          • System Auto-Start Services
        • Downloads

          • Downloads
      • MB-E30P

        • Introduction

          • MB-E30P Introduction
        • Quick Start

          • Preface
          • Environment Setup
          • Compilation Instructions
          • Flashing Guide
          • Debugging Tools
          • Software Update
          • Viewing Information
          • Test Commands
          • Application Compilation
          • Source Code Acquisition
        • Peripherals & Interfaces

          • USB
          • Display and Touch
          • Ethernet
          • WIFI
          • Bluetooth
          • TF-Card
          • Audio
          • RTC
        • Application Development

          • Key Detection Demo
          • LED Blink Demo
          • MIPI Screen Detection Demo
          • Read USB Device Information Demo
          • FAN Detection Demo
          • FPGA FSPI Communication Demo
          • FPGA DMA Read/Write Demo
          • Ethernet Test Demo
          • FPGA IIC Read/Write Demo
          • PN532 NFC Card Reading Demo
          • TF Card Read/Write Demo
        • QT Development

          • ARM64 Cross-Compiler Environment Setup
          • Adding a QT Program to the Boot Auto-Start Service
        • RKNN_NPU Development

          • RK3568 NPU Overview
          • Development Environment Setup
          • Run the Official YOLOv5 Example
          • Model Conversion In Detail
          • Run Custom Models on the Board
        • FPGA Development

          • ARM and FPGA Communication
          • FPGA Development Manual
        • Others

          • Modifying the Root Filesystem
          • System Auto-Start Service
        • Downloads

          • Downloads
    • ShimetaPi

      • M4-R1

        • Introduction

          • M4-R1 Introduction
        • Quick Start

          • OpenHarmony Overview
          • Image Burning
          • Application Development Quick Start
          • Device Development Quick Start
        • Application Development

          • ArkUI

            • ArkTS Language Overview
            • UI Components - Row Container Introduction
            • UI Components - Column Container Introduction
            • UI Components - Text Component
            • UI Components - Toggle Component
            • UI Components - Slider Component
            • UI Components - Animation Component & Transition Component
          • Documentation

            • OpenHarmony Official Materials
          • Development Notes

            • Full-SDK Replacement Tutorial
            • Introducing and Using Third-Party Libraries
            • HDC Debugging
            • Restore Factory Mode via Command Line
            • Upgrade App to System Permission
          • First App

            • Build Your First ArkTS Application - HelloWorld
          • Demos

            • Serial-Debug-Assistant Application Demo
            • Writing-Board Application Demo
            • Digital Clock Application Demo
            • Wi-Fi Information Acquisition Application Demo
        • Device Development

          • Ubuntu Development

            • Environment Setup
            • Download Source Code
            • Compile Source Code
          • DevEco Device Tool

            • Tool Introduction
            • Development Environment Construction
            • Import the SDK
            • HUAWEI DevEco Tool Function Introduction
        • Kernel Peripherals & Interfaces

          • Guide
          • Device Tree Introduction
          • NAPI Introduction
          • ArkTS Introduction
          • NAPI Development Hands-on Demo
          • GPIO Introduction
          • I2C Communication
          • SPI Communication
          • PWM Control
          • UART Communication
          • TF Card (MicroSD)
          • Screen (Display)
          • Touch
          • Ethernet
          • M.2 SSD
          • Audio
          • WIFI & BT
          • Camera
        • Downloads

          • Downloads
      • M5-R1

        • Introduction

          • M5-R1 Development Docs
        • Quick Start

          • Image Burning
          • Environment Setup
          • Download Source Code
        • Peripherals & Interfaces

          • Raspberry Pi Interfaces
          • GPIO Interface
          • I2C Interface
          • SPI Communication
          • PWM Control
          • Serial Port Communication
          • TF Card
          • Display
          • Touch
          • Audio
          • RTC
          • Ethernet
          • M.2
          • MINI-PCIE
          • Camera
          • WIFI & BT
        • Downloads

          • Downloads
      • Pico-G1

        • Product Overview

          • Product Introduction
          • SDK Version Information
        • Quick Start

          • Development Environment Setup
          • Image Build
          • Image Flashing
          • System Login
          • Network Configuration
          • File Transfer
          • SDK Directory Structure
          • Deploying Your First Application
          • Deploying Your First Driver
          • Mounting an SD Card
        • Peripherals & Interfaces

          • GPIO Control
          • UART Serial Communication
          • I2C Communication
          • SPI Communication
        • MPP Media Development

          • MPP Media Processing Software
          • Image Processing Chain
          • Video Input
          • Image Encoding
        • NPU & AI

          • NPU Driver and Runtime Library Architecture
          • .xmm Model Loading
          • SVP Video Processing
          • AI Noise Reduction (AI_NR)
        • Application Samples

          • Encryption/Decryption Application
          • ADC Acquisition Application
          • Low-Power Application
          • Audio Processing Application
          • Video Encoding Application
          • Video Input Application
          • Video Graphics Subsystem (VGS) Application
          • 08 Region Overlay Application
          • 09 Intelligent Video Engine Application
          • 10 UVC Webcam Application
          • 11 All-in-One Quickstart Application
          • 12 FPN Correction Application
          • 13 Regional Motion Detection Application
          • 14 MTCNN Face Detection Application
        • Expansion Board Peripheral Examples

          • 00 - Pico Expansion Board Peripheral Examples Overview
          • 01 - OLED Display Application
          • 02 - TFT Display Application
          • 03 - MPU6050 Gyroscope Application
          • 04 - ADC Acquisition Application
          • 05 - Passive Buzzer Application
          • 06 - MQ Gas Sensor Application
          • 07 - GPS Positioning Application
          • 08 - SHT20 Temperature & Humidity Application
          • 09 - Ultrasonic Ranging Application
          • 10 - SpO2 Sensor Application
          • 11 - DC Motor Control Application
          • 12 - Servo Control Application
    • OpenHarmony

      • SC-3568HA

        • Introduction

          • SC-3568HA Overview
        • Quick Start Guide

          • OpenHarmony Overview
          • Image Flashing
          • Setting Up the Development Environment
          • Hello World Application and Deployment
        • Application Development

          • ArkUI

            • Introduction to ArkTS Language
            • Introduction to UI Components and Practical Applications (Part 1)
            • Introduction to UI Components and Practical Applications (Part 2)
            • Introduction to UI Components and Practical Applications (Part 3)
          • Expand

            • Getting Started Guide
            • Referencing and Using Third-Party Libraries
            • Application Compilation and Deployment
            • Command-Line Factory Reset
            • System Debugging -- HDC Debugging
            • APP Stability Testing
            • Chapter 7 Application Testing
        • Device Development

          • Environment Setup
          • Download Source Code
          • Compiling Source Code
        • Peripheral And Interface

          • Raspberry Pi interface
          • GPIO Interface
          • I2C Interface
          • SPI communication
          • PWM (Pulse Width Modulation) control
          • Serial port communication
          • TF Card
          • Display Screen
          • Touch
          • Audio
          • RTC
          • Ethernet
          • M.2
          • MINI-PCIE
          • Camera
          • WIFI&BT
          • Raspberry Pi expansion board
        • Downloads

          • Downloads
      • M-K1HSE

        • Introduction

          • M-K1HSE Introduction
        • Quick Start

          • Development environment construction
          • Source code acquisition
          • Compilation Notes
          • Burning Guide
        • Application Development

          • Application Development Environment Setup
          • First Application - Hello World
        • Peripherals and interfaces

          • 01 Audio
          • 02 RS485
          • 03 Display
        • System customization development

          • System transplant
          • System customization
          • Driver Development
          • System Debugging
          • OTA Update
        • Downloads

          • Downloads
    • HVS Camera

      • Quick Start

        • SDK Overview
        • Downloads
        • Your First C++ Program
        • Python Data Analysis
        • MultiVision Studio
      • Development

        • Programming Guides

          • Open Camera
          • Read Events
          • Recording & Replay
          • Event Processing (Denoising)
          • Display & Visualization
          • Tuning
          • Capture APS Image
        • Toolkit SDK

          • Hybrid Vision Toolkit
          • Quick Start
          • C++ API
          • Python API
        • Algorithm

          • Hybrid Vision Algo
          • Hybrid Vision Algo API
          • Windows Algo SDK
        • Samples Overview
        • Applications
      • Fundamentals

        • Event Camera Fundamentals
        • HVS Hybrid Vision
        • Event Visualization
        • Data Formats Reference
        • Glossary
        • Bias & Tuning
        • Video Tutorials
      • USB Cameras

        • HVS Camera Quick Start
        • Networking Capabilities

          • HVS Camera System Architecture
          • EVS Network Server
          • EVS Time Sync
          • Web Window
        • HVS Camera Compatibility Matrix
        • FAQ & Troubleshooting Guide
        • Products

          • CF-NRS1 (Lingguang No.1 Hybrid Vision Camera)
      • MIPI Modules

        • MIPI Module Quick Start
        • Carrier Boards

          • RDK X5 Carrier Board Adaptation
          • Raspberry Pi Carrier Board Adaptation
          • Digua Pi Carrier Board Adaptation
          • ShimeTai Board Carrier Board Adaptation
        • MIPI Module Compatibility Matrix
        • Products

          • EVS_003 Sensor Module
    • AI-model

      • 1684XB-32T

        • Introduction

          • AIBOX-1684XB-32 Introduction
        • Quick Start

          • First Use
          • Network Configuration
          • Disk Usage
          • Memory Allocation
          • Fan Control Strategy
          • Firmware Upgrade
          • Cross Compilation
          • Model Quantization
        • Application Development

          • Development Overview

            • Sophgo SDK Development
            • Sophgo Demo Introduction
          • Large Language Models

            • Deploying Llama3 Example
            • Sophon LLM_api_server Development
            • Deploying MiniCPM-V-2_6
            • Qwen-2-5-VL Image and Video Recognition Demo
            • Qwen3-chat Demo
            • Qwen3-Qwen Agent-MCP Development
            • Qwen3-langchain-AI Agent
          • Deep Learning

            • ResNet (Image Classification)
            • LPRNet (License Plate Recognition)
            • SAM (General Image Segmentation Foundation Model)
            • YOLOv5 (Object Detection)
            • OpenPose (Human Keypoint Detection)
            • PP-OCR (Optical Character Recognition)
        • Downloads

          • Downloads
      • 1684X-416T

        • Introduction

          • AIBOX-1684X-416 Introduction
        • Demo Quick Guide

          • ShimeTai Intelligent Monitoring Demo Quick Usage Guide
      • RDK-X5

        • Introduction

          • RDK-X5 Hardware Introduction
        • Quick Start

          • RDK-X5 Quick Start
        • Application Development

          • AI Online Model Development

            • Experiment 01 - Access Volcengine Doubao AI
            • Experiment 02 - Image Analysis
            • Experiment 03 - Multimodal Visual Analysis & Localization
            • Experiment 04 - Multimodal Image-Text Comparison
            • Experiment 05 - Multimodal Document/Table Analysis
            • Experiment 06 - Camera-based AI Visual Analysis
          • Large Language Models

            • Experiment 01 - Speech Recognition
            • Experiment 02 - Voice Conversation
            • Experiment 03 - Multimodal Image Analysis - Voice
            • Experiment 04 - Multimodal Image Comparison - Voice
            • Experiment 05 - Multimodal Document Analysis - Voice
            • Experiment 06 - Multimodal Vision Application - Voice
          • ROS2 Basics

            • Experiment 01 - Environment Setup
            • Experiment 02 - Create & Build a Workspace Package
            • Experiment 03 - Run ROS2 Topic Communication Node
            • Experiment 04 - ROS2 Camera Application
          • 40-pin IO Development

            • Experiment 01 - GPIO Output (LED Blink)
            • Experiment 02 - GPIO Input
            • Experiment 03 - Button-controlled LED
            • Experiment 04 - PWM Output
            • Experiment 05 - Serial Output
            • Experiment 06 - I2C Experiment
            • Experiment 07 - SPI Experiment
          • USB Module Usage

            • Experiment 01 - USB Voice Module Usage
            • Experiment 02 - Sound Source Localization Module
          • Machine Vision Practice

            • Experiment 01 - Open USB Camera
            • Experiment 02 - Color Recognition
            • Experiment 03 - Gesture Recognition
            • Experiment 04 - YOLOv5 Object Detection
      • RDK-S100

        • Introduction

          • RDK-S100 Hardware Introduction
        • Quick Start

          • RDK-S100 Quick Start
        • Application Development

          • AI Online Model Development

            • Experiment 01 - Access Volcengine Doubao AI
            • Experiment 02 - Image Analysis
            • Experiment 03 - Multimodal Visual Analysis & Localization
            • Experiment 04 - Multimodal Image-Text Comparison
            • Experiment 05 - Multimodal Document/Table Analysis
            • Experiment 06 - Camera-based AI Visual Analysis
          • Large Language Models

            • Experiment 01 - Speech Recognition
            • Experiment 02 - Voice Conversation
            • Experiment 03 - Multimodal Image Analysis - Voice
            • Experiment 04 - Multimodal Image Comparison - Voice
            • Experiment 05 - Multimodal Document Analysis - Voice
            • Experiment 06 - Multimodal Vision Application - Voice
          • ROS2 Basics

            • Experiment 01 - Environment Setup
            • Experiment 02 - Create & Build a Workspace Package
            • Experiment 03 - Run ROS2 Topic Communication Node
            • Experiment 04 - ROS2 Camera Application
          • 40-pin IO Development

            • Experiment 01 - GPIO Output (LED Blink)
            • Experiment 02 - GPIO Input
            • Experiment 03 - Button-controlled LED
            • Experiment 04 - PWM Output
            • Experiment 05 - Serial Output
            • Experiment 06 - I2C Experiment
            • Experiment 07 - SPI Experiment
          • USB Module Usage

            • Experiment 01 - USB Voice Module Usage
            • Experiment 02 - Sound Source Localization Module
          • Machine Vision Practice

            • Experiment 01 - Open USB Camera
            • Experiment 02 - Image Processing Basics
            • Experiment 03 - Object Detection
            • Experiment 04 - Image Segmentation
      • RK1828

        • Introduction

          • M5-182X-A1 AI Edge Box - Product Introduction
          • M5-182X-A1 Hardware Specifications
          • M5-182X-A1 Usage & Safety
        • Quick Start

          • M5-182X-A1 Image Flashing
          • RK182X Hardware Installation & Verification
          • RK182X Development Environment Quick Setup
          • RK182X SDK Overview
          • RK182X Environment Setup in Detail
          • RK182X Quick Start
          • Vendor SDK Data Extraction Record
        • Development Guide

          • ClawChips Architecture and Principles
          • SKILL User Manual
          • RK182X Series LLM Inference (RK1828 Model)
          • RK182X Series CNN Inference (RK1828 Model)
          • Model Conversion
          • RK182X AI Agent Application Development Guide
          • RK182X Industrial Anomaly Detection Application
        • SDK Reference

          • RKNN3-SDK Overview

            • RKNN3 SDK Overview
          • RKNN3-Toolkit

            • RKNN3 Toolkit Installation and Usage
          • RKLLM

            • RKLLM On-Device LLM Inference
          • RK182X Series NPU Overview and Architecture (RK1828 Model)
          • RK182X INT8 Quantized Inference Deployment
          • RK182X MPP Multimedia Framework
          • MPP Details

            • RK182X Video Decoding
            • RK182X Video Encoding
          • NPU Details

            • RKNN Model Conversion
            • RK182X NPU INT8 Quantized Inference
            • RK182X Multi-Model Parallel Inference
          • RGA Details

            • RK182X RGA 2D Graphics Acceleration
          • VPU Details

            • RK182X VPU Codec
        • Hardware Reference

          • RK182X Series Hardware Architecture Overview (RK1828 Model)
          • RK182X Pin Definitions and Multiplexing Configuration
          • RK182X Pin Definitions
          • RK182X Power Management
          • RK182X Clock and PLL Configuration
          • RK182X Clock and Frequency Configuration
        • Tutorials

          • Hello World
          • Hello RK1828 - The First Program
          • RTSP Streaming
          • RTSP Streaming + AI Analysis
          • ShiMetaPi AI Lobster One-Click Deployment
          • PaddleOCR-VL Text Recognition
          • Qwen3-1.7B LLM Text Chat
          • AI Multi-View Inspection (Qwen3-VL Wrapper)
          • YOLOv5 Object Detection
        • Downloads

          • Downloads
        • FAQ

          • FAQ
    • Core-Board

      • C-3568BQ

        • Introduction

          • C-3568BQ Overview
      • C-3588LQ

        • Introduction

          • C-3588LQ Overview
      • GC-3568JBAF

        • Introduction

          • GC-3568JBAF Overview
      • C-K1BA

        • Introduction

          • C-K1BA Overview
    • Software Platform

      • ShiMetaPi Workbench

        • Introduction

          • Product Overview
          • Core Architecture
          • Feature Entries
          • Supported Hardware
          • Release Notes
        • Quick Start

          • Install & Login
          • Connect the Device
          • Set Up the Environment
          • Connect to AIHub
          • First Inference
        • User Guide

          • Workspace Overview
          • Device Manager
          • Model Market
          • One-Click Deploy
          • Vision — SVP
          • Vision - Custom Models
          • shimeta-py IDE
          • Terminal
          • Agent Debug Assistant
          • Settings and Resources
        • FAQ

          • Installation & Login
          • Device Connection
          • Models & Deployment
          • Vision & Runtime
          • Settings & Other
      • ShimetaPi Repository

        • Introduction

          • ShimetaPi Software Repository
        • Pico G1 (GK7206)

          • Quick Start

            • Installation & First Inference
            • shimeta_infer — Image Inference
            • shimeta_camera — Real-time Camera Inference
            • SVP Scene Detection
            • File Transfer & Built-in Model Reference
            • FAQ
          • HTTP API & Python SDK

            • HTTP API Reference
      • Model Fine-tuning Platform

        • Introduction

          • Model Training Platform
        • Quick Start

          • Register & Login
          • Create Your First Model (30-Minute Quick Experience)
        • Training Guide

          • Data Preparation & Annotation
          • Training Parameter Configuration
          • Start & Monitor Training
          • Model Evaluation & Testing
        • Model Deployment

          • Export Model
          • Deploy to Edge Device

RGA 2D Graphics Acceleration

This chapter explains how to use the RK182X RGA (Raster Graphic Acceleration) hardware 2D engine.

Overall block diagram

Camera (V4L2)
       │ dma_fd
       ↓
RGA format conversion (NV12 → RGB)
       │ same fd or a new fd
       ↓
NPU inference (RKNN)
       │ results
       ↓
RGA composition (overlay bounding boxes)
       ↓
Encoder (MPP) / display

RGA is a hardware 2D graphics engine built into the Host SoC (e.g. RK3588). The RK182X coprocessor itself has no RGA; it works through the Host SoC's RGA over PCIe and can efficiently perform image format conversion, scaling, rotation, cropping, composition, and other operations.

1. RGA Capabilities

The RGA hardware 2D engine supports six operations: format conversion, scaling, rotation, cropping, multi-layer composition, and solid / gradient fill.

OperationDescriptionTypical use
Format conversionNV12↔RGB / YUV↔RGB / arbitrary conversionsCamera→NPU input preprocessing
ScalingArbitrary-ratio scaling (1/8x ~ 8x)Resolution adaptation, thumbnails
Rotation0° / 90° / 180° / 270° / mirroringPortrait camera correction
CroppingArbitrary rectangular region extractionROI extraction
CompositionMulti-layer alpha-blended overlayOSD watermarks, picture-in-picture
FillSolid / gradient fillBackground fill

2. RGA Initialization

Call c_RkRgaInit() to initialize the RGA device; returns 0 on success, <0 on failure (check whether /dev/rga* exists).

Verified: /dev/rga exists (the Host SoC RK3588 has a built-in RGA), so the RGA device is available.

#include <rga/RgaApi.h>
#include <stdio.h>

int ret = c_RkRgaInit();
if (ret < 0) {
    printf("RGA init failed: %d\n", ret);
    return -1;
}
printf("RGA initialized.\n");

3. NV12 → RGB888 Format Conversion

Fill rga_info_t src (fd + NV12 format + rect) and rga_info_t dst (fd + RGB888 format + rect), then call c_RkRgaBlit(&src, &dst, NULL) to perform the conversion.

#include <rga/RgaApi.h>
#include <rga/drmrga.h>   /* rga_info_t / rga_rect_t */
#include <rga/rga.h>      /* RK_FORMAT_* */
#include <stdio.h>
#include <string.h>

int main(void) {
    // source image (NV12)
    rga_info_t src = {0};
    src.fd = -1;                       // replace with the real dma fd by the caller
    src.mmuFlag = 1;
    src.rect.xoffset = 0;
    src.rect.yoffset = 0;
    src.rect.width   = 1920;
    src.rect.height  = 1080;
    src.rect.wstride = 1920;
    src.rect.hstride = 1080;
    src.format = RK_FORMAT_YCbCr_420_SP;
    src.rect.format = RK_FORMAT_YCbCr_420_SP;   // older drivers read this one

    // destination image (RGB888)
    rga_info_t dst = {0};
    dst.fd = -1;
    dst.mmuFlag = 1;
    dst.rect.xoffset = 0;
    dst.rect.yoffset = 0;
    dst.rect.width   = 1920;
    dst.rect.height  = 1080;
    dst.rect.wstride = 1920;
    dst.rect.hstride = 1080;
    dst.format = RK_FORMAT_RGB_888;
    dst.rect.format = RK_FORMAT_RGB_888;

    int ret = c_RkRgaBlit(&src, &dst, NULL);
    if (ret < 0) printf("RGA blit failed: %d\n", ret);
    else printf("NV12 -> RGB888 done.\n");
    return 0;
}

3.1 Key API Points

ItemDescription
rga_rect_t fieldsxoffset / yoffset (not x / y)
rga_info_t.formatSet both the top-level format and rect.format (older drivers only read rect.format)
Conversion functionc_RkRgaBlit() or the RgaBlit() macro (there is no rga_blit())

4. Scaling and Rotation

IM2D API path (recommended): im2d_single.h:147 imrotate(), im2d_single.h:519 imrotate_t().

#include <rga/im2d.h>
#include <rga/im2d_single.h>
#include <rga/im2d_type.h>

rga_info_t src = {0};       /* same NV12 1920x1080 as above */
rga_info_t dst = {0};       /* 640x480 RGB */

int ret = c_RkRgaBlit(&src, &dst, NULL);
if (ret < 0) return ret;

/* rotation constants from im2d_single.h:136-139 */
ret = imrotate(src, dst, IM_HAL_TRANSFORM_ROT_90);

5. Multi-Layer Composition (OSD Watermark Overlay)

Multi-layer composition goes through the IM2D API, using rga_image_t (im2d_type.h:336, which has the global_alpha field; rga_info_t does not).

#include <rga/im2d.h>
#include <rga/im2d_type.h>

rga_image_t layer0 = {0};
layer0.buffer.fd = video_fd;
layer0.width  = 1920;
layer0.height = 1080;
layer0.format = RK_FORMAT_YCbCr_420_SP;
layer0.global_alpha = 0xff;     // global alpha

rga_image_t layer1 = {0};
layer1.buffer.fd = logo_fd;
layer1.width  = 280;
layer1.height = 80;
layer1.format = RK_FORMAT_RGBA_8888;
layer1.global_alpha = 200;      // semi-transparent

rga_image_t dst_img = {0};
dst_img.buffer.fd = dst_fd;
dst_img.width  = 1920;
dst_img.height = 1080;
dst_img.format = RK_FORMAT_YCbCr_420_SP;

int ret = imcomposite(dst_img, layer0, layer1);
if (ret != IM_STATUS_SUCCESS) printf("composite failed\n");

6. RGA API Verification

RGA C API function declarations:

grep -n "c_RkRgaInit\|c_RkRgaBlit" /usr/include/rga/RgaApi.h /usr/include/rga/drmrga.h

Output:

/usr/include/rga/RgaApi.h:49:    ret = c_RkRgaInit(); \
/usr/include/rga/RgaApi.h:57:#define RgaBlit(...) c_RkRgaBlit(__VA_ARGS__)
/usr/include/rga/RgaApi.h:61:int  c_RkRgaInit();
/usr/include/rga/RgaApi.h:64:int  c_RkRgaBlit(rga_info_t *src, rga_info_t *dst, rga_info_t *src1);

Full macros and function declarations in RgaApi.h:

sed -n '40,65p' /usr/include/rga/RgaApi.h

Output:

/*
 * Compatible with the old version of C interface.The new
 * version of the C interface no longer requires users to
 * initialize rga, so RgaInit and RgaDeInit are just for
 * compatibility with the old C interface, so please do
 * not use ctx, because it is usually a NULL.
 */
#define RgaInit(ctx) ({ \
    int ret = 0; \
    ret = c_RkRgaInit(); \
    c_RkRgaGetContext(ctx); \
    ret;\
})
#define RgaDeInit(ctx) { \
    (void)ctx;        /* unused */ \
    c_RkRgaDeInit(); \
}
#define RgaBlit(...) c_RkRgaBlit(__VA_ARGS__)
#define RgaCollorFill(...) c_RkRgaColorFill(__VA_ARGS__)
#define RgaFlush() c_RkRgaFlush()

int  c_RkRgaInit();
void c_RkRgaDeInit();
void c_RkRgaGetContext(void **ctx);
int  c_RkRgaBlit(rga_info_t *src, rga_info_t *dst, rga_info_t *src1);
int  c_RkRgaColorFill(rga_info_t *dst);

RGA C interface verification:

  • c_RkRgaInit() returns int (RgaApi.h:61)
  • c_RkRgaBlit() takes 3 arguments: rga_info_t *src, *dst, *src1 (RgaApi.h:64)
  • RgaBlit() is a macro wrapping c_RkRgaBlit()

The rga_rect_t struct definition:

sed -n '114,125p' /usr/include/rga/drmrga.h

Output:

typedef struct rga_rect {
    int xoffset;
    int yoffset;
    int width;
    int height;
    int wstride;
    int hstride;
    int format;
    int size;
} rga_rect_t;

rga_rect_t fields confirmed: xoffset / yoffset / width / height / wstride / hstride / format / size

The rga_info_t struct definition (partial):

sed -n '266,280p' /usr/include/rga/drmrga.h

Output:

typedef struct rga_info {
    int fd;
    void *virAddr;
    void *phyAddr;
#ifndef ANDROID /* LINUX */
    unsigned hnd;
#else /* Android */
    buffer_handle_t hnd;
#endif
    int format;
    rga_rect_t rect;
    unsigned int blend;

The imrotate / imrotate_t function declarations:

grep -n "imrotate\|IM_HAL_TRANSFORM_ROT_" /usr/include/rga/im2d_single.h | head -10

Output:

137: *      IM_HAL_TRANSFORM_ROT_90
138: *      IM_HAL_TRANSFORM_ROT_180
139: *      IM_HAL_TRANSFORM_ROT_270
147:IM_API IM_STATUS imrotate(const rga_buffer_t src, rga_buffer_t dst, int rotation, int sync = 1, int *release_fence_fd = NULL);
519:IM_C_API IM_STATUS imrotate_t(const rga_buffer_t src, rga_buffer_t dst, int rotation, int sync);

Actual rotation constant definitions:

sed -n '46,55p' /usr/include/rga/im2d_type.h

Output:

typedef enum {
    /* Rotation */
    IM_HAL_TRANSFORM_ROT_90     = 1 << 0,
    IM_HAL_TRANSFORM_ROT_180    = 1 << 1,
    IM_HAL_TRANSFORM_ROT_270    = 1 << 2,
    IM_HAL_TRANSFORM_FLIP_H     = 1 << 3,
    IM_HAL_TRANSFORM_FLIP_V     = 1 << 4,
    IM_HAL_TRANSFORM_FLIP_H_V   = 1 << 5,

Rotation constant verification (im2d_type.h:50-52):

  • IM_HAL_TRANSFORM_ROT_90 = 1<<0
  • IM_HAL_TRANSFORM_ROT_180 = 1<<1
  • IM_HAL_TRANSFORM_ROT_270 = 1<<2

IM2D composition-related structures:

grep -n "rga_image_t\|global_alpha\|imcomposite" /usr/include/rga/im2d_type.h | head -10

Output:

336:        int global_alpha;               /* global_alpha, the default should be 0xff */

Full definition of the rga_buffer_t struct:

sed -n '323,351p' /usr/include/rga/im2d_type.h

Output:

typedef struct {
    void* vir_addr;                     /* virtual address */
    void* phy_addr;                     /* physical address */
    int fd;                             /* shared fd */

    int width;                          /* width */
    int height;                         /* height */
    int wstride;                        /* wstride */
    int hstride;                        /* hstride */
    int format;                         /* format */

    int color_space_mode;               /* color_space_mode */
    union {
        int global_alpha;               /* global_alpha, the default should be 0xff */
        struct {
            uint16_t alpha0;
            uint16_t alpha1;
        } alpha_bit;                    /* alpha bit(e.g. RGBA5551), 0: alpha0, 1: alpha1 */
    };
    int rd_mode;

    /* legacy */
    int color;                          /* color, used by color fill */
    im_colorkey_range colorkey_range;   /* range value of color key */
    im_nn_t nn;
    int rop_code;

    rga_buffer_handle_t handle;         /* buffer handle */
} rga_buffer_t;

The imcomposite function signature:

grep -n "imcomposite" /usr/include/rga/im2d_single.h | head -3

Output:

212:IM_API IM_STATUS imcomposite(const rga_buffer_t srcA, const rga_buffer_t srcB, rga_buffer_t dst, int mode = IM_ALPHA_BLEND_SRC_OVER, int sync = 1, int *release_fence_fd = NULL);
imcomposite(srcA, srcB, dst, mode=IM_ALPHA_BLEND_SRC_OVER, sync=1, release_fence_fd=NULL)

You must use the rga_buffer_t type, not rga_image_t.

RK_FORMAT pixel format macros:

grep -n "RK_FORMAT_RGBA_8888 \|RK_FORMAT_RGB_888 \|RK_FORMAT_BGR_888 \|RK_FORMAT_YCbCr_422_SP \|RK_FORMAT_YCbCr_422_P \|RK_FORMAT_YCbCr_420_SP \|RK_FORMAT_ARGB_8888 " /usr/include/rga/rga.h

Output:

30:    RK_FORMAT_RGBA_8888    = 0x0 << 8,  /* [0:31] R:G:B:A 8:8:8:8 little endian */
32:    RK_FORMAT_RGB_888      = 0x2 << 8,  /* [0:23] R:G:B 8:8:8 little endian */
37:    RK_FORMAT_BGR_888      = 0x7 << 8,  /* [0:23] B:G:R 8:8:8 little endian */
39:    RK_FORMAT_YCbCr_422_SP = 0x8 << 8,  /* 2 plane YCbCr little endian
42:    RK_FORMAT_YCbCr_422_P  = 0x9 << 8,  /* 3 plane YCbCr little endian
46:    RK_FORMAT_YCbCr_420_SP = 0xa << 8,  /* 2 plane YCbCr little endian
120:    RK_FORMAT_ARGB_8888    = 0x28 << 8, /* [0:31] A:R:G:B 8:8:8:8 little endian */

7. Which Pixel Formats Does RGA Support?

FormatMacroNotes
NV12RK_FORMAT_YCbCr_420_SPYUV420 semi-planar
NV16RK_FORMAT_YCbCr_422_SPYUV422 semi-planar
RGB888RK_FORMAT_RGB_888—
RGBA8888RK_FORMAT_RGBA_8888—
BGR888RK_FORMAT_BGR_888—
YUV422PRK_FORMAT_YCbCr_422_PYUV422 planar
ARGB8888RK_FORMAT_ARGB_8888—

8. RGA Zero-Copy Data Flow

The camera / V4L2, RKNN, and MPP each obtain an fd via IOCTL_VIDIOC_xxx / rknn3_* / mpp_buffer_get_fd(); these fds can be reused directly in RGA's src.fd / dst.fd with zero memcpy throughout.

Camera (V4L2)
       │ dma_fd
       ↓
RGA format conversion (NV12 → RGB)
       │ same fd or a new fd
       ↓
NPU inference (RKNN)
       │ results
       ↓
RGA composition (overlay bounding boxes)
       ↓
Encoder (MPP) / display

9. FAQ

SymptomCauseFix
RGA init failed: -1/dev/rga* missingInstall librga / load the rga kernel module
RGA blit failedInvalid fd / format mismatchCheck the fd and format fields
xoffset/yoffset has no effectWritten as x/yUse xoffset/yoffset instead
rect.format not readOlder driverSet both info.format and rect.format
imrotate compile error about rga_image_tWrong type usedChange to rga_buffer_t
Rotation direction reversedWrong constantIM_HAL_TRANSFORM_ROT_90/180/270

10. Next Steps

  • MPP Multimedia Framework — the multimedia framework
  • VPU Codec — video encoding/decoding
  • NPU Overview — combining AI inference with multimedia
Edit this page on GitHub