Skip to content

Commit b7e1862

Browse files
authored
feat(oiiotool): New expression pseudo-metadata term: SUBIMAGES (AcademySoftwareFoundation#4804)
When doing oiiotool command line expression substitution, asking for this metadata evaluates to the number of subimages in the referenced image. The purpose is that asking to retrieve, say, `{TOP.'oiio:subimages'}` might look right, but generally it's only added to images (or format readers) that are potentially multi-image. Whereas SUBIMAGES is not actual image metadata, it's just an evaluation token that will always be the number of subimages. Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent 771bc2d commit b7e1862

4 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/doc/oiiotool.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ contents of an expression may be any of:
165165
be printed with `oiiotool -stats`.
166166
* `IS_CONSTANT`: metadata to check if the image pixels are of constant color, returns 1 if true, and 0 if false.
167167
* `IS_BLACK`: metadata to check if the image pixels are all black, a subset of IS_CONSTANT. Also returns 1 if true, and 0 if false.
168+
* `SUBIMAGES`: the number of subimages in the file.
168169

169170
* *imagename.'metadata'*
170171

src/oiiotool/expressions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ Oiiotool::express_parse_atom(const string_view expr, string_view& s,
339339
// Not even constant color case -> We don't want those to count as black frames.
340340
result = "0";
341341
}
342+
} else if (metadata == "SUBIMAGES") {
343+
result = Strutil::to_string(img->subimages());
342344

343345
} else if (using_bracket) {
344346
// For the TOP[meta] syntax, if the metadata doesn't exist,

testsuite/oiiotool-control/ref/out.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ TOP = ../common/grid.tif, BOTTOM = ../common/tahoe-tiny.tif
326326
Stack holds [1] = ../common/tahoe-small.tif
327327
filename=../common/tahoe-tiny.tif file_extension=.tif file_noextension=../common/tahoe-tiny
328328
MINCOLOR=0,0,0 MAXCOLOR=0.745098,1,1 AVGCOLOR=0.101942,0.216695,0.425293
329+
SUBIMAGES=1
329330
Testing expressions IS_BLACK, IS_CONSTANT:
330331
grey is-black? 0 is-constant? 1
331332
black is-black? 1 is-constant? 1

testsuite/oiiotool-control/run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@
181181
# Test some special attribute evaluation names
182182
command += oiiotool ("../common/tahoe-tiny.tif " +
183183
"--echo \"filename={TOP.filename} file_extension={TOP.file_extension} file_noextension={TOP.file_noextension}\" " +
184-
"--echo \"MINCOLOR={TOP.MINCOLOR} MAXCOLOR={TOP.MAXCOLOR} AVGCOLOR={TOP.AVGCOLOR}\"")
184+
"--echo \"MINCOLOR={TOP.MINCOLOR} MAXCOLOR={TOP.MAXCOLOR} AVGCOLOR={TOP.AVGCOLOR}\" " +
185+
"--echo \"SUBIMAGES={TOP.SUBIMAGES}\"")
185186

186187
command += oiiotool ("--echo \"Testing expressions IS_BLACK, IS_CONSTANT:\" " +
187188
"--pattern:type=uint16 constant:color=0.5,0.5,0.5 4x4 3 " +

0 commit comments

Comments
 (0)