Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cmake/testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ macro (oiio_add_all_tests)
python-imagecache
python-imageoutput
python-imagespec
python-oiio
python-paramlist
python-roi
python-texturesys
Expand Down
14 changes: 9 additions & 5 deletions src/python/py_texturesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,17 @@ declare_texturesystem(py::module& m)
"imagespec",
[](TextureSystemWrap& ts, const std::string& filename,
int subimage) -> py::object {
py::gil_scoped_release gil;
const ImageSpec* spec
= ts.m_texsys->imagespec(ustring(filename), subimage);
if (!spec) {
const ImageSpec* spec_ptr = nullptr;
{
py::gil_scoped_release gil;
spec_ptr = ts.m_texsys->imagespec(ustring(filename),
subimage);
}
if (!spec_ptr) {
return py::none();
}
return py::object(py::cast(*spec));
ImageSpec spec = *spec_ptr;
return py::cast(spec);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TextureSystem.imagespec() segfaulted because it returned Python objects while the GIL was released. Fixed by copying the ImageSpec after the C++ call, then casting with the GIL held.

},
"filename"_a, "subimage"_a = 0)
.def(
Expand Down
Binary file added testsuite/python-imagebufalgo/ref/deep_merge.exr
Binary file not shown.
Binary file added testsuite/python-imagebufalgo/ref/demosaic.tif
Binary file not shown.
25 changes: 21 additions & 4 deletions testsuite/python-imagebufalgo/ref/out-macarm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,29 @@ Comparison: of flip.tif and flop.tif
warns 2034 fails 2034
Relative comparison: of flip.tif and flop.tif
warns 1946 fails 1896
compare_Yee ok: True nfail: 1906 mean: True
FLIP_diff same vs same: mean=0 max=0
FLIP_diff black vs white: mean=0.96738 max=0.96738
FLIP_ppd = 67.02
isConstantColor on pink image is (1 0.50196 0.50196)
isConstantColor on checker is None
isConstantChannel pink R=1: True
isConstantChannel checker G=0.5: False
Is cmul1.exr monochrome? True
Is cmul2.exr monochrome? False
color range counts = (4, 8, 4)
Nonzero region is: 100 180 100 180 0 1 0 3
SHA-1 of bsplinekernel.exr is: 0902C72521944A879D5F8E8154B6DFA9D3F62598
SHA-1 of bsplinekernel.exr valid: True
zover closer fg wins: True
text_size defined: True width>0: True
textcentered wrote: True
render shapes nonzero: True

Testing additional IBA bindings:
copy size: 128 96 3
repremult ok: True
deep_merge deep: True samples@0,0: 1
demosaic size: 256 x 172
R hist: (10000, 0, 0, 0)
G hist: (10000, 0, 0, 0)
B hist: (0, 10000, 0, 0)
Expand Down Expand Up @@ -219,9 +232,13 @@ Comparing "box3.exr" and "../../../testsuite/oiiotool-fixnan/ref/box3.exr"
PASS
Comparing "a_over_b.exr" and "../../../testsuite/oiiotool-composite/ref/a_over_b.exr"
PASS
Comparing "tahoe-small.tx" and "ref/tahoe-small.tx"
Comparing "zover.exr" and "ref/zover.exr"
PASS
Comparing "render-shapes.tif" and "ref/render-shapes.tif"
PASS
Comparing "text.tif" and "../../../testsuite/oiiotool-text/ref/text-freetype2.7.tif"
Comparing "deep_merge.exr" and "ref/deep_merge.exr"
PASS
Comparing "textcentered.tif" and "ref/textcentered.tif"
Comparing "demosaic.tif" and "ref/demosaic.tif"
PASS
Comparing "tahoe-small.tx" and "ref/tahoe-small.tx"
PASS
25 changes: 21 additions & 4 deletions testsuite/python-imagebufalgo/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,29 @@ Comparison: of flip.tif and flop.tif
warns 2034 fails 2034
Relative comparison: of flip.tif and flop.tif
warns 1946 fails 1896
compare_Yee ok: True nfail: 1906 mean: True
FLIP_diff same vs same: mean=0 max=0
FLIP_diff black vs white: mean=0.96738 max=0.96738
FLIP_ppd = 67.02
isConstantColor on pink image is (1 0.50196 0.50196)
isConstantColor on checker is None
isConstantChannel pink R=1: True
isConstantChannel checker G=0.5: False
Is cmul1.exr monochrome? True
Is cmul2.exr monochrome? False
color range counts = (4, 8, 4)
Nonzero region is: 100 180 100 180 0 1 0 3
SHA-1 of bsplinekernel.exr is: D5826B66A5313F9A32D42C5CF49C90EC4E7F84BF
SHA-1 of bsplinekernel.exr valid: True
zover closer fg wins: True
text_size defined: True width>0: True
textcentered wrote: True
render shapes nonzero: True

Testing additional IBA bindings:
copy size: 128 96 3
repremult ok: True
deep_merge deep: True samples@0,0: 1
demosaic size: 256 x 172
R hist: (10000, 0, 0, 0)
G hist: (10000, 0, 0, 0)
B hist: (0, 10000, 0, 0)
Expand Down Expand Up @@ -219,9 +232,13 @@ Comparing "box3.exr" and "../../../testsuite/oiiotool-fixnan/ref/box3.exr"
PASS
Comparing "a_over_b.exr" and "../../../testsuite/oiiotool-composite/ref/a_over_b.exr"
PASS
Comparing "tahoe-small.tx" and "ref/tahoe-small.tx"
Comparing "zover.exr" and "ref/zover.exr"
PASS
Comparing "render-shapes.tif" and "ref/render-shapes.tif"
PASS
Comparing "text.tif" and "../../../testsuite/oiiotool-text/ref/text-freetype2.7.tif"
Comparing "deep_merge.exr" and "ref/deep_merge.exr"
PASS
Comparing "textcentered.tif" and "ref/textcentered.tif"
Comparing "demosaic.tif" and "ref/demosaic.tif"
PASS
Comparing "tahoe-small.tx" and "ref/tahoe-small.tx"
PASS
Binary file added testsuite/python-imagebufalgo/ref/render-shapes.tif
Binary file not shown.
Binary file added testsuite/python-imagebufalgo/ref/zover.exr
Binary file not shown.
5 changes: 4 additions & 1 deletion testsuite/python-imagebufalgo/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@
"tahoe-filled.tif",
"box3.exr",
"a_over_b.exr",
"zover.exr",
"render-shapes.tif",
"deep_merge.exr",
"demosaic.tif",
"tahoe-small.tx",
"text.tif", "textcentered.tif",
"out.txt"
]
# command += checkref (f)
Expand Down
79 changes: 67 additions & 12 deletions testsuite/python-imagebufalgo/src/test_imagebufalgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,10 @@ def test_iba (func: Callable[..., oiio.ImageBuf], *args, **kwargs) -> oiio.Image
print ("Relative comparison: of flip.tif and flop.tif")
print (" warns", compresults.nwarn, "fails", compresults.nfail)

