1 /* 2 * Copyright (c) 2023-2024 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 "core/components_ng/image_provider/image_object.h" 20 #include "core/components_ng/render/adapter/rosen/drawing_image.h" 21 22 namespace OHOS::Ace::NG { 23 class ImageDecoder : public virtual AceType { 24 public: 25 ImageDecoder(const RefPtr<ImageObject>& obj, const SizeF& size, bool forceResize); 26 // decode image using Skia, return true if process is successful. 27 RefPtr<CanvasImage> MakeDrawingImage(); 28 29 // decode image using ImageFramework, return true if process is successful. 30 RefPtr<CanvasImage> MakePixmapImage( 31 AIImageQuality imageQuality = AIImageQuality::NONE, bool isHdrDecoderNeed = false); 32 33 private: 34 static std::shared_ptr<RSImage> ForceResizeImage(const std::shared_ptr<RSImage>& image, const RSImageInfo& info); 35 static std::string GetResolutionQuality(AIImageQuality imageQuality); 36 std::shared_ptr<RSImage> ResizeDrawingImage(); 37 void SwapDecodeSize(int32_t &width, int32_t &height); 38 39 RefPtr<CanvasImage> QueryCompressedCache(); 40 void TryCompress(const RefPtr<DrawingImage>& image); 41 42 const RefPtr<ImageObject> obj_; 43 std::shared_ptr<RSData> data_; 44 const SizeF desiredSize_; 45 const bool forceResize_ = false; 46 }; 47 } // namespace OHOS::Ace::NG 48 49 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_IMAGE_PROVIDER_ADAPTER_IMAGE_DECODER_H 50