Ejemplo n.º 1
0
OCIO::ConstContextRcPtr manager_t::get_context( const context_t *ctx) const
{
	OCIO::ConstConfigRcPtr cfg = config();
	OCIO::ConstContextRcPtr context = cfg->getCurrentContext();

	if( !ctx)
		return context;

    OCIO::ContextRcPtr mutable_context;

	for( int i = 0; i < ctx->size(); ++i)
	{
		std::pair<std::string, std::string> ctx_pair = (*ctx)[i];

	    if( !ctx_pair.first.empty())
		{
	        if( !mutable_context)
				mutable_context = context->createEditableCopy();

			mutable_context->setStringVar( ctx_pair.first.c_str(), ctx_pair.second.c_str());
	    }
	}

    if( mutable_context)
		return mutable_context;

	return context;
}
Ejemplo n.º 2
0
flipbook_t::flipbook_t( int frame_rate, const std::string& display_device, const std::string& display_transform)
{
    frame_rate_ = frame_rate;
    aspect_ = 1.0f;

    display_device_ = display_device;
    display_transform_ = display_transform;

    try
    {
        OCIO::ConstConfigRcPtr config = app().ocio_manager().config();
        OCIO::ConstContextRcPtr context = get_local_context();
        transform_ = OCIO::DisplayTransform::Create();
        transform_->setInputColorSpaceName( OCIO::ROLE_SCENE_LINEAR);
        transform_->setDisplay( display_device.c_str());
        transform_->setView( display_transform.c_str());
        processor_ = config->getProcessor( context, transform_, OCIO::TRANSFORM_DIR_FORWARD);
        apply_display_transform_ = true;
    }
    catch( OCIO::Exception& e)
    {
        app().ui()->error( e.what());
        apply_display_transform_ = false;
    }
}
Ejemplo n.º 3
0
OCIO::ConstContextRcPtr ocio_colorspace_node_t::get_local_context()
{
	OCIO::ConstConfigRcPtr config = app().ocio_manager().config();
	OCIO::ConstContextRcPtr context = config->getCurrentContext();
	
    OCIO::ContextRcPtr mutable_context;
	
	std::string key = get_value<std::string>( param( "key1"));
	
    if( !key.empty())
    {
        if( !mutable_context)
			mutable_context = context->createEditableCopy();

		std::string value = get_value<std::string>( param( "value1"));
        mutable_context->setStringVar( key.c_str(), value.c_str());		
    }
	
	key = get_value<std::string>( param( "key2"));
	
    if( !key.empty())
	{
		if( !mutable_context)
			mutable_context = context->createEditableCopy();
		
		std::string value = get_value<std::string>( param( "value2"));
        mutable_context->setStringVar( key.c_str(), value.c_str());		
    }

	key = get_value<std::string>( param( "key3"));
	
    if( !key.empty())
    {
		if( !mutable_context)
			mutable_context = context->createEditableCopy();
		
		std::string value = get_value<std::string>( param( "value3"));
        mutable_context->setStringVar( key.c_str(), value.c_str());		
    }
	
	key = get_value<std::string>( param( "key4"));
	
    if( !key.empty())		
    {
        if(!mutable_context)
			mutable_context = context->createEditableCopy();

		std::string value = get_value<std::string>( param( "value4"));
        mutable_context->setStringVar( key.c_str(), value.c_str());
    }
	
    if( mutable_context)
		context = mutable_context;
	
	return context;
}
Ejemplo n.º 4
0
OCIO::ConstContextRcPtr flipbook_t::get_local_context()
{
    OCIO::ConstConfigRcPtr config = app().ocio_manager().config();
    OCIO::ConstContextRcPtr context = config->getCurrentContext();

    OCIO::ContextRcPtr mutable_context;

    std::pair<std::string, std::string> ctx_pair;

    ctx_pair = app().document().composition().ocio_context_pairs()[0];

    if( !ctx_pair.first.empty())
    {
        if( !mutable_context)
            mutable_context = context->createEditableCopy();

        mutable_context->setStringVar( ctx_pair.first.c_str(), ctx_pair.second.c_str());
    }

    ctx_pair = app().document().composition().ocio_context_pairs()[1];

    if( !ctx_pair.first.empty())
    {
        if( !mutable_context)
            mutable_context = context->createEditableCopy();

        mutable_context->setStringVar( ctx_pair.first.c_str(), ctx_pair.second.c_str());
    }

    ctx_pair = app().document().composition().ocio_context_pairs()[2];

    if( !ctx_pair.first.empty())
    {
        if( !mutable_context)
            mutable_context = context->createEditableCopy();

        mutable_context->setStringVar( ctx_pair.first.c_str(), ctx_pair.second.c_str());
    }

    ctx_pair = app().document().composition().ocio_context_pairs()[3];

    if( !ctx_pair.first.empty())
    {
        if(!mutable_context)
            mutable_context = context->createEditableCopy();

        mutable_context->setStringVar( ctx_pair.first.c_str(), ctx_pair.second.c_str());
    }

    if( mutable_context)
        context = mutable_context;

    return context;
}
Ejemplo n.º 5
0
void manager_t::get_displays()
{
	OCIO::ConstConfigRcPtr cfg = config();
    default_display_ = cfg->getDefaultDisplay();
    int num_device_names = cfg->getNumDisplays();

    for(int i = 0; i < num_device_names; i++)
    {
        std::string dispname = cfg->getDisplay( i);
        displays_.push_back( dispname);

        if( default_display_ == dispname)
            default_display_index_ = i;
    }
}
Ejemplo n.º 6
0
void ocio_colorspace_node_t::do_calc_hash_str( const render::context_t& context)
{
	pointop_node_t::do_calc_hash_str( context);
	
	try
	{
	    OCIO::ConstConfigRcPtr config = app().ocio_manager().config();
		OCIO::ConstContextRcPtr context = get_local_context();
		hash_generator() << config->getCacheID( context);
	}
	catch( OCIO::Exception &e)
	{
		hash_generator() << "error";
	}
}
Ejemplo n.º 7
0
void manager_t::get_views( const std::string& display, std::vector<std::string>& views, int& default_index) const
{
    OCIO::ConstConfigRcPtr cfg = config();
    int num_views = cfg->getNumViews( display.c_str());
    std::string default_view = cfg->getDefaultView( display.c_str());
	default_index = 0;
	views.clear();

    for( int i = 0; i < num_views; ++i)
    {
        std::string vname = cfg->getView( display.c_str(), i);
        views.push_back( vname);

        if( default_view == vname)
            default_index = i;
    }
}
Ejemplo n.º 8
0
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;
}
Ejemplo n.º 9
0
void ocio_colorspace_node_t::do_process( const image::const_image_view_t& src, const image::image_view_t& dst, const render::context_t& context)
{
    boost::gil::copy_pixels( src, dst);

	std::string in_cs = get_value<std::string>( param( "in_colorspace"));
	std::string out_cs = get_value<std::string>( param( "out_colorspace"));

	try
	{
	    OCIO::ConstConfigRcPtr config = app().ocio_manager().config();
		OCIO::ConstContextRcPtr context = get_local_context();
	    OCIO::ConstProcessorRcPtr proc = config->getProcessor( context, in_cs.c_str(), out_cs.c_str());
		image::ocio_transform( dst, proc);
	}
	catch( OCIO::Exception& exception)
	{
		#ifndef NDEBUG
			std::cout << "Exception while converting colorspaces: in = " << in_cs << ", out = " << out_cs << "\n";
		#endif
	}
}
Ejemplo n.º 10
0
void viewer_t::change_display_device( int index)
{
    display_device_ = display_devices_[index];

    // refresh the list of transforms
    ocio_transform_combo_->blockSignals( true);
    ocio_transform_combo_->clear();

    OCIO::ConstConfigRcPtr config = app().ocio_manager().config();

    std::string default_transform = config->getDefaultView( display_device_.c_str());
    int num_transform_names = config->getNumViews( display_device_.c_str());

    int default_index = 0, new_index = -1;
    QStringList slist;

    for( int i = 0; i < num_transform_names; ++i)
    {
        std::string trname = config->getView( display_device_.c_str(), i);
        display_transforms_.push_back( trname);
        slist << trname.c_str();

        if( display_transform_ == trname)
            new_index = i;

        if( default_transform == trname)
            default_index = i;
    }

    ocio_transform_combo_->addItems( slist);

    if( new_index < 0)
        new_index = default_index;

    ocio_transform_combo_->setCurrentIndex( new_index);
    display_transform_ = ocio_transform_combo_->itemText( new_index).toStdString();
    ocio_transform_combo_->blockSignals( false);
	view_->display_transform_changed();
}
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);
    }

}
Ejemplo n.º 12
0
OCIO::ConstConfigRcPtr manager_t::config() const
{
	OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
	config->sanityCheck();
	return config;
}
Ejemplo n.º 13
0
std::string manager_t::default_view( const std::string& display) const
{
    OCIO::ConstConfigRcPtr cfg = config();
	return cfg->getDefaultView( display.c_str());
}
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;
}