image_native.h

Overview

The file declares the cropping rectangle, size, and component data of an image.

File to include: <multimedia/image_framework/image/image_native.h>

Library: libohimage.so

System capability: SystemCapability.Multimedia.Image.Core

Since: 12

Related module: Image_NativeModule

Summary

Structs

Name typedef Keyword Description
OH_ImageBufferData OH_ImageBufferData OH_ImageBufferData is the image data struct encapsulated at the native layer.
OH_ImageNative OH_ImageNative Describes the alias for an image object at the native layer.

Functions

Name Description
Image_ErrorCode OH_ImageNative_GetImageSize(OH_ImageNative *image, Image_Size *size) Obtains the Image_Size information of an OH_ImageNative object.
Image_ErrorCode OH_ImageNative_GetComponentTypes(OH_ImageNative *image, uint32_t **types, size_t *typeSize) Obtains the component types of an OH_ImageNative object.
Image_ErrorCode OH_ImageNative_GetByteBuffer(OH_ImageNative *image, uint32_t componentType, OH_NativeBuffer **nativeBuffer) Obtains the buffer corresponding to a component type in an OH_ImageNative object.
Image_ErrorCode OH_ImageNative_GetBufferSize(OH_ImageNative *image, uint32_t componentType, size_t *size) Obtains the size of the buffer corresponding to a component type in an OH_ImageNative object.
Image_ErrorCode OH_ImageNative_GetRowStride(OH_ImageNative *image, uint32_t componentType, int32_t *rowStride) Obtains the row stride corresponding to a component type in an OH_ImageNative object.
Image_ErrorCode OH_ImageNative_GetPixelStride(OH_ImageNative *image, uint32_t componentType, int32_t *pixelStride) Obtains the pixel stride corresponding to a component type in an OH_ImageNative object.
Image_ErrorCode OH_ImageNative_GetTimestamp(OH_ImageNative *image, int64_t *timestamp) Obtains the timestamp of an OH_ImageNative object.
Image_ErrorCode OH_ImageNative_Release(OH_ImageNative *image) Releases an OH_ImageNative object.
Image_ErrorCode OH_ImageNative_GetColorSpace(OH_ImageNative *image, int32_t *colorSpaceName) Obtains the color space in an OH_ImageNative object.
Image_ErrorCode OH_ImageNative_GetFormat(OH_ImageNative *image, OH_NativeBuffer_Format *format) Obtains the image format in an OH_ImageNative object.
Image_ErrorCode OH_ImageNative_GetBufferData(OH_ImageNative *image, OH_ImageBufferData *imageBufferData) Obtains the image buffer data object in an OH_ImageNative object.

Function Description

OH_ImageNative_GetImageSize()

Image_ErrorCode OH_ImageNative_GetImageSize(OH_ImageNative *image, Image_Size *size)

Description

Obtains the Image_Size information of an OH_ImageNative object.

If the OH_ImageNative object stores the camera preview stream data (YUV image data), the width and height in Image_Size obtained correspond to those of the YUV image. If the OH_ImageNative object stores the camera photo stream data (JPEG image data, which is already encoded), the width in Image_Size obtained is the JPEG data size, and the height is 1.

The type of data stored in the OH_ImageNative object depends on whether the application passes the surface ID in the receiver to a previewOutput or captureOutput object of the camera. For details about the best practices of camera preview and photo capture, see Secondary Processing of Preview Streams (C/C++) and Photo Capture (C/C++).

Since: 12

Parameters

Name Description
OH_ImageNative *image Pointer to an OH_ImageNative object.
Image_Size *size Pointer to the Image_Size object obtained.

Returns

Type Description
Image_ErrorCode IMAGE_SUCCESS: The operation is successful.
IMAGE_BAD_PARAMETER: A parameter is incorrect.
IMAGE_UNKNOWN_ERROR: An unknown error occurs.

OH_ImageNative_GetComponentTypes()

Image_ErrorCode OH_ImageNative_GetComponentTypes(OH_ImageNative *image,uint32_t **types, size_t *typeSize)

Description

Obtains the component types of an OH_ImageNative object.

Since: 12

Parameters

Name Description
OH_ImageNative *image Pointer to an OH_ImageNative object.
uint32_t **types Pointer to the component type list object obtained. Since the number of components is uncertain, this API needs to be called twice: first, set types to NULL to obtain the number of components (typeSize); second, allocate corresponding memory for types based on typeSize and then obtain the component type list.
size_t *typeSize Pointer to the number of component types obtained.

Returns

Type Description
Image_ErrorCode IMAGE_SUCCESS: The operation is successful.
IMAGE_BAD_PARAMETER: A parameter is incorrect.

OH_ImageNative_GetByteBuffer()

Image_ErrorCode OH_ImageNative_GetByteBuffer(OH_ImageNative *image,uint32_t componentType, OH_NativeBuffer **nativeBuffer)

Description

Obtains the buffer corresponding to a component type in an OH_ImageNative object.

Since: 12

Parameters

Name Description
OH_ImageNative *image Pointer to an OH_ImageNative object.
uint32_t componentType Component type. The value is obtained using the OH_ImageNative_GetComponentTypes API.
OH_NativeBuffer **nativeBuffer Double pointer to the buffer, which is an OH_NativeBuffer object.

Returns

Type Description
Image_ErrorCode IMAGE_SUCCESS: The operation is successful.
IMAGE_BAD_PARAMETER: A parameter is incorrect.

