⭐ Starforge is a pixel art & animation studio that runs in your browser.
The GIF above was drawn, animated and exported inside Starforge.
Yesterday I said I was writing the GIF encoder by hand. It’s finished, and already sitting behind the Export button in the editor.
How it works
A GIF doesn’t store pixels. It stores a conversation between two sides that build the same notebook and never send it.
The encoder walks the image. The first time it meets a run of pixels it spells the run out, then writes that run in a notebook next to a number. The next time the same run shows up, it sends the number instead of the pixels. The decoder reads those numbers and builds the identical notebook as it goes, which is why the notebook itself never travels, both sides derive it from the same stream.
That’s LZW, and it’s lovely right up until you notice the decoder is permanently one entry behind. It can’t file a new run until it has read the code that comes after it. So when the notebook outgrows the current code width, the two sides widen at different moments, and the encoder has to wait one step longer than feels correct. Get that off-by-one wrong and the file is perfect for a few hundred bytes and then dissolves into confetti. That was my morning.
Receipts
- 545 green tests
- I encoded with my code and decoded with ffmpeg. Every pixel came back identical
- 16 frames of 256×256 encode in 135ms
- Browsers quietly treat any GIF delay under 2 centiseconds as 10, so the encoder floors every frame there.
Draw something at starforge.lacorte.city, export the GIF, and drop it in the comments!
I’ll feature my favorites in the next devlog :D.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.