From 9dbea1db66da5e277e8279811d66096751f38d29 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Tue, 5 Jan 2021 16:16:18 +0100 Subject: Compositor: Alpha Mode {D9211} introduced pre-multiplying the color for the keying node. This pre-multiplication should also be done by other keying nodes and should be the default operation for alpha node. This patch will change the logic of keying nodes (Cryptomatte Node, Channel Matte, Chroma Matte, Color Matte, Difference Matte, Distance Matte, Luminance Matte) and breaks old files. The Set alpha node has a mode parameter. This parameter changes the logic to `Apply Mask` the alpha on the RGBA channels of the input color or only replace the alpha channel (old behavior). The replace mode is automatically set for older files. When adding new files the the multiply mode is set. Reviewed By: Sergey Sharybin Differential Revision: https://developer.blender.org/D9630 --- source/blender/compositor/CMakeLists.txt | 8 ++-- .../compositor/nodes/COM_ChannelMatteNode.cpp | 4 +- .../compositor/nodes/COM_ChromaMatteNode.cpp | 4 +- .../compositor/nodes/COM_ColorMatteNode.cpp | 4 +- .../compositor/nodes/COM_CryptomatteNode.cpp | 6 +-- .../compositor/nodes/COM_DifferenceMatteNode.cpp | 4 +- .../compositor/nodes/COM_DistanceMatteNode.cpp | 4 +- source/blender/compositor/nodes/COM_KeyingNode.cpp | 4 +- .../compositor/nodes/COM_LuminanceMatteNode.cpp | 4 +- .../blender/compositor/nodes/COM_SetAlphaNode.cpp | 15 +++++- .../operations/COM_ChannelMatteOperation.cpp | 6 +-- .../operations/COM_ChromaMatteOperation.cpp | 4 +- .../operations/COM_ColorMatteOperation.cpp | 4 +- .../operations/COM_DistanceRGBMatteOperation.cpp | 4 +- .../operations/COM_KeyingSetAlphaOperation.cpp | 55 ---------------------- .../operations/COM_KeyingSetAlphaOperation.h | 39 --------------- .../operations/COM_LuminanceMatteOperation.cpp | 4 +- .../operations/COM_SetAlphaMultiplyOperation.cpp | 55 ++++++++++++++++++++++ .../operations/COM_SetAlphaMultiplyOperation.h | 40 ++++++++++++++++ .../operations/COM_SetAlphaOperation.cpp | 54 --------------------- .../compositor/operations/COM_SetAlphaOperation.h | 45 ------------------ .../operations/COM_SetAlphaReplaceOperation.cpp | 53 +++++++++++++++++++++ .../operations/COM_SetAlphaReplaceOperation.h | 45 ++++++++++++++++++ 23 files changed, 238 insertions(+), 227 deletions(-) delete mode 100644 source/blender/compositor/operations/COM_KeyingSetAlphaOperation.cpp delete mode 100644 source/blender/compositor/operations/COM_KeyingSetAlphaOperation.h create mode 100644 source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.cpp create mode 100644 source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.h delete mode 100644 source/blender/compositor/operations/COM_SetAlphaOperation.cpp delete mode 100644 source/blender/compositor/operations/COM_SetAlphaOperation.h create mode 100644 source/blender/compositor/operations/COM_SetAlphaReplaceOperation.cpp create mode 100644 source/blender/compositor/operations/COM_SetAlphaReplaceOperation.h (limited to 'source/blender/compositor') diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index 26d29f72efb..19eeb90c822 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -355,8 +355,6 @@ set(SRC operations/COM_KeyingDespillOperation.h operations/COM_KeyingOperation.cpp operations/COM_KeyingOperation.h - operations/COM_KeyingSetAlphaOperation.cpp - operations/COM_KeyingSetAlphaOperation.h operations/COM_ColorSpillOperation.cpp operations/COM_ColorSpillOperation.h @@ -461,8 +459,10 @@ set(SRC operations/COM_MapRangeOperation.h operations/COM_MapValueOperation.cpp operations/COM_MapValueOperation.h - operations/COM_SetAlphaOperation.cpp - operations/COM_SetAlphaOperation.h + operations/COM_SetAlphaMultiplyOperation.cpp + operations/COM_SetAlphaMultiplyOperation.h + operations/COM_SetAlphaReplaceOperation.cpp + operations/COM_SetAlphaReplaceOperation.h # Distort operation operations/COM_DisplaceOperation.cpp diff --git a/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp b/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp index c927865489b..598cd7b7745 100644 --- a/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp @@ -20,7 +20,7 @@ #include "BKE_node.h" #include "COM_ChannelMatteOperation.h" #include "COM_ConvertOperation.h" -#include "COM_SetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" ChannelMatteNode::ChannelMatteNode(bNode *editorNode) : Node(editorNode) { @@ -64,7 +64,7 @@ void ChannelMatteNode::convertToOperations(NodeConverter &converter, operation->setSettings((NodeChroma *)node->storage, node->custom2); converter.addOperation(operation); - SetAlphaOperation *operationAlpha = new SetAlphaOperation(); + SetAlphaMultiplyOperation *operationAlpha = new SetAlphaMultiplyOperation(); converter.addOperation(operationAlpha); if (convert != nullptr) { diff --git a/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp b/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp index 75d161d7d4d..83e88b35f92 100644 --- a/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_ChromaMatteNode.cpp @@ -20,7 +20,7 @@ #include "BKE_node.h" #include "COM_ChromaMatteOperation.h" #include "COM_ConvertOperation.h" -#include "COM_SetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" ChromaMatteNode::ChromaMatteNode(bNode *editorNode) : Node(editorNode) { @@ -48,7 +48,7 @@ void ChromaMatteNode::convertToOperations(NodeConverter &converter, operation->setSettings((NodeChroma *)editorsnode->storage); converter.addOperation(operation); - SetAlphaOperation *operationAlpha = new SetAlphaOperation(); + SetAlphaMultiplyOperation *operationAlpha = new SetAlphaMultiplyOperation(); converter.addOperation(operationAlpha); converter.mapInputSocket(inputSocketImage, operationRGBToYCC_Image->getInputSocket(0)); diff --git a/source/blender/compositor/nodes/COM_ColorMatteNode.cpp b/source/blender/compositor/nodes/COM_ColorMatteNode.cpp index f5cb84975e9..865eee5427f 100644 --- a/source/blender/compositor/nodes/COM_ColorMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_ColorMatteNode.cpp @@ -20,7 +20,7 @@ #include "BKE_node.h" #include "COM_ColorMatteOperation.h" #include "COM_ConvertOperation.h" -#include "COM_SetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" ColorMatteNode::ColorMatteNode(bNode *editorNode) : Node(editorNode) { @@ -46,7 +46,7 @@ void ColorMatteNode::convertToOperations(NodeConverter &converter, operation->setSettings((NodeChroma *)editorsnode->storage); converter.addOperation(operation); - SetAlphaOperation *operationAlpha = new SetAlphaOperation(); + SetAlphaMultiplyOperation *operationAlpha = new SetAlphaMultiplyOperation(); converter.addOperation(operationAlpha); converter.mapInputSocket(inputSocketImage, operationRGBToHSV_Image->getInputSocket(0)); diff --git a/source/blender/compositor/nodes/COM_CryptomatteNode.cpp b/source/blender/compositor/nodes/COM_CryptomatteNode.cpp index 7ca4e1f76fc..27ef98af8f3 100644 --- a/source/blender/compositor/nodes/COM_CryptomatteNode.cpp +++ b/source/blender/compositor/nodes/COM_CryptomatteNode.cpp @@ -19,13 +19,13 @@ #include "COM_CryptomatteNode.h" #include "COM_ConvertOperation.h" #include "COM_CryptomatteOperation.h" -#include "COM_SetAlphaOperation.h" #include "BLI_assert.h" #include "BLI_hash_mm3.h" #include "BLI_listbase.h" #include "BLI_string.h" +#include "COM_SetAlphaMultiplyOperation.h" #include CryptomatteNode::CryptomatteNode(bNode *editorNode) : Node(editorNode) @@ -61,13 +61,13 @@ void CryptomatteNode::convertToOperations(NodeConverter &converter, separateOperation->setChannel(3); converter.addOperation(separateOperation); - SetAlphaOperation *operationAlpha = new SetAlphaOperation(); + SetAlphaMultiplyOperation *operationAlpha = new SetAlphaMultiplyOperation(); converter.addOperation(operationAlpha); converter.addLink(operation->getOutputSocket(0), separateOperation->getInputSocket(0)); converter.addLink(separateOperation->getOutputSocket(0), operationAlpha->getInputSocket(1)); - SetAlphaOperation *clearAlphaOperation = new SetAlphaOperation(); + SetAlphaMultiplyOperation *clearAlphaOperation = new SetAlphaMultiplyOperation(); converter.addOperation(clearAlphaOperation); converter.addInputValue(clearAlphaOperation->getInputSocket(1), 1.0f); diff --git a/source/blender/compositor/nodes/COM_DifferenceMatteNode.cpp b/source/blender/compositor/nodes/COM_DifferenceMatteNode.cpp index b579502e068..3d538e9b4a0 100644 --- a/source/blender/compositor/nodes/COM_DifferenceMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_DifferenceMatteNode.cpp @@ -19,7 +19,7 @@ #include "COM_DifferenceMatteNode.h" #include "BKE_node.h" #include "COM_DifferenceMatteOperation.h" -#include "COM_SetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" DifferenceMatteNode::DifferenceMatteNode(bNode *editorNode) : Node(editorNode) { @@ -43,7 +43,7 @@ void DifferenceMatteNode::convertToOperations(NodeConverter &converter, converter.mapInputSocket(inputSocket2, operationSet->getInputSocket(1)); converter.mapOutputSocket(outputSocketMatte, operationSet->getOutputSocket(0)); - SetAlphaOperation *operation = new SetAlphaOperation(); + SetAlphaMultiplyOperation *operation = new SetAlphaMultiplyOperation(); converter.addOperation(operation); converter.mapInputSocket(inputSocket, operation->getInputSocket(0)); diff --git a/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp b/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp index 946d55d33fc..37aeb5c8504 100644 --- a/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp @@ -21,7 +21,7 @@ #include "COM_ConvertOperation.h" #include "COM_DistanceRGBMatteOperation.h" #include "COM_DistanceYCCMatteOperation.h" -#include "COM_SetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" DistanceMatteNode::DistanceMatteNode(bNode *editorNode) : Node(editorNode) { @@ -39,7 +39,7 @@ void DistanceMatteNode::convertToOperations(NodeConverter &converter, NodeOutput *outputSocketImage = this->getOutputSocket(0); NodeOutput *outputSocketMatte = this->getOutputSocket(1); - SetAlphaOperation *operationAlpha = new SetAlphaOperation(); + SetAlphaMultiplyOperation *operationAlpha = new SetAlphaMultiplyOperation(); converter.addOperation(operationAlpha); /* work in RGB color space */ diff --git a/source/blender/compositor/nodes/COM_KeyingNode.cpp b/source/blender/compositor/nodes/COM_KeyingNode.cpp index 9f0cdcbd552..4e81a412c29 100644 --- a/source/blender/compositor/nodes/COM_KeyingNode.cpp +++ b/source/blender/compositor/nodes/COM_KeyingNode.cpp @@ -32,7 +32,7 @@ #include "COM_DilateErodeOperation.h" -#include "COM_KeyingSetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" #include "COM_GaussianAlphaXBlurOperation.h" #include "COM_GaussianAlphaYBlurOperation.h" @@ -323,7 +323,7 @@ void KeyingNode::convertToOperations(NodeConverter &converter, } /* set alpha channel to output image */ - KeyingSetAlphaOperation *alphaOperation = new KeyingSetAlphaOperation(); + SetAlphaMultiplyOperation *alphaOperation = new SetAlphaMultiplyOperation(); converter.addOperation(alphaOperation); converter.mapInputSocket(inputImage, alphaOperation->getInputSocket(0)); diff --git a/source/blender/compositor/nodes/COM_LuminanceMatteNode.cpp b/source/blender/compositor/nodes/COM_LuminanceMatteNode.cpp index e435cefeefe..8bfea1eff49 100644 --- a/source/blender/compositor/nodes/COM_LuminanceMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_LuminanceMatteNode.cpp @@ -20,7 +20,7 @@ #include "BKE_node.h" #include "COM_ConvertOperation.h" #include "COM_LuminanceMatteOperation.h" -#include "COM_SetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" LuminanceMatteNode::LuminanceMatteNode(bNode *editorNode) : Node(editorNode) { @@ -42,7 +42,7 @@ void LuminanceMatteNode::convertToOperations(NodeConverter &converter, converter.mapInputSocket(inputSocket, operationSet->getInputSocket(0)); converter.mapOutputSocket(outputSocketMatte, operationSet->getOutputSocket(0)); - SetAlphaOperation *operation = new SetAlphaOperation(); + SetAlphaMultiplyOperation *operation = new SetAlphaMultiplyOperation(); converter.addOperation(operation); converter.mapInputSocket(inputSocket, operation->getInputSocket(0)); diff --git a/source/blender/compositor/nodes/COM_SetAlphaNode.cpp b/source/blender/compositor/nodes/COM_SetAlphaNode.cpp index 7b722fe4440..233a5e96ff4 100644 --- a/source/blender/compositor/nodes/COM_SetAlphaNode.cpp +++ b/source/blender/compositor/nodes/COM_SetAlphaNode.cpp @@ -18,12 +18,23 @@ #include "COM_SetAlphaNode.h" #include "COM_ExecutionSystem.h" -#include "COM_SetAlphaOperation.h" +#include "COM_SetAlphaMultiplyOperation.h" +#include "COM_SetAlphaReplaceOperation.h" void SetAlphaNode::convertToOperations(NodeConverter &converter, const CompositorContext & /*context*/) const { - SetAlphaOperation *operation = new SetAlphaOperation(); + const bNode *editorNode = this->getbNode(); + const NodeSetAlpha *storage = static_cast(editorNode->storage); + NodeOperation *operation = nullptr; + switch (storage->mode) { + case CMP_NODE_SETALPHA_MODE_APPLY: + operation = new SetAlphaMultiplyOperation(); + break; + case CMP_NODE_SETALPHA_MODE_REPLACE_ALPHA: + operation = new SetAlphaReplaceOperation(); + break; + } if (!this->getInputSocket(0)->isLinked() && this->getInputSocket(1)->isLinked()) { operation->setResolutionInputSocketIndex(1); diff --git a/source/blender/compositor/operations/COM_ChannelMatteOperation.cpp b/source/blender/compositor/operations/COM_ChannelMatteOperation.cpp index 956a2cc86ee..a2c6fd47771 100644 --- a/source/blender/compositor/operations/COM_ChannelMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_ChannelMatteOperation.cpp @@ -111,10 +111,10 @@ void ChannelMatteOperation::executePixelSampled(float output[4], alpha = (alpha - limit_min) / limit_range; } - /* store matte(alpha) value in [0] to go with - * COM_SetAlphaOperation and the Value output + /* Store matte(alpha) value in [0] to go with + * COM_SetAlphaMultiplyOperation and the Value output. */ - /* don't make something that was more transparent less transparent */ + /* Don't make something that was more transparent less transparent. */ output[0] = min(alpha, inColor[3]); } diff --git a/source/blender/compositor/operations/COM_ChromaMatteOperation.cpp b/source/blender/compositor/operations/COM_ChromaMatteOperation.cpp index 389aeaf6fed..29e18047578 100644 --- a/source/blender/compositor/operations/COM_ChromaMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_ChromaMatteOperation.cpp @@ -60,8 +60,8 @@ void ChromaMatteOperation::executePixelSampled(float output[4], this->m_inputKeyProgram->readSampled(inKey, x, y, sampler); this->m_inputImageProgram->readSampled(inImage, x, y, sampler); - /* store matte(alpha) value in [0] to go with - * COM_SetAlphaOperation and the Value output + /* Store matte(alpha) value in [0] to go with + * COM_SetAlphaMultiplyOperation and the Value output. */ /* Algorithm from book "Video Demistified," does not include the spill reduction part */ diff --git a/source/blender/compositor/operations/COM_ColorMatteOperation.cpp b/source/blender/compositor/operations/COM_ColorMatteOperation.cpp index b8749bec4b8..17ada8d89b2 100644 --- a/source/blender/compositor/operations/COM_ColorMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_ColorMatteOperation.cpp @@ -58,8 +58,8 @@ void ColorMatteOperation::executePixelSampled(float output[4], this->m_inputImageProgram->readSampled(inColor, x, y, sampler); this->m_inputKeyProgram->readSampled(inKey, x, y, sampler); - /* store matte(alpha) value in [0] to go with - * COM_SetAlphaOperation and the Value output + /* Store matte(alpha) value in [0] to go with + * COM_SetAlphaMultiplyOperation and the Value output. */ if ( diff --git a/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cpp b/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cpp index 7d79dcc657d..ecc2fc2e85f 100644 --- a/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_DistanceRGBMatteOperation.cpp @@ -65,8 +65,8 @@ void DistanceRGBMatteOperation::executePixelSampled(float output[4], distance = this->calculateDistance(inKey, inImage); - /* store matte(alpha) value in [0] to go with - * COM_SetAlphaOperation and the Value output + /* Store matte(alpha) value in [0] to go with + * COM_SetAlphaMultiplyOperation and the Value output. */ /*make 100% transparent */ diff --git a/source/blender/compositor/operations/COM_KeyingSetAlphaOperation.cpp b/source/blender/compositor/operations/COM_KeyingSetAlphaOperation.cpp deleted file mode 100644 index 47daef8d190..00000000000 --- a/source/blender/compositor/operations/COM_KeyingSetAlphaOperation.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright 2020, Blender Foundation. - */ - -#include "COM_KeyingSetAlphaOperation.h" - -KeyingSetAlphaOperation::KeyingSetAlphaOperation() -{ - this->addInputSocket(COM_DT_COLOR); - this->addInputSocket(COM_DT_VALUE); - this->addOutputSocket(COM_DT_COLOR); - - this->m_inputColor = nullptr; - this->m_inputAlpha = nullptr; -} - -void KeyingSetAlphaOperation::initExecution() -{ - this->m_inputColor = getInputSocketReader(0); - this->m_inputAlpha = getInputSocketReader(1); -} - -void KeyingSetAlphaOperation::executePixelSampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float color_input[4]; - float alpha_input[4]; - - this->m_inputColor->readSampled(color_input, x, y, sampler); - this->m_inputAlpha->readSampled(alpha_input, x, y, sampler); - - mul_v4_v4fl(output, color_input, alpha_input[0]); -} - -void KeyingSetAlphaOperation::deinitExecution() -{ - this->m_inputColor = nullptr; - this->m_inputAlpha = nullptr; -} diff --git a/source/blender/compositor/operations/COM_KeyingSetAlphaOperation.h b/source/blender/compositor/operations/COM_KeyingSetAlphaOperation.h deleted file mode 100644 index b786240f215..00000000000 --- a/source/blender/compositor/operations/COM_KeyingSetAlphaOperation.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright 2020, Blender Foundation. - */ - -#pragma once - -#include "COM_NodeOperation.h" - -/** - * Operation which is used by keying node to modify image's alpha channels. - * It keeps color properly pre-multiplied. - */ -class KeyingSetAlphaOperation : public NodeOperation { - private: - SocketReader *m_inputColor; - SocketReader *m_inputAlpha; - - public: - KeyingSetAlphaOperation(); - - void executePixelSampled(float output[4], float x, float y, PixelSampler sampler); - - void initExecution(); - void deinitExecution(); -}; diff --git a/source/blender/compositor/operations/COM_LuminanceMatteOperation.cpp b/source/blender/compositor/operations/COM_LuminanceMatteOperation.cpp index f7cc6e2d4de..096930d0a83 100644 --- a/source/blender/compositor/operations/COM_LuminanceMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_LuminanceMatteOperation.cpp @@ -68,8 +68,8 @@ void LuminanceMatteOperation::executePixelSampled(float output[4], alpha = (luminance - low) / (high - low); } - /* store matte(alpha) value in [0] to go with - * COM_SetAlphaOperation and the Value output + /* Store matte(alpha) value in [0] to go with + * COM_SetAlphaMultiplyOperation and the Value output. */ /* don't make something that was more transparent less transparent */ diff --git a/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.cpp b/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.cpp new file mode 100644 index 00000000000..3853a953c26 --- /dev/null +++ b/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.cpp @@ -0,0 +1,55 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2011, Blender Foundation. + */ + +#include "COM_SetAlphaMultiplyOperation.h" + +SetAlphaMultiplyOperation::SetAlphaMultiplyOperation() +{ + this->addInputSocket(COM_DT_COLOR); + this->addInputSocket(COM_DT_VALUE); + this->addOutputSocket(COM_DT_COLOR); + + this->m_inputColor = nullptr; + this->m_inputAlpha = nullptr; +} + +void SetAlphaMultiplyOperation::initExecution() +{ + this->m_inputColor = getInputSocketReader(0); + this->m_inputAlpha = getInputSocketReader(1); +} + +void SetAlphaMultiplyOperation::executePixelSampled(float output[4], + float x, + float y, + PixelSampler sampler) +{ + float color_input[4]; + float alpha_input[4]; + + this->m_inputColor->readSampled(color_input, x, y, sampler); + this->m_inputAlpha->readSampled(alpha_input, x, y, sampler); + + mul_v4_v4fl(output, color_input, alpha_input[0]); +} + +void SetAlphaMultiplyOperation::deinitExecution() +{ + this->m_inputColor = nullptr; + this->m_inputAlpha = nullptr; +} diff --git a/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.h b/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.h new file mode 100644 index 00000000000..db58b18688a --- /dev/null +++ b/source/blender/compositor/operations/COM_SetAlphaMultiplyOperation.h @@ -0,0 +1,40 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2011, Blender Foundation. + */ + +#pragma once + +#include "COM_NodeOperation.h" + +/** + * This operation will apply a mask to its input image. + * + * `output color.rgba = input color.rgba * input alpha` + */ +class SetAlphaMultiplyOperation : public NodeOperation { + private: + SocketReader *m_inputColor; + SocketReader *m_inputAlpha; + + public: + SetAlphaMultiplyOperation(); + + void executePixelSampled(float output[4], float x, float y, PixelSampler sampler); + + void initExecution(); + void deinitExecution(); +}; diff --git a/source/blender/compositor/operations/COM_SetAlphaOperation.cpp b/source/blender/compositor/operations/COM_SetAlphaOperation.cpp deleted file mode 100644 index bf8fbacbfe1..00000000000 --- a/source/blender/compositor/operations/COM_SetAlphaOperation.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright 2011, Blender Foundation. - */ - -#include "COM_SetAlphaOperation.h" - -SetAlphaOperation::SetAlphaOperation() -{ - this->addInputSocket(COM_DT_COLOR); - this->addInputSocket(COM_DT_VALUE); - this->addOutputSocket(COM_DT_COLOR); - - this->m_inputColor = nullptr; - this->m_inputAlpha = nullptr; -} - -void SetAlphaOperation::initExecution() -{ - this->m_inputColor = getInputSocketReader(0); - this->m_inputAlpha = getInputSocketReader(1); -} - -void SetAlphaOperation::executePixelSampled(float output[4], - float x, - float y, - PixelSampler sampler) -{ - float alphaInput[4]; - - this->m_inputColor->readSampled(output, x, y, sampler); - this->m_inputAlpha->readSampled(alphaInput, x, y, sampler); - - output[3] = alphaInput[0]; -} - -void SetAlphaOperation::deinitExecution() -{ - this->m_inputColor = nullptr; - this->m_inputAlpha = nullptr; -} diff --git a/source/blender/compositor/operations/COM_SetAlphaOperation.h b/source/blender/compositor/operations/COM_SetAlphaOperation.h deleted file mode 100644 index a84fb0f2228..00000000000 --- a/source/blender/compositor/operations/COM_SetAlphaOperation.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * Copyright 2011, Blender Foundation. - */ - -#pragma once - -#include "COM_NodeOperation.h" - -/** - * this program converts an input color to an output value. - * it assumes we are in sRGB color space. - */ -class SetAlphaOperation : public NodeOperation { - private: - SocketReader *m_inputColor; - SocketReader *m_inputAlpha; - - public: - /** - * Default constructor - */ - SetAlphaOperation(); - - /** - * the inner loop of this program - */ - void executePixelSampled(float output[4], float x, float y, PixelSampler sampler); - - void initExecution(); - void deinitExecution(); -}; diff --git a/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.cpp b/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.cpp new file mode 100644 index 00000000000..cd6e82902cc --- /dev/null +++ b/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.cpp @@ -0,0 +1,53 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2011, Blender Foundation. + */ + +#include "COM_SetAlphaReplaceOperation.h" + +SetAlphaReplaceOperation::SetAlphaReplaceOperation() +{ + this->addInputSocket(COM_DT_COLOR); + this->addInputSocket(COM_DT_VALUE); + this->addOutputSocket(COM_DT_COLOR); + + this->m_inputColor = nullptr; + this->m_inputAlpha = nullptr; +} + +void SetAlphaReplaceOperation::initExecution() +{ + this->m_inputColor = getInputSocketReader(0); + this->m_inputAlpha = getInputSocketReader(1); +} + +void SetAlphaReplaceOperation::executePixelSampled(float output[4], + float x, + float y, + PixelSampler sampler) +{ + float alpha_input[4]; + + this->m_inputColor->readSampled(output, x, y, sampler); + this->m_inputAlpha->readSampled(alpha_input, x, y, sampler); + output[3] = alpha_input[0]; +} + +void SetAlphaReplaceOperation::deinitExecution() +{ + this->m_inputColor = nullptr; + this->m_inputAlpha = nullptr; +} diff --git a/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.h b/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.h new file mode 100644 index 00000000000..b4cab82855b --- /dev/null +++ b/source/blender/compositor/operations/COM_SetAlphaReplaceOperation.h @@ -0,0 +1,45 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2011, Blender Foundation. + */ + +#pragma once + +#include "COM_NodeOperation.h" + +/** + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. + */ +class SetAlphaReplaceOperation : public NodeOperation { + private: + SocketReader *m_inputColor; + SocketReader *m_inputAlpha; + + public: + /** + * Default constructor + */ + SetAlphaReplaceOperation(); + + /** + * the inner loop of this program + */ + void executePixelSampled(float output[4], float x, float y, PixelSampler sampler); + + void initExecution(); + void deinitExecution(); +}; -- cgit v1.2.3