• 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 #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/vector.h"
30 #include "base/memory/ace_type.h"
31 #include "core/components/common/layout/constants.h"
32 #include "third_party/node/src/js_native_api_types.h"
33 #include "core/components_ng/property/measure_property.h"
34 
35 namespace OHOS::Ace {
36 using onSubcjectAnalyzedFunc = std::optional<std::function<void(const std::string&, std::vector<uint8_t>&)>>;
37 using onTextAnalyzedFunc = std::optional<std::function<void(const std::string&, const std::string&)>>;
38 using onTextSelectedFunc = std::optional<std::function<void(const std::string&, const std::string&)>>;
39 
40 enum class ImageAnalyzerType {
41     SUBJECT = 0,
42     TEXT,
43 };
44 
45 struct ImageAnalyzerSubjectOptions {
46     onSubcjectAnalyzedFunc onAnalyzedCallback;
47     std::vector<uint8_t> analyzedData;
48     napi_value sourcePixelmap;
49 };
50 
51 struct ImageAnalyzerTextOptions {
52     onTextAnalyzedFunc onAnalyzedCallback;
53     onTextSelectedFunc onTextSelected;
54     std::string analyzedData;
55     bool isAutoDetectText = true;
56 };
57 
58 struct ImageAnalyzerConfig {
59     ImageAnalyzerSubjectOptions subjectOptions_ {};
60     ImageAnalyzerTextOptions textOptions {};
61     NG::MarginProperty aiButtonMargin;
62     std::set<ImageAnalyzerType> types;
63     std::string tag;
64     bool isShowAIButton = true;
65 };
66 
67 struct ImageAnalyzerInnerConfig {
68     float contentWidth = 0.0f;
69     float contentHeight = 0.0f;
70     ImageFit imageFit = ImageFit::COVER;
71     Matrix4 transformMat = Matrix4::CreateIdentity();
72 };
73 } // namespace OHOS::Ace
74 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_PROPERTIES_IMAGE_ANALYZER_H