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