Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2016-01-08 15:29:42 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-01-08 15:35:34 +0300
commite830334357d1f73afbeeeb421ffcbed8e99b2fab (patch)
tree01042f96ba220e1afba8f090730b9933c257d31d
parent0634fd0e974573d4e9452795ce99b2c8105f9fee (diff)
Math Lib: use x-span for fill_poly_v2i_n callback
Instead of running the callback per-pixel, pass the x-span to the callback.
-rw-r--r--source/blender/blenkernel/intern/tracking.c9
-rw-r--r--source/blender/blenlib/BLI_math_geom.h2
-rw-r--r--source/blender/blenlib/intern/math_geom.c21
-rw-r--r--source/blender/editors/mesh/editmesh_select.c8
-rw-r--r--source/blender/editors/sculpt_paint/paint_mask.c8
-rw-r--r--source/blender/windowmanager/intern/wm_gesture.c9
6 files changed, 45 insertions, 12 deletions
diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c
index 094db3cfcc9..e5719bdca62 100644
--- a/source/blender/blenkernel/intern/tracking.c
+++ b/source/blender/blenkernel/intern/tracking.c
@@ -814,11 +814,14 @@ typedef struct TrackMaskSetPixelData {
int mask_height;
} TrackMaskSetPixelData;
-static void track_mask_set_pixel_cb(int x, int y, void *user_data)
+static void track_mask_set_pixel_cb(int x, int x_end, int y, void *user_data)
{
TrackMaskSetPixelData *data = (TrackMaskSetPixelData *)user_data;
- size_t index = (size_t)y * data->mask_width + x;
- data->mask[index] = 1.0f;
+ size_t index = (size_t)y * data->mask_width + x;
+ size_t index_end = (size_t)y * data->mask_width + x_end;
+ do {
+ data->mask[index] = 1.0f;
+ } while (++index != index_end);
}
static void track_mask_gpencil_layer_rasterize(int frame_width, int frame_height,
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index d8e2b7f5e4c..863bc766276 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -291,7 +291,7 @@ void plot_line_v2v2i(const int p1[2], const int p2[2], bool (*callback)(int, int
void fill_poly_v2i_n(
const int xmin, const int ymin, const int xmax, const int ymax,
const int polyXY[][2], const int polyCorners,
- void (*callback)(int, int, void *), void *userData);
+ void (*callback)(int x, int x_end, int y, void *), void *userData);
/****************************** Interpolation ********************************/
/* tri or quad, d can be NULL */
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 7ce602238d3..8859be62fea 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -2642,10 +2642,20 @@ void plot_line_v2v2i(const int p1[2], const int p2[2], bool (*callback)(int, int
}
}
+/**
+ * \param callback: Takes the x, y coords and x-span (\a x_end is not inclusive),
+ * note that \a x_end will always be greater than \a x, so we can use:
+ *
+ * \code{.c}
+ * do {
+ * func(x, y);
+ * } while (++x != x_end);
+ * \endcode
+ */
void fill_poly_v2i_n(
const int xmin, const int ymin, const int xmax, const int ymax,
const int verts[][2], const int nr,
- void (*callback)(int, int, void *), void *userData)
+ void (*callback)(int x, int x_end, int y, void *), void *userData)
{
/* originally by Darel Rex Finley, 2007 */
@@ -2686,9 +2696,18 @@ void fill_poly_v2i_n(
if (node_x[i + 1] > xmin) {
if (node_x[i ] < xmin) node_x[i ] = xmin;
if (node_x[i + 1] > xmax) node_x[i + 1] = xmax;
+
+#if 0
+ /* for many x/y calls */
for (j = node_x[i]; j < node_x[i + 1]; j++) {
callback(j - xmin, pixel_y - ymin, userData);
}
+#else
+ /* for single call per x-span */
+ if (node_x[i] < node_x[i + 1]) {
+ callback(node_x[i] - xmin, node_x[i + 1] - xmin, pixel_y - ymin, userData);
+ }
+#endif
}
}
}
diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c
index a770fc26cba..83a1cdbedc6 100644
--- a/source/blender/editors/mesh/editmesh_select.c
+++ b/source/blender/editors/mesh/editmesh_select.c
@@ -249,10 +249,14 @@ struct LassoMaskData {
int width;
};
-static void edbm_mask_lasso_px_cb(int x, int y, void *user_data)
+static void edbm_mask_lasso_px_cb(int x, int x_end, int y, void *user_data)
{
struct LassoMaskData *data = user_data;
- data->px[(y * data->width) + x] = true;
+ unsigned int *px = &data->px[(y * data->width) + x];
+ do {
+ *px = true;
+ px++;
+ } while (++x != x_end);
}
diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c
index ead0fb5d067..83589a9b05e 100644
--- a/source/blender/editors/sculpt_paint/paint_mask.c
+++ b/source/blender/editors/sculpt_paint/paint_mask.c
@@ -315,10 +315,14 @@ static bool is_effected_lasso(LassoMaskData *data, float co[3])
return BLI_BITMAP_TEST_BOOL(data->px, scr_co_s[1] * data->width + scr_co_s[0]);
}
-static void mask_lasso_px_cb(int x, int y, void *user_data)
+static void mask_lasso_px_cb(int x, int x_end, int y, void *user_data)
{
struct LassoMaskData *data = user_data;
- BLI_BITMAP_ENABLE(data->px, (y * data->width) + x);
+ int index = (y * data->width) + x;
+ int index_end = (y * data->width) + x_end;
+ do {
+ BLI_BITMAP_ENABLE(data->px, index);
+ } while (++index != index_end);
}
static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op)
diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c
index 288e6711b56..92c9b81cdef 100644
--- a/source/blender/windowmanager/intern/wm_gesture.c
+++ b/source/blender/windowmanager/intern/wm_gesture.c
@@ -235,12 +235,15 @@ struct LassoFillData {
int width;
};
-static void draw_filled_lasso_px_cb(int x, int y, void *user_data)
+static void draw_filled_lasso_px_cb(int x, int x_end, int y, void *user_data)
{
struct LassoFillData *data = user_data;
unsigned char *col = (unsigned char *)&(data->px[(y * data->width) + x]);
- col[0] = col[1] = col[2] = 0xff;
- col[3] = 0x10;
+ do {
+ col[0] = col[1] = col[2] = 0xff;
+ col[3] = 0x10;
+ col += 4;
+ } while (++x != x_end);
}
static void draw_filled_lasso(wmWindow *win, wmGesture *gt)