From ae9b5a76b89f61b30b8230b2e82485406add85d2 Mon Sep 17 00:00:00 2001 From: yaozhupeng Date: Mon, 14 Apr 2025 18:06:36 +0800 Subject: [PATCH] add pixelmap create with allocatorType interfaces Signed-off-by: yaozhupeng --- .../include/image/image_common.h | 32 +++++++++++ .../include/image/pixelmap_native.h | 57 +++++++++++++++++++ .../image_framework/libpixelmap.ndk.json | 12 ++++ 3 files changed, 101 insertions(+) diff --git a/multimedia/image_framework/include/image/image_common.h b/multimedia/image_framework/include/image/image_common.h index d17f95a5d..395223163 100644 --- a/multimedia/image_framework/include/image/image_common.h +++ b/multimedia/image_framework/include/image/image_common.h @@ -179,6 +179,12 @@ typedef enum { * @since 15 */ IMAGE_LOCK_UNLOCK_FAILED = 7600303, + /** + * @error unsupported allocator mode, e.g., use share memory to create a HDR image as only + * DMA supported hdr metadata. + * @since 20 + */ + IMAGE_ALLOCATOR_MODE_UNSUPPROTED = 7600501, /** unknown error */ IMAGE_UNKNOWN_ERROR = 7600901, /** decode data source exception */ @@ -230,6 +236,32 @@ typedef enum { FRAGMENT_METADATA = 2, } Image_MetadataType; +/** + * @brief Type of allocator used to allocate memory of a PixelMap. + * + * @since 20 + */ +typedef enum { + /** + * The system determines which memory to use to create the PixelMap. + * + * @since 20 + */ + IMAGE_ALLOCATOR_MODE_AUTO = 0, + /** + * Use DMA buffer to create the PixelMap. + * + * @since 20 + */ + IMAGE_ALLOCATOR_MODE_DMA = 1, + /** + * Use share memory to create the PixelMap. + * + * @since 20 + */ + IMAGE_ALLOCATOR_MODE_SHARED_MEMORY = 2, +} IMAGE_ALLOCATOR_MODE; + /** * @brief Creates a PictureMetadata object. * diff --git a/multimedia/image_framework/include/image/pixelmap_native.h b/multimedia/image_framework/include/image/pixelmap_native.h index 1fa825bab..bd0694c4d 100644 --- a/multimedia/image_framework/include/image/pixelmap_native.h +++ b/multimedia/image_framework/include/image/pixelmap_native.h @@ -576,6 +576,18 @@ Image_ErrorCode OH_PixelmapImageInfo_GetWidth(OH_Pixelmap_ImageInfo *info, uint3 */ Image_ErrorCode OH_PixelmapImageInfo_GetHeight(OH_Pixelmap_ImageInfo *info, uint32_t *height); +/** + * @brief Get alphaMode number for imageinfo struct. + * + * @param info The imageinfo pointer will be operated. + * @param alphaMode The number of imageinfo alphaMode. + * @return Image functions result code. + * {@link IMAGE_SUCCESS} if the execution is successful. + * {@link IMAGE_BAD_PARAMETER} pixelmapNative is nullptr, or pixelmapNapi is not a pixelmap. + * @since 20 + */ +Image_ErrorCode OH_PixelmapImageInfo_GetAlphaMode(OH_Pixelmap_ImageInfo *info, int32_t *alphaMode); + /** * @brief Get rowStride number for imageinfo struct. * @@ -639,6 +651,30 @@ Image_ErrorCode OH_PixelmapImageInfo_Release(OH_Pixelmap_ImageInfo *info); Image_ErrorCode OH_PixelmapNative_CreatePixelmap(uint8_t *data, size_t dataLength, OH_Pixelmap_InitializationOptions *options, OH_PixelmapNative **pixelmap); +/** + * @brief Creates a pixelmap based on options {@link OH_Pixelmap_InitializationOptions}, the memory type used by the + * pixelmap can be specified by allocatorType {@link IMAGE_ALLOCATOR_MODE}. By default, the system selects the memory + * type based on the image type, image size, platform capability, etc. When processing the pixelmap returned by this + * interface, please always consider the impact of stride. + * + * @param data Input color buffer in BGRA_8888 format by default. + * @param dataLength Length of input buffer in bytes. + * @param options Pixelmap initialization properties including size, pixel format, alpha type, and editable flags. + * @param allocator Indicate which memory type will be used by the returned pixelmap. + * @param pixelmap Output parameter receiving the created pixelmap object pointer. + * @return Function result code: + * {@link IMAGE_SUCCESS} If the operation is successful. + * {@link IMAGE_BAD_PARAMETER} If the param is nullptr or invalid. + * {@link IMAGE_TOO_LARGE} too large data or image. + * {@link IMAGE_UNSUPPORTED_OPERATION} unsupported operations. + * {@link IMAGE_DMA_OPERATION_FAILED} DMA operation failed. + * {@link IMAGE_UNSUPPORTED_ALLOCATOR_MODE} unsupported allocator mode, e.g., + * use share memory to create a HDR image as only DMA supported hdr metadata. + * @since 20 + */ +Image_ErrorCode OH_PixelmapNative_CreatePixelmapUsingAllocator(uint8_t *data, size_t dataLength, + OH_Pixelmap_InitializationOptions *options, IMAGE_ALLOCATOR_MODE allocator, OH_PixelmapNative **pixelmap); + /** * @brief Convert a native PixelMap object to PixelMap napi object. * @@ -886,6 +922,27 @@ Image_ErrorCode OH_PixelmapNative_ConvertAlphaFormat(OH_PixelmapNative* srcpixel Image_ErrorCode OH_PixelmapNative_CreateEmptyPixelmap( OH_Pixelmap_InitializationOptions *options, OH_PixelmapNative **pixelmap); +/** + * @brief Creates a empty pixelmap based on options {@link OH_Pixelmap_InitializationOptions}, the memory type used by the + * pixelmap can be specified by allocatorType {@link IMAGE_ALLOCATOR_MODE}. By default, the system selects the memory + * type based on the image type, image size, platform capability, etc. When processing the pixelmap returned by this + * interface, please always consider the impact of stride. + * + * @param options Pixelmap initialization properties including size, pixel format, alpha type, and editable flags. + * @param allocator Indicate which memory type will be used by the returned pixelmap. + * @param pixelmap Output parameter receiving the created pixelmap object pointer. + * @return Function result code: + * {@link IMAGE_SUCCESS} If the operation is successful. + * {@link IMAGE_BAD_PARAMETER} If the param is nullptr or invalid. + * {@link IMAGE_TOO_LARGE} too large data or image. + * {@link IMAGE_UNSUPPORTED_OPERATION} unsupported operations. + * {@link IMAGE_UNSUPPORTED_ALLOCATOR_MODE} unsupported allocator mode, e.g., use + * share memory to create a HDR image as only DMA supported hdr metadata. + * @since 20 + */ +Image_ErrorCode OH_PixelmapNative_CreateEmptyPixelmapUsingAllocator( + OH_Pixelmap_InitializationOptions *options, IMAGE_ALLOCATOR_MODE allocator, OH_PixelmapNative **pixelmap); + /** * @brief Get metadata. * diff --git a/multimedia/image_framework/libpixelmap.ndk.json b/multimedia/image_framework/libpixelmap.ndk.json index 68d850462..f52699ef6 100644 --- a/multimedia/image_framework/libpixelmap.ndk.json +++ b/multimedia/image_framework/libpixelmap.ndk.json @@ -15,6 +15,10 @@ "first_introduced": "12", "name": "OH_PixelmapInitializationOptions_GetHeight" }, + { + "first_introduced": "20", + "name": "OH_PixelmapImageInfo_GetAlphaMode" + }, { "first_introduced": "12", "name": "OH_PixelmapInitializationOptions_SetHeight" @@ -99,6 +103,10 @@ "first_introduced": "12", "name": "OH_PixelmapNative_CreatePixelmap" }, + { + "first_introduced": "20", + "name": "OH_PixelmapNative_CreatePixelmapUsingAllocator" + }, { "first_introduced": "12", "name": "OH_PixelmapNative_ReadPixels" @@ -171,6 +179,10 @@ "first_introduced": "12", "name": "OH_PixelmapNative_CreateEmptyPixelmap" }, + { + "first_introduced": "20", + "name": "OH_PixelmapNative_CreateEmptyPixelmapUsingAllocator" + }, { "first_introduced": "12", "name": "OH_PixelmapNative_GetMetadata" -- Gitee