• 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_FRAMEWORKS_CORE_COMPONENTS_NG_IMAGE_PROVIDER_ADAPTER_IMAGE_DECODER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_IMAGE_PROVIDER_ADAPTER_IMAGE_DECODER_H
18 
19 #include "include/core/SkImage.h"
20 
21 #include "core/components_ng/image_provider/image_object.h"
22 #ifndef USE_ROSEN_DRAWING
23 #include "core/components_ng/render/adapter/skia_image.h"
24 #else
25 #include "core/components_ng/render/adapter/rosen/drawing_image.h"
26 #endif
27 
28 namespace OHOS::Ace::NG {
29 class ImageDecoder : public virtual AceType {
30 public:
31     ImageDecoder(const RefPtr<ImageObject>& obj, const SizeF& size, bool forceResize);
32     // decode image using Skia, return true if process is successful.
33 #ifndef USE_ROSEN_DRAWING
34     RefPtr<CanvasImage> MakeSkiaImage();
35 #else
36     RefPtr<CanvasImage> MakeDrawingImage();
37 #endif
38 
39     // decode image using ImageFramework, return true if process is successful.
40     RefPtr<CanvasImage> MakePixmapImage();
41 
42 private:
43     static sk_sp<SkImage> ForceResizeImage(const sk_sp<SkImage>& image, const SkImageInfo& info);
44     sk_sp<SkImage> ResizeSkImage();
45 
46     RefPtr<CanvasImage> QueryCompressedCache();
47 #ifndef USE_ROSEN_DRAWING
48     void TryCompress(const RefPtr<SkiaImage>& image);
49 #else
50     void TryCompress(const RefPtr<DrawingImage>& image);
51 #endif
52 
53     const RefPtr<ImageObject> obj_;
54 #ifndef USE_ROSEN_DRAWING
55     sk_sp<SkData> data_;
56 #else
57     std::shared_ptr<RSData> data_;
58 #endif
59     const SizeF desiredSize_;
60     const bool forceResize_ = false;
61 };
62 } // namespace OHOS::Ace::NG
63 
64 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_IMAGE_PROVIDER_ADAPTER_IMAGE_DECODER_H
65