2000.08.16 13:42 "Raster information in a tiff file", by Sylvain St-Germain
Hi!
My problem is to write information from a raster (8 bits grayscale no header) to a tiff file. I don't know how and i can't explain why it does not work.
- the buffer is limited to 8kb ???
- the method to emulate tdata_t is not right, it is possible with TIFFWriteBufferSetup ?
Thanx!
void Ecrire_Image(TIFF *tif, uint8 *buffer)
{
/*
---------------------------------------------------------------------------- ----------
local
---------------------------------------------------------------------------- ----------
*/
char ch; /* pixel information grayscale 8 bit from the raster */
uint32 compteur = 0; /* for count */
FILE *flecture = NULL; /* ratser file contain only 8 bit pixel no header */
uint32 max = 891374; /* number of pixel flecture contain => 687 (lenght) * 1307 (width) */
if ( (flecture = fopen("decoupage1.raw","rb")) == NULL)
{
fprintf(stderr, "ERROR opening file.\n");
exit(1);
}
/*
---------------------------------------------------------------------------- ------------
try to emulate tdata_t of the TIFFWriteScanline function with buffer
---------------------------------------------------------------------------- ------------
*/
buffer = (uint8*) _TIFFmalloc (max);
/*
---------------------------------------------------------------------------- ------------
read the raster and construct the buffer information for storage
---------------------------------------------------------------------------- ------------
*/
for ( compteur =0; compteur < max; compteur ++)
{
ch = fgetc(flecture);
buffer[compteur] = (uint8) ch ;
}
/*
---------------------------------------------------------------------------- ----------
now the problem => memory fault core dump TIFFWriteScanline
---------------------------------------------------------------------------- ----------
*/
if (!TIFFWriteScanline(tif, buffer, compteur, 0))
{
TIFFError("WriteImage","failure in WriteScanline\n");
}
free (buffer);
fclose(flecture);
}