[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [61162] trunk/blender/source/blender: Syncing methods for Color Balance node LGG and ASC-CDL modes.

Lukas Toenne lukas.toenne at googlemail.com
Wed Nov 6 13:44:54 CET 2013


Revision: 61162
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=61162
Author:   lukastoenne
Date:     2013-11-06 12:44:54 +0000 (Wed, 06 Nov 2013)
Log Message:
-----------
Syncing methods for Color Balance node LGG and ASC-CDL modes. The settings for either mode are converted into equivalent settings of the other. This keeps the result of both modes roughly the same and
mimics the previous behavior when settings were shared by both modes (but not equivalent).
NOTE: Due to the use of additional sRGB conversion in the LGG mode the result is not entirely accurate, this should perhaps be fixed.

Settings for each mode are kept in their own color values nevertheless, this avoids potential problems with float precision.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_blender.h
    trunk/blender/source/blender/blenkernel/BKE_node.h
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
    trunk/blender/source/blender/nodes/composite/nodes/node_composite_colorbalance.c

Modified: trunk/blender/source/blender/blenkernel/BKE_blender.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_blender.h	2013-11-06 12:44:51 UTC (rev 61161)
+++ trunk/blender/source/blender/blenkernel/BKE_blender.h	2013-11-06 12:44:54 UTC (rev 61162)
@@ -42,7 +42,7 @@
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         269
-#define BLENDER_SUBVERSION      1
+#define BLENDER_SUBVERSION      2
 /* 262 was the last editmesh release but it has compatibility code for bmesh data */
 #define BLENDER_MINVERSION      262
 #define BLENDER_MINSUBVERSION   0

Modified: trunk/blender/source/blender/blenkernel/BKE_node.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_node.h	2013-11-06 12:44:51 UTC (rev 61161)
+++ trunk/blender/source/blender/blenkernel/BKE_node.h	2013-11-06 12:44:54 UTC (rev 61162)
@@ -944,6 +944,9 @@
 void ntreeCompositOutputFileUniquePath(struct ListBase *list, struct bNodeSocket *sock, const char defname[], char delim);
 void ntreeCompositOutputFileUniqueLayer(struct ListBase *list, struct bNodeSocket *sock, const char defname[], char delim);
 
+void ntreeCompositColorBalanceSyncFromLGG(bNodeTree *ntree, bNode *node);
+void ntreeCompositColorBalanceSyncFromCDL(bNodeTree *ntree, bNode *node);
+
 /* ************** TEXTURE NODES *************** */
 
 struct TexResult;

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2013-11-06 12:44:51 UTC (rev 61161)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2013-11-06 12:44:54 UTC (rev 61162)
@@ -9783,6 +9783,33 @@
 		}
 	}
 
+	if (!MAIN_VERSION_ATLEAST(main, 269, 2)) {
+		/* Initialize CDL settings for Color Balance nodes */
+		FOREACH_NODETREE(main, ntree, id) {
+			if (ntree->type == NTREE_COMPOSIT) {
+				bNode *node;
+				for (node = ntree->nodes.first; node; node = node->next) {
+					if (node->type == CMP_NODE_COLORBALANCE) {
+						NodeColorBalance *n = node->storage;
+						if (node->custom1 == 0) {
+							/* LGG mode stays the same, just init CDL settings */
+							ntreeCompositColorBalanceSyncFromLGG(ntree, node);
+						}
+						else if (node->custom1 == 1) {
+							/* CDL previously used same variables as LGG, copy them over
+							 * and then sync LGG for comparable results in both modes.
+							 */
+							copy_v3_v3(n->offset, n->lift);
+							copy_v3_v3(n->power, n->gamma);
+							copy_v3_v3(n->slope, n->gain);
+							ntreeCompositColorBalanceSyncFromCDL(ntree, node);
+						}
+					}
+				}
+			}
+		} FOREACH_NODETREE_END
+	}
+
 	{
 		Scene *scene;
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2013-11-06 12:44:51 UTC (rev 61161)
+++ trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2013-11-06 12:44:54 UTC (rev 61162)
@@ -2693,6 +2693,18 @@
 	return ptr;
 }
 
+static void rna_NodeColorBalance_update_lgg(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+	ntreeCompositColorBalanceSyncFromLGG(ptr->id.data, ptr->data);
+	rna_Node_update(bmain, scene, ptr);
+}
+
+static void rna_NodeColorBalance_update_cdl(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+	ntreeCompositColorBalanceSyncFromCDL(ptr->id.data, ptr->data);
+	rna_Node_update(bmain, scene, ptr);
+}
+
 /* ******** Node Socket Types ******** */
 
 static PointerRNA rna_NodeOutputFile_slot_layer_get(CollectionPropertyIterator *iter)
@@ -5236,7 +5248,7 @@
 	RNA_def_property_float_array_default(prop, default_1);
 	RNA_def_property_ui_range(prop, 0, 2, 0.1, 3);
 	RNA_def_property_ui_text(prop, "Lift", "Correction for Shadows");
