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

Fix inability for python to set timecode #2279

Merged
merged 1 commit into from
Jul 4, 2019
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
12 changes: 11 additions & 1 deletion src/python/py_oiio.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,12 @@ py_indexable_pod_to_stdvector(std::vector<T>& vals, const PYT& obj)
} else if ((std::is_same<T, float>::value || std::is_same<T, int>::value)
&& py::isinstance<py::int_>(elem)) {
vals.emplace_back(elem.template cast<int>());
} else if (std::is_same<T, unsigned int>::value
&& py::isinstance<py::int_>(elem)) {
vals.emplace_back(elem.template cast<unsigned int>());
} else {
// FIXME? Other cases?
vals.emplace_back(T(0));
vals.emplace_back(T(42));
ok = false;
}
}
Expand Down Expand Up @@ -329,6 +332,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<unsigned int> 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<float> vals;
py_to_stdvector(vals, dataobj);
Expand Down
7 changes: 6 additions & 1 deletion testsuite/python-imagespec/ref/out-python3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ 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)

extra_attribs size is 5
extra_attribs size is 6
0 foo_str string blah
"blah"
1 foo_int int 14
Expand All @@ -99,6 +100,8 @@ extra_attribs size is 5
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 smpte:TimeCode timecode (18356486, 4294967295)
01:18:19:06

seralize(xml):
<ImageSpec version="22">
Expand Down Expand Up @@ -134,6 +137,7 @@ seralize(xml):
<attrib name="foo_float" type="float">3.14</attrib>
<attrib name="foo_vector" type="vector">1 0 11</attrib>
<attrib name="foo_matrix" type="matrix">1 0 0 0 0 2 0 0 0 0 1 0 1 2 3 1</attrib>
<attrib name="smpte:TimeCode" type="timecode" description="01:18:19:06">01:18:19:06</attrib>
</ImageSpec>

serialize(text, human):
Expand All @@ -148,6 +152,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
Expand Down
7 changes: 6 additions & 1 deletion testsuite/python-imagespec/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ 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)

extra_attribs size is 5
extra_attribs size is 6
0 foo_str string blah
"blah"
1 foo_int int 14
Expand All @@ -99,6 +100,8 @@ extra_attribs size is 5
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 smpte:TimeCode timecode (18356486L, 4294967295L)
01:18:19:06

seralize(xml):
<ImageSpec version="22">
Expand Down Expand Up @@ -134,6 +137,7 @@ seralize(xml):
<attrib name="foo_float" type="float">3.14</attrib>
<attrib name="foo_vector" type="vector">1 0 11</attrib>
<attrib name="foo_matrix" type="matrix">1 0 0 0 0 2 0 0 0 0 1 0 1 2 3 1</attrib>
<attrib name="smpte:TimeCode" type="timecode" description="01:18:19:06">01:18:19:06</attrib>
</ImageSpec>

serialize(text, human):
Expand All @@ -148,6 +152,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
Expand Down
2 changes: 2 additions & 0 deletions testsuite/python-imagespec/src/test_imagespec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
print ("get_int_attribute('foo_int') retrieves", s.get_int_attribute ("foo_int"))
print ("get_int_attribute('foo_int',21) with default retrieves", s.get_int_attribute ("foo_int", 21))
print ("get_int_attribute('foo_no',23) retrieves", s.get_int_attribute ("foo_no", 23))
Expand All @@ -105,6 +106,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 ()

print ("extra_attribs size is", len(s.extra_attribs))
Expand Down