3DSoftware.com > Programming > File Formats > BIP > Page 6
BIP File Format  Page 6
 
Compression
 
Compression can be CCITT, RLE, ZLIB, or RLE and ZLIB.
 
CCITT
 
CCITT Group 3 (T4) is a bit-level compression scheme that consists of using variable bit length CCITT codes in place of bit runs, beginning with the bit color that is the complement of the Default Color (1 if the default color is 0; 0 if the default color is 1). Each tile (or block or band) is treated as a single line in this 1-dimensional compression scheme, with all lines of the tile concatenated into a single line without pad bits between the concatenated lines. Pad bits are used as needed only at the end of that stream to make it a byte stream.
 
If the file has only one channel, CCITT encoding produces one CCITT stream per tile (or block or band), as was just discussed. If there is more than one channel, each tile channel produces a separate stream (channels are not combined into one CCITT stream), as will be discussed in a later page of this document.
 
EOL codes are not used if tiles, blocks or bands are used. Otherwise (if the image is not partitioned or broken up) then an EOL code is used at the end of each scan line and the next scan line starts at the beginning of a new byte without any kind of special bits in between except pad bits at the end of the previous line so that it can be a byte stream.
 
RLE
 
RLE is Change Based Run Length Encoding, as explained in Samet, Foundations of Multidimensional and Metric Data Structures, p. 409.
 
RLE consists of run lengths without specifying the color of each run length. Since only two colors are possible, each run length has the opposite color of the previous run length, and you only need to record the first color of a stream. Each run length is an 8-bit number (can be 0 through 255).
 
For example, a stream of 300 white pixels is encoded as follows:
 
W, 255, 0, 45
 
That is 255 white pixels, followed by 0 black pixels, followed by 45 white pixels.
 
If the grid is not partitioned or broken up, each scan line is a separate stream. Otherwise each tile (or block or band) is a stream of that tile's scan lines concatenated together.
 
If the file has only one channel, RLE encoding produces one RLE stream per tile. If there is more than one channel, each tile channel produces a separate stream (channels are not combined into one RLE stream). That will be discussed later.
 
ZLIB
 
With ZLIB compression, tile scan lines form a byte stream that is compressed with the ZLib programming library. The uncompressed byte stream that is fed into ZLib simply consists of one scan line after the other, beginning with the top scan line. There are no extra (pad) bytes between scan lines.
 
As mentioned in the overview at the beginning of this article, if the number of pixels in a row is not a multiple of 8, then there will be unused pixels in the last byte of each scan line that will be compressed with ZLib. When allocating memory for scan lines, zero out that memory before using it.
 
If the grid is not partitioned or broken up, each scan line is a separate stream. Otherwise each tile (or block or band) is a stream of that tile's scan lines concatenated together.
 
If there is one channel, each tile produces a ZLib stream of scan lines. If there is more than one channel, each tile channel produces a separate stream (channels are not combined into one ZLib stream). That will be discussed later.
 
—  Page 6  —
 « Page 5 Contents Page 7 » 
 
Copyright © 2008 by 3D Software. All rights reserved.
3D Software, P.O. Box 221190, Sacramento CA 95822 USA
www.3DSoftware.com     Contact us
Tuesday, 06-Jan-2009 02:20:55 GMT