TIFF and LibTiff Mail List Archive


1997.05.05 08:00 "Can't write Tiff directory first", by Pesce Roberto
1997.05.05 13:09 "Re: Can't write Tiff directory first", by Rainer Wiesenfarth

1997.05.05 08:00 "Can't write Tiff directory first", by Pesce Roberto


I'm quite a newbie as a LIBTiff user, in fact I only used lilbtiff for reading 'till today and all worked fine; now I have to write some group 4 compressed images but when I tried the writing/compressing capabilities, stealing some code from the samples included with the library, I succeeded in writing but the TIFF directory is appended to the compressed data.

The image is correct and the file is OK, but I'd like to have the directory at the beginning of the file...

Here follows the sample code I used to write the file:

int WriteTIFF(pic,w,h,rmap,gmap,bmap,
     unsigned char *pic;
     int   w,h,comp;
     unsigned char *rmap, *gmap, *bmap;
     char *fname, *comment;
  double res;
  TIFF *tif;
  unsigned char *pix;
  int   i,j;
  int sz;
  unsigned short *ppix;
  tdata_t buf;

  tif = TIFFOpen(fname, "w");

  if (!tif) return 0;


  if (comment && strlen(comment)>0) {



  res = 200;


  sz = TIFFStripSize(tif);

  buf = malloc(TIFFStripSize(tif));

  TIFFWriteEncodedStrip(tif, 0, buf, (tsize_t) sz); 



  return 0;

I've tried to put an explicit call to the TIFFWriteDirectory() before the TIFFFlush() but a warning is raised claiming that I Must set the Image Width before doing that, and that's the first TAG I set.

Many thanxs in advance to anyone that will help me


Roberto Pesce
Divisione MAP
* +39-10-6582250
fax +39-10-6582498

Elsag Bailey - un'Azienda FINMECCANICA
Via Puccini, 2
16154 Genova - ITALY