5.14. 2D Graphics Processing - 2D GPU

5.14.1. Module Description

The 2D GPU supports the following functions (for 2D image processing):

  • Bit Block Transfer (BitBlt)

  • Stretch Blit

  • Rectangle Fill and Clear

  • One-Pass Filter Blit

  • Alpha Blending

  • Supports 90°, 180°, 270° rotation in clockwise or counterclockwise direction

  • Supports mirroring flip

  • Supports ROP (Raster Operation Code)

  • Supports clipping

  • Supports color space conversion, i.e., YUV to RGB and RGB to YUV (Color Space Convert)

  • Multi-source composition

Note: When using GPU2D for data conversion between YUV formats, inaccuracies may occur:

  1. Format conversion between YUV and RGB inherently involves precision loss.

  2. Due to hardware implementation, when performing YUV format conversion (e.g., YUYV to NV12), the hardware first converts YUYV to RGB, then converts RGB to NV12.

5.14.1.1. Basic Specifications

  • Maximum resolution: 4K

  • Processing performance: 4K@90fps

Note: 4K refers to 3840 × 2160

5.14.1.2. Supported Formats

Format Input Output
A8 Y Y
R8 Y Y
A1R5G5B5 Y Y
A4R4G4B4 Y Y
X1R5G5B5 Y Y
X4R4G4B4 Y Y
R5G6B5 Y Y
RG16 Y Y
X8R8G8B8 Y Y
A8R8G8B8 Y Y
A2R10G10B10 Y Y
YUY2 (packed YUV422) Y Y
UYVY (packed YUV422) Y Y
YV12 (planar YUV420) Y Y
I010(10bit planar YUV420) Y Y
NV12 (semi-planar YUV420) Y Y
NV16 (semi-planar YUV422) Y Y
P010(semi-planar YUV420) Y Y
NV12-10bit (semi-planar YUV420) Y Y
NV16-10bit (semi-planar YUV422) Y N
Planar RGB888/YUV444(8bit) Y Y
  • Y: Indicates supported

  • N: Indicates not supported

5.14.1.3. Alignment Requirements

Explanations of some table headers are as follows (with detailed descriptions below):

  • Number of Planes: Defines how many parts the image data is divided into.

  • Bits Per Pixel Per Plane: Defines the number of bits used per pixel in each plane.

  • Horizontal Pixel Width / Vertical Pixel Height: Defines the layout of pixels in each plane in the horizontal and vertical directions.

  • Row Alignment Within Plane: Defines memory alignment for each row of data.

  • Address Alignment Per Plane: Defines memory alignment for the starting address of each plane.

Format Name BPP Number of Planes Bits Per Pixel Per Plane Horizontal Pixel Width Vertical Pixel Height Row Alignment (Bytes) Address Alignment (Bytes)
A8 8 1 8, 0, 0 1 1 1, 0, 0 1, 0, 0
A1R5G5B5 16 1 16, 0, 0 1 1 2, 0, 0 2, 0, 0
A4R4G4B4 16 1 16, 0, 0 1 1 2, 0, 0 2, 0, 0
X1R5G5B5 16 1 16, 0, 0 1 1 2, 0, 0 2, 0, 0
X4R4G4B4 16 1 16, 0, 0 1 1 2, 0, 0 2, 0, 0
R5G6B5 16 1 16, 0, 0 1 1 2, 0, 0 2, 0, 0
RG16 16 1 16, 0, 0 1 1 2, 0, 0 2, 0, 0
X8R8G8B8 32 1 32, 0, 0 1 1 4, 0, 0 4, 0, 0
A8R8G8B8 32 1 32, 0, 0 1 1 4, 0, 0 4, 0, 0
A2R10G10B10 32 1 32, 0, 0 1 1 4, 0, 0 4, 0, 0
YUYV 16 1 16, 0, 0 2 1 4, 0, 0 4, 0, 0
UYVY 16 1 16, 0, 0 2 1 4, 0, 0 4, 0, 0
YV12 24 3 8, 8, 8 2 2 64, 32, 32 64, 64, 64
I010 48 3 16, 16, 16 2 2 128, 64, 64 128, 64, 64
NV12 16 2 8, 8, 0 2 2 64, 64, 0 64, 64, 0
NV16 16 2 8, 8, 0 2 1 64, 64, 0 64, 64, 0
P010 32 2 16, 16, 0 2 2 128, 128, 0 128, 128, 0
NV12_10BIT 24 2 16, 8, 0 4 2 80, 80, 0 80, 80, 0
NV16_10BIT 32 2 16, 16, 0 2 1 40, 40, 0 80, 80, 0
Planar RGB888 24 3 8, 8, 8 1 1 4, 4, 4 4, 4, 4

Detailed explanations of table headers are as follows:

Number of Planes

  • Definition: Indicates the number of independent parts into which image data is divided in memory.

  • Explanation:

    • Image data can be stored in one or more planes. A plane refers to an independent portion of image data used to store specific color components or luminance/chrominance information.

    • Single-plane formats: All image data is stored in one plane, typically used for RGB formats, such as A8R8G8B8, RGB888.

    • Multi-plane formats: Image data is divided and stored across multiple planes, typically used for YUV formats like YV12, NV12, etc.

      • Dual-plane: For example, in NV12, the Y component is stored in one plane, and the UV components are stored in another.

      • Triple-plane: For example, in YV12, the Y, U, and V components are stored in three separate planes.

Bits Per Pixel Per Plane (BPP)

  • Definition: Indicates the number of bits used per pixel in each plane.

  • Explanation:

    • For single-plane formats, such as A8R8G8B8, each pixel uses 32 bits, so the bits per pixel per plane is 32.

    • For multi-plane formats, such as YV12, the Y plane uses 8 bits, and the U and V planes also use 8 bits each.

    • The number of bits per plane can vary; for example, in NV12, the Y plane uses 8 bits, while the UV plane uses 8 bits (together forming 16 bits).

