Functions and Restrictions

Function Usage

JPEG Decoder (JPEGD) implements .jpg, .jpeg, .JPG, and .JPEG image decoding.

  • JPEGD supports image rotation during image decoding.

    If the input stream contains orientation information (the orientation of the camera to the scene when the image is captured), JPEGD parses the orientation information during decoding and rotates the image by 90º, 180º, or 270º, or mirrors the image. The width stride, height stride, and output buffer of the rotated image must meet the restrictions described in Restrictions on Image Formats, Width and Height Alignment, and Buffers.

    If the stream of the input image is abnormal, JPEGD fails to read the orientation information. As a result, the image rotation function cannot be implemented.

    There are restrictions when the image rotation function is used for the following products. For details, see Table 1.
    Table 1 Restrictions on the rotation function of JPEGD

    Product Version

    Restriction

    Atlas 200I/500 A2 inference products

    Atlas A2 training products/Atlas A2 inference products

    Atlas A3 training products/Atlas A3 inference products

    • For JPEGD 422 image rotation, if the height of the original image is an odd number and the rotation angle 90 or 270 degrees, black edges will exist in the odd boarders after rotation. In this case, align the odd boarders downwards to an even number (to remove the black edges). For example, if the original size is 200 x 101 and the size after rotation is 101 x 200, it is recommended that the actual area be 100 x 200.
    • For JPEGD 440 image rotation, if the width of the original image is an odd number and the rotation angle 90 or 270 degrees, black edges will exist in the odd boarders after rotation. In this case, align the odd boarders downwards to an even number (to remove the black edges). For example, if the original size is 201 x 100 and the size after rotation is 100 x 201, it is recommended that the actual area be 100 x 200.
  • JPEGD supports retaining the source image format during image decoding.

    The image encoding formats before and after decoding remain consistent. For example, if the source format is JPEG(440), the destination format is YUV440SP with V component before U component or YUV440SP with U component before V component.

    To retain the source image format after decoding, try either of the following ways:

    • Call acl.media.dvpp_jpeg_get_image_info_v2 to obtain the source image format before JPEGD decoding. In the JPEGD decoding API call, set the format of the output image to be the same as that of the input image.
    • In the JPEGD decoding API call, set the output format to PIXEL_FORMAT_UNKNOWN to get a semi-planar output in the source format with V component before U component.

      For example, if the source format is JPEG(440) and the destination format is set to PIXEL_FORMAT_UNKNOWN, the JPEGD destination format is YUV440SP with V component before U component.

    If the JPEGD destination image will be fed to a model for inference, you are advised to set the output image format to PIXEL_FORMAT_UNKNOWN. In this case, JPEGD decodes with the source format preserved (ensure that the JPEGD destination format is supported by the model) to avoid inference accuracy drop.

    If the JPEGD destination image will be used as the input of VPC, to decode with the source format preserved, check that VPC supports the JPEGD destination format by referring to Restrictions. If VPC does not support the JPEGD destination format, reconfigure a JPEGD destination format that is also supported by VPC.

Resolution Restrictions

  • Input resolution range:

    Version

    Resolution Range

    Atlas training products

    Atlas inference products

    32 x 32 to 8192 x 8192

    Atlas A2 training products/Atlas A2 inference products

    Atlas 200I/500 A2 inference products

    Atlas A3 training products/Atlas A3 inference products

    32 x 32 to 16384 x 16384

  • Output resolution range:

    JPEGD 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 Image Formats, Width and Height Alignment, and Buffers

During JPEGD image decoding, acl.media.dvpp_malloc and acl.media.dvpp_free are called to allocate and free the input and output buffers on the device. The buffer lifetime is managed by the user.

  • The size of the input buffer is the size of space occupied by the input image.
  • The size of the output buffer can be predicted by calling acl.media.dvpp_jpeg_predict_dec_size. For details about the calculation formula, see the following table.

JPEGD supports only Huffman coding and does not support arithmetic encoding, progressive JPEG format, or JPEG 2000 format. The color space of the input image must be YUV with YUV components in the ratio of 4:4:4, 4:2:2, 4:2:0, 4:0:0, or 4:4:0.

For details about the definition of the output image format, see acldvppPixelFormat. For details about the concepts such as width stride and height stride, see Terminology.

Table 2 Restrictions on the image format, width and height alignment, and buffer size

Input Format (YUV)

Output Format

Output Width and Height

Output Width Stride, Height Stride, and Buffer Size

Atlas training products

Output Width Stride, Height Stride, and Buffer Size

Atlas inference products

Atlas 200I/500 A2 inference products

Atlas A2 training products/Atlas A2 inference products

Atlas A3 training products/Atlas A3 inference products

JPEG(444)

YVU444SP 8-bit

No alignment requirement.

Width stride: Round up the width to the nearest multiple of 128.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 3

Width stride: Round up the width to the nearest multiple of 64.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 3

YUV444SP 8-bit

YUV420SP NV12 8-bit

Width: Must be a multiple of 2.

Height: Must be a multiple of 2.

Width stride: Round up the width to the nearest multiple of 128.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 3/2

Width stride: Round up the width to the nearest multiple of 64.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 3/2

YUV420SP NV21 8-bit

JPEG(422)

YVU422SP 8-bit

Width: Must be a multiple of 2.

Height: Must be a multiple of 2.

Width stride: Round up the width to the nearest multiple of 128.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 2

