How best to implement a GIF loading class?
<p><strong>The task:</strong></p>

<p>I want to write a C++ header file that can load a given GIF file and turn it into RGBA array of pixels.</p>

<p><strong>The problems:</strong></p>

<p>I found trying to read the specification confusing because certain blocks (such as comments) can occur anywhere in the file. I also tried reading source code for other GIF loading files but I found these also highly confusing. I had attempted writing code for it, but after it went horribly wrong, I then deleted it and postponed trying to do it as it wasn't required: it now is.</p>

<p><strong>The restrictions:</strong></p>

<p>I don't wish to use an external library (suggesting boost is a bit of a cliche here) or pre-built code, as I want to understand what is going, but to write my own code notably for several reasons:</p>

<ol>
<li>So I can repair the code if it goes wrong.</li>
<li>So I can expand the features and incorporate them with other pre-existing classes I have.</li>
<li>To avoid licencing problems:
<ul>
<li>So I don't get sued for misuse (I neither want to pay or be forced to make my code open-source).</li>
<li>So I can bundle the code with, or sell the program (this is unlikely but I'm covering bases here) without any copyright/copyleft issues.</li>
<li>So I can safely give the code to others and be able to tell them they don't have to worry about a licence.</li>
<li>So I can offer the code to a library that lacks GIF loading so they can use it without worrying about licence issues.</li>
</ul></li>
<li>To keep the codebase small (compared to a library of other features).</li>
</ol>

<p>I know that's quite a list and seems unnecessary but when I previously say on stack overflow 'no libraries' people assume it's something optional that they can argue me into submission or force a library down my throat.</p>

<p><strong>The questions:</strong></p>

<p>What is the best way to both understand (I found the specification confusing remember) and implement GIF loading so it converts a GIF (which might be a singular image or a series of images) into an array of pixels? And how best to ignore 'unnecessary' data (at least in regards to the task at hand, so ignoring comments etc) when reading?</p>

<p>For convenience you can assume a pixel array class already exists.</p>

<p>Clear-cut code snippets with explanations would be appreciated on this one.</p>
