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