Monthly Archives: October 2014

Parentheses: more than emoticon mouths

emoticonI keep telling my students to use parentheses all the time. I even tell them to parenthesize something like 2+(3*4), even though we know that multiplication has precedence over addition, because it’s a good habit to always be crystal-clear to humans and computers alike.

Sometimes I feel silly for being so dogmatic about this. But I just spent an hour debugging, because (a&0xFF<<24) did not put my alpha value into the top 8 bits of an int. It should have been ((a&0xFF)<<24). Now I feel good again about telling people to use lots of parentheses!

Keeping gif Animations Small

grid of lines of different thicknessesAnimated gifs can be big. A 300-frame animation at 500-by-500 pixels can easily run 25 megabytes (MB) or more.

25 MB doesn’t sound like much these days, but there are still a lot of services out there for whom that’s too big. For example, Tumblr has a 10 MB limit. In order to get my animations down to Tumblr size, I’ve relied on two blunt tools: making each frame smaller (and thus losing detail), and making fewer frames (causing shorter or choppier animation).

Recently, though, I discovered something that surprised me: gif compression depends very much on the directional qualities of your image (unlike, say, JPEG). After the break, some data I’ve collected and some advice. Continue reading