Functions and Restrictions

Atlas training products do 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

    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

  • Call the acl.himpi.png_get_image_info API to obtain the information about the output image, including the width, height, width stride, height stride, size of the output buffer, and image format, based on the input PNG source image. Then, call the PNGD decoding API and set the output image format to the image format obtained by the acl.himpi.png_get_image_info API.

APIs for Buffer Allocation and Freeing

The size of the input buffer is the actual 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 products

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

Atlas A2 training products / Atlas A2 inference products

Atlas 200I/500 A2 inference products

Atlas A3 training products / Atlas A3 inference products

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

  • Allocate or release the input and output buffer on the device by calling acl.rt.malloc/acl.rt.free. The lifecycle of the buffer is managed by the user.
  • Allocate or release the input and output buffer on the device by calling acl.himpi.dvpp_malloc/acl.himpi.dvpp_free. The lifecycle of the buffer is managed by the user.

acl.himpi.dvpp_malloc allocates a dedicated buffer for processing media data. However, the address space of the dedicated buffer is limited. If buffer planning is cared or buffer resources are limited, you are advised to allocate buffer by calling acl.rt.malloc.

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

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

  • For details about the output image format, see hi_pixel_format. For details about the 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 but not data packets split from a PNG image.