3 ms·
I actually wrote a GIF decoder over the xmas break (in C for 16 bit DOS for a game project I'm working on). In itself it's not to difficult. Once you've figured
by pan69 5y ago
I actually wrote a GIF decoder over the xmas break (in C for 16 bit DOS for a game project I'm working on). In itself it's not to difficult. Once you've figured out the algorithm of when to add a new phrase to the dictionary and how to extract a code from the bit stream, it's pretty straight forward.
I had a massive bug however and I couldn't for the life of me figure out the issue up until two weeks ago.
Turns out, once you've reached a code size of 12 bits, I was "assuming" you should reset to the root code size, however, you should not. Instead of resetting, you should ignore either increasing or resetting the code size, but just keep reading 12 bits codes from the bit stream because from that point on, all codes read from the stream will be in the dictionary. The encoder will have inserted a Clear Code to reset and start from scratch.
It was a difficult thing to debug but once I wrapped my head around it, it made total sense. It was very satisfying to throw a large collection of GIFs at my decoder and see them being displayed.