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 
42 enum class ImageAnalyzerType {
43     SUBJECT = 0,
44     TEXT,
45 };
46 
47 enum class ImageAnalyzerHolder {
48     IMAGE = 0,
49     CANVAS,
50     XCOMPONENT,
51     VIDEO_CUSTOM,
52     VIDEO_DEFAULT,
53     WEB,
54     OTHERS,
55 };
56 
57 enum class ImageAnalyzerState {
58     UNSUPPORTED = 0,
59     ONGOING,
60     STOPPED,
61     FINISHED
62 };
63 
64 enum class Status {
65     SELECTED = 0,
66     UNSELECTED,
67     MENU_SHOW,
68     MENU_HIDE
69 };
70 
71 struct TouchInfo {
72     TouchPoint touchPoint;
73     TouchType touchType = TouchType::CANCEL;
74 };
75 
76 struct PixelMapInfo {
77     float width = 0.0f;
78     float height = 0.0f;
79     NG::OffsetF overlayOffset = { 0.0f, 0.0f };
80 };
81 
82 struct AIButtonConfig {
83     std::vector<float> buttonOffset = {0.0f, 0.0f, 0.0f, 0.0f};
84     bool isShow = true;
85 };
86 
87 struct ImageAnalyzerConfig {
88     NG::MarginProperty aiButtonMargin;
89     std::set<ImageAnalyzerType> types;
90     std::string tag;
91     bool isShowAIButton = true;
92 };
93 
94 struct ImageAnalyzerInnerConfig {
95     float contentWidth = 0.0f;
96     float contentHeight = 0.0f;
97     float pixelMapWidth = 0.0f;
98     float pixelMapHeight = 0.0f;
99     NG::OffsetF overlayOffset = { 0.0f, 0.0f };
100     ImageAnalyzerHolder holder = ImageAnalyzerHolder::OTHERS;
101     ImageFit imageFit = ImageFit::COVER;
102     Matrix4 transformMat = Matrix4::CreateIdentity();
103     OnAnalyzedCallback onAnalyzed;
104     Status selectedStatus = Status::SELECTED;
105     Status menuStatus = Status::MENU_SHOW;
106     OnTextSelectedCallback onTextSelected;
107     void* pixelmapNapiVal = nullptr;
108     OHOS::Ace::TouchInfo touchInfo;
109     OnNotifySelectedStatusCallback onNotifySelectedStatus = nullptr;
110 
UpdateFromInfoImageAnalyzerInnerConfig111     void UpdateFromInfo(const PixelMapInfo& info)
112     {
113         contentWidth = info.width;
114         contentHeight = info.height;
115         pixelMapWidth = info.width;
116         pixelMapHeight = info.height;
117         overlayOffset = info.overlayOffset;
118     }
119 };
120 } // namespace OHOS::Ace
121 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_PROPERTIES_IMAGE_ANALYZER_H