Width stride: Round up the width to the nearest multiple of 64.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 2

YUV422SP 8-bit

YUV420SP NV12 8-bit

Width: Must be a multiple of 2.

Height: Must be a multiple of 2.

Width stride: Round up the width to the nearest multiple of 128.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 3/2

Width stride: Round up the width to the nearest multiple of 64.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 3/2

YUV420SP NV21 8-bit

JPEG(420)

YUV420SP NV12 8-bit

Width: Must be a multiple of 2.

Height: Must be a multiple of 2.

Width stride: Round up the width to the nearest multiple of 128.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 3/2

Width stride: Round up the width to the nearest multiple of 64.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 3/2

YUV420SP NV21 8-bit

JPEG(400)

YUV420SP NV12 8-bit

Width: Must be a multiple of 2.

Height: Must be a multiple of 2.

Width stride: Round up the width to the nearest multiple of 128.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 3/2

Width stride: Round up the width to the nearest multiple of 64.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 3/2

YUV420SP NV21 8-bit

YUV400 8bit

The Atlas 200/300/500 inference products and Atlas training products do not support this format.

No alignment requirement.

Width stride: Round up the width to the nearest multiple of 128.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 2

Width stride: Round up the width to the nearest multiple of 64.

Height stride: Round up the height to the nearest multiple of 16.

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

JPEG(440)

YVU440SP 8-bit

Width: Must be a multiple of 2.

Height: Must be a multiple of 2.

Width stride: Round up the width to the nearest multiple of 128.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 2

Width stride: Round up the width to the nearest multiple of 64.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 2

YUV440SP 8-bit

YUV420SP NV12 8-bit

Width: Must be a multiple of 2.

Height: Must be a multiple of 2.

Width stride: Round up the width to the nearest multiple of 128.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 3/2

Width stride: Round up the width to the nearest multiple of 64.

Height stride: Round up the height to the nearest multiple of 16.

Buffer size (in bytes) ≥ Width stride x Height stride x 3/2

YUV420SP NV21 8-bit

Requirements for Software and Hardware

  • Hardware requirements
    • A maximum of four Huffman tables are supported, including two direct coefficient (DC) tables and two alternating coefficient (AC) tables.
    • A maximum of three quantization tables are supported.
    • Only 8-bit sampling is supported.
    • Only sequentially-encoded images can be decoded.
    • Only JPEG decoding based on discrete cosine transform (DCT) is supported.
    • Only one start of scan (SOS) marker is supported for image decoding.
  • Software requirements
    • A maximum of three SOS markers are allowed for image decoding.
    • Decoding of abnormal images with insufficient data in minimum coded units (MCUs) is supported.

Accuracy Restrictions

Atlas training products: In the event of JPEGD+VPC cascade, the width stride by the height stride of the JPEGD output image is 128 x 16 aligned, which means that the width and height of the JPEGD output have invalid edge paddings. Therefore, when executing VPC functions such as resizing, call acl.media.dvpp_set_pic_desc_width and acl.media.dvpp_set_pic_desc_height to correctly set the original width and height of the input image. As such, VPC will automatically crop the image based on the width and height of the source image before resizing the image, eliminating the impact of invalid data on image accuracy.

Atlas 200I/500 A2 inference products: In the event of JPEGD+VPC cascade, the width stride by the height stride of the JPEGD output image is 64 x 16 aligned, which means that the width and height of the JPEGD output have invalid edge paddings. Therefore, when executing VPC functions such as resizing, call acl.media.dvpp_set_pic_desc_width and acl.media.dvpp_set_pic_desc_height to correctly set the original width and height of the input image. As such, VPC will automatically crop the image based on the width and height of the source image before resizing the image, eliminating the impact of invalid data on image accuracy.

Atlas inference products: In the event of JPEGD+VPC cascade, the width stride by the height stride of the JPEGD output image is 64 x 16 aligned, which means that the width and height of the JPEGD output have invalid edge paddings. Therefore, when executing VPC functions such as resizing, call acl.media.dvpp_set_pic_desc_width and acl.media.dvpp_set_pic_desc_height to correctly set the original width and height of the input image. As such, VPC will automatically crop the image based on the width and height of the source image before resizing the image, eliminating the impact of invalid data on image accuracy.

Atlas A2 training products/Atlas A2 inference products: In the event of JPEGD+VPC cascade, the width stride by the height stride of the JPEGD output image is 64 x 16 aligned, which means that the width and height of the JPEGD output have invalid edge paddings. Therefore, when executing VPC functions such as resizing, call acl.media.dvpp_set_pic_desc_width and acl.media.dvpp_set_pic_desc_height to correctly set the original width and height of the input image. As such, VPC will automatically crop the image based on the width and height of the source image before resizing the image, eliminating the impact of invalid data on image accuracy.

Atlas A3 training products/Atlas A3 inference products: In the event of JPEGD+VPC cascade, the width stride by the height stride of the JPEGD output image is 64 x 16 aligned, which means that the width and height of the JPEGD output have invalid edge paddings. Therefore, when executing VPC functions such as resizing, call acl.media.dvpp_set_pic_desc_width and acl.media.dvpp_set_pic_desc_height to correctly set the original width and height of the input image. As such, VPC will automatically crop the image based on the width and height of the source image before resizing the image, eliminating the impact of invalid data on image accuracy.