Image

Function Usage

Constructor of the Image class. It can be created in the following ways: If the construction fails due to insufficient memory or unidentified processor, an exception occurs.

  • Construct an empty Image object.
  • Create an image with custom memory data. The default image format is ImageFormat::YUV_SP_420, and the default device ID is -1 is on the host side.
  • Create an image with aligned height and width, valid height and width, and custom memory data, meeting the following conditions:
    • The deviceId (device ID) must be in the range of [–1, Number of detected devices – 1]. Otherwise, the API fails to be called.
    • The format can be:
      1
      2
      3
      4
      5
      6
      7
      YUV_400 = 0,
      RGB_888 = 12,
      BGR_888 = 13,
      ARGB_8888 = 14,
      ABGR_8888 = 15,
      RGBA_8888 = 16,
      BGRA_8888 = 17,
      
    • The dataSize must be the same as the valid width/height or the aligned width/height. Calculation formula: dataSize = Width x Height x Number of channels.

To construct an Image object on the device after applying memory is allocated on the host, perform the following operations:

  1. Construct an Image object on the host and set deviceId to -1 (the location is on the host, the same as that of the imageData memory).
  2. The constructed Image object uses the ToDevice(deviceId) method to migrate the memory to the device.

Prototype

1
Image::Image();
1
Image::Image(const std::shared_ptr<uint8_t> imageData, const uint32_t dataSize, const int32_t deviceId = -1, const Size imageSize = DEFAULT_IMAGE_SIZE, const ImageFormat format = ImageFormat::YUV_SP_420);
1
Image::Image(const std::shared_ptr<uint8_t> imageData, const uint32_t dataSize, const int32_t deviceId, const std::pair<Size, Size> imageSizeInfo, const ImageFormat format);

Parameters

Parameter

Input/Output

Description

imageData

Input

Input memory constructed by the user. The memory is allocated and released by the user and cannot be a null pointer (nullptr).

dataSize

Input

Size of the memory input by the user. The value must be the same as the actual size of the memory data.

imageSize

Input

Image width and height, (0, 0) by default.

If the memory on the device is allocated by the user, set the value based on the actual memory data.

imageSizeInfo

Input

Combination of the valid width/height of the image and the aligned width/height. The valid width/height cannot exceed the aligned width/height. The height and width inputs are as follows:

std::pair<Size, Size> imageSizeInfo(valid width/height,aligned width/height)
  • The valid width/height range is [6, 8192].
  • The aligned width/height range is [16, 8192]. The width is a multiple of 16, and the height is a multiple of 2.

format

Input

Image format type.

deviceId

Input

ID of the device where memory is input by the user. If the memory on the device is allocated by the user, enter the corresponding device ID.

Value range: [-1, Number of detected devices – 1].

The memory of the device ID and that of imageData must be on the same side (host: -1; device: device ID). Otherwise, there are risks and exceptions in subsequent services.