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