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
March 2003

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

2003.03.18 22:58 "Grayscale 16-bit images", by Claus Ekstroem
2003.03.19 09:59 "Re: Grayscale 16-bit images", by Andrey Kiselev

2003.03.19 09:59 "Re: Grayscale 16-bit images", by Andrey Kiselev

On Tue, Mar 18, 2003 at 11:58:33PM +0100, Claus Ekstroem wrote:
> I'm trying to read a 16-bit grayscale image:
> I figure reading 
> the file as a RGBAImage is the wrong approach, so could someone mail me a
> couple of lines of code to read and access the 
> individual pixels?

You should use something like:


TIFF *tif;
uint16 spp, bpp, photo;
uint32 width, height;
char *buf;

tif = TIFFOpen(filename, "r");
if (!tif)
{
	fprintf (stderr, "Can't open %s for reading\n", filename);
	return 2;
}

TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &height);
TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bpp);
TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &spp);
TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photo);
linesize = TIFFScanlineSize(tif);
buf = malloc(linesize * height);
for (i = 0; i < height; i++)
    TIFFReadScanline(tif, &buf[i * linesize], i, 0);

TIFFClose(tif);

The whole image will be read into buffer. After this you can access
individual pixels according bpp and spp values,
i.e. for 16 bit unsigned integer: ((uint16 *)buf)[i].


					Regards,
					Andrey

-- 
Andrey V. Kiselev
Home phone:  +7 812 5274898  ICQ# 26871517