[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47179] branches/soc-2011-tomato/source/ blender: Initial commit of new keying nodes

Sergey Sharybin sergey.vfx at gmail.com
Tue May 29 16:00:47 CEST 2012


Revision: 47179
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47179
Author:   nazgul
Date:     2012-05-29 14:00:47 +0000 (Tue, 29 May 2012)
Log Message:
-----------
Initial commit of new keying nodes

First node is called Keying Screen (Add -> Matte -> Keying Screen) and it's
aimed to resolve issues with gradients on green screens by producing image
with gradient which is later used as an input for screen color in keying nodes.

This node gets motion tracks from given movie clip and trackign object and uses
them to define color and position of points of gradient: for position marker's
position on current frame is sued, for color average color of pattern area is
used.

Gradient is calculating in the following way:
- On first step voronoi diagram is creating for given tracks.
- On second step triangulation of this diagram happens by connecting sites
  to edges which defines area this site belongs to.
- On third step gradient filling of this triangles happens. One of triangle
  vertices is colored with average track color, two rest vertoces are colored
  with average color between two neighbor sites. Current pixel's color in
  triangle is calculating as linear combination of vertices colors and
  barycentric coordinates of this pixel.

This node is implemented for both tile and legacy compositor systems.

Second node is basically a combination of several existing nodes to make keying
more straighforward and reduce spagetti mess in the compositor, but it also
ships some fresh approaches calculating matte which seems to be working better
for not actually green screens.

This node supports:
- Chroma preblur
- Dispilling
- Clip white/black
- Dilate/Erode
- Matte post blur

This node doesn't support chroma pre-blur for legacy compositor (yet).

There're still lots of stuff to be improved here, but this nodes night already
be used i think.

Some details might be found on this wiki page:
http://wiki.blender.org/index.php/User:Nazg-gul/Keying

This patch also contains some currently unused code from color math module, but
it was used for tests and might be used for tests in the future. Think it's ok
to have it in branch at least.

Modified Paths:
--------------
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_node.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/node.c
    branches/soc-2011-tomato/source/blender/blenlib/BLI_math_base.h
    branches/soc-2011-tomato/source/blender/blenlib/BLI_math_color.h
    branches/soc-2011-tomato/source/blender/blenlib/BLI_math_geom.h
    branches/soc-2011-tomato/source/blender/blenlib/CMakeLists.txt
    branches/soc-2011-tomato/source/blender/blenlib/intern/math_color.c
    branches/soc-2011-tomato/source/blender/blenlib/intern/math_geom.c
    branches/soc-2011-tomato/source/blender/compositor/CMakeLists.txt
    branches/soc-2011-tomato/source/blender/compositor/intern/COM_Converter.cpp
    branches/soc-2011-tomato/source/blender/editors/space_node/drawnode.c
    branches/soc-2011-tomato/source/blender/makesdna/DNA_node_types.h
    branches/soc-2011-tomato/source/blender/makesrna/RNA_access.h
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_nodetree.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_nodetree_types.h
    branches/soc-2011-tomato/source/blender/nodes/CMakeLists.txt
    branches/soc-2011-tomato/source/blender/nodes/NOD_composite.h
    branches/soc-2011-tomato/source/blender/nodes/composite/node_composite_util.c
    branches/soc-2011-tomato/source/blender/nodes/composite/node_composite_util.h
    branches/soc-2011-tomato/source/blender/nodes/composite/nodes/node_composite_blur.c
    branches/soc-2011-tomato/source/blender/nodes/composite/nodes/node_composite_dilate.c

Added Paths:
-----------
    branches/soc-2011-tomato/source/blender/blenlib/BLI_voronoi.h
    branches/soc-2011-tomato/source/blender/blenlib/intern/voronoi.c
    branches/soc-2011-tomato/source/blender/compositor/nodes/COM_KeyingNode.cpp
    branches/soc-2011-tomato/source/blender/compositor/nodes/COM_KeyingNode.h
    branches/soc-2011-tomato/source/blender/compositor/nodes/COM_KeyingScreenNode.cpp
    branches/soc-2011-tomato/source/blender/compositor/nodes/COM_KeyingScreenNode.h
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingDispillOperation.cpp
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingDispillOperation.h
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingOperation.cpp
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingOperation.h
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingScreenOperation.h
    branches/soc-2011-tomato/source/blender/nodes/composite/nodes/node_composite_keying.c
    branches/soc-2011-tomato/source/blender/nodes/composite/nodes/node_composite_keyingscreen.c

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_node.h	2012-05-29 13:59:31 UTC (rev 47178)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_node.h	2012-05-29 14:00:47 UTC (rev 47179)
@@ -655,6 +655,8 @@
 #define CMP_NODE_DOUBLEEDGEMASK    266
 #define CMP_NODE_OUTPUT_MULTI_FILE__DEPRECATED	267	/* DEPRECATED multi file node has been merged into regular CMP_NODE_OUTPUT_FILE */
 #define CMP_NODE_MASK		268
