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