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 access to pixel data and pixel map 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 functions for you to lock and access or unlock pixel data, and obtain the width and height of a pixel 31 * map. 32 * 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 <stdint.h> 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 result codes that may be returned by a function. 49 * 50 * @since 8 51 * @version 1.0 52 */ 53 enum { 54 /** Success result */ 55 OHOS_IMAGE_RESULT_SUCCESS = 0, 56 /** Invalid parameters */ 57 OHOS_IMAGE_RESULT_BAD_PARAMETER = -1, 58 }; 59 60 /** 61 * @brief Enumerates pixel formats. 62 * 63 * @since 8 64 * @version 1.0 65 */ 66 enum { 67 /** 68 * Unknown format 69 */ 70 OHOS_PIXEL_MAP_FORMAT_NONE = 0, 71 /** 72 * 32-bit RGBA. Components R, G, B, and A each occupies 8 bits 73 * and are stored from the higher-order to the lower-order bits. 74 */ 75 OHOS_PIXEL_MAP_FORMAT_RGBA_8888 = 3, 76 /** 77 * 16-bit RGB. Only the R, G, and B components are encoded 78 * from the higher-order to the lower-order bits: red is stored with 5 bits of precision, 79 * green is stored with 6 bits of precision, and blue is stored with 5 bits of precision. 80 */ 81 OHOS_PIXEL_MAP_FORMAT_RGB_565 = 2, 82 }; 83 84 /** 85 * @brief Defines pixel map information. 86 * 87 * @since 8 88 * @version 1.0 89 */ 90 struct OhosPixelMapInfo { 91 /** Image width, in pixels. */ 92 uint32_t width; 93 /** Image height, in pixels. */ 94 uint32_t height; 95 /** Number of bytes in each row of a pixel map */ 96 uint32_t rowSize; 97 /** Pixel format */ 98 int32_t pixelFormat; 99 }; 100 101 /** 102 * @brief Obtains information about a given <b>PixelMap</b> and stores the information in a {@link OhosPixelMapInfo} 103 * structure. 104 * 105 * @param env Indicates the pointer to the JNI environment. 106 * @param pixelMapObject Indicates the Java <b>PixelMap</b> object. 107 * @param info Indicates the pointer to the pixel map information to obtain. For details, see {@link 108 * OhosPixelMapInfo}. 109 * @return Returns <b>0</b> if the information is obtained and stored in the structure; returns result codes if the 110 * operation fails. 111 * @see OhosPixelMapInfo 112 * @since 8 113 * @version 1.0 114 */ 115 int32_t OH_GetImageInfo(napi_env env, napi_value value, OhosPixelMapInfo *info); 116 117 /** 118 * @brief Obtains the memory address of a given <b>PixelMap</b> object and locks the memory. 119 * 120 * If this function call is successful, <b>*addrPtr</b> is set to the memory address. After accessing the pixel data, 121 * you must use {@link UnAccessPixels} to unlock the memory. Otherwise, resources cannot be released. 122 * After the memory is unlocked, it can be invalid and should not be accessed. 123 * 124 * @param env Indicates the pointer to the JNI environment. 125 * @param pixelMapObject Indicates the Java <b>PixelMap</b> object. 126 * @param addrPtr Indicates the double pointer to the memory address. 127 * @see UnAccessPixels 128 * @return Returns {@link OHOS_IMAGE_RESULT_SUCCESS} if the operation is successful; returns other result codes if 129 * the operation fails. 130 * @since 8 131 * @version 1.0 132 */ 133 int32_t OH_AccessPixels(napi_env env, napi_value value, void** addrPtr); 134 135 /** 136 * @brief Unlocks the memory storing the pixel data of a given <b>PixelMap</b> to balance a successful call to {@link 137 * AccessPixels}. 138 * 139 * @param env Indicates the pointer to the JNI environment. 140 * @param pixelMapObject Indicates the Java <b>PixelMap</b> object. 141 * @return Returns {@link OHOS_IMAGE_RESULT_SUCCESS} if the operation is successful; returns other result codes if 142 * the operation fails. 143 * @see AccessPixels 144 * @since 8 145 * @version 1.0 146 */ 147 int32_t OH_UnAccessPixels(napi_env env, napi_value value); 148 149 #ifdef __cplusplus 150 }; 151 #endif 152 /** @} */ 153 } // namespace Media 154 } // namespace OHOS 155 #endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PIXEL_MAP_NAPI_H_ 156