# compare_Yee,
# compare_Yee
yee = oiio.CompareResults()
ok = ImageBufAlgo.compare_Yee(ImageBuf("flip.tif"), ImageBuf("flop.tif"), yee)
print ("compare_Yee ok:", ok, "nfail:", yee.nfail, "mean:", yee.meanerror >= 0)

# FLIP_diff
black = make_constimage(64, 64, 3, oiio.FLOAT, (0, 0, 0))
Expand All @@ -437,14 +440,17 @@ def test_iba (func: Callable[..., oiio.ImageBuf], *args, **kwargs) -> oiio.Image
assert 60 < ppd < 80

# isConstantColor, isConstantChannel

b = ImageBuf (ImageSpec(256,256,3,oiio.UINT8))
ImageBufAlgo.fill (b, (1,0.5,0.5))
v = ImageBufAlgo.isConstantColor (b)
assert v is not None
print ("isConstantColor on pink image is (%.5g %.5g %.5g)" % (v[0], v[1], v[2]))
v = ImageBufAlgo.isConstantColor (checker)
print ("isConstantColor on checker is ", v)
print ("isConstantChannel pink R=1:",
ImageBufAlgo.isConstantChannel(b, 0, 1.0))
print ("isConstantChannel checker G=0.5:",
ImageBufAlgo.isConstantChannel(checker, 1, 0.5))

