Databending Tutorial

This is an outline of my tutorials on basic databending. You will need a text editing application that does not change text formatting, only file contents, such as TextEdit in Mac OS. You will need a hex editor: for Mac OS I found 0xED very handy. You will need the Audacity audio application. Finally, you will need the Gimp or Photoshop or some other application that can save images files as raw data bytes in RGB format.

Image as Text

Retrieve a JPEG from the Internet or anywhere else
Keep a backup copy
Open it in Preview
Open it in TexEdit

To open the file in TextEdit, control-click on the JPEG file to get a popup menu. Choose the Open with ▶ Other… command and choose TextEdit as the application for opening the file.

You are looking at two different interpretations of the same file, as text and as an image.
Scroll about halfway into the file in TextEdit and add some random text. Save the file.
Go to Preview and click the image to refresh it.

In TextEdit, copy a block of text and paste it in a new location. View your changes in Preview.
In TextEdit, use the Find and Replace command. View your changes in Preview.

Hint: To restrict find and replace to just part of the image, copy a block of text to a new window, run find and replace, then paste it back in.
Hex Editor

As a preliminary step in using the hex editor, let’s take a look at Ted Davis’s online applet HEADer REMIX. You can find it at http://www.teddavis.org/. The Wikipedia page on the JPEG format is also very useful: halfway down the page is a table with information on the structure of the JPEG file header.

Experiment with HEADer_REMIX.
Change values in the quantization table.
Change values in the Huffman tables (this can be very glitchy)
Some changes may result in an image so damaged it can’t be viewed.
You can save your work by control-clicking (right-clicking) on the image to get a popup menu.

Now let’s find the quantization tables with the hex editor.
Open a JPEG file in the the hex editor.
Set the write mode to overwrite (in 0xED, Edit menu, Write Mode ▶ Overwrite)
Set the Search field to use Hex search (use the popup menu on the left edge of the field)
Enter the bytes to find in Search field

FFD8: start of the file.
FFDB: start of a quantization table (there may be more than one)
FFC4: start of a Huffmann table (there may be more than one)
FFC0: start of the frame, with width and height values
FFDA: start of the scan, with the databytes for the compressed image

What is safe to edit? Refer to HEADer_REMIX to get the offsets to the “safe” data.

HEADer_REMIX screenshot

HEADer_REMIX, by Ted Davis

Experiment with editing the header bytes in 0xED. You can use HEADer_REMIX as a guide. Open the glitched files in Preview. Also try to open them in Photoshop. Photoshop is much pickier about what it will open. Try viewing the files in a web browser. Your results may be different in each case. Digital images are really the result of a process: the file format specification, the encoding method, the software that displays them, and the hardware where they are viewed. All elements in the process are “tuned” to give the appearance of stability to the image. Glitching reveals the inherent instability of the image.

If you want to “stabilize” the image, you can save it as a PNG file in Preview. PNG uses lossless compression, so the image should be preserved intact, even though its data representation will be very different from the JPEG file.

Glitching Raw Files

Open a file in Photoshop (8 bit RGB format)
Save it as a copy in Photoshop Raw file format, with the channels in interleaved order.
Open the Raw file.
Photoshop will display a dialog where you can set different attributes of the data. It should already be filled in. If you don’t alter any values, you can import the original image.

Photoshop Raw Dialog

Photoshop Raw Dialog

Try modifying the width. First, just decrease it by 1, then try other values.
Modify both width and height. The total number of pixels must be less than or equal to the original or Photoshop won’t open the file.
What happens if you uncheck interleaving?
What happens if you set the channels to 1 or 4?

Transcoding with Audacity

Launch Audacity.
If necessary, create a new file (File Menu New command).
Choose Import ▶ Raw Data… from the File menu.
Import the data as Unsigned 8 bit PCM with no Endianess and one channel. Leave sample rate at 44100 for now.

Audacity Import Dialog

Audacity Import Dialog

The image opens as audio data. Listen to it.
Cut a section of the data and paste it in a new location.
Export the file as “Other uncompressed files,” with the Options set to RAW (header-less) and Unsigned 8 bit PCM. Give it a new name and a “.raw” extension.
Open the file in Photoshop. Specify the original dimensions, interleaving and bit depth.
Experiment with multiple copy and paste actions.

Hint: Set the selection start and end (length) displays at the bottom of the Audacity window to display samples. When the start and end are both divisible by 3, your selection will match the boundaries of the RGB triplets stored in the Raw file.

Next, try running some of Audacity’s effects on the raw data.
Phaser is a good place to start.
Echo can be interesting.
Equalization is also fun.

It’s generally useful to apply effects that don’t change the file size. If you change the file size, the RGB triplets may no longer be aligned and the dimensions of the file will certainly be different. However, you could get some serious glitching.
Further Experiments

You can of course mix and match all these techniques. Edit raw files in a text or hex editor. Paste text from your favorite story into a raw file. Save the results as a JPEG and glitch it further.

My GlitchSort application may also prove useful for glitching still images. It has a fancier interface than a hex editor, and does some interesting things, including interrupted sorting, color shifting and Fast Fourier Transforms. It even has a user manual.

If you’d like to go from here to glitching video, I particularly recommend Nick Briz’s Glitch Codec Tutorial. You will need to burn a DVD that reboots your Mac or Windows computer into Linux, but the results are worth the trouble. Beyond that, Nick’s tutorial provides some very cogent insight into the culture and politics of software, image and video encoding, intellectual property rights, and glitch art as a community effort. Highly recommended.

Glitchometry, an article by Daniel Temkin in LAB magazine, has some beautiful images produced by applying audio filters to simple geometric shapes. There’s also an article on Glitch Textiles by Phillip David Stearns.

 

1 Response to “Databending Tutorial”


Leave a Reply

You must be logged in to post a comment.