tinyimg 1.0.0
Lightweight image manipulation library for Cloudflare Workers
Loading...
Searching...
No Matches
lzw.h File Reference

The variable width LZW shared by the GIF and TIFF codecs. More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Classes

struct  TinyLzwTable
 The dictionary a stream builds as it is read. More...
struct  TinyLzwReader
 A code stream being read, in either bit order and framing. More...

Macros

#define TINY_LZW_MAX_BITS   12u
#define TINY_LZW_CODES   (1u << TINY_LZW_MAX_BITS)

Functions

void tiny_lzw_init (TinyLzwReader *reader, const uint8_t *data, size_t size, size_t at, int chained, int msb)
 Points a reader at a stream.
int tiny_lzw_expand (TinyLzwReader *reader, TinyLzwTable *table, uint32_t code_bits, int early, uint8_t *out, size_t capacity)
 Expands a stream into a byte plane.

Detailed Description

The variable width LZW shared by the GIF and TIFF codecs.

Author
Gregory Mitchell (me@gm.nosp@m.itch.nosp@m.215.x.nosp@m.yz)
Version
1.0.0
Date
2026-09-02

Macro Definition Documentation

◆ TINY_LZW_CODES

#define TINY_LZW_CODES   (1u << TINY_LZW_MAX_BITS)

How many codes a dictionary can hold, which is all a twelve bit code names.

◆ TINY_LZW_MAX_BITS

#define TINY_LZW_MAX_BITS   12u

Codes never exceed twelve bits in either format.

Function Documentation

◆ tiny_lzw_expand()

int tiny_lzw_expand ( TinyLzwReader * reader,
TinyLzwTable * table,
uint32_t code_bits,
int early,
uint8_t * out,
size_t capacity )

Expands a stream into a byte plane.

Stops at the stream's end code, at the end of the buffer, or when the plane is full, whichever comes first. A stream that stops early leaves the rest of the plane as the caller filled it, which is what lets a truncated file decode the rows that did arrive.

Parameters
readerThe reader, positioned at the first code.
tableScratch for the dictionary, which the caller owns.
code_bitsRoot symbol width, so the first codes are one bit wider.
earlyNon-zero to widen a code one entry early, which is TIFF's rule.
outDestination plane.
capacityHow many bytes the plane holds.
Returns
int TINYIMG_OK, or TINYIMG_ERR_CORRUPT for a code the dictionary cannot explain.

◆ tiny_lzw_init()

void tiny_lzw_init ( TinyLzwReader * reader,
const uint8_t * data,
size_t size,
size_t at,
int chained,
int msb )

Points a reader at a stream.

Parameters
readerThe reader.
dataThe bytes.
sizeNumber of bytes.
atOffset of the first code.
chainedNon-zero when the data is framed in sub-blocks.
msbNon-zero to read most significant bit first.