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

oiiotool: allow optional subimages modifier for many ops #2582

Merged
merged 1 commit into from
May 14, 2020

Conversation

lgritz
Copy link
Collaborator

@lgritz lgritz commented May 12, 2020

For a large number of oiiotool commands (anything whose implementation
inherits from the OiiotoolOp class), allow the optional modifier
:subimages=... to control how the operation applies to different
subimages (when dealing with multi-subimage images).

Of course, previously, the default is that most commands operate only
on the first subimage, discarding the others. The global -a (and for
many commands the optional :allsubimages=1 modifier) cause all
subimages to be preserved and the operation to be performed on all of
them.

This new subimages=... allows more fine-grained control by
specifying which subimages will be active, as a comma-separated list
of either numeric indices (starting at 0) or subimage names. The
special string "all" means all subimages (thus :subimages=all is
equivalent to :allsubimages=1). Any subimage number or name preceded
by a "-" excludes that subimage from the active list. The operation
is performed on only on the active subimages, with excluded subimages
merely being copied from the first input image. The presence of any
subimages modifier implies that all subimages should be preserved.

For example, if a.exr is a "multi-part" OpenEXR image (what OIIO calls
multi-image):

# color convert just the first subimage, discard the rest
oiiotool a.exr --colorconvert linear sRGB -o out.exr

# color convert and output all subimages: -a
oiiotool -a a.exr --colorconvert linear sRGB -o out.exr

# color convert just the subimage named "beauty", but output them all
oiiotool a.exr --colorconvert:subimages=beauty linear sRGB -o out.exr

# color convert all EXCEPT the subimage named "normal"
oiiotool a.exr --colorconvert:subimages=-normal linear sRGB -o out.exr

# color convert subimages 1, 2, and 5, leave the others unmodified
oiiotool a.exr --colorconvert:subimages=1,3,5 linear sRGB -o out.exr

Signed-off-by: Larry Gritz lg@larrygritz.com

For a large number of oiiotool commands (anything whose implementation
inherits from the OiiotoolOp class), allow the optional modifier
`:subimages=...` to control how the operation applies to different
subimages (when dealing with multi-subimage images).

Of course, previously, the default is that most commands operate only
on the first subimage, discarding the others. The global `-a` (and for
many commands the optional `:allsubimages=1` modifier) cause all
subimages to be preserved and the operation to be performed on all of
them.

This new `subimages=...` allows more fine-grained control by
specifying which subimages will be active, as a comma-separated list
of either numeric indices (starting at 0) or subimage names. The
special string "all" means all subimages (thus `:subimages=all` is
equivalent to `:allsubimages=1`). Any subimage number or name preceded
by a "-" excludes that subimage from the active list.  The operation
is performed on only on the active subimages, with excluded subimages
merely being copied from the first input image. The presence of any
`subimages` modifier implies that all subimages should be preserved.

For example, if a.exr is a "multi-part" OpenEXR image (what OIIO calls
multi-image):

    # color convert just the first subimage, discard the rest
    oiiotool a.exr --colorconvert linear sRGB -o out.exr

    # color convert and output all subimages: -a
    oiiotool -a a.exr --colorconvert linear sRGB -o out.exr

    # color convert just the subimage named "beauty", but output them all
    oiiotool a.exr --colorconvert:subimages=beauty linear sRGB -o out.exr

    # color convert all EXCEPT the subimage named "normal"
    oiiotool a.exr --colorconvert:subimages=-normal linear sRGB -o out.exr

    # color convert subimages 1, 2, and 5, leave the others unmodified
    oiiotool a.exr --colorconvert:subimages=1,3,5 linear sRGB -o out.exr

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

Love it!! :)

@lgritz
Copy link
Collaborator Author

lgritz commented May 12, 2020

Thanks for the prompt to consider this issue. I'm really pleased with this solution, and it also inspires me to convert all the remaining ops to be subclasses of OiiotoolOp. It's very powerful to have a central place where I can make an interesting option apply to all commands. It would have taken a long time (and be very error-prone) to do this to each op individually.

@lgritz lgritz merged commit 10d8f40 into AcademySoftwareFoundation:master May 14, 2020
@lgritz lgritz deleted the lg-subimages branch May 17, 2020 04:27
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.

None yet

2 participants