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