diff --git a/intern/cycles/blender/blender_python.cpp b/intern/cycles/blender/blender_python.cpp index 8e6bcaee350..f10b185287d 100644 --- a/intern/cycles/blender/blender_python.cpp +++ b/intern/cycles/blender/blender_python.cpp @@ -475,11 +475,25 @@ void *CCL_python_module_init() PyObject *mod = PyModule_Create(&ccl::module); #ifdef WITH_OSL + /* TODO(sergey): This gives us library we've been linking against. + * In theory with dynamic OSL library it might not be + * accurate, but there's nothing in OSL API which we + * might use th get version in runtime. + */ + int curversion = OSL_LIBRARY_VERSION_CODE; PyModule_AddObject(mod, "with_osl", Py_True); Py_INCREF(Py_True); + PyModule_AddObject(mod, "osl_version", + Py_BuildValue("(iii)", + curversion / 10000, (curversion / 100) % 100, curversion % 100)); + PyModule_AddObject(mod, "osl_version_string", + PyUnicode_FromFormat("%2d, %2d, %2d", + curversion / 10000, (curversion / 100) % 100, curversion % 100)); #else PyModule_AddObject(mod, "with_osl", Py_False); Py_INCREF(Py_False); + PyModule_AddStringCOnstant(mod, "osl_version", "unknown"); + PyModule_AddStringCOnstant(mod, "osl_version_string", "unknown"); #endif #ifdef WITH_NETWORK diff --git a/intern/opencolorio/fallback_impl.cc b/intern/opencolorio/fallback_impl.cc index ca999eab569..6383bbbb07f 100644 --- a/intern/opencolorio/fallback_impl.cc +++ b/intern/opencolorio/fallback_impl.cc @@ -431,3 +431,13 @@ void FallbackImpl::finishGLSLDraw(OCIO_GLSLDrawState * /*state*/) void FallbackImpl::freeGLState(struct OCIO_GLSLDrawState * /*state_r*/) { } + +const char *FallbackImpl::getVersionString(void) +{ + return "fallback"; +} + +int FallbackImpl::getVersionHex(void) +{ + return 0; +} diff --git a/intern/opencolorio/ocio_capi.cc b/intern/opencolorio/ocio_capi.cc index 30668dff245..47ee3afddfd 100644 --- a/intern/opencolorio/ocio_capi.cc +++ b/intern/opencolorio/ocio_capi.cc @@ -338,3 +338,13 @@ void OCIO_freeOGLState(struct OCIO_GLSLDrawState *state) { impl->freeGLState(state); } + +const char *OCIO_getVersionString(void) +{ + return impl->getVersionString(); +} + +int OCIO_getVersionHex(void) +{ + return impl->getVersionHex(); +} diff --git a/intern/opencolorio/ocio_capi.h b/intern/opencolorio/ocio_capi.h index 5532ade1f3a..5abe104fcd4 100644 --- a/intern/opencolorio/ocio_capi.h +++ b/intern/opencolorio/ocio_capi.h @@ -193,6 +193,9 @@ int OCIO_setupGLSLDraw(struct OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorR void OCIO_finishGLSLDraw(struct OCIO_GLSLDrawState *state); void OCIO_freeOGLState(struct OCIO_GLSLDrawState *state); +const char *OCIO_getVersionString(void); +int OCIO_getVersionHex(void); + #ifdef __cplusplus } #endif diff --git a/intern/opencolorio/ocio_impl.cc b/intern/opencolorio/ocio_impl.cc index 2cffe1a89ef..663ca2d1c75 100644 --- a/intern/opencolorio/ocio_impl.cc +++ b/intern/opencolorio/ocio_impl.cc @@ -609,3 +609,13 @@ void OCIOImpl::matrixTransformScale(float *m44, float *offset4, const float *sca { MatrixTransform::Scale(m44, offset4, scale4f); } + +const char *OCIOImpl::getVersionString(void) +{ + return GetVersion(); +} + +int OCIOImpl::getVersionHex(void) +{ + return GetVersionHex(); +} diff --git a/intern/opencolorio/ocio_impl.h b/intern/opencolorio/ocio_impl.h index 8b666e8ae14..4e7c1bcc832 100644 --- a/intern/opencolorio/ocio_impl.h +++ b/intern/opencolorio/ocio_impl.h @@ -110,6 +110,9 @@ public: OCIO_CurveMappingSettings *curve_mapping_settings, bool predivide) = 0; virtual void finishGLSLDraw(struct OCIO_GLSLDrawState *state) = 0; virtual void freeGLState(struct OCIO_GLSLDrawState *state_r) = 0; + + virtual const char *getVersionString(void) = 0; + virtual int getVersionHex(void) = 0; }; class FallbackImpl : public IOCIOImpl { @@ -194,6 +197,9 @@ public: OCIO_CurveMappingSettings *curve_mapping_settings, bool predivide); void finishGLSLDraw(struct OCIO_GLSLDrawState *state); void freeGLState(struct OCIO_GLSLDrawState *state_r); + + const char *getVersionString(void); + int getVersionHex(void); }; #ifdef WITH_OCIO @@ -279,6 +285,9 @@ public: OCIO_CurveMappingSettings *curve_mapping_settings, bool predivide); void finishGLSLDraw(struct OCIO_GLSLDrawState *state); void freeGLState(struct OCIO_GLSLDrawState *state_r); + + const char *getVersionString(void); + int getVersionHex(void); }; #endif diff --git a/release/scripts/modules/sys_info.py b/release/scripts/modules/sys_info.py index 83f2647c5b2..ef3e56209f0 100644 --- a/release/scripts/modules/sys_info.py +++ b/release/scripts/modules/sys_info.py @@ -118,6 +118,36 @@ def write_sysinfo(op): else: output.write("Blender was built without FFmpeg support\n") + output.write("\nOther Libraries:\n") + output.write(lilies) + ocio = bpy.app.ocio + output.write("OpenColorIO: ") + if ocio.supported: + if ocio.version_string == "fallback": + output.write("Blender was built with OpenColorIO, " + + "but it currently uses fallback color management.\n") + else: + output.write("%s\n" % (ocio.version_string)) + else: + output.write("Blender was built without OpenColorIO support\n") + + oiio = bpy.app.oiio + output.write("OpenImageIO: ") + if ocio.supported : + output.write("%s\n" % (oiio.version_string)) + else: + output.write("Blender was built without OpenImageIO support\n") + + output.write("OpenShadingLanguuage: ") + if bpy.app.build_options.cycles: + if bpy.app.build_options.cycles_osl: + from _cycles import osl_version_string + output.write("%s\n" % (osl_version_string)) + else: + output.write("Blender was built without OpenShadingLanguage support in Cycles\n") + else: + output.write("Blender was built without Cycles support\n") + if bpy.app.background: output.write("\nOpenGL: missing, background mode\n") else: diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.cpp b/source/blender/imbuf/intern/oiio/openimageio_api.cpp index fe74b8f7cce..ec9c8fdbb4d 100644 --- a/source/blender/imbuf/intern/oiio/openimageio_api.cpp +++ b/source/blender/imbuf/intern/oiio/openimageio_api.cpp @@ -275,6 +275,11 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac } } +int OIIO_getVersionHex(void) +{ + return openimageio_version(); +} + } // export "C" diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.h b/source/blender/imbuf/intern/oiio/openimageio_api.h index ad11f4bcfe3..df1122584bd 100644 --- a/source/blender/imbuf/intern/oiio/openimageio_api.h +++ b/source/blender/imbuf/intern/oiio/openimageio_api.h @@ -39,12 +39,16 @@ extern "C" { #include +struct ImBuf; + int imb_is_a_photoshop (const char *name); int imb_save_photoshop (struct ImBuf *ibuf, const char *name, int flags); struct ImBuf *imb_load_photoshop (const char *name, int flags, char *colorspace); +int OIIO_getVersionHex(void); + #ifdef __cplusplus } diff --git a/source/blender/python/SConscript b/source/blender/python/SConscript index 0ac0285031e..3378c43f1f6 100644 --- a/source/blender/python/SConscript +++ b/source/blender/python/SConscript @@ -183,8 +183,13 @@ if env['WITH_BF_SMOKE']: if env['WITH_BF_COLLADA']: defs.append('WITH_COLLADA') -if env['WITH_BF_OIIO']: +if env['WITH_BF_OCIO']: defs.append('WITH_OCIO') + incs += ' ' + '#/intern/opencolorio' + +if env['WITH_BF_OIIO']: + defs.append('WITH_OPENIMAGEIO') + incs += ' ../../imbuf/intern/oiio' if env['WITH_BF_PLAYER']: defs.append('WITH_PLAYER') diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt index ef5d26dccdc..0605f408348 100644 --- a/source/blender/python/intern/CMakeLists.txt +++ b/source/blender/python/intern/CMakeLists.txt @@ -35,6 +35,7 @@ set(INC ../../makesrna ../../windowmanager ../../../../intern/cycles/blender + ../../../../intern/opencolorio ../../../../intern/guardedalloc ) @@ -49,6 +50,8 @@ set(SRC bpy_app_ffmpeg.c bpy_app_build_options.c bpy_app_handlers.c + bpy_app_ocio.c + bpy_app_oiio.c bpy_app_translations.c bpy_driver.c bpy_interface.c @@ -73,6 +76,8 @@ set(SRC bpy_app_ffmpeg.h bpy_app_build_options.h bpy_app_handlers.h + bpy_app_ocio.h + bpy_app_oiio.h bpy_app_translations.h bpy_driver.h bpy_intern_string.h @@ -242,6 +247,13 @@ if(WITH_OPENCOLORIO) add_definitions(-DWITH_OCIO) endif() +if(WITH_OPENIMAGEIO) + add_definitions(-DWITH_OPENIMAGEIO) + list(APPEND INC + ../../imbuf/intern/oiio + ) +endif() + if(WITH_PLAYER) add_definitions(-DWITH_PLAYER) endif() diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c index 21767196e11..795015c42a0 100644 --- a/source/blender/python/intern/bpy_app.c +++ b/source/blender/python/intern/bpy_app.c @@ -34,6 +34,8 @@ #include "bpy_app.h" #include "bpy_app_ffmpeg.h" +#include "bpy_app_ocio.h" +#include "bpy_app_oiio.h" #include "bpy_app_build_options.h" #include "bpy_app_translations.h" @@ -93,6 +95,8 @@ static PyStructSequence_Field app_info_fields[] = { /* submodules */ {(char *)"ffmpeg", (char *)"FFmpeg library information backend"}, + {(char *)"ocio", (char *)"OpenColorIO library information backend"}, + {(char *)"oiio", (char *)"OpenImageIO library information backend"}, {(char *)"build_options", (char *)"A set containing most important enabled optional build features"}, {(char *)"handlers", (char *)"Application handler callbacks"}, {(char *)"translations", (char *)"Application and addons internationalization API"}, @@ -167,6 +171,8 @@ static PyObject *make_app_info(void) #endif SetObjItem(BPY_app_ffmpeg_struct()); + SetObjItem(BPY_app_ocio_struct()); + SetObjItem(BPY_app_oiio_struct()); SetObjItem(BPY_app_build_options_struct()); SetObjItem(BPY_app_handlers_struct()); SetObjItem(BPY_app_translations_struct()); diff --git a/source/blender/python/intern/bpy_app_ocio.c b/source/blender/python/intern/bpy_app_ocio.c new file mode 100644 index 00000000000..dfcbfe94ead --- /dev/null +++ b/source/blender/python/intern/bpy_app_ocio.c @@ -0,0 +1,109 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * Contributor(s): Sergey Sharybin + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/intern/bpy_app_ocio.c + * \ingroup pythonintern + */ + +#include +#include "BLI_utildefines.h" + +#include "bpy_app_ocio.h" + +#ifdef WITH_OCIO +# include "ocio_capi.h" +#endif + +static PyTypeObject BlenderAppOCIOType; + +static PyStructSequence_Field app_ocio_info_fields[] = { + {(char *)"supported", (char *)("Boolean, True when Blender is built with OpenColorIO support")}, + {(char *)("version"), (char *)("The OpenColorIO version as a tuple of 3 numbers")}, + {(char *)("version_string"), (char *)("The OpenColorIO version formatted as a string")}, + {NULL} +}; + +static PyStructSequence_Desc app_ocio_info_desc = { + (char *)"bpy.app.ocio", /* name */ + (char *)"This module contains information about OpenColorIO blender is linked against", /* doc */ + app_ocio_info_fields, /* fields */ + (sizeof(app_ocio_info_fields) / sizeof(PyStructSequence_Field)) - 1 +}; + +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; + } + +#define SetStrItem(str) \ + PyStructSequence_SET_ITEM(ocio_info, pos++, PyUnicode_FromString(str)) +#define SetObjItem(obj) \ + PyStructSequence_SET_ITEM(ocio_info, pos++, obj) + +#ifdef WITH_OCIO + curversion = OCIO_getVersionHex(); + SetObjItem(PyBool_FromLong(1)); + SetObjItem(Py_BuildValue("(iii)", + curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256)); + SetObjItem(PyUnicode_FromFormat("%2d, %2d, %2d", + curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256)); +#else + SetObjItem(PyBool_FromLong(0)); + SetStrItem("Unknown"); + SetStrItem("Unknown"); +#endif + + if (PyErr_Occurred()) { + Py_CLEAR(ocio_info); + 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)_Py_HashPointer; /* without this we can't do set(sys.modules) [#29635] */ + + return ret; +} diff --git a/source/blender/python/intern/bpy_app_ocio.h b/source/blender/python/intern/bpy_app_ocio.h new file mode 100644 index 00000000000..ff230b4ba66 --- /dev/null +++ b/source/blender/python/intern/bpy_app_ocio.h @@ -0,0 +1,32 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * Contributor(s): Sergey Sharybin + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/intern/bpy_app_ocio.h + * \ingroup pythonintern + */ + +#ifndef __BPY_APP_OCIO_H__ +#define __BPY_APP_OCIO_H__ + +PyObject *BPY_app_ocio_struct(void); + +#endif /* __BPY_APP_OCIO_H__ */ diff --git a/source/blender/python/intern/bpy_app_oiio.c b/source/blender/python/intern/bpy_app_oiio.c new file mode 100644 index 00000000000..db6df9288bb --- /dev/null +++ b/source/blender/python/intern/bpy_app_oiio.c @@ -0,0 +1,109 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * Contributor(s): Sergey Sharybin + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/intern/bpy_app_oiio.c + * \ingroup pythonintern + */ + +#include +#include "BLI_utildefines.h" + +#include "bpy_app_oiio.h" + +#ifdef WITH_OPENIMAGEIO +# include "openimageio_api.h" +#endif + +static PyTypeObject BlenderAppOIIOType; + +static PyStructSequence_Field app_oiio_info_fields[] = { + {(char *)"supported", (char *)("Boolean, True when Blender is built with OpenImageIO support")}, + {(char *)("version"), (char *)("The OpenImageIO version as a tuple of 3 numbers")}, + {(char *)("version_string"), (char *)("The OpenImageIO version formatted as a string")}, + {NULL} +}; + +static PyStructSequence_Desc app_oiio_info_desc = { + (char *)"bpy.app.oiio", /* name */ + (char *)"This module contains information about OpeImageIO blender is linked against", /* doc */ + app_oiio_info_fields, /* fields */ + (sizeof(app_oiio_info_fields) / sizeof(PyStructSequence_Field)) - 1 +}; + +static PyObject *make_oiio_info(void) +{ + PyObject *oiio_info; + int pos = 0; + +#ifdef WITH_OPENIMAGEIO + int curversion; +#endif + + oiio_info = PyStructSequence_New(&BlenderAppOIIOType); + if (oiio_info == NULL) { + return NULL; + } + +#define SetStrItem(str) \ + PyStructSequence_SET_ITEM(oiio_info, pos++, PyUnicode_FromString(str)) +#define SetObjItem(obj) \ + PyStructSequence_SET_ITEM(oiio_info, pos++, obj) + +#ifdef WITH_OPENIMAGEIO + curversion = OIIO_getVersionHex(); + SetObjItem(PyBool_FromLong(1)); + SetObjItem(Py_BuildValue("(iii)", + curversion / 10000, (curversion / 100) % 100, curversion % 100)); + SetObjItem(PyUnicode_FromFormat("%2d, %2d, %2d", + curversion / 10000, (curversion / 100) % 100, curversion % 100)); +#else + SetObjItem(PyBool_FromLong(0)); + SetStrItem("Unknown"); + SetStrItem("Unknown"); +#endif + + if (PyErr_Occurred()) { + Py_CLEAR(oiio_info); + return NULL; + } + +#undef SetStrItem +#undef SetObjItem + + return oiio_info; +} + +PyObject *BPY_app_oiio_struct(void) +{ + PyObject *ret; + + PyStructSequence_InitType(&BlenderAppOIIOType, &app_oiio_info_desc); + + ret = make_oiio_info(); + + /* prevent user from creating new instances */ + BlenderAppOIIOType.tp_init = NULL; + BlenderAppOIIOType.tp_new = NULL; + BlenderAppOIIOType.tp_hash = (hashfunc)_Py_HashPointer; /* without this we can't do set(sys.modules) [#29635] */ + + return ret; +} diff --git a/source/blender/python/intern/bpy_app_oiio.h b/source/blender/python/intern/bpy_app_oiio.h new file mode 100644 index 00000000000..775fed237f2 --- /dev/null +++ b/source/blender/python/intern/bpy_app_oiio.h @@ -0,0 +1,32 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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. + * + * Contributor(s): Sergey Sharybin + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/intern/bpy_app_oiio.h + * \ingroup pythonintern + */ + +#ifndef __BPY_APP_OIIO_H__ +#define __BPY_APP_OIIO_H__ + +PyObject *BPY_app_oiio_struct(void); + +#endif /* __BPY_APP_OIIO_H__ */