[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48878] trunk/blender/source: new mask rasterizer written to take advantage of the compositors threading , mostly functional but disabled by default (still a little wip).

Campbell Barton ideasman42 at gmail.com
Thu Jul 12 22:10:42 CEST 2012


Revision: 48878
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48878
Author:   campbellbarton
Date:     2012-07-12 20:10:41 +0000 (Thu, 12 Jul 2012)
Log Message:
-----------
new mask rasterizer written to take advantage of the compositors threading, mostly functional but disabled by default (still a little wip).

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_mask.h
    trunk/blender/source/blender/blenkernel/CMakeLists.txt
    trunk/blender/source/blender/blenkernel/intern/mask.c
    trunk/blender/source/blender/blenkernel/intern/particle_system.c
    trunk/blender/source/blender/compositor/operations/COM_MaskOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_MaskOperation.h
    trunk/blender/source/creator/CMakeLists.txt

Added Paths:
-----------
    trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c

Modified: trunk/blender/source/blender/blenkernel/BKE_mask.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_mask.h	2012-07-12 19:56:47 UTC (rev 48877)
+++ trunk/blender/source/blender/blenkernel/BKE_mask.h	2012-07-12 20:10:41 UTC (rev 48878)
@@ -64,6 +64,8 @@
 /* splines */
 struct MaskSpline *BKE_mask_spline_add(struct MaskLayer *masklay);
 
+int BKE_mask_spline_differentiate_calc_total(const struct MaskSpline *spline, const int resol);
+
 float (*BKE_mask_spline_differentiate(struct MaskSpline *spline, int *tot_diff_point))[2];
 float (*BKE_mask_spline_feather_differentiated_points(struct MaskSpline *spline, int *tot_feather_point))[2];
 
@@ -203,4 +205,21 @@
 #define MASKPOINT_SEL_HANDLE(p)     { (p)->bezt.f1 |=  SELECT; (p)->bezt.f3 |=  SELECT; } (void)0
 #define MASKPOINT_DESEL_HANDLE(p)   { (p)->bezt.f1 &= ~SELECT; (p)->bezt.f3 &= ~SELECT; } (void)0
 
-#endif
+/* disable to test alternate rasterizer */
+#define USE_RASKTER
+
+/* mask_rasterize.c */
+#ifndef USE_RASKTER
+struct MaskRasterHandle;
+typedef struct MaskRasterHandle MaskRasterHandle;
+
+MaskRasterHandle *BLI_maskrasterize_handle_new(void);
+void              BLI_maskrasterize_handle_free(MaskRasterHandle *mr_handle);
+void              BLI_maskrasterize_handle_init(MaskRasterHandle *mr_handle, struct Mask *mask,
+                                                const int width, const int height,
+                                                const short do_aspect_correct, const short do_mask_aa,
+                                                const short do_feather);
+float             BLI_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float xy[2]);
+#endif /* USE_RASKTER */
+
+#endif /* __BKE_MASK_H__ */

Modified: trunk/blender/source/blender/blenkernel/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/blenkernel/CMakeLists.txt	2012-07-12 19:56:47 UTC (rev 48877)
+++ trunk/blender/source/blender/blenkernel/CMakeLists.txt	2012-07-12 20:10:41 UTC (rev 48878)
@@ -101,6 +101,7 @@
 	intern/lamp.c
 	intern/lattice.c
 	intern/library.c
+	intern/mask_rasterize.c
 	intern/mask.c
 	intern/material.c
 	intern/mball.c

Modified: trunk/blender/source/blender/blenkernel/intern/mask.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mask.c	2012-07-12 19:56:47 UTC (rev 48877)
+++ trunk/blender/source/blender/blenkernel/intern/mask.c	2012-07-12 20:10:41 UTC (rev 48878)
@@ -314,7 +314,7 @@
 	return resol;
 }
 
