Esempio n. 1
0
void ColorMatteNode::convertToOperations(NodeConverter &converter, const CompositorContext &/*context*/) const
{
    bNode *editorsnode = getbNode();

    NodeInput *inputSocketImage = this->getInputSocket(0);
    NodeInput *inputSocketKey = this->getInputSocket(1);
    NodeOutput *outputSocketImage = this->getOutputSocket(0);
    NodeOutput *outputSocketMatte = this->getOutputSocket(1);

    ConvertRGBToHSVOperation *operationRGBToHSV_Image = new ConvertRGBToHSVOperation();
    ConvertRGBToHSVOperation *operationRGBToHSV_Key = new ConvertRGBToHSVOperation();
    converter.addOperation(operationRGBToHSV_Image);
    converter.addOperation(operationRGBToHSV_Key);

    ColorMatteOperation *operation = new ColorMatteOperation();
    operation->setSettings((NodeDiamond *)editorsnode->storage);
    converter.addOperation(operation);

    SetAlphaOperation *operationAlpha = new SetAlphaOperation();
    converter.addOperation(operationAlpha);

    converter.mapInputSocket(inputSocketImage, operationRGBToHSV_Image->getInputSocket(0));
    converter.mapInputSocket(inputSocketKey, operationRGBToHSV_Key->getInputSocket(0));
    converter.addLink(operationRGBToHSV_Image->getOutputSocket(), operation->getInputSocket(0));
    converter.addLink(operationRGBToHSV_Key->getOutputSocket(), operation->getInputSocket(1));
    converter.mapOutputSocket(outputSocketMatte, operation->getOutputSocket(0));

    converter.mapInputSocket(inputSocketImage, operationAlpha->getInputSocket(0));
    converter.addLink(operation->getOutputSocket(), operationAlpha->getInputSocket(1));
    converter.mapOutputSocket(outputSocketImage, operationAlpha->getOutputSocket());

    converter.addPreview(operationAlpha->getOutputSocket());
}
void DifferenceMatteNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const
{
	NodeInput *inputSocket = this->getInputSocket(0);
	NodeInput *inputSocket2 = this->getInputSocket(1);
	NodeOutput *outputSocketImage = this->getOutputSocket(0);
	NodeOutput *outputSocketMatte = this->getOutputSocket(1);
	bNode *editorNode = this->getbNode();

	DifferenceMatteOperation *operationSet = new DifferenceMatteOperation();
	operationSet->setSettings((NodeChroma *)editorNode->storage);
	converter.addOperation(operationSet);
	
	converter.mapInputSocket(inputSocket, operationSet->getInputSocket(0));
	converter.mapInputSocket(inputSocket2, operationSet->getInputSocket(1));
	converter.mapOutputSocket(outputSocketMatte, operationSet->getOutputSocket(0));

	SetAlphaOperation *operation = new SetAlphaOperation();
	converter.addOperation(operation);
	
	converter.mapInputSocket(inputSocket, operation->getInputSocket(0));
	converter.addLink(operationSet->getOutputSocket(), operation->getInputSocket(1));
	converter.mapOutputSocket(outputSocketImage, operation->getOutputSocket());
	
	converter.addPreview(operation->getOutputSocket());
}
void DistanceMatteNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
{
	InputSocket *inputSocketImage = this->getInputSocket(0);
	InputSocket *inputSocketKey = this->getInputSocket(1);
	OutputSocket *outputSocketImage = this->getOutputSocket(0);
	OutputSocket *outputSocketMatte = this->getOutputSocket(1);

	DistanceMatteOperation *operation = new DistanceMatteOperation();
	bNode *editorsnode = getbNode();
	operation->setSettings((NodeChroma *)editorsnode->storage);

	inputSocketImage->relinkConnections(operation->getInputSocket(0), 0, graph);
	inputSocketKey->relinkConnections(operation->getInputSocket(1), 1, graph);

	if (outputSocketMatte->isConnected()) {
		outputSocketMatte->relinkConnections(operation->getOutputSocket());
	}

	graph->addOperation(operation);

	SetAlphaOperation *operationAlpha = new SetAlphaOperation();
	addLink(graph, operation->getInputSocket(0)->getConnection()->getFromSocket(), operationAlpha->getInputSocket(0));
	addLink(graph, operation->getOutputSocket(), operationAlpha->getInputSocket(1));

	graph->addOperation(operationAlpha);
	addPreviewOperation(graph, operationAlpha->getOutputSocket());

	if (outputSocketImage->isConnected()) {
		outputSocketImage->relinkConnections(operationAlpha->getOutputSocket());
	}
}
void DistanceMatteNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
{
	InputSocket *inputSocketImage = this->getInputSocket(0);
	InputSocket *inputSocketKey = this->getInputSocket(1);
	OutputSocket *outputSocketImage = this->getOutputSocket(0);
	OutputSocket *outputSocketMatte = this->getOutputSocket(1);

	NodeOperation *operation;
	bNode *editorsnode = getbNode();
	NodeChroma *storage = (NodeChroma *)editorsnode->storage;

	/* work in RGB color space */
	if (storage->channel == 1) {
		operation = new DistanceRGBMatteOperation();
		((DistanceRGBMatteOperation *) operation)->setSettings(storage);

		inputSocketImage->relinkConnections(operation->getInputSocket(0), 0, graph);
		inputSocketKey->relinkConnections(operation->getInputSocket(1), 1, graph);
	}
	/* work in YCbCr color space */
	else {
		operation = new DistanceYCCMatteOperation();
		((DistanceYCCMatteOperation *) operation)->setSettings(storage);

		ConvertRGBToYCCOperation *operationYCCImage = new ConvertRGBToYCCOperation();
		inputSocketImage->relinkConnections(operationYCCImage->getInputSocket(0), 0, graph);
		addLink(graph, operationYCCImage->getOutputSocket(), operation->getInputSocket(0));
		graph->addOperation(operationYCCImage);

		ConvertRGBToYCCOperation *operationYCCMatte = new ConvertRGBToYCCOperation();
		inputSocketKey->relinkConnections(operationYCCMatte->getInputSocket(0), 1, graph);
		addLink(graph, operationYCCMatte->getOutputSocket(), operation->getInputSocket(1));
		graph->addOperation(operationYCCMatte);
	}

	if (outputSocketMatte->isConnected()) {
		outputSocketMatte->relinkConnections(operation->getOutputSocket());
	}

	graph->addOperation(operation);

	SetAlphaOperation *operationAlpha = new SetAlphaOperation();
	addLink(graph, operation->getInputSocket(0)->getConnection()->getFromSocket(), operationAlpha->getInputSocket(0));
	addLink(graph, operation->getOutputSocket(), operationAlpha->getInputSocket(1));

	graph->addOperation(operationAlpha);
	addPreviewOperation(graph, context, operationAlpha->getOutputSocket());

	if (outputSocketImage->isConnected()) {
		outputSocketImage->relinkConnections(operationAlpha->getOutputSocket());
	}
}
void SetAlphaNode::convertToOperations(NodeConverter &converter, const CompositorContext &/*context*/) const
{
	SetAlphaOperation *operation = new SetAlphaOperation();
	
	if (!this->getInputSocket(0)->isLinked() && this->getInputSocket(1)->isLinked()) {
		operation->setResolutionInputSocketIndex(1);
	}
	
	converter.addOperation(operation);
	
	converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0));
	converter.mapInputSocket(getInputSocket(1), operation->getInputSocket(1));
	converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket());
}
void ChromaMatteNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
{
	InputSocket *inputSocketImage = this->getInputSocket(0);
	InputSocket *inputSocketKey = this->getInputSocket(1);
	OutputSocket *outputSocketImage = this->getOutputSocket(0);
	OutputSocket *outputSocketMatte = this->getOutputSocket(1);

	ConvertRGBToYCCOperation *operationRGBToYCC_Image = new ConvertRGBToYCCOperation();
	ConvertRGBToYCCOperation *operationRGBToYCC_Key = new ConvertRGBToYCCOperation();
	operationRGBToYCC_Image->setMode(0); /* BLI_YCC_ITU_BT601 */
	operationRGBToYCC_Key->setMode(0); /* BLI_YCC_ITU_BT601 */

	ChromaMatteOperation *operation = new ChromaMatteOperation();
	bNode *editorsnode = getbNode();
	operation->setSettings((NodeChroma *)editorsnode->storage);

	inputSocketImage->relinkConnections(operationRGBToYCC_Image->getInputSocket(0), 0, graph);
	inputSocketKey->relinkConnections(operationRGBToYCC_Key->getInputSocket(0), 0, graph);

	addLink(graph, operationRGBToYCC_Image->getOutputSocket(), operation->getInputSocket(0));
	addLink(graph, operationRGBToYCC_Key->getOutputSocket(), operation->getInputSocket(1));

	graph->addOperation(operationRGBToYCC_Image);
	graph->addOperation(operationRGBToYCC_Key);
	graph->addOperation(operation);

	if (outputSocketMatte->isConnected()) {
		outputSocketMatte->relinkConnections(operation->getOutputSocket());
	}

	SetAlphaOperation *operationAlpha = new SetAlphaOperation();
	addLink(graph, operationRGBToYCC_Image->getInputSocket(0)->getConnection()->getFromSocket(), operationAlpha->getInputSocket(0));
	addLink(graph, operation->getOutputSocket(), operationAlpha->getInputSocket(1));

	graph->addOperation(operationAlpha);
	addPreviewOperation(graph, context, operationAlpha->getOutputSocket());

	if (outputSocketImage->isConnected()) {
		outputSocketImage->relinkConnections(operationAlpha->getOutputSocket());
	}
}
void ChannelMatteNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const
{
	bNode *node = this->getbNode();
	
	NodeInput *inputSocketImage = this->getInputSocket(0);
	NodeOutput *outputSocketImage = this->getOutputSocket(0);
	NodeOutput *outputSocketMatte = this->getOutputSocket(1);
	
	NodeOperation *convert = NULL;
	/* colorspace */
	switch (node->custom1) {
		case CMP_NODE_CHANNEL_MATTE_CS_RGB:
			break;
		case CMP_NODE_CHANNEL_MATTE_CS_HSV: /* HSV */
			convert = new ConvertRGBToHSVOperation();
			break;
		case CMP_NODE_CHANNEL_MATTE_CS_YUV: /* YUV */
			convert = new ConvertRGBToYUVOperation();
			break;
		case CMP_NODE_CHANNEL_MATTE_CS_YCC: /* YCC */
			convert = new ConvertRGBToYCCOperation();
			((ConvertRGBToYCCOperation *)convert)->setMode(0); /* BLI_YCC_ITU_BT601 */
			break;
		default:
			break;
	}
	
	ChannelMatteOperation *operation = new ChannelMatteOperation();
	/* pass the ui properties to the operation */
	operation->setSettings((NodeChroma *)node->storage, node->custom2);
	converter.addOperation(operation);
	
	SetAlphaOperation *operationAlpha = new SetAlphaOperation();
	converter.addOperation(operationAlpha);
	
	if (convert) {
		converter.addOperation(convert);
		
		converter.mapInputSocket(inputSocketImage, convert->getInputSocket(0));
		converter.addLink(convert->getOutputSocket(), operation->getInputSocket(0));
		converter.addLink(convert->getOutputSocket(), operationAlpha->getInputSocket(0));
	}
	else {
		converter.mapInputSocket(inputSocketImage, operation->getInputSocket(0));
		converter.mapInputSocket(inputSocketImage, operationAlpha->getInputSocket(0));
	}
	
	converter.mapOutputSocket(outputSocketMatte, operation->getOutputSocket(0));
	
	converter.addLink(operation->getOutputSocket(), operationAlpha->getInputSocket(1));
	converter.mapOutputSocket(outputSocketImage, operationAlpha->getOutputSocket());
	
	converter.addPreview(operationAlpha->getOutputSocket());
}
void DistanceMatteNode::convertToOperations(NodeConverter &converter, const CompositorContext &/*context*/) const
{
	bNode *editorsnode = getbNode();
	NodeChroma *storage = (NodeChroma *)editorsnode->storage;
	
	NodeInput *inputSocketImage = this->getInputSocket(0);
	NodeInput *inputSocketKey = this->getInputSocket(1);
	NodeOutput *outputSocketImage = this->getOutputSocket(0);
	NodeOutput *outputSocketMatte = this->getOutputSocket(1);
	
	SetAlphaOperation *operationAlpha = new SetAlphaOperation();
	converter.addOperation(operationAlpha);
	
	/* work in RGB color space */
	NodeOperation *operation;
	if (storage->channel == 1) {
		DistanceRGBMatteOperation *matte = new DistanceRGBMatteOperation();
		matte->setSettings(storage);
		converter.addOperation(matte);
		
		converter.mapInputSocket(inputSocketImage, matte->getInputSocket(0));
		converter.mapInputSocket(inputSocketImage, operationAlpha->getInputSocket(0));
		
		converter.mapInputSocket(inputSocketKey, matte->getInputSocket(1));
		
		operation = matte;
	}
	/* work in YCbCr color space */
	else {
		DistanceYCCMatteOperation *matte = new DistanceYCCMatteOperation();
		matte->setSettings(storage);
		converter.addOperation(matte);
		
		ConvertRGBToYCCOperation *operationYCCImage = new ConvertRGBToYCCOperation();
		ConvertRGBToYCCOperation *operationYCCMatte = new ConvertRGBToYCCOperation();
		operationYCCImage->setMode(0);  /* BLI_YCC_ITU_BT601 */
		operationYCCMatte->setMode(0);  /* BLI_YCC_ITU_BT601 */
		converter.addOperation(operationYCCImage);
		converter.addOperation(operationYCCMatte);
		
		converter.mapInputSocket(inputSocketImage, operationYCCImage->getInputSocket(0));
		converter.addLink(operationYCCImage->getOutputSocket(), matte->getInputSocket(0));
		converter.addLink(operationYCCImage->getOutputSocket(), operationAlpha->getInputSocket(0));
		
		converter.mapInputSocket(inputSocketKey, operationYCCMatte->getInputSocket(0));
		converter.addLink(operationYCCMatte->getOutputSocket(), matte->getInputSocket(1));
		
		operation = matte;
	}
	
	converter.mapOutputSocket(outputSocketMatte, operation->getOutputSocket(0));
	converter.addLink(operation->getOutputSocket(), operationAlpha->getInputSocket(1));
	
	if (storage->channel != 1) {
		ConvertYCCToRGBOperation *inv_convert = new ConvertYCCToRGBOperation();
		inv_convert->setMode(0); /* BLI_YCC_ITU_BT601 */

		converter.addOperation(inv_convert);
		converter.addLink(operationAlpha->getOutputSocket(0), inv_convert->getInputSocket(0));
		converter.mapOutputSocket(outputSocketImage, inv_convert->getOutputSocket());
	}
	else {
		converter.mapOutputSocket(outputSocketImage, operationAlpha->getOutputSocket());
	}
	
	converter.addPreview(operationAlpha->getOutputSocket());
}
Esempio n. 9
0
void KeyingNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
{
	InputSocket *inputImage = this->getInputSocket(0);
	InputSocket *inputScreen = this->getInputSocket(1);
	InputSocket *inputGarbageMatte = this->getInputSocket(2);
	InputSocket *inputCoreMatte = this->getInputSocket(3);
	OutputSocket *outputImage = this->getOutputSocket(0);
	OutputSocket *outputMatte = this->getOutputSocket(1);
	OutputSocket *outputEdges = this->getOutputSocket(2);
	OutputSocket *postprocessedMatte = NULL, *postprocessedImage = NULL, *originalImage = NULL, *edgesMatte = NULL;

	bNode *editorNode = this->getbNode();
	NodeKeyingData *keying_data = (NodeKeyingData *) editorNode->storage;

	/* keying operation */
	KeyingOperation *keyingOperation = new KeyingOperation();

	keyingOperation->setScreenBalance(keying_data->screen_balance);

	inputScreen->relinkConnections(keyingOperation->getInputSocket(1), 1, graph);

	if (keying_data->blur_pre) {
		/* chroma preblur operation for input of keying operation  */
		OutputSocket *preBluredImage = setupPreBlur(graph, inputImage, keying_data->blur_pre, &originalImage);
		addLink(graph, preBluredImage, keyingOperation->getInputSocket(0));
	}
	else {
		inputImage->relinkConnections(keyingOperation->getInputSocket(0), 0, graph);
		originalImage = keyingOperation->getInputSocket(0)->getConnection()->getFromSocket();
	}

	graph->addOperation(keyingOperation);

	postprocessedMatte = keyingOperation->getOutputSocket();

	/* black / white clipping */
	if (keying_data->clip_black > 0.0f || keying_data->clip_white < 1.0f) {
		postprocessedMatte = setupClip(graph, postprocessedMatte,
		                               keying_data->edge_kernel_radius, keying_data->edge_kernel_tolerance,
		                               keying_data->clip_black, keying_data->clip_white, false);
	}

	/* output edge matte */
	if (outputEdges->isConnected()) {
		edgesMatte = setupClip(graph, postprocessedMatte,
		                       keying_data->edge_kernel_radius, keying_data->edge_kernel_tolerance,
		                       keying_data->clip_black, keying_data->clip_white, true);
	}

	/* apply garbage matte */
	if (inputGarbageMatte->isConnected()) {
		SetValueOperation *valueOperation = new SetValueOperation();
		MathSubtractOperation *subtractOperation = new MathSubtractOperation();
		MathMinimumOperation *minOperation = new MathMinimumOperation();

		valueOperation->setValue(1.0f);

		addLink(graph, valueOperation->getOutputSocket(), subtractOperation->getInputSocket(0));
		inputGarbageMatte->relinkConnections(subtractOperation->getInputSocket(1), 0, graph);

		addLink(graph, subtractOperation->getOutputSocket(), minOperation->getInputSocket(0));
		addLink(graph, postprocessedMatte, minOperation->getInputSocket(1));

		postprocessedMatte = minOperation->getOutputSocket();

		graph->addOperation(valueOperation);
		graph->addOperation(subtractOperation);
		graph->addOperation(minOperation);
	}

	/* apply core matte */
	if (inputCoreMatte->isConnected()) {
		MathMaximumOperation *maxOperation = new MathMaximumOperation();

		inputCoreMatte->relinkConnections(maxOperation->getInputSocket(0), 0, graph);

		addLink(graph, postprocessedMatte, maxOperation->getInputSocket(1));

		postprocessedMatte = maxOperation->getOutputSocket();

		graph->addOperation(maxOperation);
	}

	/* apply blur on matte if needed */
	if (keying_data->blur_post)
		postprocessedMatte = setupPostBlur(graph, postprocessedMatte, keying_data->blur_post);

	/* matte dilate/erode */
	if (keying_data->dilate_distance != 0) {
		postprocessedMatte = setupDilateErode(graph, postprocessedMatte, keying_data->dilate_distance);
	}

	/* matte feather */
	if (keying_data->feather_distance != 0) {
		postprocessedMatte = setupFeather(graph, context, postprocessedMatte, keying_data->feather_falloff,
		                                  keying_data->feather_distance);
	}

	/* set alpha channel to output image */
	SetAlphaOperation *alphaOperation = new SetAlphaOperation();
	addLink(graph, originalImage, alphaOperation->getInputSocket(0));
	addLink(graph, postprocessedMatte, alphaOperation->getInputSocket(1));

	postprocessedImage = alphaOperation->getOutputSocket();

	/* despill output image */
	if (keying_data->despill_factor > 0.0f) {
		postprocessedImage = setupDespill(graph, postprocessedImage,
		                                  keyingOperation->getInputSocket(1)->getConnection()->getFromSocket(),
		                                  keying_data->despill_factor,
		                                  keying_data->despill_balance);
	}

	/* connect result to output sockets */
	outputImage->relinkConnections(postprocessedImage);
	outputMatte->relinkConnections(postprocessedMatte);

	if (edgesMatte)
		outputEdges->relinkConnections(edgesMatte);

	graph->addOperation(alphaOperation);
}