[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54429] trunk/blender/source/blender: Added option to composite/viewer nodes which specifys whether alpha input

Sergey Sharybin sergey.vfx at gmail.com
Sun Feb 10 13:20:11 CET 2013


Revision: 54429
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54429
Author:   nazgul
Date:     2013-02-10 12:20:10 +0000 (Sun, 10 Feb 2013)
Log Message:
-----------
Added option to composite/viewer nodes which specifys whether alpha input
is straight or not (premultiplied is default).

This is useful in cases when you want to check on output of such nodes
as keying which does have straight alpha output.

Also added missing do_version code to previous compo do_versions.

Modified Paths:
--------------
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/compositor/nodes/COM_CompositorNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_ViewerNode.cpp
    trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.h
    trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.h
    trunk/blender/source/blender/compositor/operations/COM_ViewerOperation.cpp
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/editors/space_node/node_draw.c
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
    trunk/blender/source/blender/makesrna/intern/rna_nodetree_types.h
    trunk/blender/source/blender/nodes/composite/nodes/node_composite_composite.c
    trunk/blender/source/blender/nodes/composite/nodes/node_composite_viewer.c

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2013-02-10 10:29:38 UTC (rev 54428)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2013-02-10 12:20:10 UTC (rev 54429)
@@ -8795,14 +8795,16 @@
 	// add storage for compositor translate nodes when not existing
 	if (!MAIN_VERSION_ATLEAST(main, 265, 10)) {
 		bNodeTreeType *ntreetype;
+		bNodeTree *ntree;
 
 		ntreetype = ntreeGetType(NTREE_COMPOSIT);
 		if (ntreetype && ntreetype->foreach_nodetree)
 			ntreetype->foreach_nodetree(main, NULL, do_version_node_fix_translate_wrapping);
+
+		for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
+			do_version_node_fix_translate_wrapping(NULL, NULL, ntree);
 	}
 
-
-
 	// if (main->versionfile < 265 || (main->versionfile == 265 && main->subversionfile < 7)) {
 
 	/* WATCH IT!!!: pointers from libdata have not been converted yet here! */

Modified: trunk/blender/source/blender/compositor/nodes/COM_CompositorNode.cpp
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_CompositorNode.cpp	2013-02-10 10:29:38 UTC (rev 54428)
+++ trunk/blender/source/blender/compositor/nodes/COM_CompositorNode.cpp	2013-02-10 12:20:10 UTC (rev 54429)
@@ -41,6 +41,7 @@
 	compositorOperation->setSceneName(editorNode->id->name);
 	compositorOperation->setRenderData(context->getRenderData());
 	compositorOperation->setbNodeTree(context->getbNodeTree());
+	compositorOperation->setStraightAlpha(editorNode->custom2 & 1);
 	imageSocket->relinkConnections(compositorOperation->getInputSocket(0), 0, graph);
 	alphaSocket->relinkConnections(compositorOperation->getInputSocket(1));
 	depthSocket->relinkConnections(compositorOperation->getInputSocket(2));

Modified: trunk/blender/source/blender/compositor/nodes/COM_ViewerNode.cpp
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_ViewerNode.cpp	2013-02-10 10:29:38 UTC (rev 54428)
+++ trunk/blender/source/blender/compositor/nodes/COM_ViewerNode.cpp	2013-02-10 12:20:10 UTC (rev 54429)
@@ -47,6 +47,7 @@
 	viewerOperation->setChunkOrder((OrderOfChunks)editorNode->custom1);
 	viewerOperation->setCenterX(editorNode->custom3);
 	viewerOperation->setCenterY(editorNode->custom4);
+	viewerOperation->setStraightAlpha(editorNode->custom2 & 1);
 
 	viewerOperation->setViewSettings(context->getViewSettings());
 	viewerOperation->setDisplaySettings(context->getDisplaySettings());

Modified: trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.cpp	2013-02-10 10:29:38 UTC (rev 54428)
+++ trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.cpp	2013-02-10 12:20:10 UTC (rev 54429)
@@ -49,6 +49,8 @@
 	this->m_alphaInput = NULL;
 	this->m_depthInput = NULL;
 
+	this->m_straightAlpha = false;
+
 	this->m_sceneName[0] = '\0';
 }
 
@@ -141,6 +143,10 @@
 			if (this->m_alphaInput != NULL) {
 				this->m_alphaInput->read(&(color[3]), x, y, COM_PS_NEAREST);
 			}
+
+			if (this->m_straightAlpha)
+				straight_to_premul_v4(color);
+
 			copy_v4_v4(buffer + offset4, color);
 
 			if (this->m_depthInput != NULL) {

Modified: trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.h
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.h	2013-02-10 10:29:38 UTC (rev 54428)
+++ trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.h	2013-02-10 12:20:10 UTC (rev 54429)
@@ -65,6 +65,10 @@
 	 * @brief local reference to the depth operation
 	 */
 	SocketReader *m_depthInput;
+
+	/* node input has got straight alpha which shall be premultiplied */
+	bool m_straightAlpha;
+
 public:
 	CompositorOperation();
 	void executeRegion(rcti *rect, unsigned int tileNumber);
@@ -75,5 +79,6 @@
 	void deinitExecution();
 	const CompositorPriority getRenderPriority() const { return COM_PRIORITY_MEDIUM; }
 	void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]);
+	void setStraightAlpha(bool value) { this->m_straightAlpha = value; }
 };
 #endif

