Skip to content

Commit

Permalink
testing/api: Add test for filter values and 'filter_list' query (Acad…
Browse files Browse the repository at this point in the history
…emySoftwareFoundation#4140)

Add testsuite/filters that verifies that the filter shapes are correct
and don't change if we make future changes to the filter code.

Along the way, add a new global getattribute query 'filter_list', that
returns a semicolon-separated list of all the 2D filters it knows about.

---------

Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz authored Feb 10, 2024
1 parent fbe7b12 commit 372bb8e
Show file tree
Hide file tree
Showing 23 changed files with 79 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/cmake/testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ macro (oiio_add_all_tests)
python-roi
python-texturesys
python-typedesc
filters
)
# These Python tests also need access to oiio-images
oiio_add_tests (
Expand Down
5 changes: 5 additions & 0 deletions src/include/OpenImageIO/imageio.h
Original file line number Diff line number Diff line change
Expand Up @@ -3079,6 +3079,11 @@ inline bool attribute (string_view name, string_view val) {
/// full paths), and all the directories that OpenImageIO will search for
/// fonts. (Added in OpenImageIO 2.5)
///
/// - `string filter_list`
///
/// A semicolon-separated list of all built-in 2D filters. (Added in
/// OpenImageIO 2.5.9)
///
/// - int64_t IB_local_mem_current
/// - int64_t IB_local_mem_peak
///
Expand Down
8 changes: 8 additions & 0 deletions src/libOpenImageIO/imageio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <OpenImageIO/color.h>
#include <OpenImageIO/dassert.h>
#include <OpenImageIO/filter.h>
#include <OpenImageIO/fmath.h>
#include <OpenImageIO/hash.h>
#include <OpenImageIO/imageio.h>
Expand Down Expand Up @@ -539,6 +540,13 @@ getattribute(string_view name, TypeDesc type, void* val)
*(ustring*)val = ustring(Strutil::join(font_list(), ";"));
return true;
}
if (name == "filter_list" && type == TypeString) {
std::vector<string_view> filternames;
for (int i = 0, e = Filter2D::num_filters(); i < e; ++i)
filternames.emplace_back(Filter2D::get_filterdesc(i).name);
*(ustring*)val = ustring(Strutil::join(filternames, ";"));
return true;
}
if (name == "exr_threads" && type == TypeInt) {
*(int*)val = oiio_exr_threads;
return true;
Expand Down
7 changes: 3 additions & 4 deletions src/oiiotool/oiiotool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6496,12 +6496,11 @@ print_help_end(Oiiotool& ot, std::ostream& out)
print(out, " Run `oiiotool --colorconfiginfo` for a "
"full color management inventory.\n");

std::vector<string_view> filternames;
for (int i = 0, e = Filter2D::num_filters(); i < e; ++i)
filternames.emplace_back(Filter2D::get_filterdesc(i).name);
print(out, "{}\n",
Strutil::wordwrap("Filters available: "
+ Strutil::join(filternames, ", "),
+ Strutil::replace(OIIO::get_string_attribute(
"filter_list"),
";", ", ", true),
columns, 4));

print_build_info(ot, out);
Expand Down
Binary file added testsuite/filters/ref/blackman-harris.exr
Binary file not shown.
Binary file added testsuite/filters/ref/box.exr
Binary file not shown.
Binary file added testsuite/filters/ref/bspline.exr
Binary file not shown.
Binary file added testsuite/filters/ref/catmull-rom.exr
Binary file not shown.
Binary file added testsuite/filters/ref/cubic.exr
Binary file not shown.
Binary file added testsuite/filters/ref/disk.exr
Binary file not shown.
Binary file added testsuite/filters/ref/gaussian.exr
Binary file not shown.
Binary file added testsuite/filters/ref/keys.exr
Binary file not shown.
Binary file added testsuite/filters/ref/lanczos3.exr
Binary file not shown.
Binary file added testsuite/filters/ref/mitchell.exr
Binary file not shown.
Binary file added testsuite/filters/ref/nuke-lanczos6.exr
Binary file not shown.
34 changes: 34 additions & 0 deletions testsuite/filters/ref/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Comparing "box.exr" and "ref/box.exr"
PASS
Comparing "triangle.exr" and "ref/triangle.exr"
PASS
Comparing "gaussian.exr" and "ref/gaussian.exr"
PASS
Comparing "sharp-gaussian.exr" and "ref/sharp-gaussian.exr"
PASS
Comparing "catmull-rom.exr" and "ref/catmull-rom.exr"
PASS
Comparing "blackman-harris.exr" and "ref/blackman-harris.exr"
PASS
Comparing "sinc.exr" and "ref/sinc.exr"
PASS
Comparing "lanczos3.exr" and "ref/lanczos3.exr"
PASS
Comparing "radial-lanczos3.exr" and "ref/radial-lanczos3.exr"
PASS
Comparing "nuke-lanczos6.exr" and "ref/nuke-lanczos6.exr"
PASS
Comparing "mitchell.exr" and "ref/mitchell.exr"
PASS
Comparing "bspline.exr" and "ref/bspline.exr"
PASS
Comparing "disk.exr" and "ref/disk.exr"
PASS
Comparing "cubic.exr" and "ref/cubic.exr"
PASS
Comparing "keys.exr" and "ref/keys.exr"
PASS
Comparing "simon.exr" and "ref/simon.exr"
PASS
Comparing "rifman.exr" and "ref/rifman.exr"
PASS
Binary file added testsuite/filters/ref/radial-lanczos3.exr
Binary file not shown.
Binary file added testsuite/filters/ref/rifman.exr
Binary file not shown.
Binary file added testsuite/filters/ref/sharp-gaussian.exr
Binary file not shown.
Binary file added testsuite/filters/ref/simon.exr
Binary file not shown.
Binary file added testsuite/filters/ref/sinc.exr
Binary file not shown.
Binary file added testsuite/filters/ref/triangle.exr
Binary file not shown.
28 changes: 28 additions & 0 deletions testsuite/filters/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python

# Copyright Contributors to the OpenImageIO project.
# SPDX-License-Identifier: Apache-2.0
# https://github.com/AcademySoftwareFoundation/OpenImageIO

# Test the filters

import OpenImageIO as oiio

filters = oiio.get_string_attribute("filter_list").split(";")
print ("all filters: ", filters)
i = 0
outputs = [ ]

delta = oiio.ImageBuf(oiio.ImageSpec(16, 16, 1, "float"))
oiio.ImageBufAlgo.render_point(delta, 8, 8)

for f in filters:
buf = oiio.ImageBufAlgo.resize(delta, f, roi=oiio.ROI(0, 80, 0, 80, 0, 1))
# Make a marker different for each filter so they dont compare against
# each other
oiio.ImageBufAlgo.render_point(buf, i, 0)
i += 1
buf.write("{}.exr".format(f), "half")
outputs += [ "{}.exr".format(f) ]

outputs += [ "out.txt" ]

0 comments on commit 372bb8e

Please sign in to comment.