diff --git a/src/apps/ociodisplay/main.cpp b/src/apps/ociodisplay/main.cpp index d464abcf02..ed7f09759a 100644 --- a/src/apps/ociodisplay/main.cpp +++ b/src/apps/ociodisplay/main.cpp @@ -1,7 +1,6 @@ // SPDX-License-Identifier: BSD-3-Clause // Copyright Contributors to the OpenColorIO Project. - #include #include #include @@ -37,11 +36,11 @@ namespace OCIO = OCIO_NAMESPACE; #include "oglapp.h" #include "imageio.h" -bool g_verbose = false; +bool g_verbose = false; bool g_gpulegacy = false; -bool g_gpuinfo = false; +bool g_gpuinfo = false; #if __APPLE__ -bool g_useMetal = false; +bool g_useMetal = false; #endif std::string g_filename; @@ -52,22 +51,21 @@ std::string g_inputColorSpace; std::string g_display; std::string g_transformName; std::string g_look; -OCIO::OptimizationFlags g_optimization{ OCIO::OPTIMIZATION_DEFAULT }; +OCIO::OptimizationFlags g_optimization{OCIO::OPTIMIZATION_DEFAULT}; -static const std::array, 5> OptmizationMenu = { { - { "None", OCIO::OPTIMIZATION_NONE }, - { "Lossless", OCIO::OPTIMIZATION_LOSSLESS }, - { "Very good", OCIO::OPTIMIZATION_VERY_GOOD }, - { "Good", OCIO::OPTIMIZATION_GOOD }, - { "Draft", OCIO::OPTIMIZATION_DRAFT } } }; +static const std::array, 5> OptmizationMenu = {{{"None", OCIO::OPTIMIZATION_NONE}, + {"Lossless", OCIO::OPTIMIZATION_LOSSLESS}, + {"Very good", OCIO::OPTIMIZATION_VERY_GOOD}, + {"Good", OCIO::OPTIMIZATION_GOOD}, + {"Draft", OCIO::OPTIMIZATION_DRAFT}}}; -float g_exposure_fstop{ 0.0f }; -float g_display_gamma{ 1.0f }; -int g_channelHot[4]{ 1, 1, 1, 1 }; // show rgb +float g_exposure_fstop{0.0f}; +float g_display_gamma{1.0f}; +int g_channelHot[4]{1, 1, 1, 1}; // show rgb +int g_viewsMenuID; OCIO::OglAppRcPtr g_oglApp; - void UpdateOCIOGLState(); static void InitImageTexture(const char * filename) @@ -82,7 +80,7 @@ static void InitImageTexture(const char * filename) { img.read(filename, OCIO::BIT_DEPTH_F32); } - catch (const std::exception & e) + catch (const std::exception &e) { std::cerr << "ERROR: Loading file failed: " << e.what() << std::endl; exit(1); @@ -100,19 +98,19 @@ static void InitImageTexture(const char * filename) img.init(512, 512, OCIO::CHANNEL_ORDERING_RGBA, OCIO::BIT_DEPTH_F32); - float * pixels = (float *) img.getData(); + float * pixels = (float *)img.getData(); const long width = img.getWidth(); const long channels = img.getNumChannels(); - for (int y=0; yinitImage(img.getWidth(), img.getHeight(), comp, - (float*) img.getData()); + (float *)img.getData()); } - } void InitOCIO(const char * filename) @@ -167,7 +164,7 @@ void InitOCIO(const char * filename) } else { - std::cout << "colorspace: " << g_inputColorSpace + std::cout << "colorspace: " << g_inputColorSpace << " \t(could not determine from filename, using default)" << std::endl; } @@ -251,34 +248,34 @@ static void Key(unsigned char key, int /*x*/, int /*y*/) static void SpecialKey(int key, int x, int y) { - (void) x; - (void) y; + (void)x; + (void)y; int mod = glutGetModifiers(); - if(key == GLUT_KEY_UP && (mod & GLUT_ACTIVE_CTRL)) + if (key == GLUT_KEY_UP && (mod & GLUT_ACTIVE_CTRL)) { g_exposure_fstop += 0.25f; } - else if(key == GLUT_KEY_DOWN && (mod & GLUT_ACTIVE_CTRL)) + else if (key == GLUT_KEY_DOWN && (mod & GLUT_ACTIVE_CTRL)) { g_exposure_fstop -= 0.25f; } - else if(key == GLUT_KEY_HOME && (mod & GLUT_ACTIVE_CTRL)) + else if (key == GLUT_KEY_HOME && (mod & GLUT_ACTIVE_CTRL)) { g_exposure_fstop = 0.0f; g_display_gamma = 1.0f; } - else if(key == GLUT_KEY_UP && (mod & GLUT_ACTIVE_ALT)) + else if (key == GLUT_KEY_UP && (mod & GLUT_ACTIVE_ALT)) { g_display_gamma *= 1.1f; } - else if(key == GLUT_KEY_DOWN && (mod & GLUT_ACTIVE_ALT)) + else if (key == GLUT_KEY_DOWN && (mod & GLUT_ACTIVE_ALT)) { g_display_gamma /= 1.1f; } - else if(key == GLUT_KEY_HOME && (mod & GLUT_ACTIVE_ALT)) + else if (key == GLUT_KEY_HOME && (mod & GLUT_ACTIVE_ALT)) { g_exposure_fstop = 0.0f; g_display_gamma = 1.0f; @@ -289,6 +286,22 @@ static void SpecialKey(int key, int x, int y) glutPostRedisplay(); } +void updateViewsMenu(const char * displayValue) +{ + + OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig(); + glutSetMenu(g_viewsMenuID); + int numViewsMenuItems = glutGet(GLUT_MENU_NUM_ITEMS); + for (int i = numViewsMenuItems; i > 0; --i) + { + glutRemoveMenuItem(i); + } + for (int i = 0; i < config->getNumViews(displayValue); ++i) + { + glutAddMenuEntry(config->getView(displayValue, i), i); + } +} + void UpdateOCIOGLState() { if (!g_oglApp) @@ -300,9 +313,9 @@ void UpdateOCIOGLState() OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig(); OCIO::DisplayViewTransformRcPtr transform = OCIO::DisplayViewTransform::Create(); - transform->setSrc( g_inputColorSpace.c_str() ); - transform->setDisplay( g_display.c_str() ); - transform->setView( g_transformName.c_str() ); + transform->setSrc(g_inputColorSpace.c_str()); + transform->setDisplay(g_display.c_str()); + transform->setView(g_transformName.c_str()); OCIO::LegacyViewingPipelineRcPtr vp = OCIO::LegacyViewingPipeline::Create(); vp->setDisplayViewTransform(transform); @@ -314,37 +327,37 @@ void UpdateOCIOGLState() std::cout << std::endl; std::cout << "Color transformation composed of:" << std::endl; std::cout << " Image ColorSpace is:\t" << g_inputColorSpace << std::endl; - std::cout << " Transform is:\t\t" << g_transformName << std::endl; - std::cout << " Device is:\t\t" << g_display << std::endl; + std::cout << " Views is:\t\t" << g_transformName << std::endl; + std::cout << " Display is:\t\t" << g_display << std::endl; std::cout << " Looks Override is:\t'" << g_look << "'" << std::endl; std::cout << " with:" << std::endl; std::cout << " exposure_fstop = " << g_exposure_fstop << std::endl; std::cout << " display_gamma = " << g_display_gamma << std::endl; - std::cout << " channels = " + std::cout << " channels = " << (g_channelHot[0] ? "R" : "") << (g_channelHot[1] ? "G" : "") << (g_channelHot[2] ? "B" : "") << (g_channelHot[3] ? "A" : "") << std::endl; - for (const auto & opt : OptmizationMenu) + for (const auto &opt : OptmizationMenu) { if (opt.second == g_optimization) { - std::cout << std::endl << "Optimization: " << opt.first << std::endl; + std::cout << std::endl + << "Optimization: " << opt.first << std::endl; } } - } // Add optional transforms to create a full-featured, "canonical" display pipeline // Fstop exposure control (in SCENE_LINEAR) { double gain = powf(2.0f, g_exposure_fstop); - const double slope4f[] = { gain, gain, gain, gain }; + const double slope4f[] = {gain, gain, gain, gain}; double m44[16]; double offset4[4]; OCIO::MatrixTransform::Scale(m44, offset4, slope4f); - OCIO::MatrixTransformRcPtr mtx = OCIO::MatrixTransform::Create(); + OCIO::MatrixTransformRcPtr mtx = OCIO::MatrixTransform::Create(); mtx->setMatrix(m44); mtx->setOffset(offset4); vp->setLinearCC(mtx); @@ -365,9 +378,9 @@ void UpdateOCIOGLState() // Post-display transform gamma { - double exponent = 1.0/std::max(1e-6, static_cast(g_display_gamma)); - const double exponent4f[4] = { exponent, exponent, exponent, exponent }; - OCIO::ExponentTransformRcPtr expTransform = OCIO::ExponentTransform::Create(); + double exponent = 1.0 / std::max(1e-6, static_cast(g_display_gamma)); + const double exponent4f[4] = {exponent, exponent, exponent, exponent}; + OCIO::ExponentTransformRcPtr expTransform = OCIO::ExponentTransform::Create(); expTransform->setValue(exponent4f); vp->setDisplayCC(expTransform); } @@ -377,7 +390,7 @@ void UpdateOCIOGLState() { processor = vp->getProcessor(config, config->getCurrentContext()); } - catch (const OCIO::Exception & e) + catch (const OCIO::Exception &e) { std::cerr << e.what() << std::endl; return; @@ -391,17 +404,15 @@ void UpdateOCIOGLState() OCIO::GpuShaderDescRcPtr shaderDesc = OCIO::GpuShaderDesc::CreateShaderDesc(); shaderDesc->setLanguage( #if __APPLE__ - g_useMetal ? - OCIO::GPU_LANGUAGE_MSL_2_0 : + g_useMetal ? OCIO::GPU_LANGUAGE_MSL_2_0 : #endif - OCIO::GPU_LANGUAGE_GLSL_1_2); + OCIO::GPU_LANGUAGE_GLSL_1_2); shaderDesc->setFunctionName("OCIODisplay"); shaderDesc->setResourcePrefix("ocio_"); // Extract the shader information. - OCIO::ConstGPUProcessorRcPtr gpu - = g_gpulegacy ? processor->getOptimizedLegacyGPUProcessor(g_optimization, 32) - : processor->getOptimizedGPUProcessor(g_optimization); + OCIO::ConstGPUProcessorRcPtr gpu = g_gpulegacy ? processor->getOptimizedLegacyGPUProcessor(g_optimization, 32) + : processor->getOptimizedGPUProcessor(g_optimization); gpu->extractGpuShaderInfo(shaderDesc); g_oglApp->setShader(shaderDesc); @@ -446,6 +457,7 @@ void displayDevice_CB(int id) g_look = config->getDisplayViewLooks(g_display.c_str(), g_transformName.c_str()); + updateViewsMenu(display); UpdateOCIOGLState(); glutPostRedisplay(); } @@ -499,7 +511,7 @@ static void PopulateOCIOMenus() int csMenuID = glutCreateMenu(imageColorSpace_CB); std::map families; - for (int i=0; igetNumColorSpaces(); ++i) + for (int i = 0; i < config->getNumColorSpaces(); ++i) { const char * csName = config->getColorSpaceNameByIndex(i); if (csName && *csName) @@ -510,7 +522,7 @@ static void PopulateOCIOMenus() const char * family = cs->getFamily(); if (family && *family) { - if (families.find(family)==families.end()) + if (families.find(family) == families.end()) { families[family] = glutCreateMenu(imageColorSpace_CB); glutAddMenuEntry(csName, i); @@ -533,35 +545,32 @@ static void PopulateOCIOMenus() } } - int deviceMenuID = glutCreateMenu(displayDevice_CB); - for (int i=0; igetNumDisplays(); ++i) + int displayMenuID = glutCreateMenu(displayDevice_CB); + for (int i = 0; i < config->getNumDisplays(); ++i) { glutAddMenuEntry(config->getDisplay(i), i); } - int transformMenuID = glutCreateMenu(transform_CB); + g_viewsMenuID = glutCreateMenu(transform_CB); const char * defaultDisplay = config->getDefaultDisplay(); - for (int i=0; igetNumViews(defaultDisplay); ++i) - { - glutAddMenuEntry(config->getView(defaultDisplay, i), i); - } + updateViewsMenu(defaultDisplay); int lookMenuID = glutCreateMenu(look_CB); - for (int i=0; igetNumLooks(); ++i) + for (int i = 0; i < config->getNumLooks(); ++i) { glutAddMenuEntry(config->getLookNameByIndex(i), i); } int optimizationMenuID = glutCreateMenu(optimization_CB); - for (size_t i = 0; i(i)); } glutCreateMenu(menuCallback); glutAddSubMenu("Image ColorSpace", csMenuID); - glutAddSubMenu("Transform", transformMenuID); - glutAddSubMenu("Device", deviceMenuID); + glutAddSubMenu("Views", g_viewsMenuID); + glutAddSubMenu("Display", displayMenuID); glutAddSubMenu("Looks Override", lookMenuID); glutAddSubMenu("Optimization", optimizationMenuID); @@ -569,49 +578,49 @@ static void PopulateOCIOMenus() } const char * USAGE_TEXT = "\n" -"Keys:\n" -"\tCtrl+Up: Exposure +1/4 stop (in scene linear)\n" -"\tCtrl+Down: Exposure -1/4 stop (in scene linear)\n" -"\tCtrl+Home: Reset Exposure + Gamma\n" -"\n" -"\tAlt+Up: Gamma up (post display transform)\n" -"\tAlt+Down: Gamma down (post display transform)\n" -"\tAlt+Home: Reset Exposure + Gamma\n" -"\n" -"\tC: View Color\n" -"\tR: View Red\n" -"\tG: View Green\n" -"\tB: View Blue\n" -"\tA: View Alpha\n" -"\tL: View Luma\n" -"\n" -"\tRight-Mouse Button: Configure Display / Transform / ColorSpace / Looks / Optimization\n" -"\n" -"\tEsc: Quit\n"; + "Keys:\n" + "\tCtrl+Up: Exposure +1/4 stop (in scene linear)\n" + "\tCtrl+Down: Exposure -1/4 stop (in scene linear)\n" + "\tCtrl+Home: Reset Exposure + Gamma\n" + "\n" + "\tAlt+Up: Gamma up (post display transform)\n" + "\tAlt+Down: Gamma down (post display transform)\n" + "\tAlt+Home: Reset Exposure + Gamma\n" + "\n" + "\tC: View Color\n" + "\tR: View Red\n" + "\tG: View Green\n" + "\tB: View Blue\n" + "\tA: View Alpha\n" + "\tL: View Luma\n" + "\n" + "\tRight-Mouse Button: Configure Display / Transform / ColorSpace / Looks / Optimization\n" + "\n" + "\tEsc: Quit\n"; void parseArguments(int argc, char **argv) { - for (int i=1; i("ociodisplay", 512, 512); } } - catch (const OCIO::Exception & e) + catch (const OCIO::Exception &e) { std::cerr << e.what() << std::endl; return 1; @@ -703,8 +712,8 @@ int main(int argc, char **argv) { std::cout << std::endl; std::cout << "OCIO Config. file : '" << env << "'" << std::endl; - std::cout << "OCIO Config. version: " << config->getMajorVersion() << "." - << config->getMinorVersion() << std::endl; + std::cout << "OCIO Config. version: " << config->getMajorVersion() << "." + << config->getMinorVersion() << std::endl; std::cout << "OCIO search_path : " << config->getSearchPath() << std::endl; } } @@ -717,7 +726,7 @@ int main(int argc, char **argv) { InitOCIO(g_filename.c_str()); } - catch(OCIO::Exception & e) + catch (OCIO::Exception &e) { std::cerr << e.what() << std::endl; exit(1); @@ -729,7 +738,7 @@ int main(int argc, char **argv) { UpdateOCIOGLState(); } - catch (const OCIO::Exception & e) + catch (const OCIO::Exception &e) { std::cerr << e.what() << std::endl; exit(1);