AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
WebpImageFactory.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 Alex2772 and Contributors
    4 *
    5 * SPDX-License-Identifier: MPL-2.0
    6 *
    7 * This Source Code Form is subject to the terms of the Mozilla Public
    8 * License, v. 2.0. If a copy of the MPL was not distributed with this
    9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10 */
   11
   12#pragma once
   13
   14#include "AUI/Image/IAnimatedImageFactory.h"
   15#include <webp/mux_types.h>
   16
   17struct WebPAnimDecoder;
   18
   22class WebpImageFactory : public IAnimatedImageFactory {
   23public:
   24    explicit WebpImageFactory(AByteBufferView buffer);
   25
   26    ~WebpImageFactory();
   27
   28    AImage provideImage(const glm::ivec2& size) override;
   29
   30    bool isNewImageAvailable() override;
   31
   32    glm::ivec2 getSizeHint() override;
   33
   34    bool hasAnimationFinished() override;
   35
   36private:
   37    size_t mWidth;
   38    size_t mHeight;
   39
   43    size_t mCurrentFrame = -1;
   44    size_t mFrameCount;
   45    AVector<std::chrono::milliseconds> mDurations;
   46    size_t mLoopsPassed = 0;
   47    size_t mLoopCount;
   48    bool mAnimationFinished = false;
   49    std::chrono::time_point<std::chrono::system_clock> mLastTimeFrameStarted;
   50
   51    static constexpr APixelFormat PIXEL_FORMAT = APixelFormat(APixelFormat::RGBA_BYTE);
   52
   53    void loadNextFrame();
   54
   55    WebPData mFileData;
   56    WebPAnimDecoder* mDecoder = nullptr;
   57    uint8_t* mDecodedFrameBuffer = nullptr;
   58    int mDecodedFrameTimestamp = 0;
   59};
Acts like std::string_view but for AByteBuffer.
Definition AByteBufferView.h:24
Owning image representation.
Definition AImage.h:25
Pixel in-memory format descriptor (type, count and order of subpixel components).
Definition APixelFormat.h:27
A std::vector with AUI extensions.
Definition AVector.h:39
Produces images related to an animation.
Definition IAnimatedImageFactory.h:19
bool hasAnimationFinished() override
Returns true, if last provided frame was last (within one cycle of animation)
glm::ivec2 getSizeHint() override