PNGD Functions and Restrictions

Function Description

PNG Decoder (PNGD) decodes PNG images.

PNGD allows retaining the source image format during image decoding. That is, the image formats before and after decoding are the same. For example, if the source format is RGB, the destination format can be RGB888.

If the source format of the PNG image is unknown, you can preserve the source format using either of the following methods:

  • When using the PNGD decoding APIs, set the output image format to HI_PIXEL_FORMAT_UNKNOWN. By default, the source image format is used for output. In this method, however, the output image format is unknown. Therefore, you must allocate the output buffer as large as possible to ensure that the output image can be stored properly.

    Input Format

    Operation

    Output Format

    RGB/GRAY

    Set the output image format to HI_PIXEL_FORMAT_UNKNOWN.

    RGB888

    RGBA/AGRAY

    Set the output image format to HI_PIXEL_FORMAT_UNKNOWN.

    RGBA8888

  • Call the hi_mpi_png_get_image_info API to obtain the width, height, width stride, height stride, output buffer size, and image format of the output image based on the input PNG source image, and then call the PNGD decoding API, use the image format obtained through the hi_mpi_png_get_image_info API to set the output image format.

Resolution Restrictions

  • Input resolution range

    32 × 32 to 4096 × 4096

  • Output resolution range:

    PNGD only decodes images and does not change the image resolution. Therefore, the resolution of the output image is the same as that of the input image.

Restrictions on Buffer Allocation and Freeing APIs

The size of the input buffer refers to the actual size occupied by the input image. For details about the size of the output buffer, see the formula in Table 1.

Model

Buffer Allocation/Freeing API

Atlas inference product

During PNG image decoding, call the hi_mpi_dvpp_malloc\hi_mpi_dvpp_free API to allocate or release the input and output buffers on the device. The lifecycle of the buffers is managed by the user.

Atlas 350 Accelerator Card

Atlas A3 training product / Atlas A3 inference product

Atlas A2 training product / Atlas A2 inference product

Atlas 200I/500 A2 inference product

During PNG image decoding, the following two types of APIs for buffer allocation/freeing are supported:

  • Call the aclrtMalloc\aclrtFree API to allocate or release the input and output memory on the device. The lifecycle of the memory is managed by the user.
  • Call the hi_mpi_dvpp_malloc\hi_mpi_dvpp_free API to allocate or release the input and output memory on the device. The lifecycle of the memory is managed by the user.

Note: The memory allocated by calling hi_mpi_dvpp_malloc is the dedicated memory for media data processing. However, the address space of the dedicated memory is limited. If memory planning is concerned or memory resources are limited, you are advised to call aclrtMalloc to allocate memory.

Restrictions on Image Formats, Width and Height Alignment, and Buffers

For details about the output image format, see hi_pixel_format. For details about the width stride and height stride, see Terminology.

If the output image format is unknown, set it to HI_PIXEL_FORMAT_UNKNOWN:

  • Width stride

    If the input image is in RGB or GRAY format, the width stride is obtained by rounding up the width of the output image to the nearest multiple of 128 and then multiplying the result by 3. If the input image is in RGBA or AGRAY format, the width stride is obtained by rounding up the width of the output image to the nearest multiple of 128 and then multiplying the result by 4.

  • Height stride: Round up the height of the output image to the nearest multiple of 16.
Table 1 Restrictions on the image format, width and height alignment, and buffer size

Input Format

Output Format

Output Width and Height

Output Width Stride, Height Stride, and Buffer Size

RGB

RGB888

No alignment requirement.

Width stride: Round up the width to the nearest multiple of 1, 16, or 128 and multiply the result by 3.

Value range of the height stride: [Height of the output image, Height of the output image rounded up to a multiple of 128]

Buffer size (in bytes) = Width stride x Height stride

GRAY

RGB888

No alignment requirement.

RGBA

RGB888

No alignment requirement.

Width stride: Round up the width to the nearest multiple of 1, 16, or 128 and multiply the result by 3.

Value range of the height stride: [Height of the output image, Height of the output image rounded up to a multiple of 128]

Buffer size (in bytes) = Width stride x Height stride

RGBA

RGBA8888 8bit

No alignment requirement.

Width stride: Round up the width to the nearest multiple of 1, 16, or 128 and multiply the result by 4.

Value range of the height stride: [Height of the output image, Height of the output image rounded up to a multiple of 128]

Buffer size (in bytes) = Width stride x Height stride

AGRAY

RGB888

No alignment requirement.

Width stride: Round up the width to the nearest multiple of 1, 16, or 128 and multiply the result by 3.

Value range of the height stride: [Height of the output image, Height of the output image rounded up to a multiple of 128]

Buffer size (in bytes) = Width stride x Height stride

AGRAY

RGBA8888 8bit

No alignment requirement.

Width stride: Round up the width to the nearest multiple of 1, 16, or 128 and multiply the result by 4.

Value range of the height stride: [Height of the output image, Height of the output image rounded up to a multiple of 128]

Buffer size (in bytes) = Width stride x Height stride

Other Restrictions

PNGD can decode only complete PNG images but not data packets split from a PNG image.

If the width stride and height stride are set to 0 and passed to the corresponding APIs, PNGD will round up the width stride to the nearest multiple of 128 and round up the height stride to the nearest multiple of 16 by default based on the output image format.