Farbfeld
Farbfeld is the suckless lossless image
format: a 16-byte header, then raw 16-bit RGBA. It is made to be piped between small
tools (png2ff < in.png | filter | ff2png > out.png), not to be
served to browsers. This page mirrors the C tools and has a converter written in
plain JavaScript.
This site's images stay PNG/JPEG on purpose: farbfeld is uncompressed, about 8 bytes per pixel, and no browser can display it, so it would make pages slower.
Convert in your browser
Runs locally in farbfeld.js. Nothing is uploaded. Opaque, untagged images round-trip byte-exact. Browsers decode through a canvas, so colour-profiled PNGs and semi-transparent pixels can shift by a level or two; for archival work use the C tools below.
Use .ff and .fz as images on a page
Browsers can't show these natively, so ffimg.js (pure JS, no
dependencies) fetches the file, decodes it, and swaps the <img> for a
<canvas> that keeps its class, id, style and alt text. Lazy loading works.
<img data-src="photo.fz" alt="A photo" width="320" loading="lazy"> <script src="ffimg.js" defer></script>
Live, each decoded by that script from a different format (no src, so no wasted request):
.ff · 176 KiBRaw farbfeld. Lain, bear hood on.
.ff.gz · 45 KiBGzipped farbfeld. Lain, close-up.
.fz · 20 KiBExperimental fork. Lain, hood off.
Three different pictures, three formats, one script. The hood-on and hood-off shots are frames from the animated GIF on the home page.
| format | what it is |
|---|---|
.ff / .ff.gz | Farbfeld as specified, optionally gzipped. |
.fz | Experimental lossless 8-bit fork (working name): "fz1", alpha flag, u32be width and height, then deflate of per-channel planes predicted with the median edge predictor. Spec is in the header comment of ffimg.js. |
Honest caveat: in a browser benchmark of 8 screenshots and photos, .fz came out about the
size of PNG but slower, since JS decoding costs more than the native PNG decoder. Use these formats for
pipelines and archives, and serve PNG, JPEG or AVIF to visitors. This site does.
node fz-encode.cjs photo.png photo.fz photo.ff # needs node + ImageMagick
The format
BYTES DESCRIPTION 8 "farbfeld" magic value 4 32-bit BE unsigned integer (width) 4 32-bit BE unsigned integer (height) [2222] 4 x 16-bit BE unsigned integers [RGBA] per pixel, row-major
sRGB, not alpha-premultiplied. Extension .ff; compressors append theirs (.ff.bz2).
The whole decoder, as in farbfeld.js:
var dv = new DataView(buf); var w = dv.getUint32(8), h = dv.getUint32(12); for (var i = 0, o = 16; i < w*h*4; i++, o += 2) px[i] = dv.getUint16(o);
Source (C tools)
Mirror of upstream git.suckless.org/farbfeld
at commit 03f1f1f (ISC/0BSD licensed, © Laslo Hunhold). Unmodified;
needs libpng and libjpeg.
farbfeld-03f1f1f.tar.gz SHA256SUMS
tar xzf farbfeld-03f1f1f.tar.gz && cd farbfeld make && sudo make install png2ff < photo.png | bzip2 > photo.ff.bz2
| to farbfeld | from farbfeld |
|---|---|
png2ff, jpg2ff, 2ff (wrapper) |
ff2png, ff2jpg, ff2pam, ff2ppm |