Return-Path: <tiff-bounces@lists.maptools.org>
X-Original-To: info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-n.b-one.net (mx-n.one.com [91.198.169.61])
	by mail9.b-one.net (Postfix) with ESMTP id BFD0E400223
	for <info@awaresystems.be>; Wed, 26 Nov 2008 10:41:37 +0100 (CET)
X-Virus-Scanned: by one.com
X-Spam-Score: 0
X-Spam-Level: 
X-Spam-Status: No, score=0 tagged_above=0 required=6 tests=[none]
X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4
Received: from duke.maptools.org (r153.dmsolutions.ca [209.217.116.153])
	by mx-n.b-one.net (Postfix) with ESMTP id 8FF7D8C680C
	for <info@awaresystems.be>; Wed, 26 Nov 2008 10:41:36 +0100 (CET)
Received: from duke.maptools.org (duke.maptools.org [127.0.0.1])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id mAQ9bYQS003127;
	Wed, 26 Nov 2008 04:38:56 -0500
Received: from web38903.mail.mud.yahoo.com (web38903.mail.mud.yahoo.com
	[209.191.125.109])
	by duke.maptools.org (8.12.11/8.12.10) with SMTP id mAQ9bT1f003123
	for <tiff@lists.maptools.org>; Wed, 26 Nov 2008 04:37:30 -0500
Received: (qmail 6027 invoked by uid 60001); 26 Nov 2008 09:37:28 -0000
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com;
	h=X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Message-ID;
	b=Wz3ElZVNJ46Y2unWqk+XmC48UGy4kI99Z/JF3vJxz3Wx4MA6G6yyOvsPSzaHt5d/HchhtaFZ4aJHdqA5SFtBJ9qDSPWVdDW8wudG8bQol4SzjZY/6NgK+axh1w/FJERQYsfRcSjSxuw8Pe7x+8n/T261Ou2DxR0Mtlc98xFKGuQ=;
X-YMail-OSG: zZx.VnkVM1mTgln1WXPwGStDqS_P6zXCSBZm3OqgTMWEot91wN_.TaSTLh_dP3AC8kCRAsujHqcxe7VqDJKMwmuuQIif9up.3pU1CLYMQceYP2cK3AsLObjkFFlTWlDu9EKCaClJsEqqpfPCqW04xoOocaoNGDoPEZloOkk-
Received: from [193.48.36.141] by web38903.mail.mud.yahoo.com via HTTP;
	Wed, 26 Nov 2008 01:37:27 PST
X-Mailer: YahooMailRC/1155.32 YahooMailWebService/0.7.260.1
Date: Wed, 26 Nov 2008 01:37:27 -0800 (PST)
From: Cristian Perca <cristianperca@yahoo.com>
To: tiff@lists.maptools.org
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Message-ID: <154140.5938.qm@web38903.mail.mud.yahoo.com>
Subject: [Tiff] Help write 16bites grey level image
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.4
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.maptools.org>
List-Unsubscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=unsubscribe>
List-Archive: <http://lists.maptools.org/mailman/private/tiff>
List-Post: <mailto:tiff@lists.maptools.org>
List-Help: <mailto:tiff-request@lists.maptools.org?subject=help>
List-Subscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=subscribe>
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org



 Hi,
I have a problem while trying to write a 16 bites grey level TIFF image.  Here is a part of the code. The compilation and the execution are OK but the image I get has the expected size but all pixels are black.
If someone has any idea I would really appreciated.
Thank you



    char *flatBuffer=NULL;
    TIFF *flatTiff=NULL;


    flatBuffer=malloc(bufferSize);

    /*test: fill the image with average of input images in imageArray*/
       //imageArray is an dynamical array of struct, each object contains an image
    //All images are correctly read and object buffers filled
    for (count = 0; count < bufferSize; count +=2) {
        uint32 sumPixel=0;
        for(i=0; i<noFiles; i++) {
                      //noFiles is the number of input images == number of created objects
            sumPixel += (*(uint16 *)((imageArray+i) -> buffer + count));
        }
        *(uint16 *)(flatBuffer+count) = (uint16)sumPixel/noFiles;
    }

    if((flatTiff = TIFFOpen("flat.tiff", "w")) == NULL){
      fprintf(stderr, "Could not open flat.tif for writing\n");
      exit(42);
   }

  TIFFSetField(flatTiff, TIFFTAG_IMAGEWIDTH, width);
  TIFFSetField(flatTiff, TIFFTAG_IMAGELENGTH, height);
  TIFFSetField(flatTiff, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
  TIFFSetField(flatTiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
  TIFFSetField(flatTiff, TIFFTAG_BITSPERSAMPLE, bps); //bps=16
  TIFFSetField(flatTiff, TIFFTAG_SAMPLESPERPIXEL, spp); //spp=1
  TIFFSetField(flatTiff, TIFFTAG_ROWSPERSTRIP, height);    // put all rows(==height no of rows) in one strip 
  TIFFSetField(flatTiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
  TIFFSetField(flatTiff, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);

    if( i=TIFFWriteEncodedStrip(flatTiff, 0, flatBuffer, bufferSize) == -1) {
        fprintf(stderr, "Error while writing image to file!");
        exit(42);
    }
//the image has only black pixels, but if I print flatBuffer on the screen I get the expected values:
//printf("%d %d\n", *(uint16 *)(flatBuffer+0), *(uint16 *)(flatBuffer+2));
    TIFFClose(flatTiff);
}



      
_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
