Blender  V2.93
bpy_app_oiio.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BLI_utildefines.h"
22 #include <Python.h>
23 
24 #include "bpy_app_oiio.h"
25 
26 #include "../generic/py_capi_utils.h"
27 
28 #ifdef WITH_OPENIMAGEIO
29 # include "openimageio_api.h"
30 #endif
31 
32 static PyTypeObject BlenderAppOIIOType;
33 
34 static PyStructSequence_Field app_oiio_info_fields[] = {
35  {"supported", "Boolean, True when Blender is built with OpenImageIO support"},
36  {"version", "The OpenImageIO version as a tuple of 3 numbers"},
37  {"version_string", "The OpenImageIO version formatted as a string"},
38  {NULL},
39 };
40 
41 static PyStructSequence_Desc app_oiio_info_desc = {
42  "bpy.app.oiio", /* name */
43  "This module contains information about OpeImageIO blender is linked against", /* doc */
44  app_oiio_info_fields, /* fields */
46 };
47 
48 static PyObject *make_oiio_info(void)
49 {
50  PyObject *oiio_info;
51  int pos = 0;
52 
53 #ifdef WITH_OPENIMAGEIO
54  int curversion;
55 #endif
56 
57  oiio_info = PyStructSequence_New(&BlenderAppOIIOType);
58  if (oiio_info == NULL) {
59  return NULL;
60  }
61 
62 #ifndef WITH_OPENIMAGEIO
63 # define SetStrItem(str) PyStructSequence_SET_ITEM(oiio_info, pos++, PyUnicode_FromString(str))
64 #endif
65 
66 #define SetObjItem(obj) PyStructSequence_SET_ITEM(oiio_info, pos++, obj)
67 
68 #ifdef WITH_OPENIMAGEIO
69  curversion = OIIO_getVersionHex();
70  SetObjItem(PyBool_FromLong(1));
71  SetObjItem(PyC_Tuple_Pack_I32(curversion / 10000, (curversion / 100) % 100, curversion % 100));
72  SetObjItem(PyUnicode_FromFormat(
73  "%2d, %2d, %2d", curversion / 10000, (curversion / 100) % 100, curversion % 100));
74 #else
75  SetObjItem(PyBool_FromLong(0));
77  SetStrItem("Unknown");
78 #endif
79 
80  if (UNLIKELY(PyErr_Occurred())) {
81  Py_DECREF(oiio_info);
82  return NULL;
83  }
84 
85 #undef SetStrItem
86 #undef SetObjItem
87 
88  return oiio_info;
89 }
90 
91 PyObject *BPY_app_oiio_struct(void)
92 {
93  PyObject *ret;
94 
95  PyStructSequence_InitType(&BlenderAppOIIOType, &app_oiio_info_desc);
96 
97  ret = make_oiio_info();
98 
99  /* prevent user from creating new instances */
100  BlenderAppOIIOType.tp_init = NULL;
101  BlenderAppOIIOType.tp_new = NULL;
102  BlenderAppOIIOType.tp_hash = (hashfunc)
103  _Py_HashPointer; /* without this we can't do set(sys.modules) T29635. */
104 
105  return ret;
106 }
#define ARRAY_SIZE(arr)
#define UNLIKELY(x)
static PyStructSequence_Field app_oiio_info_fields[]
Definition: bpy_app_oiio.c:34
static PyStructSequence_Desc app_oiio_info_desc
Definition: bpy_app_oiio.c:41
static PyTypeObject BlenderAppOIIOType
Definition: bpy_app_oiio.c:32
PyObject * BPY_app_oiio_struct(void)
Definition: bpy_app_oiio.c:91
static PyObject * make_oiio_info(void)
Definition: bpy_app_oiio.c:48
#define SetStrItem(str)
#define SetObjItem(obj)
uint pos
int OIIO_getVersionHex(void)
#define PyC_Tuple_Pack_I32(...)
Definition: py_capi_utils.h:67
return ret