void parseArguments(int argc, char **argv) { for(int i=1; i<argc; ++i) { if(0==strcmp(argv[i], "-v")) { g_verbose = true; } else if(0==strcmp(argv[i], "-gpulegacy")) { g_gpulegacy = true; } else if(0==strcmp(argv[i], "-gpuinfo")) { g_gpuinfo = true; } else if(0==strcmp(argv[i], "-h")) { std::cout << std::endl; std::cout << "help:" << std::endl; std::cout << " ociodisplay [OPTIONS] [image] where" << std::endl; std::cout << std::endl; std::cout << " OPTIONS:" << std::endl; std::cout << " -h : displays the help and exit" << std::endl; std::cout << " -v : displays the color space information" << std::endl; std::cout << " -gpulegacy : use the legacy (i.e. baked) GPU color processing" << std::endl; std::cout << " -gpuinfo : output the OCIO shader program" << std::endl; std::cout << std::endl; exit(0); } else { g_filename = argv[i]; } } if(g_verbose) { std::cout << std::endl; if(!g_filename.empty()) { std::cout << "Image:" << std::endl << "\t" << g_filename << std::endl; } std::cout << std::endl; std::cout << "OIIO: " << std::endl << "\tversion = " << OIIO_VERSION_STRING << std::endl; std::cout << std::endl; std::cout << "OCIO: " << std::endl << "\tversion = " << OCIO::GetVersion() << std::endl; if(getenv("OCIO")) { std::cout << "\tconfiguration = " << getenv("OCIO") << std::endl; OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig(); std::cout << "\tsearch_path = " << config->getSearchPath() << std::endl; } } }
int main(int argc, const char **argv) { bool help = false; int errorcount = 0; std::string inputconfig; std::string outputconfig; ArgParse ap; ap.options("ociocheck -- validate an OpenColorIO configuration\n\n" "usage: ociocheck [options]\n", "--help", &help, "Print help message", "--iconfig %s", &inputconfig, "Input .ocio configuration file (default: $OCIO)", "--oconfig %s", &outputconfig, "Output .ocio file", NULL); if (ap.parse(argc, argv) < 0) { std::cout << ap.geterror() << std::endl; ap.usage(); std::cout << DESC_STRING; return 1; } if (help) { ap.usage(); std::cout << DESC_STRING; return 1; } try { OCIO::ConstConfigRcPtr config; std::cout << std::endl; std::cout << "OpenColorIO Library Version: " << OCIO::GetVersion() << std::endl; std::cout << "OpenColorIO Library VersionHex: " << OCIO::GetVersionHex() << std::endl; if(!inputconfig.empty()) { std::cout << "Loading " << inputconfig << std::endl; config = OCIO::Config::CreateFromFile(inputconfig.c_str()); } else if(getenv("OCIO")) { std::cout << "Loading $OCIO " << getenv("OCIO") << std::endl; config = OCIO::Config::CreateFromEnv(); } else { std::cout << "ERROR: You must specify an input OCIO configuration "; std::cout << "(either with --iconfig or $OCIO).\n"; ap.usage (); std::cout << DESC_STRING; return 1; } std::cout << std::endl; std::cout << "** General **" << std::endl; std::cout << "Search Path: " << config->getSearchPath() << std::endl; std::cout << "Working Dir: " << config->getWorkingDir() << std::endl; std::cout << std::endl; std::cout << "Default Display: " << config->getDefaultDisplay() << std::endl; std::cout << "Default View: " << config->getDefaultView(config->getDefaultDisplay()) << std::endl; { std::cout << std::endl; std::cout << "** Roles **" << std::endl; std::set<std::string> usedroles; const char * allroles[] = { OCIO::ROLE_DEFAULT, OCIO::ROLE_SCENE_LINEAR, OCIO::ROLE_DATA, OCIO::ROLE_REFERENCE, OCIO::ROLE_COMPOSITING_LOG, OCIO::ROLE_COLOR_TIMING, OCIO::ROLE_COLOR_PICKING, OCIO::ROLE_TEXTURE_PAINT, OCIO::ROLE_MATTE_PAINT, NULL }; int MAXROLES=256; for(int i=0;i<MAXROLES; ++i) { const char * role = allroles[i]; if(!role) break; usedroles.insert(role); OCIO::ConstColorSpaceRcPtr cs = config->getColorSpace(role); if(cs) { std::cout << cs->getName() << " (" << role << ")" << std::endl; } else { std::cout << "ERROR: NOT DEFINED" << " (" << role << ")" << std::endl; errorcount += 1; } } for(int i=0; i<config->getNumRoles(); ++i) { const char * role = config->getRoleName(i); if(usedroles.find(role) != usedroles.end()) continue; OCIO::ConstColorSpaceRcPtr cs = config->getColorSpace(role); if(cs) { std::cout << cs->getName() << " (" << role << ": user)" << std::endl; } else { std::cout << "ERROR: NOT DEFINED" << " (" << role << ")" << std::endl; errorcount += 1; } } } std::cout << std::endl; std::cout << "** ColorSpaces **" << std::endl; OCIO::ConstColorSpaceRcPtr lin = config->getColorSpace(OCIO::ROLE_SCENE_LINEAR); if(!lin) { std::cout << "Error: scene_linear role must be defined." << std::endl; errorcount += 1; } else { for(int i=0; i<config->getNumColorSpaces(); ++i) { OCIO::ConstColorSpaceRcPtr cs = config->getColorSpace(config->getColorSpaceNameByIndex(i)); bool convertsToLinear = true; std::string convertsToLinearErrorText; bool convertsFromLinear = true; std::string convertsFromLinearErrorText; try { OCIO::ConstProcessorRcPtr p = config->getProcessor(cs, lin); } catch(OCIO::Exception & exception) { convertsToLinear = false; convertsToLinearErrorText = exception.what(); } try { OCIO::ConstProcessorRcPtr p = config->getProcessor(lin, cs); } catch(OCIO::Exception & exception) { convertsFromLinear = false; convertsFromLinearErrorText = exception.what(); } if(convertsToLinear && convertsFromLinear) { std::cout << cs->getName() << std::endl; } else if(!convertsToLinear && !convertsFromLinear) { std::cout << cs->getName(); std::cout << " -- error" << std::endl; std::cout << "\t" << convertsToLinearErrorText << std::endl; std::cout << "\t" << convertsFromLinearErrorText << std::endl; errorcount += 1; } else if(convertsToLinear) { std::cout << cs->getName(); std::cout << " -- input only" << std::endl; } else if(convertsFromLinear) { std::cout << cs->getName(); std::cout << " -- output only" << std::endl; } } } std::cout << std::endl; std::cout << "** Looks **" << std::endl; if(config->getNumLooks()>0) { for(int i=0; i<config->getNumLooks(); ++i) { std::cout << config->getLookNameByIndex(i) << std::endl; } } else { std::cout << "no looks defined" << std::endl; } std::cout << std::endl; std::cout << "** Sanity Check **" << std::endl; try { config->sanityCheck(); std::cout << "passed" << std::endl; } catch(OCIO::Exception & exception) { std::cout << "ERROR" << std::endl; errorcount += 1; std::cout << exception.what() << std::endl; } if(!outputconfig.empty()) { std::ofstream output; output.open(outputconfig.c_str()); if(!output.is_open()) { std::cout << "Error opening " << outputconfig << " for writing." << std::endl; } else { config->serialize(output); output.close(); std::cout << "Wrote " << outputconfig << std::endl; } } } catch(OCIO::Exception & exception) { std::cout << "ERROR: " << exception.what() << std::endl; return 1; } catch (std::exception& exception) { std::cout << "ERROR: " << exception.what() << "\n"; return 1; } catch(...) { std::cout << "Unknown error encountered." << std::endl; return 1; } std::cout << std::endl; if(errorcount == 0) { std::cout << "Tests complete." << std::endl << std::endl; return 0; } else { std::cout << errorcount << " tests failed." << std::endl << std::endl; return 1; } }