Horizontal Pixel Width (aWidthPixel)

  • Definition: Indicates the number of pixels in each plane in the horizontal direction.

  • Explanation:

    • Usually 1, meaning each pixel is stored independently.

    • In certain YUV formats, the chroma component’s pixel width may be half that of the luma component; for example, in YUV 4:2:0 format, the width of the U and V planes is only half that of the Y plane.

Vertical Pixel Height (aHeightPixel)

  • Definition: Indicates the number of pixels in each plane in the vertical direction.

  • Explanation:

    • Similar to horizontal pixel width, usually 1.

    • However, in some YUV formats (e.g., YUV 4:2:0), the height of the chroma components is half that of the luma component, which helps reduce storage space.

Row Alignment Within Plane (aStrideByte)

  • Definition: Refers to ensuring alignment in bytes for each row of image data stored in memory.

  • Explanation:

    • The purpose is to improve access efficiency by reducing memory access discontinuity when the CPU or GPU reads data.

    • For example, in the NV12 format, both the Y and UV planes have a byte alignment of 64 bytes, meaning each row’s data length is padded to a multiple of 64 bytes.

Address Alignment Per Plane (aAddressByte)

  • Definition: Refers to the byte alignment required for the starting address of each plane in memory.

  • Explanation:

    • Ensures that the starting address of each image plane is a multiple of a specific byte boundary (e.g., 16-byte, 32-byte, or 64-byte), thus improving memory access efficiency.

    • For example, in the NV12 format, the Y and UV planes typically require 64-byte address alignment, which helps reduce memory access time.

5.14.2. Reference Examples

  • Example code for GPU 2D can be found in the sample_gpu_2d section.

5.14.3. API Reference

API Interface Functionality
n2d_open Open the GPU2D module; can only be opened once per process
n2d_close Close the GPU2D module
n2d_commit Submit the command buffer for execution to GPU hardware
n2d_commit_ex Submit the command buffer for execution to GPU hardware
n2d_allocate Allocate a memory block for storing GPU operation context and resources
n2d_free Free memory allocated by n2d_allocate
n2d_map Map user-space allocated memory address for GPU usage
n2d_unmap Release memory previously mapped by n2d_map and unmap the relationship
n2d_is_feature_support Query whether hardware supports a given feature
n2d_blit Perform Bit Block Transfer operation
n2d_filterblit Perform Bit Block Transfer with FIR resampling filter for high-quality image scaling
n2d_multisource_blit Perform multi-source Bit Block Transfer
n2d_fill Fill or clear a specified buffer with a given color
n2d_set Set configuration

5.14.4. API Interface Descriptions

5.14.4.1. n2d_open

【Function Declaration】

n2d_error_t n2d_open(n2d_void)

【Function Description】

  • To use N2D functionality, n2d_open must be called first to obtain GPU context and resources. Only one GPU context is allowed per process.

  • If this is the first initialization on the N2D hardware, the GPU will be powered on and enabled.

  • In multi-process usage, subsequent calls to n2d_open will destroy resources obtained by previous processes.

【Parameter Description】

  • None

【Return Value】

5.14.4.2. n2d_close

【Function Declaration】

n2d_error_t n2d_close(n2d_void)

【Function Description】

  • This function closes the context opened by n2d_open, destroys all resources, and releases all memory.

  • If this function releases the last resource on the GPU hardware, the GPU hardware will be powered off.

【Parameter Description】

  • None

【Return Value】

5.14.4.3. n2d_commit

【Function Declaration】

 n2d_error_t n2d_commit(n2d_void)

【Function Description】

  • Submit the command buffer for execution to the GPU hardware.

  • This function will block until the GPU hardware completes processing before returning.

【Parameter Description】

  • None

【Return Value】

5.14.4.4. n2d_commit_ex

【Function Declaration】

n2d_error_t n2d_commit_ex(n2d_bool_t stall)

【Function Description】

  • Submit the command buffer for execution to the GPU hardware.

【Parameter Description】

  • [IN] stall

    • When stall is N2D_TRUE, the function will block until the GPU hardware completes processing before returning.

    • When stall is N2D_FALSE, the function will return immediately.

【Return Value】

5.14.4.5. n2d_allocate

【Function Declaration】

n2d_error_t n2d_allocate (n2d_buffer_t *buffer)

【Function Description】

  • This function allocates a memory block for storing context and resources during GPU operations.

  • Parameters such as width, height, and format must be pre-configured in the structure pointed to by buffer.

  • This function must be used in pair with n2d_free.

【Parameter Description】

  • [IN] buffer

    • Pointer to the n2d_buffer_t structure, which should be pre-configured with width, height, and format.

【Return Value】

5.14.4.6. n2d_free

【Function Declaration】

n2d_error_t n2d_free (n2d_buffer_t *buffer)

【Function Description】

  • This function releases the memory resource previously allocated by n2d_allocate.

  • This function must be used in pair with n2d_allocate.

【Parameter Description】

  • [IN] buffer

    • Pointer to the n2d_buffer_t structure, which must have been allocated via n2d_allocate.

【Return Value】

5.14.4.7. n2d_map

【Function Declaration】

n2d_error_t n2d_map (n2d_buffer_t *buffer)

【Function Description】

  • This function maps user-space allocated memory address for GPU usage.

  • Memory must be contiguous.

  • Must be used in pair with n2d_unmap.

【Parameter Description】

  • [IN] buffer

    • Pointer to the n2d_buffer_t structure, with width, height, and format pre-configured.

    • If the memory address is virtual, assign the memory field to the virtual address and set the gpu field to 0.

    • If the memory address is physical, assign the gpu field to the physical address and set the memory field to 0.

