fix: Improve IB::nsubimages and other related fixes #4228
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background: Some formats that support multi-image files know as soon as they are opened and read the header what the total subimage count is. Others (I'm looking at you, TIFF) can't know without reading each subimage in succession until you hit the end of the file. Format readers who can easily figure it out open first opening are supposed to set attribute "oiio:subimages" to the number of subimages, or 0 / unset if it can't be cheaply or immediately determined.
ImageBuf has a
nsubimages()
method that you'd think would give you the right count, and it did when all IBs were read through the ImageCache (which fully inventories the subimages of any file it reads). But when OIIO 2.5 changed IB behavior to only be backed by IC when explicitly requested, we effectively lost this functionality most of the time, and instead returned 0 ("don't know yet"). This was confusing. And also silly, because it reported 0 even for files whose formats don't permit multiple images (so you know the count is 1).This patch does the following:
ImageBuf::nsubimages()
to the following return values:Fixes #4225