Blender V5.0
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.h"
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 ocio = blender::ocio;
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#ifndef WITH_OPENCOLORIO
49# define SetStrItem(str) PyStructSequence_SET_ITEM(ocio_info, pos++, PyUnicode_FromString(str))
50#endif
51
52#define SetObjItem(obj) PyStructSequence_SET_ITEM(ocio_info, pos++, obj)
53
54#ifdef WITH_OPENCOLORIO
55 const ocio::Version ocio_version = ocio::get_version();
56 SetObjItem(PyBool_FromLong(1));
57 SetObjItem(PyC_Tuple_Pack_I32({ocio_version.major, ocio_version.minor, ocio_version.patch}));
58 SetObjItem(PyUnicode_FromFormat(
59 "%2d, %2d, %2d", ocio_version.major, ocio_version.minor, ocio_version.patch));
60#else
61 SetObjItem(PyBool_FromLong(0));
63 SetStrItem("Unknown");
64#endif
65
66 if (UNLIKELY(PyErr_Occurred())) {
67 Py_DECREF(ocio_info);
68 return nullptr;
69 }
70
71#undef SetStrItem
72#undef SetObjItem
73
74 return ocio_info;
75}
76
78{
79 PyObject *ret;
80
81 PyStructSequence_InitType(&BlenderAppOCIOType, &app_ocio_info_desc);
82
84
85 /* prevent user from creating new instances */
86 BlenderAppOCIOType.tp_init = nullptr;
87 BlenderAppOCIOType.tp_new = nullptr;
88 /* Without this we can't do `set(sys.modules)` #29635. */
89 BlenderAppOCIOType.tp_hash = (hashfunc)Py_HashPointer;
90
91 return ret;
92}
#define ARRAY_SIZE(arr)
#define UNLIKELY(x)
static PyObject * make_ocio_info()
static PyTypeObject BlenderAppOCIOType
static PyStructSequence_Desc app_ocio_info_desc
PyObject * BPY_app_ocio_struct()
#define SetStrItem(str)
static PyStructSequence_Field app_ocio_info_fields[]
#define SetObjItem(obj)
uint pos
Version get_version()
Definition version.cc:11
PyObject * PyC_Tuple_Pack_I32(const blender::Span< int > values)
header-only compatibility defines.
#define Py_HashPointer
Py_DECREF(oname)
return ret