【Return Value】

5.14.4.8. n2d_unmap

【Function Declaration】

n2d_error_t n2d_unmap (n2d_buffer_t *buffer)

【Function Description】

  • This function releases memory previously mapped by n2d_map and removes the mapping relationship.

  • Must be used in pair with n2d_map.

【Parameter Description】

  • [IN] buffer

    • Pointer to the n2d_buffer_t structure, which must have been used by n2d_map.

【Return Value】

5.14.4.9. n2d_is_feature_support

【Function Declaration】

n2d_bool_t n2d_is_feature_support (n2d_feature_t feature)

【Function Description】

  • This function queries whether the hardware supports the specified feature.

【Parameter Description】

  • [IN] feature

    • Pointer to the n2d_feature_t enumeration type; see n2d_feature_t description for details.

【Return Value】

  • Success: Supported

  • Failure: Otherwise, not supported

5.14.4.10. n2d_blit

【Function Declaration】

n2d_error_t n2d_blit(n2d_buffer_t *dst_buf, n2d_rectangle_t *dst_rect, n2d_buffer_t *src_buf, n2d_rectangle_t *src_rect, n2d_blend_t mode)

【Function Description】

  • This is a blit function. The blit operation uses source and destination buffers, both defined by the n2d_buffer_t structure.

  • [IN] blit copies a specified region from the source image to a specified region in the destination buffer, supporting blending, rotation, and format conversion. If the region sizes differ, automatic scaling will be performed.

  • This function waits for hardware completion; it is synchronous. Only one blit function can be active at a time. The driver does not support multiple contexts, so the current blit must complete before another can be initiated.

  • [IN] The blit function can be used with or without blending.

  • [IN] The blit function can perform color conversion by specifying appropriate formats for source and destination buffers.

  • When the source or destination buffer format is N2D_YUYV, N2D_UYVY, N2D_YV12, N2D_I420, N2D_NV12, N2D_NV21, N2D_NV16, or N2D_NV61, the source and destination rectangle sizes must be equal; otherwise, N2D_INVALID_ARGUMENT will be returned, and ROP or alpha blending will be ignored.

【Parameter Description】

  • [IN] dst_buf

    • Pointer to the destination buffer’s n2d_buffer_t structure. Valid destination formats for the blit function include most color formats in the n2d_buffer_format_t enum.

    • If the source buffer format is N2D_YUYV, N2D_UYVY, N2D_YV12, N2D_I420, N2D_NV12, N2D_NV21, N2D_NV16, or N2D_NV61, the source and destination rectangle sizes must be equal; otherwise, n2d_blit returns N2D_INVALID_ARGUMENT.

  • [IN] src_buf

    • Pointer to the n2d_buffer_t structure describing the blit source. Valid source formats include all color formats in the n2d_buffer_format_t enum.

  • [IN] dst_rect

    • Optional parameter; pointer to a n2d_rectangle_t structure defining the region in the destination buffer. If not specified, the entire destination buffer is used.

  • [IN] src_rect

    • Optional parameter; pointer to a n2d_rectangle_t structure defining the region in the source buffer. If not specified, the entire source buffer is used. If the source buffer format is N2D_YUYV or N2D_UYVY, the source and destination rectangle sizes must be equal; otherwise, n2d_blit returns N2D_INVALID_ARGUMENT.

  • [IN] mode

    • Specifies one of the hardware-supported blending modes applied to each pixel. Set to N2D_BLEND_NONE (0) if no blending is needed. See n2d_blend_t enum.

【Return Value】

5.14.4.11. n2d_filterblit

【Function Declaration】

n2d_error_t n2d_filterblit(n2d_buffer_t *dst_buf, n2d_rectangle_t *dst_rect, n2d_rectangle_t *dst_subrect, n2d_buffer_t *src_buf, n2d_rectangle_t *src_rect, n2d_blend_t mode)

【Function Description】

  • [IN] n2d_filterblit uses FIR resampling filters for high-quality image scaling.

  • If the source region and destination region are the same size, n2d_filterblit acts as a bit block transfer (bitblit). Supports blending and rotation.

  • This function waits for hardware completion; it is synchronous. Only one n2d_filterblit function can be active at a time. The driver does not support multiple contexts, so the current n2d_filterblit must complete before another can be initiated.

  • [IN] The n2d_filterblit function can be used with or without blending.

【Parameter Description】

  • [IN] dst_buf

    • Pointer to the destination buffer’s n2d_buffer_t structure. Valid destination formats include most color formats in the n2d_buffer_format_t enum.

  • [IN] dst_rect

    • Optional parameter; pointer to a n2d_rectangle_t structure defining the sub-region in the destination buffer. If not specified, the entire destination buffer is used.

  • [IN] dst_subrect

    • Pointer to a n2d_rectangle_t structure providing coordinates of a sub-region within the destination. If dst_subrect is N2D_NULL, the full image is rendered using dst_rect. If dst_subrect is not N2D_NULL and differs from dst_rect, it is assumed to be within dst_rect and only the sub-region is rendered.

  • [IN] src_buf

    • Pointer to the n2d_buffer_t structure describing the n2d_filterblit source. Valid source formats include all color formats in the n2d_buffer_format_t enum.

  • [IN] src_rect

    • Optional parameter; pointer to a n2d_rectangle_t structure defining the sub-region in the source buffer. If not specified, the entire source buffer is used.

  • [IN] mode

    • Specifies one of the hardware-supported blending modes applied to each pixel. Set to N2D_BLEND_NONE (0) if no blending is needed. See n2d_blend_t enum.

【Return Value】

5.14.4.12. n2d_multisource_blit

【Function Declaration】

n2d_error_t n2d_multisource_blit(n2d_buffer_t *dst_buf, n2d_int32_t mask)

