Skip to content
Open
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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ jobs:
fmt_ver: 12.1.0
opencolorio_ver: v2.5.0
openexr_ver: v3.4.3
pybind11_ver: v3.0.1
pybind11_ver: v3.0.2
python_ver: "3.12"
simd: avx2,f16c
setenvs: export LIBJPEGTURBO_VERSION=3.1.2
Expand All @@ -465,7 +465,7 @@ jobs:
fmt_ver: master
opencolorio_ver: main
openexr_ver: main
pybind11_ver: v3.0.1
pybind11_ver: master
python_ver: "3.12"
simd: avx2,f16c
benchmark: 1
Expand Down Expand Up @@ -524,7 +524,7 @@ jobs:
fmt_ver: 12.1.0
opencolorio_ver: v2.5.0
openexr_ver: v3.4.3
pybind11_ver: v3.0.1
pybind11_ver: v3.0.2
python_ver: "3.12"
setenvs: export LIBJPEGTURBO_VERSION=3.1.2
LIBPNG_VERSION=v1.6.50
Expand All @@ -545,7 +545,7 @@ jobs:
fmt_ver: 12.1.0
opencolorio_ver: v2.5.0
openexr_ver: v3.4.3
pybind11_ver: v3.0.1
pybind11_ver: v3.0.2
python_ver: "3.12"
setenvs: export LIBJPEGTURBO_VERSION=3.1.2
LIBPNG_VERSION=v1.6.50
Expand Down
1 change: 1 addition & 0 deletions src/cmake/build_pybind11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ build_dependency_with_cmake(pybind11
VERSION ${pybind11_BUILD_VERSION}
GIT_REPOSITORY ${pybind11_GIT_REPOSITORY}
GIT_TAG ${pybind11_GIT_TAG}
GIT_COMMIT ${pybind11_GIT_COMMIT}
CMAKE_ARGS
-D PYBIND11_PYTHON_VERSION=${PYTHON3_VERSION}
# Don't built unnecessary parts of Pybind11
Expand Down
14 changes: 2 additions & 12 deletions src/python/py_imagecache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,11 @@ declare_imagecache(py::module& m)
.def_static("destroy", &ImageCacheWrap::destroy, "cache"_a,
"teardown"_a = false)

.def("attribute",
[](ImageCacheWrap& ic, const std::string& name, float val) {
if (ic.m_cache)
ic.m_cache->attribute(name, val);
})
.def("attribute",
[](ImageCacheWrap& ic, const std::string& name, int val) {
if (ic.m_cache)
ic.m_cache->attribute(name, val);
})
.def("attribute",
[](ImageCacheWrap& ic, const std::string& name,
const std::string& val) {
const py::object& obj) {
if (ic.m_cache)
ic.m_cache->attribute(name, val);
attribute_onearg(*ic.m_cache, name, obj);
})
.def("attribute",
[](ImageCacheWrap& ic, const std::string& name, TypeDesc type,
Expand Down
6 changes: 1 addition & 5 deletions src/python/py_imagespec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,9 @@ declare_imagespec(py::module& m)
// For now, do not expose auto_stride. It's not obvious that
// anybody will want to do pointer work and strides from Python.

.def("attribute", [](ImageSpec& spec, const std::string& name,
float val) { spec.attribute(name, val); })
.def("attribute", [](ImageSpec& spec, const std::string& name,
int val) { spec.attribute(name, val); })
.def("attribute",
[](ImageSpec& spec, const std::string& name,
const std::string& val) { spec.attribute(name, val); })
const py::object& obj) { attribute_onearg(spec, name, obj); })
.def("attribute",
[](ImageSpec& spec, const std::string& name, TypeDesc type,
const py::object& obj) {
Expand Down
24 changes: 16 additions & 8 deletions src/python/py_oiio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,24 @@ oiio_getattribute_typed(const std::string& name, TypeDesc type = TypeUnknown)
}


// Wrapper to let attribute_typed work for global attributes.
// Wrapper to let attribute_typed/attribute_onearg work for global attributes.
struct oiio_global_attrib_wrapper {
bool attribute(string_view name, TypeDesc type, const void* data)
{
return OIIO::attribute(name, type, data);
}
bool attribute(string_view name, int val)
{
return OIIO::attribute(name, val);
}
bool attribute(string_view name, float val)
{
return OIIO::attribute(name, val);
}
bool attribute(string_view name, const std::string& val)
{
return OIIO::attribute(name, val);
}
};


Expand Down Expand Up @@ -297,13 +309,9 @@ OIIO_DECLARE_PYMODULE(PYMODULE_NAME)

// Global (OpenImageIO scope) functions and symbols
m.def("geterror", &OIIO::geterror, "clear"_a = true);
m.def("attribute", [](const std::string& name, float val) {
OIIO::attribute(name, val);
});
m.def("attribute",
[](const std::string& name, int val) { OIIO::attribute(name, val); });
m.def("attribute", [](const std::string& name, const std::string& val) {
OIIO::attribute(name, val);
m.def("attribute", [](const std::string& name, const py::object& obj) {
oiio_global_attrib_wrapper wrapper;
attribute_onearg(wrapper, name, obj);
});
m.def("attribute",
[](const std::string& name, TypeDesc type, const py::object& obj) {
Expand Down
20 changes: 20 additions & 0 deletions src/python/py_oiio.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,26 @@ attribute_typed(T& myobj, string_view name, TypeDesc type, const POBJ& dataobj)



// Dispatch a single-value attribute() call based on the type of the
// Python object (int, float, or string).
template<typename T>
inline void
attribute_onearg(T& myobj, string_view name, const py::object& obj)
{
if (py::isinstance<py::float_>(obj))
myobj.attribute(name, float(obj.template cast<py::float_>()));
else if (py::isinstance<py::int_>(obj))
myobj.attribute(name, int(obj.template cast<py::int_>()));
else if (py::isinstance<py::str>(obj))
myobj.attribute(name, std::string(obj.template cast<py::str>()));
else if (py::isinstance<py::bytes>(obj))
myobj.attribute(name, std::string(obj.template cast<py::bytes>()));
else
throw py::type_error("attribute() value must be int, float, or str");
}



// `data` points to values of `type`. Make a python object that represents
// them.
py::object
Expand Down
22 changes: 10 additions & 12 deletions src/python/py_paramvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ ParamValue_from_pyobject(string_view name, TypeDesc type, int nvalues,



static void
ParamValueList_attribute_onearg(ParamValueList& self, const std::string& name,
const py::object& obj)
{
attribute_onearg(self, name, obj);
}



// Based on attribute_typed in py_oiio.h, but with nvalues.
template<typename T, typename POBJ>
bool
Expand Down Expand Up @@ -240,18 +249,7 @@ declare_paramvalue(py::module& m)
"value"_a, "casesensitive"_a = true)
.def("sort", &ParamValueList::sort, "casesensitive"_a = true)
.def("merge", &ParamValueList::merge, "other"_a, "override"_a = false)
.def("attribute",
[](ParamValueList& self, const std::string& name, float val) {
self.attribute(name, TypeFloat, &val);
})
.def("attribute", [](ParamValueList& self, const std::string& name,
int val) { self.attribute(name, TypeInt, &val); })
.def("attribute",
[](ParamValueList& self, const std::string& name,
const std::string& val) {
const char* s = val.c_str();
self.attribute(name, TypeString, &s);
})
.def("attribute", ParamValueList_attribute_onearg, "name"_a, "val"_a)
.def("attribute",
[](ParamValueList& self, const std::string& name, TypeDesc type,
const py::object& obj) {
Expand Down
14 changes: 2 additions & 12 deletions src/python/py_texturesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,11 @@ declare_texturesystem(py::module& m)
.def(py::init<bool>(), "shared"_a = true)
.def_static("destroy", &TextureSystemWrap::destroy)

.def("attribute",
[](TextureSystemWrap& ts, const std::string& name, float val) {
if (ts.m_texsys)
ts.m_texsys->attribute(name, val);
})
.def("attribute",
[](TextureSystemWrap& ts, const std::string& name, int val) {
if (ts.m_texsys)
ts.m_texsys->attribute(name, val);
})
.def("attribute",
[](TextureSystemWrap& ts, const std::string& name,
const std::string& val) {
const py::object& obj) {
if (ts.m_texsys)
ts.m_texsys->attribute(name, val);
attribute_onearg(*ts.m_texsys, name, obj);
})
.def("attribute",
[](TextureSystemWrap& ts, const std::string& name, TypeDesc type,
Expand Down
Loading
Loading