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 APIs for access to the image interface. 21 * 22 * @syscap SystemCapability.Multimedia.Image.Core 23 * @since 10 24 * @version 2.0 25 */ 26 27 /** 28 * @file image_mdk.h 29 * 30 * @brief Declares functions that access the image rectangle, size, format, and component data. 31 * Need link <b>libimagendk.z.so</b> 32 * 33 * @library libimage_ndk.z.so 34 * @kit ImageKit 35 * @syscap SystemCapability.Multimedia.Image.Core 36 * @since 10 37 * @version 2.0 38 */ 39 40 #ifndef INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_MDK_H_ 41 #define INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_MDK_H_ 42 #include "napi/native_api.h" 43 #include "image_mdk_common.h" 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 struct ImageNative_; 50 51 /** 52 * @brief Defines an image object at the native layer for the image interface. 53 * 54 * @since 10 55 * @version 2.0 56 */ 57 typedef struct ImageNative_ ImageNative; 58 59 /** 60 * @brief Enumerates the image formats. 61 * 62 * @since 10 63 * @version 2.0 64 */ 65 enum { 66 /** YCbCr422 semi-planar format. */ 67 OHOS_IMAGE_FORMAT_YCBCR_422_SP = 1000, 68 /** JPEG encoding format. */ 69 OHOS_IMAGE_FORMAT_JPEG = 2000 70 }; 71 72 /** 73 * @brief Enumerates the image components. 74 * 75 * @since 10 76 * @version 2.0 77 */ 78 enum { 79 /** Luminance component. */ 80 OHOS_IMAGE_COMPONENT_FORMAT_YUV_Y = 1, 81 /** Chrominance component - blue projection. */ 82 OHOS_IMAGE_COMPONENT_FORMAT_YUV_U = 2, 83 /** Chrominance component - red projection. */ 84 OHOS_IMAGE_COMPONENT_FORMAT_YUV_V = 3, 85 /** JPEG format. */ 86 OHOS_IMAGE_COMPONENT_FORMAT_JPEG = 4, 87 }; 88 89 /** 90 * @brief Defines the information about an image rectangle. 91 * 92 * @since 10 93 * @version 2.0 94 */ 95 struct OhosImageRect { 96 /** X coordinate of the rectangle. */ 97 int32_t x; 98 /** Y coordinate of the rectangle. */ 99 int32_t y; 100 /** Width of the rectangle, in pixels. */ 101 int32_t width; 102 /** Height of the rectangle, in pixels. */ 103 int32_t height; 104 }; 105 106 /** 107 * @brief Defines the image composition information. 108 * 109 * @since 10 110 * @version 2.0 111 */ 112 struct OhosImageComponent { 113 /** Buffer that stores the pixel data. */ 114 uint8_t* byteBuffer; 115 /** Size of the pixel data in the memory. */ 116 size_t size; 117 /** Type of the pixel data. */ 118 int32_t componentType; 119 /** Row stride of the pixel data. */ 120 int32_t rowStride; 121 /** Pixel stride of the pixel data */ 122 int32_t pixelStride; 123 }; 124 125 /** 126 * @brief Parses an {@link ImageNative} object at the native layer from a JavaScript native API <b>image </b> object. 127 * 128 * @param env Indicates the pointer to the Java Native Interface (JNI) environment. 129 * @param source Indicates a JavaScript native API <b>image </b> object. 130 * @return Returns an {@link ImageNative} pointer object if the operation is successful 131 * returns a null pointer otherwise. 132 * @see ImageNative, OH_Image_Release 133 * @since 10 134 * @version 2.0 135 */ 136 ImageNative* OH_Image_InitImageNative(napi_env env, napi_value source); 137 138 /** 139 * @brief Obtains {@link OhosImageRect} of an {@link ImageNative} at the native layer. 140 * 141 * @param native Indicates the pointer to an {@link ImageNative} object at the native layer. 142 * @param rect Indicates the pointer to the {@link OhosImageRect} object obtained. 143 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 144 * returns {@link IRNdkErrCode} IMAGE_RESULT_JNI_ENV_ABNORMAL - if Abnormal JNI environment. 145 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 146 * returns {@link IRNdkErrCode} IMAGE_RESULT_SURFACE_GET_PARAMETER_FAILED - if Failed to obtain parameters for surface. 147 * returns {@link IRNdkErrCode} IMAGE_RESULT_BAD_PARAMETER - if bad parameter. 148 * @see ImageNative, OhosImageRect 149 * @since 10 150 * @version 2.0 151 */ 152 int32_t OH_Image_ClipRect(const ImageNative* native, struct OhosImageRect* rect); 153 154 /** 155 * @brief Obtains {@link OhosImageSize} of an {@link ImageNative} object at the native layer. 156 * 157 * @param native Indicates the pointer to an {@link ImageNative} object at the native layer. 158 * @param size Indicates the pointer to the {@link OhosImageSize} object obtained. 159 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 160 * returns {@link IRNdkErrCode} IMAGE_RESULT_JNI_ENV_ABNORMAL - if Abnormal JNI environment. 161 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 162 * returns {@link IRNdkErrCode} IMAGE_RESULT_SURFACE_GET_PARAMETER_FAILED - if Failed to obtain parameters for surface. 163 * returns {@link IRNdkErrCode} IMAGE_RESULT_BAD_PARAMETER - if bad parameter. 164 * @see ImageNative, OhosImageSize 165 * @since 10 166 * @version 2.0 167 */ 168 int32_t OH_Image_Size(const ImageNative* native, struct OhosImageSize* size); 169 170 /** 171 * @brief Obtains the image format of an {@link ImageNative} object at the native layer. 172 * 173 * @param native Indicates the pointer to an {@link ImageNative} object at the native layer. 174 * @param format Indicates the pointer to the image format obtained. 175 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 176 * returns {@link IRNdkErrCode} IMAGE_RESULT_JNI_ENV_ABNORMAL - if Abnormal JNI environment. 177 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 178 * returns {@link IRNdkErrCode} IMAGE_RESULT_SURFACE_GET_PARAMETER_FAILED - if Failed to obtain parameters for surface. 179 * returns {@link IRNdkErrCode} IMAGE_RESULT_BAD_PARAMETER - if bad parameter. 180 * @see ImageNative 181 * @since 10 182 * @version 2.0 183 */ 184 int32_t OH_Image_Format(const ImageNative* native, int32_t* format); 185 186 /** 187 * @brief Obtains {@link OhosImageComponent} of an {@link ImageNative} object at the native layer. 188 * 189 * @param native Indicates the pointer to an {@link ImageNative} object at the native layer. 190 * @param componentType Indicates the type of the required component. 191 * @param componentNative Indicates the pointer to the {@link OhosImageComponent} object obtained. 192 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 193 * returns {@link IRNdkErrCode} IMAGE_RESULT_JNI_ENV_ABNORMAL - if Abnormal JNI environment. 194 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 195 * returns {@link IRNdkErrCode} IMAGE_RESULT_SURFACE_GET_PARAMETER_FAILED - if Failed to obtain parameters for surface. 196 * returns {@link IRNdkErrCode} IMAGE_RESULT_BAD_PARAMETER - if bad parameter. 197 * @see ImageNative, OhosImageComponent 198 * @since 10 199 * @version 2.0 200 */ 201 int32_t OH_Image_GetComponent(const ImageNative* native, 202 int32_t componentType, struct OhosImageComponent* componentNative); 203 204 /** 205 * @brief Releases an {@link ImageNative} object at the native layer. 206 * Note: This API is not used to release a JavaScript native API <b>Image</b> object. 207 * It is used to release the object {@link ImageNative} at the native layer 208 * parsed by calling {@link OH_Image_InitImageNative}. 209 * 210 * @param native Indicates the pointer to an {@link ImageNative} object at the native layer. 211 * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful. 212 * returns {@link IRNdkErrCode} IMAGE_RESULT_JNI_ENV_ABNORMAL - if Abnormal JNI environment. 213 * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter. 214 * returns {@link IRNdkErrCode} IMAGE_RESULT_BAD_PARAMETER - if bad parameter. 215 * @see ImageNative, OH_Image_InitImageNative 216 * @since 10 217 * @version 2.0 218 */ 219 int32_t OH_Image_Release(ImageNative* native); 220 #ifdef __cplusplus 221 }; 222 #endif 223 /** @} */ 224 #endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_MDK_H_ 225