From 78f98df1531864125b706ebe1c32104557cad07e Mon Sep 17 00:00:00 2001 From: yangfan Date: Mon, 13 Nov 2023 19:34:55 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ImagePacker=20NDK?= =?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: yangfan --- 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..258533ca7 --- /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 ImagePackerNative} object at the native layer. + * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. + * @see {@link OH_ImagePacker_InitNative} + * @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 From 95e5ea876c0d725340e252b2f7bc0798367a3c2f Mon Sep 17 00:00:00 2001 From: yangfan Date: Tue, 14 Nov 2023 14:14:50 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangfan --- multimedia/image_framework/include/image_packer_mdk.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/multimedia/image_framework/include/image_packer_mdk.h b/multimedia/image_framework/include/image_packer_mdk.h index 258533ca7..dadf221ad 100644 --- a/multimedia/image_framework/include/image_packer_mdk.h +++ b/multimedia/image_framework/include/image_packer_mdk.h @@ -21,7 +21,7 @@ * * 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 */ -- Gitee From 910da9ab63e09de21b0637caaf503406e7679920 Mon Sep 17 00:00:00 2001 From: yangfan Date: Tue, 14 Nov 2023 19:40:24 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0first=5Fintroduced?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangfan --- multimedia/image_framework/libimage_packer_ndk.ndk.json | 1 + 1 file changed, 1 insertion(+) diff --git a/multimedia/image_framework/libimage_packer_ndk.ndk.json b/multimedia/image_framework/libimage_packer_ndk.ndk.json index cb9b31730..50a496091 100644 --- a/multimedia/image_framework/libimage_packer_ndk.ndk.json +++ b/multimedia/image_framework/libimage_packer_ndk.ndk.json @@ -1,5 +1,6 @@ [ { + "first_introduced": "11", "name": "OH_ImagePacker_Create" }, { -- Gitee From 40bd2d806c3085430334d63573b47705260c5eda Mon Sep 17 00:00:00 2001 From: yangfan Date: Wed, 15 Nov 2023 19:52:10 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0first=5Fintroduced=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangfan --- multimedia/image_framework/libimage_packer_ndk.ndk.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/multimedia/image_framework/libimage_packer_ndk.ndk.json b/multimedia/image_framework/libimage_packer_ndk.ndk.json index 50a496091..6a4b55b61 100644 --- a/multimedia/image_framework/libimage_packer_ndk.ndk.json +++ b/multimedia/image_framework/libimage_packer_ndk.ndk.json @@ -4,15 +4,19 @@ "name": "OH_ImagePacker_Create" }, { + "first_introduced": "11", "name": "OH_ImagePacker_InitNative" }, { + "first_introduced": "11", "name": "OH_ImagePacker_PackToData" }, { + "first_introduced": "11", "name": "OH_ImagePacker_PackToFile" }, { + "first_introduced": "11", "name": "OH_ImagePacker_Release" } ] \ No newline at end of file -- Gitee From 3ee2ace9913f2009fb322edec457cc4775badac7 Mon Sep 17 00:00:00 2001 From: yangfan Date: Thu, 16 Nov 2023 10:52:53 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E7=BB=93=E6=9E=84=E4=BD=93=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E8=A7=84=E8=8C=83=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangfan --- .../include/image_packer_mdk.h | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/multimedia/image_framework/include/image_packer_mdk.h b/multimedia/image_framework/include/image_packer_mdk.h index dadf221ad..0bda67058 100644 --- a/multimedia/image_framework/include/image_packer_mdk.h +++ b/multimedia/image_framework/include/image_packer_mdk.h @@ -55,7 +55,7 @@ extern "C" { #endif -struct ImagePackerNative_; +struct ImagePacker_Native_; /** * @brief Defines an image packer object at the native layer for the image packer interface. @@ -63,7 +63,7 @@ struct ImagePackerNative_; * @since 11 * @version 4.1 */ -typedef struct ImagePackerNative_ ImagePackerNative; +typedef struct ImagePacker_Native_ ImagePacker_Native; /** * @brief Defines the image packing options. @@ -71,13 +71,21 @@ typedef struct ImagePackerNative_ ImagePackerNative; * @since 11 * @version 4.1 */ -struct OhosImagePackerOpts { +struct ImagePacker_Opts_ { /** Encoding format. */ const char* format; /** Encoding quality. */ int quality; }; +/** + * @brief Defines alias of image packing options. + * + * @since 11 + * @version 4.1 + */ +typedef struct ImagePacker_Opts_ ImagePacker_Opts; + /** * @brief Creates an ImagePacker object at the JavaScript native layer. * @@ -93,25 +101,25 @@ struct OhosImagePackerOpts { int32_t OH_ImagePacker_Create(napi_env env, napi_value *res); /** - * @brief Parses an {@link ImagePackerNative} object at the native layer + * @brief Parses an {@link ImagePacker_Native} 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 + * @return Returns an {@link ImagePacker_Native} 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); +ImagePacker_Native* 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 opts Indicates the encoding {@link ImagePacker_Opts} . * @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. @@ -125,15 +133,15 @@ ImagePackerNative* OH_ImagePacker_InitNative(napi_env env, napi_value packer); * @since 11 * @version 4.1 */ -int32_t OH_ImagePacker_PackToData(ImagePackerNative* native, napi_value source, - struct OhosImagePackerOpts* opts, uint8_t* outData, size_t* size); +int32_t OH_ImagePacker_PackToData(ImagePacker_Native* native, napi_value source, + ImagePacker_Opts* 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 opts Indicates the encoding {@link ImagePacker_Opts} . * @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. @@ -146,23 +154,23 @@ int32_t OH_ImagePacker_PackToData(ImagePackerNative* native, napi_value source, * @since 11 * @version 4.1 */ -int32_t OH_ImagePacker_PackToFile(ImagePackerNative* native, napi_value source, - struct OhosImagePackerOpts* opts, int fd); +int32_t OH_ImagePacker_PackToFile(ImagePacker_Native* native, napi_value source, + ImagePacker_Opts* opts, int fd); /** - * @brief Releases an {@link ImagePackerNative} object at the native layer. + * @brief Releases an {@link ImagePacker_Native} 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 + * It is used to release the object {@link ImagePacker_Native} at the native layer * parsed by calling {@link OH_ImagePacker_InitNative}. * - * @param native Indicates the pointer to an {@link ImagePackerNative} object at the native layer. + * @param native Indicates the pointer to an {@link ImagePacker_Native} object at the native layer. * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. * @see {@link OH_ImagePacker_InitNative} * @since 11 * @version 4.1 */ -int32_t OH_ImagePacker_Release(ImagePackerNative* native); +int32_t OH_ImagePacker_Release(ImagePacker_Native* native); #ifdef __cplusplus }; #endif -- Gitee From 0937882c8baabe20c6e43a0a421d31bdb5993fd6 Mon Sep 17 00:00:00 2001 From: yangfan Date: Thu, 16 Nov 2023 14:18:41 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangfan --- multimedia/image_framework/include/image_packer_mdk.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multimedia/image_framework/include/image_packer_mdk.h b/multimedia/image_framework/include/image_packer_mdk.h index 0bda67058..0a49718d7 100644 --- a/multimedia/image_framework/include/image_packer_mdk.h +++ b/multimedia/image_framework/include/image_packer_mdk.h @@ -35,10 +35,10 @@ * * 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. + * And then covert the image packer object to ImagePacker_Native 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. + * Finally, release the ImagePacker_Native by OH_ImagePacker_Release. * * @library libimage_packer_ndk.z.so * @syscap SystemCapability.Multimedia.Image -- Gitee