Skip to content

fix(oiiotool): better type understanding with -i:ch= and other cleanup#5056

Open
lgritz wants to merge 3 commits intoAcademySoftwareFoundation:mainfrom
lgritz:lg-half
Open

fix(oiiotool): better type understanding with -i:ch= and other cleanup#5056
lgritz wants to merge 3 commits intoAcademySoftwareFoundation:mainfrom
lgritz:lg-half

Conversation

@lgritz
Copy link
Collaborator

@lgritz lgritz commented Feb 21, 2026

Background: oiiotool is pretty good at remembering the data type of the first file it reads in a command, and ensuring that the output preserves the same types, despite the fact that internally, it tends to keep everything in float. (As a further reminder: -d can override the heuristics that make this work.)

But there was an exception: when -i was used with the optinal modifier -i:ch=... to select a subset of channels or reorder channels upon read, the underlying call to IBA::channels would cause it to not have that information in the "nativespec" at the right time that it was collected.

This PR primarily ensures that the -i:ch=... preserves the information about which channels had which data types, despite the channel shuffle.

Some other bits and pieces along the way:

  • A new TypeDesc::basetype_merge() variety that take a cspan<TypeDesc>.
  • A new utility TypeDesc::all_types_equal(cspan<TypeDesc>)
  • Cleanup in IBA::channels() to more correctly compute the common type of the channel subset that you actually specify.

Background: oiiotool is pretty good at remembering the data type of
the first file it reads in a command, and ensuring that the output
preserves the same types, despite the fact that internally, it tends
to keep everything in float. (As a further reminder: -d can override
the heuristics that make this work.)

But there was an exception: when `-i` was used with the optinal
modifier `-i:ch=...` to select a subset of channels or reorder
channels upon read, the underlying call to IBA::channels would cause
it to not have that information in the "nativespec" at the right time
that it was collected.

This PR primarily ensures that the `-i:ch=...` preserves the information
about which channels had which data types, despite the channel shuffle.

Some other bits and pieces along the way:

* A new `TypeDesc::basetype_merge()` variety that take a `cspan<TypeDesc>`.
* A new utility `TypeDesc::all_types_equal(cspan<TypeDesc>)`
* Cleanup in IBA::channels() to more correctly cmopute the common type
  of the channel subset that you actually specify.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes oiiotool’s native type propagation when -i is combined with channel selection/reordering (-i:ch=...), ensuring the “first input’s” per-channel native types are preserved even after a channel shuffle.

Changes:

  • Preserve/restore nativespec channel format information after applying ImageBufAlgo::channels() during -i:ch=....
  • Add new TypeDesc helpers: basetype_merge(cspan<TypeDesc>) and all_types_equal(cspan<TypeDesc>).
  • Update ImageBufAlgo::channels() to compute the merged output format from the actually-selected channels and clear channelformats when uniform; extend tests to cover the regression case.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
testsuite/oiiotool-copy/run.py Adds a regression test exercising channel reordering/renaming without -d to validate correct type propagation.
testsuite/oiiotool-copy/ref/out.txt Updates expected output to include info for the new regression output file.
src/python/py_typedesc.cpp Exposes TypeDesc::all_types_equal to Python.
src/oiiotool/imagerec.cpp After IBA::channels() channel shuffles, restores per-channel native types into nativespec and recomputes merged native format.
src/libOpenImageIO/imagebufalgo_channels.cpp Computes newspec.format from selected channel formats and clears per-chan formats when all equal.
src/include/OpenImageIO/typedesc.h Adds span-based basetype merging and uniform-type checking helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

lgritz added 2 commits March 1, 2026 18:14
Signed-off-by: Larry Gritz <lg@larrygritz.com>
Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz
Copy link
Collaborator Author

lgritz commented Mar 4, 2026

2 weeks, no objections. Will merge by the end of the week.

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 this pull request may close these issues.

2 participants