WhyWaitForever

London England

VisibleGif

Image As Data Codes

Within the XML file, within the <image> tag block, image data can be displayed within the <data-codes> tag block. A single tag <code size=" ">, with the mandatory "size" attribute, is valid within this block. This page describes the characteristics and use of this data.



Image data as codes

 ^  Warning on manually editing the "codes" data

The data in the <data-codes> tag block should only be manually amended by an expert who understands the GIF variant with variable bit size of the LZW compression algorithm.

 ^  Why work with the <data-codes> tag block?

The <data-codes> view of image data provides an insight into the efficiency of the image editor software that created the original GIF image.

The image data is equivalent to that in the <data-packed> tag block. The tags that can be amended are the same. It is easier, since files are smaller, to work with the <data-packed> tag block than with the <data-codes> tag block.

 ^  Precedence in generation - after <data-packed> and before <data-rows>

If an XML file contains the three versions of the image data, the precedence when generating the GIF image file is as follows.

  1. <data-packed>
  2. <data-codes>
  3. <data-rows>

So if <data-packed> is not present and both <data-codes> and <data-rows> are present in an XML file, the image will be generated from the <data-codes> tag block.


Technical details

 ^  Codes and Sizes

The data in a <data-packed> tag block comprises bytes organised in blocks. A byte comprises eight bits. A variable group of bits represent a "compression table" code. The minimum number of bits which can store a code is three and the maximum number of bits is twelve. The <lzw-minimum-code-size> plus one represents the initial number of bits used to store the first "compression table" code.

The data in a <data-codes> tag block comprises <code> tags. Each tag contains the "size" attribute which is the number of bits in which the code will be packed. The contents of the tag are the "compression table" code.

There are two special codes. The first, the "clear" (CC) code, is one more than the initial code size (which in turn is one more than <lzw-minimum-code-size>. The second, the "end of information" (EOI) code is one more than the "clear" code.

In the following example "CC" is 4 and "EOI" is 5. Any code less than "CC" represents the index of a particular colour in the relevant colour table (either global or local). Any code greater than "EOI" represents a "compression table" code which in turn represents a character string as defined by the LZW compression algorithm.


  <lzw-minimum-code-size>2</lzw-minimum-code-size>

  <data-codes>
     <code size="3" > 4</code>    <code size="3" > 0</code> 
     <code size="3" > 6</code>    <code size="3" > 7</code>
     <code size="4" > 8</code>    <code size="4" > 9</code>
     <code size="4" >10</code>    <code size="4" >11</code>
     <code size="4" >12</code>    <code size="4" >13</code>
     <code size="4" >14</code>    <code size="4" >15</code>
     <code size="5" >16</code>    <code size="5" >17</code>
     <code size="5" >18</code>    <code size="5" >19</code>
     <code size="5" >20</code>    <code size="5" >21</code>
     <code size="5" >22</code>    <code size="5" >23</code>
     <code size="5" >20</code>    <code size="5" > 1</code>
     <code size="5" >26</code>    <code size="5" >27</code>
     <code size="5" >28</code>    <code size="5" >26</code>
     <code size="5" >13</code>    <code size="5" >29</code>
     <code size="6" >32</code>    <code size="6" > 1</code>
     <code size="6" >31</code>    <code size="6" >33</code>
     <code size="6" >28</code>    <code size="6" >35</code>
     <code size="6" >36</code>    <code size="6" >30</code>
     <code size="6" >12</code>    <code size="6" >39</code>
     <code size="6" >27</code>    <code size="6" >38</code>
     <code size="6" >39</code>    <code size="6" >44</code>
     <code size="6" >36</code>    <code size="6" >24</code>
     <code size="6" >14</code>    <code size="6" > 5</code>
  </data-codes>


For large images the maximum number of "compression table" codes might be exceeded. This is the maximum number of "compression table" codes that can be referenced in twelve bits. When the occurs "CC" is included once again in the series of codes. This forces processing to re-initialise and as a result all previous "compression table" codes created earlier are disgarded.

 ^  Checklist for efficiency

  1. If all code values are less than "CC" then LZW compression is not being used and the GIF image is very inefficient.

  2. The relationship between the colour table size and <lzw-minimum-code-size> is important.

    "CC" should be the size of the colour table. If the colour table is larger than it need be because it contains colours that are not used, the initial size is higher than it need be.

  3. Colour code tables should be kept as small as possible and runs of the same colour should be kept as long as possible. Some image editing software handles bits and bytes better than others. If a colour table has 256 colours the minimum code size will be nine bits. In most image editor software eight bits are handled faster than nine bites.

  4. "CC" can be included in the series of codes at any time. Some image editor software includes more occurances of "CC" than is needed for optimal performance. The code size should be "12" and a "compression code" of "4096" should be required before "CC" is needed.

Life's too short why wait forever
Privacy Declaration
Copyright © 2000 - 2005. WhyWaitForever. All rights reserved.
Legal Disclaimer