【Function Description】

  • This function performs multi-source bit block transfer (multi-blit) using multiple sources.

【Parameter Description】

  • [IN] dst_buf

    • Pointer to the n2d_buffer_t structure defining the destination buffer.

  • [IN] mask

    • Indicates which of the eight possible sources will be used for the multi-source bit block transfer (MultiSrcBlit, i.e., compositing operation). Bit N corresponds to source index N.

【Return Value】

5.14.4.13. n2d_fill

【Function Declaration】

n2d_error_t n2d_fill(n2d_buffer_t *dest, n2d_rectangle_t *rect, n2d_color_t color, n2d_blend_t mode)

【Parameter Description】

  • [IN] dest

    • Pointer to the n2d_buffer_t structure of the destination buffer to be filled.

  • [IN] rect

    • Pointer to a n2d_rectangle_t structure specifying the fill region. If NULL, the entire buffer is filled with the specified color.

  • [IN] color

    • Color value used to fill/clear the buffer. See n2d_color_t.

  • [IN] mode

    • Blending mode applied to each pixel. Set to N2D_BLEND_NONE (0) if no blending is needed. See n2d_blend_t enum.

【Function Description】

  • This function fills or clears the specified buffer (entire buffer or a rectangular region) with a specified color.

  • This function waits for hardware completion; it is synchronous.

【Return Value】

5.14.4.14. n2d_set

【Function Declaration】

n2d_error_t n2d_set(n2d_state_config_t *config)

【Function Description】

  • This function sets configuration parameters.

【Parameter Description】

  • [IN] config

    • Sets attribute states for certain features. See the n2d_state_config_t structure for supported values.

【Return Value】

5.14.5. Data Structures

5.14.5.1. Type Definitions

Name Typedef
n2d_bool_t int
n2d_int8_t char
n2d_int16_t short
n2d_uint16_t unsigned short
n2d_int_t int
n2d_int32_t int
n2d_uint_t unsigned int
n2d_uint32_t unsigned int
n2d_uint64_t unsigned long long
n2d_float_t float
n2d_double_t double
n2d_string char*
n2d_void void
n2d_const_string const char*
n2d_size_t unsigned long long (64-bit OS)
n2d_pointer void*
n2d_color_t uint32_t

5.14.5.2. Enumerations

n2d_error_t

  • Description

    • Nano2D API functions return status codes via n2d_error_. If successful, N2D_SUCCESS is returned. N2D_SUCCESS is defined as zero, so any non-zero return value indicates an error. Possible error values are listed in the table below.

n2d_error_t value String Values Description
0 N2D_SUCCESS Success, no error
1 N2D_INVALID_ARGUMENT Invalid argument specified
2 N2D_OUT_OF_MEMORY Insufficient memory
3 N2D_NO_CONTEXT No open context
4 N2D_TIMEOUT Timeout occurred during wait
5 N2D_OUT_OF_RESOURCES Insufficient system resources
6 N2D_GENERIC_IO Failed to communicate with kernel driver
7 N2D_NOT_SUPPORTED Request not supported
8 N2D_ERROR_HEAP_CORRUPTED MMU table corrupted
9 N2D_NOT_ALIGNED Not aligned
10 N2D_NOT_FOUND Not found
11 N2D_INTERRUPTED Interrupted
12 N2D_MEMORY_LEAK Memory leak

n2d_blend_t

  • Description

    • This enumeration defines the blending modes supported by the HAL. S and D represent source and destination color channels, and Sa and Da represent source and destination alpha channels.

n2d_blend_t value String Values Description
0 N2D_BLEND_NONE S, no blending
1 N2D_BLEND_SRC_OVER S + (1 - Sa) * D
2 N2D_BLEND_DST_OVER (1 – Da) * S + D
3 N2D_BLEND_SRC_IN Da * S
4 N2D_BLEND_DST_IN Sa * D
5 N2D_BLEND_ADDITIVE S + D
6 N2D_BLEND_SUBTRACT D * (1 – S)

n2d_buffer_format_t

  • Description

    • Specifies the pixel color format type used for buffers.

