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
April 2009

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

2009.04.06 15:35 "Writing tiff to in-memory buffer", by Christian Henning
2009.04.06 16:30 "Re: Writing tiff to in-memory buffer", by Bob Friesenhahn
2009.04.06 18:10 "Re: Writing tiff to in-memory buffer", by Christian Henning
2009.04.06 18:45 "Re: Writing tiff to in-memory buffer", by Bob Friesenhahn
2009.04.07 13:44 "Re: Writing tiff to in-memory buffer", by Christian Henning
2009.04.07 14:13 "Re: Writing tiff to in-memory buffer", by Edward Lam
2009.04.07 15:35 "Re: Writing tiff to in-memory buffer", by Bob Friesenhahn
2009.04.07 15:56 "Re: Writing tiff to in-memory buffer", by Christian Henning

2009.04.06 15:35 "Writing tiff to in-memory buffer", by Christian Henning

Hi there, I'm extending my code to allow writing to an in-memory
buffer using std::stringstream. I'm using stringstream successfully
with libpng and libjpeg. Though, I thought libtiff can do that too.
I'm actually pretty sure it can and the fault is on my side. Please
consider the following code:


static tsize_t read_proc( thandle_t fd
                        , tdata_t buf
                        , tsize_t size
                        )
{
    return size;
}

static tsize_t write_proc( thandle_t handle
                         , tdata_t   buf
                         , tsize_t   size
                         )
{
    std::ostream* os = reinterpret_cast< std::ostream* >( handle );
    boost::gil::detail::io_error_if( os->write( reinterpret_cast<char
const*>( buf )
                          , static_cast<std::streamsize>( size )
                          ).bad() == true
               , "ostream_device: Cannot write."
               );

    return size;
}

static toff_t seek_proc( thandle_t handle
                       , toff_t    off
                       , int       i
                       )
{
    std::ostream* os = reinterpret_cast< std::ostream* >( handle );

    os->seekp( off
             , i == SEEK_SET
             ? std::ios::beg
             : ( i == SEEK_CUR
                 ? std::ios::cur
                 : std::ios::end )
              );

    return off;
}

static int close_proc( thandle_t handle )
{
    std::ostream* os = reinterpret_cast< std::ostream* >( handle );
    os->operator<< ( std::flush );

    return 0;
}

static toff_t size_proc( thandle_t handle )
{
    return 0;
}

void error_handler( const char* module, const char* fmt, va_list ap )
{
}

int main()
{
    TIFFSetErrorHandler(&error_handler);

    stringstream ss( ios_base::in | ios_base::out | ios_base::binary );

    TIFF* t = TIFFClientOpen( "dummy"
                            , "w"
                            , &ss
                            , &read_proc
                            , &write_proc
                            , &seek_proc
                            , &close_proc
                            , &size_proc
                            , NULL
                            , NULL
                            );

}

TIFFClientOpen returns zero while the error handler tells me:

"Not a TIFF or MDI file, bad magic number %d (0x%x)"

I'm using libtiff version 3 something.

Someone any idea what I'm doing wrong here?

Thanks,
Christian