From ac511484a22821cdec7b0224d84defd9e3b1cec1 Mon Sep 17 00:00:00 2001 From: Cao Chuan Date: Tue, 17 Oct 2023 16:37:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EImagePacker=E7=9A=84NDK?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yang Fan --- multimedia/image_framework/BUILD.gn | 10 ++ .../include/image_packer_mdk.h | 170 ++++++++++++++++++ .../libimage_packer_ndk.ndk.json | 17 ++ 3 files changed, 197 insertions(+) create mode 100644 multimedia/image_framework/include/image_packer_mdk.h create mode 100644 multimedia/image_framework/libimage_packer_ndk.ndk.json diff --git a/multimedia/image_framework/BUILD.gn b/multimedia/image_framework/BUILD.gn index 833b5fb73..22c7d1fb9 100644 --- a/multimedia/image_framework/BUILD.gn +++ b/multimedia/image_framework/BUILD.gn @@ -62,3 +62,13 @@ ohos_ndk_headers("image_source_ndk_header") { dest_dir = "$ndk_headers_out_dir/multimedia/image_framework" sources = [ "./include/image_source_mdk.h" ] } + +ohos_ndk_library("libimage_packer_ndk") { + ndk_description_file = "./libimage_packer_ndk.ndk.json" + output_name = "image_packer_ndk" +} + +ohos_ndk_headers("image_packer_ndk_header") { + dest_dir = "$ndk_headers_out_dir/multimedia/image_framework" + sources = [ "./include/image_packer_mdk.h" ] +} diff --git a/multimedia/image_framework/include/image_packer_mdk.h b/multimedia/image_framework/include/image_packer_mdk.h new file mode 100644 index 000000000..5b9564707 --- /dev/null +++ b/multimedia/image_framework/include/image_packer_mdk.h @@ -0,0 +1,170 @@ +/* + * 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 Provides native APIs for encoding image data + * + * The encoding image data module part of image module. + * It used to pack pixel data infomation into a target like data or file. + * + * @since 11 + * @version 4.1 + */ + +/** + * @file image_packer_mdk.h + * + * @brief Declares APIs for encoding image into data or file. + * + * The packing image data module used to pack pixel data into a target. + * + * The following steps are recommended for packing process: + * Create a image packer object by calling OH_ImagePacker_Create function. + * And then covert the image packer object to ImagePakcerNative by OH_ImagePacker_InitNative. + * Next using OH_ImagePacker_PackToData or OH_ImagePacker_PackToFile to pack source to target area with + * requird packing options. + * Finally, release the ImagePakcerNative by OH_ImagePacker_Release. + * + * @library libimage_packer_ndk.z.so + * @syscap SystemCapability.Multimedia.Image + * @since 11 + * @version 4.1 + */ + +#ifndef INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PACKER_MDK_H_ +#define INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PACKER_MDK_H_ +#include "napi/native_api.h" +#include "image_mdk_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct ImagePackerNative_; + +/** + * @brief Defines an image packer object at the native layer for the image packer interface. + * + * @since 11 + * @version 4.1 + */ +typedef struct ImagePackerNative_ ImagePackerNative; + +/** + * @brief Defines the image packing options. + * + * @since 11 + * @version 4.1 + */ +struct OhosImagePackerOpts { + /** Encoding format. */ + const char* format; + /** Encoding quality. */ + int quality; +}; + +/** + * @brief Creates an ImagePacker object at the JavaScript native layer. + * + * @param env Indicates a pointer to the JavaScript Native Interface (JNI) environment. + * @param res Indicates a pointer to the ImagePacker object created at the JavaScript native layer. + * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. + * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. + * + * @Syscap SystemCapability.Multimedia.Image + * @since 11 + * @version 4.1 + */ +int32_t OH_ImagePacker_Create(napi_env env, napi_value *res); + +/** + * @brief Parses an {@link ImagePackerNative} object at the native layer + * from a JavaScript native API ImagePacker object. + * + * @param env Indicates the pointer to the JavaScript Native Interface (JNI) environment. + * @param packer Indicates a JavaScript native API ImagePacker object. + * @return Returns an {@link ImagePackerNative} pointer object if the operation is successful + * returns a null pointer otherwise. + * @see {@link OH_ImagePacker_Release} + * @since 11 + * @version 4.1 + */ +ImagePackerNative* OH_ImagePacker_InitNative(napi_env env, napi_value packer); + +/** + * @brief Encoding an ImageSource or a PixelMap into the data with required format + * + * @param native Indicates the pointer to an {@link ImagePacker} object at the native layer. + * @param source Indicates an encoding source, a JS pixel map object or a JS image source object . + * @param opts Indicates the encoding {@link OhosImagePackerOpts} . + * @param outData Indicates the pointer to the encoded data. + * @param size Indicates the pointer to the {@link OhosImageComponent} object obtained. + * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. + * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. + * returns {@link IRNdkErrCode} ERR_IMAGE_DATA_ABNORMAL - if output target abnormal + * returns {@link IRNdkErrCode} ERR_IMAGE_MISMATCHED_FORMAT - if format mismatched + * returns {@link IRNdkErrCode} ERR_IMAGE_MALLOC_ABNORMAL - if malloc internal buffer error + * returns {@link IRNdkErrCode} ERR_IMAGE_DECODE_ABNORMAL - if init codec internal error + * returns {@link IRNdkErrCode} ERR_IMAGE_ENCODE_FAILED - if encoder occur error during encoding + * @see {@link OH_ImagePacker_PackToFile} + * @since 11 + * @version 4.1 + */ +int32_t OH_ImagePacker_PackToData(ImagePackerNative* native, napi_value source, + struct OhosImagePackerOpts* opts, uint8_t* outData, size_t* size); + +/** + * @brief Encoding an ImageSource or a PixelMap into the a file with fd with required format + * + * @param native Indicates the pointer to an {@link ImagePacker} object at the native layer. + * @param source Indicates an encoding source, a JS pixel map object or a JS image source object . + * @param opts Indicates the encoding {@link OhosImagePackerOpts} . + * @param fd Indicates the a writable file descriptor. + * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. + * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. + * returns {@link IRNdkErrCode} ERR_IMAGE_DATA_ABNORMAL - if output target abnormal + * returns {@link IRNdkErrCode} ERR_IMAGE_MISMATCHED_FORMAT - if format mismatched + * returns {@link IRNdkErrCode} ERR_IMAGE_MALLOC_ABNORMAL - if malloc internal buffer error + * returns {@link IRNdkErrCode} ERR_IMAGE_DECODE_ABNORMAL - if init codec internal error + * returns {@link IRNdkErrCode} ERR_IMAGE_ENCODE_FAILED - if encoder occur error during encoding + * @see {@link OH_ImagePacker_PackToData} + * @since 11 + * @version 4.1 + */ +int32_t OH_ImagePacker_PackToFile(ImagePackerNative* native, napi_value source, + struct OhosImagePackerOpts* opts, int fd); + + +/** + * @brief Releases an {@link ImagePackerNative} object at the native layer. + * Note: This API is not used to release a JavaScript native API ImagePacker object. + * It is used to release the object {@link ImagePackerNative} at the native layer + * parsed by calling {@link OH_ImagePacker_InitNative}. + * + * @param native Indicates the pointer to an {@link ImageNative} object at the native layer. + * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. + * @see {@link OH_Image_InitImageNative} + * @since 11 + * @version 4.1 + */ +int32_t OH_ImagePacker_Release(ImagePackerNative* native); +#ifdef __cplusplus +}; +#endif +/** @} */ +#endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PACKER_MDK_H_ diff --git a/multimedia/image_framework/libimage_packer_ndk.ndk.json b/multimedia/image_framework/libimage_packer_ndk.ndk.json new file mode 100644 index 000000000..cb9b31730 --- /dev/null +++ b/multimedia/image_framework/libimage_packer_ndk.ndk.json @@ -0,0 +1,17 @@ +[ + { + "name": "OH_ImagePacker_Create" + }, + { + "name": "OH_ImagePacker_InitNative" + }, + { + "name": "OH_ImagePacker_PackToData" + }, + { + "name": "OH_ImagePacker_PackToFile" + }, + { + "name": "OH_ImagePacker_Release" + } +] \ No newline at end of file -- Gitee