This commit is contained in:
itsmattkc
2020-05-06 00:23:11 +10:00
3 changed files with 22 additions and 41 deletions
+14 -2
View File
@@ -51,7 +51,7 @@ OCIO::ConstConfigRcPtr ColorManager::GetConfig() const
OCIO::ConstConfigRcPtr ColorManager::CreateConfigFromFile(const QString &filename)
{
SetCLocale();
OCIO_SET_C_LOCALE_FOR_SCOPE;
return OCIO::Config::CreateFromFile(filename.toUtf8());
}
@@ -68,10 +68,11 @@ OCIO::ConstConfigRcPtr ColorManager::GetDefaultConfig()
void ColorManager::SetUpDefaultConfig()
{
OCIO_SET_C_LOCALE_FOR_SCOPE;
if (!qgetenv("OCIO").isEmpty()) {
// Attempt to set config from "OCIO" environment variable
try {
SetCLocale();
default_config_ = OCIO::Config::CreateFromEnv();
return;
@@ -381,4 +382,15 @@ void ColorManager::AssociateAlphaInternal(ColorManager::AlphaAction action, T *d
}
}
ColorManager::SetLocale::SetLocale(const char* new_locale)
{
old_locale_ = setlocale(LC_NUMERIC, nullptr);
setlocale(LC_NUMERIC, new_locale);
}
ColorManager::SetLocale::~SetLocale()
{
setlocale(LC_NUMERIC, old_locale_.toUtf8());
}
OLIVE_NAMESPACE_EXIT
+6 -39
View File
@@ -26,6 +26,8 @@
#include "codec/frame.h"
#include "colorprocessor.h"
#define OCIO_SET_C_LOCALE_FOR_SCOPE ColorManager::SetLocale d("C")
OLIVE_NAMESPACE_ENTER
class ColorManager : public QObject
@@ -92,50 +94,15 @@ public:
static void SetOCIOMethodForMode(RenderMode::Mode mode, OCIOMethod method);
class SetCLocale
class SetLocale
{
public:
SetCLocale()
{
#ifdef Q_OS_WINDOWS
// set locale will only change locale on the current thread
previousThreadConfig = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
SetLocale(const char* new_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
}
~SetLocale();
private:
#ifdef Q_OS_WINDOWS
SoStringA ssaLocale;
int previousThreadConfig;
#else
locale_t oldLocale;
locale_t currentLocale;
#endif
QString old_locale_;
};
+2
View File
@@ -44,10 +44,12 @@ ColorProcessor::ColorProcessor(ColorManager *config, const QString &input, const
display_transform->setLooksOverrideEnabled(true);
}
OCIO_SET_C_LOCALE_FOR_SCOPE;
processor_ = config->GetConfig()->getProcessor(display_transform);
} else {
OCIO_SET_C_LOCALE_FOR_SCOPE;
processor_ = config->GetConfig()->getProcessor(input.toUtf8(),
output.toUtf8());