Beispiel #1
0
 void GetCDLTransforms(CDLTransformMap & transformMap,
                       CDLTransformVec & transformVec,
                       TiXmlElement * cccRootElement)
 {
     if(!cccRootElement)
     {
         std::ostringstream os;
         os << "GetCDLTransforms Error. ";
         os << "Null cccRootElement.";
         throw Exception(os.str().c_str());
     }
         
     if(std::string(cccRootElement->Value()) != "ColorCorrectionCollection")
     {
         std::ostringstream os;
         os << "GetCDLTransforms Error. ";
         os << "Root element is type '" << cccRootElement->Value() << "', ";
         os << "ColorCorrectionCollection expected.";
         throw Exception(os.str().c_str());
     }
     
     TiXmlNode * child = cccRootElement->FirstChild("ColorCorrection");
     while(child)
     {
         CDLTransformRcPtr transform = CDLTransform::Create();
         LoadCDL(transform.get(), child->ToElement());
         
         transformVec.push_back(transform);
         
         std::string id = transform->getID();
         if(!id.empty())
         {
             CDLTransformMap::iterator iter = transformMap.find(id);
             if(iter != transformMap.end())
             {
                 std::ostringstream os;
                 os << "Error loading ccc xml. ";
                 os << "Duplicate elements with '" << id << "' found. ";
                 os << "If id is specified, it must be unique.";
                 throw Exception(os.str().c_str());
             }
             
             transformMap[id] = transform;
         }
         
         child = child->NextSibling("ColorCorrection");
     }
 }
Beispiel #2
0
 void GetCDLTransforms(CDLTransformMap & transforms,
                       TiXmlElement * cccRootElement)
 {
     if(std::string(cccRootElement->Value()) != "ColorCorrectionCollection")
     {
         std::ostringstream os;
         os << "GetCDLTransforms Error. ";
         os << "Root element is type '" << cccRootElement->Value() << "', ";
         os << "ColorCorrectionCollection expected.";
         throw Exception(os.str().c_str());
     }
     
     TiXmlNode * child = cccRootElement->FirstChild("ColorCorrection");
     while(child)
     {
         CDLTransformRcPtr transform = CDLTransform::Create();
         LoadCDL(transform.get(), child->ToElement());
         
         std::string id = transform->getID();
         if(id.empty())
         {
             std::ostringstream os;
             os << "Error loading ccc xml, ";
             os << "All ASC ColorCorrections must specify an 'id' value.";
             throw Exception(os.str().c_str());
         }
         
         CDLTransformMap::iterator iter = transforms.find(id);
         if(iter != transforms.end())
         {
             std::ostringstream os;
             os << "Error loading ccc xml. ";
             os << "All ASC ColorCorrections must specify a unique 'id' value. ";
             os << "Duplicate elements with '" << id << "' found.";
             throw Exception(os.str().c_str());
         }
         
         transforms[id] = transform;
         
         child = child->NextSibling("ColorCorrection");
     }
 }
Beispiel #3
0
 CDLTransformRcPtr CDLTransform::CreateFromFile(const char * src, const char * cccid_)
 {
     if(!src || (strlen(src) == 0) )
     {
         std::ostringstream os;
         os << "Error loading CDL xml. ";
         os << "Source file not specified.";
         throw Exception(os.str().c_str());
     }
     
     std::string cccid;
     if(cccid_) cccid = cccid_;
     
     // Check cache
     AutoMutex lock(g_cacheMutex);
     
     // Use g_cacheSrcIsCC as a proxy for if we have loaded this source
     // file already (in which case it must be in cache, or an error)
     
     StringBoolMap::iterator srcIsCCiter = g_cacheSrcIsCC.find(src);
     if(srcIsCCiter != g_cacheSrcIsCC.end())
     {
         // If the source file is known to be a pure ColorCorrection element,
         // null out the cccid so its ignored.
         if(srcIsCCiter->second) cccid = "";
         
         // Search for the cccid by name
         CDLTransformMap::iterator iter = 
             g_cache.find(GetCDLLocalCacheKey(src, cccid));
         if(iter != g_cache.end())
         {
             return iter->second;
         }
         
         // Search for cccid by index
         int cccindex=0;
         if(StringToInt(&cccindex, cccid.c_str(), true))
         {
             iter = g_cache.find(GetCDLLocalCacheKey(src, cccindex));
             if(iter != g_cache.end())
             {
                 return iter->second;
             }
         }
         
         std::ostringstream os;
         os << "The specified cccid/cccindex '" << cccid;
         os << "' could not be loaded from the src file '";
         os << src;
         os << "'.";
         throw Exception (os.str().c_str());
     }
     
     
     // Try to read all ccs from the file, into cache
     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());
         
         cccid = "";
         g_cacheSrcIsCC[src] = true;
         g_cache[GetCDLLocalCacheKey(src, cccid)] = cdl;
     }
     else if(rootValue == "ColorCorrectionCollection")
     {
         // Load all CCs from the ColorCorrectionCollection
         // into the cache
         CDLTransformMap transformMap;
         CDLTransformVec transformVec;
         GetCDLTransforms(transformMap, transformVec, doc.RootElement());
         
         if(transformVec.empty())
         {
             std::ostringstream os;
             os << "Error loading ccc xml. ";
             os << "No ColorCorrection elements found in file '";
             os << src << "'.";
             throw Exception(os.str().c_str());
         }
         
         g_cacheSrcIsCC[src] = false;
         
         // Add all by transforms to cache
         // First by index, then by id
         for(unsigned int i=0; i<transformVec.size(); ++i)
         {
             g_cache[GetCDLLocalCacheKey(src, i)] = transformVec[i];
         }
         
         for(CDLTransformMap::iterator iter = transformMap.begin();
             iter != transformMap.end();
             ++iter)
         {
             g_cache[GetCDLLocalCacheKey(src, iter->first)] = iter->second;
         }
     }
     
     // The all transforms should be in the cache.  Look it up, and try
     // to return it.
     {
         // Search for the cccid by name
         CDLTransformMap::iterator iter = 
             g_cache.find(GetCDLLocalCacheKey(src, cccid));
         if(iter != g_cache.end())
         {
             return iter->second;
         }
         
         // Search for cccid by index
         int cccindex=0;
         if(StringToInt(&cccindex, cccid.c_str(), true))
         {
             iter = g_cache.find(GetCDLLocalCacheKey(src, cccindex));
             if(iter != g_cache.end())
             {
                 return iter->second;
             }
         }
         
         std::ostringstream os;
         os << "The specified cccid/cccindex '" << cccid;
         os << "' could not be loaded from the src file '";
         os << src;
         os << "'.";
         throw Exception (os.str().c_str());
     }
 }
Beispiel #4
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());
 }