colormanager: always temporarily set C locale when loading an OCIO config from file
Fixes known bug in OCIO when loading files from non-English locales.
This commit is contained in:
@@ -177,7 +177,7 @@ void ProjectPropertiesDialog::OCIOFilenameUpdated()
|
|||||||
if (ocio_filename_->text().isEmpty()) {
|
if (ocio_filename_->text().isEmpty()) {
|
||||||
c = ColorManager::GetDefaultConfig();
|
c = ColorManager::GetDefaultConfig();
|
||||||
} else {
|
} else {
|
||||||
c = OCIO::Config::CreateFromFile(ocio_filename_->text().toUtf8());
|
c = ColorManager::CreateConfigFromFile(ocio_filename_->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
ocio_filename_->setStyleSheet(QString());
|
ocio_filename_->setStyleSheet(QString());
|
||||||
|
|||||||
@@ -49,6 +49,13 @@ OCIO::ConstConfigRcPtr ColorManager::GetConfig() const
|
|||||||
return config_;
|
return config_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OCIO::ConstConfigRcPtr ColorManager::CreateConfigFromFile(const QString &filename)
|
||||||
|
{
|
||||||
|
SetCLocale();
|
||||||
|
|
||||||
|
return OCIO::Config::CreateFromFile(filename.toUtf8());
|
||||||
|
}
|
||||||
|
|
||||||
const QString &ColorManager::GetConfigFilename() const
|
const QString &ColorManager::GetConfigFilename() const
|
||||||
{
|
{
|
||||||
return config_filename_;
|
return config_filename_;
|
||||||
@@ -62,7 +69,9 @@ OCIO::ConstConfigRcPtr ColorManager::GetDefaultConfig()
|
|||||||
void ColorManager::SetUpDefaultConfig()
|
void ColorManager::SetUpDefaultConfig()
|
||||||
{
|
{
|
||||||
if (!qgetenv("OCIO").isEmpty()) {
|
if (!qgetenv("OCIO").isEmpty()) {
|
||||||
|
// Attempt to set config from "OCIO" environment variable
|
||||||
try {
|
try {
|
||||||
|
SetCLocale();
|
||||||
default_config_ = OCIO::Config::CreateFromEnv();
|
default_config_ = OCIO::Config::CreateFromEnv();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -71,7 +80,7 @@ void ColorManager::SetUpDefaultConfig()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kind of hacky, but it'll work
|
// Extract OCIO config - kind of hacky, but it'll work
|
||||||
QString dir = QDir(FileFunctions::GetTempFilePath()).filePath(QStringLiteral("ocioconf"));
|
QString dir = QDir(FileFunctions::GetTempFilePath()).filePath(QStringLiteral("ocioconf"));
|
||||||
|
|
||||||
FileFunctions::CopyDirectory(QStringLiteral(":/ocioconf"),
|
FileFunctions::CopyDirectory(QStringLiteral(":/ocioconf"),
|
||||||
@@ -80,7 +89,7 @@ void ColorManager::SetUpDefaultConfig()
|
|||||||
|
|
||||||
qDebug() << "Extracting default OCIO config to" << dir;
|
qDebug() << "Extracting default OCIO config to" << dir;
|
||||||
|
|
||||||
default_config_ = OCIO::Config::CreateFromFile(QDir(dir).filePath(QStringLiteral("config.ocio")).toUtf8());
|
default_config_ = CreateConfigFromFile(QDir(dir).filePath(QStringLiteral("config.ocio")));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorManager::SetConfig(const QString &filename)
|
void ColorManager::SetConfig(const QString &filename)
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ public:
|
|||||||
|
|
||||||
OCIO::ConstConfigRcPtr GetConfig() const;
|
OCIO::ConstConfigRcPtr GetConfig() const;
|
||||||
|
|
||||||
|
static OCIO::ConstConfigRcPtr CreateConfigFromFile(const QString& filename);
|
||||||
|
|
||||||
const QString& GetConfigFilename() const;
|
const QString& GetConfigFilename() const;
|
||||||
|
|
||||||
static OCIO::ConstConfigRcPtr GetDefaultConfig();
|
static OCIO::ConstConfigRcPtr GetDefaultConfig();
|
||||||
@@ -90,6 +92,53 @@ public:
|
|||||||
|
|
||||||
static void SetOCIOMethodForMode(RenderMode::Mode mode, OCIOMethod method);
|
static void SetOCIOMethodForMode(RenderMode::Mode mode, OCIOMethod method);
|
||||||
|
|
||||||
|
class SetCLocale
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SetCLocale()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
|
// set locale will only change locale on the current thread
|
||||||
|
previousThreadConfig = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
|
||||||
|
|
||||||
|
// get and store current locale
|
||||||
|
ssaLocale.convert(setlocale(LC_ALL, NULL));
|
||||||
|
|
||||||
|
// set to "C" locale
|
||||||
|
setlocale(LC_ALL, "C");
|
||||||
|
#else
|
||||||
|
// set to C locale, saving the old one (returned from useLocale)
|
||||||
|
currentLocale = newlocale(LC_ALL_MASK,"C",NULL);
|
||||||
|
oldLocale = uselocale(currentLocale);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
~SetCLocale()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
|
// thread specific
|
||||||
|
setlocale(LC_ALL, ssaLocale.c_str());
|
||||||
|
|
||||||
|
// set back to global settings]
|
||||||
|
_configthreadlocale(previousThreadConfig);
|
||||||
|
#else
|
||||||
|
// restore the previous locale and freeing the created locale
|
||||||
|
uselocale(oldLocale);
|
||||||
|
freelocale(currentLocale);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
#ifdef Q_OS_WINDOWS
|
||||||
|
SoStringA ssaLocale;
|
||||||
|
int previousThreadConfig;
|
||||||
|
#else
|
||||||
|
locale_t oldLocale;
|
||||||
|
locale_t currentLocale;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void ConfigChanged();
|
void ConfigChanged();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user