2022-02-23 21:04:18 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//
|
|
|
|
// EmulationStation Desktop Edition
|
|
|
|
// GIFAnimComponent.h
|
|
|
|
//
|
|
|
|
// Component to play GIF animations.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ES_CORE_COMPONENTS_GIF_ANIM_COMPONENT_H
|
|
|
|
#define ES_CORE_COMPONENTS_GIF_ANIM_COMPONENT_H
|
|
|
|
|
|
|
|
#include "GuiComponent.h"
|
2022-03-05 21:12:50 +00:00
|
|
|
#include "ThemeData.h"
|
2022-03-05 19:56:47 +00:00
|
|
|
#include "renderers/Renderer.h"
|
|
|
|
#include "resources/TextureResource.h"
|
|
|
|
#include "utils/MathUtil.h"
|
|
|
|
|
|
|
|
#include <FreeImage.h>
|
|
|
|
#include <chrono>
|
2022-02-23 21:04:18 +00:00
|
|
|
|
|
|
|
class GIFAnimComponent : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GIFAnimComponent();
|
2022-03-06 11:53:20 +00:00
|
|
|
~GIFAnimComponent();
|
2022-03-05 19:56:47 +00:00
|
|
|
|
|
|
|
void setAnimation(const std::string& path);
|
|
|
|
void setKeepAspectRatio(bool value) { mKeepAspectRatio = value; }
|
|
|
|
void setPauseAnimation(bool state) { mExternalPause = state; }
|
|
|
|
|
|
|
|
void resetFileAnimation() override;
|
|
|
|
void onSizeChanged() override;
|
|
|
|
|
|
|
|
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme,
|
|
|
|
const std::string& view,
|
|
|
|
const std::string& element,
|
|
|
|
unsigned int properties) override;
|
|
|
|
|
|
|
|
void update(int deltaTime) override;
|
2022-02-23 21:04:18 +00:00
|
|
|
|
|
|
|
private:
|
2022-03-05 19:56:47 +00:00
|
|
|
void render(const glm::mat4& parentTrans) override;
|
|
|
|
|
2022-03-06 11:53:20 +00:00
|
|
|
static inline unsigned int readProc(void* buffer,
|
|
|
|
unsigned int size,
|
|
|
|
unsigned int count,
|
|
|
|
fi_handle handle)
|
|
|
|
{
|
|
|
|
return static_cast<unsigned int>(
|
|
|
|
fread(buffer, size, count, reinterpret_cast<FILE*>(handle)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int writeProc(void* buffer,
|
|
|
|
unsigned int size,
|
|
|
|
unsigned int count,
|
|
|
|
fi_handle handle)
|
|
|
|
{
|
|
|
|
return static_cast<unsigned int>(
|
|
|
|
fwrite(buffer, size, count, reinterpret_cast<FILE*>(handle)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int seekProc(fi_handle handle, long offset, int origin)
|
|
|
|
{
|
|
|
|
return fseek(reinterpret_cast<FILE*>(handle), offset, origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline long int tellProc(fi_handle handle)
|
|
|
|
{
|
|
|
|
return ftell(reinterpret_cast<FILE*>(handle));
|
|
|
|
}
|
|
|
|
|
2022-03-05 19:56:47 +00:00
|
|
|
std::shared_ptr<TextureResource> mTexture;
|
|
|
|
std::vector<uint8_t> mPictureRGBA;
|
|
|
|
size_t mFrameSize;
|
|
|
|
|
|
|
|
std::chrono::time_point<std::chrono::system_clock> mAnimationStartTime;
|
2022-03-06 11:53:20 +00:00
|
|
|
FILE* mAnimFile;
|
|
|
|
FreeImageIO mAnimIO;
|
2022-03-05 19:56:47 +00:00
|
|
|
FIMULTIBITMAP* mAnimation;
|
|
|
|
FIBITMAP* mFrame;
|
|
|
|
std::string mPath;
|
|
|
|
std::string mStartDirection;
|
|
|
|
std::string mDirection;
|
|
|
|
int mTotalFrames;
|
|
|
|
int mFrameNum;
|
|
|
|
int mFrameTime;
|
|
|
|
|
|
|
|
unsigned int mFileWidth;
|
|
|
|
unsigned int mFileHeight;
|
|
|
|
|
|
|
|
double mFrameRate;
|
|
|
|
float mSpeedModifier;
|
|
|
|
int mTargetPacing;
|
|
|
|
int mTimeAccumulator;
|
|
|
|
int mLastRenderedFrame;
|
|
|
|
int mSkippedFrames;
|
|
|
|
|
|
|
|
bool mHoldFrame;
|
|
|
|
bool mPause;
|
|
|
|
bool mExternalPause;
|
|
|
|
bool mAlternate;
|
|
|
|
bool mKeepAspectRatio;
|
2022-02-23 21:04:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ES_CORE_COMPONENTS_GIF_ANIM_COMPONENT_H
|