Fri Mar 30 15:29:30 EDT 2012

fun with animated images

(Crossposted from my tumblr. Hey, read this other thing, too!)

Anonymous asked: What kind of details get lost? I don’t know if it’s just me, but they literally look the same.:

It’s probably more noticeable to me, since I had been staring at them for hours while working on them, but the quality goes down dramatically:

Whenever I post the animated version of something, I don’t know, I just hate seeing all the work I tried to do get all grainy and flat. :’\

GIF is a fairly old format, standardized in 1989, and therefore has some quirks characteristic of its time. One of those is its support of color.

GIF is palette-based, it can display any color in the 24-bit RGB colorspace, but the actual bitmap only has 8 bits of intensity, which means the final image can only have 256 different colors. This is not obvious with flat-shaded illustrations, but becomes very obvious with gradients. Here’s a 24-bit PNG:

And the same thing, converted to GIF:

Imagemagick tried very hard to make up for the difference in gamut using dithering, but that can only go so far.

You would reasonably expect that GIF would go the way of all the other dinosaur image formats, like XPM and PPM, except for one thing: it’s the only reasonably popular image format that supports animation.

You would expect PNG, the GIF replacement, to support animation: and indeed it does, as the MNG format, first released 11 years ago.

(This is territory I don’t quite know as well: if I get anything wrong, speak up.)

As you may have noticed by the fact that it’s older than most Tumblr users, yet you’ve never heard of it, MNG hasn’t exactly taken the world by storm. There’s a couple reasons why:

1.) Many, many, many are the clever tricks that can be used to compress video. GIF uses hardly any of them, MNG uses quite a lot. This means that its reference implementation is unusually large compared to most static image compression formats, simply because it does so much.

2.) They named it MNG. When you’re writing something that uses GIFs, but doesn’t support GIF animation, then your software is broken, and your users will complain. You can explain to them that your software doesn’t actually need to use GIF animations, that the spec is a mess, and also that coding it would be really hard and you don’t wanna, and they will nod along, then dump your half-assed piece of shit, and go give their money to your competitors. Therefore, if you support GIF, you have to support GIF animation.

MNGs, however, aren’t PNGs. Different name, different library. MNG support doesn’t come free with importing libpng. Two separate and different things, with no possibility of confusion on the user’s end, and absolutely no incentive to support it on the developer’s end.

3.) Programmers generally don’t like GIF animations. It’s terribly inefficient at compressing video, it can’t contain sound, most implementations don’t provide playback controls, it unnecessarily complicates a lot of image-display code that would otherwise be very simple… Basically, it poorly solves a problem that doesn’t exist. Why not just use a real video format, like AVI?

Additionally, GIF is often used by uneducated users to do stupid things. (eg: gifsets on tumblr, which replicate the functionality of a 10 second Youtube video by using 10 times the bandwidth; Blingee) If there’s anything programmers hate more than sunlight, it’s people solving problems badly. Witness the widespread hate for Visual Basic and Access. (Both Microsoft products, hmm.)

4.) Up to the year 2003, Firefox could actually decode MNG. But because of #1, this required using a lot of code to support a feature used by essentially nobody, and the Firefox team is under constant fire for their awful, bloated codebase, even though any modern web browser has to be enormously complex. So they ripped out that code and added a small hack to the PNG decoder that would recognize a series of PNG files pasted together as an image format. (See also!) This is the APNG format.

This minor hack is quite similar to something Netscape did back in 1996, with the release of Netscape Navigator 2.0. Originally, GIF animations only played once. (Loops didn’t exist) The manifest uselessness of GIF animations, combined with the general jankiness of the implementation, meant that essentially nobody used them, like how nobody uses the physical units in CSS.

But! GIF has an Application Extension Block, which allows programs to set custom attributes in a somewhat standardized way. This allowed Netscape to add a field that specifies how many times you want the animation to repeat. (0 to 65535, 0 for “forever”. The field’s an unsigned short, of course.) This is also why every GIF animation on the internet contains the string NETSCAPE2.0.

The architecture astronauts of the libpng group were outraged. Those dirty software vendors had taken a perfectly functional piece of standards compliant code, and thrown it away just because it was huge and useless. Then they had the incredible effrontery to replicate one of the worse excesses of the Browser Wars! The bastards were siding with the Visual Basic crowd, rejecting a technically superior product for boring reasons of practicality.

Therefore libpng rejected the APNG extension, to show those jerks who’s boss. So here we are in the year 2012, stuck with 80s technology, because nobody can agree to use software that doesn’t suck.

This reminds me of an old truth about computers, which is, that computer novices hate computers.

As in, they hate the machine. Everywhere the novice looks, he is faced with bewildering complexity. Vast bulwarks of obtuse, impenetrable metaphors confront him at every turn, making even the simplest task complex. Even when he figures out how to force the machine to do what he wants it to do, by trial and painful error; vast and invisible forces can at any time rip the rug out from under his feet, and force him to begin again. Software updates, computer viruses, bit rot, inexplicable configuration changes, even mundane hardware failure. The computer is cyclopean and faceless, a machine paradoxically both indifferent and supremely malevolent. The computer doesn’t care about you want to do, and when it breaks, it breaks because it hates you. The ancient mistake of anthropomorphizing: the novice doesn’t understand the rules, and so sees intent where there is none.

The expert, on the other hand, likes computers. They do what you tell them. In a real and fundamental way, software can be perfected. There is no room for bugs in 2+3=5, and this can be extended to any piece of software. It’s all just math.

In fact, the only thing that stands in the way of the perfectability of software is the humans.

Any time the expert encounters a bug, or a mangled sentence, or a broken piece of software, she knows that a human did this.

When the HTML5 <video> tag is rendered useless by political infighting between Apple and People Who Aren’t Assholes, it’s not the fault of the computers. It’s the fault of the humans.

When Android phones executed everything typed into them as root, this was the fault of humans. When a Patriot antimissile battery missed an incoming SCUD, resulting in the deaths of 28 soldiers, this was the fault of humans.

Why are programmers such miserable bastards all the time? It’s because they get maybe two solid hours of flow a day, and then have to descend from the platonic plane of pure math to deal with all the other stupid, willfully ignorant humans.

Posted by Samuel Bierwagen | Permanent link