| AWARE [SYSTEMS] | Imaging expertise for the Delphi developer | |||||||
![]() |
TIFF and LibTiff Mailing List Archive | |||||||
LibTiff Mailing List
TIFF and LibTiff Mailing List Archive Contact
The TIFF Mailing List Homepage |
Thread2004.04.30 08:37 "Re: multipage TIFFs source code", by Andrey KiselevOn 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 = 8; /* Bits per sample */
photo = PHOTOMETRIC_MINISBLACK;
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);
}
TIFFClose(out);
return 0;
}
|
|||||||