Commit: e830334357d1f73afbeeeb421ffcbed8e99b2fab
Author: Campbell Barton
Date:   Fri Jan 8 23:29:42 2016 +1100
Branches: master
https://developer.blender.org/rBe830334357d1f73afbeeeb421ffcbed8e99b2fab

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.

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

M       source/blender/blenkernel/intern/tracking.c
M       source/blender/blenlib/BLI_math_geom.h
M       source/blender/blenlib/intern/math_geom.c
M       source/blender/editors/mesh/editmesh_select.c
M       source/blender/editors/sculpt_paint/paint_mask.c
M       source/blender/windowmanager/intern/wm_gesture.c

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

diff --git a/source/blender/blenkernel/intern/tracking.c 
b/source/blender/blenkernel/intern/tracking.c
index 094db3c..e5719bd 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 d8e2b7f..863bc76 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 7ce6022..8859be6 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 a770fc2..83a1cdb 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 ead0fb5..83589a9 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 288e671..92c9b81 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)

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to