n2d_buffer_format_t value String Values Description
0x100 N2D_RGBA8888 32-bit RGBA format, 8 bits per color channel. Red at bits 7:0, green at 15:8, blue at 23:16, alpha at 31:24.
0x101 N2D_RGBX8888 32-bit RGBX format, 8 bits per color channel. Red at bits 7:0, green at 15:8, blue at 23:16, X at 31:24.
0x200 N2D_R1010B10A2 32-bit RGBA format, 10 bits per color channel, 2 bits for alpha. Red at 9:0, green at 19:10, blue at 29:20, alpha at 31:30.
0x300 N2D_R5G5B5A1 16-bit RGBA format, 5 bits per color channel, 1 bit for alpha. Red at 4:0, green at 9:5, blue at 14:10, alpha at 15:15.
0x301 N2D_R5G5B5X1 16-bit RGBX format, 5 bits per color channel, 1 bit for X. Red at 4:0, green at 9:5, blue at 14:10, X at 15:15.
0x400 N2D_RGBA4444 16-bit RGBA format, 4 bits per color channel. Red at 3:0, green at 7:4, blue at 11:8, alpha at 15:12.
0x401 N2D_RGBX4444 16-bit RGBX format, 4 bits per color channel. Red at 3:0, green at 7:4, blue at 11:8, X at 15:12.
0x402 N2D_RGB565 16-bit RGB format, 5 bits per red/blue, 6 bits for green. Red at 4:0, green at 10:5, blue at 15:11.
0x403 N2D_RGB888 24-bit RGB format, 8 bits per color channel. Red at 7:0, green at 15:8, blue at 23:16.
0x404 N2D_RGB888I 24-bit RGB format, 8 bits per color channel. Red at 7:0, green at 15:8, blue at 23:16.
0x405 N2D_RGB161616I 48-bit RGB format, 16 bits per color channel. Red at 15:0, green at 31:16, blue at 47:32.
0x406 N2D_BGRA8888 32-bit RGBA format, 8 bits per color channel. Red at 23:16, green at 15:8, blue at 7:0, alpha at 31:24.
0x407 N2D_BGRX8888 32-bit RGBX format, 8 bits per color channel. Red at 23:16, green at 15:8, blue at 7:0, X at 31:24.
0x408 N2D_B10G10R10A2 32-bit RGBA format, 10 bits per color channel, 2 bits for alpha. Red at 29:20, green at 19:10, blue at 9:0, alpha at 31:30.
0x409 N2D_BGR565 16-bit RGB format, 5 bits per red/blue, 6 bits for green. Red at 15:11, green at 10:5, blue at 4:0.
0x40A N2D_B5G5R5A1 16-bit RGBA format, 5 bits per color channel, 1 bit for alpha. Red at 14:10, green at 9:5, blue at 4:0, alpha at 15:15.
0x40B N2D_B5G5R5X1 16-bit RGBX format, 5 bits per color channel, 1 bit for X. Red at 14:10, green at 9:5, blue at 4:0, X at 15:15.
0x40C N2D_BGRA4444 16-bit RGBA format, 4 bits per color channel. Red at 11:8, green at 7:4, blue at 3:0, alpha at 15:12.
0x40D N2D_BGRX4444 16-bit RGBX format, 4 bits per color channel. Red at 11:8, green at 7:4, blue at 3:0, X at 15:12.
0x40E N2D_ABGR8888 32-bit RGBA format, 8 bits per color channel. Red at 31:24, green at 23:16, blue at 15:8, alpha at 7:0.
0x40F N2D_XBGR8888 32-bit RGBX format, 8 bits per color channel. Red at 31:24, green at 23:16, blue at 15:8, X at 7:0.
0x410 N2D_A2B10G10R10 32-bit RGBA format, 10 bits per color channel, 2 bits for alpha. Red at 31:22, green at 21:12, blue at 11:2, alpha at 1:0.
0x411 N2D_A1B5G5R5 16-bit RGBA format, 5 bits per color channel, 1 bit for alpha. Red at 15:11, green at 10:6, blue at 5:1, alpha at 0:0.
0x412 N2D_X1B5G5R5 16-bit RGBX format, 5 bits per color channel, 1 bit for X. Red at 15:11, green at 10:6, blue at 5:1, X at 0:0.
0x413 N2D_ABGR4444 16-bit RGBA format, 4 bits per color channel. Red at 15:12, green at 11:8, blue at 7:4, alpha at 3:0.
0x414 N2D_XBGR4444 16-bit RGBX format, 4 bits per color channel. Red at 15:12, green at 11:8, blue at 7:4, X at 3:0.
0x415 N2D_ARGB8888 32-bit RGBA format, 8 bits per color channel. Red at 15:8, green at 23:16, blue at 31:24, alpha at 7:0.
0x416 N2D_XRGB8888 32-bit RGBX format, 8 bits per color channel. Red at 15:8, green at 23:16, blue at 31:24, X at 7:0.
0x417 N2D_A2R10G10B10 32-bit RGBA format, 10 bits per color channel, 2 bits for alpha. Red at 11:2, green at 21:12, blue at 31:22, alpha at 1:0.
0x418 N2D_A1R5G5B5 16-bit RGBA format, 5 bits per color channel, 1 bit for alpha. Red at 5:1, green at 10:6, blue at 15:11, alpha at 0:0.
0x419 N2D_X1R5G5B5 16-bit RGBX format, 5 bits per color channel, 1 bit for X. Red at 5:1, green at 10:6, blue at 15:11, X at 0:0.
0x41A N2D_ARGB4444 16-bit RGBA format, 4 bits per color channel. Red at 7:4, green at 11:8, blue at 15:12, alpha at 3:0.
0x41B N2D_XRGB4444 16-bit RGBX format, 4 bits per color channel. Red at 7:4, green at 11:8, blue at 15:12, X at 3:0.
0x500 N2D_RGB888_PLANAR Planar RGB format, 8 bits per color channel. R/G/B 0 at 7:0, R/G/B 1 at 15:8, R/G/B 2 at 23:16, R/G/B 3 at 31:24.
0x501 N2D_RGB888I_PLANAR Planar RGB format, 8 bits per color channel. R/G/B 0 at 7:0, R/G/B 1 at 15:8, R/G/B 2 at 23:16, R/G/B 3 at 31:24.
0x502 N2D_RGB161616I_PLANAR Planar RGB format, 16 bits per color channel. R/G/B 0 at 15:0, R/G/B 1 at 31:16, R/G/B 2 at 47:32, R/G/B 3 at 63:48.
0x600 N2D_A8 8-bit alpha format. No RGB values.
0x700 N2D_YUYV 32-bit packed YUV format, 32 bits per 2 pixels. Y0 at 7:0, V at 31:24.
0x701 N2D_UYVY 32-bit packed YUV format, 32 bits per 2 pixels. U at 7:0, Y1 at 31:24.
0x702 N2D_AYUV 3-planar YUV format, no alpha. Y/U/V0 at 7:0, Y/U/V1 at 15:8, Y/U/V2 at 23:16, Y/U/V3 at 31:24.
0x703 N2D_YV12 12 bpp planar YUV4:2:0 format, 8 bits per component.
0x704 N2D_I420 Planar YUV format, 8-bit Y plane, followed by 8-bit 2x2 U and V planes.
0x705 N2D_NV12 12 bpp planar YUV 4:2:0 format, 8 bits per component. 16 Y pixels = 16 bytes, 16 UV pixels = 16 bytes.
0x706 N2D_NV21 12 bpp planar YUV 4:2:0 format, same as NV12 but U and V layers are swapped.
0x707 N2D_NV16 16 bpp planar YUV 4:2:2 format, 8 bits per component.
0x708 N2D_NV61 16 bpp planar YUV 4:2:2 format, same as NV16 but U and V planes are swapped.
0x709 N2D_NV12_10BIT 10-bit YUV format, 10 bits per component.
0x70A N2D_NV21_10BIT 10-bit YUV format, 10 bits per component.
0x70B N2D_NV16_10BIT 10-bit YUV format, 10 bits per component.
0x70C N2D_NV61_10BIT 10-bit YUV format, 10 bits per component.
0x70D N2D_P010_MSB P010 (YUV 4:2:0 2-planar, 10 bits per component)

