1 /* 2 * Copyright (C) 2022 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 obtaining pixel map data and information. 21 * 22 * @syscap SystemCapability.Multimedia.Image.Core 23 * @since 8 24 * @version 1.0 25 */ 26 27 /** 28 * @file image_pixel_map_napi.h 29 * 30 * @brief Declares the APIs that can lock, access, and unlock a pixel map. 31 * 32 * @library libpixelmap_ndk.so 33 * @syscap SystemCapability.Multimedia.Image.Core 34 * @kit ImageKit 35 * @since 8 36 * @version 1.0 37 */ 38 39 #ifndef INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PIXEL_MAP_NAPI_H_ 40 #define INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PIXEL_MAP_NAPI_H_ 41 #ifdef __cplusplus 42 #include <cstdint> 43 #else 44 #include <stdint.h> 45 #endif 46 #include "napi/native_api.h" 47 namespace OHOS { 48 namespace Media { 49 #ifdef __cplusplus 50 extern "C" { 51 #endif 52 53 /** 54 * @brief Enumerates the error codes returned by the functions. 55 * 56 * @deprecated since 10 57 * @since 8 58 * @version 1.0 59 */ 60 enum { 61 /** Operation success. */ 62 OHOS_IMAGE_RESULT_SUCCESS = 0, 63 /** Invalid value. */ 64 OHOS_IMAGE_RESULT_BAD_PARAMETER = -1, 65 }; 66 67 /** 68 * @brief Enumerates the pixel formats. 69 * 70 * @deprecated since 10 71 * @since 8 72 * @version 1.0 73 */ 74 enum { 75 /** 76 * Unknown format. 77 */ 78 OHOS_PIXEL_MAP_FORMAT_NONE = 0, 79 /** 80 * 32-bit RGBA, with 8 bits each for R (red), G (green), B (blue), and A (alpha). 81 * The data is stored from the most significant bit to the least significant bit. 82 */ 83 OHOS_PIXEL_MAP_FORMAT_RGBA_8888 = 3, 84 /** 85 * 16-bit RGB, with 5, 6, and 5 bits for R, G, and B, respectively. 86 * The data is stored from the most significant bit to the least significant bit. 87 */ 88 OHOS_PIXEL_MAP_FORMAT_RGB_565 = 2, 89 }; 90 91 /** 92 * @brief Defines the pixel map information. 93 * 94 * @deprecated since 10 95 * @since 8 96 * @version 1.0 97 */ 98 struct OhosPixelMapInfo { 99 /** Image width, in pixels. */ 100 uint32_t width; 101 /** Image height, in pixels. */ 102 uint32_t height; 103 /** Number of bytes per row. */ 104 uint32_t rowSize; 105 /** Pixel format. */ 106 int32_t pixelFormat; 107 }; 108 109 /** 110 * @brief Enumerates the pixel map scale modes. 111 * 112 * @since 10 113 * @version 2.0 114 */ 115 enum { 116 /** 117 * Adaptation to the target image size. 118 */ 119 OHOS_PIXEL_MAP_SCALE_MODE_FIT_TARGET_SIZE = 0, 120 /** 121 * Cropping the center portion of an image to the target size. 122 */ 123 OHOS_PIXEL_MAP_SCALE_MODE_CENTER_CROP = 1, 124 }; 125 126 /** 127 * @brief Obtains the information about a <b>PixelMap</b> object 128 * and stores the information to the {@link OhosPixelMapInfo} struct. 129 * 130 * @deprecated since 10 131 * @param env Indicates the NAPI environment pointer. 132 * @param value Indicates the <b>PixelMap</b> object at the application layer. 133 * @param info Indicates the pointer to the object that stores the information obtained. 134 * For details, see {@link OhosPixelMapInfo}. 135 * @return Returns <b>0</b> if the information is obtained and stored successfully; returns an error code otherwise. 136 * @see OhosPixelMapInfo 137 * @since 8 138 * @version 1.0 139 */ 140 int32_t OH_GetImageInfo(napi_env env, napi_value value, OhosPixelMapInfo *info); 141 142 /** 143 * @brief Obtains the memory address of a <b>PixelMap</b> object and locks the memory. 144 * 145 * After the function is executed successfully, <b>*addrPtr</b> is the memory address to be accessed. 146 * After the access operation is complete, you must use {@link OH_UnAccessPixels} to unlock the memory. 147 * Otherwise, the resources in the memory cannot be released. 148 * After the memory is unlocked, its address cannot be accessed or operated. 149 * 150 * @deprecated since 10 151 * @param env Indicates the NAPI environment pointer. 152 * @param value Indicates the <b>PixelMap</b> object at the application layer. 153 * @param addrPtr Indicates the double pointer to the memory address. 154 * @see UnAccessPixels 155 * @return Returns {@link OHOS_IMAGE_RESULT_SUCCESS} if the operation is successful; returns an error code otherwise. 156 * @since 8 157 * @version 1.0 158 */ 159 int32_t OH_AccessPixels(napi_env env, napi_value value, void** addrPtr); 160 161 /** 162 * @brief Unlocks the memory of a <b>PixelMap</b> object. This function is used with {@link OH_AccessPixels} in pairs. 163 * 164 * @deprecated since 10 165 * @param env Indicates the NAPI environment pointer. 166 * @param value Indicates the <b>PixelMap</b> object at the application layer. 167 * @return Returns {@link OHOS_IMAGE_RESULT_SUCCESS} if the operation is successful; returns an error code otherwise. 168 * @see AccessPixels 169 * @since 8 170 * @version 1.0 171 */ 172 int32_t OH_UnAccessPixels(napi_env env, napi_value value); 173 174 #ifdef __cplusplus 175 }; 176 #endif 177 /** @} */ 178 } // namespace Media 179 } // namespace OHOS 180 #endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PIXEL_MAP_NAPI_H_ 181