GIFs aren’t limited to 256 colors

Everyone knows that GIF images are limited to 256 colors, right? This has been accepted knowledge since before I started using the web back in 1995. The only problem is, it’s false (where are you now, Snopes?!). GIF images aren’t restricted to 256 colors. They never have been. It looks like people just plum forgot about a part of the specification that allows a way to get around the 256 color limit. File this factoid under your YLSNED folder. Here’s proof, in the form of a GIF image that includes much more than 256 colors:

A GIF image with more than 256 colors

12 Responses to “GIFs aren’t limited to 256 colors”

  1. Kelly Martin Says:

    This isn’t news to me. You’ve been able to specify distinct colormaps on each frame of an animated GIF since the GIF89a standard, if I recall correctly. Note that some GIF viewers will not process these correctly, and if viewed on an 8-bit display may yield starkly unexpected results (including the possibility of palette flashing, if that’s the mode you’ve set in your window manager).

    Of course, I used to write graphics software.

  2. Cyde Weys Says:

    Well Kelly, you’re in the distinct minority of people involved in writing The GIMP. I guess this blog post was targeted at everyone else.

    I also think it’s funny how slowly this GIF renders upon the first view — it’s not animated, but the little 16×16 chunks come in one by one, remarkably slowly. Firefox clearly wasn’t optimized for handling GIFs with more than one image block in them. But then afterwards, the decompressed image is stored in memory, and it renders instantly. Until you lose that cache (the easiest way being restarting Firefox).

  3. drinian Says:

    Neat hack, although it’s still no PNG.

  4. Cyde Weys Says:

    In that it’s supported on more browsers than PNG, then yes, it is no PNG :-P

  5. T2A` Says:

    Old. :P

    Also, it’s not “rendering slowly.” The limitation is that each frame of a GIF can support 256 colors, but each frame can use a different set of 256 colors. That image is over 170 frames long and it doesn’t repeat. That’s not “rendering.”

    Clearly you still don’t understand the issue here. :]

  6. Kelly Martin Says:

    Actually 255 colors. You have to pick one of the 256 to be the “transparent” color in each frame (doesn’t have to be the same one) for this trick to work.

  7. Cyde Weys Says:

    Sorry T2A`, I think you’re the one who doesn’t understand the issue here. This is emphatically not an animated GIF, and thus it doesn’t have multiple frames (try opening it up in an animated GIF editor if you don’t believe me; I have). What it does have a multitude of is image blocks, which are substantively different than animation frames. I’m seeing it rendering slowly in my browser, which is a different process than an animation. I guess Firefox has a lot of overhead in switching image block contexts or something. You can tell it’s a rendering issue and not an animation issue because when you view the image by itself and press refresh, you don’t see the rendering process play out again but the rendered image is still stored in memory. If it was an animated GIF that was set to animate once and then stop, you would see the animation play again upon a refresh.

    And I do believe “rendering” is the proper term to use when a compressed image format is decompressed into a simple bitmap array for display on screen (which is what your browser does with every image format, because it’s not about to re-uncompress the image each time you scroll up and down the page, for instance).

  8. Cyde Weys Says:

    Nevermind, forget everything I just said. Photoshop seems incapable of opening an image like this (it was only showing the first frame). The Gimp correctly shows all 173 frames which are used to generate the complete image. Each one has a 0 ms delay, so the “rendering” process I was seeing was really the image being displayed as it was downloaded.

  9. Loki Says:

    Try importing it into Flash. Easiest way I had to see all 173 frames. Interesting how Flash changes everything.

  10. Cyde Weys Says:

    That would require having whatever program is used to make Flash applets, right?

    I stay as far away from Flash as possible ..

  11. required field Says:

    loads slow as fuck

  12. bancy Says:

    This is a good article