Return-Path: <owner-tiff@olympiakos.com>
Received: from nataly.at1895.spb.edu (localhost [127.0.0.1])
	by at1895.spb.edu (8.12.4/8.12.4/Debian-4) with ESMTP id g8UI09YR011643
	for <dron@at1895.spb.edu>; Mon, 30 Sep 2002 22:00:09 +0400
Received: from olympiakos.com (uucp@localhost)
	by nataly.at1895.spb.edu (8.12.4/8.12.4/Debian-4) with UUCP id g8UI09Qp011641
	for dron@at1895.spb.edu; Mon, 30 Sep 2002 22:00:09 +0400
Received: from knot.pu.ru (knot.pu.ru [193.124.85.214] (may be forged))
	by wg.pu.ru (8.9.1a/8.9.1) with ESMTP id RAA17354
	for <dron@at1895.spb.edu>; Mon, 30 Sep 2002 17:54:02 GMT
Received: from gate7.olympiakos.com (sdsl-64-32-199-150.dsl.iad.megapath.net [64.32.199.150])
	by knot.pu.ru (8.9.3/8.9.0) with ESMTP id VAA23755
	for <dron@at1895.spb.edu>; Mon, 30 Sep 2002 21:54:00 +0400 (MSD)
Received: from localhost (daemon@localhost)
	by gate7.olympiakos.com (8.9.3/8.9.3) with SMTP id NAA15970;
	Mon, 30 Sep 2002 13:49:59 -0400
Received: by gate7.olympiakos.com (bulk_mailer v1.9); Mon, 30 Sep 2002 13:35:02 -0400
Received: (from majordom@localhost)
	by gate7.olympiakos.com (8.9.3/8.9.3) id NAA15887
	for tiff-outgoing; Mon, 30 Sep 2002 13:34:41 -0400
X-Authentication-Warning: gate7.olympiakos.com: majordom set sender to owner-tiff@olympiakos.com using -f
Received: from oxmail.ox.ac.uk (oxmail4.ox.ac.uk [163.1.2.33])
	by gate7.olympiakos.com (8.9.3/8.9.3) with ESMTP id NAA15884
	for <tiff@olympiakos.com>; Mon, 30 Sep 2002 13:34:40 -0400
Received: from wing2.herald.ox.ac.uk ([163.1.0.226])
	by oxmail.ox.ac.uk with esmtp (Exim 3.36 #1)
	id 17w4RL-0000oO-04
	for tiff@olympiakos.com; Mon, 30 Sep 2002 18:34:39 +0100
Received: from httpd by wing2.herald.ox.ac.uk with local (Exim 3.35 #1)
	id 17w4RL-0005cf-00
	for tiff@olympiakos.com; Mon, 30 Sep 2002 18:34:39 +0100
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
MIME-Version: 1.0
X-Mailer: MIME-tools 5.411 (Entity 5.404)
From: Zhongfu Zhou <zhongfu.zhou@wolfson.oxford.ac.uk>
Date: Mon, 30 Sep 2002 18:34:39 +0100 (BST)
Subject: Seek help
To: tiff@olympiakos.com
Message-Id: <E17w4RL-0005cf-00@wing2.herald.ox.ac.uk>
Sender: owner-tiff@olympiakos.com
Precedence: bulk
Content-Transfer-Encoding: binary
Status: RO
Content-Length: 2187
Lines: 91

Dear all,

I want to creat some grayscale images and wrote following code, but the images produced is always wrong. Anyone can kindly have a look to my code and give me some suggestions. Thanks a lot.

#include <stdio.h>
#include <tiffio.h>
#include <math.h>

int main(int argc, char *argv[])
  {
    FILE * pFile;
    uint32 width, height;
    uint32 lSize;
    int buffer[100];
    int i;

    pFile = fopen ( "test4" , "r" );

    if (pFile==NULL) exit (1);

   //Giving values of width and height
    width =  10;
    height = 10;
    lSize =width*height;

   //copy the file into the buffer.

      for (i=0; i<lSize; ++i)
	{
	  fscanf (pFile,"%i",&buffer[i]);
	  printf ("%i,%i\n", i,buffer[i]);
	}
      
     if (buffer == NULL) exit (2);


  TIFF *image;

  // Open the Tiff flie
  if ((image = TIFFOpen("output.tif","w")) == NULL)
    {
    printf ("Could not open output.tif for writing \n");
    exit (42);
    }

  //set parameters
  
  TIFFSetField(image,TIFFTAG_IMAGEWIDTH, 10);
  TIFFSetField(image,TIFFTAG_IMAGELENGTH, 10);
  TIFFSetField(image,TIFFTAG_BITSPERSAMPLE, 8);
  TIFFSetField(image,TIFFTAG_SAMPLESPERPIXEL, 1);
  TIFFSetField(image,TIFFTAG_ROWSPERSTRIP, 10);
  TIFFSetField(image,TIFFTAG_ORIENTATION,ORIENTATION_TOPLEFT);

  TIFFSetField(image,TIFFTAG_COMPRESSION, COMPRESSION_NONE);
  TIFFSetField(image,TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
  //TIFFSetField(image,TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);
  TIFFSetField(image,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);


  TIFFSetField(image,TIFFTAG_XRESOLUTION, 10.0);
  TIFFSetField(image,TIFFTAG_YRESOLUTION, 10.0);
  TIFFSetField(image,TIFFTAG_RESOLUTIONUNIT,RESUNIT_INCH);

  TIFFWriteEncodedStrip(image,0,buffer,100);

    free (buffer);
    fclose(pFile);
    TIFFClose(image);
}


The date matrix of file "test4" I used is:

1 0 1 0 1 0 1 0 1 0 
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 
1 0 1 0 1 0 1 0 1 0 
0 1 0 1 0 1 0 1 0 1 
1 1 1 1 1 1 1 1 1 1 
1 1 1 0 1 1 1 1 0 1 
1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 





To subscribe or unsubscribe email tiff-request@olympiakos.com with subscribe
or unsubscribe in the email body.  Libtiff home page: http://www.libtiff.org

