1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup image 18 * @{ 19 * 20 * @brief Provides native APIs for encoding image data 21 * 22 * The encoding image data module part of image module. 23 * It used to pack pixel data infomation into a target like data or file. 24 * 25 * @since 11 26 * @version 4.1 27 */ 28 29 /** 30 * @file image_packer_mdk.h 31 * 32 * @brief Declares APIs for encoding image into data or file. 33 * 34 * The packing image data module used to pack pixel data into a target. 35 * 36 * The following steps are recommended for packing process: 37 * Create a image packer object by calling OH_ImagePacker_Create function. 38 * And then covert the image packer object to ImagePacker_Native by OH_ImagePacker_InitNative. 39 * Next using OH_ImagePacker_PackToData or OH_ImagePacker_PackToFile to pack source to target area with 40 * requird packing options. 41 * Finally, release the ImagePacker_Native by OH_ImagePacker_Release. 42 * 43 * @library libimage_packer_ndk.z.so 44 * @syscap SystemCapability.Multimedia.Image 45 * @since 11 46 * @version 4.1 47 */ 48 49 #ifndef INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PACKER_MDK_H 50 #define INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PACKER_MDK_H 51 #include "napi/native_api.h" 52 #include "image_mdk_common.h" 53 54 #ifdef __cplusplus 55 extern "C" { 56 #endif 57 58 struct ImagePacker_Native_; 59 60 /** 61 * @brief Defines an image packer object at the native layer for the image packer interface. 62 * 63 * @since 11 64 * @version 4.1 65 */ 66 typedef struct ImagePacker_Native_ ImagePacker_Native; 67 68 /** 69 * @brief Defines the image packing options. 70 * 71 * @since 11 72 * @version 4.1 73 */ 74 struct ImagePacker_Opts_ { 75 /** Encoding format. */ 76 const char* format; 77 /** Encoding quality. */ 78 int quality; 79 }; 80 81 /** 82 * @brief Defines alias of image packing options. 83 * 84 * @since 11 85 * @version 4.1 86 */ 87 typedef struct ImagePacker_Opts_ ImagePacker_Opts; 88 89 /** 90 * @brief Creates an <b>ImagePacker</b> object at the JavaScript native layer. 91 * 92 * @param env Indicates a pointer to the JavaScript Native Interface (JNI) environment. 93 * @param res Indicates a pointer to the <b>ImagePacker</b> object created at the JavaScript native layer. 94 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 95 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 96 * 97 * @Syscap SystemCapability.Multimedia.Image 98 * @since 11 99 * @version 4.1 100 */ 101 int32_t OH_ImagePacker_Create(napi_env env, napi_value *res); 102 103 /** 104 * @brief Parses an {@link ImagePacker_Native} object at the native layer 105 * from a JavaScript native API <b>ImagePacker</b> object. 106 * 107 * @param env Indicates the pointer to the JavaScript Native Interface (JNI) environment. 108 * @param packer Indicates a JavaScript native API <b>ImagePacker</b> object. 109 * @return Returns an {@link ImagePacker_Native} pointer object if the operation is successful 110 * returns a null pointer otherwise. 111 * @see {@link OH_ImagePacker_Release} 112 * @since 11 113 * @version 4.1 114 */ 115 ImagePacker_Native* OH_ImagePacker_InitNative(napi_env env, napi_value packer); 116 117 /** 118 * @brief Encoding an <b>ImageSource</b> or a <b>PixelMap</b> into the data with required format 119 * 120 * @param native Indicates the pointer to an {@link ImagePacker} object at the native layer. 121 * @param source Indicates an encoding source, a JS pixel map object or a JS image source object . 122 * @param opts Indicates the encoding {@link ImagePacker_Opts} . 123 * @param outData Indicates the pointer to the encoded data. 124 * @param size Indicates the pointer to the {@link OhosImageComponent} object obtained. 125 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 126 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 127 * returns {@link IRNdkErrCode} ERR_IMAGE_DATA_ABNORMAL - if output target abnormal 128 * returns {@link IRNdkErrCode} ERR_IMAGE_MISMATCHED_FORMAT - if format mismatched 129 * returns {@link IRNdkErrCode} ERR_IMAGE_MALLOC_ABNORMAL - if malloc internal buffer error 130 * returns {@link IRNdkErrCode} ERR_IMAGE_DECODE_ABNORMAL - if init codec internal error 131 * returns {@link IRNdkErrCode} ERR_IMAGE_ENCODE_FAILED - if encoder occur error during encoding 132 * @see {@link OH_ImagePacker_PackToFile} 133 * @since 11 134 * @version 4.1 135 */ 136 int32_t OH_ImagePacker_PackToData(ImagePacker_Native* native, napi_value source, 137 ImagePacker_Opts* opts, uint8_t* outData, size_t* size); 138 139 /** 140 * @brief Encoding an <b>ImageSource</b> or a <b>PixelMap</b> into the a file with fd with required format 141 * 142 * @param native Indicates the pointer to an {@link ImagePacker} object at the native layer. 143 * @param source Indicates an encoding source, a JS pixel map object or a JS image source object . 144 * @param opts Indicates the encoding {@link ImagePacker_Opts} . 145 * @param fd Indicates the a writable file descriptor. 146 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 147 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 148 * returns {@link IRNdkErrCode} ERR_IMAGE_DATA_ABNORMAL - if output target abnormal 149 * returns {@link IRNdkErrCode} ERR_IMAGE_MISMATCHED_FORMAT - if format mismatched 150 * returns {@link IRNdkErrCode} ERR_IMAGE_MALLOC_ABNORMAL - if malloc internal buffer error 151 * returns {@link IRNdkErrCode} ERR_IMAGE_DECODE_ABNORMAL - if init codec internal error 152 * returns {@link IRNdkErrCode} ERR_IMAGE_ENCODE_FAILED - if encoder occur error during encoding 153 * @see {@link OH_ImagePacker_PackToData} 154 * @since 11 155 * @version 4.1 156 */ 157 int32_t OH_ImagePacker_PackToFile(ImagePacker_Native* native, napi_value source, 158 ImagePacker_Opts* opts, int fd); 159 160 /** 161 * @brief Releases an {@link ImagePacker_Native} object at the native layer. 162 * Note: This API is not used to release a JavaScript native API <b>ImagePacker</b> object. 163 * It is used to release the object {@link ImagePacker_Native} at the native layer 164 * parsed by calling {@link OH_ImagePacker_InitNative}. 165 * 166 * @param native Indicates the pointer to an {@link ImagePacker_Native} object at the native layer. 167 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 168 * @see {@link OH_ImagePacker_InitNative} 169 * @since 11 170 * @version 4.1 171 */ 172 int32_t OH_ImagePacker_Release(ImagePacker_Native* native); 173 #ifdef __cplusplus 174 }; 175 #endif 176 /** @} */ 177 #endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PACKER_MDK_H 178