DIPlib Documentation - ©1995-2017 Quantitative Imaging Group, Delft University of Technology.

Compression methods for image files

The dipio_Compression structure

The structure dipio_Compression specifies the compression method to use when writing an image file, and contains the following elements:

Data typeNameDescription
dipio_CompressionMethodmethodCompression method
dip_intlevelCompression parameter, dependent on method

dipio_CompressionMethod is an enum with the known compression methods. File formats typically only support one or a few of these, and most of these methods do not have a parameter to set, in which case level is ignored. If an unsupported compression method is selected, no compression is done. The dipio_CompressionMethod has the following values:

NameDescription
DIPIO_CMP_DEFAULTDefault compression method for the file format
DIPIO_CMP_NONENo compression
DIPIO_CMP_GZIPZIP compression, using zlib. The level parameter is between 0 and 9, 1 being the faster, lesser compression and 9 being the slower, higher compression. 0 indicates no compression.
DIPIO_CMP_DEFLATEDeflate (same as DIPIO_CMP_GZIP)
DIPIO_CMP_COMPRESSUsing UNIX's "compress" utility, which uses the LZW algorithm
DIPIO_CMP_LZWLZW compression (same as DIPIO_CMP_COMPRESS)
DIPIO_CMP_JPEGLossy JPEG compression. The level parameter is between 1 and 100, higher numbers giving better quality output but larger files.
DIPIO_CMP_PACKBITSPackBits
DIPIO_CMP_THUNDERSCANThunderScan
DIPIO_CMP_NEXTNeXT
DIPIO_CMP_CCITTRLECCITT RLE
DIPIO_CMP_CCITTRLEWCCITT RLE/W
DIPIO_CMP_CCITTFAX3CCITT Group 3
DIPIO_CMP_CCITTFAX4CCITT Group 4

Thus only DIPIO_CMP_GZIP and DIPIO_CMP_JPEG currently have a level to set.

Supported compression methods for the various file formats

The TIFF file writer understand the methods DIPIO_CMP_NONE, DIPIO_CMP_DEFLATE, DIPIO_CMP_LZW, DIPIO_CMP_JPEG, DIPIO_CMP_PACKBITS, DIPIO_CMP_THUNDERSCAN, DIPIO_CMP_NEXT, DIPIO_CMP_CCITTRLE, DIPIO_CMP_CCITTRLEW, DIPIO_CMP_CCITTFAX3 and DIPIO_CMP_CCITTFAX4. It defaults to DIPIO_CMP_DEFLATE. The level parameter is currently not used.

The ICS file writer understands DIPIO_CMP_NONE, DIPIO_CMP_GZIP and DIPIO_CMP_COMPRESS, although DIPIO_CMP_COMPRESS is currently not implemented. It defaults to DIPIO_CMP_GZIP.

The GIF file writer only understands DIPIO_CMP_LZW. The compression method selected is simply ignored.

The JPEG file writer only understands DIPIO_CMP_JPEG. The compression method selected is simply ignored.

The PNG file writer only understands DIPIO_CMP_GZIP. The compression method selected is simply ignored. [The PNG writer is not yet implemented!]

All other file writers do not compress, and simply ignore the compression method requested.