void cutter::load_masks(const config& conf) { const config::child_list& masks = conf.get_children("mask"); for(config::child_list::const_iterator itor = masks.begin(); itor != masks.end(); ++itor) { const std::string name = (**itor)["name"]; const std::string image = get_mask_dir() + "/" + (**itor)["image"]; if(verbose_) { std::cerr << "Adding mask " << name << "\n"; } if(image.empty()) throw exploder_failure("Missing image for mask " + name); const exploder_point shift((**itor)["shift"]); const exploder_rect cut((**itor)["cut"]); if(masks_.find(name) != masks_.end() && masks_[name].filename != image) { throw exploder_failure("Mask " + name + " correspond to two different files: " + name + " and " + masks_.find(name)->second.filename); } if(masks_.find(name) == masks_.end()) { mask& cur_mask = masks_[name]; cur_mask.name = name; cur_mask.shift = shift; cur_mask.cut = cut; cur_mask.filename = image; surface tmp(IMG_Load(image.c_str())); if(tmp == NULL) throw exploder_failure("Unable to load mask image " + image); cur_mask.image = surface(make_neutral_surface(tmp)); } if(masks_[name].image == NULL) throw exploder_failure("Unable to load mask image " + image); } }
void cutter::load_masks(const config& conf) { BOOST_FOREACH(const config &m, conf.child_range("mask")) { const std::string name = m["name"]; const std::string image = get_mask_dir() + "/" + std::string(m["image"]); if(verbose_) { std::cerr << "Adding mask " << name << "\n"; } if(image.empty()) throw exploder_failure("Missing image for mask " + name); const exploder_point shift(m["shift"]); const exploder_rect cut(m["cut"]); if(masks_.find(name) != masks_.end() && masks_[name].filename != image) { throw exploder_failure("Mask " + name + " correspond to two different files: " + name + " and " + masks_.find(name)->second.filename); } if(masks_.find(name) == masks_.end()) { mask& cur_mask = masks_[name]; cur_mask.name = name; cur_mask.shift = shift; cur_mask.cut = cut; cur_mask.filename = image; surface tmp(IMG_Load(image.c_str())); if(tmp == NULL) throw exploder_failure("Unable to load mask image " + image); cur_mask.image = surface(make_neutral_surface(tmp)); } if(masks_[name].image == NULL) throw exploder_failure("Unable to load mask image " + image); } }