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.07 13:44 "Re: 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/