Return-Path: <tiff-bounces@lists.maptools.org>
X-Original-To: info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-g.b-one.net (mx-g.one.com [91.198.169.54])
	by mail9.b-one.net (Postfix) with ESMTP id BBA2040090A
	for <info@awaresystems.be>; Wed, 20 Jan 2010 02:43:55 +0100 (CET)
Received: by mx-g.b-one.net (Postfix, from userid 106)
	id A11E9A3BB0; Wed, 20 Jan 2010 02:43:55 +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 lists.maptools.org (lists.maptools.org [65.39.174.144]) by
 mx-g.b-one.net (Postfix) with ESMTP id B01A01C986C for
 <info@awaresystems.be>; Wed, 20 Jan 2010 02:43:54 +0100 (CET)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by
 lists.maptools.org (Postfix) with ESMTP id 7B55C1D18B106; Tue, 19 Jan 2010
 20:43:06 -0500 (EST)
Received: from edge.aegean.gr (edge.aegean.gr [195.251.128.7]) by
 lists.maptools.org (Postfix) with ESMTPS id E37EF1D201DE3 for
 <tiff@lists.maptools.org>; Tue, 19 Jan 2010 20:30:54 -0500 (EST)
Received: from hermes.aegean.gr (195.251.128.2) by edge.aegean.gr
 (195.251.128.7) with Microsoft SMTP Server (TLS) id 8.2.213.0; Wed, 20 Jan
 2010 03:30:46 +0200
Received: from hermes.aegean.gr ([195.251.128.2]) by hermes.aegean.gr
 ([195.251.128.2]) with mapi; Wed, 20 Jan 2010 03:30:46 +0200
From: Kavallieratou Ergina <kavallieratou@aegean.gr>
To: "tiff@lists.maptools.org" <tiff@lists.maptools.org>
Date: Wed, 20 Jan 2010 03:30:46 +0200
Thread-Topic: RE:2010.01.11 09:47 "Re: me again...", by Gerben Vos
Thread-Index: AQHKmXAwLzhOymCUtEmeU2Pgxehv7w==
Message-ID: <87230A7E62A21E4F9EBD941DF2A48F03E2C32AC331@hermes.aegean.gr>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
acceptlanguage: en-US
MIME-Version: 1.0
Subject: Re: [Tiff] 2010.01.11 09:47 "Re: me again...", by Gerben Vos
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.9
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>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org

Thanks to your advices, I manage to build the program below. However, it works only with one kind of tiff and not any e.g from paint or matlab. What is wrong? My files are always black and white.

thank you again
Gin

#include <stddef.h>
#include <tiffio.h> 
using namespace std;
typedef unsigned char BYTE;

struct gen
{
 BYTE** data;
 unsigned short int width;
 unsigned short int height;
 unsigned short int bits_per_pixel;
};
struct eidiki
{
 int **data;
 int width;
 int height;
};


