ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
lzss.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
6namespace esphome::lzss {
7
21class Lzss {
22 public:
24 static constexpr uint8_t HASH_BITS = 8;
26 static constexpr size_t MAX_CHAIN = 32;
29 static constexpr size_t WINDOW = 512;
31 static constexpr size_t MAX_MATCH = 65536;
34 static constexpr size_t CHAIN_WORDS = (size_t{1} << HASH_BITS) + WINDOW;
35
37 Lzss(const uint8_t *dictionary, size_t dictionary_size)
39
40 size_t dictionary_size() const { return this->dictionary_size_; }
41
44 size_t compress(const uint8_t *in, size_t size, uint8_t *out, size_t capacity, uint16_t *chains) const;
47 size_t expand(const uint8_t *in, size_t size, uint8_t *out, size_t capacity) const;
48
49 protected:
51 uint8_t byte_at_(const uint8_t *data, size_t pos) const;
52
53 const uint8_t *dictionary_;
55};
56
57} // namespace esphome::lzss
LZSS compression of a block of data on its own, with a preset dictionary: text that both ends hold,...
Definition lzss.h:21
static constexpr size_t MAX_CHAIN
How many earlier positions the compressor tries for each match; more finds longer matches,...
Definition lzss.h:26
static constexpr size_t MAX_MATCH
The longest match, as the decoder reads a length code of at most 16 bits after the first.
Definition lzss.h:31
static constexpr uint8_t HASH_BITS
The compressor finds earlier positions starting with the same two bytes through a hash table of this ...
Definition lzss.h:24
static constexpr size_t CHAIN_WORDS
The working space compress() needs: the latest position for each hash, then the previous one for each...
Definition lzss.h:34
const uint8_t * dictionary_
Definition lzss.h:53
uint8_t byte_at_(const uint8_t *data, size_t pos) const
The byte at pos counting from the start of the dictionary, with data following it.
Definition lzss.cpp:94
size_t compress(const uint8_t *in, size_t size, uint8_t *out, size_t capacity, uint16_t *chains) const
Compress size bytes into out, which holds capacity bytes, using chains (CHAIN_WORDS words) as working...
Definition lzss.cpp:98
Lzss(const uint8_t *dictionary, size_t dictionary_size)
Definition lzss.h:37
size_t dictionary_size() const
Definition lzss.h:40
static constexpr size_t WINDOW
Part of the format: a match reaches back at most this far, and offsets take the bits that the bytes b...
Definition lzss.h:29
size_t dictionary_size_
Definition lzss.h:54
size_t expand(const uint8_t *in, size_t size, uint8_t *out, size_t capacity) const
Expand size bytes into out, which holds capacity bytes; returns the length, or SIZE_MAX if the data i...
Definition lzss.cpp:170
std::vector< uint8_t > & out
Definition gif.cpp:49
uint16_t size
Definition helpers.cpp:44
size_t size_t pos
Definition helpers.h:1530
uint16_t uint16_t & capacity
Definition helpers.cpp:44