| 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 |
Thread2006.05.23 11:03 "Question to TIFF mailing list", by Alexey AushevHello, the Community!
I'm novice at TIFF coding. Would you say me, please, why my output 24-bit
color image has no this IFD part? Here is the simpliest example of output
of 10x10 image, using TIFFWriteEncodedStrip().
TIFF dump is:
output.tif:
Magic: 0x4949 <little-endian> Version: 0x2a
Directory 0: offset 308 (0x134) next 0 (0)
ImageWidth (256) SHORT (3) 1<10>
ImageLength (257) SHORT (3) 1<10>
BitsPerSample (258) SHORT (3) 3<8 8 8>
Compression (259) SHORT (3) 1<1>
Photometric (262) SHORT (3) 1<2>
StripOffsets (273) LONG (4) 10<8 38 68 98 128 158 188 218 248 278>
SamplesPerPixel (277) SHORT (3) 1<3>
RowsPerStrip (278) SHORT (3) 1<1>
StripByteCounts (279) LONG (4) 10<30 30 30 30 30 30 30 30 30 30>
PlanarConfig (284) SHORT (3) 1<1>
The code, used to get the image is:
TIFF *output;
uint32 width, height;
uint32 *raster;
// Open the output image
output = TIFFOpen ("output.tif", "w");
if (output == NULL)
{
fprintf (stderr, "Could not open output file\n");
return 0;
}
width = 10;
height = 10;
if ((raster = (uint32 *) malloc(sizeof (uint32) * width * height * 3)) ==
NULL)
{
fprintf(stderr, "Could not allocate memory\n");
return 0;
}
// set image content, here is the simpliest, cause doesn't matter
for (unsigned int i=0; i<width*height; i++)
{
raster[i] = 0xffacacac;
}
// Write the tiff tags to the file
TIFFSetField (output, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField (output, TIFFTAG_IMAGELENGTH, height);
TIFFSetField (output, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
TIFFSetField (output, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField (output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField (output, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField (output, TIFFTAG_SAMPLESPERPIXEL, 3);
// uint32 rowperstrip = TIFFDefaultStripSize (output, 0);
// for this simple case
uint32 rowperstrip = 1;
TIFFSetField (output, TIFFTAG_ROWSPERSTRIP, rowperstrip);
tsize_t strip_size = TIFFStripSize (output);
tstrip_t strips_num = TIFFNumberOfStrips (output);
// Write the image
for (unsigned int i=0; i<strips_num; i++)
{
if (TIFFWriteEncodedStrip (output, i, raster+i*strip_size, strip_size) ==
0)
{
// error handling
}
}
free (raster);
TIFFClose (output);
return 1;
I will appreciate any comments to this code and the cituation itself,
because I'm already disappointed to find the solution, reading articles
and debugging.
Beforehand thanks,
Alexey Aushev, Saint-Petersburg, Russia.
|
|||||||