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 API_CORE_IMAGE_IANIMATED_IMAGE_H 17 #define API_CORE_IMAGE_IANIMATED_IMAGE_H 18 19 #include <base/containers/unique_ptr.h> 20 #include <core/image/intf_image_container.h> 21 #include <core/namespace.h> 22 CORE_BEGIN_NAMESPACE()23CORE_BEGIN_NAMESPACE() 24 25 /** Interface for decoding animated images for different image formats. */ 26 class IAnimatedImage { 27 public: 28 static constexpr int MAX_ERR_MSG_LEN = 128; 29 30 /** Single frame from animation. */ 31 struct AnimationFrame { 32 /** frame timestamp */ 33 uint64_t timestamp; 34 35 /** frame number starting from 0 */ 36 uint32_t frameNumber; 37 38 /** Pointer to image container for this frame */ 39 IImageContainer::Ptr image; 40 }; 41 42 /** Restart animation from begining */ 43 virtual void Restart() = 0; 44 45 /** Get loop count */ 46 virtual uint32_t GetLoopCount() = 0; 47 48 /** Get total number of frames */ 49 virtual uint32_t GetNumberOfFrames() = 0; 50 51 /** Get the next animation frame. */ 52 virtual AnimationFrame GetNextFrame() = 0; 53 54 /** Preventing copy construction and assign. */ 55 IAnimatedImage(IAnimatedImage const&) = delete; 56 IAnimatedImage& operator=(IAnimatedImage const&) = delete; 57 58 struct Deleter { 59 constexpr Deleter() noexcept = default; 60 void operator()(IAnimatedImage* ptr) const 61 { 62 ptr->Destroy(); 63 } 64 }; 65 using Ptr = BASE_NS::unique_ptr<IAnimatedImage, Deleter>; 66 67 protected: 68 IAnimatedImage() = default; 69 virtual ~IAnimatedImage() = default; 70 virtual void Destroy() = 0; 71 }; 72 CORE_END_NAMESPACE() 73 74 #endif // API_CORE_IMAGE_IANIMATED_IMAGE_H 75