Index: blender/source/blender/editors/space_node/drawnode.c =================================================================== --- blender/source/blender/editors/space_node/drawnode.c (revision 53911) +++ blender/source/blender/editors/space_node/drawnode.c (working copy) @@ -2520,6 +2520,16 @@ uiItemR(layout, ptr, "blur_max", 0, NULL, ICON_NONE); } +static void node_composit_buts_deband(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +{ + + uiLayout *col; + + col = uiLayoutColumn(layout, FALSE); + uiItemR(layout, ptr, "use_singlechannel", 0, NULL, ICON_NONE); + // uiItemR(layout, ptr, "f_stop", 0, NULL, ICON_NONE); // UNUSED +} + static void node_composit_backdrop_viewer(SpaceNode *snode, ImBuf *backdrop, bNode *node, int x, int y) { // node_composit_backdrop_canvas(snode, backdrop, node, x, y); @@ -2890,6 +2900,9 @@ case CMP_NODE_INVERT: ntype->uifunc = node_composit_buts_invert; break; + case CMP_NODE_DEBAND: + ntype->uifunc = node_composit_buts_deband; + break; case CMP_NODE_PREMULKEY: ntype->uifunc = node_composit_buts_premulkey; break; Index: blender/source/blender/makesdna/DNA_node_types.h =================================================================== --- blender/source/blender/makesdna/DNA_node_types.h (revision 53911) +++ blender/source/blender/makesdna/DNA_node_types.h (working copy) @@ -425,6 +425,12 @@ int pad; } ColorCorrectionData; +typedef struct Deband { + float treshold; + float radius; +} DebandData; + + typedef struct NodeColorCorrection { ColorCorrectionData master; ColorCorrectionData shadows; Index: blender/source/blender/compositor/CMakeLists.txt =================================================================== --- blender/source/blender/compositor/CMakeLists.txt (revision 53911) +++ blender/source/blender/compositor/CMakeLists.txt (working copy) @@ -291,7 +291,9 @@ nodes/COM_FilterNode.cpp nodes/COM_FilterNode.h nodes/COM_DespeckleNode.cpp - nodes/COM_DespeckleNode.h + nodes/COM_DespeckleNode.h + nodes/COM_DebandNode.cpp + nodes/COM_DebandNode.h nodes/COM_DilateErodeNode.cpp nodes/COM_DilateErodeNode.h nodes/COM_InpaintNode.cpp @@ -314,6 +316,8 @@ operations/COM_GaussianBokehBlurOperation.h operations/COM_BokehBlurOperation.cpp operations/COM_BokehBlurOperation.h + operations/COM_DebandOperation.cpp + operations/COM_DebandOperation.h operations/COM_VariableSizeBokehBlurOperation.cpp operations/COM_VariableSizeBokehBlurOperation.h operations/COM_FastGaussianBlurOperation.cpp Index: blender/source/blender/compositor/intern/COM_Converter.cpp =================================================================== --- blender/source/blender/compositor/intern/COM_Converter.cpp (revision 53911) +++ blender/source/blender/compositor/intern/COM_Converter.cpp (working copy) @@ -61,6 +61,7 @@ #include "COM_DilateErodeNode.h" #include "COM_DirectionalBlurNode.h" #include "COM_DisplaceNode.h" +#include "COM_DebandNode.h" #include "COM_DistanceMatteNode.h" #include "COM_DoubleEdgeMaskNode.h" #include "COM_EllipseMaskNode.h" @@ -313,6 +314,11 @@ case CMP_NODE_DESPECKLE: node = new DespeckleNode(b_node); break; + + case CMP_NODE_DEBAND: + node = new DebandNode(b_node); + break; + case CMP_NODE_LENSDIST: node = new LensDistortionNode(b_node); break; Index: blender/source/blender/compositor/operations/COM_DebandOperation.cpp =================================================================== --- blender/source/blender/compositor/operations/COM_DebandOperation.cpp (revision 0) +++ blender/source/blender/compositor/operations/COM_DebandOperation.cpp (working copy) @@ -0,0 +1,192 @@ +/* + * Copyright 2011, Blender Foundation. + * + * 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. + * + * Contributor: + * Björn Sonnenschein + * Jeroen Bakker + * Monique Dewanchand + */ + +#include "COM_DebandOperation.h" +#include "BLI_math_color.h" + +DebandOperation::DebandOperation() : NodeOperation() +{ + this->addInputSocket(COM_DT_COLOR); + this->addInputSocket(COM_DT_VALUE); + this->addInputSocket(COM_DT_VALUE); + this->addOutputSocket(COM_DT_COLOR); + this->m_inputProgram = NULL; + this->setSinglechannel(false); +} +void DebandOperation::initExecution() +{ + this->m_inputProgram = this->getInputSocketReader(0); + this->m_inputTresholdProgram = this->getInputSocketReader(1); + this->m_inputRadiusProgram = this->getInputSocketReader(2); +} + +void DebandOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) +{ + float v[4]; /*The pixel's RGB value*/ + float inputTreshold[4]; /* How large a banding step our codec produces may be. */ + float inputRadius[4]; /* How wide our maximal searching and blur range will be.*/ + + this->m_inputProgram->read(v, x, y, sampler); + this->m_inputTresholdProgram->read(inputTreshold, x, y, sampler); + this->m_inputRadiusProgram->read(inputRadius, x, y, sampler); + + int width = this->m_inputProgram->getWidth(); + int height = this->m_inputProgram->getHeight(); + + float treshold = inputTreshold[0]; + float radius = inputRadius[0]; + int channels; + treshold /= 100.0f; + + int i, j; + int changex = 0, changey = 0; /* Store the number of pixels in treshold we detected within our search radius */ + float valuex[4], valuey[4]; /* Store the culminated values of all detected pixels in range. Later we will divide this by the detected pixel to geht the average value */ + float v2[4]; /* The value of the pixel we currently compare with the base pixel */ + int position2; /* The position of the pixel we currently compare with the base pixel */ + + /* If we want to use the node for separate channels with a separate RGB node for example, + we only need to apply the effect to the first input channel*/ + if (this->m_singlechannel) { + channels = 1; } + + else { + channels = 3; } + + /* Look for banding steps in x and y direction. There must be at least three pixels in the treshold range + to assume our actual pixel is on a banding step. If there were only two, it might also be a pixel in a + slight gradient. If we encounter a step that is larger than treshold, we stop here because we assume that + we have reached the end of the banding area. */ + for (i=0; i < channels; i++) { + + changex = 0; + changey = 0; + valuex[i] = 0; + valuey[i] = 0; + + for (j = 1; j<= radius; j++){ + + position2 = x + j; + + if (position2 >= width) { + break;} + + + this->m_inputProgram->read(v2, position2, y, sampler); + + if ((v[i] - v2[i]) * (v[i] - v2[i]) < treshold * treshold) { + valuex[i] += v2[i]; + changex++; + } + + else { + break; } + } + + for (j = 1; j<= radius; j++){ + + position2 = x - j; + + if (position2 < 0) { + break;} + + this->m_inputProgram->read(v2, position2, y, sampler); + + if ((v[i] - v2[i]) * (v[i] - v2[i]) < treshold * treshold) { + valuex[i] += v2[i]; + changex++; + } + + else { + break; } + } + + for (j = 1; j<= radius; j++){ + + position2 = y + j; + + if (position2 >= height) { + break;} + + this->m_inputProgram->read(v2, x, position2, sampler); + + if ((v[i] - v2[i]) * (v[i] - v2[i]) < treshold * treshold) { + valuey[i] += v2[i]; + changey++; + } + + else { + break; } + } + + for (j = 1; j<= radius; j++){ + + position2 = y - j; + + if (position2 < 0) { + break;} + + this->m_inputProgram->read(v2, x, position2, sampler); + + if ((v[i] - v2[i]) * (v[i] - v2[i]) < treshold * treshold) { + valuey[i] += v2[i]; + changey++; + } + + else { + break; } + } + + /* Calculate the new Values for the pixel*/ + if ((changex >= 2) && (changey >= 2)) { + v[i] = (valuex[i] + valuey[i] + v[i]) / (changex + changey + 1); + } + + else if (changex >= 2) { + v[i] = (valuex[i] + v[i]) / (changex + 1); + } + + else if (changey >= 2) { + v[i] = (valuey[i] + v[i]) / (changey + 1); + } + + } + + output[0] = v[0]; + output[3] = v[3]; + + if (this->m_singlechannel) { + output[1] = v[0]; + output[2] = v[0];} + + else { + output[1] = v[1]; + output[2] = v[2];} +} + +void DebandOperation::deinitExecution() +{ + this->m_inputProgram = NULL; + this->m_inputTresholdProgram = NULL; + this->m_inputRadiusProgram = NULL; +} + Index: blender/source/blender/compositor/operations/COM_DebandOperation.h =================================================================== --- blender/source/blender/compositor/operations/COM_DebandOperation.h (revision 0) +++ blender/source/blender/compositor/operations/COM_DebandOperation.h (working copy) @@ -0,0 +1,61 @@ +/* + * Copyright 2011, Blender Foundation. + * + * 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. + * + * Contributor: + * Björn Sonnenschein + * Jeroen Bakker + * Monique Dewanchand + */ + +#ifndef _COM_DebandOperation_h +#define _COM_DebandOperation_h +#include "COM_NodeOperation.h" + + +class DebandOperation : public NodeOperation { +private: + /** + * Cached reference to the inputProgram + */ + SocketReader *m_inputProgram; + SocketReader *m_inputTresholdProgram; + SocketReader *m_inputRadiusProgram; + + bool m_singlechannel; + +public: + DebandOperation(); + + /** + * the inner loop of this program + */ + void executePixel(float output[4], float x, float y, PixelSampler sampler); + + /** + * Initialize the execution + */ + void initExecution(); + + /** + * Deinitialize the execution + */ + void deinitExecution(); + + void setSinglechannel(bool singlechannel) { this->m_singlechannel = singlechannel; } + +}; +#endif Index: blender/source/blender/compositor/nodes/COM_DebandNode.h =================================================================== --- blender/source/blender/compositor/nodes/COM_DebandNode.h (revision 0) +++ blender/source/blender/compositor/nodes/COM_DebandNode.h (working copy) @@ -0,0 +1,39 @@ +/* + * Copyright 2011, Blender Foundation. + * + * 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. + * + * Contributor: + * Björn Sonnenschein + * Jeroen Bakker + * Monique Dewanchand + */ + +#ifndef _COM_DebandNode_h_ +#define _COM_DebandNode_h_ + +#include "COM_Node.h" + +/** + * @brief DebandNode + * @ingroup Node + */ +class DebandNode : public Node { +public: + DebandNode(bNode *editorNode); + void convertToOperations(ExecutionSystem *graph, CompositorContext *context); +}; + +#endif Index: blender/source/blender/compositor/nodes/COM_DebandNode.cpp =================================================================== --- blender/source/blender/compositor/nodes/COM_DebandNode.cpp (revision 0) +++ blender/source/blender/compositor/nodes/COM_DebandNode.cpp (working copy) @@ -0,0 +1,44 @@ +/* + * Copyright 2011, Blender Foundation. + * + * 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. + * + * Contributor: + * Björn Sonnenschein + * Jeroen Bakker + * Monique Dewanchand + */ + +#include "COM_DebandNode.h" +#include "COM_DebandOperation.h" +#include "COM_ExecutionSystem.h" + +DebandNode::DebandNode(bNode *editorNode) : Node(editorNode) +{ + /* pass */ +} + +void DebandNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) +{ + DebandOperation *operation = new DebandOperation(); + bNode *node = this->getbNode(); + operation->setSinglechannel(node->custom1); + + this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); + this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph); + this->getInputSocket(2)->relinkConnections(operation->getInputSocket(2), 2, graph); + this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0)); + graph->addOperation(operation); +} Index: blender/source/blender/makesrna/RNA_access.h =================================================================== --- blender/source/blender/makesrna/RNA_access.h (revision 53911) +++ blender/source/blender/makesrna/RNA_access.h (working copy) @@ -130,6 +130,7 @@ extern StructRNA RNA_CompositorNodeCurveRGB; extern StructRNA RNA_CompositorNodeCurveVec; extern StructRNA RNA_CompositorNodeDBlur; +extern StructRNA RNA_CompositorNodeDeband; extern StructRNA RNA_CompositorNodeDefocus; extern StructRNA RNA_CompositorNodeDiffMatte; extern StructRNA RNA_CompositorNodeDilateErode; Index: blender/source/blender/makesrna/intern/rna_nodetree.c =================================================================== --- blender/source/blender/makesrna/intern/rna_nodetree.c (revision 53911) +++ blender/source/blender/makesrna/intern/rna_nodetree.c (working copy) @@ -3873,6 +3873,15 @@ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); } +static void def_cmp_deband(StructRNA *srna) +{ + PropertyRNA *prop; + prop = RNA_def_property(srna, "use_singlechannel", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "custom1", 0); + RNA_def_property_ui_text(prop, "Single Channel", "Support variable blue per-pixel when using an image for size input"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); +} + static void def_cmp_colorcorrection(StructRNA *srna) { PropertyRNA *prop; Index: blender/source/blender/makesrna/intern/rna_nodetree_types.h =================================================================== --- blender/source/blender/makesrna/intern/rna_nodetree_types.h (revision 53911) +++ blender/source/blender/makesrna/intern/rna_nodetree_types.h (working copy) @@ -154,6 +154,7 @@ DefNode( CompositorNode, CMP_NODE_MATH, def_math, "MATH", Math, "Math", "" ) DefNode( CompositorNode, CMP_NODE_LUMA_MATTE, def_cmp_luma_matte, "LUMA_MATTE", LumaMatte, "Luminance Key", "" ) DefNode( CompositorNode, CMP_NODE_BRIGHTCONTRAST, 0, "BRIGHTCONTRAST", BrightContrast, "Bright/Contrast", "" ) +DefNode( CompositorNode, CMP_NODE_DEBAND, def_cmp_deband, "DEBAND", Deband, "Deband", "" ) DefNode( CompositorNode, CMP_NODE_GAMMA, 0, "GAMMA", Gamma, "Gamma", "" ) DefNode( CompositorNode, CMP_NODE_INVERT, def_cmp_invert, "INVERT", Invert, "Invert", "" ) DefNode( CompositorNode, CMP_NODE_NORMALIZE, 0, "NORMALIZE", Normalize, "Normalize", "" ) Index: blender/source/blender/nodes/CMakeLists.txt =================================================================== --- blender/source/blender/nodes/CMakeLists.txt (revision 53911) +++ blender/source/blender/nodes/CMakeLists.txt (working copy) @@ -62,6 +62,7 @@ composite/nodes/node_composite_despeckle.c composite/nodes/node_composite_doubleEdgeMask.c composite/nodes/node_composite_defocus.c + composite/nodes/node_composite_deband.c composite/nodes/node_composite_diffMatte.c composite/nodes/node_composite_dilate.c composite/nodes/node_composite_directionalblur.c Index: blender/source/blender/nodes/NOD_composite.h =================================================================== --- blender/source/blender/nodes/NOD_composite.h (revision 53911) +++ blender/source/blender/nodes/NOD_composite.h (working copy) @@ -81,6 +81,7 @@ void register_node_type_cmp_dilateerode(struct bNodeTreeType *ttype); void register_node_type_cmp_inpaint(struct bNodeTreeType *ttype); void register_node_type_cmp_despeckle(struct bNodeTreeType *ttype); +void register_node_type_cmp_deband(struct bNodeTreeType *ttype); void register_node_type_cmp_defocus(struct bNodeTreeType *ttype); void register_node_type_cmp_valtorgb(struct bNodeTreeType *ttype); Index: blender/source/blender/blenkernel/BKE_node.h =================================================================== --- blender/source/blender/blenkernel/BKE_node.h (revision 53911) +++ blender/source/blender/blenkernel/BKE_node.h (working copy) @@ -694,6 +694,7 @@ #define CMP_NODE_TRACKPOS 271 #define CMP_NODE_INPAINT 272 #define CMP_NODE_DESPECKLE 273 +#define CMP_NODE_DEBAND 274 #define CMP_NODE_GLARE 301 #define CMP_NODE_TONEMAP 302 Index: blender/source/blender/blenkernel/intern/node.c =================================================================== --- blender/source/blender/blenkernel/intern/node.c (revision 53911) +++ blender/source/blender/blenkernel/intern/node.c (working copy) @@ -2226,6 +2226,7 @@ register_node_type_cmp_inpaint(ttype); register_node_type_cmp_despeckle(ttype); register_node_type_cmp_defocus(ttype); + register_node_type_cmp_deband(ttype); register_node_type_cmp_valtorgb(ttype); register_node_type_cmp_rgbtobw(ttype);