AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2014.05.09 12:06 "[Tiff] TIFFCurrentDirectory inconsistency", by Roger Leigh
2014.05.09 13:17 "Re: [Tiff] TIFFCurrentDirectory inconsistency", by Roger Leigh

2014.05.09 12:06 "[Tiff] TIFFCurrentDirectory inconsistency", by Roger Leigh

Hi. I'm using tiff 4.0.3 on Debian.

If I iterate over all IFDs in a TIFF by index using TIFFSetDirectory, and for each IFD query the index, offset and whether it's last with TIFFCurrentDirectory, TIFFCurrentDirOffset and TIFFLastDirectory I get this:

[ RUN      ] TIFFTest.IFDsByIndex
IDX: 0   OFF: 8 LAST: 0
IDX: 1   OFF: 839 LAST: 0
IDX: 2   OFF: 1670 LAST: 0
IDX: 3   OFF: 2501 LAST: 0
IDX: 4   OFF: 3332 LAST: 0
IDX: 5   OFF: 4163 LAST: 0
IDX: 6   OFF: 4994 LAST: 0
IDX: 7   OFF: 5825 LAST: 0
IDX: 8   OFF: 6656 LAST: 0
IDX: 9   OFF: 7487 LAST: 1

All looks fine.  But, if I iterate by offset using TIFFSetSubDirectory:

[RUN      ] TIFFTest.IFDsByOffset
IDX: 5   OFF: 8 LAST: 0
IDX: 6   OFF: 839 LAST: 0
IDX: 7   OFF: 1670 LAST: 0
IDX: 8   OFF: 2501 LAST: 0
IDX: 9   OFF: 3332 LAST: 0

IDX: 10   OFF: 4163 LAST: 0
IDX: 11   OFF: 4994 LAST: 0
IDX: 12   OFF: 5825 LAST: 0
IDX: 13   OFF: 6656 LAST: 0
IDX: 14   OFF: 7487 LAST: 1

You can see here that while the offsets are identical, the indexes returned by TIFFCurrentDirectory are now somewhat fictional.

Likewise, if I set the directory to index 0 with TIFFSetDirectory, and then iterate using TIFFReadDirectory. I'm calling TIFFReadDirectory, then TIFFCurrentDirOffset, then TIFFSetSubDirectory in a loop (I'm caching the offsets)

[ RUN      ] TIFFTest.IFDSimpleIter
IDX: 0   OFF: 8 LAST: 0
IDX: 4   OFF: 839 LAST: 0
IDX: 9   OFF: 1670 LAST: 0
IDX: 14   OFF: 2501 LAST: 0
IDX: 19   OFF: 3332 LAST: 0
IDX: 24   OFF: 4163 LAST: 0
IDX: 29   OFF: 4994 LAST: 0
IDX: 34   OFF: 5825 LAST: 0
IDX: 39   OFF: 6656 LAST: 0
IDX: 44   OFF: 7487 LAST: 1

Again, the offsets are incorrect. And unlike the previous example, they aren't just off by +5, it's incrementing by 4, then 5 for all subsequent TIFFReadDirectory calls.

For the last example, if I call TIFFSetSubdirectory three times in a row instead of once, the indexes change:

[ RUN      ] TIFFTest.IFDSimpleIter
IDX: 0   OFF: 8 LAST: 0
IDX: 10   OFF: 839 LAST: 0
IDX: 23   OFF: 1670 LAST: 0
IDX: 36   OFF: 2501 LAST: 0
IDX: 49   OFF: 3332 LAST: 0
IDX: 62   OFF: 4163 LAST: 0
IDX: 75   OFF: 4994 LAST: 0
IDX: 88   OFF: 5825 LAST: 0

IDX: 101   OFF: 6656 LAST: 0
IDX: 114   OFF: 7487 LAST: 1

My question is really just if this is expected behaviour or not? Are the indexes expected to be valid if I've not called TIFFSetDirectory explicitly, and instead used TIFFSetSubDirectory or TIFFReadDirectory? Something seems a bit amiss in how the index is computed.

Many thanks,

Roger

--
  .''`. Roger Leigh

 : :' :  Debian GNU/Linux    http://people.debian.org/~rleigh/
 `. `'   schroot and sbuild  http://alioth.debian.org/projects/buildd-tools

`- GPG Public Key F33D 281D 470A B443 6756 147C 07B3 C8BC 4083 E800