n2d_cache_mode_t

  • Description

    • Specifies the cache mode.

    • Structure used: n2d_buffer_t

    • Constant definition: #define N2D_CACHEMODE_DEFAULT N2D_CACHE_256

n2d_cache_mode_t value String Values Description
0 N2D_CACHE_AUTO
0x1 N2D_CACHE_128
0x2 N2D_CACHE_256
0x3 N2D_CACHE_ALL N2D_CACHE_128 or N2D_CACHE_256

n2d_core_id_t

  • Description

    • Specifies the core ID in a multi-processor design.

    • Function used: n2d_switch_core

n2d_core_id_t value String Values Description
0 N2D_CORE_0
1 N2D_CORE_1
2 N2D_CORE_2
3 N2D_CORE_3

n2d_csc_mode_t

  • Description

    • Specifies the color space conversion mode.

    • Structure used: n2d_csc_config_t

n2d_csc_mode_t value String Values Description
0 N2D_CSC_BT709
0x1 N2D_CSC_BT601
0x2 N2D_CSC_BT2020
0x4 N2D_CSC_USER_DEFINED
0x5 N2D_CSC_USER_DEFINED_CLAMP
0x40000000 N2D_CSC_SET_FULL_RANGE
0x80000000 N2D_CSC_DST

Note: When performing format conversion, if not explicitly set, the default color space is BT709 with limited range.

To change the color space and luma range, execute the following code before format conversion:

    /*CSC SETTING*/
    n2d_state_config_t csc_com = {0};
    csc_com.state = N2D_SET_CSC;
    csc_com.config.csc.cscMode = N2D_CSC_SET_FULL_RANGE | N2D_CSC_BT709; // Set to BT709, full range
    csc_com.config.csc.userCSCMode = N2D_CSC_YUV_TO_RGB;
    n2d_set(&csc_com);
    csc_com.config.csc.userCSCMode = N2D_CSC_RGB_TO_YUV;
    n2d_set(&csc_com);
    /*END*/

This also applies to YUV-to-YUV conversion (e.g., NV12 to YUYV), as the hardware performs such conversions via a YUV->RGB->YUV pipeline.

n2d_feature_t

  • Description

    • Specifies features that may be available and supported in hardware.

    • Function used: n2d_is_feature_support

n2d_feature_t value String Values Description
0 N2D_FEATURE_YUV420_OUTPUT Supports YUV420 output
1 N2D_FEATURE_2D_10BIT_OUTPUT_LINEAR Supports 10-bit linear output
2 N2D_FEATURE_MAJOR_SUPER_TILE
3 N2D_FEATURE_DEC400_COMPRESSION Supports DEC400 compression
4 N2D_FEATURE_ANDROID_ONLY
5 N2D_FEATURE_2D_TILING Supports tiling
6 N2D_FEATURE_2D_MINOR_TILING
7 N2D_FEATURE_DEC_COMPRESSION Supports DEC compression
8 N2D_FEATURE_2D_MULTI_SOURCE_BLT Supports multi-source blit
9 N2D_FEATURE_BGR_PLANAR Supports BGR8888 and AYUV formats
10 N2D_FEATURE_SCALER Supports scaling
11 N2D_FEATURE_2D_ONE_PASS_FILTER Supports single-pass filtering
12 N2D_FEATURE_2D_OPF_YUV_OUTPUT Single-pass filter supports YUV output
13 N2D_FEATURE_SEPARATE_SRC_DST Supports separate source and destination
14 N2D_FEATURE_2D_ALL_QUAD
15 N2D_FEATURE_2D_POST_FLIP
16 N2D_FEATURE_AXI_FE
17 N2D_FEATURE_CSC_PROGRAMMABLE Supports color space conversion
18 N2D_FEATURE_DEC400_FC
19 N2D_FEATURE_TRANSPARENCY_MASK Supports mask-based blit
20 N2D_FEATURE_TRANSPARENCY_COLOR_KEY
21 N2D_FEATURE_NORMALIZATION
22 N2D_FEATURE_NORMALIZATION_QUALTIZATION
23 N2D_FEATURE_HISTOGRAM Supports histogram function
24 N2D_FEATURE_BRIGHTNESS_SATURATION Supports brightness and saturation
25 N2D_FEATURE_64BIT_ADDRESS Supports 64-bit addressing
26 N2D_FEATURE_FEATURE_CONTEXT_ID Supports context ID
27 N2D_FEATURE_FEATURE_SECURE_BUFFER Supports secure memory buffers
28 N2D_FEATURE_MMU_PAGE_DESCRIPTOR Supports kernel MMU page descriptors
29 N2D_FEATURE_SECURITY_AHB
30 N2D_FEATURE_FRAME_DONE_INTERRUPT Supports frame-done interrupt

n2d_orientation_t

  • Description

    • Specifies the orientation of the n2d_buffer_t structure.

    • Structure used: n2d_buffer_t