int main(int argc, char *argv[])
{
 int i, j, y;
 gen *imagen=(gen*)malloc(sizeof(gen)); 
 gen *im=(gen*)malloc(sizeof(gen));
 eidiki *imagen1=(eidiki*)malloc(sizeof(eidiki));
 char *strin;
 strin=(char*)malloc(100*sizeof(char));
 char *strout0;
 strout0=(char*)malloc(100*sizeof(char));
 strcpy(strin, argv[1]); 
 strcpy(strout0,"C:\\bethlehem\\samples\\rmvRulerLines.tif\0");
//****************************************************************************************
 // Reading Tif Image
 TIFF *in = TIFFOpen(strin, "r");
 cout<<"Ok";
 if (in) {
  int w=0, h=0; 
  uint16 photo, bpp, spp, fillorder, rows_per_strip, compression, planar, orientation, res_unit;
  uint32 image_offset = 0;
  float xres, yres;
  
  //info reading
  TIFFGetField(in,TIFFTAG_IMAGEWIDTH, &w);
  TIFFGetField(in,TIFFTAG_IMAGELENGTH, &h);
  TIFFGetField(in, TIFFTAG_PHOTOMETRIC, &photo);
  TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bpp);
  TIFFGetField(in, TIFFTAG_SAMPLESPERPIXEL, &spp);
  TIFFGetField(in, TIFFTAG_FILLORDER, &fillorder);
  TIFFGetField(in, TIFFTAG_COMPRESSION, &compression);
  TIFFGetField(in, TIFFTAG_ROWSPERSTRIP, &rows_per_strip);
  TIFFGetField(in, TIFFTAG_STRIPOFFSETS, &image_offset);
  TIFFGetField(in, TIFFTAG_PLANARCONFIG, &planar);
  TIFFGetField(in, TIFFTAG_ORIENTATION, &orientation);
  TIFFGetField(in, TIFFTAG_RESOLUTIONUNIT, &res_unit);
  TIFFGetField(in, TIFFTAG_XRESOLUTION, &xres);
  TIFFGetField(in, TIFFTAG_YRESOLUTION, &yres);
  size_t npixels=w*h;
  uint32 * raster=(uint32 *) _TIFFmalloc(npixels *sizeof(uint32));
  //image reading
  if (raster != NULL) {
   if (TIFFReadRGBAImage(in, w, h, raster, 0)) {
    imagen1->height=h;
    imagen1->width=w;
    imagen1->data=(int**)malloc(sizeof(int*)*h);
    for(i=0;i<h;i++)
     imagen1->data[i]=(int*)malloc(sizeof(int)*w);
    for(i=0;i<h;i++)
     for(j=0;j<w;j++)
      imagen1->data[h-1-i][j]=1-raster[i*w+j]; //1- in order to be appropriate for my functions
    
     txt_to_bmp(imagen,imagen1);
    im->height=imagen->height;
    im->width=imagen->width;
    im->data=(BYTE**)malloc(sizeof(BYTE*)*im->height);
    for(i=0;i<im->height;i++){
     im->data[i]=(BYTE*)malloc(sizeof(BYTE)*im->width);
     for(j=0;j<im->width;j++){
      if (imagen->data[i][j]==2)
       im->data[i][j]=0;
      else
       im->data[i][j]=1;
     }
    }
    
   //my functions...

    for(i=0;i<im->height;i++)
     for(j=0;j<im->width;j++){
      if (im->data[i][j]==0)
       imagen->data[i][j]=2;
      else
       imagen->data[i][j]=1;
     }

    //writing tiff
    TIFF *out=TIFFOpen(strout0,"w");
    int width=w;int height=h;int sampleperpixel=1; //RGBA=4 bw/gray=1
    TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width);
    TIFFSetField(out, TIFFTAG_IMAGELENGTH, height);
    TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photo);
    TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, bpp);
    TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, spp);
    //TIFFSetField(out, TIFFTAG_FILLORDER, fillorder);
    TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
    TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, rows_per_strip);
    TIFFSetField(out, TIFFTAG_PLANARCONFIG, planar);
    TIFFSetField(out, TIFFTAG_ORIENTATION, orientation);
    TIFFSetField(out, TIFFTAG_RESOLUTIONUNIT, res_unit);
    TIFFSetField(out, TIFFTAG_XRESOLUTION, xres);
    TIFFSetField(out, TIFFTAG_YRESOLUTION, yres);
      
    for(i=0;i<imagen->height;i++)
     for(j=0;j<imagen->width;j++){
      imagen->data[i][j]=(BYTE)1-imagen->data[i][j]; //1- gia swsto swsimo
      }
    BYTE *bits;
    bits=new BYTE [imagen->width]; 
    for ( y = 0; y < imagen->height; y++)
    {
     bits= imagen->data[y];
     if (TIFFWriteScanline(out,bits, y, 0)==-1) return 0;
    }
    TIFFClose(out);
   }
   _TIFFfree(raster);
  }
  TIFFClose(in);
 }
return 1;
}
_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
