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