Hey Blender Coders,
The attached patch introduces a new node called "ASC-CDL Saturation"
that implements the saturation function as discribed by the ASC Color
Decision List (ASC CDL) Transfer Functions and Interchange Syntax
(v1.2) spec.
This is the first patch I've ever done, so there may be some cargo
cult programming as I have based the node on CMP_gamma.c and the
registration of it on various commits. Also, the algorithm is adapted
from the ASC-CDL reference code.
There is one caviate however. The output from blender does not match
the reference spec. I suspect that this is due to some issue with
blender's image or color management. That said, the node still does a
"good enough" job of desaturating an image.
I have attached an image showing the discrepancy on the patch tracker.
http://projects.blender.org/tracker/index.php?func=detail&aid=25695&group_id=9&atid=127
Cheers,
Andrew
=== modified file 'source/blender/blenkernel/BKE_node.h'
--- source/blender/blenkernel/BKE_node.h 2010-12-04 13:00:28 +0000
+++ source/blender/blenkernel/BKE_node.h 2011-01-17 23:52:27 +0000
@@ -361,6 +361,7 @@
#define CMP_NODE_COLOR_MATTE 259
#define CMP_NODE_COLORBALANCE 260
#define CMP_NODE_HUECORRECT 261
+#define CMP_NODE_SATURATION 262
#define CMP_NODE_GLARE 301
#define CMP_NODE_TONEMAP 302
=== modified file 'source/blender/blenkernel/intern/node.c'
--- source/blender/blenkernel/intern/node.c 2011-01-08 11:08:51 +0000
+++ source/blender/blenkernel/intern/node.c 2011-01-18 01:15:08 +0000
@@ -3229,6 +3229,7 @@
nodeRegisterType(ntypelist, &cmp_node_zcombine);
nodeRegisterType(ntypelist, &cmp_node_colorbalance);
nodeRegisterType(ntypelist, &cmp_node_huecorrect);
+ nodeRegisterType(ntypelist, &cmp_node_saturation);
nodeRegisterType(ntypelist, &cmp_node_normal);
nodeRegisterType(ntypelist, &cmp_node_curve_vec);
=== modified file 'source/blender/makesdna/DNA_node_types.h'
--- source/blender/makesdna/DNA_node_types.h 2010-08-25 02:18:37 +0000
+++ source/blender/makesdna/DNA_node_types.h 2011-01-18 00:00:22 +0000
@@ -324,6 +324,10 @@
float uspillr, uspillg, uspillb;
}NodeColorspill;
+typedef struct NodeSaturation {
+ double luma;
+} NodeSaturation;
+
/* TEX_output */
typedef struct TexNodeOutput {
char name[32];
=== modified file 'source/blender/makesrna/intern/rna_nodetree.c'
--- source/blender/makesrna/intern/rna_nodetree.c 2011-01-16 18:38:54 +0000
+++ source/blender/makesrna/intern/rna_nodetree.c 2011-01-18 00:24:02 +0000
@@ -2200,6 +2200,11 @@
RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
}
+static void def_cmp_saturation(StructRNA *srna)
+{
+
+}
+
static void def_cmp_zcombine(StructRNA *srna)
{
PropertyRNA *prop;
=== modified file 'source/blender/makesrna/intern/rna_nodetree_types.h'
--- source/blender/makesrna/intern/rna_nodetree_types.h 2010-12-13 21:17:00 +0000
+++ source/blender/makesrna/intern/rna_nodetree_types.h 2011-01-18 00:25:17 +0000
@@ -109,6 +109,7 @@
DefNode( CompositorNode, CMP_NODE_DIST_MATTE, def_cmp_distance_matte, "DISTANCE_MATTE", DistanceMatte, "Distance Matte", "" )
DefNode( CompositorNode, CMP_NODE_COLORBALANCE, def_cmp_colorbalance, "COLORBALANCE", ColorBalance, "Color Balance", "" )
DefNode( CompositorNode, CMP_NODE_HUECORRECT, def_cmp_huecorrect, "HUECORRECT", HueCorrect, "Hue Correct", "" )
+DefNode( CompositorNode, CMP_NODE_SATURATION, def_cmp_saturation, "SATURATION", Saturation, "ASC-CDL Saturation", "" )
DefNode( TextureNode, TEX_NODE_OUTPUT, def_tex_output, "OUTPUT", Output, "Output", "" )
DefNode( TextureNode, TEX_NODE_CHECKER, 0, "CHECKER", Checker, "Checker", "" )
=== modified file 'source/blender/nodes/CMP_node.h'
--- source/blender/nodes/CMP_node.h 2010-02-12 13:34:04 +0000
+++ source/blender/nodes/CMP_node.h 2011-01-18 00:06:07 +0000
@@ -61,6 +61,7 @@
extern bNodeType cmp_node_zcombine;
extern bNodeType cmp_node_colorbalance;
extern bNodeType cmp_node_huecorrect;
+extern bNodeType cmp_node_saturation;
extern bNodeType cmp_node_normal;
extern bNodeType cmp_node_curve_vec;
=== modified file 'source/blender/nodes/CMakeLists.txt'
--- source/blender/nodes/CMakeLists.txt 2010-12-22 23:09:30 +0000
+++ source/blender/nodes/CMakeLists.txt 2011-01-18 01:14:32 +0000
@@ -85,6 +85,7 @@
intern/CMP_nodes/CMP_sepcombYUVA.c
intern/CMP_nodes/CMP_setalpha.c
intern/CMP_nodes/CMP_splitViewer.c
+ intern/CMP_nodes/CMP_sat.c
intern/CMP_nodes/CMP_texture.c
intern/CMP_nodes/CMP_tonemap.c
intern/CMP_nodes/CMP_translate.c
=== added file 'source/blender/nodes/intern/CMP_nodes/CMP_sat.c'
--- source/blender/nodes/intern/CMP_nodes/CMP_sat.c 1970-01-01 00:00:00 +0000
+++ source/blender/nodes/intern/CMP_nodes/CMP_sat.c 2011-01-18 02:35:39 +0000
@@ -0,0 +1,116 @@
+/**
+* $Id$
+*
+* ***** BEGIN GPL LICENSE BLOCK *****
+*
+* 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.
+*
+* The Original Code is Copyright (C) 2006 Blender Foundation.
+* All rights reserved.
+*
+* The Original Code is: all of this file.
+*
+* Contributor(s): Andrew Hunter
+*
+* ***** END GPL LICENSE BLOCK *****
+
+*/
+
+#include "../CMP_util.h"
+
+/* **************** ASC-CDL Saturation ******************** */
+
+static bNodeSocketType cmp_node_saturation_in[]= {
+ { SOCK_RGBA, 1, "Image", 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f},
+ { SOCK_VALUE, 1, "Saturation", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f},
+ { -1, 0, "" }
+};
+static bNodeSocketType cmp_node_saturation_out[]= {
+ { SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
+ { -1, 0, "" }
+};
+
+/* we propose using the standard rec709 saturation coefficients... */
+double sat_coef_709[3] = { 0.2126, 0.7152, 0.0722 };
+
+
+/*
+ the saturation parameter "sat" is floating point:
+ "sat" range: 0.0 <= sat < infinity
+
+ 0.0 -> fully desaturated
+ 1.0 -> no change
+ >1.0 -> more saturation
+
+ in this implementation, the input rgb values are overwritten
+ in place with the results of the saturation calculation
+*/
+
+static void do_saturation(bNode *UNUSED(node), float *out, float *in, float *fac)
+{
+
+
+ /* compute the fully desaturated grey value */
+ double luma = in[0] * sat_coef_709[0] +
+ in[1] * sat_coef_709[1] +
+ in[2] * sat_coef_709[2] ;
+ int i=0;
+
+ for(i=0; i<3; i++) {
+ /* Output rgb is a weighted average between the input rgb and
+ the fully desaturated grey value with "sat" as the weight...*/
+ out[i] = in[i] * fac[0] + luma * (1.0 - fac[0]);
+ }
+ out[3] = in[3];
+}
+static void node_composit_exec_saturation(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **out)
+{
+ /* stack order in: Fac, Image */
+ /* stack order out: Image */
+ if(out[0]->hasoutput==0) return;
+
+ /* input no image? then only color operation */
+ if(in[0]->data==NULL) {
+ do_saturation(node, out[0]->vec, in[0]->vec, in[1]->vec);
+ }
+ else {
+ /* make output size of input image */
+ CompBuf *cbuf= in[0]->data;
+ CompBuf *stackbuf= alloc_compbuf(cbuf->x, cbuf->y, CB_RGBA, 1); // allocs
+
+ composit2_pixel_processor(node, stackbuf, cbuf, in[0]->vec, in[1]->data, in[1]->vec, do_saturation, CB_RGBA, CB_VAL);
+
+ out[0]->data= stackbuf;
+ }
+}
+
+bNodeType cmp_node_saturation= {
+ /* *next,*prev */ NULL, NULL,
+ /* type code */ CMP_NODE_SATURATION,
+ /* name */ "ASC-CDL Saturation",
+ /* width+range */ 140, 100, 320,
+ /* class+opts */ NODE_CLASS_OP_COLOR, NODE_OPTIONS,
+ /* input sock */ cmp_node_saturation_in,
+ /* output sock */ cmp_node_saturation_out,
+ /* storage */ "",
+ /* execfunc */ node_composit_exec_saturation,
+ /* butfunc */ NULL,
+ /* initfunc */ NULL,
+ /* freestoragefunc */ NULL,
+ /* copysotragefunc */ NULL,
+ /* id */ NULL
+};
+
+
_______________________________________________
Bf-committers mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-committers