Beispiel #1
0
 CDLTransformRcPtr CDLTransform::CreateFromFile(const char * src, const char * cccid)
 {
     if(!src || (strlen(src) == 0) || !cccid)
     {
         std::ostringstream os;
         os << "Error loading CDL xml. ";
         os << "Source file not specified.";
         throw Exception(os.str().c_str());
     }
     
     // Check cache
     AutoMutex lock(g_cacheMutex);
     {
         CDLTransformMap::iterator iter = 
             g_cache.find(GetCDLLocalCacheKey(src,cccid));
         if(iter != g_cache.end())
         {
             return iter->second;
         }
     }
     
     std::ifstream istream(src);
     if(istream.fail()) {
         std::ostringstream os;
         os << "Error could not read CDL source file '" << src;
         os << "'. Please verify the file exists and appropriate ";
         os << "permissions are set.";
         throw Exception (os.str().c_str());
     }
     
     // Read the file into a string.
     std::ostringstream rawdata;
     rawdata << istream.rdbuf();
     std::string xml = rawdata.str();
     
     if(xml.empty())
     {
         std::ostringstream os;
         os << "Error loading CDL xml. ";
         os << "The specified source file, '";
         os << src << "' appears to be empty.";
         throw Exception(os.str().c_str());
     }
     
     TiXmlDocument doc;
     doc.Parse(xml.c_str());
     
     if(doc.Error())
     {
         std::ostringstream os;
         os << "Error loading CDL xml from file '";
         os << src << "'. ";
         os << doc.ErrorDesc() << " (line ";
         os << doc.ErrorRow() << ", character ";
         os << doc.ErrorCol() << ")";
         throw Exception(os.str().c_str());
     }
     
     if(!doc.RootElement())
     {
         std::ostringstream os;
         os << "Error loading CDL xml from file '";
         os << src << "'. ";
         os << "Please confirm the xml is valid.";
         throw Exception(os.str().c_str());
     }
     
     std::string rootValue = doc.RootElement()->Value();
     if(rootValue == "ColorCorrection")
     {
         // Load a single ColorCorrection into the cache
         CDLTransformRcPtr cdl = CDLTransform::Create();
         LoadCDL(cdl.get(), doc.RootElement()->ToElement());
         g_cache[GetCDLLocalCacheKey(src,cccid)] = cdl;
         return cdl;
     }
     else if(rootValue == "ColorCorrectionCollection")
     {
         // Load all CCs from the ColorCorrectionCollection
         // into the cache
         
         CDLTransformMap transforms;
         GetCDLTransforms(transforms, doc.RootElement());
         
         if(transforms.empty())
         {
             std::ostringstream os;
             os << "Error loading ccc xml. ";
             os << "No ColorCorrection elements found in file '";
             os << src << "'.";
             throw Exception(os.str().c_str());
         }
         
         for(CDLTransformMap::iterator iter = transforms.begin();
             iter != transforms.end();
             ++iter)
         {
             g_cache[GetCDLLocalCacheKey(src,iter->first)] = iter->second;
         }
         
         CDLTransformMap::iterator cciter = g_cache.find(GetCDLLocalCacheKey(src,cccid));
         if(cciter == g_cache.end())
         {
             std::ostringstream os;
             os << "Error loading ccc xml. ";
             os << "The specified cccid " << cccid << " ";
             os << "could not be found in file '";
             os << src << "'.";
             throw Exception(os.str().c_str());
         }
         
         return cciter->second;
     }
     
     std::ostringstream os;
     os << "Error loading CDL xml from file '";
     os << src << "'. ";
     os << "Root xml element is type '" << rootValue << "', ";
     os << "ColorCorrection or ColorCorrectionCollection expected.";
     throw Exception(os.str().c_str());
 }