Skip to content

Commit 8e579df

Browse files
committed
BOTTOM as symonym for the bottom of the stack
Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent eb5dd6d commit 8e579df

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

src/doc/oiiotool.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ contents of an expression may be any of:
126126
The *imagename* may be one of:
127127

128128
* `TOP` : the top or current image;
129+
* `BOTTOM` : the image at the bottom of the stack;
129130
* `IMG[index]` : if `index` evaluates to an integer `i`, the i-th image on
130131
the stack (thus `TOP` is a synonym for `IMG[0]`, the next image on the
131-
stack is `IMG[1]`, etc.);
132+
stack is `IMG[1]`, ..., and `BOTTOM` is a synonmym for `IMG[NIMAGES-1]`);
132133
* `IMG[name]` : an image named by filename or by label name.
133134

134135
Remember that the positions on the stack (including `TOP`) refer to *at that

src/oiiotool/expressions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,14 @@ Oiiotool::express_parse_atom(const string_view expr, string_view& s,
149149
return false;
150150

151151
} else if (Strutil::starts_with(s, "TOP")
152+
|| Strutil::starts_with(s, "BOTTOM")
152153
|| Strutil::starts_with(s, "IMG[")) {
153154
// metadata substitution
154155
ImageRecRef img;
155156
if (Strutil::parse_prefix(s, "TOP")) {
156157
img = curimg;
158+
} else if (Strutil::parse_prefix(s, "BOTTOM")) {
159+
img = (image_stack.size() <= 1) ? curimg : image_stack[0];
157160
} else if (Strutil::parse_prefix(s, "IMG[")) {
158161
std::string until_bracket = Strutil::parse_until(s, "]");
159162
if (until_bracket.empty() || !Strutil::parse_char(s, ']')) {

testsuite/oiiotool-control/ref/out.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,9 @@ Stats FiniteCount: 12288 12288 12288
259259
Constant: No
260260
Monochrome: No
261261

262-
Stack holds [0] = ../common/tahoe-small.tif, [1] = ../common/tahoe-tiny.tif
263-
Stack holds [1] = ../common/tahoe-tiny.tif
262+
Stack holds [0] = ../common/grid.tif, [1] = ../common/tahoe-small.tif, [2] = ../common/tahoe-tiny.tif
263+
TOP = ../common/grid.tif, BOTTOM = ../common/tahoe-tiny.tif
264+
Stack holds [1] = ../common/tahoe-small.tif
264265
filename=../common/tahoe-tiny.tif file_extension=.tif file_noextension=../common/tahoe-tiny
265266
MINCOLOR=0,0,0 MAXCOLOR=0.745098,1,1 AVGCOLOR=0.101942,0.216695,0.425293
266267
Testing NIMAGES:

testsuite/oiiotool-control/run.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,13 @@
134134
+ " --echo \"\\nMeta native: {TOP.METANATIVE}\""
135135
+ " --echo \"\\nStats:\\n{TOP.STATS}\\n\"")
136136

137-
# Test IMG[]
138-
command += oiiotool ("../common/tahoe-tiny.tif ../common/tahoe-small.tif " +
139-
"--echo \"Stack holds [0] = {IMG[0].filename}, [1] = {IMG[1].filename}\" " +
137+
# Test IMG[], TOP, BOTTOM
138+
command += oiiotool ("../common/tahoe-tiny.tif ../common/tahoe-small.tif ../common/grid.tif " +
139+
"--echo \"Stack holds [0] = {IMG[0].filename}, [1] = {IMG[1].filename}, [2] = {IMG[2].filename}\" " +
140+
"--echo \"TOP = {TOP.filename}, BOTTOM = {BOTTOM.filename}\" " +
140141
"--set i 1 " +
141-
"--echo \"Stack holds [{i}] = {IMG[i].filename}\" ")
142+
"--echo \"Stack holds [{i}] = {IMG[i].filename}\" "
143+
)
142144

143145
# Test some special attribute evaluation names
144146
command += oiiotool ("../common/tahoe-tiny.tif " +

0 commit comments

Comments
 (0)