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
February 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!



1998.02.09 23:06 "Problem with Libtiff", by Tony Mochan

Hi there,

I have been trying to use libtiff to write a small program to view a
TIFF file and calculate various things using the colour of pixels.

I have been successful in viewing images that have up to 16384 pixels
(4000 Hex), but beyond that value, the image mearly repeats itself, thus
chopping off the rest of the pixels.

I'm not sure if it is when loading it in, allocating the memory or
displaying it that I'm going wrong.

Any help would be appreciated.

Code extracts follow : (raster, width and height are class variables)

/********************** OnFileOpen Function
*****************************/

// Open the TIFF file            
    		TIFF* tif=TIFFOpen(fname,"r");

    if (tif) {                    

// Get the Width and Height of the Image
	TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
	TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
	    
// Allocate the memory for the raster
	raster = (uint32*) _TIFFmalloc(width * height * sizeof(uint32));
                         
	if (raster != NULL) {
// Read in the Image Raster
		if (TIFFReadRGBAImage(tif, width, height, raster, 1)) {
	
			// Redraw the Window			
			RedrawWindow(); 
	    }
	}
	TIFFClose(tif);
	} // End of if(tif)


/********************** OnDraw Function *****************************/

   if (raster!=NULL)             
    {                                        
		// Centre the Image
		StartPosY = (WinHeight-(int)height)/2;
		if (StartPosY<0)
			StartPosY=0;
		StartPosX = (WinWidth-(int)width)/2;
		if (StartPosX<0)
			StartPosX=0;
        
        // Draw the Image (Pixel by Pixel)
		for (uint32 y=StartPosY;y<(height+StartPosY);y++)
			for (uint32 x=StartPosX;x<(width+StartPosX);x++)
    		{
				rpixel = TIFFGetR(raster[((y-StartPosY)*width)+(x-StartPosX)]);
				gpixel = TIFFGetG(raster[((y-StartPosY)*width)+(x-StartPosX)]);
				bpixel = TIFFGetB(raster[((y-StartPosY)*width)+(x-StartPosX)]);
	    		pDC->SetPixel((int)x, (int)(WinHeight-y),
RGB(rpixel,gpixel,bpixel));
    		}
	}

Also, is there a maximum limit to the size of a TIFF file that can be
read, or does this just depend on the computer???

Thanks.

--
Tony Mochan                             amochan@mcs.dundee.ac.uk
Software Developer
Department of Orthopaedic & Trauma Surgery (University of Dundee)
Dundee Royal Infirmary
Scotland, U.K.