| AWARE [SYSTEMS] | Imaging expertise for the Delphi developer | |||||||
![]() |
TIFF and LibTiff Mailing List Archive | |||||||
LibTiff Mailing List
TIFF and LibTiff Mailing List Archive Contact
The TIFF Mailing List Homepage |
Thread2005.10.26 12:06 "Re: checking test images", by <ryuki_dono@yahoo.de>> > I didn't know that libtiff was so limited. Or did I something wrong?
> > I think quad-jpeg and zackthecat can't
> > be decoded because of my missing JPEG support in my build. But whats
> > with all the 2 to 64 Bit pixeldepth?
> > What's with the contig files?
It was not meant as an insult. I used JPEG.lib and PNG.lib before and
they where able to provide the full support of the image format with high
level functions. I had to check the support informations more. I only
wondered why there is no 24 and 32 bit support yet? Since TIFFReadRGBAImage
provides 4x8Bit output there should be no problem with that.
But I don't feel comfortable hacking the support into the library functions.
Only for providing a simple solution:
static void MyRobWarningHandler(const char* module, const char* fmt,
va_list ap)
{
return;
}
static void MyRobErrorHandler(const char* module, const char* fmt,
va_list ap)
{
throw "Error";
// CString message;
// throw message.Format(fmt,ap);
}
bool CDIB::Load_TIF(CString &pf) // Load TIF from file (ORIGINAL)
{
TIFF* tif=NULL;
uint32* raster=NULL;
uint32 w, h; // width and height
size_t npixels;
uint16 orientation=ORIENTATION_TOPLEFT;
try {
tif = TIFFOpen((LPCTSTR)pf, "r");
if (tif)
{
TIFFSetErrorHandler(MyRobErrorHandler); // break when errors occure
TIFFSetWarningHandler(MyRobWarningHandler); // ignores warnings
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
TIFFGetField(tif, TIFFTAG_ORIENTATION, &orientation);
npixels = w * h;
raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32));
if (raster != NULL)
{
if (TIFFReadRGBAImage(tif, w, h, raster, 0)) // try to read RGBA data
{
if (!Create(w, h, 24)) // malloc dib memory for 24 bit data everytime
{
_TIFFfree(raster); // free all memory
TIFFClose(tif);
return false; // error
}
BYTE *bits;
BYTE *source=(BYTE*)raster;
for (long y=0; y < h; y++)
{
if ((orientation==ORIENTATION_TOPLEFT) || (orientation==ORIENTATION_TOPRIGHT)) // upside down picture
bits=(BYTE*)GetPixelAddress(0,h-y-1); // get memory adress of pixel
else
bits=(BYTE*)GetPixelAddress(0,y);
for (long x=0; x < w; x++)
{
*bits++ = (BYTE)source[2]; //B copy ABGR -> BGR
*bits++ = (BYTE)source[1]; //G
*bits++ = (BYTE)source[0]; //R
source+=4; // count 4 bytes further
} // endfor x
} // endfor y
} // endif raster
_TIFFfree(raster);
}
TIFFClose(tif);
}
else // no tif
return false;
} catch (char *message) // error
{
if (raster) // you can try to read the image after all
{
_TIFFfree(raster); // free memory
}
if (tif) TIFFClose(tif); // close tiff
return false;
}
return true; // no error while reading the image
}
As you can see I corrected the RGB copy part. Now that litle function
should read all standart tiff images. If there is an error while reading,
the function doesn't provide an image but the return value false. That
small function would have saved me a lot of time, since I wasn't able to
find any sample about using an own errormanagement. I hope it helps some
beginners.
|
|||||||