|
11 | 11 | #include <iostream>
|
12 | 12 | #include <iterator>
|
13 | 13 | #include <map>
|
| 14 | +#include <numeric> |
14 | 15 | #include <regex>
|
15 | 16 | #include <sstream>
|
16 | 17 | #include <string>
|
@@ -1942,6 +1943,13 @@ Oiiotool::express_parse_atom(const string_view expr, string_view& s,
|
1942 | 1943 | for (size_t i = 0; i < pixstat.avg.size(); ++i)
|
1943 | 1944 | out << (i ? "," : "") << pixstat.avg[i];
|
1944 | 1945 | result = out.str();
|
| 1946 | + } else if (metadata == "NONFINITE_COUNT") { |
| 1947 | + auto pixstat = ImageBufAlgo::computePixelStats((*img)(0, 0)); |
| 1948 | + imagesize_t sum = std::accumulate(pixstat.nancount.begin(), |
| 1949 | + pixstat.nancount.end(), 0) |
| 1950 | + + std::accumulate(pixstat.infcount.begin(), |
| 1951 | + pixstat.infcount.end(), 0); |
| 1952 | + result = Strutil::to_string(sum); |
1945 | 1953 | } else if (metadata == "META" || metadata == "METANATIVE") {
|
1946 | 1954 | std::stringstream out;
|
1947 | 1955 | print_info_options opt;
|
@@ -4878,19 +4886,23 @@ action_fixnan(Oiiotool& ot, cspan<const char*> argv)
|
4878 | 4886 | ImageRecRef A = ot.pop();
|
4879 | 4887 | ot.push(new ImageRec(*A, allsubimages ? -1 : 0, allsubimages ? -1 : 0, true,
|
4880 | 4888 | false));
|
4881 |
| - int subimages = allsubimages ? A->subimages() : 1; |
| 4889 | + imagesize_t total_nonfinite = 0; |
| 4890 | + int subimages = allsubimages ? A->subimages() : 1; |
4882 | 4891 | for (int s = 0; s < subimages; ++s) {
|
4883 | 4892 | int miplevels = ot.curimg->miplevels(s);
|
4884 | 4893 | for (int m = 0; m < miplevels; ++m) {
|
4885 | 4894 | const ImageBuf& Aib((*A)(s, m));
|
4886 | 4895 | ImageBuf& Rib((*ot.curimg)(s, m));
|
4887 |
| - bool ok = ImageBufAlgo::fixNonFinite(Rib, Aib, mode); |
4888 |
| - if (!ok) { |
| 4896 | + int num_nonfinite = 0; |
| 4897 | + bool ok = ImageBufAlgo::fixNonFinite(Rib, Aib, mode, |
| 4898 | + &num_nonfinite); |
| 4899 | + if (!ok) |
4889 | 4900 | ot.error(command, Rib.geterror());
|
4890 |
| - return; |
4891 |
| - } |
| 4901 | + total_nonfinite += num_nonfinite; |
4892 | 4902 | }
|
4893 | 4903 | }
|
| 4904 | + // Set user variable NONFINITE_COUNT to the number of pixels modified. |
| 4905 | + ot.uservars["NONFINITE_COUNT"] = int(total_nonfinite); |
4894 | 4906 | }
|
4895 | 4907 |
|
4896 | 4908 |
|
|
0 commit comments