OH_ImageNative_GetBufferSize()

Image_ErrorCode OH_ImageNative_GetBufferSize(OH_ImageNative *image,uint32_t componentType, size_t *size)

Description

Obtains the size of the buffer corresponding to a component type in an OH_ImageNative object.

Since: 12

Parameters

Name Description
OH_ImageNative *image Pointer to an OH_ImageNative object.
uint32_t componentType Component type. The value is obtained using the OH_ImageNative_GetComponentTypes API.
size_t *size Pointer to the size of the buffer.

Returns

Type Description
Image_ErrorCode IMAGE_SUCCESS: The operation is successful.
IMAGE_BAD_PARAMETER: A parameter is incorrect.

OH_ImageNative_GetRowStride()

Image_ErrorCode OH_ImageNative_GetRowStride(OH_ImageNative *image,uint32_t componentType, int32_t *rowStride)

Description

Obtains the row stride corresponding to a component type in an OH_ImageNative object.

Camera preview stream data must be read based on the stride. For details, see Secondary Processing of Preview Streams (C/C++).

Since: 12

Parameters

Name Description
OH_ImageNative *image Pointer to an OH_ImageNative object.
uint32_t componentType Component type. The value is obtained using the OH_ImageNative_GetComponentTypes API.
int32_t *rowStride Pointer to the row stride obtained.

Returns

Type Description
Image_ErrorCode IMAGE_SUCCESS: The operation is successful.
IMAGE_BAD_PARAMETER: A parameter is incorrect.

OH_ImageNative_GetPixelStride()

Image_ErrorCode OH_ImageNative_GetPixelStride(OH_ImageNative *image,uint32_t componentType, int32_t *pixelStride)

Description

Obtains the pixel stride corresponding to a component type in an OH_ImageNative object.

Since: 12

Parameters

Name Description
OH_ImageNative *image Pointer to an OH_ImageNative object.
uint32_t componentType Component type. The value is obtained using the OH_ImageNative_GetComponentTypes API.
int32_t *pixelStride Pointer to the pixel stride obtained.

Returns

Type Description
Image_ErrorCode IMAGE_SUCCESS: The operation is successful.
IMAGE_BAD_PARAMETER: A parameter is incorrect.

OH_ImageNative_GetTimestamp()

Image_ErrorCode OH_ImageNative_GetTimestamp(OH_ImageNative *image, int64_t *timestamp)

Description

Obtains the timestamp of an OH_ImageNative object. Timestamps, measured in nanoseconds, are usually monotonically increasing.

The specific meaning and baseline of these timestamps are determined by the image producer, which is the camera in the camera preview and photo scenarios. As a result, images from different producers may carry timestamps with distinct meanings and baselines, making direct comparison between them infeasible.

To obtain the generation time of a photo, you can use OH_ImageSourceNative_GetImageProperty to read the related Exif information.

Since: 12

Parameters

Name Description
OH_ImageNative *image Pointer to an OH_ImageNative object.
int64_t *timestamp Pointer to the timestamp.

Returns

Type Description
Image_ErrorCode IMAGE_SUCCESS: The operation is successful.
IMAGE_BAD_PARAMETER: A parameter is incorrect.

OH_ImageNative_Release()

Image_ErrorCode OH_ImageNative_Release(OH_ImageNative *image)

Description

Releases an OH_ImageNative object.

Since: 12

Parameters

Name Description
OH_ImageNative *image Pointer to an OH_ImageNative object.

Returns

Type Description
Image_ErrorCode IMAGE_SUCCESS: The operation is successful.
IMAGE_BAD_PARAMETER: A parameter is incorrect.

OH_ImageNative_GetColorSpace()

Image_ErrorCode OH_ImageNative_GetColorSpace(OH_ImageNative *image, int32_t *colorSpaceName)

Description

Obtains the color space in an OH_ImageNative object.

Since: 23

Parameters

Name Description
OH_ImageNative *image Pointer to an OH_ImageNative object.
int32_t *colorSpaceName Pointer to the image color space. For details about the color space corresponding to colorSpaceName, see ColorSpaceName.

Returns

Type Description
Image_ErrorCode IMAGE_SUCCESS: The operation is successful.
IMAGE_BAD_PARAMETER: A parameter is incorrect.

OH_ImageNative_GetFormat()

Image_ErrorCode OH_ImageNative_GetFormat(OH_ImageNative *image, OH_NativeBuffer_Format *format)

Description

Obtains the image format in an OH_ImageNative object.

Since: 23

Parameters

Name Description
OH_ImageNative *image Pointer to an OH_ImageNative object.
OH_NativeBuffer_Format *format Pointer to the image format.

Returns

Type Description
Image_ErrorCode IMAGE_SUCCESS: The operation is successful.
IMAGE_BAD_PARAMETER: A parameter is incorrect.

OH_ImageNative_GetBufferData()

Image_ErrorCode OH_ImageNative_GetBufferData(OH_ImageNative *image, OH_ImageBufferData *imageBufferData)

Description

Obtains the image buffer data object in an OH_ImageNative object.

Since: 23

Parameters

Name Description
OH_ImageNative *image Pointer to an OH_ImageNative object.
OH_ImageBufferData *imageBufferData Pointer to the image buffer data object.

Returns

Type Description
Image_ErrorCode IMAGE_SUCCESS: The operation is successful.
IMAGE_BAD_PARAMETER: A parameter is incorrect.