b = ImageBuf("cmul1.exr")
print ("Is", b.name, "monochrome? ", ImageBufAlgo.isMonochrome(b))
Expand Down Expand Up @@ -523,8 +529,10 @@ def test_iba (func: Callable[..., oiio.ImageBuf], *args, **kwargs) -> oiio.Image
write (b, "tahoe-laplacian.tif", oiio.UINT8)

# computePixelHashSHA1
print ("SHA-1 of bsplinekernel.exr is: " +
ImageBufAlgo.computePixelHashSHA1(bsplinekernel))
sha1 = ImageBufAlgo.computePixelHashSHA1(bsplinekernel)
sha1_valid = (len(sha1) == 40
and all(c in '0123456789ABCDEF' for c in sha1))
print ("SHA-1 of bsplinekernel.exr valid:", sha1_valid)

# fft, ifft
blue = ImageBufAlgo.channels (ImageBuf(OIIO_TESTSUITE_ROOT+"/common/tahoe-tiny.tif"), (2,))
Expand Down Expand Up @@ -559,14 +567,28 @@ def test_iba (func: Callable[..., oiio.ImageBuf], *args, **kwargs) -> oiio.Image
ImageBuf(OIIO_TESTSUITE_ROOT+"/oiiotool-composite/src/b.exr"))
write (b, "a_over_b.exr")

# FIXME - no test for zover (not in oiio-composite either)

# zover
zspec = ImageSpec(4, 4, 5, oiio.FLOAT)
zspec.channelnames = ("R", "G", "B", "A", "Z")
zspec.z_channel = 4
zA = ImageBuf(zspec)
ImageBufAlgo.fill(zA, (0.5, 0.5, 0.5, 1.0, 10.0))
zB = ImageBuf(zspec)
ImageBufAlgo.fill(zB, (0.0, 0.0, 0.0, 1.0, 15.0))
ImageBufAlgo.fill(zB, (1.0, 1.0, 1.0, 1.0, 5.0), oiio.ROI(2, 4, 1, 3))
b = test_iba(ImageBufAlgo.zover, zA, zB, True)
write(b, "zover.exr", oiio.FLOAT)
p = b.getpixel(3, 2)
print ("zover closer fg wins:", p[0] > 0.9 and p[4] < 10)

# render_text (default font only -- DroidSerif is not guaranteed)
b = make_constimage (320, 240, 3, oiio.FLOAT)
ImageBufAlgo.render_text (b, 25, 50, "Hello, world",
16, "DroidSerif", (1,1,1))
ImageBufAlgo.render_text (b, 50, 120, "Go Big Red!",
42, "", (1,0,0))
ImageBufAlgo.render_text (b, 25, 50, "Hello, world", 16, "", (1,1,1))
ImageBufAlgo.render_text (b, 50, 120, "Go Big Red!", 42, "", (1,0,0))
write (b, "text.tif", oiio.UINT8)
ts = ImageBufAlgo.text_size ("Hello, world", 16)
print ("text_size defined:", ts.defined,
"width>0:", ts.width > 0 if ts.defined else False)

b = make_constimage (320, 240, 3, oiio.FLOAT)
broi = b.roi
Expand All @@ -576,8 +598,41 @@ def test_iba (func: Callable[..., oiio.ImageBuf], *args, **kwargs) -> oiio.Image
y = broi.ybegin + broi.height//2 - (textsize.ybegin + textsize.height//2)
ImageBufAlgo.render_text (b, x, y, "Centered", 40)
write (b, "textcentered.tif", oiio.UINT8)

# FIXME - need tests for render_point, render_line, render_box
print ("textcentered wrote:", not b.has_error)

# render_line, render_box (render_point tested above in normalize)
shapes = make_constimage (64, 64, 3, oiio.UINT8, (0, 0, 0))
ImageBufAlgo.render_line (shapes, 5, 5, 58, 58, (1, 0, 0))
ImageBufAlgo.render_box (shapes, 10, 10, 54, 54, (0, 1, 0))
write (shapes, "render-shapes.tif", oiio.UINT8)
nz = ImageBufAlgo.nonzero_region(shapes)
print ("render shapes nonzero:", nz.defined)

print ("\nTesting additional IBA bindings:")

# copy
src = ImageBuf(OIIO_TESTSUITE_ROOT+"/common/tahoe-tiny.tif")
b = test_iba(ImageBufAlgo.copy, src)
print ("copy size:", b.spec().width, b.spec().height, b.spec().nchannels)

