Revision: 49561
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49561
Author: campbellbarton
Date: 2012-08-04 20:17:22 +0000 (Sat, 04 Aug 2012)
Log Message:
-----------
resolve some issues with curve resolution calculaction
- resolution could become so high that it would wrap around to a negative
number, now check for small numbers before doing float division.
- resolution was being calculated in some cases when it already met the clamp
value - now this is skipped.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/BKE_mask.h
trunk/blender/source/blender/blenkernel/intern/mask.c
trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c
trunk/blender/source/blender/editors/mask/mask_add.c
Modified: trunk/blender/source/blender/blenkernel/BKE_mask.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_mask.h 2012-08-04 19:34:38 UTC
(rev 49560)
+++ trunk/blender/source/blender/blenkernel/BKE_mask.h 2012-08-04 20:17:22 UTC
(rev 49561)
@@ -64,8 +64,8 @@
/* splines */
struct MaskSpline *BKE_mask_spline_add(struct MaskLayer *masklay);
-int BKE_mask_spline_resolution(struct MaskSpline *spline, int width, int
height);
-int BKE_mask_spline_feather_resolution(struct MaskSpline *spline, int width,
int height);
+unsigned int BKE_mask_spline_resolution(struct MaskSpline *spline, int width,
int height);
+unsigned int BKE_mask_spline_feather_resolution(struct MaskSpline *spline, int
width, int height);
int BKE_mask_spline_differentiate_calc_total(const struct MaskSpline *spline,
const int resol);
@@ -76,7 +76,7 @@
const int resol))[2];
float (*BKE_mask_spline_differentiate_with_resolution(struct MaskSpline
*spline, int width, int height, int *tot_diff_point))[2];
float
(*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(struct
MaskSpline *spline, int *tot_feather_point,
- const
int resol, const int do_collapse))[2];
+ const
unsigned int resol, const int do_collapse))[2];
float (*BKE_mask_spline_feather_differentiated_points_with_resolution(struct
MaskSpline *spline, int width, int height, int *tot_feather_point))[2];
float (*BKE_mask_spline_feather_points(struct MaskSpline *spline, int
*tot_feather_point))[2];
@@ -98,16 +98,18 @@
void BKE_mask_point_set_handle(struct MaskSplinePoint *point, float loc[2],
int keep_direction,
float orig_handle[2], float orig_vec[3][3]);
-float *BKE_mask_point_segment_diff(struct MaskSpline *spline, struct
MaskSplinePoint *point, int *tot_diff_point);
+float *BKE_mask_point_segment_diff(struct MaskSpline *spline, struct
MaskSplinePoint *point,
+ unsigned int *tot_diff_point);
float *BKE_mask_point_segment_feather_diff(struct MaskSpline *spline, struct
MaskSplinePoint *point,
- int *tot_feather_point);
+ unsigned int *tot_feather_point);
float *BKE_mask_point_segment_diff_with_resolution(struct MaskSpline *spline,
struct MaskSplinePoint *point,
- int width, int height, int
*tot_diff_point);
+ int width, int height,
+ unsigned int
*tot_diff_point);
float *BKE_mask_point_segment_feather_diff_with_resolution(struct MaskSpline
*spline, struct MaskSplinePoint *point,
int width, int
height,
- int
*tot_feather_point);
+ unsigned int
*tot_feather_point);
void BKE_mask_point_segment_co(struct MaskSpline *spline, struct
MaskSplinePoint *point, float u, float co[2]);
void BKE_mask_point_normal(struct MaskSpline *spline, struct MaskSplinePoint
*point,
Modified: trunk/blender/source/blender/blenkernel/intern/mask.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mask.c 2012-08-04
19:34:38 UTC (rev 49560)
+++ trunk/blender/source/blender/blenkernel/intern/mask.c 2012-08-04
20:17:22 UTC (rev 49561)
@@ -265,10 +265,10 @@
return spline;
}
-int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height)
+unsigned int BKE_mask_spline_resolution(MaskSpline *spline, int width, int
height)
{
float max_segment = 0.01f;
- int i, resol = 1;
+ unsigned int i, resol = 1;
if (width != 0 && height != 0) {
if (width >= height)
@@ -281,7 +281,7 @@
MaskSplinePoint *point = &spline->points[i];
BezTriple *bezt, *bezt_next;
float a, b, c, len;
- int cur_resol;
+ unsigned int cur_resol;
bezt = &point->bezt;
bezt_next = mask_spline_point_next_bezt(spline, spline->points,
point);
@@ -298,24 +298,34 @@
cur_resol = len / max_segment;
resol = MAX2(resol, cur_resol);
+
+ if (resol >= MASK_RESOL_MAX) {
+ break;
+ }
}
- BLI_assert(resol > 0);
-
if (resol > MASK_RESOL_MAX) {
resol = MASK_RESOL_MAX;
}
+ else if (resol == 0) {
+ return 1;
+ }
return resol;
}
-int BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, int
height)
+unsigned int BKE_mask_spline_feather_resolution(MaskSpline *spline, int width,
int height)
{
const float max_segment = 0.005;
- int resol = BKE_mask_spline_resolution(spline, width, height);
+ unsigned int resol = BKE_mask_spline_resolution(spline, width, height);
float max_jump = 0.0f;
int i;
+ /* avoid checking the featrher if we already hit the maximum value */
+ if (resol >= MASK_RESOL_MAX) {
+ return MASK_RESOL_MAX;
+ }
+
for (i = 0; i < spline->tot_point; i++) {
MaskSplinePoint *point = &spline->points[i];
float prev_u, prev_w;
@@ -325,10 +335,17 @@
prev_w = point->bezt.weight;
for (j = 0; j < point->tot_uw; j++) {
- float jump = fabsf((point->uw[j].w - prev_w) /
(point->uw[j].u - prev_u));
+ const float w_diff = (point->uw[j].w - prev_w);
+ const float u_diff = (point->uw[j].u - prev_u);
- max_jump = MAX2(max_jump, jump);
+ /* avoid divide by zero and very high values,
+ * though these get clamped eventually */
+ if (u_diff > FLT_EPSILON) {
+ float jump = fabsf(w_diff / u_diff);
+ max_jump = MAX2(max_jump, jump);
+ }
+
prev_u = point->uw[j].u;
prev_w = point->uw[j].w;
}
@@ -336,11 +353,12 @@
resol += max_jump / max_segment;
- BLI_assert(resol > 0);
-
if (resol > MASK_RESOL_MAX) {
resol = MASK_RESOL_MAX;
}
+ else if (resol == 0) {
+ return 1;
+ }
return resol;
}
@@ -705,7 +723,7 @@
*/
float
(*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(MaskSpline
*spline,
int
*tot_feather_point,
- const
int resol,
+ const
unsigned int resol,
const
int do_collapse
))[2]
{
@@ -779,7 +797,7 @@
float
(*BKE_mask_spline_feather_differentiated_points_with_resolution(MaskSpline
*spline, int width, int height,
int
*tot_feather_point))[2]
{
- int resol = BKE_mask_spline_feather_resolution(spline, width, height);
+ unsigned int resol = BKE_mask_spline_feather_resolution(spline, width,
height);
return
BKE_mask_spline_feather_differentiated_points_with_resolution_ex(spline,
tot_feather_point, resol, FALSE);
}
@@ -1056,10 +1074,11 @@
float *BKE_mask_point_segment_feather_diff_with_resolution(MaskSpline *spline,
MaskSplinePoint *point,
int width, int
height,
- int
*tot_feather_point)
+ unsigned int
*tot_feather_point)
{
float *feather, *fp;
- int i, resol = BKE_mask_spline_feather_resolution(spline, width,
height);
+ unsigned int resol = BKE_mask_spline_feather_resolution(spline, width,
height);
+ unsigned int i;
feather = fp = MEM_callocN(2 * resol * sizeof(float), "mask point
spline feather diff points");
@@ -1080,13 +1099,13 @@
return feather;
}
-float *BKE_mask_point_segment_feather_diff(MaskSpline *spline, MaskSplinePoint
*point, int *tot_feather_point)
+float *BKE_mask_point_segment_feather_diff(MaskSpline *spline, MaskSplinePoint
*point, unsigned int *tot_feather_point)
{
return BKE_mask_point_segment_feather_diff_with_resolution(spline,
point, 0, 0, tot_feather_point);
}
float *BKE_mask_point_segment_diff_with_resolution(MaskSpline *spline,
MaskSplinePoint *point,
- int width, int height, int
*tot_diff_point)
+ int width, int height,
unsigned int *tot_diff_point)
{
MaskSplinePoint *points_array =
BKE_mask_spline_point_array_from_point(spline, point);
@@ -1115,7 +1134,7 @@
return diff_points;
}
-float *BKE_mask_point_segment_diff(MaskSpline *spline, MaskSplinePoint *point,
int *tot_diff_point)
+float *BKE_mask_point_segment_diff(MaskSpline *spline, MaskSplinePoint *point,
unsigned int *tot_diff_point)
{
return BKE_mask_point_segment_diff_with_resolution(spline, point, 0, 0,
tot_diff_point);
}
Modified: trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c
2012-08-04 19:34:38 UTC (rev 49560)
+++ trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c
2012-08-04 20:17:22 UTC (rev 49561)
@@ -577,9 +577,9 @@
float (*diff_feather_points)[2];
int tot_diff_feather_points;
- const int resol_a = BKE_mask_spline_resolution(spline,
width, height) / 4;
- const int resol_b =
BKE_mask_spline_feather_resolution(spline, width, height) / 4;
- const int resol = CLAMPIS(MAX2(resol_a, resol_b), 4,
512);
+ const unsigned int resol_a =
BKE_mask_spline_resolution(spline, width, height) / 4;
+ const unsigned int resol_b =
BKE_mask_spline_feather_resolution(spline, width, height) / 4;
+ const unsigned int resol = CLAMPIS(MAX2(resol_a,
resol_b), 4, 512);
diff_points =
BKE_mask_spline_differentiate_with_resolution_ex(
spline, &tot_diff_point, resol);
Modified: trunk/blender/source/blender/editors/mask/mask_add.c
===================================================================
--- trunk/blender/source/blender/editors/mask/mask_add.c 2012-08-04
19:34:38 UTC (rev 49560)
+++ trunk/blender/source/blender/editors/mask/mask_add.c 2012-08-04
20:17:22 UTC (rev 49561)
@@ -91,13 +91,14 @@
i++, cur_point++)
{
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs