1 /* SPDX-FileCopyrightText: 2023 Blender Authors
3 * SPDX-License-Identifier: GPL-2.0-or-later */
6 * \ingroup pythonintern
9 #include "BLI_utildefines.h"
12 #include "bpy_app_ocio.hh"
14 #include "../generic/py_capi_utils.hh"
17 # include "ocio_capi.h"
20 static PyTypeObject BlenderAppOCIOType
;
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"},
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,
36 static PyObject
*make_ocio_info()
45 ocio_info
= PyStructSequence_New(&BlenderAppOCIOType
);
46 if (ocio_info
== nullptr) {
51 # define SetStrItem(str) PyStructSequence_SET_ITEM(ocio_info, pos++, PyUnicode_FromString(str))
54 #define SetObjItem(obj) PyStructSequence_SET_ITEM(ocio_info, pos++, obj)
57 curversion
= OCIO_getVersionHex();
58 SetObjItem(PyBool_FromLong(1));
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));
64 SetObjItem(PyBool_FromLong(0));
65 SetObjItem(PyC_Tuple_Pack_I32({0, 0, 0}));
66 SetStrItem("Unknown");
69 if (UNLIKELY(PyErr_Occurred())) {
80 PyObject
*BPY_app_ocio_struct()
84 PyStructSequence_InitType(&BlenderAppOCIOType
, &app_ocio_info_desc
);
86 ret
= make_ocio_info();
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
;