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
October 2005

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

2005.10.22 13:47 "checking test images", by <ryuki_dono@yahoo.de>
2005.10.25 11:25 "Re: checking test images", by <ryuki_dono@yahoo.de>
2005.10.25 13:38 "Re: checking test images", by Frank Warmerdam
2005.10.25 14:37 "Re: checking test images", by Bob Friesenhahn
2005.10.26 12:06 "Re: checking test images", by <ryuki_dono@yahoo.de>
2005.10.26 14:43 "Re: checking test images", by Frank Warmerdam
2005.10.26 17:47 "Re: checking test images", by <ryuki_dono@yahoo.de>
2005.10.26 18:05 "Re: checking test images", by Bob Friesenhahn
2005.10.26 18:59 "Re: checking test images", by Joris Van Damme
2005.10.26 19:47 "Re: checking test images", by Bob Friesenhahn
2005.10.26 21:38 "Re: checking test images", by <ryuki_dono@yahoo.de>
2005.10.26 22:06 "Re: checking test images", by Frank Warmerdam

2005.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.