| 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 |
Thread2005.10.24 20:16 "Re: How can I insert IFD at custom index?", by Andrey KiselevOn Tue, Oct 25, 2005 at 12:02:32AM +0400, Andrey Kiselev wrote:
> You can write IFD either at the end of file (using usual method) or at
> the any position using the TIFFCheckpointDirectory() function. The IFD
> structure will be dumped out immediately whenever the
> TIFFCheckpointDirectory() will be called. See the attached sample code,
Forgot to attach the sample.
--
Andrey V. Kiselev
Home phone: +7 812 5970603 ICQ# 26871517
#include <stdio.h>
#include "tiffio.h"
#define XSIZE 256
#define YSIZE 256
int main (int argc, char **argv)
{
uint32 image_width, image_height, checkpoint;
float xres, yres;
uint16 spp, bpp, photo, res_unit;
TIFF *out;
int i, j;
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;
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);
TIFFSetField(out,TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, 0));
xres = yres = 100;
res_unit = RESUNIT_INCH;
TIFFSetField(out, TIFFTAG_XRESOLUTION, xres);
TIFFSetField(out, TIFFTAG_YRESOLUTION, yres);
TIFFSetField(out, TIFFTAG_RESOLUTIONUNIT, res_unit);
/*
* We will set the DateTime tag to easy locate the IFD position
* in the written file.
*/
TIFFSetField(out, TIFFTAG_DATETIME, "THIS IS DATETIME ");
/*
* Write out the image data until the checkpoints lines will be written.
* Afterwards dump out IFD structure and continue writing the rest of
* scanlines.
*/
checkpoint = image_height / 2;
for (j = 0; j < checkpoint; j++)
TIFFWriteScanline(out, &array[j * image_width], j, 0);
TIFFCheckpointDirectory(out);
for (j = checkpoint; j < image_height; j++)
TIFFWriteScanline(out, &array[j * image_width], j, 0);
TIFFClose(out);
return 0;
}
|
|||||||