Skip to content

Commit 86bc18a

Browse files
committed
oiiotool: control flow
How do you craft an oiiotool command that will examine a file and add an alpha=1 channel if it's a 3-channel file, but leave the existing alpha alone if it's already a 4 channel file? This patch adds control flow, so you could express the above like this: oiiotool in.exr --if "{TOP.nchannels < 4}" --ch R,G,B,A=1 --endif -o out.exr The following slate of new fetures is added: * `--set name value` sets a "user variable". * Expression evaluation will expand identifiers that are the names of user variables. For example, `{i}` is replaced by the value of user variable `i`, and `{i+3}` returns 3 more than the current numerical value of `i`. * Expression evaluation has been extended to support the following numerical comparison operators: `<` `>` `<=` `>=` `==` `!=` and `<=>` (the last one being the 3-way comparison, like in C++20). Also logical operators `&&` and `||`. All return 1 for true, 0 for false. Note that the comprison and logical operators have the same precedence as `+` and `-`, so use parentheses liberally to disambiguate complex mixed expressions. * New functions recognized within expressions: - the value held by a named user variable: `var(name)` - logical negation: `!`, `not()` - string comparison: `eq()`, `neq()` * `--if condition commands... [--else commands...] --endif` * `--while condition commands... --endwhile` * `--for variable range commands... --endfor` where the range may be, like Python, any of `end` (implied begin=0, step=1), `begin,end` (implied step=1), or `begin,end,step`. Also needed to modify ArgParse so that it has the notion of whether it's "running" -- actually calling the actions for each argument, or if it's merely parsing but taking no action -- and to be able to set and retrieve which command line argument index an action is responding to.
1 parent 1fe7bcd commit 86bc18a

File tree

21 files changed

+1196
-345
lines changed

21 files changed

+1196
-345
lines changed

src/cmake/testing.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ endmacro ()
155155
macro (oiio_add_all_tests)
156156
# Tests that require oiio-images:
157157
oiio_add_tests (gpsread
158-
oiiotool oiiotool-attribs oiiotool-copy
158+
oiiotool oiiotool-attribs oiiotool-copy
159159
oiiotool-xform
160160
maketx oiiotool-maketx
161161
misnamed-file
@@ -172,7 +172,7 @@ macro (oiio_add_all_tests)
172172
oiio_add_tests (
173173
cmake-consumer
174174
nonwhole-tiles
175-
oiiotool-composite
175+
oiiotool-composite oiiotool-control
176176
oiiotool-fixnan
177177
oiiotool-pattern
178178
oiiotool-readerror

0 commit comments

Comments
 (0)