GIF - Horizon-NTH/HorizonGUI GitHub Wiki

GIF

The GIF class in the hgui::kernel namespace is designed for handling animated GIF image data. It encapsulates GIF information in the form of a structure (GIFData) and provides functions for retrieving GIF data and frames from a file. The class is defined in the header file GIF.h and utilizes the stb_image library to handle image loading.

GIFData Structure

The GIFData structure represents essential information about a GIF, including width, height, number of frames, color channels, and pixel data.

  • Size<unsigned> size: Size of the GIF in pixels.
  • unsigned int framesCount: Number of frames in the GIF.
  • channels channel: color channels of the GIF.
  • GIFData::data pixels: Vector of frames, each containing pixel data and delay.

using delay = std::chrono::milliseconds;
using frame = std::pair<stbi_uc*, delay>;
using data = std::vector<frame>;

  • GIFData::pointer ptr: Unique pointer to manage pixel data memory.

using pointer = std::unique_ptr<stbi_uc, void(*)(stbi_uc*)>;

Constructors

  • explicit GIF(const std::string& gifPath): Constructs a GIF object by specifying the path to the GIF file.

  • explicit GIF(GIFData&& data): Constructs a GIF object using GIF data provided as a rvalue reference.

Note: The parameter is a rvalue reference. Be sure to use std::move when passing data, and avoid accessing the old data afterward.

Member Functions

  • GIFData& get_data(): Retrieves the GIF data stored in the GIF object.

  • unsigned int get_frames_count() const: Retrieves the GIF'a frames count.

  • size get_size() const: Retrieves the size of the GIF (dimensions).

  • Frame get_frame(unsigned int frameNumber) const: Retrieves a specific frame of the GIF, including the image and delay.

using Frame = std::pair<std::shared_ptr<Image>, GIFData::delay>;

  • void set_data(GIFData&& newData): Sets the GIF data in the GIF object to the provided GIFData structure as a rvalue reference.

Note: The parameter is a rvalue reference. Be sure to use std::move when passing data, and avoid accessing the old data afterward.

  • void set_delay(const GIFData::delay& delay, unsigned int frameNumber): Sets the delay for a specific frame in the GIF.

  • void set_delay(const std::vector<GIFData::delay>& delays): Sets delays for all frames in the GIF.

Example Usage

#include <hgui/header/GIF.h>

// Example Usage of GIF class
std::string gifPath = "path_to_gif.gif";
hgui::kernel::GIF gif(gifPath);

// Get the GIF data
GIFData& gifData = gif.get_data();

// Access the size of the GIF
size gifSize = gif.get_size();

// Access a specific frame
GIF::Frame gifFrame = gif.get_frame(0);

// Process or display the GIF

Note: In the "Example Usage" section, replace "path_to_gif.gif" with the actual path to the GIF file you want to use.

⚠️ **GitHub.com Fallback** ⚠️