Tuesday, October 21, 2014

databending and glitch art primer part 3: the GIF

it's been more than a year since i posted to this blog at all, and more than five years since i posted part 2 of my glitch art primer. so much has changed in the glitch art scene in that time, some of which i may touch on in passing, but let's not get bogged down in nostalgia. we have art to make.

GIF, as seemingly everyone on the internet knows, is an image format that has become synonymous with the fact that it supports animation (even though it wasn't originally intended to). it's extremely popular and in recent years has become popular among glitch artists as well.

i run a tumblr blog called glitchgifs, where i'm regularly asked some variation of the question "how do i make glitch gifs?" my usual answer is that there are three basic ways:
  1. glitch a still image several times, then animate it.
  2. glitch a video, then make gifs from that.
  3. glitch a gif file—the most difficult because the file will likely break and then you'll need to use a program like irfanview to retrieve the damaged frames.
most "glitch gifs" that you see online are made using methods 1-2. in fact, i suspect that the majority of people who ask how to make glitch gifs are really asking how to do the technique that's come to be known as datamoshing. there are lots of great glitch tutorials and resources out there for these methods, so i don't want to waste anyone's time reinventing the wheel. instead, i want to talk more about how the GIF format works, and how you can take advantage of some of its idiosyncrasies.

indexed color

unlike other common image formats (most of which use RGB color mode), GIF uses indexed color mode. "indexed" here means that gifs handle color using a color table that defines every color used in the image. this has a lot of implications, first and foremost being that gifs have a very limited color palette—usually no more than 256. this is a huge difference compared to formats like JPG and PNG that support up to millions of colors.

it's notable that the color table is usually stored in the gif file itself. that means that we can glitch it, if we're careful. just take a gif and change the data in the table (and only that data):

you have to be pretty precise to do this without breaking it—the global color table (when present) starts at byte 14 usually starts around byte 44-45, and each 8-bit color takes up 3 6 bytes (or 6 hex characters). so your best bet is probably using a hex editor, though perhaps some kind soul will write a web app or processing script that makes it easy to replace the colors in an existing gif in this fashion. (hint, hint)


another classic feature of GIF is support for transparency, which is handled by defining one of the colors in the table as transparent. but this can go wrong: google+ used to have a glitch in its gif uploader that confused transparent pixels with solid black ones, and vice versa. this created bizarre ghosting artifacts, as it would just lay the frames on top of each other, with some bits invisible so you could see the frames beneath:

 g+ has since been fixed but you can create similar effects using tools like klear.me:

if you're super handy with a hex editor, you can even play with transparency there by manipulating the graphic control extension block. when present, this block will be eight bytes long, with the first three bytes being 21 F9 04 and the eighth byte always being 00. if present at all, there will be one GCE block for each frame in the animation.

again: if it's used at all, there will be one such block at the beginning of each frame... meaning you could even use different settings for each frame! more detailed information here.


early computer graphic designers using limited color palettes often had to use tricks to create the illusion of color depth. GIF uses a trick called dithering—simulating colors using randomly- or algorithmically-produced patterns of dots. with dithering and a well-chosen color table, it's possible to create gifs with almost-photorealistic colors.

each individual dither is just one pixel. that can be awfully small on today's screens, so to really play with dithering, you may want to enlarge them, like in daniel temkin's dither studies. to enlarge an image and get that "big pixel" look that i love so much, the setting is usually called something like nearest neighbor or preserve edges/crisp edges. many web browsers now support this as well, which means you can load up a gif in a web app like my HTML5 image filter, crank up the size slider, and watch the pixels dance. 

(ironically, this feature works beautifully in browsers like firefox, even though the actual CSS filters themselves don't work in that browser, whereas the filters work in chrome, but chrome doesn't currently support "crisp edge" resizing!)

when upsizing your pixels in this fashion, the usual advice is to always go in powers of 2—200%, 400%, 800%, 1600%, etc. this will ensure that you get the crispest edges possible. but hey, maybe you want your edges to be a little messy...

more fun with color tables

if it's possible to get almost-photolike colors in a gif with the right color table, then from a glitch artist's perspective, we might be more interested in going the other way—deliberately using the "wrong" color tables to accentuate the dithering. for example, the "bitcrushed" look used by artists like jonCates involves extremely small color tables: as small as 2-4 colors.

i've taken a different approach with my color tables series. a year or so ago i was using photoshop's "save for web" dialog, preparing to save an image, when something about the color table caught my eye. the colors, the composition of how they were arranged (sorted by luminance)... these were beautiful and i was compelled to save it and take a screenshot. this became glitch color table #1.

so i started collecting color tables and posting them on tumblr. i've collected and published a few dozen now, many of them derived from glitched or bent source images. but these color tables aren't just pretty pictures—they're also tools for creating other artworks. by deliberately applying a color table that has few colors in common with the source material, we can get some unusual effects, as the software is forced to choose the "best" of many bad options. glitch color table #1 has no green in it, so watch how it deals with grass:

of course, you don't have to start a color table collection. you can load color tables directly from another gif, or use a palette editor program to design or edit your own dream color table. and though you're welcome to download and use mine, there are probably bunches more color tables floating around online. want to use the color palette from the original nintendo NES or gameboy? get the color tables here!

i've been using this trick a lot lately, such as in my dither sunsets series and my latest video. i start out by shrinking the source image/video at the beginning, which allows me to enlarge it back later once the dithering has been added. then i try it out with different color tables, and when i find a result i like, i enlarge it again. i can even animate them by exporting several different versions with slightly different dither settings, and then stringing them together into a gif:

so there you have it: GIF is far more than just an export format for silent video loops. it is a unique format to be mastered, with its own world of artifacts waiting to be explored.¶