Blender V5.3
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
8
9#include "BLI_utildefines.hh"
10#include <Python.h>
11
12#include "../generic/python_compat.hh" /* IWYU pragma: keep. */
13
14#include "bpy_app_ocio.hh"
15
17
18#include "OCIO_version.hh"
19
20namespace blender {
21
22static PyTypeObject BlenderAppOCIOType;
23
24static PyStructSequence_Field app_ocio_info_fields[] = {
25 {"supported", "Boolean, True when Blender is built with OpenColorIO support"},
26 {"version", "The OpenColorIO version as a tuple of 3 numbers"},
27 {"version_string", "The OpenColorIO version formatted as a string"},
28 {nullptr},
29};
30
31static PyStructSequence_Desc app_ocio_info_desc = {
32 /*name*/ "bpy.app.ocio",
33 /*doc*/ "This module contains information about OpenColorIO blender is linked against",
34 /*fields*/ app_ocio_info_fields,
35 /*n_in_sequence*/ ARRAY_SIZE(app_ocio_info_fields) - 1,
36};
37
38static PyObject *make_ocio_info()
39{
40 PyObject *ocio_info;
41 int pos = 0;
42
43 ocio_info = PyStructSequence_New(&BlenderAppOCIOType);
44 if (ocio_info == nullptr) {
45 return nullptr;
46 }
47
48#define SetObjItem(obj) PyStructSequence_SET_ITEM(ocio_info, pos++, obj)
49
50 const ocio::Version ocio_version = ocio::get_version();
51 SetObjItem(PyBool_FromLong(1));
52 SetObjItem(PyC_Tuple_Pack_I32({ocio_version.major, ocio_version.minor, ocio_version.patch}));
53 SetObjItem(PyUnicode_FromFormat(
54 "%2d, %2d, %2d", ocio_version.major, ocio_version.minor, ocio_version.patch));
55
56 if (PyErr_Occurred()) [[unlikely]] {
57 Py_DECREF(ocio_info);
58 return nullptr;
59 }
60
61#undef SetObjItem
62
63 return ocio_info;
64}
65
67{
68 PyObject *ret;
69
70 PyStructSequence_InitType(&BlenderAppOCIOType, &app_ocio_info_desc);
71
73
74 /* prevent user from creating new instances */
75 BlenderAppOCIOType.tp_init = nullptr;
76 BlenderAppOCIOType.tp_new = nullptr;
77 /* Without this we can't do `set(sys.modules)` #29635. */
78 BlenderAppOCIOType.tp_hash = reinterpret_cast<hashfunc>(Py_HashPointer);
79
80 return ret;
81}
82
83} // namespace blender
#define SetObjItem(obj)
Version get_version()
Definition version.cc:11
BMesh Iterators.
PyObject * PyC_Tuple_Pack_I32(const Span< int > values)
static PyObject * make_ocio_info()
PyObject * BPY_app_ocio_struct()
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
static PyTypeObject BlenderAppOCIOType
static PyStructSequence_Desc app_ocio_info_desc
static PyStructSequence_Field app_ocio_info_fields[]
header-only compatibility defines.
#define Py_HashPointer