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