Functions and Restrictions

The Atlas training product does not support the PNGD function described in this section.

Description

PNG Decoder (PNGD) decodes PNG images using hardware.

PNGD supports retaining the source image format during image decoding. That is, the image formats before and after decoding remain consistent. For example, if the source format is RGB, the destination format is RGB888.

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

  • When using the PNGD 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 acl.himpi.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 acl.himpi.png_get_image_info API to set the output image format.

Restrictions on Buffer Allocation and Freeing APIs

The size of the input buffer is the size of the input image. For details about the size of the output buffer, see the formula in Table 1.

Version

Buffer Allocation/Freeing API

Atlas inference product

During PNG image decoding, call acl.himpi.dvpp_malloc\acl.himpi.dvpp_free to allocate or free the input and output buffers on the device. The buffer lifetime is managed by the user.

Atlas A2 training product / Atlas A2 inference product

Atlas 200I/500 A2 inference product

Atlas A3 training product / Atlas A3 inference product

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

The memory allocated by calling the acl.himpi.dvpp_malloc API 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 the acl.rt.malloc API to allocate memory.

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

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.

  • High 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

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

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

RGBA8888 8-bit

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

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

RGBA8888 8-bit

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

  • 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 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.

Other Restrictions

PNGD can decode only complete PNG images rather than data packets split from a PNG image.