Skip to content

Commit 9efbfd5

Browse files
committed
updated expressions logic per feedback
Signed-off-by: Lydia Zheng <[email protected]>
1 parent f8d9380 commit 9efbfd5

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/doc/oiiotool.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ contents of an expression may be any of:
163163
information from when the file was read from disk.
164164
* `STATS` : a multi-line string containing the image statistics that would
165165
be printed with `oiiotool -stats`.
166-
166+
* `IS_CONSTANT`: metadata to check if the image pixels are of constant color, returns 1 if true, and 0 if false.
167+
* `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+
167169
* *imagename.'metadata'*
168170

169171
If the metadata name is not a "C identifier" (initial letter followed by

src/oiiotool/expressions.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,32 @@ Oiiotool::express_parse_atom(const string_view expr, string_view& s,
317317
result = out.str();
318318
if (result.size() && result.back() == '\n')
319319
result.pop_back();
320+
321+
} else if (metadata == "IS_CONSTANT") {
322+
std::vector<float> color((*img)(0, 0).nchannels());
323+
if (ImageBufAlgo::isConstantColor((*img)(0, 0), 0.0f, color)) {
324+
result = "1";
325+
} else {
326+
result = "0";
327+
}
328+
329+
330+
} else if (metadata == "IS_BLACK") {
331+
std::vector<float> color((*img)(0, 0).nchannels());
332+
// Check constant first to guard against false positive average of 0 with negative values i.e. -2, 1, 1
333+
if (ImageBufAlgo::isConstantColor((*img)(0, 0), 0.0f, color)) {
334+
// trusting that the constantcolor check means all channels have the same value, so we only check the first channel
335+
if (color[0] == 0.0f) {
336+
result = "1";
337+
}
338+
else {
339+
result = "0";
340+
}
341+
} else {
342+
// Not even constant color case -> We don't want those to count as black frames.
343+
result = "0";
344+
}
345+
320346
} else if (using_bracket) {
321347
// For the TOP[meta] syntax, if the metadata doesn't exist,
322348
// return the empty string, and do not make an error.

0 commit comments

Comments
 (0)