• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 native APIs for encoding image data
21  *
22  * The encoding image data module part of image module.
23  * It used to pack pixel data infomation into a target like data or file.
24  *
25  * @since 11
26  * @version 4.1
27  */
28 
29 /**
30  * @file image_packer_mdk.h
31  *
32  * @brief Declares APIs for encoding image into data or file.
33  *
34  * The packing image data module used to pack pixel data into a target.
35  *
36  * The following steps are recommended for packing process:
37  * Create a image packer object by calling OH_ImagePacker_Create function.
38  * And then covert the image packer object to ImagePacker_Native by OH_ImagePacker_InitNative.
39  * Next using OH_ImagePacker_PackToData or OH_ImagePacker_PackToFile to pack source to target area with
40  * requird packing options.
41  * Finally, release the ImagePacker_Native by OH_ImagePacker_Release.
42  *
43  * @library libimage_packer_ndk.z.so
44  * @kit ImageKit
45  * @syscap SystemCapability.Multimedia.Image.Core
46  * @since 11
47  * @version 4.1
48  */
49 
50 #ifndef INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PACKER_MDK_H_
51 #define INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PACKER_MDK_H_
52 #include "napi/native_api.h"
53 #include "image_mdk_common.h"
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 struct ImagePacker_Native_;
60 
61 /**
62  * @brief Defines an image packer object at the native layer for the image packer interface.
63  *
64  * @since 11
65  * @version 4.1
66  */
67 typedef struct ImagePacker_Native_ ImagePacker_Native;
68 
69 /**
70  * @brief Defines the image packing options.
71  *
72  * @since 11
73  * @version 4.1
74  */
75 struct ImagePacker_Opts_ {
76     /** Encoding format. */
77     const char* format;
78     /** Encoding quality. */
79     int quality;
80 };
81 
82 /**
83  * @brief Defines alias of image packing options.
84  *
85  * @since 11
86  * @version 4.1
87  */
88 typedef struct ImagePacker_Opts_ ImagePacker_Opts;
89 
90 /**
91  * @brief Creates an <b>ImagePacker</b> object at the JavaScript native layer.
92  *
93  * @param env Indicates a pointer to the JavaScript Native Interface (JNI) environment.
94  * @param res Indicates a pointer to the <b>ImagePacker</b> object created at the JavaScript native layer.
95  * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful.
96  * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter.
97  *
98  * @syscap SystemCapability.Multimedia.Image
99  * @since 11
100  * @version 4.1
101  */
102 int32_t OH_ImagePacker_Create(napi_env env, napi_value *res);
103 
104 /**
105  * @brief Parses an {@link ImagePacker_Native} object at the native layer
106  * from a JavaScript native API <b>ImagePacker</b> object.
107  *
108  * @param env Indicates the pointer to the JavaScript Native Interface (JNI) environment.
109  * @param packer Indicates a JavaScript native API <b>ImagePacker</b> object.
110  * @return Returns an {@link ImagePacker_Native} pointer object if the operation is successful
111  * returns a null pointer otherwise.
112  * @see {@link OH_ImagePacker_Release}
113  * @since 11
114  * @version 4.1
115  */
116 ImagePacker_Native* OH_ImagePacker_InitNative(napi_env env, napi_value packer);
117 
118 /**
119  * @brief Encoding an <b>ImageSource</b> or a <b>PixelMap</b> into the data with required format
120  *
121  * @param native Indicates the pointer to an {@link ImagePacker} object at the native layer.
122  * @param source Indicates an encoding source, a JS pixel map object or a JS image source object .
123  * @param opts Indicates the encoding {@link ImagePacker_Opts} .
124  * @param outData Indicates the pointer to the encoded data.
125  * @param size Indicates the pointer to the {@link OhosImageComponent} object obtained.
126  * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful.
127   * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter.
128   * returns {@link IRNdkErrCode} ERR_IMAGE_DATA_ABNORMAL - if output target abnormal
129   * returns {@link IRNdkErrCode} ERR_IMAGE_MISMATCHED_FORMAT - if format mismatched
130   * returns {@link IRNdkErrCode} ERR_IMAGE_MALLOC_ABNORMAL - if malloc internal buffer error
131   * returns {@link IRNdkErrCode} ERR_IMAGE_DECODE_ABNORMAL - if init codec internal error
132   * returns {@link IRNdkErrCode} ERR_IMAGE_ENCODE_FAILED - if encoder occur error during encoding
133  * @see {@link OH_ImagePacker_PackToFile}
134  * @since 11
135  * @version 4.1
136  */
137 int32_t OH_ImagePacker_PackToData(ImagePacker_Native* native, napi_value source,
138     ImagePacker_Opts* opts, uint8_t* outData, size_t* size);
139 
140 /**
141  * @brief Encoding an <b>ImageSource</b> or a <b>PixelMap</b> into the a file with fd with required format
142  *
143  * @param native Indicates the pointer to an {@link ImagePacker} object at the native layer.
144  * @param source Indicates an encoding source, a JS pixel map object or a JS image source object .
145  * @param opts Indicates the encoding {@link ImagePacker_Opts} .
146  * @param fd Indicates the a writable file descriptor.
147  * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful.
148   * returns {@link IRNdkErrCode} IMAGE_RESULT_INVALID_PARAMETER - if invalid parameter.
149   * returns {@link IRNdkErrCode} ERR_IMAGE_DATA_ABNORMAL - if output target abnormal
150   * returns {@link IRNdkErrCode} ERR_IMAGE_MISMATCHED_FORMAT - if format mismatched
151   * returns {@link IRNdkErrCode} ERR_IMAGE_MALLOC_ABNORMAL - if malloc internal buffer error
152   * returns {@link IRNdkErrCode} ERR_IMAGE_DECODE_ABNORMAL - if init codec internal error
153   * returns {@link IRNdkErrCode} ERR_IMAGE_ENCODE_FAILED - if encoder occur error during encoding
154  * @see {@link OH_ImagePacker_PackToData}
155  * @since 11
156  * @version 4.1
157  */
158 int32_t OH_ImagePacker_PackToFile(ImagePacker_Native* native, napi_value source,
159     ImagePacker_Opts* opts, int fd);
160 
161 
162 /**
163  * @brief Releases an {@link ImagePacker_Native} object at the native layer.
164  * Note: This API is not used to release a JavaScript native API <b>ImagePacker</b> object.
165  * It is used to release the object {@link ImagePacker_Native} at the native layer
166  * parsed by calling {@link OH_ImagePacker_InitNative}.
167  *
168  * @param native Indicates the pointer to an {@link ImagePacker_Native} object at the native layer.
169  * @return Returns {@link IRNdkErrCode} IMAGE_RESULT_SUCCESS - if the operation is successful.
170  * @see {@link OH_ImagePacker_InitNative}
171  * @since 11
172  * @version 4.1
173  */
174 int32_t OH_ImagePacker_Release(ImagePacker_Native* native);
175 #ifdef __cplusplus
176 };
177 #endif
178 /** @} */
179 #endif // INTERFACES_KITS_NATIVE_INCLUDE_IMAGE_PACKER_MDK_H_
180