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 #ifndef FOUNDATION_ACE_INTERFACE_INNERKITS_PROPERTIES_IMAGE_ANALYZER_H
17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_PROPERTIES_IMAGE_ANALYZER_H
18 
19 #include <array>
20 #include <cstdint>
21 #include <functional>
22 #include <optional>
23 #include <set>
24 #include <string>
25 #include <vector>
26 
27 #include "base/geometry/calc_dimension.h"
28 #include "base/geometry/matrix4.h"
29 #include "base/geometry/ng/offset_t.h"
30 #include "base/geometry/ng/vector.h"
31 #include "base/memory/ace_type.h"
32 #include "core/components/common/layout/constants.h"
33 #include "third_party/node/src/js_native_api_types.h"
34 #include "core/components_ng/property/measure_property.h"
35 
36 namespace OHOS::Ace {
37 enum class ImageAnalyzerState;
38 using OnAnalyzedCallback = std::optional<std::function<void(ImageAnalyzerState)>>;
39 using OnTextSelectedCallback = std::function<void()>;
40 using OnNotifySelectedStatusCallback = std::function<void(bool)>;
41 using OnCanPlayCallback = std::function<void(bool)>;
42 
43 enum class ImageAnalyzerType {
44     SUBJECT = 0,
45     TEXT,
46 };
47 
48 enum class ImageAnalyzerHolder {
49     IMAGE = 0,
50     CANVAS,
51     XCOMPONENT,
52     VIDEO_CUSTOM,
53     VIDEO_DEFAULT,
54     WEB,
55     OTHERS,
56     MOVINGPHOTO,
57 };
58 
59 enum class ImageAnalyzerState {
60     UNSUPPORTED = 0,
61     ONGOING,
62     STOPPED,
63     FINISHED
64 };
65 
66 enum class Status {
67     SELECTED = 0,
68     UNSELECTED,
69     MENU_SHOW,
70     MENU_HIDE
71 };
72 
73 struct TouchInfo {
74     TouchPoint touchPoint;
75     TouchType touchType = TouchType::CANCEL;
76 };
77 
78 struct PixelMapInfo {
79     float width = 0.0f;
80     float height = 0.0f;
81     NG::OffsetF overlayOffset = { 0.0f, 0.0f };
82 };
83 
84 struct AIButtonConfig {
85     std::vector<float> buttonOffset = {0.0f, 0.0f, 0.0f, 0.0f};
86     bool isShow = true;
87 };
88 
89 struct ImageAnalyzerConfig {
90     NG::MarginProperty aiButtonMargin;
91     std::set<ImageAnalyzerType> types;
92     std::string tag;
93     bool isShowAIButton = true;
94 };
95 
96 struct ImageAnalyzerInnerConfig {
97     float contentWidth = 0.0f;
98     float contentHeight = 0.0f;
99     float pixelMapWidth = 0.0f;
100     float pixelMapHeight = 0.0f;
101     NG::OffsetF overlayOffset = { 0.0f, 0.0f };
102     ImageAnalyzerHolder holder = ImageAnalyzerHolder::OTHERS;
103     ImageFit imageFit = ImageFit::COVER;
104     Matrix4 transformMat = Matrix4::CreateIdentity();
105     OnAnalyzedCallback onAnalyzed;
106     Status selectedStatus = Status::SELECTED;
107     Status menuStatus = Status::MENU_SHOW;
108     OnTextSelectedCallback onTextSelected;
109     void* pixelmapNapiVal = nullptr;
110     OHOS::Ace::TouchInfo touchInfo;
111     OnNotifySelectedStatusCallback onNotifySelectedStatus = nullptr;
112     bool createAIEngine = false;
113     OnCanPlayCallback onCanPlay = nullptr;
114 
UpdateFromInfoOHOS::Ace::ImageAnalyzerInnerConfig115     void UpdateFromInfo(const PixelMapInfo& info)
116     {
117         contentWidth = info.width;
118         contentHeight = info.height;
119         pixelMapWidth = info.width;
120         pixelMapHeight = info.height;
121         overlayOffset = info.overlayOffset;
122     }
123 };
124 } // namespace OHOS::Ace
125 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_PROPERTIES_IMAGE_ANALYZER_H