-static int mask_spline_points_calc_tot(const MaskSpline *spline, const int resol)
+int BKE_mask_spline_differentiate_calc_total(const MaskSpline *spline, const int resol)
 {
 	int len;
 
@@ -338,7 +338,7 @@
 
 	MaskSplinePoint *point, *prev;
 	float (*diff_points)[2], (*fp)[2];
-	const int tot = mask_spline_points_calc_tot(spline, resol);
+	const int tot = BKE_mask_spline_differentiate_calc_total(spline, resol);
 	int a;
 
 	if (spline->tot_point <= 1) {
@@ -412,7 +412,7 @@
 	MaskSplinePoint *point, *prev;
 	float (*feather)[2], (*fp)[2];
 
-	const int tot = mask_spline_points_calc_tot(spline, resol);
+	const int tot = BKE_mask_spline_differentiate_calc_total(spline, resol);
 	int a;
 
 	/* tot+1 because of 'forward_diff_bezier' function */

Added: trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c	                        (rev 0)
+++ trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c	2012-07-12 20:10:41 UTC (rev 48878)
@@ -0,0 +1,586 @@
+/*
+ * ***** 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): Blender Foundation,
+ *                 Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/mask_rasterize.c
+ *  \ingroup bke
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_vec_types.h"
+#include "DNA_mask_types.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_kdopbvh.h"
+#include "BLI_scanfill.h"
+
+#include "BLI_math.h"
+#include "BLI_rect.h"
+#include "BLI_listbase.h"
+#include "BLI_mempool.h"
+
+#include "BKE_mask.h"
+
+#ifndef USE_RASKTER
+
+/**
+ * A single #MaskRasterHandle contains multile #MaskRasterLayer's,
+ * each #MaskRasterLayer does its own lookup which contributes to
+ * the final pixel with its own blending mode and the final pixel is blended between these.
+ */
+
+/* internal use only */
+typedef struct MaskRasterLayer {
+	/* xy raytree */
+	BVHTree *bvhtree;
+
+	/* 2d bounds (to quickly skip raytree lookup) */
+	rctf bounds;
+
+	/* geometry */
+	unsigned int (*tri_array)[3];  /* access coords */
+	float        (*tri_coords)[3]; /* xy, z 0-1 (1.0 == filled) */
+
+
+	/* copied direct from #MaskLayer.--- */
+	/* blending options */
+	float  alpha;
+	char   blend;
+	char   blend_flag;
+
+} MaskRasterLayer;
+
+
+/**
+ * opaque local struct for mask pixel lookup, each MaskLayer needs one of these
+ */
+struct MaskRasterHandle {
+	MaskRasterLayer *layers;
+	unsigned int     layers_tot;
+
+	/* 2d bounds (to quickly skip raytree lookup) */
+	rctf bounds;
+};
+
+MaskRasterHandle *BLI_maskrasterize_handle_new(void)
+{
+	MaskRasterHandle *mr_handle;
+
+	mr_handle = MEM_callocN(sizeof(MaskRasterHandle), STRINGIFY(MaskRasterHandle));
+
+	return mr_handle;
+}
+
+void BLI_maskrasterize_handle_free(MaskRasterHandle *mr_handle)
+{
+	const unsigned int layers_tot = mr_handle->layers_tot;
+	unsigned int i;
+	MaskRasterLayer *raslayers = mr_handle->layers;
+
+	/* raycast vars */
+	for (i = 0; i < layers_tot; i++, raslayers++) {
+		BLI_bvhtree_free(raslayers->bvhtree);
+
+		if (raslayers->tri_array) {
+			MEM_freeN(raslayers->tri_array);
+		}
+
+		if (raslayers->tri_coords) {
+			MEM_freeN(raslayers->tri_coords);
+		}
+	}
+
+	MEM_freeN(mr_handle->layers);
+	MEM_freeN(mr_handle);
+}
+
+#define PRINT_MASK_DEBUG printf
+
+#define SF_EDGE_IS_BOUNDARY 0xff
+
+#define SF_KEYINDEX_TEMP_ID ((unsigned int) -1)
+
+
+void maskrasterize_spline_differentiate_point_inset(float (*diff_feather_points)[2], float (*diff_points)[2],
+                                                    const int tot_diff_point, const float ofs, const int do_test)
+{
+	int k_prev = tot_diff_point - 2;
+	int k_curr = tot_diff_point - 1;
+	int k_next = 0;
+
+	int k;
+
+	float d_prev[2];
+	float d_next[2];
+	float d[2];
+
+	const float *co_prev;
+	const float *co_curr;
+	const float *co_next;
+
+	const float ofs_squared = ofs * ofs;
+
+	co_prev = diff_points[k_prev];
+	co_curr = diff_points[k_curr];
+	co_next = diff_points[k_next];
+
+	/* precalc */
+	sub_v2_v2v2(d_prev, co_prev, co_curr);
+	normalize_v2(d_prev);
+
+	/* TODO, speedup by only doing one normalize per iter */
+
+
+	for (k = 0; k < tot_diff_point; k++) {
+
+		co_prev = diff_points[k_prev];
+		co_curr = diff_points[k_curr];
+		co_next = diff_points[k_next];
+
+		/* sub_v2_v2v2(d_prev, co_prev, co_curr); */ /* precalc */
+		sub_v2_v2v2(d_next, co_curr, co_next);
+
+		/* normalize_v2(d_prev); */ /* precalc */
+		normalize_v2(d_next);
+
+		if ((do_test == FALSE) ||
+		    (len_squared_v2v2(diff_feather_points[k], diff_points[k]) < ofs_squared))
+		{
+
+			add_v2_v2v2(d, d_prev, d_next);
+
+			normalize_v2(d);
+
+			diff_feather_points[k][0] = diff_points[k][0] + ( d[1] * ofs);
+			diff_feather_points[k][1] = diff_points[k][1] + (-d[0] * ofs);
+		}
+
+		/* use next iter */
+		copy_v2_v2(d_prev, d_next);
+
+		k_prev = k_curr;
+		k_curr = k_next;
+		k_next++;
+	}
+}
+
+void BLI_maskrasterize_handle_init(MaskRasterHandle *mr_handle, struct Mask *mask,
+                                   const int width, const int height,
+                                   const short do_aspect_correct, const short do_mask_aa,
+                                   const short do_feather)
+{
+	/* TODO: real size */
+	const int resol = 16;
+	const float aa_filter_size = 1.0f / MIN2(width, height);
+
+	const float zvec[3] = {0.0f, 0.0f, 1.0f};
+	MaskLayer *masklay;
+	int masklay_index;
+
+	mr_handle->layers_tot = BLI_countlist(&mask->masklayers);
+	mr_handle->layers = MEM_mallocN(sizeof(MaskRasterLayer) * mr_handle->layers_tot, STRINGIFY(MaskRasterLayer));
+	BLI_rctf_init_minmax(&mr_handle->bounds);
+
+	for (masklay = mask->masklayers.first, masklay_index = 0; masklay; masklay = masklay->next, masklay_index++) {
+
+		MaskSpline *spline;
+
+		/* scanfill */
+		ScanFillContext sf_ctx;
+		ScanFillVert *sf_vert = NULL;
+		ScanFillVert *sf_vert_next = NULL;
+		ScanFillFace *sf_tri;
+
+		unsigned int sf_vert_tot = 0;
+		unsigned int tot_feather_quads = 0;
+
+		if (masklay->restrictflag & MASK_RESTRICT_RENDER) {
+			continue;
+		}
+
+		BLI_scanfill_begin(&sf_ctx);
+
+		for (spline = masklay->splines.first; spline; spline = spline->next) {
+
+			float (*diff_points)[2];
+			int tot_diff_point;
+
+			float (*diff_feather_points)[2];
+			int tot_diff_feather_points;
+
+			diff_points = BKE_mask_spline_differentiate_with_resolution_ex(spline, resol, &tot_diff_point);
+
+			/* dont ch*/
+			if (do_feather) {
+				diff_feather_points = BKE_mask_spline_feather_differentiated_points_with_resolution_ex(spline, resol, &tot_diff_feather_points);
+			}
+			else {
+				tot_diff_feather_points = 0;
+				diff_feather_points = NULL;
+			}
+
+			if (do_aspect_correct) {
+				if (width != height) {
+					float *fp;
+					float *ffp;
+					int i;
+					float asp;
+
+					if (width < height) {
+						fp = &diff_points[0][0];
+						ffp = tot_diff_feather_points ? &diff_feather_points[0][0] : NULL;
+						asp = (float)width / (float)height;
+					}
+					else {
+						fp = &diff_points[0][1];

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list