ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
gif.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_HOST
4#include <cstddef>
5#include <cstdint>
6#include <cstdio>
7#include <vector>
8
9namespace esphome::snapshot {
10
15class GifWriter {
16 public:
17 GifWriter(FILE *file, int width, int height);
18
20 bool write_header();
24 bool write_frame(const uint8_t *bgr, size_t row_stride, unsigned delay_centiseconds);
26 bool write_trailer();
27
28 protected:
30 struct ColorBin {
31 uint64_t sum[3];
33 };
34
37 size_t build_palette_(uint8_t *palette);
38
39 FILE *file_;
40 int width_;
42 std::vector<ColorBin> bins_;
43 std::vector<uint16_t> used_colors_;
44 std::vector<uint8_t> palette_index_;
45 std::vector<uint8_t> indices_;
46 std::vector<uint8_t> output_;
47};
48
49} // namespace esphome::snapshot
50
51#endif
Writes an animated GIF a frame at a time, so a long recording is never held in memory.
Definition gif.h:15
std::vector< ColorBin > bins_
Definition gif.h:42
std::vector< uint8_t > palette_index_
Definition gif.h:44
std::vector< uint16_t > used_colors_
Definition gif.h:43
std::vector< uint8_t > output_
Definition gif.h:46
GifWriter(FILE *file, int width, int height)
Definition gif.cpp:124
bool write_header()
Write the start of the file. This must come first. The animation repeats forever.
Definition gif.cpp:132
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,...
Definition gif.cpp:224
std::vector< uint8_t > indices_
Definition gif.h:45
bool write_trailer()
Write the end of the file. This must come last.
Definition gif.cpp:277
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 ...
Definition gif.cpp:149
static void uint32_t
How many pixels of one colour there are in the frame, and the sum of their red, green and blue.
Definition gif.h:30