# repremult
unprem = ImageBuf(OIIO_TESTSUITE_ROOT+"/common/unpremult.tif")
b = test_iba(ImageBufAlgo.repremult, unprem)
print ("repremult ok:", not b.has_error)

# deep_merge (tiny deep images)
deep_a = ImageBuf(OIIO_TESTSUITE_ROOT+"/oiiotool-deep/src/deep-onesample.exr")
deep_b = ImageBuf(OIIO_TESTSUITE_ROOT+"/oiiotool-deep/src/deep-nosamples.exr")
b = test_iba(ImageBufAlgo.deep_merge, deep_a, deep_b)
print ("deep_merge deep:", b.deep, "samples@0,0:", b.deep_samples(0, 0))
write (b, "deep_merge.exr")

# demosaic
bayer = ImageBuf(OIIO_TESTSUITE_ROOT+"/common/bayer.png")
b = test_iba(ImageBufAlgo.demosaic, bayer, layout="BGGR",
white_balance_mode="manual", white_balance=(1.0, 1.0, 1.0, 1.0))
print ("demosaic size:", b.spec().width, "x", b.spec().height)
write (b, "demosaic.tif", oiio.UINT8)

# histogram, histogram_draw,
b = make_constimage (100, 100, 3, oiio.UINT8, (.1, .2, .3))
Expand Down
85 changes: 60 additions & 25 deletions testsuite/python-imagecache/ref/out-win.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,66 @@
getattribute("max_open_files") 90
getattribute("max_memory_MB") 900.0
getattribute("searchpath") ../common
tahoe_tiny is 128 x 96
grid is 1000 x 1000
full getattribute stat:cache_memory_used 0
full getattribute stat:image_size 4036864
full getattribute total_files 2
full getattribute all_filenames ('../common/grid.tif', '../common/tahoe-tiny.tif')
getattributetype stat:cache_memory_used int64
getattributetype stat:image_size int64
getattributetype total_files int
getattributetype all_filenames string[2]
untyped getattribute stat:cache_memory_used 0
untyped getattribute stat:image_size 4036864
untyped getattribute total_files 2
untyped getattribute all_filenames ('../common/grid.tif', '../common/tahoe-tiny.tif')
getpixels from grid.tif: [[[1. 0.49803925 0.49803925 1. ]
Testing attribute() one-arg:
max_open_files: 90
max_memory_MB: 900.0
searchpath: ../common

Testing attribute() typed:
max_open_files typed round-trip: True

Testing get_imagespec:
tahoe_tiny is 128 x 96
grid is 1000 x 1000

Testing resolve_filename:
resolve ends with grid.tif: True

Testing get_cache_dimensions:
cache dimensions width>0: True
cache dimensions height>0: True

Testing getattribute() and getattributetype():
getattributetype stat:cache_memory_used: int64
getattributetype stat:image_size: int64
getattributetype total_files: int
getattributetype searchpath: string
total_files is int: True
total_files >= 2: True
stat:image_size is int: True
stat:image_size positive: True
all_filenames is tuple: True
all_filenames len matches total_files: True
untyped stat:cache_memory_used is int: True

Testing get_pixels() coord overload:
getpixels from grid.tif: [[[1. 0.49803925 0.49803925 1. ]
[1. 0.49803925 0.49803925 1. ]]

[[1. 0.49803925 0.49803925 1. ]
[1. 0.49803925 0.49803925 1. ]]]
has_error? False
geterror?
getpixels from broken.tif: None
has_error? True
geterror? Invalid image file "broken.tif": Could not open file: S: Cannot open
getstats beginning:
['OpenImageIO', 'ImageCache', 'statistics']
has_error after success: False

Testing get_pixels() ROI overload:
ROI matches coord overload: True

Testing get_pixels() missing file:
broken returns None: True
has_error after broken: True
geterror nonempty: True

Testing getstats:
getstats starts with OpenImageIO: True
getstats contains statistics: True

Testing invalidate/invalidate_all:
invalidate ok: True

Testing ImageCache.destroy:
destroy shared=False ok: True

Testing has_error/geterror on private cache:
has_error before: False
has_error after bad file: True
geterror persists: True
geterror clear returns message: True
has_error after clear: False

Done.
Loading
Loading