+#define CMP_NODE_KEYINGSCREEN		269
+#define CMP_NODE_KEYING		270
 
 #define CMP_NODE_GLARE		301
 #define CMP_NODE_TONEMAP	302

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/node.c	2012-05-29 13:59:31 UTC (rev 47178)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/node.c	2012-05-29 14:00:47 UTC (rev 47179)
@@ -1926,6 +1926,8 @@
 	register_node_type_cmp_color_spill(ttype);
 	register_node_type_cmp_luma_matte(ttype);
 	register_node_type_cmp_doubleedgemask(ttype);
+	register_node_type_cmp_keyingscreen(ttype);
+	register_node_type_cmp_keying(ttype);
 
 	register_node_type_cmp_translate(ttype);
 	register_node_type_cmp_rotate(ttype);

Modified: branches/soc-2011-tomato/source/blender/blenlib/BLI_math_base.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenlib/BLI_math_base.h	2012-05-29 13:59:31 UTC (rev 47178)
+++ branches/soc-2011-tomato/source/blender/blenlib/BLI_math_base.h	2012-05-29 14:00:47 UTC (rev 47179)
@@ -53,6 +53,9 @@
 #ifndef M_SQRT1_2
 #define M_SQRT1_2   0.70710678118654752440
 #endif
+#ifndef M_SQRT3
+#define M_SQRT3   1.7320508075688772
+#endif
 #ifndef M_1_PI
 #define M_1_PI      0.318309886183790671538
 #endif

Modified: branches/soc-2011-tomato/source/blender/blenlib/BLI_math_color.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenlib/BLI_math_color.h	2012-05-29 13:59:31 UTC (rev 47178)
+++ branches/soc-2011-tomato/source/blender/blenlib/BLI_math_color.h	2012-05-29 14:00:47 UTC (rev 47179)
@@ -69,6 +69,8 @@
 void rgb_to_hsv_v(const float rgb[3], float r_hsv[3]);
 void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *lv);
 void rgb_to_hsv_compat_v(const float rgb[3], float r_hsv[3]);
+void rgb_to_lab(float r, float g, float b, float *ll, float *la, float *lb);
+void rgb_to_xyz(float r, float g, float b, float *x, float *y, float *z);
 unsigned int rgb_to_cpack(float r, float g, float b);
 unsigned int hsv_to_cpack(float h, float s, float v);
 
@@ -112,6 +114,8 @@
 void rgb_float_to_uchar(unsigned char col_r[3], const float col_f[3]);
 void rgba_float_to_uchar(unsigned char col_r[4], const float col_f[4]);
 
+void xyz_to_lab(float x, float y, float z, float *l, float *a, float *b);
+
 /***************** lift/gamma/gain / ASC-CDL conversion *****************/
 
 void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *offset, float *slope, float *power);

Modified: branches/soc-2011-tomato/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenlib/BLI_math_geom.h	2012-05-29 13:59:31 UTC (rev 47178)
+++ branches/soc-2011-tomato/source/blender/blenlib/BLI_math_geom.h	2012-05-29 14:00:47 UTC (rev 47179)
@@ -191,6 +191,9 @@
 void barycentric_weights_v2(const float v1[2], const float v2[2], const float v3[2],
                             const float co[2], float w[3]);
 
+int barycentric_coords_v2(const float v1[2], const float v2[2], const float v3[2], const float co[2], float w[3]);
+int barycentric_inside_triangle_v2(const float w[3]);
+
 void resolve_tri_uv(float r_uv[2], const float st[2], const float st0[2], const float st1[2], const float st2[2]);
 void resolve_quad_uv(float uv[2], const float st[2], const float st0[2], const float st1[2], const float st2[2], const float st3[2]);
 

Added: branches/soc-2011-tomato/source/blender/blenlib/BLI_voronoi.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenlib/BLI_voronoi.h	                        (rev 0)
+++ branches/soc-2011-tomato/source/blender/blenlib/BLI_voronoi.h	2012-05-29 14:00:47 UTC (rev 47179)
@@ -0,0 +1,70 @@
+/*
+ * ***** 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) 2012 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Sergey Sharybin
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BLI_VORONOI_H__
+#define __BLI_VORONOI_H__
+
+struct ListBase;
+
+/** \file BLI_voronoi.h
+ *  \ingroup bli
+ */
+
+typedef struct VoronoiSite {
+	float co[2];
+	float color[3];
+} VoronoiSite;
+
+typedef struct VoronoiEdge {
+	struct VoronoiEdge *next, *prev;
+
+	float start[2], end[2];	/* start and end points */
+
+	/* this fields are used during diagram computation only */
+
+	float direction[2];		/* directional vector, from "start", points to "end", normal of |left, right| */
+
+	float left[2];			/* point on Voronoi place on the left side of edge */
+	float right[2];			/* point on Voronoi place on the right side of edge */
+
+	float f, g;				/* directional coeffitients satisfying equation y = f*x + g (edge lies on this line) */
+
+	/* some edges consist of two parts, so we add the pointer to another part to connect them at the end of an algorithm */
+	struct VoronoiEdge *neighbour;
+} VoronoiEdge;
+
+typedef struct VoronoiTriangulationPoint {
+	float co[2];
+	float color[3];
+	int power;
+} VoronoiTriangulationPoint;
+
+void BLI_voronoi_compute(const VoronoiSite *sites, int sites_total, int width, int height, struct ListBase *edges);
+
+void BLI_voronoi_triangulate(const VoronoiSite *sites, int sites_total, struct ListBase *edges, int width, int height,
+                             VoronoiTriangulationPoint **triangulated_points_r, int *triangulated_points_total_r,
+                             int (**triangles_r)[3], int *triangles_total_r);
+
+#endif /* __BLI_VORONOI_H__ */

