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