Decode

Function Usage

Image decoding API of the ImageProcessor class. The 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.

  • 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 products also support RGB_888 and BGR_888 formats.)
    • Output image width: a multiple of 128 (Atlas 200/300/500 inference product); a multiple of 64 (Atlas inference products); a multiple of 16 (RGB_888 and BGR_888). The decoding API automatically aligns the width.
    • Output image height: a multiple of 16. The decoding API automatically aligns the height.
      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.
    • decodeFormat does not need to be set. By default, decoding is performed based on the PNG source format. For example:
      • 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.
    • 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

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

Parameter Description

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, you do not need to set decodeFormat. PNG images are decoded based on the image source format.

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.

Return Parameter Description

Data Structure

Description

APP_ERROR

Error code returned during program execution. For details, see the MxBase/ErrorCode/ErrorCode.h file.