Modified: branches/soc-2011-tomato/source/blender/blenlib/CMakeLists.txt
===================================================================
--- branches/soc-2011-tomato/source/blender/blenlib/CMakeLists.txt	2012-05-29 13:59:31 UTC (rev 47178)
+++ branches/soc-2011-tomato/source/blender/blenlib/CMakeLists.txt	2012-05-29 14:00:47 UTC (rev 47179)
@@ -89,6 +89,7 @@
 	intern/time.c
 	intern/uvproject.c
 	intern/voxel.c
+	intern/voronoi.c
 	intern/winstuff.c
 
 	BLI_args.h

Modified: branches/soc-2011-tomato/source/blender/blenlib/intern/math_color.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenlib/intern/math_color.c	2012-05-29 13:59:31 UTC (rev 47178)
+++ branches/soc-2011-tomato/source/blender/blenlib/intern/math_color.c	2012-05-29 14:00:47 UTC (rev 47179)
@@ -264,6 +264,35 @@
 	rgb_to_hsv(rgb[0], rgb[1], rgb[2], &r_hsv[0], &r_hsv[1], &r_hsv[2]);
 }
 
+void rgb_to_hsl(float r, float g, float b, float *lh, float *ls, float *ll)
+{
+	float cmax = MAX3(r, g, b);
+	float cmin = MIN3(r, g, b);
+	float h, s, l = (cmax + cmin) / 2.0f;
+
+	if (cmax == cmin) {
+		h = s = 0.0f; // achromatic
+	}
+	else {
+		float d = cmax - cmin;
+		s = l > 0.5f ? d / (2.0f - cmax - cmin) : d / (cmax + cmin);
+		if (cmax == r) {
+			h = (g - b) / d + (g < b ? 6.0f : 0.0f);
+		}
+		else if (cmax == g) {
+			h = (b - r) / d + 2.0f;
+		}
+		else {
+			h = (r - g) / d + 4.0f;
+		}
+        }
+        h /= 6.0f;
+
+	*lh = h;
+	*ls = s;
+	*ll = l;
+}
+
 void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *lv)
 {
 	float orig_h = *lh;
@@ -603,3 +632,58 @@
 		BLI_color_to_srgb_table[i] = b * 0x100;
 	}
 }
+static float inverse_srgb_companding(float v)
+{
+    if (v > 0.04045f) {
+        return powf((v + 0.055f) / 1.055f, 2.4);
+    }
+    else {
+        return v / 12.92f;
+    }
+}
+
+void rgb_to_xyz(float r, float g, float b, float *x, float *y, float *z)
+{
+    r = inverse_srgb_companding(r) * 100.0f;
+    g = inverse_srgb_companding(g) * 100.0f;
+    b = inverse_srgb_companding(b) * 100.0f;
+
+    *x = r * 0.4124 + g * 0.3576 + b * 0.1805;
+    *y = r * 0.2126 + g * 0.7152 + b * 0.0722;
+    *z = r * 0.0193 + g * 0.1192 + b * 0.9505;
+}
+
+static float xyz_to_lab_component(float v)
+{
+	const float eps = 0.008856f;
+	const float k = 903.3f;
+
+	if (v > eps) {
+		return pow(v, 1.0f / 3.0f);
+	}
+	else {
+		return (k * v + 16.0f) / 116.0f;
+	}
+}
+
+void xyz_to_lab(float x, float y, float z, float *l, float *a, float *b)
+{
+	float xr = x / 95.047f;
+	float yr = y / 100.0f;
+	float zr = z / 108.883f;
+
+	float fx = xyz_to_lab_component(xr);
+	float fy = xyz_to_lab_component(yr);
+	float fz = xyz_to_lab_component(zr);
+
+	*l = 116.0f * fy - 16.0f;
+	*a = 500.0f * (fx - fy);
+	*b = 200.0f * (fy - fz);
+}
+
+void rgb_to_lab(float r, float g, float b, float *ll, float *la, float *lb)
+{
+	float x, y, z;
+	rgb_to_xyz(r, g, b, &x, &y, &z);
+	xyz_to_lab(x, y, z, ll, la, lb);
+}

Modified: branches/soc-2011-tomato/source/blender/blenlib/intern/math_geom.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenlib/intern/math_geom.c	2012-05-29 13:59:31 UTC (rev 47178)
+++ branches/soc-2011-tomato/source/blender/blenlib/intern/math_geom.c	2012-05-29 14:00:47 UTC (rev 47179)
@@ -1825,6 +1825,45 @@
 	}
 }
 
+/* return 1 of point is inside triangle, 2 if it's on the edge, 0 if point is outside of triangle */

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list