Extend system-info with information about OIIO, OCIO and OSL
authorSergey Sharybin <sergey.vfx@gmail.com>
Sun, 8 Dec 2013 09:03:17 +0000 (15:03 +0600)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sun, 8 Dec 2013 09:03:17 +0000 (15:03 +0600)
Summary:
Version of those libraries might be useful to know.

- OIIO and OCIO is exposed via bpy.app.oiio and bpy.app.ocio.
  There're "supported", "version" and "version_string" defined
  in those modules.

- OSL is available as _cycles.osl_version and _cycles.osl_version_string.

Reviewers: campbellbarton

Reviewed By: campbellbarton

CC: dingto
Differential Revision: http://developer.blender.org/D79

16 files changed:
intern/cycles/blender/blender_python.cpp
intern/opencolorio/fallback_impl.cc
intern/opencolorio/ocio_capi.cc
intern/opencolorio/ocio_capi.h
intern/opencolorio/ocio_impl.cc
intern/opencolorio/ocio_impl.h
release/scripts/modules/sys_info.py
source/blender/imbuf/intern/oiio/openimageio_api.cpp
source/blender/imbuf/intern/oiio/openimageio_api.h
source/blender/python/SConscript
source/blender/python/intern/CMakeLists.txt
source/blender/python/intern/bpy_app.c
source/blender/python/intern/bpy_app_ocio.c [new file with mode: 0644]
source/blender/python/intern/bpy_app_ocio.h [new file with mode: 0644]
source/blender/python/intern/bpy_app_oiio.c [new file with mode: 0644]
source/blender/python/intern/bpy_app_oiio.h [new file with mode: 0644]

index 8e6bcaee3503853cffe5c6cf3c3068f67732514a..f10b185287db4c576cb183015ce1853e794c1654 100644 (file)
@@ -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
index ca999eab569cd1dea77d61209a33175d82a610d2..6383bbbb07f388b8fe04924b21bf3ce198aaca0c 100644 (file)
@@ -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;
+}
index 30668dff245d3d402de9e6b87c9dbfb84dd06e99..47ee3afddfd315d05a81c3a380bb6a5e0fd3fd7d 100644 (file)
@@ -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();
+}
index 5532ade1f3a1d9b1f2311c5b1e524bffeab2d6a2..5abe104fcd41f2fad7b462790e57db436ec1a4d5 100644 (file)
@@ -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
index 2cffe1a89ef7f6a55c3c01808b7804856ee98838..663ca2d1c750a0f410ecd9106b9b166b51d31e8e 100644 (file)
@@ -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();
+}
index 8b666e8ae1446ba4eba65928d9189c69d3ca4ec9..4e7c1bcc83282894c4a8bf462ea1fe8131627fde 100644 (file)
@@ -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
 
index 83f2647c5b2640c5cfde6b275a020577d27b0f1c..ef3e56209f0a75fe38f645e207011658c48e4c44 100644 (file)
@@ -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:
index fe74b8f7cce56aafc82014e1b24db4ba3450664b..ec9c8fdbb4d0be5f2e18979defd40a3aaacb7f0b 100644 (file)
@@ -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"
 
 
index ad11f4bcfe37c1df7374c7d0c24acaa860ca27de..df1122584bd72b21cad36eeccec8cb9356325e11 100644 (file)
@@ -39,12 +39,16 @@ extern "C" {
 
 #include <stdio.h>
 
+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
 }
 
index 0ac0285031e25813d21ed84a4d1f03f9ec5714e0..3378c43f1f65ff10eb0c5b4188a302d654a6a2ec 100644 (file)
@@ -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')
index ef5d26dccdcd36707dd73350f428328bb2765f4d..0605f408348eefc5d5a3022746ed024efffa2462 100644 (file)
@@ -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()
index 21767196e119e3ee19355d9705d20b7c1487ce65..795015c42a00d64cce308c38effa659ae44bb636 100644 (file)
@@ -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 (file)
index 0000000..dfcbfe9
--- /dev/null
@@ -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 <Python.h>
+#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 (file)
index 0000000..ff230b4
--- /dev/null
@@ -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 (file)
index 0000000..db6df92
--- /dev/null
@@ -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 <Python.h>
+#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 (file)
index 0000000..775fed2
--- /dev/null
@@ -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__ */