n2d_orientation_t value String Values Description
0 N2D_0 Buffer is 0 degrees rotated.
1 N2D_90 Buffer is 90 degrees rotated.
2 N2D_180 Buffer is 180 degrees rotated.
3 N2D_270 Buffer is 270 degrees rotated.
4 N2D_FLIP_X Flip in horizontal direction.
5 N2D_FLIP_Y Flip in vertical direction.

n2d_tiling_t

  • Description

    • Specifies the tiling mode of the n2d_buffer_t structure.

    • Structure used: n2d_buffer_t

n2d_tiling_t value String Values Description
0 N2D_INVALID_TILED Invalid tiling
1 N2D_LINEAR No tiling
2 N2D_TILED 4x4 tiling
3 N2D_SUPER_TILED 64x64 tiling
4 N2D_MINOR_TILED 2x2 tiling
5 N2D_TILING_SPLIT_BUFFER 2x2 tiling
6 N2D_TILING_X_MAJOR X Major (Z-ordered) tiling
7 N2D_TILING_Y_MAJOR Y Major tiling
8 N2D_TILING_SWAP
9 N2D_MULTI_TILED N2D_TILED | N2D_TILING_SPLIT_BUFFER
10 N2D_MULTI_SUPER_TILED N2D_SUPER_TILED | N2D_TILING_SPLIT_BUFFER
11 N2D_YMAJOR

n2d_tile_status_config_t

  • Description

    • Specifies the tile status mode of the n2d_buffer_t structure.

    • Structure used: n2d_buffer_t

n2d_tile_status_config_t value String Values Description
0 N2D_TSC_DISABLE No compression
0x00000001 N2D_TSC_DEC_COMPRESSED DEC400 compression

n2d_pixel_color_multiply_mode_t

  • Description

    • Function used: n2d_set_pixel_multiply_mode

n2d_pixel_color_multiply_mode_t value String Values Description
0 N2D_COLOR_MULTIPLY_DISABLE
1 N2D_COLOR_MULTIPLY_ENABLE

n2d_global_color_multiply_mode_t

  • Description

    • Specifies the global mode for alpha blending.

    • Function used: n2d_set_pixel_multiply_mode

n2d_global_color_multiply_mode_t value String Values Description
0 N2D_GLOBAL_COLOR_MULTIPLY_DISABLE
1 N2D_GLOBAL_COLOR_MULTIPLY_ALPHA
2 N2D_GLOBAL_COLOR_MULTIPLY_COLOR

n2d_filter_type_t

  • Description

    • Specifies the filter type.

    • Structure used: n2d_state_config_t

n2d_filter_type_t value String Values Description
0 N2D_FILTER_SYNC
1 N2D_FILTER_BLUR Blur filter
2 N2D_FILTER_USER User specified filter
3 N2D_FILTER_BILINEAR Bilinear
4 N2D_FILTER_BICUBIC Bicubic

n2d_state_value_t

  • Description

    • Used to distinguish specific configuration behaviors.

    • Structure used: n2d_csc_config_t

n2d_state_value_t value String Values Description
0x1 N2D_CSC_YUV_TO_RGB
0x2 N2D_CSC_RGB_TO_YUV

n2d_state_type_t

  • Description

    • Specifies the configuration state to be set.

    • Structure used: n2d_state_config_t

n2d_state_type_t value String Values Description
0 N2D_SET_ALPHABLEND_MODE
1 N2D_SET_BRIGHTNESS Not supported
2 N2D_SET_CLIP_RECTANGLE
3 N2D_SET_CONTEXT_ID Not supported
4 N2D_SET_CSC
5 N2D_SET_DITHER
6 N2D_SET_DST_COLORKEY
7 N2D_SET_FAST_CLEAR Not supported
8 N2D_SET_FILTER_TYPE
9 N2D_SET_GLOBAL_ALPHA
10 N2D_SET_HISTOGRAM_CALC Not supported
11 N2D_SET_HISTOGRAM_EQUAL Not supported
12 N2D_SET_KERNEL_SIZE
13 N2D_SET_MASKPACK Not supported
14 N2D_SET_MULTISOURCE_INDEX
15 N2D_SET_MULTISRC_DST_RECTANGLE
16 N2D_SET_NORMALIZATION Not supported
17 N2D_SET_PIXEL_MULTIPLY_MODE
18 N2D_SET_ROP
19 N2D_SET_SRC_COLORKEY
20 N2D_SET_TRANSPARENCY Not supported

n2d_source_type_t

  • Description

    • Specifies the source type.

n2d_source_type_t value String Values Description
0 N2D_SOURCE_DEFAULT
N2D_SOURCE_MASKED
N2D_SOURCE_MASKED_MONO

5.14.5.3. Structures

n2d_point_t

  • Description

    • This structure describes point data in Nano2D. A point defines a pixel on the screen.

    • Functions used: n2d_line, n2d_maskpack_config_t

  • Member Table

Member Type Description
x n2d_int32_t X coordinate of the point
y n2d_int32_t Y coordinate of the point

n2d_rectangle_t

  • Description

    • This structure defines the organization of a Nano2D rectangular data area.

    • Functions used: n2d_blit, n2d_fill, n2d_line, n2d_set_filter_type, n2d_set_source, n2d_set_clip

  • Member Table

Member Type Description
x n2d_int32_t X coordinate of the rectangle (top-left)
y n2d_int32_t Y coordinate of the rectangle (top)
width n2d_int32_t Width of the rectangle
height n2d_int32_t Height of the rectangle

n2d_csc_config_t

  • Description

    • This structure specifies the color space conversion (CSC) mode.

    • Structure used: n2d_state_config_t

    • Constant definition: #define N2D_CSC_PROGRAMMABLE_SIZE 12

  • Member Table

