2002.02.27 02:53 "Must set "ImageWidth" before writing data", by Stephen Rasku

2002.02.28 17:56 "Re: Must set "ImageWidth" before writing data", by Stephen Rasku

I am trying to write an encoded strip and I am getting the error message specified in the subject line. I am using v3.5.5.

I looked in the source and this happens if FIELD_IMAGEDIMENSIONS is not set. However, the man page for TIFFSetField doesn't mention this field. In fact, tif_dir.h, refers to this as a "multi-item field". This leads me to believe (possibly incorrectly) that this is set automatically by the TIFF library if you set the correct fields.

I am explicitly setting the following fields:


Are there other fields I need to set to get rid of this error message?

Here's the code for a sample program that has the problem:

#include <stdio.h>
#include <stdarg.h>
#include "tiffio.h"

#define OUTFILE         "tiffcreate.tif"
#define NUMROWS         10
#define IMAGE_WIDTH   16

unsigned char blackbuf[BYTES_PER_BUF];
unsigned char whitebuf[BYTES_PER_BUF];

void myHandler(const char *module, const char *fmt, va_list ap)
    fprintf(stderr, "%s: ", module);
    fprintf(stderr, fmt, ap);
    fprintf(stderr, "\n");

main(int argc, char *argv[])

    do {
   TIFF *tif;
      int row;

        memset(blackbuf, -1, BYTES_PER_BUF);
    memset(whitebuf, 0, BYTES_PER_BUF);

     if ( !( tif = TIFFOpen(OUTFILE, "w") ) )
           fprintf(stderr, "%s: Error opening file %s\n", argv[0], OUTFILE);
     TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, (unsigned)IMAGE_WIDTH) &&
         TIFFSetField(tif, TIFFTAG_IMAGELENGTH, (unsigned)NUMROWS) &&
            TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, (unsigned)1) ) )
   TIFFSetField(tif, TIFFTAG_XRESOLUTION, 204.);


        for (row = 0; row < NUMROWS; ++row)
        if ( TIFFWriteEncodedStrip(tif, row, row % 2 ? blackbuf : whitebuf,
          IMAGE_WIDTH) == -1) break;

    } while(0);

Stephen Rasku                   E-mail: stephen@tgivan.com
Senior Software Engineer      Web:    http://www.pop-star.net/
TGI Technologies