Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: add ability to getattribute of int64 and uint64 data #3555

Merged
merged 1 commit into from
Sep 16, 2022
Merged
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 @@ -215,6 +215,7 @@ macro (oiio_add_all_tests)
python-colorconfig
python-deep
python-imagebuf
python-imagecache
python-imageoutput
python-imagespec
python-paramlist
Expand Down
5 changes: 5 additions & 0 deletions src/python/py_oiio.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ template<> struct PyTypeForCType<unsigned short> { typedef py::int_ type; };
template<> struct PyTypeForCType<char> { typedef py::int_ type; };
template<> struct PyTypeForCType<unsigned char> { typedef py::int_ type; };
template<> struct PyTypeForCType<int64_t> { typedef py::int_ type; };
template<> struct PyTypeForCType<uint64_t> { typedef py::int_ type; };
template<> struct PyTypeForCType<float> { typedef py::float_ type; };
template<> struct PyTypeForCType<half> { typedef py::float_ type; };
template<> struct PyTypeForCType<double> { typedef py::float_ type; };
Expand Down Expand Up @@ -536,6 +537,10 @@ getattribute_typed(const T& obj, const std::string& name,
return C_to_val_or_tuple((const half*)data, type);
if (type.basetype == TypeDesc::STRING)
return C_to_val_or_tuple((const char**)data, type);
if (type.basetype == TypeDesc::INT64)
return C_to_val_or_tuple((const int64_t*)data, type);
if (type.basetype == TypeDesc::UINT64)
return C_to_val_or_tuple((const uint64_t*)data, type);
return py::none();
}

Expand Down
6 changes: 6 additions & 0 deletions testsuite/python-imagecache/ref/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
stat:cache_memory_used 0
stat:image_size 4036864
total_files 2
all_filenames ('../common/grid.tif', '../common/tahoe-tiny.tif')

Done.
8 changes: 8 additions & 0 deletions testsuite/python-imagecache/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env python

# Run the script
command += pythonbin + " src/test_imagecache.py > out.txt ;"

# compare the outputs
outputs = [ "out.txt" ]

30 changes: 30 additions & 0 deletions testsuite/python-imagecache/src/test_imagecache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python

from __future__ import print_function
from __future__ import absolute_import
import array
import numpy
import OpenImageIO as oiio



######################################################################
# main test starts here

try:
ic = oiio.ImageCache()

# Force a file to be touched by the IC
ib = oiio.ImageBuf("../common/tahoe-tiny.tif")
ib = oiio.ImageBuf("../common/grid.tif")

print ("stat:cache_memory_used", ic.getattribute("stat:cache_memory_used", 'int64'))
print ("stat:image_size", ic.getattribute("stat:image_size", 'int64'))
total_files = ic.getattribute("total_files", 'int')
print ("total_files", ic.getattribute("total_files", 'int'))
print ("all_filenames", ic.getattribute("all_filenames", 'string[{}]'.format(total_files)))

print ("\nDone.")
except Exception as detail:
print ("Unknown exception:", detail)