Member Type Description
cscMode n2d_csc_mode_t Color space conversion mode, see enumeration n2d_csc_mode_t
userCSCMode n2d_state_value_t Direction of user-defined CSC. Valid values: N2D_CSC_YUV_TO_RGB or N2D_CSC_RGB_TO_YUV, used only when cscMode is N2D_CSC_USER_DEFINED or N2D_CSC_USER_DEFINED_CLAMP
cscTable[N2D_CSC_PROGRAMMABLE_SIZE] n2d_int32_t Color conversion table

n2d_dither_info_t

  • Description

    • This structure specifies whether dithering is enabled.

    • Structure used: n2d_state_config_t

  • Member Table

Member Type Description
enable n2d_bool_t 1 = enable dithering

n2d_multisrc_dst_rect_config_t

  • Description

    • This structure describes the configuration of a multi-source destination rectangle.

    • Structure used: n2d_state_config_t

  • Member Table

Member Type Description
*source n2d_buffer_t Pointer to the structure containing the source buffer
srcRect n2d_rectangle_t Structure of the source rectangle
dstRect n2d_rectangle_t Structure of the destination rectangle

n2d_rop_config_t

  • Description

    • This structure defines the ROP configuration for Nano2D data.

    • Structure used: n2d_state_config_t

  • Member Table

Member Type Description
fg_rop n2d_uint32_t Foreground ROP
bg_rop n2d_uint32_t Background ROP

n2d_multiply_mode_config_t

  • Description

    • This structure describes pre-multiply / pre-divide modes for alpha blending.

    • Structure used: n2d_state_config_t

  • Member Table

Member Type Description
srcPremult n2d_pixel_color_multiply_mode_t Enumeration for source pre-multiply
dstPremult n2d_pixel_color_multiply_mode_t Enumeration for destination pre-multiply
srcGlobal n2d_global_color_multiply_mode_t Enumeration for source global multiply
dstDemult n2d_pixel_color_multiply_mode_t Enumeration for destination pre-divide

n2d_kernel_size_config_t

  • Description

    • This structure provides horizontal and vertical kernel sizes.

    • Structure used: n2d_state_config_t

  • Member Table

Member Type Description
horSize n2d_uint8_t Horizontal kernel size
verSize n2d_uint8_t Vertical kernel size

n2d_state_config_t

  • Description

    • This structure provides state configuration data.

    • Function used: n2d_set

  • Member Table

Member Type Description
state n2d_state_type_t Enumeration type for state data
config union Union containing different configuration structures
  • Members of config union

Member Type Description
csc n2d_csc_config_t Structure for color space conversion configuration
ditherInfo n2d_dither_info_t Structure containing dithering information
multisourceIndex n2d_multisource_index_config_t Source index, defined as n2d_uint32_t
clipRect n2d_rectangle_t Structure for clipping rectangle
globalAlpha n2d_global_alpha_config_t Structure for global alpha value
alphablendMode n2d_blend_t Enumeration type for alpha blending mode
multisrcAndDstRect n2d_multisrc_dst_rect_config_t Structure for multi-source and destination rectangles
rop n2d_rop_config_t Structure for foreground and background ROP
pixelMultiplyMode n2d_multiply_mode_config_t Structure for pre-multiply / pre-divide mode
kernelSize n2d_kernel_size_config_t Structure for kernel size
filterType n2d_filter_type_t Enumeration type for filter type

n2d_buffer_t

  • Description

    • This structure defines the information of a Nano2D buffer

  • Member Table

Member Type Description
width n2d_int32_t Width of the buffer (in pixels)
height n2d_int32_t Height of the buffer (in pixels)
alignedw n2d_int32_t Aligned width of the buffer (in pixels)
alignedh n2d_int32_t Aligned height of the buffer (in pixels)
stride n2d_int32_t Stride of the buffer
srcType n2d_source_type_t Source type
format n2d_buffer_format_t Pixel format of the buffer
orientation n2d_orientation_t Orientation of the buffer
tiling n2d_tiling_t Tiling mode
cacheMode n2d_cache_mode_t Cache mode of the buffer
handle n2d_uintptr_t Buffer handle
memory n2d_pointer CPU-side address pointer
gpu n2d_uint32_t GPU-side address pointer
uvstride[MAX_UV_PLANE] n2d_int32_t Stride of UV plane [Valid only for YUV formats]
uv_handle[MAX_UV_PLANE] n2d_pointer Handle of UV plane [Valid only for YUV formats]
uv_memory[MAX_UV_PLANE] n2d_pointer CPU-side address of UV plane [Valid only for YUV formats]
uv_gpu[MAX_UV_PLANE] n2d_uint32_t GPU-side address of UV plane [Valid only for YUV formats]
tile_status_config n2d_tile_status_config_t Tiling status configuration
tile_status_buffer n2d_tile_status_buffer_t Tiling status

5.14.6. Return Value Description

5.14.6.1. n2d_error_t

  • Description

    • Nano2D API functions return status codes via n2d_error_. If successful, N2D_SUCCESS is returned. N2D_SUCCESS is defined as zero; therefore, any non-zero return value indicates an error. Possible error values are listed in the table below.

n2d_error_t value String Values Description
0 N2D_SUCCESS Success, no error
1 N2D_INVALID_ARGUMENT Invalid argument specified
2 N2D_OUT_OF_MEMORY Out of memory
3 N2D_NO_CONTEXT No open context
4 N2D_TIMEOUT Timeout occurred during wait
5 N2D_OUT_OF_RESOURCES Insufficient system resources
6 N2D_GENERIC_IO Failed to communicate with kernel driver
7 N2D_NOT_SUPPORTED Request not supported
8 N2D_ERROR_HEAP_CORRUPTED MMU table corrupted
9 N2D_NOT_ALIGNED Not aligned
10 N2D_NOT_FOUND Not found
11 N2D_INTERRUPTED Interrupted
12 N2D_MEMORY_LEAK Memory leak