Fix T47869: OpenColorIO Error with unicode path to config file under Windows
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 23 Mar 2016 14:09:09 +0000 (15:09 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 23 Mar 2016 14:09:36 +0000 (15:09 +0100)
intern/opencolorio/ocio_impl.cc
source/blender/imbuf/intern/colormanagement.c

index 82536a74159efa36b42e6cfcc0fefc21cab33ea3..5c05d18ac487071bc4b7ac64b053cc96ab748fab 100644 (file)
@@ -25,6 +25,7 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
+#include <fstream>
 #include <iostream>
 #include <sstream>
 #include <string.h>
@@ -55,6 +56,19 @@ using namespace OCIO_NAMESPACE;
 #  define __func__ __FUNCTION__
 #endif
 
+#ifdef _WIN32
+#  ifndef NOGDI
+#    define NOGDI
+#  endif
+#  ifndef NOMINMAX
+#   define NOMINMAX
+#  endif
+#  ifndef WIN32_LEAN_AND_MEAN
+#    define WIN32_LEAN_AND_MEAN
+#  endif
+#  include <windows.h>
+#endif
+
 static void OCIO_reportError(const char *err)
 {
        std::cerr << "OpenColorIO Error: " << err << std::endl;
@@ -121,7 +135,26 @@ OCIO_ConstConfigRcPtr *OCIOImpl::configCreateFromFile(const char *filename)
        ConstConfigRcPtr *config = OBJECT_GUARDED_NEW(ConstConfigRcPtr);
 
        try {
-               *config = Config::CreateFromFile(filename);
+#ifdef _WIN32
+               const int length_mb = strlen(filename);
+               const int length_wc = MultiByteToWideChar(CP_UTF8,
+                                                         0,
+                                                         filename,
+                                                         length_mb,
+                                                         NULL,
+                                                         0);
+               std::wstring wfilename(length_wc, 0);
+               MultiByteToWideChar(CP_UTF8,
+                                   0,
+                                   filename,
+                                   length_mb,
+                                   &wfilename[0],
+                                   length_wc);
+               std::fstream stream(wfilename);
+#else
+               std::fstream stream(filename);
+#endif
+               *config = Config::CreateFromStream(stream);
 
                if (*config)
                        return (OCIO_ConstConfigRcPtr *) config;
@@ -622,7 +655,7 @@ void OCIOImpl::matrixTransformScale(float *m44, float *offset4, const float *sca
 
 const char *OCIOImpl::getVersionString(void)
 {
-       return GetVersion();
+       return OCIO_NAMESPACE::GetVersion();
 }
 
 int OCIOImpl::getVersionHex(void)
index e4e93d3c4da529226f1f4ba0367bc6fb292286be..e38367414fd508d85829c66b923c3b72ba9681d6 100644 (file)
@@ -635,18 +635,7 @@ void colormanagement_init(void)
 
                if (configdir) {
                        BLI_join_dirfile(configfile, sizeof(configfile), configdir, BCM_CONFIG_FILE);
-
-#ifdef WIN32
-                       {
-                               /* quite a hack to support loading configuration from path with non-acii symbols */
-
-                               char short_name[256];
-                               BLI_get_short_name(short_name, configfile);
-                               config = OCIO_configCreateFromFile(short_name);
-                       }
-#else
                        config = OCIO_configCreateFromFile(configfile);
-#endif
                }
        }