diff --git a/src/python/py_oiio.h b/src/python/py_oiio.h index 0f8145d44b..5713569a65 100644 --- a/src/python/py_oiio.h +++ b/src/python/py_oiio.h @@ -131,9 +131,12 @@ py_indexable_pod_to_stdvector(std::vector& vals, const PYT& obj) } else if ((std::is_same::value || std::is_same::value) && py::isinstance(elem)) { vals.emplace_back(elem.template cast()); + } else if (std::is_same::value + && py::isinstance(elem)) { + vals.emplace_back(elem.template cast()); } else { // FIXME? Other cases? - vals.emplace_back(T(0)); + vals.emplace_back(T(42)); ok = false; } } @@ -330,6 +333,13 @@ attribute_typed(T& myobj, string_view name, TypeDesc type, const POBJ& dataobj) myobj.attribute(name, type, &vals[0]); return; } + if (type.basetype == TypeDesc::UINT) { + std::vector vals; + py_to_stdvector(vals, dataobj); + if (vals.size() == type.numelements() * type.aggregate) + myobj.attribute(name, type, &vals[0]); + return; + } if (type.basetype == TypeDesc::FLOAT) { std::vector vals; py_to_stdvector(vals, dataobj); diff --git a/testsuite/python-imagespec/ref/out-python3.txt b/testsuite/python-imagespec/ref/out-python3.txt index e26dcf495f..50bdc6de31 100644 --- a/testsuite/python-imagespec/ref/out-python3.txt +++ b/testsuite/python-imagespec/ref/out-python3.txt @@ -87,11 +87,12 @@ getattribute('foo_str') retrieves blah getattribute('foo_vector') retrieves (1.0, 0.0, 11.0) getattribute('foo_matrix') retrieves (1.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0) getattribute('foo_no') retrieves None +getattribute('smpte:TimeCode') retrieves (18356486, 4294967295) s['delfoo_float'] = 99.5 s['delfoo_int'] = 29 s['delfoo_str'] = egg -extra_attribs size is 8 +extra_attribs size is 9 0 foo_str string blah "blah" 1 foo_int int 14 @@ -102,11 +103,13 @@ extra_attribs size is 8 1, 0, 11 4 foo_matrix matrix (1.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0) 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1 -5 delfoo_str string egg +5 smpte:TimeCode timecode (18356486, 4294967295) +01:18:19:06 +6 delfoo_str string egg "egg" -6 delfoo_int int 29 +7 delfoo_int int 29 29 -7 delfoo_float float 99.5 +8 delfoo_float float 99.5 99.5 seralize(xml): @@ -143,6 +146,7 @@ seralize(xml): 3.14 1, 0, 11 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1 +01:18:19:06 egg 29 99.5 @@ -163,6 +167,7 @@ serialize(text, human): foo_matrix: 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1 foo_str: "blah" foo_vector: 1, 0, 11 + smpte:TimeCode: 01:18:19:06 Testing construction from ROI: resolution (width,height,depth) = 640 480 1 diff --git a/testsuite/python-imagespec/ref/out.txt b/testsuite/python-imagespec/ref/out.txt index b05caa3a13..f03f2b5519 100644 --- a/testsuite/python-imagespec/ref/out.txt +++ b/testsuite/python-imagespec/ref/out.txt @@ -87,11 +87,12 @@ getattribute('foo_str') retrieves blah getattribute('foo_vector') retrieves (1.0, 0.0, 11.0) getattribute('foo_matrix') retrieves (1.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0) getattribute('foo_no') retrieves None +getattribute('smpte:TimeCode') retrieves (18356486L, 4294967295L) s['delfoo_float'] = 99.5 s['delfoo_int'] = 29 s['delfoo_str'] = egg -extra_attribs size is 8 +extra_attribs size is 9 0 foo_str string blah "blah" 1 foo_int int 14 @@ -102,11 +103,13 @@ extra_attribs size is 8 1, 0, 11 4 foo_matrix matrix (1.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 2.0, 3.0, 1.0) 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1 -5 delfoo_str string egg +5 smpte:TimeCode timecode (18356486L, 4294967295L) +01:18:19:06 +6 delfoo_str string egg "egg" -6 delfoo_int int 29 +7 delfoo_int int 29 29 -7 delfoo_float float 99.5 +8 delfoo_float float 99.5 99.5 seralize(xml): @@ -143,6 +146,7 @@ seralize(xml): 3.14 1, 0, 11 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1 +01:18:19:06 egg 29 99.5 @@ -163,6 +167,7 @@ serialize(text, human): foo_matrix: 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1 foo_str: "blah" foo_vector: 1, 0, 11 + smpte:TimeCode: 01:18:19:06 Testing construction from ROI: resolution (width,height,depth) = 640 480 1 diff --git a/testsuite/python-imagespec/src/test_imagespec.py b/testsuite/python-imagespec/src/test_imagespec.py index fa1231444a..3a5c531563 100755 --- a/testsuite/python-imagespec/src/test_imagespec.py +++ b/testsuite/python-imagespec/src/test_imagespec.py @@ -89,6 +89,7 @@ def print_imagespec (spec, msg="") : s.attribute ("foo_vector", oiio.TypeDesc.TypeVector, (1, 0, 11)) s.attribute ("foo_matrix", oiio.TypeDesc.TypeMatrix, (1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, 1, 2, 3, 1)) + s.attribute ("smpte:TimeCode", oiio.TypeDesc.TypeTimeCode, (18356486, 4294967295)) s["delfoo_str"] = "egg" s["delfoo_int"] = 29 s["delfoo_float"] = 99.5 @@ -108,6 +109,7 @@ def print_imagespec (spec, msg="") : print ("getattribute('foo_vector') retrieves", s.getattribute("foo_vector")) print ("getattribute('foo_matrix') retrieves", s.getattribute("foo_matrix")) print ("getattribute('foo_no') retrieves", s.getattribute("foo_no")) + print ("getattribute('smpte:TimeCode') retrieves", s.getattribute("smpte:TimeCode")) print ("s['delfoo_float'] =", s['delfoo_float']) print ("s['delfoo_int'] =", s['delfoo_int']) print ("s['delfoo_str'] =", s['delfoo_str'])