-
Notifications
You must be signed in to change notification settings - Fork 633
oiiotool: control flow #3243
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
Merged
Merged
oiiotool: control flow #3243
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I beg you to reconsider your life choices if you find yourself doing anything like this:
|
Update: Added |
There is a special notoriety, and a surprise gift from me, for the first person who posts the code for a working ray tracer implemented entirely as a single oiiotool command line. |
Updated PR to add new expression functionality:
|
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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:
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 uservariable
i
, and{i+3}
returns 3 more than the current numericalvalue 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).Note that the comprison operators have the same precedence as
+
and
-
, so use parentheses liberally to disambiguate complex mixedexpressions.
--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.