Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing GIF Raster Data - LZW
    primarykey
    data
    text
    <p>I've been trying to decompress GIF's in PHP and seem to have everything except the LZW decompression down. I have saved an image that is shown: <img src="https://i.stack.imgur.com/LWStT.gif" alt="sample image"></p> <p>This image is 3 x 5 like this:</p> <pre><code>Blue Black Black Black Blue Black Black Black Black White White White White White White </code></pre> <p>I decided to go through manually in Binary and parse this file. The result of manual parsing is below. I am still stuck as to how to decode the raster data here. Can someone break down how the raster data becomes the image? I've been able to break down one image, but nothing else (not this image). I have posted my understanding of how this should break down, but I am obviously doing it wrong.</p> <pre><code>01000111 G 01001001 I 01000110 F 00111000 8 00111001 9 01100001 a Screen Descriptor WIDTH 00000011 3 00000000 00000101 5 00000000 10010001 GCM (1), CR (001), BPP (001), CD = 2, COLORS = 4 00000000 BGCOLOR Index 00000000 Aspect Ratio GCM BLUE 00110101 | 53 00000000 | 0 11000001 | 193 WHITE 11111111 | 255 11111111 | 255 11111111 | 255 BLACK 00000000 | 0 00000000 | 0 00000000 | 0 00000000 | 0 00000000 | 0 00000000 | 0 Extension 00100001 | 21 Function Code 11111001 | F9 Length 00000100 | 4 00000000 00000000 00000000 00000000 Terminator 00000000 Local Descriptor 00101100 Header XPOS 00000000 | 0 00000000 YPOS 00000000 | 0 00000000 Width 00000011 | 3 00000000 Height 00000101 | 5 00000000 Flags 00000000 (LCM = 0, Interlaced = 0, Sorted = 0, Reserved = 0, Pixel Bits = 0) RASTER DATA Initial Code Size 00000010 | 2 Length 00000101 | 5 Data 10000100 01101110 00100111 11000001 01011101 Terminator 00000000 00111011 | ; 00000000 </code></pre> <p><strong>My Attempt</strong></p> <pre><code>10000100 01101110 00100111 11000001 01011101 </code></pre> <p>Initial Code Size = 3 Read 2 bits at a time</p> <pre><code>10 00 Append last bit to first (010) String becomes 010 or 2. 2 would be color # 3 or BLACK </code></pre> <p>At this point, I am already wrong. The first color should be blue.</p> <p>Resources I have been using:</p> <p><a href="http://www.daubnet.com/en/file-format-gif" rel="nofollow noreferrer">http://www.daubnet.com/en/file-format-gif</a> <a href="http://en.wikipedia.org/wiki/Graphics_Interchange_Format" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Graphics_Interchange_Format</a> <a href="http://www.w3.org/Graphics/GIF/spec-gif87.txt" rel="nofollow noreferrer">http://www.w3.org/Graphics/GIF/spec-gif87.txt</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload