Exemple #1
0
bool LibAVParams::setOption( const std::string& libAVOptionName, const std::string& value, const std::string& detailedName )
{
	try
	{
		// Get libav option
		avtranscoder::Option& option = getLibAVOption( libAVOptionName, detailedName );

		// Set libav option's value
		option.setString( value );

		// Get corresponding OFX parameter
		OFX::ValueParam* param = getOFXParameter( libAVOptionName, detailedName );
		if( ! param)
		{
			TUTTLE_LOG_WARNING( "Can't get OFX parameter corresponding to option " << libAVOptionName << " of subgroup " << detailedName );
			return false;
		}

		// Set OFX parameter's value
		OFX::BooleanParam* paramBoolean = dynamic_cast<OFX::BooleanParam*>( param );
		if( paramBoolean )
		{
			paramBoolean->setValue( option.getBool() );
			return true;
		}
		OFX::IntParam* paramInt = dynamic_cast<OFX::IntParam*>( param );
		if( paramInt )
		{
			paramInt->setValue( option.getInt() );
			return true;
		}
		OFX::DoubleParam* paramDouble = dynamic_cast<OFX::DoubleParam*>( param );
		if( paramDouble )
		{
			paramDouble->setValue( option.getDouble() );
			return true;
		}
		OFX::StringParam* paramString = dynamic_cast<OFX::StringParam*>( param );
		if( paramString )
		{
			paramString->setValue( option.getString() );
			return true;
		}
		OFX::Int2DParam* paramRatio = dynamic_cast<OFX::Int2DParam*>( param );
		if( paramRatio )
		{
			paramRatio->setValue( option.getRatio().first, option.getRatio().second );
			return true;
		}
		OFX::ChoiceParam* paramChoice = dynamic_cast<OFX::ChoiceParam*>( param );
		if( paramChoice )
		{
			paramChoice->setValue( option.getInt() );
			return true;
		}
	}
	catch( std::exception& e )
	{
		TUTTLE_LOG_WARNING( "Can't set option " << libAVOptionName << " to " << value << ": " << e.what() );
		return false;
	}
}
void CropPlugin::changedParam( const OFX::InstanceChangedArgs& args, const std::string& paramName )
{
	if( paramName == kCropHelpButton )
	{
		sendMessage( OFX::Message::eMessageMessage,
		             "", // No XML resources
		             kCropHelpString );
	}
	else if( paramName == kParamPresets )
	{
		// Compute bands sizes in pixels
		int f, bandSize;
		double ratio;
		_paramFormats->getValue( f );
		OFX::IntParam* upBand    = fetchIntParam( kParamUp );
		OFX::IntParam* downBand  = fetchIntParam( kParamDown );
		OFX::IntParam* leftBand  = fetchIntParam( kParamLeft );
		OFX::IntParam* rightBand = fetchIntParam( kParamRight );
		OfxRectD rod             = _clipSrc->getCanonicalRod( timeLineGetTime() );
		double par               = _clipSrc->getPixelAspectRatio();
		int w                    = (int)std::abs( rod.x2 - rod.x1 );
		int h                    = (int)std::abs( rod.y2 - rod.y1 );

		switch( f )
		{
			// 4/3
			case k1_1_33:
				ratio = 4.0 / 3.0;
				break;
			// 16 / 9
			case k1_1_77:
				ratio = 16.0 / 9.0;
				break;
			// 1:1.85
			case k1_1_85:
				ratio = 1.85;
				break;
			// Cinemascope
			case k1_2_35:
				ratio = 2.35;
				break;
			case k1_2_40:
				ratio = 2.40;
				break;
			default:
				ratio = 0;
				break;
		}

		// If image ratio is lesser than the specified ratio, we need to add left and right bands
		if( ( (double)( w ) / h ) > ratio )
		{
			bandSize = (int)round( ( w - ( h / ( 1.0 / ratio ) ) ) / 2.0 );
			upBand->setValue( 0 );
			downBand->setValue( 0 );
			leftBand->setValue( (int)round( bandSize / par ) );
			rightBand->setValue( (int)round( bandSize / par ) );
		}
		else if( ( (double)( w )  / h ) < ratio )
		{
			// Add top and bottom bands
			bandSize = (int)round( ( h - ( ( w ) / ratio ) ) / 2.0 );
			upBand->setValue( bandSize );
			downBand->setValue( bandSize );
			leftBand->setValue( 0 );
			rightBand->setValue( 0 );
		}
		else
		{
			upBand->setValue( 0 );
			downBand->setValue( 0 );
			leftBand->setValue( 0 );
			rightBand->setValue( 0 );
		}
	}
}