AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
June 1998

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

1998.06.10 15:00 "TIFFGetField syntax and use", by Steve Garcia
1998.06.10 15:54 "Re: TIFFGetField syntax and use", by Frank Kim
1998.06.10 16:09 "Re: TIFFGetField syntax and use", by Steven Michael Garcia
1998.06.10 17:04 "Re: TIFFGetField syntax and use", by Bill Davis
1998.06.10 16:21 "Re: TIFFGetField syntax and use", by George Sazaklis

1998.06.10 17:04 "Re: TIFFGetField syntax and use", by Bill Davis

> From Frank.Kim@NetCentric.com Wed Jun 10 12:40:18 1998
> From: Frank Kim <Frank.Kim@NetCentric.com>
> To: "'Steve Garcia'" <steveg@engin.umich.edu>, tiff@sgi.com
> Subject: RE: TIFFGetField syntax and use
> Date: Wed, 10 Jun 1998 11:54:11 -0400
> MIME-Version: 1.0
> X-Mailer: Internet Mail Service (5.0.1460.8)
> Sender: owner-tiff@fddi-sgi.sgi.com
> 
> try this:
> 
> #include <tiffio.h>
> int photo, bitspersample;

Change the line above to:
  short photo, bitspersample;

> main ()
> {
> 	TIFF *tif = TIFFOpen("myfile.tif", "r");
> 	TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photo);

Note the change to add the & on the variable.  You are passing
an address and it is important to pass the address of something
that is the proper size.  An int and short will not be the same
size on every compiler.  A 16 bit compiler usually has int=16 and
short=16 but a 32 bit compiler usually has int=32 and short=16.
Pointing at an int will work if:
 1) the int has been initialized to zero
 2) the value being read is not negative
 3) the byte order on the machine is the right one to have
    a pointer to an int point at the low order two bytes
    of the int so it is also a pointer to a short
So, don't use an int where a short is called for by the spec.
The spec I referenced said short.  Someone correct me if that
has changed.

Bill Davis

> 	TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitspersample);
> 	printf("Photo = %d, Bits/Sample = %d", photo, bitspersample);
> 	TIFFClose(tif);
> }
> 
> 
> by the way, i suggest moving to C++ instead of C.  much better language.
> 
> then for printing you can do this:
> 
> cout << "Photo = " << photo << ", Bits/Sample = " << bitspersample << endl;
> 
> see how you don't have to worry about the type of the data you are printing.
> :-)
> 
> 
> -----Original Message-----
> From: Steve Garcia [mailto:steveg@engin.umich.edu]
> Sent: Wednesday, June 10, 1998 11:00 AM
> To: tiff@sgi.com
> Subject: TIFFGetField syntax and use
> 
> 
> I want to retrieve the value of the tag's PHOTOMETRIC and BITSPERSAMPLE.
> I'm presuming that it is easiest to use the TIFFGetField function to do
> this,
> but I'm not having any real success.  I'm using tiff-v3.4.
> 
> I'm not sure I understand the syntax of the function properly.  My code 
> (truncated for e-mail purposes) is as follows:
> 
> #include <tiffio.h>
> int photo, bitspersample;
> 
> main ()
> {
> 	TIFF *tif = TIFFOpen("myfile.tif", "r");
> 	TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, photo);
> 	TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, bitspersample);
> 	printf("Photo = %d, Bits/Sample = %d", photo, bitspersample);
> 	TIFFClose(tif);
> }
> 
> Now I know I'm getting the memory address when I print out the "photo"
> and "bitspersample", yet I can't seem to retrieve the actual value that the
> Tags contain.  
> 
> Any suggestions?  First major C program I'm trying to write (still a novice
> at this) but I really like this programming stuff.  Thanks for any 
> suggestions!
> 
> Steve
> 		
>     /\         /^\    Steven Garcia	    Graduate School, Bioengineering
>    /^^\       /^^^\   steveg@engin.umich.edu              Univ. of Michigan
>   /    \/^\  /     \      
>  /      \  \/       \                          
> /  	 \  \	     \	   	         "I AM the last one!" - Dragonheart 
>