[Bf-blender-cvs] [ac58a7fa19] master: Compositor: Make HSV node inputs a real sockets

Sergey Sharybin noreply at git.blender.org
Thu Jan 26 15:26:28 CET 2017


Commit: ac58a7fa190de82ee8265cfe9f1b7a7323b86982
Author: Sergey Sharybin
Date:   Wed Dec 7 13:52:12 2016 +0100
Branches: master
https://developer.blender.org/rBac58a7fa190de82ee8265cfe9f1b7a7323b86982

Compositor: Make HSV node inputs a real sockets

This is much more flexible solution which will allow doing some
more procedural features.

Reviewers: brecht, dfelinto, mont29

Reviewed By: mont29

Subscribers: Severin

Differential Revision: https://developer.blender.org/D2403

===================================================================

M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/readfile.h
M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/compositor/nodes/COM_HueSaturationValueNode.cpp
M	source/blender/compositor/operations/COM_ChangeHSVOperation.cpp
M	source/blender/compositor/operations/COM_ChangeHSVOperation.h
M	source/blender/editors/space_node/drawnode.c
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/NOD_static_types.h
M	source/blender/nodes/composite/nodes/node_composite_hueSatVal.c

===================================================================

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 4396fa218b..dce079ff20 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8393,9 +8393,10 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
 
 static void do_versions_after_linking(Main *main)
 {
-	UNUSED_VARS(main);
 //	printf("%s for %s (%s), %d.%d\n", __func__, main->curlib ? main->curlib->name : main->name,
 //	       main->curlib ? "LIB" : "MAIN", main->versionfile, main->subversionfile);
+
+	do_versions_after_linking_270(main);
 }
 
 static void lib_link_all(FileData *fd, Main *main)
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index 7719aaa2b0..d97bef13a7 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -170,5 +170,7 @@ void blo_do_versions_250(struct FileData *fd, struct Library *lib, struct Main *
 void blo_do_versions_260(struct FileData *fd, struct Library *lib, struct Main *main);
 void blo_do_versions_270(struct FileData *fd, struct Library *lib, struct Main *main);
 
+void do_versions_after_linking_270(struct Main *main);
+
 #endif
 
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index 805542c35a..c9ea077e6f 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -34,6 +34,7 @@
 /* allow readfile to use deprecated functionality */
 #define DNA_DEPRECATED_ALLOW
 
+#include "DNA_anim_types.h"
 #include "DNA_armature_types.h"
 #include "DNA_brush_types.h"
 #include "DNA_camera_types.h"
@@ -58,6 +59,7 @@
 
 #include "DNA_genfile.h"
 
+#include "BKE_animsys.h"
 #include "BKE_colortools.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
@@ -76,6 +78,9 @@
 
 #include "BLO_readfile.h"
 
+#include "NOD_common.h"
+#include "NOD_socket.h"
+
 #include "readfile.h"
 
 #include "MEM_guardedalloc.h"
@@ -195,6 +200,50 @@ static void do_version_bones_super_bbone(ListBase *lb)
 	}
 }
 
