Skip to content

Commit

Permalink
feat: adding is_constant and is_black checks
Browse files Browse the repository at this point in the history
Signed-off-by: Lydia Zheng <lydiamzheng@gmail.com>
  • Loading branch information
lydia-zheng committed Jan 30, 2025
1 parent c1a8bbb commit 559c7a8
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/oiiotool/expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,35 @@ Oiiotool::express_parse_atom(const string_view expr, string_view& s,
result = out.str();
if (result.size() && result.back() == '\n')
result.pop_back();

} else if (metadata == "IS_CONSTANT") {
std::vector<float> color((*img)(0, 0).nchannels());
if (ImageBufAlgo::isConstantColor((*img)(0, 0), color)) {
result = "1";
} else {
result = "0";
}


} else if (metadata == "IS_BLACK") {
auto pixstat = ImageBufAlgo::computePixelStats((*img)(0, 0));
std::vector<float> color((*img)(0, 0).nchannels());
// Check constant first to guard against false positive average of 0 with negative values i.e. -2, 1, 1
if (ImageBufAlgo::isConstantColor((*img)(0, 0), color)) {
// Do we need this loop if we know that all channels should be the same value in constant frame?
for (size_t i = 0; i < pixstat.avg.size(); ++i) {
// If any of the pixel doesn't have an average of (0,0,0), then we don't have a black frame
// Is this the best way to check? Feels fishy to have the specified number...should we look at 0.0f or other formats?
if (pixstat.avg[i] == 0.000000) {
result = "1";
} else {
result = "0";
}
}
} else {
result = "0";
}

} else if (using_bracket) {
// For the TOP[meta] syntax, if the metadata doesn't exist,
// return the empty string, and do not make an error.
Expand Down

0 comments on commit 559c7a8

Please sign in to comment.