libtiff.net
libtiff.net copied to clipboard
Added overload for NumberOfDirectories to return list of directory po…
I've added some extra methods that allows advanced use cases to cache directory offsets for super fast page specific retrieval in subsequent calls. I am using this for multi-thousand page tiff's and decided to submit PR.
Hello Marius,
Thank you for the PR.
Could you please share the before/after stats for your case? I mean, how much time is saved with the changes?
Also, could you please clarify what do you need the Ifd class for?
Other points:
- There is a merge conflict that should be resolved
- Overloads for
advanceDirectory
seems like not needed. "Starting with C# 7.0, you can declare the out variable in the argument list of the method call, rather than in a separate variable declaration." Would you agree this is enough? Or do you see some other reasons for having the overloads? - I would expect existing
SetDirectory
to call the newSetDirectory(short number, long directoryOffset)
in order to avoid code duplication. - The same is for
NumberOfDirectories
and the newGetNumberOfDirectories
. I would expect the former to call the latter.
Distinguishing here between Random access to IFDs as opposed to simple one step forward access to the next IFD.
Fast random access works today (see below), but is not very user friendly as pointed out above. Also it does not avoid the "extra seek" to read each IFD.;Caching could help there.
The more user friendly system suggested in this PR must ensure that the chain of IFDs has not been altered by a add/ change/ delete/ insert. So this is limited to read only access, or must update the list when we write to the stream and change the IFD chain.
Here is one way to do random access today:
For random access we can scan through the IFDs once and store the offsets into a list
- using ReadDirectory() and CurrentDirOffset() we can then jump to any IFD
- using Tiff.SetSubDirectory(ifdOffset).
here is a fragment that does that
//scan the pages long offset = input.CurrentDirOffset(); pageList.Add(offset); while (input.ReadDirectory()) { offset = input.CurrentDirOffset(); pageList.Add(offset); } //now revisit the pages foreach (long ifdOffset in pageList) { input.SetSubDirectory(ifdOffset); //... do stuff here }
(There is also the m_dirlist field of "already visited" directories).
Given that @celeronpm didn't answer for 3+ years, I am closing this pull request. It is not ready to be merged anyway.
@xela-trawets desribed a workaround for the original issue. The workaround might not be very convenient, but it works without any changes to the library code.