-
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.07 13:44 "Re: [Tiff] Writing tiff to in-memory buffer", by Christian Henning
Ok, my read function was wrong. Since I only want to write into the buffer the read procedure should return 0 and not the size read. Fixing that gives me a valid TIFF*. I also need to setup my seek_proc to prohibit it from seeking on an empty ostream. Doing though would raise the failbit. I don't understand why TIFFClientOpen is calling seek_proc( 0,0). It seems redundant to me.
This code is working:
static tsize_t read_proc( thandle_t fd
, tdata_t buf
, tsize_t size
)
{
return 0;
}
static tsize_t write_proc( thandle_t handle
, tdata_t buf
, tsize_t size
)
{
std::ostream* os = reinterpret_cast< std::ostream* >( handle );
os->write( reinterpret_cast< char const*>( buf )
, static_cast<std::streamsize>( size )
);
return size;
}
static toff_t seek_proc( thandle_t handle
, toff_t off
, int i
)
{
std::ostream* os = reinterpret_cast< std::ostream* >( handle );
std::ostream::streamoff size = os->tellp();
if( size == -1 ) return 0;
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
);
}
On Mon, Apr 6, 2009 at 2:45 PM, Bob Friesenhahn <bfriesen@simple.dallas.tx.us> wrote:
> On Mon, 6 Apr 2009, Christian Henning wrote:
>>>
>>> It should be useful to use contrib/stream/tiffstream.cpp from the libtiff >>> source distribution as a reference. The version which will be included
>>> in
>>> libtiff4 is updated to standard C++.
>>
>> Seems I need to recompile libtiff and start debugging. Does the code
>> work on your machine?
>
> I don't know if your code would work on my machine and I have also never > actually tested contrib/stream/tiffstream.cpp.
>
> I am now also reminded that there is a libtiff/tif_stream.cxx which is
> included in libtiff's C++ library. I have spent some time updating this > source file for libtiff4 (but without actually testing it).
>
> As far as the viability of TIFFClientOpen() goes, GraphicsMagick has been > using it for many years without any problems.
>
> The error message you are seeing suggests that libtiff requests to read back > from the file it is writing and perhaps your wrapper functions do not
> adequately support this.
Bob
--
Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/