• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 #ifndef IMAGE_EFFECT_NATIVE_COMMON_UTILS_H
17 #define IMAGE_EFFECT_NATIVE_COMMON_UTILS_H
18 
19 #include <vector>
20 
21 #include "any.h"
22 #include "effect_info.h"
23 #include "error_code.h"
24 #include "image_effect_filter.h"
25 #include "image_type.h"
26 #include "pixel_map_napi.h"
27 #include "picture_native_impl.h"
28 
29 #define EFFECT_EXPORT __attribute__((visibility("default")))
30 
31 namespace OHOS {
32 namespace Media {
33 namespace Effect {
34 class NativeCommonUtils {
35 public:
36     /**
37      * Parses an ImageEffect_Any object and converts it to Any.
38      *
39      * @param value The input ImageEffect_Any object.
40      * @param any The output Any object.
41      * @return ErrorCode indicating the result of the operation.
42      */
43     static ErrorCode ParseOHAny(const ImageEffect_Any *value, Any &any);
44 
45     /**
46      * Converts a Any object to an ImageEffect_Any object.
47      *
48      * @param any The input Any object.
49      * @param value The output ImageEffect_Any object.
50      * @return ErrorCode indicating the result of the operation.
51      */
52     static ErrorCode SwitchToOHAny(const Any &any, ImageEffect_Any *value);
53 
54     /**
55      * Converts an IEffectFormat object to an ImageEffect_Format object.
56      *
57      * @param formatType The input IEffectFormat object.
58      * @param ohFormatType The output ImageEffect_Format object.
59      */
60     static void SwitchToOHFormatType(const IEffectFormat &formatType, ImageEffect_Format &ohFormatType);
61 
62     /**
63      * Converts an ImageEffect_Format object to an IEffectFormat object.
64      *
65      * @param ohFormatType The input ImageEffect_Format object.
66      * @param formatType The output IEffectFormat object.
67      */
68     static void SwitchToFormatType(const ImageEffect_Format &ohFormatType, IEffectFormat &formatType);
69 
70     /**
71      * Converts an EffectInfo object to an OH_EffectFilterInfo object.
72      *
73      * @param effectInfo The input EffectInfo object.
74      * @param ohFilterInfo The output OH_EffectFilterInfo object.
75      */
76     static void SwitchToOHEffectInfo(const EffectInfo *effectInfo, OH_EffectFilterInfo *ohFilterInfo);
77 
78     /**
79      * Retrieves a PixelMap object from an OH_PixelmapNative object.
80      *
81      * @param pixelmapNative The input OH_PixelmapNative object.
82      * @return A pointer to the retrieved PixelMap object.
83      */
84     static PixelMap *GetPixelMapFromOHPixelmap(OH_PixelmapNative *pixelmapNative);
85 
86     /**
87      * Retrieves a Picture object from an OH_PictureNative object.
88      *
89      * @param pictureNative The input OH_PictureNative object.
90      * @return A pointer to the retrieved Picture object.
91      */
92     static Picture *GetPictureFromNativePicture(OH_PictureNative *pictureNative);
93 
94     /**
95      * Parses a lookup key and populates a vector with matching filter names.
96      *
97      * @param key The input lookup key string.
98      * @param matchEFilter The output vector containing matching filter names.
99      */
100     static void ParseLookupKey(std::string &key, std::vector<const char *> &matchEFilter);
101 
102     /**
103      * Converts an OH_EffectFilterInfo object to an EffectInfo object.
104      *
105      * @param info The input OH_EffectFilterInfo object.
106      * @param effectInfo The output EffectInfo object.
107      */
108     static void SwitchToEffectInfo(const OH_EffectFilterInfo *info, const std::shared_ptr<EffectInfo> &effectInfo);
109 
110     /**
111      * Retrieves supported formats from an OH_EffectFilterInfo object.
112      *
113      * @param ohFilterInfo The input OH_EffectFilterInfo object.
114      * @return A uint32_t representing supported formats.
115      */
116     static uint32_t GetSupportedFormats(const OH_EffectFilterInfo *ohFilterInfo);
117 
118     /**
119      * Reports a start failure event with an error code and message.
120      *
121      * @param errorCode The error code indicating the type of failure.
122      * @param errorMsg The error message describing the failure.
123      */
124     static void ReportEventStartFailed(ImageEffect_ErrorCode errorCode, const char *errorMsg);
125 
126     /**
127      * Converts an ErrorCode to an ImageEffect_ErrorCode.
128      *
129      * @param errorCode The input ErrorCode.
130      * @return The converted ImageEffect_ErrorCode.
131      */
132     static ImageEffect_ErrorCode ConvertStartResult(ErrorCode errorCode);
133 
134     static ImageEffect_ErrorCode ConvertRenderResult(ErrorCode errorCode);
135 };
136 } // namespace Effect
137 } // namespace Media
138 } // namespace OHOS
139 #endif // IMAGE_EFFECT_NATIVE_COMMON_UTILS_H