2000.11.23 20:06 "Using libtiff without reading from a file", by Wolfram Bettermann

2000.11.24 13:52 "Re: [Re: Using libtiff without reading from a file]", by Bjorn Brox

thanks for discussing this topic so deeply, I appreciate that.

Somehow I'm lost. Can I now use TIFFClientOpen to pass a memory blob to libtiff, and use TIFFRGBA to get it decoded or do I have to use ImageMagick (thanks, Leonhard!)

The only problem with passing a blob of memory to libtiff using TIFFOpen I saw was that libtiff uses internally a "tif" handle

It is this handle that is the client part, - not an internal tiff handle.

Just define any structure you want, fill in the values needed for managing io, opening files etc, and pass it to TIFFClientOpen() together with pointers to your own io functions, where the first parameter, thandle_t, is the handle you supplied to TIFFClientOpen(). In your own io-functions you just cast the thandle_t parameter to your own struct typedef and use it.

Example reading from memory:

typedef struct {
        char *data;
        size_t data_size;
        size_t io_pos;
    } Fm_TiffInfo;

static tsize_t FM_tiffReadProc(thandle_t th, tdata_t buf, tsize_t size)
    Fm_TiffInfo *fmti = (Fm_TiffInfo *)th;

    if (fmti->io_pos + size > fmti->data_size)
        size = fmti->data_size - fmti->io_pos;

    (void)memcpy(buf, fmti->data + fmti->io_pos, size);
    fmti->io_pos += size;
    return size;

    Fm_TiffInfo fmti;

    fmti.data = data;
    fmti.data_size = data_size;
    fmti.io_pos = 0;


    tif = TIFFClientOpen("dummy", "r", (thandle_t) &fmti,
                         FM_tiffReadProc, FM_tiffWriteProc,
                         FM_tiffSeekProc, FM_tiffCloseProc,
                         FM_tiffSizeProc, FM_tiffMapProc,

- Brox, CORENA Norge AS, http://www.corena.no/, ICQ 17872043
Kirkegaardsvn. 45, P.O.Box 1024, N-3601 Kongsberg, NORWAY
Phone: +47 32287435, Fax: +47 32736877, Mobile: +47 92638590