| 235 | } |
| 236 | |
| 237 | void Baker::bake(std::ostream & os) const |
| 238 | { |
| 239 | FileFormat* fmt = FormatRegistry::GetInstance().getFileFormatByName(getImpl()->m_formatName); |
| 240 | |
| 241 | if(!fmt) |
| 242 | { |
| 243 | std::ostringstream err; |
| 244 | err << "The format named '" << getImpl()->m_formatName; |
| 245 | err << "' could not be found. "; |
| 246 | throw Exception(err.str().c_str()); |
| 247 | } |
| 248 | |
| 249 | FormatInfoVec fmtInfoVec; |
| 250 | fmt->getFormatInfo(fmtInfoVec); |
| 251 | FormatInfo fmtInfo = fmtInfoVec[0]; |
| 252 | |
| 253 | const std::string & inputSpace = getImpl()->m_inputSpace; |
| 254 | const std::string & targetSpace = getImpl()->m_targetSpace; |
| 255 | const std::string & shaperSpace = getImpl()->m_shaperSpace; |
| 256 | const std::string & display = getImpl()->m_display; |
| 257 | const std::string & view = getImpl()->m_view; |
| 258 | |
| 259 | const bool displayViewMode = !display.empty() && !view.empty(); |
| 260 | const bool colorSpaceMode = !targetSpace.empty(); |
| 261 | |
| 262 | // Settings validation. |
| 263 | if(!getConfig()) |
| 264 | { |
| 265 | throw Exception("No OCIO config has been set."); |
| 266 | } |
| 267 | |
| 268 | if(inputSpace.empty()) |
| 269 | { |
| 270 | throw Exception("No input space has been set."); |
| 271 | } |
| 272 | |
| 273 | if(!displayViewMode && !colorSpaceMode) |
| 274 | { |
| 275 | throw Exception("No display / view or target colorspace has been set."); |
| 276 | } |
| 277 | |
| 278 | if(displayViewMode && colorSpaceMode) |
| 279 | { |
| 280 | throw Exception("Cannot use both display / view and target colorspace."); |
| 281 | } |
| 282 | |
| 283 | if(!getConfig()->getColorSpace(inputSpace.c_str())) |
| 284 | { |
| 285 | std::ostringstream os; |
| 286 | os << "Could not find input colorspace '" << inputSpace << "'."; |
| 287 | throw Exception(os.str().c_str()); |
| 288 | } |
| 289 | |
| 290 | if(colorSpaceMode && !getConfig()->getColorSpace(targetSpace.c_str())) |
| 291 | { |
| 292 | std::ostringstream os; |
| 293 | os << "Could not find target colorspace '" << targetSpace << "'."; |
| 294 | throw Exception(os.str().c_str()); |