Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

lzw and gif file format 1

Status
Not open for further replies.

wduty

Programmer
Jun 24, 2000
271
US
Does anyone know the precise implementation of the Lempel-Ziv-Welch algorithm (LZW) as it is used in the GIF file format? (This isn't a java question but it seems like something java programmers might know. If there's a more appropriate place to post this please let me know.)<br><br>I am trying to write a specific encoder for gifs. Here is the problem. I have read a bunch of material which explains the gif file format and have come to understand how it apparently works in general. However, the stumbling block is that the last part of the file which contains the actual compressed pixel data. This is said to be compressed using a modified LZW strategy. By creating a series of simple gifs in photoshop then looking at the byte values manually, I can see how the various blocks are set up and how they vary depending of the image size, color set, etc. However, the last block is beyond me to figure out. <br><br>There are several issues here:<br>1. The compression of pixel data is of variable bit size which is specified in the first byte of the header of the image data block.<br>2. There are 2 special codes which are added to the actual data stream (a &quot;clear code&quot; to change the compression code size and an &quot;end of information&quot; code).<br>3. the data bits are sequentially organized so that the lowest order bit for each compression code is pointed towards the lower order of the bytes within which it is contained.<br>4. How is the LZW-initial root table organized? How do you know what order to put the root values in in relation to the global color palette? And are the root values the byte values or the indices of each color in the global palette?<br><br>As an example, here is a gif-image which is a 4 pixel square of green pixels (2x2). The color value of this pixel is (80,184,75) which you can see in the file data below:<br><br><br>byte no.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;character&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;description<br>------------------------------------------------------------------<br>1:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;71&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n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bsp;&nbsp;<font color=red>logical screen height (2 bytes)</font><br>10:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0<br>11:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;128&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;€&nbsp;&nbsp;&nbsp;&nbsp;<font color=red>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;global palette bits</font><br>12:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ÿ&nbsp;&nbsp;&nbsp;&nbsp;<font color=red>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background color</font><br>13:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=red>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aspect ratio</font><br>14:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;80&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;P&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=red>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;green pixel (R value)</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=red>start global palette</font><br>15:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;184&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;¸&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=red>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;green pixel (G value)</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>16:&nbsp;&n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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color=red>file close</font><br><br><br>The real issue is the 4 IMAGE DATA pixels. These are:<br><br>132 143 9 5<br><br>which in binary are:<br><br>10000100 10001111 00001001 00000101<br><br>However, since the compression is not spaced in bytes the actual encoded data is contained within some break up of this stream. This break-up furthermore is not in the same direction as the order of bits but rather staggered with the lowest bit of each compression code-word starting toward the right and continuing in the same fashion throughout.<br><br>Although I understand the LZW process for a series of characters I don't know where the code is organized within this bits show above. How do I read this bit stream so that I can see where the root table and encoded data are? Where are the two special codes in this data?<br><br>Any comments or corrections gratefully appreciated!<br> <p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br>
 
Thanks, however, all the links at those sites were the places I already went to. Nevertheless I managed to figure it out. For anyone who is interested here's the run down.<br><br>The problem is that the bit stream has to be read backwards and the bits divided according to the (code size)+1. So, in the above example the bit-stream was:<br><br>10000100 10001111 00001001 00000101<br><br>But it has to be read backwards like this:<br><br>00000101 00001001 10001111 10000100<br><br>then <i>respaced</i> according to the (code size) + 1<br><br>0000 0101 0000 1001 1000 111 110 000 100<br><br>reversing this for readability we have:<br><br>100 000 110 111 1000 1001 0000 0101 0000 <br><br>one problem is that the first code here is the CLEAR CODE which is 100 or 4 in decimal and this isn't part of the actual image data. Also the code size changes as you can see, when the LZW root-table reaches a value of 4 the code-size increases by 1 bit (in this case to 3+1 or 4). I went through the process of encoding this manually and it matches although it's too long to bother with here. Also the image in the above example is 16 pixels not 4 (it's a 4x4 image) sorry.<br><br><br><br><br> <p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br>
 
isn't LZW under copyright by Unisys (those @#%!)? or is that a different algorithm for GIF? <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
Yes it's true. The LZW for gifs is a modified version of the standard LZW but it's still patented. Apparently Unisys originally patented the standard LZW algorithm in 1985 although it wasn't because of the gif file format but rather because the algorithm is very efficient and is widely used in data-compression so they were interested in those revenues. After a few years they became aware that there was this file format called &quot;gif&quot; which used the algorithm and so they underwent legal proceedings to ensure that people developing software which encoded or decoded gifs would have to pay a royalty.<br><br>Apparently their revenues aren't even that significant from the gif-related portion of the licensing. I read somewhere that their position is that they have a responsibility to their shareholders to protect their products etc...<br><br>Since this is a public forum I would like to stress that I would NEVER use any LZW related code which I have written for any purposes other than personal and educational ones, at least as long as such legal and conceptual fascism is in effect. To me it's something like patenting algebra or a high-five... <p>--Will Duty<br><a href=mailto:wduty@radicalfringe.com>wduty@radicalfringe.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top