ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
esphome::snapshot::GifWriter Class Reference

Writes an animated GIF a frame at a time, so a long recording is never held in memory. More...

#include <gif.h>

Data Structures

struct  ColorBin
 How many pixels of one colour there are in the frame, and the sum of their red, green and blue. More...
 

Public Member Functions

 GifWriter (FILE *file, int width, int height)
 
bool write_header ()
 Write the start of the file. This must come first. The animation repeats forever.
 
bool write_frame (const uint8_t *bgr, size_t row_stride, unsigned delay_centiseconds)
 Add a frame from three bytes per pixel in blue, green, red order, topmost row first, with row_stride bytes from the start of one row to the start of the next.
 
bool write_trailer ()
 Write the end of the file. This must come last.
 

Protected Member Functions

size_t build_palette_ (uint8_t *palette)
 Choose up to 256 colours for the frame in bins_, storing them as red, green, blue triples in palette and which one each colour is nearest in palette_index_.
 

Protected Attributes

FILE * file_
 
int width_
 
int height_
 
std::vector< ColorBin > bins_
 
std::vector< uint16_t > used_colors_
 
std::vector< uint8_t > palette_index_
 
std::vector< uint8_t > indices_
 
std::vector< uint8_t > output_
 

Detailed Description

Writes an animated GIF a frame at a time, so a long recording is never held in memory.

A GIF frame can use at most 256 colours. Each frame gets its own colour table, chosen from what is in that frame, so a frame with 256 colours or fewer is stored exactly.

Definition at line 15 of file gif.h.

Constructor & Destructor Documentation

◆ GifWriter()

esphome::snapshot::GifWriter::GifWriter ( FILE * file,
int width,
int height )

Definition at line 124 of file gif.cpp.

Member Function Documentation

◆ build_palette_()

size_t esphome::snapshot::GifWriter::build_palette_ ( uint8_t * palette)
protected

Choose up to 256 colours for the frame in bins_, storing them as red, green, blue triples in palette and which one each colour is nearest in palette_index_.

Returns how many were chosen.

Definition at line 149 of file gif.cpp.

◆ write_frame()

bool esphome::snapshot::GifWriter::write_frame ( const uint8_t * bgr,
size_t row_stride,
unsigned delay_centiseconds )

Add a frame from three bytes per pixel in blue, green, red order, topmost row first, with row_stride bytes from the start of one row to the start of the next.

The frame is shown for delay_centiseconds hundredths of a second.

Definition at line 224 of file gif.cpp.

◆ write_header()

bool esphome::snapshot::GifWriter::write_header ( )

Write the start of the file. This must come first. The animation repeats forever.

Definition at line 132 of file gif.cpp.

◆ write_trailer()

bool esphome::snapshot::GifWriter::write_trailer ( )

Write the end of the file. This must come last.

Definition at line 277 of file gif.cpp.

Field Documentation

◆ bins_

std::vector<ColorBin> esphome::snapshot::GifWriter::bins_
protected

Definition at line 42 of file gif.h.

◆ file_

FILE* esphome::snapshot::GifWriter::file_
protected

Definition at line 39 of file gif.h.

◆ height_

int esphome::snapshot::GifWriter::height_
protected

Definition at line 41 of file gif.h.

◆ indices_

std::vector<uint8_t> esphome::snapshot::GifWriter::indices_
protected

Definition at line 45 of file gif.h.

◆ output_

std::vector<uint8_t> esphome::snapshot::GifWriter::output_
protected

Definition at line 46 of file gif.h.

◆ palette_index_

std::vector<uint8_t> esphome::snapshot::GifWriter::palette_index_
protected

Definition at line 44 of file gif.h.

◆ used_colors_

std::vector<uint16_t> esphome::snapshot::GifWriter::used_colors_
protected

Definition at line 43 of file gif.h.

◆ width_

int esphome::snapshot::GifWriter::width_
protected

Definition at line 40 of file gif.h.


The documentation for this class was generated from the following files: