Commit: 68126662f05eb262c06b21e4746b3b02118427a0
Author: Antony Riakiotakis
Date:   Sun Apr 27 16:43:38 2014 +0300
https://developer.blender.org/rB68126662f05eb262c06b21e4746b3b02118427a0

Fix some clamping issues.

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

M       source/blender/blenkernel/intern/brush.c
M       source/blender/editors/sculpt_paint/paint_image_2d.c
M       source/blender/editors/sculpt_paint/paint_image_proj.c
M       source/blender/imbuf/intern/rectop.c

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

diff --git a/source/blender/blenkernel/intern/brush.c 
b/source/blender/blenkernel/intern/brush.c
index fc9be23..3c1c2c9 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -757,12 +757,14 @@ float BKE_brush_sample_masktex(const Scene *scene, Brush 
*br,
                          rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool);
        }
 
+       CLAMP(intensity, 0.0, 1.0);
+
        switch(br->mask_pressure) {
                case BRUSH_MASK_PRESSURE_CUTOFF:
                        intensity  = ((1.0 - intensity) < 
ups->size_pressure_value)? 1.0 : 0.0;
                        break;
                case BRUSH_MASK_PRESSURE_RAMP:
-                       intensity = ups->size_pressure_value + intensity*(1.0 - 
ups->size_pressure_value);
+                       intensity = ups->size_pressure_value + intensity * (1.0 
- ups->size_pressure_value);
                        break;
                default:
                        break;
diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c 
b/source/blender/editors/sculpt_paint/paint_image_2d.c
index e0bbaf3..31c701e 100644
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@ -220,7 +220,6 @@ static unsigned short 
*brush_painter_mask_ibuf_new(BrushPainter *painter, int si
                        float res;
                        brush_imbuf_tex_co(&mask_mapping, x, y, texco);
                        res = BKE_brush_sample_masktex(scene, brush, texco, 
thread, pool);
-                       CLAMP(res, 0.0, 1.0);
                        *m = (unsigned short)(65535.0f * res);
                }
        }
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c 
b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 6d5b2f9..825ab3d 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -4160,15 +4160,15 @@ static void *do_projectpaint_thread(void *ph_v)
 
                                                        if (ps->is_maskbrush) {
                                                                float texmask = 
BKE_brush_sample_masktex(ps->scene, ps->brush, projPixel->projCoSS, 
thread_index, pool);
-                                                               CLAMP(texmask, 
0.0f, 1.0f);
                                                                max_mask *= 
texmask;
                                                        }
 
                                                        if (brush->flag & 
BRUSH_ACCUMULATE)
-                                                               mask = 
min_ff(mask_accum + max_mask, 65535.0f);
+                                                               mask = 
mask_accum + max_mask;
                                                        else
                                                                mask = 
mask_accum + (max_mask - mask_accum * falloff);
 
+                                                       mask = min_ff(mask, 
65535.0f);
                                                        mask_short = (unsigned 
short)mask;
 
                                                        if (mask_short > 
*projPixel->mask_accum) {
diff --git a/source/blender/imbuf/intern/rectop.c 
b/source/blender/imbuf/intern/rectop.c
index 0eb1d72..0303fca 100644
--- a/source/blender/imbuf/intern/rectop.c
+++ b/source/blender/imbuf/intern/rectop.c
@@ -551,9 +551,11 @@ void IMB_rectblend(ImBuf *dbuf, ImBuf *obuf, ImBuf *sbuf, 
unsigned short *dmask,
                                                                float mask;
 
                                                                if (accumulate)
-                                                                       mask = 
min_ff(*dmr + mask_lim, 65535.0);
+                                                                       mask = 
*dmr + mask_lim;
                                                                else
-                                                                       mask = 
*dmr + (((mask_lim - *dmr  * (*cmr) / 65535.0f)));
+                                                                       mask = 
*dmr + mask_lim - (*dmr  * (*cmr / 65535.0f));
+
+                                                               mask = 
min_ff(mask, 65535.0);
 
                                                                if (mask > 
*dmr) {
                                                                        
unsigned char mask_src[4];
@@ -575,12 +577,14 @@ void IMB_rectblend(ImBuf *dbuf, ImBuf *obuf, ImBuf *sbuf, 
unsigned short *dmask,
                                        else {
                                                for (x = width; x > 0; x--, 
dr++, or++, sr++, cmr++) {
                                                        unsigned char *src = 
(unsigned char *)sr;
-                                                       unsigned short mask = 
(float)mask_max * ((float)(*cmr));
+                                                       float mask = 
(float)mask_max * ((float)(*cmr));
 
                                                        if (texmaskrect)
                                                                mask *= 
((float)(*tmr++) / 65535.0f);
 
-                                                       if (src[3] && mask) {
+                                                       mask = min_ff(mask, 
65535.0);
+
+                                                       if (src[3] && (mask > 
0.0)) {
                                                                unsigned char 
mask_src[4];
 
                                                                mask_src[0] = 
src[0];
@@ -635,13 +639,15 @@ void IMB_rectblend(ImBuf *dbuf, ImBuf *obuf, ImBuf *sbuf, 
unsigned short *dmask,
                                                                if (accumulate)
                                                                        mask = 
min_ff(*dmr + mask_lim, 65535.0);
                                                                else
-                                                                       mask = 
*dmr + (((mask_lim - *dmr  * (*cmr) / 65535.0f)));
+                                                                       mask = 
*dmr + mask_lim - (*dmr  * (*cmr / 65535.0f));
+
+                                                               mask = 
min_ff(mask, 65535.0);
 
                                                                if (mask > 
*dmr) {
                                                                        float 
mask_srf[4];
 
                                                                        *dmr = 
mask;
-                                                                       
mul_v4_v4fl(mask_srf, srf, mask * (1.0f / 65535.0f));
+                                                                       
mul_v4_v4fl(mask_srf, srf, mask / 65535.0f);
 
                                                                        
func_float(drf, orf, mask_srf);
                                                                }
@@ -657,10 +663,12 @@ void IMB_rectblend(ImBuf *dbuf, ImBuf *obuf, ImBuf *sbuf, 
unsigned short *dmask,
                                                        if (texmaskrect)
                                                                mask *= 
((float)(*tmr++) / 65535.0f);
 
-                                                       if (srf[3] && mask) {
+                                                       mask = min_ff(mask, 
65535.0);
+
+                                                       if (srf[3] && (mask > 
0.0)) {
                                                                float 
mask_srf[4];
 
-                                                               
mul_v4_v4fl(mask_srf, srf, mask * (1.0f / 65535.0f));
+                                                               
mul_v4_v4fl(mask_srf, srf, mask / 65535.0f);
 
                                                                func_float(drf, 
orf, mask_srf);
                                                        }

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

Reply via email to