DIPlib Documentation - ©1995-2013 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 type | Name | Description
`dipio_CompressionMethod` | `method` | Compression method
`dip_int` | `level` | Compression 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:

Name | Description
`DIPIO_CMP_DEFAULT` | Default compression method for the file format
`DIPIO_CMP_NONE` | No compression
`DIPIO_CMP_GZIP` | ZIP 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_DEFLATE` | Deflate (same as `DIPIO_CMP_GZIP`)
`DIPIO_CMP_COMPRESS` | Using UNIX's "compress" utility, which uses the LZW algorithm
`DIPIO_CMP_LZW` | LZW compression (same as `DIPIO_CMP_COMPRESS`)
`DIPIO_CMP_JPEG` | Lossy JPEG compression. The `level` parameter is between 1 and 100, higher numbers giving better quality output but larger files.
`DIPIO_CMP_PACKBITS` | PackBits
`DIPIO_CMP_THUNDERSCAN` | ThunderScan
`DIPIO_CMP_NEXT` | NeXT
`DIPIO_CMP_CCITTRLE` | CCITT RLE
`DIPIO_CMP_CCITTRLEW` | CCITT RLE/W
`DIPIO_CMP_CCITTFAX3` | CCITT Group 3
`DIPIO_CMP_CCITTFAX4` | CCITT 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.