Blender V5.0
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.h"
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
20static PyTypeObject BlenderAppOIIOType;
21
22static PyStructSequence_Field app_oiio_info_fields[] = {
23 {"supported", "Boolean, True when Blender is built with OpenImageIO support"},
24 {"version", "The OpenImageIO version as a tuple of 3 numbers"},
25 {"version_string", "The OpenImageIO version formatted as a string"},
26 {nullptr},
27};
28
29static PyStructSequence_Desc app_oiio_info_desc = {
30 /*name*/ "bpy.app.oiio",
31 /*doc*/ "This module contains information about OpeImageIO blender is linked against",
32 /*fields*/ app_oiio_info_fields,
33 /*n_in_sequence*/ ARRAY_SIZE(app_oiio_info_fields) - 1,
34};
35
36static PyObject *make_oiio_info()
37{
38 PyObject *oiio_info;
39 int pos = 0;
40
41 int curversion;
42
43 oiio_info = PyStructSequence_New(&BlenderAppOIIOType);
44 if (oiio_info == nullptr) {
45 return nullptr;
46 }
47
48#define SetObjItem(obj) PyStructSequence_SET_ITEM(oiio_info, pos++, obj)
49
50 curversion = OIIO_getVersionHex();
51 SetObjItem(PyBool_FromLong(1));
52 SetObjItem(PyC_Tuple_Pack_I32({curversion / 10000, (curversion / 100) % 100, curversion % 100}));
53 SetObjItem(PyUnicode_FromFormat(
54 "%2d, %2d, %2d", curversion / 10000, (curversion / 100) % 100, curversion % 100));
55
56 if (UNLIKELY(PyErr_Occurred())) {
57 Py_DECREF(oiio_info);
58 return nullptr;
59 }
60
61#undef SetStrItem
62#undef SetObjItem
63
64 return oiio_info;
65}
66
68{
69 PyObject *ret;
70
71 PyStructSequence_InitType(&BlenderAppOIIOType, &app_oiio_info_desc);
72
74
75 /* prevent user from creating new instances */
76 BlenderAppOIIOType.tp_init = nullptr;
77 BlenderAppOIIOType.tp_new = nullptr;
78 /* Without this we can't do `set(sys.modules)` #29635. */
79 BlenderAppOIIOType.tp_hash = (hashfunc)Py_HashPointer;
80
81 return ret;
82}
#define ARRAY_SIZE(arr)
#define UNLIKELY(x)
static PyStructSequence_Field app_oiio_info_fields[]
static PyStructSequence_Desc app_oiio_info_desc
static PyTypeObject BlenderAppOIIOType
PyObject * BPY_app_oiio_struct()
static PyObject * make_oiio_info()
#define SetObjItem(obj)
uint pos
int OIIO_getVersionHex()
PyObject * PyC_Tuple_Pack_I32(const blender::Span< int > values)
header-only compatibility defines.
#define Py_HashPointer
Py_DECREF(oname)
return ret