TITLE: Introduction to libtiff POSTDATE: 05 December 2000 POSTER: mikal@stillhq.com POSTERNAME: Mikal BEGIN CONTENT Libtiff is the TIFF imaging library used by Panda, among other things. It is also the accepted industry standard for TIFF imaging, and is available for most operating systems, including various Unices and Windows.

The programmers interface to libtiff is superficially like the standard ANSI I/O routines. For instance, at the very start you have to open the TIFF document, which is done with:
#include <tiffio.h>

...

TIFF	*mytiff;

if((mytiff = TIFFOpen("input.tif", "r")) == NULL){
  fprintf(stderr, "Could not open the tiff input.tif\n");
  exit(42);
  }
As you can see here, the TIFF file is opened using TIFFOpen(3), which looks a lot like fopen(3). A TIFF document is closed with TIFFClose(3). TIFFClientOpen(3) and TIFFFdOpen(3) are also available for opening TIFF documents, and will be investigated more later on.

What do you do with the image once you have it open? This is really limited by you imagination, but I will present some simple examples here for your edification. They are by no means the only things you can do.

Change the compression algorithm - one of the common things that I do is change the compression algorithm. This is done using the TIFFGetField(3) and TIFFSetField(3) function calls. For instance, the code below checks if an image is in CCITT Group 3 Fax compression, and if it is then saves it out as a CCITT Group 4 Fax compressed TIFF image.

It should be noted that the compression algorithm is one of a whole bunch of things inside the TIFF that you can change and have libtiff handle in this manner. Other common ones include: the image description, the number of rows per strip, the fill order, and the name of the software that last played with the image. A complete list can be found in the TIFFSetField(3) man page.

Reverse an image vertically -

Reverse an image horizontally -

Manipulate pixels - for instance to add some text onto an image

And anything else that you can think of.