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 ImageNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const { /// Image output NodeOutput *outputImage = this->getOutputSocket(0); bNode *editorNode = this->getbNode(); Image *image = (Image *)editorNode->id; ImageUser *imageuser = (ImageUser *)editorNode->storage; int framenumber = context.getFramenumber(); int numberOfOutputs = this->getNumberOfOutputSockets(); bool outputStraightAlpha = (editorNode->custom1 & CMP_NODE_IMAGE_USE_STRAIGHT_OUTPUT) != 0; BKE_image_user_frame_calc(imageuser, context.getFramenumber(), 0); /* force a load, we assume iuser index will be set OK anyway */ if (image && image->type == IMA_TYPE_MULTILAYER) { bool is_multilayer_ok = false; ImBuf *ibuf = BKE_image_acquire_ibuf(image, imageuser, NULL); if (image->rr) { RenderLayer *rl = (RenderLayer *)BLI_findlink(&image->rr->layers, imageuser->layer); if (rl) { NodeOutput *socket; int index; is_multilayer_ok = true; for (index = 0; index < numberOfOutputs; index++) { NodeOperation *operation = NULL; socket = this->getOutputSocket(index); bNodeSocket *bnodeSocket = socket->getbNodeSocket(); /* Passes in the file can differ from passes stored in sockets (#36755). * Look up the correct file pass using the socket identifier instead. */ #if 0 NodeImageLayer *storage = (NodeImageLayer *)bnodeSocket->storage;*/ int passindex = storage->pass_index;*/ RenderPass *rpass = (RenderPass *)BLI_findlink(&rl->passes, passindex); #endif int passindex; RenderPass *rpass; for (rpass = (RenderPass *)rl->passes.first, passindex = 0; rpass; rpass = rpass->next, ++passindex) if (STREQ(rpass->name, bnodeSocket->identifier)) break; if (rpass) { imageuser->pass = passindex; switch (rpass->channels) { case 1: operation = doMultilayerCheck(converter, rl, image, imageuser, framenumber, index, passindex, COM_DT_VALUE); break; /* using image operations for both 3 and 4 channels (RGB and RGBA respectively) */ /* XXX any way to detect actual vector images? */ case 3: operation = doMultilayerCheck(converter, rl, image, imageuser, framenumber, index, passindex, COM_DT_VECTOR); break; case 4: operation = doMultilayerCheck(converter, rl, image, imageuser, framenumber, index, passindex, COM_DT_COLOR); break; default: /* dummy operation is added below */ break; } if (index == 0 && operation) { converter.addPreview(operation->getOutputSocket()); } } /* incase we can't load the layer */ if (operation == NULL) converter.setInvalidOutput(getOutputSocket(index)); } } }
void DilateErodeNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const { bNode *editorNode = this->getbNode(); if (editorNode->custom1 == CMP_NODE_DILATEERODE_DISTANCE_THRESH) { DilateErodeThresholdOperation *operation = new DilateErodeThresholdOperation(); operation->setDistance(editorNode->custom2); operation->setInset(editorNode->custom3); converter.addOperation(operation); converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0)); if (editorNode->custom3 < 2.0f) { AntiAliasOperation *antiAlias = new AntiAliasOperation(); converter.addOperation(antiAlias); converter.addLink(operation->getOutputSocket(), antiAlias->getInputSocket(0)); converter.mapOutputSocket(getOutputSocket(0), antiAlias->getOutputSocket(0)); } else { converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket(0)); } } else if (editorNode->custom1 == CMP_NODE_DILATEERODE_DISTANCE) { if (editorNode->custom2 > 0) { DilateDistanceOperation *operation = new DilateDistanceOperation(); operation->setDistance(editorNode->custom2); converter.addOperation(operation); converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0)); converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket(0)); } else { ErodeDistanceOperation *operation = new ErodeDistanceOperation(); operation->setDistance(-editorNode->custom2); converter.addOperation(operation); converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0)); converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket(0)); } } else if (editorNode->custom1 == CMP_NODE_DILATEERODE_DISTANCE_FEATHER) { /* this uses a modified gaussian blur function otherwise its far too slow */ CompositorQuality quality = context.getQuality(); GaussianAlphaXBlurOperation *operationx = new GaussianAlphaXBlurOperation(); operationx->setData(&m_alpha_blur); operationx->setQuality(quality); operationx->setFalloff(PROP_SMOOTH); converter.addOperation(operationx); converter.mapInputSocket(getInputSocket(0), operationx->getInputSocket(0)); // converter.mapInputSocket(getInputSocket(1), operationx->getInputSocket(1)); // no size input // yet GaussianAlphaYBlurOperation *operationy = new GaussianAlphaYBlurOperation(); operationy->setData(&m_alpha_blur); operationy->setQuality(quality); operationy->setFalloff(PROP_SMOOTH); converter.addOperation(operationy); converter.addLink(operationx->getOutputSocket(), operationy->getInputSocket(0)); // converter.mapInputSocket(getInputSocket(1), operationy->getInputSocket(1)); // no size input // yet converter.mapOutputSocket(getOutputSocket(0), operationy->getOutputSocket()); converter.addPreview(operationy->getOutputSocket()); /* TODO? */ /* see gaussian blue node for original usage */ #if 0 if (!connectedSizeSocket) { operationx->setSize(size); operationy->setSize(size); } #else operationx->setSize(1.0f); operationy->setSize(1.0f); #endif operationx->setSubtract(editorNode->custom2 < 0); operationy->setSubtract(editorNode->custom2 < 0); if (editorNode->storage) { NodeDilateErode *data_storage = (NodeDilateErode *)editorNode->storage; operationx->setFalloff(data_storage->falloff); operationy->setFalloff(data_storage->falloff); } } else { if (editorNode->custom2 > 0) { DilateStepOperation *operation = new DilateStepOperation(); operation->setIterations(editorNode->custom2); converter.addOperation(operation); converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0)); converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket(0)); } else { ErodeStepOperation *operation = new ErodeStepOperation(); operation->setIterations(-editorNode->custom2); converter.addOperation(operation); converter.mapInputSocket(getInputSocket(0), operation->getInputSocket(0)); converter.mapOutputSocket(getOutputSocket(0), operation->getOutputSocket(0)); } } }
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()); }
void MixNode::convertToOperations(NodeConverter &converter, const CompositorContext &/*context*/) const { NodeInput *valueSocket = this->getInputSocket(0); NodeInput *color1Socket = this->getInputSocket(1); NodeInput *color2Socket = this->getInputSocket(2); NodeOutput *outputSocket = this->getOutputSocket(0); bNode *editorNode = this->getbNode(); bool useAlphaPremultiply = (this->getbNode()->custom2 & 1) != 0; bool useClamp = (this->getbNode()->custom2 & 2) != 0; MixBaseOperation *convertProg; switch (editorNode->custom1) { case MA_RAMP_ADD: convertProg = new MixAddOperation(); break; case MA_RAMP_MULT: convertProg = new MixMultiplyOperation(); break; case MA_RAMP_LIGHT: convertProg = new MixLightenOperation(); break; case MA_RAMP_BURN: convertProg = new MixBurnOperation(); break; case MA_RAMP_HUE: convertProg = new MixHueOperation(); break; case MA_RAMP_COLOR: convertProg = new MixColorOperation(); break; case MA_RAMP_SOFT: convertProg = new MixSoftLightOperation(); break; case MA_RAMP_SCREEN: convertProg = new MixScreenOperation(); break; case MA_RAMP_LINEAR: convertProg = new MixLinearLightOperation(); break; case MA_RAMP_DIFF: convertProg = new MixDifferenceOperation(); break; case MA_RAMP_SAT: convertProg = new MixSaturationOperation(); break; case MA_RAMP_DIV: convertProg = new MixDivideOperation(); break; case MA_RAMP_SUB: convertProg = new MixSubtractOperation(); break; case MA_RAMP_DARK: convertProg = new MixDarkenOperation(); break; case MA_RAMP_OVERLAY: convertProg = new MixOverlayOperation(); break; case MA_RAMP_VAL: convertProg = new MixValueOperation(); break; case MA_RAMP_DODGE: convertProg = new MixDodgeOperation(); break; case MA_RAMP_BLEND: default: convertProg = new MixBlendOperation(); break; } convertProg->setUseValueAlphaMultiply(useAlphaPremultiply); convertProg->setUseClamp(useClamp); converter.addOperation(convertProg); converter.mapInputSocket(valueSocket, convertProg->getInputSocket(0)); converter.mapInputSocket(color1Socket, convertProg->getInputSocket(1)); converter.mapInputSocket(color2Socket, convertProg->getInputSocket(2)); converter.mapOutputSocket(outputSocket, convertProg->getOutputSocket(0)); converter.addPreview(convertProg->getOutputSocket(0)); }
void ImageNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const { /// Image output NodeOutput *outputImage = this->getOutputSocket(0); bNode *editorNode = this->getbNode(); Image *image = (Image *)editorNode->id; ImageUser *imageuser = (ImageUser *)editorNode->storage; int framenumber = context.getFramenumber(); int numberOfOutputs = this->getNumberOfOutputSockets(); bool outputStraightAlpha = (editorNode->custom1 & CMP_NODE_IMAGE_USE_STRAIGHT_OUTPUT) != 0; BKE_image_user_frame_calc(imageuser, context.getFramenumber(), 0); /* force a load, we assume iuser index will be set OK anyway */ if (image && image->type == IMA_TYPE_MULTILAYER) { bool is_multilayer_ok = false; ImBuf *ibuf = BKE_image_acquire_ibuf(image, imageuser, NULL); if (image->rr) { RenderLayer *rl = (RenderLayer *)BLI_findlink(&image->rr->layers, imageuser->layer); if (rl) { NodeOutput *socket; int index; is_multilayer_ok = true; for (index = 0; index < numberOfOutputs; index++) { NodeOperation *operation = NULL; socket = this->getOutputSocket(index); bNodeSocket *bnodeSocket = socket->getbNodeSocket(); RenderPass *rpass = (RenderPass *)BLI_findstring(&rl->passes, bnodeSocket->identifier, offsetof(RenderPass, internal_name)); int view = 0; /* Passes in the file can differ from passes stored in sockets (#36755). * Look up the correct file pass using the socket identifier instead. */ #if 0 NodeImageLayer *storage = (NodeImageLayer *)bnodeSocket->storage;*/ int passindex = storage->pass_index;*/ RenderPass *rpass = (RenderPass *)BLI_findlink(&rl->passes, passindex); #endif /* returns the image view to use for the current active view */ if (BLI_listbase_count_ex(&image->rr->views, 2) > 1) { const int view_image = imageuser->view; const bool is_allview = (view_image == 0); /* if view selected == All (0) */ if (is_allview) { /* heuristic to match image name with scene names * check if the view name exists in the image */ view = BLI_findstringindex(&image->rr->views, context.getViewName(), offsetof(RenderView, name)); if (view == -1) view = 0; } else { view = view_image - 1; } } if (rpass) { switch (rpass->channels) { case 1: operation = doMultilayerCheck(converter, rl, image, imageuser, framenumber, index, rpass->passtype, view, COM_DT_VALUE); break; /* using image operations for both 3 and 4 channels (RGB and RGBA respectively) */ /* XXX any way to detect actual vector images? */ case 3: operation = doMultilayerCheck(converter, rl, image, imageuser, framenumber, index, rpass->passtype, view, COM_DT_VECTOR); break; case 4: operation = doMultilayerCheck(converter, rl, image, imageuser, framenumber, index, rpass->passtype, view, COM_DT_COLOR); break; default: /* dummy operation is added below */ break; } if (index == 0 && operation) { converter.addPreview(operation->getOutputSocket()); } if (rpass->passtype == SCE_PASS_COMBINED) { BLI_assert(operation != NULL); BLI_assert(index < numberOfOutputs - 1); NodeOutput *outputSocket = this->getOutputSocket(index + 1); SeparateChannelOperation *separate_operation; separate_operation = new SeparateChannelOperation(); separate_operation->setChannel(3); converter.addOperation(separate_operation); converter.addLink(operation->getOutputSocket(), separate_operation->getInputSocket(0)); converter.mapOutputSocket(outputSocket, separate_operation->getOutputSocket()); index++; } } /* incase we can't load the layer */ if (operation == NULL) converter.setInvalidOutput(getOutputSocket(index)); } } }