AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2004.04.02 14:05 "[Tiff] 16 bit gray scale images and tiff", by Wendel Dean Renner
2004.04.04 17:22 "Re: [Tiff] 16 bit gray scale images and tiff", by Bob Friesenhahn
2004.04.04 17:22 "Re: [Tiff] 16 bit gray scale images and tiff", by Andrey Kiselev
2004.04.30 08:37 "Re: [Tiff] multipage TIFFs source code", by Andrey Kiselev
2004.04.30 07:44 "[Tiff] multipage TIFFs source code", by Peter Van Osta
2004.04.30 08:21 "Re: [Tiff] multipage TIFFs source code", by Kai-Uwe Behrmann

2004.04.30 08:37 "Re: [Tiff] 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 software.

Andrey

--
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 =

    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_PLANARCONFIG, PLANARCONFIG_CONTIG);
    TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photo);
    TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_BOTLEFT);
    /* 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 */
        TIFFSetField(out, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE);
        /* 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);

        TIFFWriteDirectory(out);
    }