Blender  V3.3
bpy_app_oiio.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BLI_utildefines.h"
8 #include <Python.h>
9 
10 #include "bpy_app_oiio.h"
11 
12 #include "../generic/py_capi_utils.h"
13 
14 #ifdef WITH_OPENIMAGEIO
15 # include "openimageio_api.h"
16 #endif
17 
18 static PyTypeObject BlenderAppOIIOType;
19 
20 static 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  {NULL},
25 };
26 
27 static PyStructSequence_Desc app_oiio_info_desc = {
28  "bpy.app.oiio", /* name */
29  "This module contains information about OpeImageIO blender is linked against", /* doc */
30  app_oiio_info_fields, /* fields */
32 };
33 
34 static PyObject *make_oiio_info(void)
35 {
36  PyObject *oiio_info;
37  int pos = 0;
38 
39 #ifdef WITH_OPENIMAGEIO
40  int curversion;
41 #endif
42 
43  oiio_info = PyStructSequence_New(&BlenderAppOIIOType);
44  if (oiio_info == NULL) {
45  return NULL;
46  }
47 
48 #ifndef WITH_OPENIMAGEIO
49 # define SetStrItem(str) PyStructSequence_SET_ITEM(oiio_info, pos++, PyUnicode_FromString(str))
50 #endif
51 
52 #define SetObjItem(obj) PyStructSequence_SET_ITEM(oiio_info, pos++, obj)
53 
54 #ifdef WITH_OPENIMAGEIO
55  curversion = OIIO_getVersionHex();
56  SetObjItem(PyBool_FromLong(1));
57  SetObjItem(PyC_Tuple_Pack_I32(curversion / 10000, (curversion / 100) % 100, curversion % 100));
58  SetObjItem(PyUnicode_FromFormat(
59  "%2d, %2d, %2d", curversion / 10000, (curversion / 100) % 100, curversion % 100));
60 #else
61  SetObjItem(PyBool_FromLong(0));
63  SetStrItem("Unknown");
64 #endif
65 
66  if (UNLIKELY(PyErr_Occurred())) {
67  Py_DECREF(oiio_info);
68  return NULL;
69  }
70 
71 #undef SetStrItem
72 #undef SetObjItem
73 
74  return oiio_info;
75 }
76 
77 PyObject *BPY_app_oiio_struct(void)
78 {
79  PyObject *ret;
80 
81  PyStructSequence_InitType(&BlenderAppOIIOType, &app_oiio_info_desc);
82 
83  ret = make_oiio_info();
84 
85  /* prevent user from creating new instances */
86  BlenderAppOIIOType.tp_init = NULL;
87  BlenderAppOIIOType.tp_new = NULL;
88  BlenderAppOIIOType.tp_hash = (hashfunc)
89  _Py_HashPointer; /* without this we can't do set(sys.modules) T29635. */
90 
91  return ret;
92 }
#define ARRAY_SIZE(arr)
#define UNLIKELY(x)
static PyStructSequence_Field app_oiio_info_fields[]
Definition: bpy_app_oiio.c:20
static PyStructSequence_Desc app_oiio_info_desc
Definition: bpy_app_oiio.c:27
static PyTypeObject BlenderAppOIIOType
Definition: bpy_app_oiio.c:18
PyObject * BPY_app_oiio_struct(void)
Definition: bpy_app_oiio.c:77
static PyObject * make_oiio_info(void)
Definition: bpy_app_oiio.c:34
#define SetStrItem(str)
#define SetObjItem(obj)
uint pos
int OIIO_getVersionHex(void)
#define PyC_Tuple_Pack_I32(...)
Definition: py_capi_utils.h:88
return ret