| 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 |
Thread2009.04.06 15:35 "Writing tiff to in-memory buffer", by Christian HenningHi 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
|
|||||||