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
May 2008

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

2008.05.28 11:04 "Re: Help needed regarding TIFFClientOpen seekproc", by <shailaj@mail.com.np>
2008.05.28 15:03 "Re: Help needed regarding TIFFClientOpen seekproc", by Bob Friesenhahn
2008.06.04 09:03 "Re: Help needed regarding TIFFClientOpen seekproc", by <shailaj@mail.com.np>

2008.05.28 11:04 "Re: Help needed regarding TIFFClientOpen seekproc", by <shailaj@mail.com.np>

Hello all,

Environment Windows XP:
The libtiff source is built by Visual Studio 2005 SP1. The build completed
successfully.

I am using TIFFClientOpen: If I do not use TIFFClientOpen but use TIFFOpen
with an arbitary file name, it is working perfectly. Also I do not have
problem reading the multipage tiff file and displaying them with
TIFFClientOpen ("r" option).

The multipage writing code is taken from here:
http://www.asmail.be/msg0055488937.html

The following is my code:

////////////////////////////////////////////////////////
#include "tiffio.h"
#include "tiffwrite.h"

#define XSIZE 256
#define YSIZE 256
#define NPAGES 10

tsize_t tiff_Read(thandle_t st,tdata_t buffer,tsize_t size)
{
 return ((MyStream*)st)->Read(buffer,size);
};

tsize_t tiff_Write(thandle_t st,tdata_t buffer,tsize_t size)
{
 return ((MyStream*)st)->Write(buffer,size);
};

int tiff_Close(thandle_t)
{
 return 0;
};

//THE PROBLEM LIES IN THIS FUNCTION

toff_t tiff_Seek(thandle_t st,toff_t pos, int whence)
{
    if( pos == 0xFFFFFFFF ) return 0xFFFFFFFF;
        MyStream::seek_modes dwMoveMethod=MyStream::FROM_START;

        switch(whence)
        {
        case SEEK_SET:
                dwMoveMethod = MyStream::FROM_START;
                break;
        case SEEK_CUR:
                dwMoveMethod = MyStream::FROM_CURRENT;
                break;
        case SEEK_END:
                dwMoveMethod = MyStream::FROM_END;
                break;
        }

        return ((MyStream*)st)->Seek(pos,dwMoveMethod);
};

toff_t tiff_Size(thandle_t st)
{
        return  ((MyStream*)st)->GetSize();
};

int tiff_Map(thandle_t, tdata_t*, toff_t*)
{
 return 0;
};

void tiff_Unmap(thandle_t, tdata_t, toff_t)
{
 return;
};

WT::WT(MyStream*_st, MyContext *_context, TIFF *_tiff)
{
  memset(this,0,sizeof(WT));
  st=_st;
  context = _context;
  out = _tiff;
};

int WT::WriteTIF()
{

    uint32 image_width, image_height;
    float xres, yres;
    uint16 spp, bpp, photo, res_unit;
    int i, j;
    uint16 page;

    unsigned char array[XSIZE * YSIZE];

    for (j = 0; j < YSIZE; j++)
            for(i = 0; i < XSIZE; i++)
                    array[j * XSIZE + i] = (unsigned char)(i * j);

    image_width = XSIZE;
    image_height = YSIZE;
    spp = 1; /* Samples per pixel */
    bpp = 8; /* Bits per sample */
    photo = PHOTOMETRIC_MINISBLACK;

    for (page = 0; page < NPAGES; page++)
    {
        TIFFSetField(out, TIFFTAG_IMAGEWIDTH, image_width / spp);
        TIFFSetField(out, TIFFTAG_IMAGELENGTH, image_height);
        TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, bpp);
        TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, spp);
        TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
        TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photo);
        TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_BOTLEFT);
        /* It is good to set resolutions too (but it is not nesessary) */
        xres = yres = 100;
        res_unit = RESUNIT_INCH;
        TIFFSetField(out, TIFFTAG_XRESOLUTION, xres);
        TIFFSetField(out, TIFFTAG_YRESOLUTION, yres);
        TIFFSetField(out, TIFFTAG_RESOLUTIONUNIT, res_unit);

        /* We are writing single page of the multipage file */
        TIFFSetField(out, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE);
        /* Set the page number */
        TIFFSetField(out, TIFFTAG_PAGENUMBER, page, NPAGES);

        for (j = 0; j < image_height; j++)
            TIFFWriteScanline(out, &array[j * image_width], j, 0);

        TIFFWriteDirectory(out);
    }

    return 1;
}

bool _SaveTIFF()
 {

    TIFF* tif=TIFFClientOpen("Stream", "w", (thandle_t)st,
                           tiff_Read, tiff_Write,
                           tiff_Seek, tiff_Close,
                           tiff_Size,
                           tiff_Map, tiff_Unmap);

    if(!tif)
        return 0;

    WT t(st, context, tif);

    t.WriteTIF();

    TIFFClose(tif);

    return TRUE;
 };
////////////////////////////////////////////////////////////////////////////
/////////

The problem lies in the toff_t tiff_Seek(thandle_t st,toff_t pos, int
whence) function

I am getting an invalid toff_t pos value. Or in other words the seek
position value is invalid and thus my stream function
((MyStream*)st)->Seek(pos,dwMoveMethod); is crashing and complaining. The
error description is as follows

"Seek error:

OS Info: An attempt was mode to move the file pointer before the beginning
of the file"

Before the crash occurs the pos value is decimal 4294967293 or FFFFFFFD and
whence value is 0 (SEEK_SET). As you can see the code FFFFFFFF case is
handled by the code but not FFFFFFFD.

Please provide me with suggestions and advice and what can be causing this
problem?

Thank you,

Regards,

Mitesh Raj Pandey