oiiotool: expression evaluation and substitution for command line arguments#1064
Conversation
30f117f to
0588826
Compare
0588826 to
3917cc8
Compare
|
Response to this proposal internally at my facility has been very positive. I'll let it sit for a few more days to gather feedback and/or reviews by anybody looking over the code. But by early next week, if there are no objections, I will merge it. |
|
Only positive comments (offline), no objections, so I will merge this. |
…uments
Anything enclosed in braces { } in a command line argument will be
substituted by the evaluation of the enclosed expression.
Currently, expressions may be:
* numbers
* Simple arithmetic: expr + expr, expr - expr, expr * expr, expr / expr
(simple left to right evaluation, no operator precedence)
* Retrieve image metadata:
TOP.metadata current image
IMG[i].metadata ith image on the stack (IMG[0] is TOP)
IMG[name].metadata named image
We may allow more complex expressions later.
Motivating examples that illustrate how this can be used for fun and profit:
// create a gradient the same size as fg.exr, composite fg over it
oiiotool fg.exr --pattern fill:top=0,0,0,0:bottom=0,0,1,1 {TOP.geom} {TOP.nchannels} -over -o overgradient.exr
// trim 20 pixels from all sides
oiiotool input.exr -cut "{TOP.width-40}x{TOP.height-40}+{TOP.x+20}+{TOP.y+20}" -o cropped.exr
// Write the time in the lower left corner of the image
oiiotool -v input.jpg --text:size=30:x=30:y={TOP.height-30} {TOP.DateTime} -o out.jpg
3917cc8 to
ef4e56a
Compare
|
Sorry to dredge up an old merge request, but I had a question about the expression support. Am I correct that it isn't currently complex enough to handle something like expressing a "center padded" fit? Something along the lines of: ... where the input size is 2048x1152, and I would like to center pad to 2048x1556, but dynamically offset it. It would have to support something like |
|
And I realize I could have written this like: But still wondering if expressions can be used to offset dynamically. |
|
You were very close, just need to change the image references I think that should work. |
|
Ah, thanks for clarifying. And I also just realized that this feature wasn't merged into 1.5. At my studio I think our latest available build is 1.5.16 :-/ |
|
Aha, yes, that's a new 1.6/master feature. IIRC, oiiotool.cpp has diverged quite a bit and backporting would be a big pain. If it's any consolation, I am aiming to branch 1.6 relatively soon. Next few weeks, I hope. |
I've been thinking about this for a long time, and finally did it as a weekend project.
Motivating examples that illustrate how this can be used for fun and profit:
Anything enclosed in braces { } will undgo expression substitution.
Currently, expressions may be:
We may allow more complex expressions later, but this seems like a good start for now.
Feedback appreciated. And what clever things can you think to do with this feature?
(Note: this review incorporates pull request #1062 and #1063. You need not review those again here if you don't want. All the changes specific to this feature are on oiiotool.h and oiiotool.cpp, though they make use of the new features in those other two PR's.)