void CompositorNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const { bNode *editorNode = this->getbNode(); bool is_active = (editorNode->flag & NODE_DO_OUTPUT_RECALC) || context.isRendering(); bool ignore_alpha = (editorNode->custom2 & CMP_NODE_OUTPUT_IGNORE_ALPHA) != 0; NodeInput *imageSocket = this->getInputSocket(0); NodeInput *alphaSocket = this->getInputSocket(1); NodeInput *depthSocket = this->getInputSocket(2); CompositorOperation *compositorOperation = new CompositorOperation(); compositorOperation->setScene(context.getScene()); compositorOperation->setSceneName(context.getScene()->id.name); compositorOperation->setRenderData(context.getRenderData()); compositorOperation->setViewName(context.getViewName()); compositorOperation->setbNodeTree(context.getbNodeTree()); /* alpha socket gives either 1 or a custom alpha value if "use alpha" is enabled */ compositorOperation->setUseAlphaInput(ignore_alpha || alphaSocket->isLinked()); compositorOperation->setActive(is_active); converter.addOperation(compositorOperation); converter.mapInputSocket(imageSocket, compositorOperation->getInputSocket(0)); /* only use alpha link if "use alpha" is enabled */ if (ignore_alpha) { converter.addInputValue(compositorOperation->getInputSocket(1), 1.0f); } else { converter.mapInputSocket(alphaSocket, compositorOperation->getInputSocket(1)); } converter.mapInputSocket(depthSocket, compositorOperation->getInputSocket(2)); converter.addNodeInputPreview(imageSocket); }
void ViewLevelsNode::convertToOperations(NodeConverter &converter, const CompositorContext &/*context*/) const { NodeInput *input = this->getInputSocket(0); if (input->isLinked()) { // add preview to inputSocket; /* calculate mean operation */ { CalculateMeanOperation *operation = new CalculateMeanOperation(); operation->setSetting(this->getbNode()->custom1); converter.addOperation(operation); converter.mapInputSocket(input, operation->getInputSocket(0)); converter.mapOutputSocket(this->getOutputSocket(0), operation->getOutputSocket()); } /* calculate standard deviation operation */ { CalculateStandardDeviationOperation *operation = new CalculateStandardDeviationOperation(); operation->setSetting(this->getbNode()->custom1); converter.addOperation(operation); converter.mapInputSocket(input, operation->getInputSocket(0)); converter.mapOutputSocket(this->getOutputSocket(1), operation->getOutputSocket()); } } else { converter.addOutputValue(getOutputSocket(0), 0.0f); converter.addOutputValue(getOutputSocket(1), 0.0f); } }
void BokehBlurNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const { bNode *b_node = this->getbNode(); NodeInput *inputSizeSocket = this->getInputSocket(2); bool connectedSizeSocket = inputSizeSocket->isLinked(); const bool extend_bounds = (b_node->custom1 & CMP_NODEFLAG_BLUR_EXTEND_BOUNDS) != 0; if ((b_node->custom1 & CMP_NODEFLAG_BLUR_VARIABLE_SIZE) && connectedSizeSocket) { VariableSizeBokehBlurOperation *operation = new VariableSizeBokehBlurOperation(); operation->setQuality(context.getQuality()); operation->setThreshold(0.0f); operation->setMaxBlur(b_node->custom4); operation->setDoScaleSize(true); converter.addOperation(operation); converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0)); converter.mapInputSocket(getInputSocket(1), operation->getInputSocket(1)); converter.mapInputSocket(getInputSocket(2), operation->getInputSocket(2)); converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket()); } else { BokehBlurOperation *operation = new BokehBlurOperation(); operation->setQuality(context.getQuality()); operation->setExtendBounds(extend_bounds); converter.addOperation(operation); converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0)); converter.mapInputSocket(getInputSocket(1), operation->getInputSocket(1)); // NOTE: on the bokeh blur operation the sockets are switched. // for this reason the next two lines are correct. // Fix for T43771 converter.mapInputSocket(getInputSocket(2), operation->getInputSocket(3)); converter.mapInputSocket(getInputSocket(3), operation->getInputSocket(2)); converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket()); if (!connectedSizeSocket) { operation->setSize(this->getInputSocket(2)->getEditorValueFloat()); } } }
void BoxMaskNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const { NodeInput *inputSocket = this->getInputSocket(0); NodeOutput *outputSocket = this->getOutputSocket(0); BoxMaskOperation *operation; operation = new BoxMaskOperation(); operation->setData((NodeBoxMask *)this->getbNode()->storage); operation->setMaskType(this->getbNode()->custom1); converter.addOperation(operation); if (inputSocket->isLinked()) { converter.mapInputSocket(inputSocket, operation->getInputSocket(0)); converter.mapOutputSocket(outputSocket, operation->getOutputSocket()); } else { /* Value operation to produce original transparent image */ SetValueOperation *valueOperation = new SetValueOperation(); valueOperation->setValue(0.0f); converter.addOperation(valueOperation); /* Scale that image up to render resolution */ const RenderData *rd = context.getRenderData(); ScaleFixedSizeOperation *scaleOperation = new ScaleFixedSizeOperation(); scaleOperation->setIsAspect(false); scaleOperation->setIsCrop(false); scaleOperation->setOffset(0.0f, 0.0f); scaleOperation->setNewWidth(rd->xsch * rd->size / 100.0f); scaleOperation->setNewHeight(rd->ysch * rd->size / 100.0f); scaleOperation->getInputSocket(0)->setResizeMode(COM_SC_NO_RESIZE); converter.addOperation(scaleOperation); converter.addLink(valueOperation->getOutputSocket(0), scaleOperation->getInputSocket(0)); converter.addLink(scaleOperation->getOutputSocket(0), operation->getInputSocket(0)); converter.mapOutputSocket(outputSocket, operation->getOutputSocket(0)); } converter.mapInputSocket(getInputSocket(1), operation->getInputSocket(1)); }
void BlurNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const { bNode *editorNode = this->getbNode(); NodeBlurData *data = (NodeBlurData *)editorNode->storage; NodeInput *inputSizeSocket = this->getInputSocket(1); bool connectedSizeSocket = inputSizeSocket->isLinked(); const float size = this->getInputSocket(1)->getEditorValueFloat(); CompositorQuality quality = context.getQuality(); NodeOperation *input_operation = NULL, *output_operation = NULL; if (data->filtertype == R_FILTER_FAST_GAUSS) { FastGaussianBlurOperation *operationfgb = new FastGaussianBlurOperation(); operationfgb->setData(data); converter.addOperation(operationfgb); converter.mapInputSocket(getInputSocket(1), operationfgb->getInputSocket(1)); input_operation = operationfgb; output_operation = operationfgb; } else if (editorNode->custom1 & CMP_NODEFLAG_BLUR_VARIABLE_SIZE) { MathAddOperation *clamp = new MathAddOperation(); SetValueOperation *zero = new SetValueOperation(); zero->setValue(0.0f); clamp->setUseClamp(true); converter.addOperation(clamp); converter.addOperation(zero); converter.mapInputSocket(getInputSocket(1), clamp->getInputSocket(0)); converter.addLink(zero->getOutputSocket(), clamp->getInputSocket(1)); GaussianAlphaXBlurOperation *operationx = new GaussianAlphaXBlurOperation(); operationx->setData(data); operationx->setQuality(quality); operationx->setSize(1.0f); operationx->setFalloff(PROP_SMOOTH); operationx->setSubtract(false); converter.addOperation(operationx); converter.addLink(clamp->getOutputSocket(), operationx->getInputSocket(0)); GaussianAlphaYBlurOperation *operationy = new GaussianAlphaYBlurOperation(); operationy->setData(data); operationy->setQuality(quality); operationy->setSize(1.0f); operationy->setFalloff(PROP_SMOOTH); operationy->setSubtract(false); converter.addOperation(operationy); converter.addLink(operationx->getOutputSocket(), operationy->getInputSocket(0)); GaussianBlurReferenceOperation *operation = new GaussianBlurReferenceOperation(); operation->setData(data); operation->setQuality(quality); converter.addOperation(operation); converter.addLink(operationy->getOutputSocket(), operation->getInputSocket(1)); output_operation = operation; input_operation = operation; } else if (!data->bokeh) { GaussianXBlurOperation *operationx = new GaussianXBlurOperation(); operationx->setData(data); operationx->setQuality(quality); converter.addOperation(operationx); converter.mapInputSocket(getInputSocket(1), operationx->getInputSocket(1)); GaussianYBlurOperation *operationy = new GaussianYBlurOperation(); operationy->setData(data); operationy->setQuality(quality); converter.addOperation(operationy); converter.mapInputSocket(getInputSocket(1), operationy->getInputSocket(1)); converter.addLink(operationx->getOutputSocket(), operationy->getInputSocket(0)); if (!connectedSizeSocket) { operationx->setSize(size); operationy->setSize(size); } input_operation = operationx; output_operation = operationy; } else { GaussianBokehBlurOperation *operation = new GaussianBokehBlurOperation(); operation->setData(data); operation->setQuality(quality); converter.addOperation(operation); converter.mapInputSocket(getInputSocket(1), operation->getInputSocket(1)); if (!connectedSizeSocket) { operation->setSize(size); } input_operation = operation; output_operation = operation; } if (data->gamma) { GammaCorrectOperation *correct = new GammaCorrectOperation(); GammaUncorrectOperation *inverse = new GammaUncorrectOperation(); converter.addOperation(correct); converter.addOperation(inverse); converter.mapInputSocket(getInputSocket(0), correct->getInputSocket(0)); converter.addLink(correct->getOutputSocket(), input_operation->getInputSocket(0)); converter.addLink(output_operation->getOutputSocket(), inverse->getInputSocket(0)); converter.mapOutputSocket(getOutputSocket(), inverse->getOutputSocket()); converter.addPreview(inverse->getOutputSocket()); } else { converter.mapInputSocket(getInputSocket(0), input_operation->getInputSocket(0)); converter.mapOutputSocket(getOutputSocket(), output_operation->getOutputSocket()); converter.addPreview(output_operation->getOutputSocket()); } }
void OutputFileNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const { NodeImageMultiFile *storage = (NodeImageMultiFile *)this->getbNode()->storage; if (!context.isRendering()) { /* only output files when rendering a sequence - * otherwise, it overwrites the output files just * scrubbing through the timeline when the compositor updates. */ return; } if (storage->format.imtype == R_IMF_IMTYPE_MULTILAYER) { /* single output operation for the multilayer file */ OutputOpenExrMultiLayerOperation *outputOperation = new OutputOpenExrMultiLayerOperation( context.getRenderData(), context.getbNodeTree(), storage->base_path, storage->format.exr_codec); converter.addOperation(outputOperation); int num_inputs = getNumberOfInputSockets(); bool previewAdded = false; for (int i = 0; i < num_inputs; ++i) { NodeInput *input = getInputSocket(i); NodeImageMultiFileSocket *sockdata = (NodeImageMultiFileSocket *)input->getbNodeSocket()->storage; /* note: layer becomes an empty placeholder if the input is not linked */ outputOperation->add_layer(sockdata->layer, input->getDataType(), input->isLinked()); converter.mapInputSocket(input, outputOperation->getInputSocket(i)); if (!previewAdded) { converter.addNodeInputPreview(input); previewAdded = true; } } } else { /* single layer format */ int num_inputs = getNumberOfInputSockets(); bool previewAdded = false; for (int i = 0; i < num_inputs; ++i) { NodeInput *input = getInputSocket(i); if (input->isLinked()) { NodeImageMultiFileSocket *sockdata = (NodeImageMultiFileSocket *)input->getbNodeSocket()->storage; ImageFormatData *format = (sockdata->use_node_format ? &storage->format : &sockdata->format); char path[FILE_MAX]; /* combine file path for the input */ BLI_join_dirfile(path, FILE_MAX, storage->base_path, sockdata->path); OutputSingleLayerOperation *outputOperation = new OutputSingleLayerOperation( context.getRenderData(), context.getbNodeTree(), input->getDataType(), format, path, context.getViewSettings(), context.getDisplaySettings()); converter.addOperation(outputOperation); converter.mapInputSocket(input, outputOperation->getInputSocket(0)); if (!previewAdded) { converter.addNodeInputPreview(input); previewAdded = true; } } } } }