SYSTEM.ARCHIVE // LOGS

The Archive

A log of thoughts, esoteric tools, recommended reading, and unorganized debris from the production process.

Subscribe via RSS
← Back to Archive Index
2026-06-11 GLITCH & DEGRADATION

databend.jpg: Image Databending in the Browser

Databending means editing a file's raw bytes without regard for what format it's in, for example opening an image as audio or a sound file in a text editor, changing some data, and opening it again as what it was. Building DATABEND, my playground for doing this to sound, changed how I think about files. I started seeing them as bytes rather than as audio or pictures: a spectrogram is an image, and a corrupted header is something to play with rather than a problem to fix. I had a tool for breaking sound but not one for images, so I made databend.jpg.

How a JPEG file is put together

A JPEG file is a sequence of segments, each starting with a two-byte marker: 0xFF followed by a byte that says what the segment is. The file starts with FFD8 (start of image) and ends with FFD9 (end of image). In between come the headers: application segments such as APP0 (FFE0, used by JFIF) and APP1 (FFE1, used by Exif), the quantization tables (FFDB), the frame header with the image size and colour components (FFC0 for baseline JPEG), and the Huffman tables (FFC4). Then comes FFDA, start of scan, followed by the entropy-coded image data, which makes up most of the file.

This is why where you edit matters so much:

  • Frame header or Huffman tables. Changing the image size, component layout or code tables usually leaves a file the decoder refuses to open.
  • Quantization tables. The file still decodes, but every block's frequency coefficients are scaled differently, so contrast, colour and blockiness change across the whole image.
  • Scan data after FFDA. A changed byte throws the Huffman decoder out of step. Because each block's DC (average) value is stored as a difference from the previous block, the error carries forward: everything after the edit can shift in colour and brightness, and blocks slide sideways.

Two more details matter. Inside scan data a literal 0xFF byte is written as FF 00, so writing a stray FF followed by something else can be read as a marker and break the file. And if the encoder used restart markers (FFD0 to FFD7), decoding resynchronises at each one, so an error only spreads as far as the next restart. The usual advice for hand-editing is to leave everything up to FFDA alone and make small changes in the scan data.

The sandbox

The current version doesn't edit JPEG bytes. It works on decoded pixels in a canvas and imitates some familiar glitch looks:

  • Slice shift moves horizontal bands sideways by different amounts, like a damaged videotape.
  • Colour separation offsets the red and blue channels horizontally in opposite directions.
  • Pixel melt smears pixels down some columns.
  • Sine wobble bends rows sideways with a sine wave.
  • Byte scrambler overwrites rectangular blocks with generated stripe and noise patterns.

It's a sketchbook for figuring out how images break, not an attempt at a photo editor. The bigger version I'm working on is meant to get closer to the file itself: full-resolution rendering, node-based routing, stream bending, and operating on the actual bytes rather than imitating the results. What I like about databending is that it turns mistakes into material, and it makes it obvious that every image or song is structure held together by conventions a decoder expects.

In the lab below you can load one of three generated images or upload your own, adjust the five effects, switch on an LFO that animates them, reset everything to zero, and export the frame as a PNG.

// LOADING LAB…