コード例 #1
0
void Stabilize2dNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const
{
	NodeInput *imageInput = this->getInputSocket(0);
	MovieClip *clip = (MovieClip *)getbNode()->id;
	
	ScaleOperation *scaleOperation = new ScaleOperation();
	scaleOperation->setSampler((PixelSampler)this->getbNode()->custom1);
	RotateOperation *rotateOperation = new RotateOperation();
	rotateOperation->setDoDegree2RadConversion(false);
	TranslateOperation *translateOperation = new TranslateOperation();
	MovieClipAttributeOperation *scaleAttribute = new MovieClipAttributeOperation();
	MovieClipAttributeOperation *angleAttribute = new MovieClipAttributeOperation();
	MovieClipAttributeOperation *xAttribute = new MovieClipAttributeOperation();
	MovieClipAttributeOperation *yAttribute = new MovieClipAttributeOperation();
	SetSamplerOperation *psoperation = new SetSamplerOperation();
	psoperation->setSampler((PixelSampler)this->getbNode()->custom1);
	
	scaleAttribute->setAttribute(MCA_SCALE);
	scaleAttribute->setFramenumber(context.getFramenumber());
	scaleAttribute->setMovieClip(clip);
	
	angleAttribute->setAttribute(MCA_ANGLE);
	angleAttribute->setFramenumber(context.getFramenumber());
	angleAttribute->setMovieClip(clip);
	
	xAttribute->setAttribute(MCA_X);
	xAttribute->setFramenumber(context.getFramenumber());
	xAttribute->setMovieClip(clip);
	
	yAttribute->setAttribute(MCA_Y);
	yAttribute->setFramenumber(context.getFramenumber());
	yAttribute->setMovieClip(clip);
	
	converter.addOperation(scaleAttribute);
	converter.addOperation(angleAttribute);
	converter.addOperation(xAttribute);
	converter.addOperation(yAttribute);
	converter.addOperation(scaleOperation);
	converter.addOperation(translateOperation);
	converter.addOperation(rotateOperation);
	converter.addOperation(psoperation);
	
	converter.mapInputSocket(imageInput, scaleOperation->getInputSocket(0));
	converter.addLink(scaleAttribute->getOutputSocket(), scaleOperation->getInputSocket(1));
	converter.addLink(scaleAttribute->getOutputSocket(), scaleOperation->getInputSocket(2));
	
	converter.addLink(scaleOperation->getOutputSocket(), rotateOperation->getInputSocket(0));
	converter.addLink(angleAttribute->getOutputSocket(), rotateOperation->getInputSocket(1));

	converter.addLink(rotateOperation->getOutputSocket(), translateOperation->getInputSocket(0));
	converter.addLink(xAttribute->getOutputSocket(), translateOperation->getInputSocket(1));
	converter.addLink(yAttribute->getOutputSocket(), translateOperation->getInputSocket(2));
	
	converter.addLink(translateOperation->getOutputSocket(), psoperation->getInputSocket(0));
	converter.mapOutputSocket(getOutputSocket(), psoperation->getOutputSocket());
}
コード例 #2
0
void TransformNode::convertToOperations(NodeConverter &converter,
                                        const CompositorContext & /*context*/) const
{
  NodeInput *imageInput = this->getInputSocket(0);
  NodeInput *xInput = this->getInputSocket(1);
  NodeInput *yInput = this->getInputSocket(2);
  NodeInput *angleInput = this->getInputSocket(3);
  NodeInput *scaleInput = this->getInputSocket(4);

  ScaleOperation *scaleOperation = new ScaleOperation();
  converter.addOperation(scaleOperation);

  RotateOperation *rotateOperation = new RotateOperation();
  rotateOperation->setDoDegree2RadConversion(false);
  converter.addOperation(rotateOperation);

  TranslateOperation *translateOperation = new TranslateOperation();
  converter.addOperation(translateOperation);

  SetSamplerOperation *sampler = new SetSamplerOperation();
  sampler->setSampler((PixelSampler)this->getbNode()->custom1);
  converter.addOperation(sampler);

  converter.mapInputSocket(imageInput, sampler->getInputSocket(0));
  converter.addLink(sampler->getOutputSocket(), scaleOperation->getInputSocket(0));
  converter.mapInputSocket(scaleInput, scaleOperation->getInputSocket(1));
  converter.mapInputSocket(scaleInput, scaleOperation->getInputSocket(2));  // xscale = yscale

  converter.addLink(scaleOperation->getOutputSocket(), rotateOperation->getInputSocket(0));
  converter.mapInputSocket(angleInput, rotateOperation->getInputSocket(1));

  converter.addLink(rotateOperation->getOutputSocket(), translateOperation->getInputSocket(0));
  converter.mapInputSocket(xInput, translateOperation->getInputSocket(1));
  converter.mapInputSocket(yInput, translateOperation->getInputSocket(2));

  converter.mapOutputSocket(getOutputSocket(), translateOperation->getOutputSocket());
}
コード例 #3
0
ファイル: COM_Converter.cpp プロジェクト: wchargin/blender
void Converter::convertResolution(NodeOperationBuilder &builder, NodeOperationOutput *fromSocket, NodeOperationInput *toSocket)
{
	InputResizeMode mode = toSocket->getResizeMode();

	NodeOperation *toOperation = &toSocket->getOperation();
	const float toWidth = toOperation->getWidth();
	const float toHeight = toOperation->getHeight();
	NodeOperation *fromOperation = &fromSocket->getOperation();
	const float fromWidth = fromOperation->getWidth();
	const float fromHeight = fromOperation->getHeight();
	bool doCenter = false;
	bool doScale = false;
	float addX = (toWidth - fromWidth) / 2.0f;
	float addY = (toHeight - fromHeight) / 2.0f;
	float scaleX = 0;
	float scaleY = 0;

	switch (mode) {
		case COM_SC_NO_RESIZE:
			break;
		case COM_SC_CENTER:
			doCenter = true;
			break;
		case COM_SC_FIT_WIDTH:
			doCenter = true;
			doScale = true;
			scaleX = scaleY = toWidth / fromWidth;
			break;
		case COM_SC_FIT_HEIGHT:
			doCenter = true;
			doScale = true;
			scaleX = scaleY = toHeight / fromHeight;
			break;
		case COM_SC_FIT:
			doCenter = true;
			doScale = true;
			scaleX = toWidth / fromWidth;
			scaleY = toHeight / fromHeight;
			if (scaleX < scaleY) {
				scaleX = scaleY;
			}
			else {
				scaleY = scaleX;
			}
			break;
		case COM_SC_STRETCH:
			doCenter = true;
			doScale = true;
			scaleX = toWidth / fromWidth;
			scaleY = toHeight / fromHeight;
			break;

	}

	if (doCenter) {
		NodeOperation *first = NULL;
		ScaleOperation *scaleOperation = NULL;
		if (doScale) {
			scaleOperation = new ScaleOperation();
			scaleOperation->getInputSocket(1)->setResizeMode(COM_SC_NO_RESIZE);
			scaleOperation->getInputSocket(2)->setResizeMode(COM_SC_NO_RESIZE);
			first = scaleOperation;
			SetValueOperation *sxop = new SetValueOperation();
			sxop->setValue(scaleX);
			builder.addLink(sxop->getOutputSocket(), scaleOperation->getInputSocket(1));
			SetValueOperation *syop = new SetValueOperation();
			syop->setValue(scaleY);
			builder.addLink(syop->getOutputSocket(), scaleOperation->getInputSocket(2));
			builder.addOperation(sxop);
			builder.addOperation(syop);

			unsigned int resolution[2] = {fromOperation->getWidth(),
			                              fromOperation->getHeight()};
			scaleOperation->setResolution(resolution);
			sxop->setResolution(resolution);
			syop->setResolution(resolution);
			builder.addOperation(scaleOperation);
		}

		TranslateOperation *translateOperation = new TranslateOperation();
		translateOperation->getInputSocket(1)->setResizeMode(COM_SC_NO_RESIZE);
		translateOperation->getInputSocket(2)->setResizeMode(COM_SC_NO_RESIZE);
		if (!first) first = translateOperation;
		SetValueOperation *xop = new SetValueOperation();
		xop->setValue(addX);
		builder.addLink(xop->getOutputSocket(), translateOperation->getInputSocket(1));
		SetValueOperation *yop = new SetValueOperation();
		yop->setValue(addY);
		builder.addLink(yop->getOutputSocket(), translateOperation->getInputSocket(2));
		builder.addOperation(xop);
		builder.addOperation(yop);

		unsigned int resolution[2] = {toOperation->getWidth(),
		                              toOperation->getHeight()};
		translateOperation->setResolution(resolution);
		xop->setResolution(resolution);
		yop->setResolution(resolution);
		builder.addOperation(translateOperation);

		if (doScale) {
			translateOperation->getInputSocket(0)->setResizeMode(COM_SC_NO_RESIZE);
			builder.addLink(scaleOperation->getOutputSocket(), translateOperation->getInputSocket(0));
		}

		/* remove previous link and replace */
		builder.removeInputLink(toSocket);
		first->getInputSocket(0)->setResizeMode(COM_SC_NO_RESIZE);
		toSocket->setResizeMode(COM_SC_NO_RESIZE);
		builder.addLink(fromSocket, first->getInputSocket(0));
		builder.addLink(translateOperation->getOutputSocket(), toSocket);
	}
}