Decode

Function Usage

Image decoding API of the ImageProcessor class. The Image memory allocated by this API does not need to be managed or destroyed by users. Only the memory allocated on the host can be used as the input of this API. Currently, the data type of the input image memory can be JPEG or PNG. For details, see Image Decoding.

  • JPG/JPEG format:
    • Maximum resolution of the JPG/JPEG input image: 8192 x 8192. (The RGB_888 and BGR_888 formats support only 4096 x 4096.)
    • Minimum resolution of the JPG/JPEG input image: 32 x 32
    • Supported formats by the output decoded images and outputImage: YUV_SP_420 and YVU_SP_420. The Atlas inference product and Atlas 800I A2 inference product also support RGB_888 and BGR_888.
    • Width of the output image.
      • For the Atlas 200/300/500 inference product, the output width is a multiple of 128.
      • For the Atlas 200I/500 A2 inference product, the output width is a multiple of 128. Before alignment, the API performs 2-pixel alignment downwards. Assume that the width of the source image is 1023. After the image is decoded by calling the decoding API, the value obtained by calling GetSize() is 1024, and the value obtained by calling GetOriginalSize() is 1022.
      • For the Atlas inference product and Atlas 800I A2 inference product, the output width is a multiple of 64. In format RGB_888 or BGR_888, the width is 16-pixel aligned, performed by the decoding API automatically.
    • Output image height: a multiple of 16. The decoding API automatically aligns the height.
      For the Atlas 200I/500 A2 inference product, the API performs 2-pixel alignment downwards before the alignment operation. Assume that the height of the source image is 683. After the call of the Decode API, the height get by calling GetSize() is 688, and the height get by calling GetOriginalSize() is 682.
      Restrictions on the JPG and JPEG input image format:
      • Only Huffman coding is supported. The subsample of the stream is 444, 422, 420, 400, or 440.
      • Arithmetic coding is not supported.
      • The progressive JPEG format is not supported.
      • The JPEG 2000 format is not supported.
  • PNG format:
    • Maximum resolution of the PNG input image: 4096 x 4096.
    • Minimum resolution of the PNG input image: 32 x 32.
    • Output image width: a multiple of 128. The decoding API automatically aligns the width.
    • Output image height: a multiple of 16. The decoding API automatically aligns the height.

Prototype

1
APP_ERROR ImageProcessor::Decode(const std::shared_ptr<uint8_t> dataPtr, const uint32_t dataSize, Image& outputImage, const ImageFormat decodeFormat = ImageFormat::YUV_SP_420);
1
APP_ERROR ImageProcessor::Decode(const std::string inputPath, Image& outputImage, const ImageFormat decodeFormat = ImageFormat::YUV_SP_420);

Parameters

Parameter

Input/Output

Description

dataPtr

Input

Memory address of the image data to be decoded. This address needs to be managed by the user before decoding.

dataSize

Input

Memory size of the image data to be decoded. The value must be the same as the actual memory size of dataPtr.

  • If the header information of the image cannot be completely read by the user-defined dataSize, an exception is returned.
  • If the value of the user-defined dataSize is greater than the size of the header information and less than the actual memory size, partial decoding is performed based on the value of dataSize.

  • If the value of the user-defined dataSize is greater than the actual memory size, the value of image EOF is used.

decodeFormat

Input

Format of the decoded image

  • For JPG/JPEG images, the default value of decodeFormat is YUV_SP_420. Set this parameter as required.
  • For PNG images, BGR_888 is valid only when the input image channel is in RGB/GRAY format. In other cases, this parameter is invalid and decoding is performed based on the PNG input format.
    • If the PNG image channel is in RGB/GRAY format, the format of the decoded output image is RGB_888.
    • If the PNG image channel is in RGBA/AGRAY format, the format of the decoded output image is RGBA_8888.

inputPath

Input

Path of the image to be decoded.

outputImage

Output

Decoded Image class.

The original and aligned widths and heights of the image are automatically integrated into outputImage.

Response Parameters

Data Structure

Description

APP_ERROR

For details about the returned error codes, see APP_ERROR Description.