Пример #1
0
void Unpremultiply::processChannelData( const Gaffer::Context *context, const ImagePlug *parent, const std::string &channel, FloatVectorDataPtr outData ) const
{
	std::string alphaChannel = alphaChannelPlug()->getValue();

	if ( channel == alphaChannel )
	{
		return;
	}

	ConstStringVectorDataPtr inChannelNamesPtr = inPlug()->channelNamesPlug()->getValue();
	const std::vector<std::string> &inChannelNames = inChannelNamesPtr->readable();
	if ( std::find( inChannelNames.begin(), inChannelNames.end(), alphaChannel ) == inChannelNames.end() )
	{
		std::ostringstream channelError;
		channelError << "Channel '" << alphaChannel << "' does not exist";
		throw( IECore::Exception( channelError.str() ) );
	}

	ContextPtr tmpContext = new Context( *context, Context::Borrowed );
	tmpContext->set( ImagePlug::channelNameContextName, alphaChannel );
	Context::Scope scopedContext( tmpContext.get() );

	const std::vector<float> &a = inPlug()->channelDataPlug()->getValue()->readable();
	std::vector<float> &out = outData->writable();

	std::vector<float>::const_iterator aIt = a.begin();
	for ( std::vector<float>::iterator outIt = out.begin(), outItEnd = out.end(); outIt != outItEnd; ++outIt, ++aIt )
	{
		if ( *aIt != 0.0f )
		{
			*outIt /= *aIt;
		}
	}
}
Пример #2
0
void Unpremultiply::affects( const Gaffer::Plug *input, AffectedPlugsContainer &outputs ) const
{
	ChannelDataProcessor::affects( input, outputs );

	if( input == inPlug()->channelDataPlug() ||
	    input == alphaChannelPlug() )
	{
		outputs.push_back( outPlug()->channelDataPlug() );
	}
}
Пример #3
0
void Unpremultiply::hashChannelData( const GafferImage::ImagePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const
{
	std::string alphaChannel = alphaChannelPlug()->getValue();

	ChannelDataProcessor::hashChannelData( output, context, h );

	inPlug()->channelDataPlug()->hash( h );

	ImagePlug::ChannelDataScope channelDataScope( context );
	channelDataScope.setChannelName( alphaChannel );

	inPlug()->channelDataPlug()->hash( h );
}
Пример #4
0
void Unpremultiply::hashChannelData( const GafferImage::ImagePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const
{
	std::string alphaChannel = alphaChannelPlug()->getValue();

	ChannelDataProcessor::hashChannelData( output, context, h );

	inPlug()->channelDataPlug()->hash( h );

	ContextPtr tmpContext = new Context( *context, Context::Borrowed );
	tmpContext->set( ImagePlug::channelNameContextName, alphaChannel );
	Context::Scope scopedContext( tmpContext.get() );

	inPlug()->channelDataPlug()->hash( h );
}
Пример #5
0
void Premultiply::processChannelData( const Gaffer::Context *context, const ImagePlug *parent, const std::string &channel, FloatVectorDataPtr outData ) const
{
	std::string alphaChannel = alphaChannelPlug()->getValue();

	if ( channel == alphaChannel )
	{
		return;
	}

	ConstStringVectorDataPtr inChannelNamesPtr;
	{
		ImagePlug::GlobalScope c( context );
		inChannelNamesPtr = inPlug()->channelNamesPlug()->getValue();
	}

	const std::vector<std::string> &inChannelNames = inChannelNamesPtr->readable();
	if ( std::find( inChannelNames.begin(), inChannelNames.end(), alphaChannel ) == inChannelNames.end() )
	{
		std::ostringstream channelError;
		channelError << "Channel '" << alphaChannel << "' does not exist";
		throw( IECore::Exception( channelError.str() ) );
	}

	ImagePlug::ChannelDataScope channelDataScope( context );
	channelDataScope.setChannelName( alphaChannel );

	ConstFloatVectorDataPtr aData = inPlug()->channelDataPlug()->getValue();
	const std::vector<float> &a = aData->readable();
	std::vector<float> &out = outData->writable();

	std::vector<float>::const_iterator aIt = a.begin();
	for ( std::vector<float>::iterator outIt = out.begin(), outItEnd = out.end(); outIt != outItEnd; ++outIt, ++aIt )
	{
		*outIt *= *aIt;
	}
}