AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
April 2004

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date


The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems

Valid HTML 4.01!


2004.04.30 07:44 "multipage TIFFs source code", by Peter Van Osta
2004.04.30 08:21 "Re: multipage TIFFs source code", by Kai-uwe Behrmann
2004.04.30 08:37 "Re: multipage TIFFs source code", by Andrey Kiselev
2004.05.03 08:05 "Re: multipage TIFFs source code", by Peter Van Osta

2004.04.30 08:37 "Re: multipage TIFFs source code", by Andrey Kiselev

On Fri, Apr 30, 2004 at 09:44:30AM +0200, Peter Van Osta wrote:
> Thanks for the information, are there any examples available how to
> write and read multipage Tiffs ? I work on RedHat Linux and can use
> libtiff, but I need to get started with putting 3D-data, stored in
> memory to a multipage Tiff-file.

You should call TIFFWriteDirectory() after every page. I have attached a
sample code. Note, that multipage TIFF is an overkill for your purpose
(because every page has its own set of parameters), but this technique
is higly portable and not require changes in the existing viewing


Andrey V. Kiselev
Home phone:  +7 812 5274898  ICQ# 26871517

#include <stdio.h>
#include "tiffio.h"

#define XSIZE 256
#define YSIZE 256
#define NPAGES 10

int main (int argc, char **argv)
    uint32 image_width, image_height;
    float xres, yres;
    uint16 spp, bpp, photo, res_unit;
    TIFF *out;
    int i, j;
    uint16 page;

    unsigned char array[XSIZE * YSIZE];

    for (j = 0; j < YSIZE; j++)
            for(i = 0; i < XSIZE; i++)
                    array[j * XSIZE + i] = (unsigned char)(i * j);

    out = TIFFOpen("out.tif", "w");
    if (!out)
            fprintf (stderr, "Can't open %s for writing\n", argv[1]);
            return 1;
    image_width = XSIZE;
    image_height = YSIZE;
    spp = 1; /* Samples per pixel */
    bpp = 8; /* Bits per sample */

    for (page = 0; page < NPAGES; page++)
        TIFFSetField(out, TIFFTAG_IMAGEWIDTH, image_width / spp);
        TIFFSetField(out, TIFFTAG_IMAGELENGTH, image_height);
        TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, bpp);
        TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, spp);
        TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photo);
        /* It is good to set resolutions too (but it is not nesessary) */
        xres = yres = 100;
        res_unit = RESUNIT_INCH;
        TIFFSetField(out, TIFFTAG_XRESOLUTION, xres);
        TIFFSetField(out, TIFFTAG_YRESOLUTION, yres);
        TIFFSetField(out, TIFFTAG_RESOLUTIONUNIT, res_unit);

        /* We are writing single page of the multipage file */
        /* Set the page number */
        TIFFSetField(out, TIFFTAG_PAGENUMBER, page, NPAGES);

        for (j = 0; j < image_height; j++)
            TIFFWriteScanline(out, &array[j * image_width], j, 0);



    return 0;