1 /* 2 * Copyright (c) 2021-2025 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_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_IMAGE_IMAGE_MODEL_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_IMAGE_IMAGE_MODEL_H 18 19 #include <memory> 20 #include <mutex> 21 22 #include "interfaces/inner_api/ace/ai/image_analyzer.h" 23 24 #include "base/geometry/dimension.h" 25 #include "base/image/drawable_descriptor.h" 26 #include "base/image/drawing_color_filter.h" 27 #include "base/image/drawing_lattice.h" 28 #include "base/image/pixel_map.h" 29 #include "base/memory/referenced.h" 30 #include "core/components/box/drag_drop_event.h" 31 #include "core/components/common/layout/constants.h" 32 #include "core/components/common/properties/border.h" 33 #include "core/components/common/properties/color.h" 34 #include "core/components/declaration/image/image_animator_declaration.h" 35 #include "core/components/image/image_event.h" 36 #include "core/components_ng/event/gesture_event_hub.h" 37 #include "core/image/image_source_info.h" 38 39 namespace OHOS::Ace { 40 struct ACE_FORCE_EXPORT ImageInfoConfig { 41 std::shared_ptr<std::string> src; 42 std::string bundleName; 43 std::string moduleName; 44 bool isUriPureNumber = false; 45 bool isImageSpan = false; 46 }; 47 48 class ACE_FORCE_EXPORT ImageModel { 49 public: 50 static ImageModel* GetInstance(); 51 virtual ~ImageModel() = default; Create(const RefPtr<DrawableDescriptor> & drawable)52 virtual void Create(const RefPtr<DrawableDescriptor>& drawable) {} 53 virtual void Create(const ImageInfoConfig& imageInfoConfig, RefPtr<PixelMap>& pixMap) = 0; 54 55 virtual void SetAlt(const ImageSourceInfo& src) = 0; 56 virtual void SetBlur(double blur) = 0; 57 virtual void SetBorder(const Border& border) = 0; 58 virtual void SetBorderRadius(const Dimension& value) = 0; 59 virtual void SetBorderRadius(const std::optional<Dimension>& radiusTopLeft, 60 const std::optional<Dimension>& radiusTopRight, const std::optional<Dimension>& radiusBottomLeft, 61 const std::optional<Dimension>& radiusBottomRight) = 0; 62 virtual void SetBorderRadius(const NG::BorderRadiusProperty& borderRadius) = 0; 63 virtual void SetBackBorder() = 0; 64 virtual void SetImageFit(ImageFit value) = 0; 65 virtual void SetImageMatrix(const Matrix4& value) = 0; 66 virtual void SetMatchTextDirection(bool value) = 0; 67 virtual void SetFitOriginSize(bool value) = 0; 68 virtual void SetOnComplete(std::function<void(const LoadImageSuccessEvent& info)>&& callback) = 0; 69 virtual void SetOnError(std::function<void(const LoadImageFailEvent& info)>&& callback) = 0; 70 virtual void SetSvgAnimatorFinishEvent(std::function<void()>&& callback) = 0; 71 virtual void ResetImage() = 0; 72 virtual void CreateAnimation( 73 const std::vector<ImageProperties>& imageList, int32_t duration, int32_t iteration) = 0; 74 virtual void SetImageSourceSize(const std::pair<Dimension, Dimension>& size) = 0; 75 virtual void SetImageFill(const Color& color) = 0; 76 virtual void ResetImageFill() = 0; 77 virtual void SetImageInterpolation(ImageInterpolation interpolation) = 0; 78 virtual void SetImageRepeat(ImageRepeat imageRepeat) = 0; 79 virtual void SetImageRenderMode(ImageRenderMode imageRenderMode) = 0; 80 virtual bool IsSrcSvgImage() = 0; 81 virtual void SetAutoResize(bool autoResize) = 0; 82 virtual void SetResizableSlice(const ImageResizableSlice& slice) = 0; 83 virtual void SetResizableLattice(const RefPtr<DrawingLattice>& lattice) = 0; 84 virtual void ResetResizableLattice() = 0; 85 virtual void SetSyncMode(bool syncMode) = 0; 86 virtual void SetColorFilterMatrix(const std::vector<float>& matrix) = 0; 87 virtual void SetDrawingColorFilter(RefPtr<DrawingColorFilter>& colorFilter) = 0; 88 virtual void SetDraggable(bool draggable) = 0; 89 virtual void SetOnDragStart(NG::OnDragStartFunc&& onDragStart) = 0; 90 virtual void SetOnDragEnter(NG::OnDragDropFunc&& onDragEnter) = 0; 91 virtual void SetOnDragLeave(NG::OnDragDropFunc&& onDragLeave) = 0; 92 virtual void SetOnDragMove(NG::OnDragDropFunc&& onDragMove) = 0; 93 virtual void SetOnDrop(NG::OnDragDropFunc&& onDrop) = 0; 94 virtual void SetCopyOption(const CopyOptions& copyOption) = 0; 95 virtual bool UpdateDragItemInfo(DragItemInfo& itemInfo) = 0; 96 virtual void EnableAnalyzer(bool isEnableAnalyzer) = 0; 97 virtual void SetImageAnalyzerConfig(const ImageAnalyzerConfig& config) = 0; 98 virtual void SetImageAnalyzerConfig(void* config) = 0; 99 virtual void SetImageAIOptions(void* options) = 0; 100 virtual void SetSmoothEdge(float value) = 0; 101 virtual void SetDynamicRangeMode(DynamicRangeMode dynamicRangeMode) = 0; 102 virtual void SetEnhancedImageQuality(AIImageQuality imageQuality) = 0; 103 virtual void SetOrientation(ImageRotateOrientation orientation) = 0; 104 virtual bool GetIsAnimation() = 0; 105 106 private: 107 static std::unique_ptr<ImageModel> instance_; 108 static std::mutex mutex_; 109 }; 110 } // namespace OHOS::Ace 111 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_IMAGE_IMAGE_MODEL_H 112