+/* TODO(sergey): Consider making it somewhat more generic function in BLI_anim.h. */
+static void anim_change_prop_name(FCurve *fcu,
+                                  const char *prefix,
+                                  const char *old_prop_name,
+                                  const char *new_prop_name)
+{
+	const char *old_path = BLI_sprintfN("%s.%s", prefix, old_prop_name);
+	if (STREQ(fcu->rna_path, old_path)) {
+		MEM_freeN(fcu->rna_path);
+		fcu->rna_path = BLI_sprintfN("%s.%s", prefix, new_prop_name);
+	}
+	MEM_freeN((char *)old_path);
+}
+
+static void do_version_hue_sat_node(bNodeTree *ntree, bNode *node)
+{
+	/* Make sure new sockets are properly created. */
+	node_verify_socket_templates(ntree, node);
+	/* Convert value from old storage to new sockets. */
+	NodeHueSat *nhs = node->storage;
+	bNodeSocket *hue = nodeFindSocket(node, SOCK_IN, "Hue"),
+	            *saturation = nodeFindSocket(node, SOCK_IN, "Saturation"),
+	            *value = nodeFindSocket(node, SOCK_IN, "Value");
+	((bNodeSocketValueFloat *)hue->default_value)->value = nhs->hue;
+	((bNodeSocketValueFloat *)saturation->default_value)->value = nhs->sat;
+	((bNodeSocketValueFloat *)value->default_value)->value = nhs->val;
+	/* Take care of possible animation. */
+	AnimData *adt = BKE_animdata_from_id(&ntree->id);
+	if (adt != NULL && adt->action != NULL) {
+		const char *prefix = BLI_sprintfN("nodes[\"%s\"]", node->name);
+		for (FCurve *fcu = adt->action->curves.first; fcu != NULL; fcu = fcu->next) {
+			if (STRPREFIX(fcu->rna_path, prefix)) {
+				anim_change_prop_name(fcu, prefix, "color_hue", "inputs[1].default_value");
+				anim_change_prop_name(fcu, prefix, "color_saturation", "inputs[2].default_value");
+				anim_change_prop_name(fcu, prefix, "color_value", "inputs[3].default_value");
+			}
+		}
+		MEM_freeN((char *)prefix);
+	}
+	/* Free storage, it is no longer used. */
+	MEM_freeN(node->storage);
+	node->storage = NULL;
+}
+
 void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 {
 	if (!MAIN_VERSION_ATLEAST(main, 270, 0)) {
@@ -1521,5 +1570,23 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 				}
 			}
 		}
+
+	}
+}
+
+void do_versions_after_linking_270(Main *main)
+{
+	/* To be added to next subversion bump! */
+	{
+		FOREACH_NODETREE(main, ntree, id) {
+			if (ntree->type == NTREE_COMPOSIT) {
+				ntreeSetTypes(NULL, ntree);
+				for (bNode *node = ntree->nodes.first; node; node = node->next) {
+					if (node->type == CMP_NODE_HUE_SAT) {
+						do_version_hue_sat_node(ntree, node);
+					}
+				}
+			}
+		} FOREACH_NODETREE_END
 	}
 }
