PNGD Functions and Restrictions

The Atlas training products do not support the PNGD function described in this section.

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 Image Format

    Operation

    Actual Output Image 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

  • From the input source PNG image, call hi_mpi_png_get_image_info to obtain the width, height, width stride, height stride, output buffer, and format of the output image. Then call the PNGD decoding API to set the output format based on the obtained information.

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.

APIs for Buffer Allocation and Freeing

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

APIs for Buffer Allocation and Freeing

Atlas inference products

During PNG image decoding, call hi_mpi_dvpp_malloc to allocate the input and output buffers on the device, and hi_mpi_dvpp_free to free the input and output buffers. The buffer lifetime is managed by the user.

Atlas A3 training products/Atlas A3 inference products

Atlas A2 training products/Atlas A2 inference products

Atlas 200I/500 A2 inference products

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

  • Call aclrtMalloc to allocate the input and output buffers on the device, and aclrtFree to free the input and output buffers. The buffer lifetime is managed by the user.
  • Call hi_mpi_dvpp_malloc to allocate the input and output buffers on the device, and hi_mpi_dvpp_free to free the input and output buffers. The buffer lifetime is managed by the user.

Note: hi_mpi_dvpp_malloc allocates a dedicated buffer for processing media data. However, the address space of the dedicated buffer is limited. If buffer resources are limited, aclrtMalloc is recommended for allocating buffer.

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

For details about the definition of the output image format, see hi_pixel_format. For details about the concepts such as 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 image formats, width and height alignment, and buffers

Input Image Format

Output Image Format

Output Width and Height

Output Width Stride, Height Stride, and Buffer Size

RGB

RGB888

No alignment requirements.

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 the nearest multiple of 128]

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

GRAY

RGB888

RGBA

RGB888

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 the nearest multiple of 128]

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

RGBA8888 8bit

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 the nearest multiple of 128]

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

AGRAY

RGB888

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 the nearest multiple of 128]

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

RGBA8888 8bit

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 the nearest 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.