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); } }