Operator PackBitsRLE

[Caution] Disclaimer

Library: Prototype

This module is part of the Prototype library. It is in absolutely preliminary state and subject to extensive changes, even removal. Therefore, this module must not be used for productive designs. It is included for testing purposes only.

The operator PackbitsRLE performs a run-length encoding compression (RLE) of the image stream at input link I, using the packbits algorithm. Packbits was first introduced by Apple and is one of the RLE compression algorithms that can be used for lossless compression of TIFF-files.

The Packbits Algorithm

A raster image file consists of a header (containing information such as image dimension, color depth, etc.) and data that describe the color of each pixel. The data are written sequentially, i.e., the pixel color information has to be interpreted as pixel rows from left to right, top to bottom.

In uncompressed mode, color information for n adjacent pixels of the same color is written n times. This causes redundancy.

Example:

The figure represents a 4-pixel by 4-pixel, black-and-white image. In uncompressed format, the pixels are represented as follows (B=Black, W=White): BBWWWBBBBBBWWWWW This redundancy is reduced by the packbits compression.

The packbits data stream consists of packets with a one-byte header followed by data. The header is a signed byte.

The data describe each pixel with one byte. If the header contains a value n {-127 to -1}, the byte following the header is repeated -n+1 times in the decompressed output. Thus, redundant information (identical pixel color) is stored once together with a counter (header). For example, BBBBBB would be stored as -6B. For the first pixel of another color, a new header is generated.

If the header contains a value n {0 to 127}, n+1 bytes following the header are left uncompressed (copied literally).

The longest pixel series that can be compressed consists of 128 bytes.

After compression with packbits, the example image above (BBWWWBBBBBBWWWWW) becomes -2B-3W-6B-5W, i.e. can be represented by 8 symbols (bytes) instead of 16.

[Important] Effectiveness

Packbits is used for gray scale, palette, and bitonal images. The greater the number of consecutive pixels of identical color, the more effectively the operator can compress the data. Best compression results are achieved for bitonal (e.g., black-and-white) images.

The advantage of the (pretty simple) packbits algorithm lies in its speed and its extremely little need of memory (256 bytes) and processing power.

I/O Properties

Property Value
Operator Type M
Input Link I, data input
Output Link O, data output

Supported Link Format

Link Parameter Input Link I Output Link O
Bit Width [4, 12] as I
Arithmetic {unsigned, signed} as I
Parallelism 1 as I
Kernel Columns any as I
Kernel Rows any as I
Img Protocol VALT_IMAGE2D as I
Color Format any as I
Color Flavor any as I
Max. Img Width any as I1
Max. Img Height any as I

1

The output image width must not exceed 2^31 - 1.

Parameters

None