Skip to content

Commit

Permalink
core: luts with incorrect file extensions are now correctly loaded
Browse files Browse the repository at this point in the history
This was always the intent, but there was a bug in the
implementation, where were doing seekg on the filestream without clearing
potential error states beforehand.
  • Loading branch information
jeremyselan committed Oct 31, 2011
1 parent 2ebad69 commit 6da3411
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/core/FileFormatSpi3D.cpp
Expand Up @@ -111,7 +111,10 @@ OCIO_NAMESPACE_ENTER
istream.getline(lineBuffer, MAX_LINE_SIZE);
if(!pystring::startswith(pystring::lower(lineBuffer), "spilut"))
{
throw Exception("Lut does not appear to be valid spilut format.");
std::ostringstream os;
os << "Lut does not appear to be valid spilut format. ";
os << "Expected 'SPILUT'. Found, '" << lineBuffer << "'.";
throw Exception(os.str().c_str());
}

// TODO: Assert 2nd line is 3 3
Expand Down
57 changes: 53 additions & 4 deletions src/core/FileTransform.cpp
Expand Up @@ -368,6 +368,18 @@ OCIO_NAMESPACE_ENTER

}

std::string FileFormat::getName() const
{
FormatInfoVec infoVec;
GetFormatInfo(infoVec);
if(infoVec.size()>0)
{
return infoVec[0].name;
}
return "Unknown Format";
}



void FileFormat::Write(const Baker & /*baker*/,
const std::string & formatName,
Expand Down Expand Up @@ -439,36 +451,73 @@ OCIO_NAMESPACE_ENTER
FileCachePair pair = std::make_pair(primaryFormat, cachedFile);
g_fileCache[filepath] = pair;

if(IsDebugLoggingEnabled())
{
std::ostringstream os;
os << " Loaded primary format ";
os << primaryFormat->getName();
LogDebug(os.str());
}

return pair;
}
catch(std::exception & e)
{
primaryErrorText = e.what();
filestream.clear();
filestream.seekg( std::ifstream::beg );

if(IsDebugLoggingEnabled())
{
std::ostringstream os;
os << " Failed primary format ";
os << primaryFormat->getName();
os << ": " << e.what();
LogDebug(os.str());
}
}
}

// If this fails, try all other formats
FormatRegistry & formats = FormatRegistry::GetInstance();
for(int findex = 0; findex<formats.getNumRawFormats(); ++findex)
{
FileFormat * localFormat = formats.getRawFormatByIndex(findex);
FileFormat * altFormat = formats.getRawFormatByIndex(findex);

// Dont bother trying the primaryFormat twice.
if(localFormat == primaryFormat) continue;
if(altFormat == primaryFormat) continue;

try
{
CachedFileRcPtr cachedFile = localFormat->Read(filestream);
CachedFileRcPtr cachedFile = altFormat->Read(filestream);

// Add the result to our cache, return it.
FileCachePair pair = std::make_pair(localFormat, cachedFile);
FileCachePair pair = std::make_pair(altFormat, cachedFile);
g_fileCache[filepath] = pair;

if(IsDebugLoggingEnabled())
{
std::ostringstream os;
os << " Loaded alt format ";
os << altFormat->getName();
LogDebug(os.str());
}

return pair;
}
catch(std::exception & e)
{
filestream.clear();
filestream.seekg( std::ifstream::beg );

if(IsDebugLoggingEnabled())
{
std::ostringstream os;
os << " Failed alt format ";
os << altFormat->getName();
os << ": " << e.what();
LogDebug(os.str());
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/core/FileTransform.h
Expand Up @@ -87,6 +87,9 @@ OCIO_NAMESPACE_ENTER
CachedFileRcPtr cachedFile,
const FileTransform & fileTransform,
TransformDirection dir) const = 0;

// For logging purposes
std::string getName() const;
private:
FileFormat& operator= (const FileFormat &);
};
Expand Down
5 changes: 5 additions & 0 deletions src/core/Logging.cpp
Expand Up @@ -120,5 +120,10 @@ OCIO_NAMESPACE_ENTER
}
}

bool IsDebugLoggingEnabled()
{
return (GetLoggingLevel()>=LOGGING_LEVEL_DEBUG);
}

}
OCIO_NAMESPACE_EXIT
2 changes: 2 additions & 0 deletions src/core/Logging.h
Expand Up @@ -39,6 +39,8 @@ OCIO_NAMESPACE_ENTER
void LogWarning(const std::string & text);
void LogInfo(const std::string & text);
void LogDebug(const std::string & text);

bool IsDebugLoggingEnabled();
}
OCIO_NAMESPACE_EXIT

Expand Down

0 comments on commit 6da3411

Please sign in to comment.