Modified: trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp	2013-02-10 10:29:38 UTC (rev 54428)
+++ trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp	2013-02-10 12:20:10 UTC (rev 54429)
@@ -48,6 +48,7 @@
 	this->m_doDepthBuffer = false;
 	this->m_viewSettings = NULL;
 	this->m_displaySettings = NULL;
+	this->m_straightAlpha = false;
 }
 
 void ViewerBaseOperation::initExecution()

Modified: trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.h
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.h	2013-02-10 10:29:38 UTC (rev 54428)
+++ trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.h	2013-02-10 12:20:10 UTC (rev 54429)
@@ -39,6 +39,7 @@
 	OrderOfChunks m_chunkOrder;
 	bool m_doDepthBuffer;
 	ImBuf *m_ibuf;
+	bool m_straightAlpha;
 
 	const ColorManagedViewSettings *m_viewSettings;
 	const ColorManagedDisplaySettings *m_displaySettings;
@@ -59,6 +60,7 @@
 	OrderOfChunks getChunkOrder() { return this->m_chunkOrder; }
 	const CompositorPriority getRenderPriority() const;
 	bool isViewerOperation() { return true; }
+	void setStraightAlpha(bool value) { this->m_straightAlpha = value; }
 
 	void setViewSettings(const ColorManagedViewSettings *viewSettings) { this->m_viewSettings = viewSettings; }
 	void setDisplaySettings(const ColorManagedDisplaySettings *displaySettings) { this->m_displaySettings = displaySettings; }

Modified: trunk/blender/source/blender/compositor/operations/COM_ViewerOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_ViewerOperation.cpp	2013-02-10 10:29:38 UTC (rev 54428)
+++ trunk/blender/source/blender/compositor/operations/COM_ViewerOperation.cpp	2013-02-10 12:20:10 UTC (rev 54429)
@@ -98,6 +98,9 @@
 				depthbuffer[offset] = depth[0];
 			}
 
+			if (this->m_straightAlpha)
+				straight_to_premul_v4(buffer + offset4);
+
 			offset ++;
 			offset4 += 4;
 		}

Modified: trunk/blender/source/blender/editors/space_node/drawnode.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/drawnode.c	2013-02-10 10:29:38 UTC (rev 54428)
+++ trunk/blender/source/blender/editors/space_node/drawnode.c	2013-02-10 12:20:10 UTC (rev 54429)
@@ -2654,10 +2654,21 @@
 	uiItemR(layout, ptr, "mask_type", 0, NULL, ICON_NONE);
 }
 
+static void node_composit_buts_composite(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+	uiItemR(layout, ptr, "use_straight_alpha", 0, NULL, ICON_NONE);
+}
+
+static void node_composit_buts_viewer(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+	uiItemR(layout, ptr, "use_straight_alpha", 0, NULL, ICON_NONE);
+}
+
 static void node_composit_buts_viewer_but(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
 {
 	uiLayout *col;
 	
+	uiItemR(layout, ptr, "use_straight_alpha", 0, NULL, ICON_NONE);
 	uiItemR(layout, ptr, "tile_order", 0, NULL, ICON_NONE);
 	if (RNA_enum_get(ptr, "tile_order") == 0) {
 		col = uiLayoutColumn(layout, TRUE);
@@ -2965,10 +2976,13 @@
 			ntype->uifunc = node_composit_buts_bokehblur;
 			break;
 		case CMP_NODE_VIEWER:
-			ntype->uifunc = NULL;
+			ntype->uifunc = node_composit_buts_viewer;
 			ntype->uifuncbut = node_composit_buts_viewer_but;
 			ntype->uibackdropfunc = node_composit_backdrop_viewer;
 			break;
+		case CMP_NODE_COMPOSITE:
+			ntype->uifunc = node_composit_buts_composite;
+			break;
 		case CMP_NODE_MASK:
 			ntype->uifunc = node_composit_buts_mask;
 			break;

Modified: trunk/blender/source/blender/editors/space_node/node_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_draw.c	2013-02-10 10:29:38 UTC (rev 54428)
+++ trunk/blender/source/blender/editors/space_node/node_draw.c	2013-02-10 12:20:10 UTC (rev 54429)
@@ -368,7 +368,8 @@
 	}
 
 	/* buttons rect? */
-	if ((node->flag & NODE_OPTIONS) && node->typeinfo->uifunc) {
+	/* TODO: NODE_OPTION shall be cleaned up */
+	if (/*(node->flag & NODE_OPTIONS) && */node->typeinfo->uifunc) {
 		dy -= NODE_DYS / 2;
 
 		/* set this for uifunc() that don't use layout engine yet */

Modified: trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2013-02-10 10:29:38 UTC (rev 54428)
+++ trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2013-02-10 12:20:10 UTC (rev 54429)
@@ -4083,8 +4083,23 @@
 	RNA_def_property_range(prop, 0.0f, 1.0f);
 	RNA_def_property_ui_text(prop, "Y", "");
 	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
+	prop = RNA_def_property(srna, "use_straight_alpha", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "custom2", 1);
+	RNA_def_property_ui_text(prop, "Straight Alpha", "Treat alpha input of this node as straight");
+	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
+static void def_cmp_composite(StructRNA *srna)
+{
+	PropertyRNA *prop;
+
+	prop = RNA_def_property(srna, "use_straight_alpha", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "custom2", 1);
+	RNA_def_property_ui_text(prop, "Straight Alpha", "Treat alpha input of this node as straight");
+	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+}
+
 static void def_cmp_keyingscreen(StructRNA *srna)
 {
 	PropertyRNA *prop;

Modified: trunk/blender/source/blender/makesrna/intern/rna_nodetree_types.h
===================================================================

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list