| 
									
										
										
										
											2013-12-08 15:03:17 +06:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup pythonintern | 
					
						
							| 
									
										
										
										
											2013-12-08 15:03:17 +06:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include <Python.h>
 | 
					
						
							| 
									
										
										
										
											2013-12-08 15:03:17 +06:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "bpy_app_ocio.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-22 18:02:58 +10:00
										 |  |  | #include "../generic/py_capi_utils.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-08 15:03:17 +06:00
										 |  |  | #ifdef WITH_OCIO
 | 
					
						
							|  |  |  | #  include "ocio_capi.h"
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyTypeObject BlenderAppOCIOType; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyStructSequence_Field app_ocio_info_fields[] = { | 
					
						
							| 
									
										
										
										
											2019-12-20 10:42:57 +11:00
										 |  |  |     {"supported", "Boolean, True when Blender is built with OpenColorIO support"}, | 
					
						
							|  |  |  |     {"version", "The OpenColorIO version as a tuple of 3 numbers"}, | 
					
						
							|  |  |  |     {"version_string", "The OpenColorIO version formatted as a string"}, | 
					
						
							| 
									
										
										
										
											2019-01-19 13:21:18 +11:00
										 |  |  |     {NULL}, | 
					
						
							| 
									
										
										
										
											2013-12-08 15:03:17 +06:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyStructSequence_Desc app_ocio_info_desc = { | 
					
						
							| 
									
										
										
										
											2019-04-29 19:59:13 +10:00
										 |  |  |     /* name */ | 
					
						
							| 
									
										
										
										
											2019-12-20 10:42:57 +11:00
										 |  |  |     "bpy.app.ocio", | 
					
						
							| 
									
										
										
										
											2019-04-29 19:59:13 +10:00
										 |  |  |     /* doc */ | 
					
						
							| 
									
										
										
										
											2019-12-20 10:42:57 +11:00
										 |  |  |     "This module contains information about OpenColorIO blender is linked against", | 
					
						
							| 
									
										
										
										
											2019-04-29 19:59:13 +10:00
										 |  |  |     /* fields */ | 
					
						
							|  |  |  |     app_ocio_info_fields, | 
					
						
							| 
									
										
										
										
											2019-02-03 14:01:45 +11:00
										 |  |  |     ARRAY_SIZE(app_ocio_info_fields) - 1, | 
					
						
							| 
									
										
										
										
											2013-12-08 15:03:17 +06:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *make_ocio_info(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PyObject *ocio_info; | 
					
						
							|  |  |  |   int pos = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef WITH_OCIO
 | 
					
						
							|  |  |  |   int curversion; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ocio_info = PyStructSequence_New(&BlenderAppOCIOType); | 
					
						
							|  |  |  |   if (ocio_info == NULL) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-10 01:11:02 +11:00
										 |  |  | #ifndef WITH_OCIO
 | 
					
						
							| 
									
										
										
										
											2013-12-08 15:03:17 +06:00
										 |  |  | #  define SetStrItem(str) PyStructSequence_SET_ITEM(ocio_info, pos++, PyUnicode_FromString(str))
 | 
					
						
							| 
									
										
										
										
											2013-12-10 01:11:02 +11:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-08 15:03:17 +06:00
										 |  |  | #define SetObjItem(obj) PyStructSequence_SET_ITEM(ocio_info, pos++, obj)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef WITH_OCIO
 | 
					
						
							|  |  |  |   curversion = OCIO_getVersionHex(); | 
					
						
							|  |  |  |   SetObjItem(PyBool_FromLong(1)); | 
					
						
							| 
									
										
										
										
											2017-08-22 18:02:58 +10:00
										 |  |  |   SetObjItem( | 
					
						
							|  |  |  |       PyC_Tuple_Pack_I32(curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256)); | 
					
						
							| 
									
										
										
										
											2013-12-08 15:03:17 +06:00
										 |  |  |   SetObjItem(PyUnicode_FromFormat( | 
					
						
							|  |  |  |       "%2d, %2d, %2d", curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256)); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |   SetObjItem(PyBool_FromLong(0)); | 
					
						
							| 
									
										
										
										
											2017-08-22 18:02:58 +10:00
										 |  |  |   SetObjItem(PyC_Tuple_Pack_I32(0, 0, 0)); | 
					
						
							| 
									
										
										
										
											2013-12-08 15:03:17 +06:00
										 |  |  |   SetStrItem("Unknown"); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-04 15:46:07 +11:00
										 |  |  |   if (UNLIKELY(PyErr_Occurred())) { | 
					
						
							|  |  |  |     Py_DECREF(ocio_info); | 
					
						
							| 
									
										
										
										
											2013-12-08 15:03:17 +06:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #undef SetStrItem
 | 
					
						
							|  |  |  | #undef SetObjItem
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ocio_info; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyObject *BPY_app_ocio_struct(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PyObject *ret; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   PyStructSequence_InitType(&BlenderAppOCIOType, &app_ocio_info_desc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ret = make_ocio_info(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* prevent user from creating new instances */ | 
					
						
							|  |  |  |   BlenderAppOCIOType.tp_init = NULL; | 
					
						
							|  |  |  |   BlenderAppOCIOType.tp_new = NULL; | 
					
						
							|  |  |  |   BlenderAppOCIOType.tp_hash = (hashfunc) | 
					
						
							| 
									
										
										
										
											2020-09-30 20:09:02 +10:00
										 |  |  |       _Py_HashPointer; /* without this we can't do set(sys.modules) T29635. */ | 
					
						
							| 
									
										
										
										
											2013-12-08 15:03:17 +06:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return ret; | 
					
						
							|  |  |  | } |