diff --git a/zh-cn/native_sdk/media/image/image_mdk.h b/zh-cn/native_sdk/media/image/image_mdk.h new file mode 100644 index 0000000000000000000000000000000000000000..85d8a28d73b8100c927371cb67660ad1bc5a6268 --- /dev/null +++ b/zh-cn/native_sdk/media/image/image_mdk.h @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup image + * @{ + * + * @brief 提供image接口的访问。 + * + * @Syscap SystemCapability.Multimedia.Image + * @since 10 + * @version 2.0 + */ + +/** + * @file image_mdk.h + * + * @brief 声明访问图像剪辑矩形、大小、格式和组件数据的函数。 + * + * @since 10 + * @version 2.0 + */ + +#ifndef INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_MDK_H_ +#define INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_MDK_H_ +#include +#include "napi/native_api.h" +#include "image_mdk_common.h" +namespace OHOS { +namespace Media { +#ifdef __cplusplus +extern "C" { +#endif + +struct ImageNative_; + +/** + * @brief 为图像接口定义native层图像对象。 + * + * @since 10 + * @version 2.0 + */ +typedef struct ImageNative_ ImageNative; + +/** + * @brief 图像格式枚举值。 + * + * @since 10 + * @version 2.0 + */ +enum { + /** YCBCR422 semi-planar 格式 */ + OHOS_IMAGE_FORMAT_YCBCR_422_SP = 1000, + /** JPEG 编码格式 */ + OHOS_IMAGE_FORMAT_JPEG = 2000 +}; + +/** + * @brief 图像组成类型枚举值。 + * + * @since 10 + * @version 2.0 + */ +enum { + /** 亮度信息 */ + OHOS_IMAGE_COMPONENT_FORMAT_YUV_Y = 1, + /** 色度信息 */ + OHOS_IMAGE_COMPONENT_FORMAT_YUV_U = 2, + /** 色差值信息 */ + OHOS_IMAGE_COMPONENT_FORMAT_YUV_V = 3, + /** Jpeg 格式 */ + OHOS_IMAGE_COMPONENT_FORMAT_JPEG = 4, +}; + +/** + * @brief 定义图像矩形信息。 + * + * @since 10 + * @version 2.0 + */ +struct OhosImageRect { + /** 矩形x坐标值 */ + int32_t x; + /** 矩形y坐标值 */ + int32_t y; + /** 矩形宽度值,用pixels表示 */ + int32_t width; + /** 矩形高度值,用pixels表示 */ + int32_t height; +}; + +/** + * @brief 定义图像组成信息。 + * + * @since 10 + * @version 2.0 + */ +struct OhosImageComponent { + /** 像素数据地址 */ + uint8_t* byteBuffer; + /** 内存中的像素数据大小 */ + size_t size; + /** 像素数据类型 */ + int32_t componentType; + /** 像素数据行宽 */ + int32_t rowStride; + /** 像素数据的像素大小 */ + int32_t pixelStride; +}; + +/** + * @brief 从输入的JavaScript Native API 图像 对象中解析 native {@link ImageNative} 对象。 + * + * @param env 表示指向 JNI 环境的指针。 + * @param source 表示 JavaScript Native API 图像 对象。 + * @return 如果操作成果返回 {@link ImageNative} 指针对象,如果操作失败返回空指针。 + * @see ImageNative, OH_Image_Release + * @since 10 + * @version 2.0 + */ +ImageNative* OH_Image_InitImageNative(napi_env env, napi_value source); + +/** + * @brief 获取native {@link ImageNative} 对象 {@link OhosImageRect} 信息。 + * + * @param native 表示指向 {@link ImageNative} native层对象的指针。 + * @param rect 表示作为转换结果的 {@link OhosImageRect} 对象指针。 + * @return 如果操作成功返回 {@link OHOS_IMAGE_RESULT_SUCCESS}; + * 如果操作失败返回其他的错误码。 + * @see ImageNative, OhosImageRect + * @since 10 + * @version 2.0 + */ +int32_t OH_Image_ClipRect(const ImageNative* native, struct OhosImageRect* rect); + +/** + * @brief 获取native {@link ImageNative} 对象的 {@link OhosImageSize} 信息。 + * + * @param native 表示 {@link ImageNative} native对象的指针。 + * @param size 表示作为转换结果的 {@link OhosImageSize} 对象的指针。 + * @return 如果操作成功返回 {@link OHOS_IMAGE_RESULT_SUCCESS}; + * 如果操作失败返回其他的错误码。 + * @see ImageNative, OhosImageSize + * @since 10 + * @version 2.0 + */ +int32_t OH_Image_Size(const ImageNative* native, struct OhosImageSize* size); + +/** + * @brief 获取native {@link ImageNative} 对象的图像格式。 + * + * @param native 表示 {@link ImageNative} native对象的指针。 + * @param format 表示作为转换结果的图像格式对象的指针。 + * @return 如果操作成功返回 {@link OHOS_IMAGE_RESULT_SUCCESS}; + * 如果操作失败返回其他的错误码。 + * @see ImageNative + * @since 10 + * @version 2.0 + */ +int32_t OH_Image_Format(const ImageNative* native, int32_t* format); + +/** + * @brief 从 native {@link ImageNative} 对象中获取 {@link OhosImageComponent}。 + * + * @param native 表示 {@link ImageNative} native对象的指针。 + * @param componentType 表示所需组件的组件类型。 + * @param componentNative 表示转换结果的 {@link OhosImageComponent} 对象的指针。 + * @return 如果操作成功返回 {@link OHOS_IMAGE_RESULT_SUCCESS}; + * 如果操作失败返回其他的错误码。 + * @see ImageNative, OhosImageComponent + * @since 10 + * @version 2.0 + */ +int32_t OH_Image_GetComponent(const ImageNative* native, + int32_t componentType, struct OhosImageComponent* componentNative); + +/** + * @brief 释放 {@link ImageNative} native对象。 + * Note: 这个方法无法释放 JavaScript Native API Image 对象, + * 而是释放被 {@link OH_Image_InitImageNative} 解析的 {@link ImageNative} native 对象。 + * + * @param native 表示 {@link ImageNative} native对象的指针。 + * @return 如果操作成功返回 {@link OHOS_IMAGE_RESULT_SUCCESS}; + * 如果操作失败返回其他的错误码。 + * @see ImageNative, OH_Image_InitImageNative + * @since 10 + * @version 2.0 + */ +int32_t OH_Image_Release(ImageNative* native); +#ifdef __cplusplus +}; +#endif +/** @} */ +} // namespace Media +} // namespace OHOS +#endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_MDK_H_ diff --git a/zh-cn/native_sdk/media/image/image_mdk_common.h b/zh-cn/native_sdk/media/image/image_mdk_common.h new file mode 100644 index 0000000000000000000000000000000000000000..140781c9480918c3fc1846c726422448686d97ee --- /dev/null +++ b/zh-cn/native_sdk/media/image/image_mdk_common.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup image + * @{ + * + * @brief 提供image接口的访问。 + * + * @Syscap SystemCapability.Multimedia.Image + * @since 10 + * @version 2.0 + */ + +/** + * @file image_mdk_common.h + * + * @brief 声明图像常用的枚举值和结构体。 + * + * @since 10 + * @version 2.0 + */ + +#ifndef INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_COMMON_H_ +#define INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_COMMON_H_ +namespace OHOS { +namespace Media { +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief 可能被使用的接口返回值的枚举。 + * + * @since 8 + * @version 1.0 + */ +enum { + /** 成功的结果 */ + OHOS_IMAGE_RESULT_SUCCESS = 0, + /** 无效参数 */ + OHOS_IMAGE_RESULT_BAD_PARAMETER = -1, +}; + +/** + * @brief Defines image size。 + * + * @since 10 + * @version 2.0 + */ +struct OhosImageSize { + /** 像素中的图像宽度,用pixels表示 */ + int32_t width; + /** 像素中的图像高度,用pixels表示 */ + int32_t height; +}; + +#ifdef __cplusplus +}; +#endif +/** @} */ +} // namespace Media +} // namespace OHOS +#endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_COMMON_H_ diff --git a/zh-cn/native_sdk/media/image/image_pixel_map_napi.h b/zh-cn/native_sdk/media/image/image_pixel_map_napi.h index 2ad0da78e33c2f9fffbdcc1064e0b4411ae17a72..f9403adfc5a09eafd6711c342999ab82a1241706 100644 --- a/zh-cn/native_sdk/media/image/image_pixel_map_napi.h +++ b/zh-cn/native_sdk/media/image/image_pixel_map_napi.h @@ -27,7 +27,7 @@ /** * @file image_pixel_map_napi.h * - * @brief 声明可以锁定并访问pixelmap数据的方法,声明解锁的方法. + * @brief 声明可以锁定并访问pixelmap数据的方法,声明解锁的方法。 * * @since 8 * @version 1.0 @@ -44,7 +44,7 @@ extern "C" { #endif /** - * @brief 函数方法返回值的错误码的枚举. + * @brief 函数方法返回值的错误码的枚举。 * * @since 8 * @version 1.0 @@ -57,7 +57,7 @@ enum { }; /** - * @brief pixel 格式的枚举. + * @brief pixel 格式的枚举。 * * @since 8 * @version 1.0 @@ -68,26 +68,26 @@ enum { */ OHOS_PIXEL_MAP_FORMAT_NONE = 0, /** - * 32-bit RGBA. 由 R, G, B组成,包括 A 都需要占用 8 bits。存储顺序是从高位到低位. + * 32-bit RGBA. 由 R, G, B组成,包括 A 都需要占用 8 bits。存储顺序是从高位到低位。 */ OHOS_PIXEL_MAP_FORMAT_RGBA_8888 = 3, /** - * 16-bit RGB. 仅由 R, G, B 组成. - * 存储顺序是从高位到低位: 红色占用5 bits,绿色占用6 bits,蓝色占用5 bits. + * 16-bit RGB. 仅由 R, G, B 组成。 + * 存储顺序是从高位到低位: 红色占用5 bits,绿色占用6 bits,蓝色占用5 bits。 */ OHOS_PIXEL_MAP_FORMAT_RGB_565 = 2, }; /** - * @brief 用于定义 pixel map 的相关信息. + * @brief 用于定义 pixel map 的相关信息。 * * @since 8 * @version 1.0 */ struct OhosPixelMapInfo { - /** 图片的宽, 用pixels表示. */ + /** 图片的宽, 用pixels表示 */ uint32_t width; - /** 图片的高, 用pixels表示. */ + /** 图片的高, 用pixels表示 */ uint32_t height; /** 每行的bytes数 */ uint32_t rowSize; @@ -96,21 +96,21 @@ struct OhosPixelMapInfo { }; /** - * @brief 用于定义 napi PixelMap 的相关信息. + * @brief 用于定义 napi PixelMap 的相关信息。 * @since 9 * @version 1.0 */ struct NativePixelMap; /** - * @brief 用于定义NativePixelMap数据类型名称. + * @brief 用于定义NativePixelMap数据类型名称。 * @since 9 * @version 1.0 */ typedef struct NativePixelMap NativePixelMap; /** - * @brief PixelMap alpha 类型的枚举. + * @brief PixelMap alpha 类型的枚举。 * * @since 9 * @version 1.0 @@ -135,7 +135,7 @@ enum { }; /** - * @brief PixelMap 缩放类型的枚举. + * @brief PixelMap 缩放类型的枚举。 * * @since 9 * @version 1.0 @@ -152,7 +152,7 @@ enum { }; /** - * @brief PixelMap 编辑类型的枚举. + * @brief PixelMap 编辑类型的枚举。 * * @since 9 * @version 1.0 @@ -169,33 +169,33 @@ enum { }; /** - * @brief 用于定义创建 pixel map 设置选项的相关信息. + * @brief 用于定义创建 pixel map 设置选项的相关信息。 * * @since 9 * @version 1.0 */ struct OhosPixelMapCreateOps { - /** 图片的宽, 用pixels表示. */ + /** 图片的宽, 用pixels表示 */ uint32_t width; - /** 图片的高, 用pixels表示. */ + /** 图片的高, 用pixels表示 */ uint32_t height; - /** 图片的格式. */ + /** 图片的格式 */ int32_t pixelFormat; - /** 图片的编辑类型. */ + /** 图片的编辑类型 */ uint32_t editable; - /** 图片的alpha类型. */ + /** 图片的alpha类型 */ uint32_t alphaType; - /** 图片的缩放类型. */ + /** 图片的缩放类型 */ uint32_t scaleMode; } /** - * @brief 获取 PixelMap 的信息,并记录信息到{@link OhosPixelMapInfo}结构中. + * @brief 获取 PixelMap 的信息,并记录信息到{@link OhosPixelMapInfo}结构中。 * - * @param env napi的环境指针. - * @param value 应用层的 PixelMap 对象. - * @param info 用于保存信息的指针对象. 更多细节, 参看 {@link OhosPixelMapInfo}. - * @return 如果获取并保存信息成功,则返回0; 如果操作失败,则返回错误码. + * @param env napi的环境指针。 + * @param value 应用层的 PixelMap 对象。 + * @param info 用于保存信息的指针对象。 更多细节, 参看 {@link OhosPixelMapInfo}。 + * @return 如果获取并保存信息成功,则返回0; 如果操作失败,则返回错误码。 * @see OhosPixelMapInfo * @since 8 * @version 1.0 @@ -203,27 +203,27 @@ struct OhosPixelMapCreateOps { int32_t OH_GetImageInfo(napi_env env, napi_value value, OhosPixelMapInfo *info); /** - * @brief 获取PixelMap对象数据的内存地址,并锁定该内存. + * @brief 获取PixelMap对象数据的内存地址,并锁定该内存。 * - * 函数执行成功后,*addrPtr就是获取的待访问的内存地址. 访问操作完成后,必须要使用{@link OH_UnAccessPixels}来释放锁, 否则的话资源无法被释放. - * 待解锁后,内存地址就不可以再被访问和操作. + * 函数执行成功后,*addrPtr就是获取的待访问的内存地址。访问操作完成后,必须要使用{@link OH_UnAccessPixels}来释放锁,否则的话资源无法被释放。 + * 待解锁后,内存地址就不可以再被访问和操作。 * - * @param env napi的环境指针. - * @param value 应用层的 PixelMap 对象. - * @param addrPtr 用于指向的内存地址的双指针对象. + * @param env napi的环境指针。 + * @param value 应用层的 PixelMap 对象。 + * @param addrPtr 用于指向的内存地址的双指针对象。 * @see UnAccessPixels - * @return 操作成功则返回 {@link OHOS_IMAGE_RESULT_SUCCESS}; 如果操作失败,则返回错误码. + * @return 操作成功则返回 {@link OHOS_IMAGE_RESULT_SUCCESS};如果操作失败,则返回错误码。 * @since 8 * @version 1.0 */ int32_t OH_AccessPixels(napi_env env, napi_value value, void** addrPtr); /** - * @brief 释放PixelMap对象数据的内存锁, 用于匹配方法{@link OH_AccessPixels}. + * @brief 释放PixelMap对象数据的内存锁, 用于匹配方法{@link OH_AccessPixels}。 * - * @param env napi的环境指针. - * @param value 应用层的 PixelMap 对象. - * @return 操作成功则返回 {@link OHOS_IMAGE_RESULT_SUCCESS}; 如果操作失败,则返回错误码. + * @param env napi的环境指针。 + * @param value 应用层的 PixelMap 对象。 + * @return 操作成功则返回 {@link OHOS_IMAGE_RESULT_SUCCESS};如果操作失败,则返回错误码。 * @see AccessPixels * @since 8 * @version 1.0 @@ -231,14 +231,14 @@ int32_t OH_AccessPixels(napi_env env, napi_value value, void** addrPtr); int32_t OH_UnAccessPixels(napi_env env, napi_value value); /** - * @brief 创建PixelMap对象. - * - * @param env napi的环境指针. - * @param info pixel map 数据设置项. - * @param buf 图片的buffer数据. - * @param len 图片大小信息. - * @param res 应用层的 PixelMap 对象的指针. - * @return 操作成功则返回 PixelMap 对象; 如果操作失败,则返回错误码. + * @brief 创建PixelMap对象。 + * + * @param env napi的环境指针。 + * @param info pixel map 数据设置项。 + * @param buf 图片的buffer数据。 + * @param len 图片大小信息。 + * @param res 应用层的 PixelMap 对象的指针。 + * @return 操作成功则返回 PixelMap 对象;如果操作失败,则返回错误码。 * @see CreatePixelMap * @since 9 * @version 1.0 @@ -247,12 +247,12 @@ int32_t OH_PixelMap_CreatePixelMap(napi_env env, OhosPixelMapCreateOps info, void* buf, size_t len, napi_value* res); /** - * @brief 根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的PixelMap对象. + * @brief 根据Alpha通道的信息,来生成一个仅包含Alpha通道信息的PixelMap对象。 * - * @param env napi的环境指针. - * @param source PixelMap数据设置项. - * @param alpha alpha通道的指针. - * @return 操作成功则返回 PixelMap 对象; 如果操作失败,则返回错误码. + * @param env napi的环境指针。 + * @param source PixelMap数据设置项。 + * @param alpha alpha通道的指针。 + * @return 操作成功则返回 PixelMap 对象;如果操作失败,则返回错误码。 * @see CreateAlphaPixelMap * @since 9 * @version 1.0 @@ -260,11 +260,11 @@ int32_t OH_PixelMap_CreatePixelMap(napi_env env, OhosPixelMapCreateOps info, int32_t OH_PixelMap_CreateAlphaPixelMap(napi_env env, napi_value source, napi_value* alpha); /** - * @brief 初始化PixelMap对象数据. + * @brief 初始化PixelMap对象数据。 * - * @param env napi的环境指针. - * @param source PixelMap 数据设置项. - * @return 操作成功则返回NativePixelMap的指针; 如果操作失败,则返回错误码. + * @param env napi的环境指针。 + * @param source PixelMap 数据设置项。 + * @return 操作成功则返回NativePixelMap的指针;如果操作失败,则返回错误码。 * @see InitNativePixelMap * @since 9 * @version 1.0 @@ -272,11 +272,11 @@ int32_t OH_PixelMap_CreateAlphaPixelMap(napi_env env, napi_value source, napi_va NativePixelMap* OH_PixelMap_InitNativePixelMap(napi_env env, napi_value source); /** - * @brief 获取PixelMap对象每行字节数. + * @brief 获取PixelMap对象每行字节数。 * - * @param native NativePixelMap的指针. - * @param num PixelMap对象的每行字节数指针. - * @return 操作成功则返回 PixelMap 对象每行字节数; 如果操作失败,则返回错误码. + * @param native NativePixelMap的指针。 + * @param num PixelMap对象的每行字节数指针。 + * @return 操作成功则返回 PixelMap 对象每行字节数;如果操作失败,则返回错误码。 * @see GetBytesNumberPerRow * @since 9 * @version 1.0 @@ -284,11 +284,11 @@ NativePixelMap* OH_PixelMap_InitNativePixelMap(napi_env env, napi_value source); int32_t OH_PixelMap_GetBytesNumberPerRow(const NativePixelMap* native, int32_t* num); /** - * @brief 获取PixelMap对象是否可编辑的状态. + * @brief 获取PixelMap对象是否可编辑的状态。 * - * @param native NativePixelMap的指针. - * @param editable PixelMap 对象是否可编辑的指针. - * @return 操作成功则返回编辑类型的枚举值; 如果操作失败,则返回错误码. + * @param native NativePixelMap的指针。 + * @param editable PixelMap 对象是否可编辑的指针。 + * @return 操作成功则返回编辑类型的枚举值;如果操作失败,则返回错误码。 * @see GetIsEditable * @since 9 * @version 1.0 @@ -296,11 +296,11 @@ int32_t OH_PixelMap_GetBytesNumberPerRow(const NativePixelMap* native, int32_t* int32_t OH_PixelMap_GetIsEditable(const NativePixelMap* native, int32_t* editable); /** - * @brief 获取PixelMap对象是否支持Alpha通道. + * @brief 获取PixelMap对象是否支持Alpha通道。 * - * @param native NativePixelMap的指针. - * @param alpha 是否支持Alpha的指针. - * @return 操作成功则返回0; 如果操作失败,则返回错误码. + * @param native NativePixelMap的指针。 + * @param alpha 是否支持Alpha的指针。 + * @return 操作成功则返回0;如果操作失败,则返回错误码。 * @see IsSupportAlpha * @since 9 * @version 1.0 @@ -308,11 +308,11 @@ int32_t OH_PixelMap_GetIsEditable(const NativePixelMap* native, int32_t* editabl int32_t OH_PixelMap_IsSupportAlpha(const NativePixelMap* native, int32_t* alpha); /** - * @brief 设置PixelMap对象的Alpha通道. + * @brief 设置PixelMap对象的Alpha通道。 * - * @param native NativePixelMap的指针. - * @param alpha Alpha通道. - * @return 操作成功则返回0; 如果操作失败,则返回错误码. + * @param native NativePixelMap的指针。 + * @param alpha Alpha通道。 + * @return 操作成功则返回0;如果操作失败,则返回错误码。 * @see SetAlphaAble * @since 9 * @version 1.0 @@ -320,11 +320,11 @@ int32_t OH_PixelMap_IsSupportAlpha(const NativePixelMap* native, int32_t* alpha) int32_t OH_PixelMap_SetAlphaAble(const NativePixelMap* native, int32_t alpha); /** - * @brief 获取PixelMap对象像素密度. + * @brief 获取PixelMap对象像素密度。 * - * @param native NativePixelMap的指针. - * @param density 像素密度指针. - * @return 操作成功则返回像素密度; 如果操作失败,则返回错误码. + * @param native NativePixelMap的指针。 + * @param density 像素密度指针。 + * @return 操作成功则返回像素密度;如果操作失败,则返回错误码。 * @see GetDensity * @since 9 * @version 1.0 @@ -332,11 +332,11 @@ int32_t OH_PixelMap_SetAlphaAble(const NativePixelMap* native, int32_t alpha); int32_t OH_PixelMap_GetDensity(const NativePixelMap* native, int32_t* density); /** - * @brief 设置PixelMap对象像素密度. + * @brief 设置PixelMap对象像素密度。 * - * @param native NativePixelMap的指针. - * @param density 像素密度. - * @return 操作成功则返回0; 如果操作失败,则返回错误码. + * @param native NativePixelMap的指针。 + * @param density 像素密度。 + * @return 操作成功则返回0;如果操作失败,则返回错误码。 * @see GetDensity * @since 9 * @version 1.0 @@ -344,11 +344,11 @@ int32_t OH_PixelMap_GetDensity(const NativePixelMap* native, int32_t* density); int32_t OH_PixelMap_SetDensity(const NativePixelMap* native, int32_t density); /** - * @brief 设置PixelMap对象的透明度. + * @brief 设置PixelMap对象的透明度。 * - * @param native NativePixelMap的指针. - * @param opacity 透明度. - * @return 操作成功则返回0; 如果操作失败,则返回错误码. + * @param native NativePixelMap的指针。 + * @param opacity 透明度。 + * @return 操作成功则返回0;如果操作失败,则返回错误码。 * @see SetOpacity * @since 9 * @version 1.0 @@ -356,12 +356,12 @@ int32_t OH_PixelMap_SetDensity(const NativePixelMap* native, int32_t density); int32_t OH_PixelMap_SetOpacity(const NativePixelMap* native, float opacity); /** - * @brief 设置PixelMap对象的缩放. + * @brief 设置PixelMap对象的缩放。 * - * @param native NativePixelMap的指针. - * @param x 缩放宽度. - * @param y 缩放高度. - * @return 操作成功则返回0; 如果操作失败,则返回错误码. + * @param native NativePixelMap的指针。 + * @param x 缩放宽度。 + * @param y 缩放高度。 + * @return 操作成功则返回0;如果操作失败,则返回错误码。 * @see Scale * @since 9 * @version 1.0 @@ -369,12 +369,12 @@ int32_t OH_PixelMap_SetOpacity(const NativePixelMap* native, float opacity); int32_t OH_PixelMap_Scale(const NativePixelMap* native, float x, float y); /** - * @brief 设置PixelMap对象的偏移. + * @brief 设置PixelMap对象的偏移。 * - * @param native NativePixelMap的指针. - * @param x 水平偏移量. - * @param y 垂直偏移量. - * @return 操作成功则返回0; 如果操作失败,则返回错误码. + * @param native NativePixelMap的指针。 + * @param x 水平偏移量。 + * @param y 垂直偏移量。 + * @return 操作成功则返回0;如果操作失败,则返回错误码。 * @see Translate * @since 9 * @version 1.0 @@ -382,11 +382,11 @@ int32_t OH_PixelMap_Scale(const NativePixelMap* native, float x, float y); int32_t OH_PixelMap_Translate(const NativePixelMap* native, float x, float y); /** - * @brief 设置PixelMap对象的旋转. + * @brief 设置PixelMap对象的旋转。 * - * @param native NativePixelMap的指针. - * @param angle 旋转角度. - * @return 操作成功则返回0; 如果操作失败,则返回错误码. + * @param native NativePixelMap的指针。 + * @param angle 旋转角度。 + * @return 操作成功则返回0;如果操作失败,则返回错误码。 * @see Rotate * @since 9 * @version 1.0 @@ -394,12 +394,12 @@ int32_t OH_PixelMap_Translate(const NativePixelMap* native, float x, float y); int32_t OH_PixelMap_Rotate(const NativePixelMap* native, float angle); /** - * @brief 设置PixelMap对象的翻转. + * @brief 设置PixelMap对象的翻转。 * - * @param native NativePixelMap的指针. - * @param x 根据水平方向x轴进行图片翻转. - * @param y 根据垂直方向y轴进行图片翻转. - * @return 操作成功则返回0; 如果操作失败,则返回错误码. + * @param native NativePixelMap的指针。 + * @param x 根据水平方向x轴进行图片翻转。 + * @param y 根据垂直方向y轴进行图片翻转。 + * @return 操作成功则返回0;如果操作失败,则返回错误码。 * @see Flip * @since 9 * @version 1.0 @@ -407,20 +407,55 @@ int32_t OH_PixelMap_Rotate(const NativePixelMap* native, float angle); int32_t OH_PixelMap_Flip(const NativePixelMap* native, int32_t x, int32_t y); /** - * @brief 设置PixelMap对象的裁剪. - * - * @param native NativePixelMap的指针. - * @param x 目标图片左上角的x坐标. - * @param y 目标图片左上角的y坐标. - * @param width 裁剪区域的宽度. - * @param height 裁剪区域的高度. - * @return 操作成功则返回0; 如果操作失败,则返回错误码. + * @brief 设置PixelMap对象的裁剪。 + * + * @param native NativePixelMap的指针。 + * @param x 目标图片左上角的x坐标。 + * @param y 目标图片左上角的y坐标。 + * @param width 裁剪区域的宽度。 + * @param height 裁剪区域的高度。 + * @return 操作成功则返回0;如果操作失败,则返回错误码。 * @see Crop * @since 9 * @version 1.0 */ int32_t OH_PixelMap_Crop(const NativePixelMap* native, int32_t x, int32_t y, int32_t width, int32_t height); +/** + * @brief 获取PixelMap对象图像信息。 + * + * @param native NativePixelMap的指针。 + * @param info 图像信息指针。 + * @return 操作成功则返回0;如果操作失败,则返回错误码。 + * @see OhosPixelMapInfo + * @since 9 + * @version 1.0 + */ +int32_t OH_PixelMap_GetImageInfo(const NativePixelMap* native, OhosPixelMapInfo *info); + +/** + * @brief 获取native PixelMap 对象数据的内存地址,并锁定该内存。 + * + * @param native NativePixelMap的指针。 + * @param addr 用于指向的内存地址的双指针对象。 + * @see UnAccessPixels + * @return 操作成功则返回 {@link OHOS_IMAGE_RESULT_SUCCESS};如果操作失败,则返回错误码。 + * @since 8 + * @version 1.0 + */ +int32_t OH_PixelMap_AccessPixels(const NativePixelMap* native, void** addr); + +/** + * @brief 释放native PixelMap对象数据的内存锁,用于匹配方法{@link OH_PixelMap_AccessPixels}。 + * + * @param native NativePixelMap的指针。 + * @return 操作成功则返回 {@link OHOS_IMAGE_RESULT_SUCCESS};如果操作失败,则返回错误码。 + * @see AccessPixels + * @since 8 + * @version 1.0 + */ +int32_t OH_PixelMap_UnAccessPixels(const NativePixelMap* native); + #ifdef __cplusplus }; #endif diff --git a/zh-cn/native_sdk/media/image/image_receiver_mdk.h b/zh-cn/native_sdk/media/image/image_receiver_mdk.h new file mode 100644 index 0000000000000000000000000000000000000000..2725b866d57c52e80093af920a6e4fb374410e7e --- /dev/null +++ b/zh-cn/native_sdk/media/image/image_receiver_mdk.h @@ -0,0 +1,217 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup image + * @{ + * + * @brief 提供从native层获取图片数据的方法。 + * + * @Syscap SystemCapability.Multimedia.Image + * @since 10 + * @version 2.0 + */ + +/** + * @file image_receiver_mdk.h + * + * @brief 声明从native层获取图片数据的方法。 + * + * @since 10 + * @version 2.0 + */ + +#ifndef INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_RECEIVER_MDK_H_ +#define INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_RECEIVER_MDK_H_ +#include +#include "napi/native_api.h" +#include "image_mdk_common.h" +#include "image_mdk.h" + +namespace OHOS { +namespace Media { +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief 定义native层ImageReceiver对象。 + * + * @since 10 + * @version 2.0 + */ +struct ImageReceiverNative_; + +/** + * @brief 用于定义ImageReceiverNative数据类型名称。 + * + * @since 10 + * @version 2.0 + */ +typedef struct ImageReceiverNative_ ImageReceiverNative; + +/** + * @brief 定义native层图片的回调方法。 + * + * @since 10 + * @version 2.0 + */ +typedef void (*OH_Image_Receiver_On_Callback)(); + +/** + * @brief 定义ImageReceiver的相关信息。 + * + * @since 10 + * @version 2.0 + */ +struct OhosImageReceiverInfo { + /* 消费端接收图片时的默认图像宽度,用pixels表示 */ + int32_t width; + /* 消费端接收图片时的默认图像高度,用pixels表示 */ + int32_t height; + /* 通过接收器创建图像格式{@link OHOS_IMAGE_FORMAT_JPEG} */ + int32_t format; + /* 图片缓存数量的最大值 */ + int32_t capicity; +}; + +/** + * @brief 创建应用层 ImageReceiver 对象。 + * + * @param env napi的环境指针。 + * @param info ImageReceiver 数据设置项。 + * @param res 应用层的 ImageReceiver 对象的指针。 + * @return 操作成功则返回 {@link OHOS_IMAGE_RESULT_SUCCESS};如果操作失败,则返回错误码。 + * @see OhosImageReceiverInfo + * @since 10 + * @version 2.0 + */ +int32_t OH_Image_Receiver_CreateImageReceiver(napi_env env, struct OhosImageReceiverInfo info, napi_value* res); + +/** + * @brief 通过应用层ImageReceiver对象初始化native层{@link ImageReceiverNative}对象。 + * + * @param env napi的环境指针。 + * @param source napi的 ImageReceiver 对象。 + * @return 操作成功则返回 {@link ImageReceiverNative} 指针;如果操作失败,则返回nullptr。 + * @see ImageReceiverNative, OH_Image_Receiver_Release + * @since 10 + * @version 2.0 + */ +ImageReceiverNative* OH_Image_Receiver_InitImageReceiverNative(napi_env env, napi_value source); + +/** + * @brief 通过{@link ImageReceiverNative}获取receiver的id。 + * + * @param native native层的{@link ImageReceiverNative}指针。 + * @param id 指向字符缓冲区的指针,用于获取字符串的id。 + * @param len id所对应的字符缓冲区的大小。 + * @return 操作成功则返回 {@link OHOS_IMAGE_RESULT_SUCCESS};如果操作失败,则返回错误码。 + * @see ImageReceiverNative + * @since 10 + * @version 2.0 + */ +int32_t OH_Image_Receiver_GetReceivingSurfaceId(const ImageReceiverNative* native, char* id, size_t len); + +/** + * @brief 通过{@link ImageReceiverNative}获取最新的一张图片。 + * + * @param native native层的{@link ImageReceiverNative}指针。 + * @param image 获取到的应用层的 Image 指针对象。 + * @return 操作成功则返回 {@link OHOS_IMAGE_RESULT_SUCCESS};如果操作失败,则返回错误码。 + * @see ImageReceiverNative + * @since 10 + * @version 2.0 + */ +int32_t OH_Image_Receiver_ReadLatestImage(const ImageReceiverNative* native, napi_value* image); + +/** + * @brief 通过{@link ImageReceiverNative}获取下一张图片。 + * + * @param native native层的{@link ImageReceiverNative}指针。 + * @param image 读取到的应用层的 Image 指针对象。 + * @return 操作成功则返回 {@link OHOS_IMAGE_RESULT_SUCCESS};如果操作失败,则返回错误码。 + * @see ImageReceiverNative + * @since 10 + * @version 2.0 + */ +int32_t OH_Image_Receiver_ReadNextImage(const ImageReceiverNative* native, napi_value* image); + +/** + * @brief 注册一个{@link OH_Image_Receiver_On_Callback}回调事件。每当接收新图片,该回调事件就会响应。 + * + * @param native native层的{@link ImageReceiverNative}指针。 + * @param callback {@link OH_Image_Receiver_On_Callback}事件的回调函数。 + * @return 操作成功则返回 {@link OHOS_IMAGE_RESULT_SUCCESS};如果操作失败,则返回错误码。 + * @see ImageReceiverNative + * @since 10 + * @version 2.0 + */ +int32_t OH_Image_Receiver_On(const ImageReceiverNative* native, OH_Image_Receiver_On_Callback callback); + +/** + * @brief 通过{@link ImageReceiverNative}获取ImageReceiver的大小。 + * + * @param native native层的{@link ImageReceiverNative}指针。 + * @param size 作为结果的{@link OhosImageSize}指针。 + * @return 操作成功则返回 {@link OHOS_IMAGE_RESULT_SUCCESS};如果操作失败,则返回错误码。 + * @see ImageReceiverNative, OH_Image_Receiver_On_Callback + * @since 10 + * @version 2.0 + */ +int32_t OH_Image_Receiver_GetSize(const ImageReceiverNative* native, struct OhosImageSize* size); + +/** + * @brief 通过{@link ImageReceiverNative}获取ImageReceiver的容量。 + * + * @param native native层的{@link ImageReceiverNative}指针。 + * @param capacity 作为结果的指向容量的指针。 + * @return 操作成功则返回 {@link OHOS_IMAGE_RESULT_SUCCESS};如果操作失败,则返回错误码。 + * @see ImageReceiverNative, OhosImageSize + * @since 10 + * @version 2.0 + */ +int32_t OH_Image_Receiver_GetCapacity(const ImageReceiverNative* native, int32_t* capacity); + +/** + * @brief 通过{@link ImageReceiverNative}获取ImageReceiver的格式。 + * + * @param native native层的{@link ImageReceiverNative}指针。 + * @param format 作为结果的指向格式的指针。 + * @return 操作成功则返回 {@link OHOS_IMAGE_RESULT_SUCCESS};如果操作失败,则返回错误码。 + * @see ImageReceiverNative + + * @since 10 + * @version 2.0 + */ +int32_t OH_Image_Receiver_GetFormat(const ImageReceiverNative* native, int32_t* format); + +/** + * @brief 释放native层 {@link ImageReceiverNative} 对象。注意: 此方法不能释放应用层ImageReceiver对象。 + * + * @param native native层的{@link ImageReceiverNative}指针。 + * @return 操作成功则返回 {@link OHOS_IMAGE_RESULT_SUCCESS};如果操作失败,则返回错误码。 + * @see ImageReceiverNative + * @since 10 + * @version 2.0 + */ +int32_t OH_Image_Receiver_Release(ImageReceiverNative* native); +#ifdef __cplusplus +}; +#endif +/** @} */ +} // namespace Media +} // namespace OHOS +#endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_RECEIVER_MDK_H_