2005.04.06 10:22 "[Tiff] What if the given data is not the complete image/file?", by Katrina Maramba

2005.04.06 10:53 "Re: [Tiff] What if the given data is not the complete image/file?", by Joris Van Damme

I realize this is a bit hard since TIFFClientOpen would accept the whole image and parse it for you already. This time, I would have to do everything myself. I would be providing an alternative to TIFFClientOpen. Thats exactly what I need.. an alternative to TiffClientOpen.

One easy way I can think of, depends on your ability to 'suspend' input. This will probably only work if you have different threads receiving the data, retrieving the TIFF image data output, and maintaining the UI.

The first thread, that receives the data, will likely best put this data in a linked list of buffers. Protect the linked list with any mutux-like structure. Upon reception and thus addition of a new block in the linked list, set a manual reset event.

The second thread calls LibTiff's TIFFClientOpen, feeding it a pointer to a custom read function. The custom read function, when it needs to read,

- loop
    - enters the mutex
    - sees if the requested data is received already.
        - if it is, no problem,
            - mutex is left
            - requested data is returned (copied?)
            - exit reader function
        - if it is not, this read function
            - resets the manual reset event,
            - leaves the mutex
            - waits for the manual reset event
            - next iteration of loop

The big advantages of this, over the path you were walking is that 1) this setup makes full use of LibTiff, you don't need to add duplicate code of your own that knows the TIFF header, TIFF IFD structures, etc 2) any order is possible... You seem to think image data preceeds IFD. That is not necessarilly the case. It may be the other way around, or it may be that three page IFDs are followed by image data for all three in any order, etc.

The big disadvantage, is that this scheme needs 'waiting' inside the reader function, thus waiting inside your calls to LibTiff. That will not be suitable for you if you have a single-thread need, unless you don't mind a nested application message pump and such ugly problematic stuff. Thus, the need for multiple threads...

Joris Van Damme
info@awaresystems.be
http://www.awaresystems.be/
Download your free TIFF tag viewer for windows here:
http://www.awaresystems.be/imaging/tiff/astifftagviewer.html