Skip to content

Commit a669d0e

Browse files
committed
testing/api: Add test for filter values and 'filter_list' query (AcademySoftwareFoundation#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 <[email protected]>
1 parent 25ff992 commit a669d0e

23 files changed

+79
-4
lines changed

src/cmake/testing.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ macro (oiio_add_all_tests)
220220
python-roi
221221
python-texturesys
222222
python-typedesc
223+
filters
223224
)
224225
# These Python tests also need access to oiio-images
225226
oiio_add_tests (

src/include/OpenImageIO/imageio.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3079,6 +3079,11 @@ inline bool attribute (string_view name, string_view val) {
30793079
/// full paths), and all the directories that OpenImageIO will search for
30803080
/// fonts. (Added in OpenImageIO 2.5)
30813081
///
3082+
/// - `string filter_list`
3083+
///
3084+
/// A semicolon-separated list of all built-in 2D filters. (Added in
3085+
/// OpenImageIO 2.5.9)
3086+
///
30823087
/// - int64_t IB_local_mem_current
30833088
/// - int64_t IB_local_mem_peak
30843089
///

src/libOpenImageIO/imageio.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <OpenImageIO/color.h>
1111
#include <OpenImageIO/dassert.h>
12+
#include <OpenImageIO/filter.h>
1213
#include <OpenImageIO/fmath.h>
1314
#include <OpenImageIO/hash.h>
1415
#include <OpenImageIO/imageio.h>
@@ -539,6 +540,13 @@ getattribute(string_view name, TypeDesc type, void* val)
539540
*(ustring*)val = ustring(Strutil::join(font_list(), ";"));
540541
return true;
541542
}
543+
if (name == "filter_list" && type == TypeString) {
544+
std::vector<string_view> filternames;
545+
for (int i = 0, e = Filter2D::num_filters(); i < e; ++i)
546+
filternames.emplace_back(Filter2D::get_filterdesc(i).name);
547+
*(ustring*)val = ustring(Strutil::join(filternames, ";"));
548+
return true;
549+
}
542550
if (name == "exr_threads" && type == TypeInt) {
543551
*(int*)val = oiio_exr_threads;
544552
return true;

src/oiiotool/oiiotool.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6349,12 +6349,11 @@ print_help_end(Oiiotool& ot, std::ostream& out)
63496349
print(out, " Run `oiiotool --colorconfiginfo` for a "
63506350
"full color management inventory.\n");
63516351

6352-
std::vector<string_view> filternames;
6353-
for (int i = 0, e = Filter2D::num_filters(); i < e; ++i)
6354-
filternames.emplace_back(Filter2D::get_filterdesc(i).name);
63556352
print(out, "{}\n",
63566353
Strutil::wordwrap("Filters available: "
6357-
+ Strutil::join(filternames, ", "),
6354+
+ Strutil::replace(OIIO::get_string_attribute(
6355+
"filter_list"),
6356+
";", ", ", true),
63586357
columns, 4));
63596358

63606359
print_build_info(ot, out);
892 Bytes
Binary file not shown.

testsuite/filters/ref/box.exr

538 Bytes
Binary file not shown.

testsuite/filters/ref/bspline.exr

981 Bytes
Binary file not shown.

testsuite/filters/ref/catmull-rom.exr

1.06 KB
Binary file not shown.

testsuite/filters/ref/cubic.exr

679 Bytes
Binary file not shown.

testsuite/filters/ref/disk.exr

543 Bytes
Binary file not shown.

testsuite/filters/ref/gaussian.exr

892 Bytes
Binary file not shown.

testsuite/filters/ref/keys.exr

1.07 KB
Binary file not shown.

testsuite/filters/ref/lanczos3.exr

1.89 KB
Binary file not shown.

testsuite/filters/ref/mitchell.exr

1.06 KB
Binary file not shown.
1.89 KB
Binary file not shown.

testsuite/filters/ref/out.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Comparing "box.exr" and "ref/box.exr"
2+
PASS
3+
Comparing "triangle.exr" and "ref/triangle.exr"
4+
PASS
5+
Comparing "gaussian.exr" and "ref/gaussian.exr"
6+
PASS
7+
Comparing "sharp-gaussian.exr" and "ref/sharp-gaussian.exr"
8+
PASS
9+
Comparing "catmull-rom.exr" and "ref/catmull-rom.exr"
10+
PASS
11+
Comparing "blackman-harris.exr" and "ref/blackman-harris.exr"
12+
PASS
13+
Comparing "sinc.exr" and "ref/sinc.exr"
14+
PASS
15+
Comparing "lanczos3.exr" and "ref/lanczos3.exr"
16+
PASS
17+
Comparing "radial-lanczos3.exr" and "ref/radial-lanczos3.exr"
18+
PASS
19+
Comparing "nuke-lanczos6.exr" and "ref/nuke-lanczos6.exr"
20+
PASS
21+
Comparing "mitchell.exr" and "ref/mitchell.exr"
22+
PASS
23+
Comparing "bspline.exr" and "ref/bspline.exr"
24+
PASS
25+
Comparing "disk.exr" and "ref/disk.exr"
26+
PASS
27+
Comparing "cubic.exr" and "ref/cubic.exr"
28+
PASS
29+
Comparing "keys.exr" and "ref/keys.exr"
30+
PASS
31+
Comparing "simon.exr" and "ref/simon.exr"
32+
PASS
33+
Comparing "rifman.exr" and "ref/rifman.exr"
34+
PASS
1.82 KB
Binary file not shown.

testsuite/filters/ref/rifman.exr

1.04 KB
Binary file not shown.
679 Bytes
Binary file not shown.

testsuite/filters/ref/simon.exr

1.04 KB
Binary file not shown.

testsuite/filters/ref/sinc.exr

1.23 KB
Binary file not shown.

testsuite/filters/ref/triangle.exr

640 Bytes
Binary file not shown.

testsuite/filters/run.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright Contributors to the OpenImageIO project.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# https://github.com/AcademySoftwareFoundation/OpenImageIO
6+
7+
# Test the filters
8+
9+
import OpenImageIO as oiio
10+
11+
filters = oiio.get_string_attribute("filter_list").split(";")
12+
print ("all filters: ", filters)
13+
i = 0
14+
outputs = [ ]
15+
16+
delta = oiio.ImageBuf(oiio.ImageSpec(16, 16, 1, "float"))
17+
oiio.ImageBufAlgo.render_point(delta, 8, 8)
18+
19+
for f in filters:
20+
buf = oiio.ImageBufAlgo.resize(delta, f, roi=oiio.ROI(0, 80, 0, 80, 0, 1))
21+
# Make a marker different for each filter so they dont compare against
22+
# each other
23+
oiio.ImageBufAlgo.render_point(buf, i, 0)
24+
i += 1
25+
buf.write("{}.exr".format(f), "half")
26+
outputs += [ "{}.exr".format(f) ]
27+
28+
outputs += [ "out.txt" ]

0 commit comments

Comments
 (0)