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