-	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeColorBalance_update_lgg");
 	
 	prop = RNA_def_property(srna, "gamma", PROP_FLOAT, PROP_COLOR_GAMMA);
 	RNA_def_property_float_sdna(prop, NULL, "gamma");
@@ -5244,7 +5256,7 @@
 	RNA_def_property_float_array_default(prop, default_1);
 	RNA_def_property_ui_range(prop, 0, 2, 0.1, 3);
 	RNA_def_property_ui_text(prop, "Gamma", "Correction for Midtones");
-	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeColorBalance_update_lgg");
 	
 	prop = RNA_def_property(srna, "gain", PROP_FLOAT, PROP_COLOR_GAMMA);
 	RNA_def_property_float_sdna(prop, NULL, "gain");
@@ -5252,7 +5264,7 @@
 	RNA_def_property_float_array_default(prop, default_1);
 	RNA_def_property_ui_range(prop, 0, 2, 0.1, 3);
 	RNA_def_property_ui_text(prop, "Gain", "Correction for Highlights");
-	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeColorBalance_update_lgg");
 	
 	
 	prop = RNA_def_property(srna, "offset", PROP_FLOAT, PROP_COLOR_GAMMA);
@@ -5260,7 +5272,7 @@
 	RNA_def_property_array(prop, 3);
 	RNA_def_property_ui_range(prop, 0, 1, 0.1, 3);
 	RNA_def_property_ui_text(prop, "Offset", "Correction for Shadows");
-	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeColorBalance_update_cdl");
 	
 	prop = RNA_def_property(srna, "power", PROP_FLOAT, PROP_COLOR_GAMMA);
 	RNA_def_property_float_sdna(prop, NULL, "power");
@@ -5269,7 +5281,7 @@
 	RNA_def_property_range(prop, 0.f, FLT_MAX);
 	RNA_def_property_ui_range(prop, 0, 2, 0.1, 3);
 	RNA_def_property_ui_text(prop, "Power", "Correction for Midtones");
-	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeColorBalance_update_cdl");
 	
 	prop = RNA_def_property(srna, "slope", PROP_FLOAT, PROP_COLOR_GAMMA);
 	RNA_def_property_float_sdna(prop, NULL, "slope");
@@ -5278,7 +5290,7 @@
 	RNA_def_property_range(prop, 0.f, FLT_MAX);
 	RNA_def_property_ui_range(prop, 0, 2, 0.1, 3);
 	RNA_def_property_ui_text(prop, "Slope", "Correction for Highlights");
-	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeColorBalance_update_cdl");
 }
 
 static void def_cmp_huecorrect(StructRNA *srna)

Modified: trunk/blender/source/blender/nodes/composite/nodes/node_composite_colorbalance.c
===================================================================
--- trunk/blender/source/blender/nodes/composite/nodes/node_composite_colorbalance.c	2013-11-06 12:44:51 UTC (rev 61161)
+++ trunk/blender/source/blender/nodes/composite/nodes/node_composite_colorbalance.c	2013-11-06 12:44:54 UTC (rev 61162)
@@ -46,6 +46,36 @@
 	{-1, 0, ""}
 };
 
+/* Sync functions update formula parameters for other modes, such that the result is comparable.
+ * Note that the results are not exactly the same due to differences in color handling (sRGB conversion happens for LGG),
+ * but this keeps settings comparable.
+ */
+
+void ntreeCompositColorBalanceSyncFromLGG(bNodeTree *UNUSED(ntree), bNode *node)
+{
+	NodeColorBalance *n = node->storage;
+	int c;
+	
+	for (c = 0; c < 3; ++c) {
+		n->slope[c] = (2.0f - n->lift[c]) * n->gain[c];
+		n->offset[c] = (n->lift[c] - 1.0f) * n->gain[c];
+		n->power[c] = (n->gamma[c] != 0.0f) ? 1.0f / n->gamma[c] : 1000000.0f;
+	}
+}
+
+void ntreeCompositColorBalanceSyncFromCDL(bNodeTree *UNUSED(ntree), bNode *node)
+{
+	NodeColorBalance *n = node->storage;
+	int c;
+	
+	for (c = 0; c < 3; ++c) {
+		float d = n->slope[c] + n->offset[c];
+		n->lift[c] = (d != 0.0f ? n->slope[c] + 2.0f*n->offset[c] / d : 0.0f);
+		n->gain[c] = d;
+		n->gamma[c] = (n->power[c] != 0.0f) ? 1.0f / n->power[c] : 1000000.0f;
+	}
+}
+
 static void node_composit_init_colorbalance(bNodeTree *UNUSED(ntree), bNode *node)
 {
 	NodeColorBalance *n = node->storage = MEM_callocN(sizeof(NodeColorBalance), "node colorbalance");




More information about the Bf-blender-cvs mailing list