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

WebP codec, both the lossless and the lossy bitstream. More...

Go to the source code of this file.

Functions

void tiny_webp_plane_codes (uint8_t *out)
 Fills in the table that maps a short distance code to a nearby pixel.

Variables

const TinyCodec tiny_codec_webp
 The WebP codec.

Detailed Description

WebP codec, both the lossless and the lossy bitstream.

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

Function Documentation

◆ tiny_webp_plane_codes()

void tiny_webp_plane_codes ( uint8_t * out)

Fills in the table that maps a short distance code to a nearby pixel.

The 120 entries are derived rather than shipped, from the rule that they are every offset with a row of 0 to 7 and a column of -7 to 8 naming an already written pixel, ordered by squared distance, then by descending row, then by descending column. That saves 120 bytes of the module and is only safe if the derivation is exactly right, so this exists for the test that checks it against the specification's own listing.

Parameters
outReceives 120 bytes, each a row in its high nibble and eight minus a column in its low nibble.

Variable Documentation

◆ tiny_codec_webp

const TinyCodec tiny_codec_webp
extern

The WebP codec.

Reads the simple and the extended container: a bare VP8 or VP8L chunk, or a VP8X file carrying any of ALPH, ICCP, EXIF and an animation. An animation decodes its first frame composited onto the canvas the file declares, and probe reports the frame count, so an animation is identifiable without decoding it; composing or re-timing frames is out of scope, as it is for GIF.

Lossless is complete: all four transforms, the color cache, meta Huffman groups and LZ77 backward references. Lossy decodes an intra coded frame, which is every still image the format holds, with both loop filters. An ALPH chunk is read whether it is stored raw or through the lossless coder, and its three filtering methods are undone.

Encoding writes lossless for TinyEncodeOpts::lossless and lossy otherwise. The lossy encoder is intra only: it searches the 16x16 and 4x4 luma modes with a rate weighted metric, and its quality number is mapped so that a given quality lands within a few percent of cwebp -q on both size and PSNR.

Note
There is no scaled or region decode. Both bitstreams are one sequential pass whose predictors reach backward across the whole image, so a decoder cannot start in the middle of one or skip a part of it: lossless predicts from the pixel above and to the left and copies from anywhere already written, and lossy's intra prediction chains the same way. TinyDecodeOpts is honored by decoding the frame and then taking the region, which is what the contract permits and what a progressive JPEG does for the same reason.