Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Incorrect subimages for TX files #2719

Closed
zavinator opened this issue Sep 23, 2020 · 4 comments · Fixed by #2723
Closed

[BUG] Incorrect subimages for TX files #2719

zavinator opened this issue Sep 23, 2020 · 4 comments · Fixed by #2723

Comments

@zavinator
Copy link

Describe the bug
Traversing subimages in TX files (multipage TIF) cause an infinitive loop.
It is not returning a correct ImageSpec for the given page.

To Reproduce
Steps to reproduce the behavior:

auto in = OIIO::ImageInput::open("normal.tif");
auto spec = in->spec();
int subimage = 0;
while (spec.format != OIIO::TypeUnknown) 
{
  //...
  spec = in->spec(++subimage); // next subimage
}

Expected behavior
It works correctly for multipart EXRs - the loop ends by returning OIIO::TypeUnknown format if subimage not exists.
It also looks that the spec is not updated after calling in->spec(++subimage)

Evidence
normal.zip

Platform information:

  • OIIO branch/version: 2.1.17
  • OS: Windows 10 x64
  • C++ compiler: VS2019 x64
  • Any non-default build flags when you build OIIO:
@lgritz
Copy link
Collaborator

lgritz commented Sep 26, 2020

Yes, I can reproduce. Looking into it...

@lgritz
Copy link
Collaborator

lgritz commented Sep 26, 2020

A combination of a bug and a misunderstanding.

When a TIFF file is found to contain the tag TIFFTAG_PIXAR_TEXTUREFORMAT, it's recognized as a MIP-mapped texture, with the multiple TIFF directories interpreted as MIPmap levels of a single "subimage" (whereas without that tag, the image is treated as if it has multiple subimages, but they aren't MIPmapped).

The full signature of the spec() function is: ImageInput::spec(int subimage, int miplevel=0)

I can't tell if you (a) want to walk through what OIIO considers subimages, and expect to see just ONE (which will have many MIP levels, but you aren't iterating over those in your example); or (b) if you want to walk through the MIP levels.

If (b), then you want your loop to look like this:

int miplevel = 0;
while (spec.format != OIIO::TypeUnknown) 
{
  //...
  spec = in->spec(0, ++miplevel); // next MIP level
}

However, if you really did want (a), then you are doing it correctly and there is a bug -- totally my fault -- in ImageInput::spec(), in the specific case where it's a "mip-mapped" TIFF file but you are passing an invalid subimage request. I will post a patch immediately, stay tuned...

@lgritz
Copy link
Collaborator

lgritz commented Sep 26, 2020

Proposed fix: #2723

@zavinator
Copy link
Author

(a) is right :)
I'm using the subimage for multipart exrs and I don't need to walk through the MIP levels...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants