-
2009.03.27 23:57 "Re: [Tiff] TIFFOpen throws access error", by Bob Friesenhahn
- 2009.03.30 18:26 "Re: [Tiff] TIFFOpen throws access error", by
-
2009.04.07 13:44 "Re: [Tiff] Writing tiff to in-memory buffer", by Christian Henning
- 2009.04.06 15:35 "[Tiff] Writing tiff to in-memory buffer", by Christian Henning
- 2009.04.07 14:13 "Re: [Tiff] Writing tiff to in-memory buffer", by Edward Lam
- 2009.04.07 15:35 "Re: [Tiff] Writing tiff to in-memory buffer", by Bob Friesenhahn
- 2009.04.08 20:56 "[Tiff] writing in-memory tiffs", by Christian Henning
- 2009.03.28 01:03 "Re: [Tiff] TIFFOpen throws access error", by Toby Thain
2009.04.06 15:35 "[Tiff] 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