Blender V5.3
bpy_app_oiio.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_utildefines.hh"
10#include <Python.h>
11
12#include "../generic/python_compat.hh" /* IWYU pragma: keep. */
13
14#include "bpy_app_oiio.hh"
15
17
18#include "openimageio_api.h"
19
20namespace blender {
21
22static PyTypeObject BlenderAppOIIOType;
23
24static PyStructSequence_Field app_oiio_info_fields[] = {
25 {"supported", "Boolean, True when Blender is built with OpenImageIO support"},
26 {"version", "The OpenImageIO version as a tuple of 3 numbers"},
27 {"version_string", "The OpenImageIO version formatted as a string"},
28 {nullptr},
29};
30
31static PyStructSequence_Desc app_oiio_info_desc = {
32 /*name*/ "bpy.app.oiio",
33 /*doc*/ "This module contains information about OpeImageIO blender is linked against",
34 /*fields*/ app_oiio_info_fields,
35 /*n_in_sequence*/ ARRAY_SIZE(app_oiio_info_fields) - 1,
36};
37
38static PyObject *make_oiio_info()
39{
40 PyObject *oiio_info;
41 int pos = 0;
42
43 int curversion;
44
45 oiio_info = PyStructSequence_New(&BlenderAppOIIOType);
46 if (oiio_info == nullptr) {
47 return nullptr;
48 }
49
50#define SetObjItem(obj) PyStructSequence_SET_ITEM(oiio_info, pos++, obj)
51
52 curversion = OIIO_getVersionHex();
53 SetObjItem(PyBool_FromLong(1));
54 SetObjItem(PyC_Tuple_Pack_I32({curversion / 10000, (curversion / 100) % 100, curversion % 100}));
55 SetObjItem(PyUnicode_FromFormat(
56 "%2d, %2d, %2d", curversion / 10000, (curversion / 100) % 100, curversion % 100));
57
58 if (PyErr_Occurred()) [[unlikely]] {
59 Py_DECREF(oiio_info);
60 return nullptr;
61 }
62
63#undef SetStrItem
64#undef SetObjItem
65
66 return oiio_info;
67}
68
70{
71 PyObject *ret;
72
73 PyStructSequence_InitType(&BlenderAppOIIOType, &app_oiio_info_desc);
74
76
77 /* prevent user from creating new instances */
78 BlenderAppOIIOType.tp_init = nullptr;
79 BlenderAppOIIOType.tp_new = nullptr;
80 /* Without this we can't do `set(sys.modules)` #29635. */
81 BlenderAppOIIOType.tp_hash = reinterpret_cast<hashfunc>(Py_HashPointer);
82
83 return ret;
84}
85
86} // namespace blender
#define SetObjItem(obj)
BMesh Iterators.
PyObject * BPY_app_oiio_struct()
static PyObject * make_oiio_info()
PyObject * PyC_Tuple_Pack_I32(const Span< int > values)
static PyStructSequence_Desc app_oiio_info_desc
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
static PyStructSequence_Field app_oiio_info_fields[]
static PyTypeObject BlenderAppOIIOType
int OIIO_getVersionHex()
header-only compatibility defines.
#define Py_HashPointer