void ocio_colorspace_combo_t::set_default() { OCIO::ConstConfigRcPtr config = app().ocio_manager().config(); std::string default_cs_name = config->getColorSpace( OCIO::ROLE_SCENE_LINEAR)->getName(); int index = 0; int num_color_spaces = config->getNumColorSpaces(); for(int i = 0; i < num_color_spaces; i++) { if( config->getColorSpaceNameByIndex( i) == default_cs_name) index = i; } setCurrentIndex( index); current_colorspace_ = default_cs_name; }
void KisOcioDisplayFilterTest::test() { KisExposureGammaCorrectionInterface *egInterface = new KisDumbExposureGammaCorrectionInterface(); OcioDisplayFilter filter(egInterface); QString configFile = TestUtil::fetchDataFileLazy("./psyfiTestingConfig-master/config.ocio"); dbgKrita << ppVar(configFile); Q_ASSERT(QFile::exists(configFile)); OCIO::ConstConfigRcPtr ocioConfig = OCIO::Config::CreateFromFile(configFile.toUtf8()); filter.config = ocioConfig; filter.inputColorSpaceName = ocioConfig->getColorSpaceNameByIndex(0); filter.displayDevice = ocioConfig->getDisplay(1); filter.view = ocioConfig->getView(filter.displayDevice, 0); filter.gamma = 1.0; filter.exposure = 0.0; filter.swizzle = RGBA; filter.blackPoint = 0.0; filter.whitePoint = 1.0; filter.forceInternalColorManagement = false; filter.setLockCurrentColorVisualRepresentation(false); filter.updateProcessor(); dbgKrita << ppVar(filter.inputColorSpaceName); dbgKrita << ppVar(filter.displayDevice); dbgKrita << ppVar(filter.view); dbgKrita << ppVar(filter.gamma); dbgKrita << ppVar(filter.exposure); const KoColorSpace *paintingCS = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(), Float32BitsColorDepthID.id(), 0); KisImageSP image = utils::createImage(0, QSize(100, 100)); image->convertImageColorSpace(paintingCS, KoColorConversionTransformation::InternalRenderingIntent, KoColorConversionTransformation::InternalConversionFlags); image->waitForDone(); dbgKrita << ppVar(paintingCS) << ppVar(image->root()->firstChild()->colorSpace()); KoCanvasResourceManager *resourceManager = utils::createResourceManager(image, image->root(), ""); KisDisplayColorConverter converter(resourceManager, 0); dbgKrita << ppVar(image->root()->firstChild()); QVariant v; v.setValue(KisNodeWSP(image->root()->firstChild())); resourceManager->setResource(KisCanvasResourceProvider::CurrentKritaNode, v); converter.setDisplayFilter(&filter); dbgKrita << ppVar(converter.paintingColorSpace()); { QColor refColor(255, 128, 0); KoColor realColor = converter.approximateFromRenderedQColor(refColor); QColor roundTripColor = converter.toQColor(realColor); dbgKrita << ppVar(refColor); dbgKrita << ppVar(realColor.colorSpace()) << ppVar(KoColor::toQString(realColor)); dbgKrita << ppVar(roundTripColor); } { KoColor realColor(Qt::red, paintingCS); QColor roundTripColor = converter.toQColor(realColor); dbgKrita << ppVar(realColor.colorSpace()) << ppVar(KoColor::toQString(realColor)); dbgKrita << ppVar(roundTripColor); } }
bool ColorSpacePopUpMenu(OCIO::ConstConfigRcPtr config, std::string &colorSpace, bool selectRoles, const void *hwnd) { HMENU menu = CreatePopupMenu(); for(int i=0; i < config->getNumColorSpaces(); ++i) { const char *colorSpaceName = config->getColorSpaceNameByIndex(i); OCIO::ConstColorSpaceRcPtr colorSpacePtr = config->getColorSpace(colorSpaceName); const char *family = colorSpacePtr->getFamily(); std::string colorSpacePath; if(family == NULL) { colorSpacePath = colorSpaceName; } else { colorSpacePath = std::string(family) + "/" + colorSpaceName; } std::vector<std::string> pathComponents; tokenize(pathComponents, colorSpacePath, "/"); HMENU currentMenu = menu; for(int j=0; j < pathComponents.size(); j++) { const std::string &componentName = pathComponents[j]; if(j == (pathComponents.size() - 1)) { UINT flags = MF_STRING; if(componentName == colorSpace) flags |= MF_CHECKED; const BOOL inserted = AppendMenu(currentMenu, flags, i + 1, componentName.c_str()); assert(inserted); } else { int componentMenuPos = -1; for(int k=0; k < GetMenuItemCount(currentMenu) && componentMenuPos < 0; k++) { CHAR buf[256]; const int strLen = GetMenuString(currentMenu, k, buf, 255, MF_BYPOSITION); assert(strLen > 0); if(componentName == buf) componentMenuPos = k; } if(componentMenuPos < 0) { HMENU subMenu = CreateMenu(); const BOOL inserted = AppendMenu(currentMenu, MF_STRING | MF_POPUP, (UINT_PTR)subMenu, componentName.c_str()); assert(inserted); componentMenuPos = (GetMenuItemCount(currentMenu) - 1); } currentMenu = GetSubMenu(currentMenu, componentMenuPos); } } } if(config->getNumRoles() > 0) { HMENU rolesMenu = CreatePopupMenu(); const BOOL rolesInserted = InsertMenu(menu, 0, MF_STRING | MF_BYPOSITION | MF_POPUP, (UINT_PTR)rolesMenu, "Roles"); assert(rolesInserted); for(int i=0; i < config->getNumRoles(); i++) { const std::string roleName = config->getRoleName(i); OCIO::ConstColorSpaceRcPtr colorSpacePtr = config->getColorSpace(roleName.c_str()); const std::string colorSpaceName = colorSpacePtr->getName(); int colorSpaceIndex = -1; for(int k=0; k < config->getNumColorSpaces() && colorSpaceIndex < 0; k++) { const std::string colorSpaceName2 = config->getColorSpaceNameByIndex(k); if(colorSpaceName2 == colorSpaceName) colorSpaceIndex = k; } HMENU roleSubmenu = CreatePopupMenu(); UINT roleFlags = MF_STRING | MF_POPUP; if(selectRoles && roleName == colorSpace) roleFlags |= MF_CHECKED; const BOOL roleInserted = AppendMenu(rolesMenu, roleFlags, (UINT_PTR)roleSubmenu, roleName.c_str()); assert(roleInserted); UINT colorSpaceFlags = MF_STRING; if(colorSpaceName == colorSpace) colorSpaceFlags |= MF_CHECKED; const BOOL colorSpaceInsterted = AppendMenu(roleSubmenu, colorSpaceFlags, colorSpaceIndex + 1, colorSpaceName.c_str()); assert(colorSpaceInsterted); } const BOOL dividerInserted = InsertMenu(menu, 1, MF_STRING | MF_BYPOSITION | MF_SEPARATOR, 0, "Sep"); assert(dividerInserted); } POINT pos; GetCursorPos(&pos); int result = TrackPopupMenuEx(menu, (TPM_NONOTIFY | TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD), pos.x, pos.y, (HWND)hwnd, NULL); DestroyMenu(menu); if(result > 0) { colorSpace = config->getColorSpaceNameByIndex(result - 1); return true; } else return false; }