diff --git a/source/blender/compositor/nodes/COM_HueSaturationValueNode.cpp b/source/blender/compositor/nodes/COM_HueSaturationValueNode.cpp
index 29c296a896..b8971fffe3 100644
--- a/source/blender/compositor/nodes/COM_HueSaturationValueNode.cpp
+++ b/source/blender/compositor/nodes/COM_HueSaturationValueNode.cpp
@@ -37,8 +37,11 @@ HueSaturationValueNode::HueSaturationValueNode(bNode *editorNode) : Node(editorN
 
 void HueSaturationValueNode::convertToOperations(NodeConverter &converter, const CompositorContext &/*context*/) const
 {
-	NodeInput *valueSocket = this->getInputSocket(0);
-	NodeInput *colorSocket = this->getInputSocket(1);
+	NodeInput *colorSocket = this->getInputSocket(0);
+	NodeInput *hueSocket = this->getInputSocket(1);
+	NodeInput *saturationSocket = this->getInputSocket(2);
+	NodeInput *valueSocket = this->getInputSocket(3);
+	NodeInput *facSocket = this->getInputSocket(4);
 	NodeOutput *outputSocket = this->getOutputSocket(0);
 	bNode *editorsnode = getbNode();
 	NodeHueSat *storage = (NodeHueSat *)editorsnode->storage;
@@ -50,9 +53,9 @@ void HueSaturationValueNode::convertToOperations(NodeConverter &converter, const
 	converter.addOperation(hsvToRGB);
 	
 	ChangeHSVOperation *changeHSV = new ChangeHSVOperation();
-	changeHSV->setHue(storage->hue);
-	changeHSV->setSaturation(storage->sat);
-	changeHSV->setValue(storage->val);
+	converter.mapInputSocket(hueSocket, changeHSV->getInputSocket(1));
+	converter.mapInputSocket(saturationSocket, changeHSV->getInputSocket(2));
+	converter.mapInputSocket(valueSocket, changeHSV->getInputSocket(3));
 	converter.addOperation(changeHSV);
 	
 	MixBlendOperation *blend = new MixBlendOperation();
@@ -64,6 +67,6 @@ void HueSaturationValueNode::convertToOperations(NodeConverter &converter, const
 	converter.addLink(changeHSV->getOutputSocket(), hsvToRGB->getInputSocket(0));
 	converter.addLink(hsvToRGB->getOutputSocket(), blend->getInputSocket(2));
 	converter.mapInputSocket(colorSocket, blend->getInputSocket(1));
-	converter.mapInputSocket(valueSocket, blend->getInputSocket(0));
+	converter.mapInputSocket(facSocket, blend->getInputSocket(0));
 	converter.mapOutputSocket(outputSocket, blend->getOutputSocket());
 }
diff --git a/source/blender/compositor/operations/COM_ChangeHSVOperation.cpp b/source/blender/compositor/operations/COM_ChangeHSVOperation.cpp
index 964f1d6466..7ea974a41d 100644
--- a/source/blender/compositor/operations/COM_ChangeHSVOperation.cpp
+++ b/source/blender/compositor/operations/COM_ChangeHSVOperation.cpp
@@ -25,6 +25,9 @@
 ChangeHSVOperation::ChangeHSVOperation() : NodeOperation()
 {
 	this->addInputSocket(COM_DT_COLOR);
+	this->addInputSocket(COM_DT_VALUE);
+	this->addInputSocket(COM_DT_VALUE);
+	this->addInputSocket(COM_DT_VALUE);
 	this->addOutputSocket(COM_DT_COLOR);
 	this->m_inputOperation = NULL;
 }
@@ -32,24 +35,34 @@ ChangeHSVOperation::ChangeHSVOperation() : NodeOperation()
 void ChangeHSVOperation::initExecution()
 {
 	this->m_inputOperation = getInputSocketReader(0);
+	this->m_hueOperation = getInputSocketReader(1);
+	this->m_saturationOperation = getInputSocketReader(2);
+	this->m_valueOperation = getInputSocketReader(3);
 }
 
 void ChangeHSVOperation::deinitExecution()
 {
 	this->m_inputOperation = NULL;
+	this->m_hueOperation = NULL;
+	this->m_saturationOperation = NULL;
+	this->m_valueOperation = NULL;
 }
 
 void ChangeHSVOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
 {
 	float inputColor1[4];
+	float hue[4], saturation[4], value[4];
 	
 	this->m_inputOperation->readSampled(inputColor1, x, y, sampler);
+	this->m_hueOperation->readSampled(hue, x, y, sampler);
+	this->m_saturationOperation->readSampled(saturation, x, y, sampler);
+	this->m_valueOperation->readSampled(value, x, y, sampler);
 	
-	output[0] = inputColor1[0] + (this->m_hue - 0.5f);
+	output[0] = inputColor1[0] + (hue[0] - 0.5f);
 	if      (output[0] > 1.0f) output[0] -= 1.0f;
 	else if (output[0] < 0.0f) output[0] += 1.0f;
-	output[1] = inputColor1[1] * this->m_saturation;
-	output[2] = inputColor1[2] * this->m_value;
+	output[1] = inputColor1[1] * saturation[0];
+	output[2] = inputColor1[2] * value[0];
 	output[3] = inputColor1[3];
 }
 
diff --git a/source/blender/compositor/operations/COM_ChangeHSVOperation.h b/source/blender/compositor/operations/COM_ChangeHSVOperation.h
index 76025e86b7..800c09c05f 100644
--- a/source/blender/compositor/operations/COM_ChangeHSVOperation.h
+++ b/source/blender/compositor/operations/COM_ChangeHSVOperation.h
@@ -32,10 +32,9 @@
 class ChangeHSVOperation : public NodeOperation {
 private:
 	SocketReader *m_inputOperation;
-
-	float m_hue;
-	float m_saturation;
-	float m_value;
+	SocketReader *m_hueOperation;
+	SocketReader *m_saturationOperation;
+	SocketReader *m_valueOperation;
 
 public:
 	/**
@@ -51,9 +50,5 @@ public:
 	 */
 	void executePixelSampled(float output[4], float x, float y, PixelSampler sampler);
 
-	void setHue(float hue) { this->m_hue = hue; }
-	void setSaturation(float saturation) { this->m_saturation = saturation; }
-	void setValue(float value) { this->m_value = value; }
-
 };
 #endif
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 7b08b8368b..d31a475e45 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -1629,17 +1629,6 @@ static void node_composit_buts_zcombine(uiLayout *layout, bContext *UNUSED(C

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list