Blender  V2.93
bpy_app_ocio.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_ocio.h"
25 
26 #include "../generic/py_capi_utils.h"
27 
28 #ifdef WITH_OCIO
29 # include "ocio_capi.h"
30 #endif
31 
32 static PyTypeObject BlenderAppOCIOType;
33 
34 static PyStructSequence_Field app_ocio_info_fields[] = {
35  {"supported", "Boolean, True when Blender is built with OpenColorIO support"},
36  {"version", "The OpenColorIO version as a tuple of 3 numbers"},
37  {"version_string", "The OpenColorIO version formatted as a string"},
38  {NULL},
39 };
40 
41 static PyStructSequence_Desc app_ocio_info_desc = {
42  /* name */
43  "bpy.app.ocio",
44  /* doc */
45  "This module contains information about OpenColorIO blender is linked against",
46  /* fields */
49 };
50 
51 static PyObject *make_ocio_info(void)
52 {
53  PyObject *ocio_info;
54  int pos = 0;
55 
56 #ifdef WITH_OCIO
57  int curversion;
58 #endif
59 
60  ocio_info = PyStructSequence_New(&BlenderAppOCIOType);
61  if (ocio_info == NULL) {
62  return NULL;
63  }
64 
65 #ifndef WITH_OCIO
66 # define SetStrItem(str) PyStructSequence_SET_ITEM(ocio_info, pos++, PyUnicode_FromString(str))
67 #endif
68 
69 #define SetObjItem(obj) PyStructSequence_SET_ITEM(ocio_info, pos++, obj)
70 
71 #ifdef WITH_OCIO
72  curversion = OCIO_getVersionHex();
73  SetObjItem(PyBool_FromLong(1));
74  SetObjItem(
75  PyC_Tuple_Pack_I32(curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256));
76  SetObjItem(PyUnicode_FromFormat(
77  "%2d, %2d, %2d", curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256));
78 #else
79  SetObjItem(PyBool_FromLong(0));
81  SetStrItem("Unknown");
82 #endif
83 
84  if (UNLIKELY(PyErr_Occurred())) {
85  Py_DECREF(ocio_info);
86  return NULL;
87  }
88 
89 #undef SetStrItem
90 #undef SetObjItem
91 
92  return ocio_info;
93 }
94 
95 PyObject *BPY_app_ocio_struct(void)
96 {
97  PyObject *ret;
98 
99  PyStructSequence_InitType(&BlenderAppOCIOType, &app_ocio_info_desc);
100 
101  ret = make_ocio_info();
102 
103  /* prevent user from creating new instances */
104  BlenderAppOCIOType.tp_init = NULL;
105  BlenderAppOCIOType.tp_new = NULL;
106  BlenderAppOCIOType.tp_hash = (hashfunc)
107  _Py_HashPointer; /* without this we can't do set(sys.modules) T29635. */
108 
109  return ret;
110 }
#define ARRAY_SIZE(arr)
#define UNLIKELY(x)
static PyTypeObject BlenderAppOCIOType
Definition: bpy_app_ocio.c:32
static PyObject * make_ocio_info(void)
Definition: bpy_app_ocio.c:51
static PyStructSequence_Desc app_ocio_info_desc
Definition: bpy_app_ocio.c:41
PyObject * BPY_app_ocio_struct(void)
Definition: bpy_app_ocio.c:95
#define SetStrItem(str)
static PyStructSequence_Field app_ocio_info_fields[]
Definition: bpy_app_ocio.c:34
#define SetObjItem(obj)
uint pos
int OCIO_getVersionHex(void)
Definition: ocio_capi.cc:326
#define PyC_Tuple_Pack_I32(...)
Definition: py_capi_utils.h:67
return ret