svn merge ^/trunk/blender -r43294:43338
[blender.git] / source / blender / editors / sculpt_paint / paint_image.c
index fb29bec286407d7346a061a6122e43b23df964c7..50583c2bbfbfdbd178bdfc5019a12992444bfb6e 100644 (file)
@@ -383,7 +383,7 @@ typedef struct UndoImageTile {
        void *rect;
        int x, y;
 
-       short source;
+       short source, use_float;
        char gen_type;
 } UndoImageTile;
 
@@ -413,11 +413,13 @@ static void *image_undo_push_tile(Image *ima, ImBuf *ibuf, ImBuf **tmpibuf, int
        ListBase *lb= undo_paint_push_get_list(UNDO_PAINT_IMAGE);
        UndoImageTile *tile;
        int allocsize;
+       short use_float = ibuf->rect_float ? 1 : 0;
 
        for(tile=lb->first; tile; tile=tile->next)
                if(tile->x == x_tile && tile->y == y_tile && ima->gen_type == tile->gen_type && ima->source == tile->source)
-                       if(strcmp(tile->idname, ima->id.name)==0 && strcmp(tile->ibufname, ibuf->name)==0)
-                               return tile->rect;
+                       if(tile->use_float == use_float)
+                               if(strcmp(tile->idname, ima->id.name)==0 && strcmp(tile->ibufname, ibuf->name)==0)
+                                       return tile->rect;
        
        if (*tmpibuf==NULL)
                *tmpibuf = IMB_allocImBuf(IMAPAINT_TILE_SIZE, IMAPAINT_TILE_SIZE, 32, IB_rectfloat|IB_rect);
@@ -435,6 +437,7 @@ static void *image_undo_push_tile(Image *ima, ImBuf *ibuf, ImBuf **tmpibuf, int
 
        tile->gen_type= ima->gen_type;
        tile->source= ima->source;
+       tile->use_float= use_float;
 
        undo_copy_tile(tile, *tmpibuf, ibuf, 0);
        undo_paint_push_count_alloc(UNDO_PAINT_IMAGE, allocsize);
@@ -455,6 +458,8 @@ static void image_undo_restore(bContext *C, ListBase *lb)
                                                        IB_rectfloat|IB_rect);
        
        for(tile=lb->first; tile; tile=tile->next) {
+               short use_float;
+
                /* find image based on name, pointer becomes invalid with global undo */
                if(ima && strcmp(tile->idname, ima->id.name)==0) {
                        /* ima is valid */
@@ -464,6 +469,7 @@ static void image_undo_restore(bContext *C, ListBase *lb)
                }
 
                ibuf= BKE_image_get_ibuf(ima, NULL);
+               use_float = ibuf->rect_float ? 1 : 0;
 
                if(ima && ibuf && strcmp(tile->ibufname, ibuf->name)!=0) {
                        /* current ImBuf filename was changed, probably current frame
@@ -480,6 +486,9 @@ static void image_undo_restore(bContext *C, ListBase *lb)
                if (ima->gen_type != tile->gen_type || ima->source != tile->source)
                        continue;
 
+               if (use_float != tile->use_float)
+                       continue;
+
                undo_copy_tile(tile, tmpibuf, ibuf, 1);
 
                GPU_free_image(ima); /* force OpenGL reload */
@@ -1807,7 +1816,9 @@ static int project_bucket_isect_circle(const float cent[2], const float radius_s
                return 1;
         */
        
-       if((bucket_bounds->xmin <= cent[0] && bucket_bounds->xmax >= cent[0]) || (bucket_bounds->ymin <= cent[1] && bucket_bounds->ymax >= cent[1]) ) {
+       if ( (bucket_bounds->xmin <= cent[0] && bucket_bounds->xmax >= cent[0]) ||
+            (bucket_bounds->ymin <= cent[1] && bucket_bounds->ymax >= cent[1]) )
+       {
                return 1;
        }
        
@@ -2807,7 +2818,11 @@ static int project_bucket_face_isect(ProjPaintState *ps, int bucket_x, int bucke
        p4[0] = bucket_bounds.xmax;     p4[1] = bucket_bounds.ymin;
                
        if (mf->v4) {
-               if(     isect_point_quad_v2(p1, v1, v2, v3, v4) || isect_point_quad_v2(p2, v1, v2, v3, v4) || isect_point_quad_v2(p3, v1, v2, v3, v4) || isect_point_quad_v2(p4, v1, v2, v3, v4) ||
+               if ( isect_point_quad_v2(p1, v1, v2, v3, v4) ||
+                    isect_point_quad_v2(p2, v1, v2, v3, v4) ||
+                    isect_point_quad_v2(p3, v1, v2, v3, v4) ||
+                    isect_point_quad_v2(p4, v1, v2, v3, v4) ||
+
                        /* we can avoid testing v3,v1 because another intersection MUST exist if this intersects */
                        (isect_line_line_v2(p1, p2, v1, v2) || isect_line_line_v2(p1, p2, v2, v3) || isect_line_line_v2(p1, p2, v3, v4)) ||
                        (isect_line_line_v2(p2, p3, v1, v2) || isect_line_line_v2(p2, p3, v2, v3) || isect_line_line_v2(p2, p3, v3, v4)) ||
@@ -2818,7 +2833,10 @@ static int project_bucket_face_isect(ProjPaintState *ps, int bucket_x, int bucke
                }
        }
        else {
-               if(     isect_point_tri_v2(p1, v1, v2, v3) || isect_point_tri_v2(p2, v1, v2, v3) || isect_point_tri_v2(p3, v1, v2, v3) || isect_point_tri_v2(p4, v1, v2, v3) ||
+               if ( isect_point_tri_v2(p1, v1, v2, v3) ||
+                    isect_point_tri_v2(p2, v1, v2, v3) ||
+                    isect_point_tri_v2(p3, v1, v2, v3) ||
+                    isect_point_tri_v2(p4, v1, v2, v3) ||
                        /* we can avoid testing v3,v1 because another intersection MUST exist if this intersects */
                        (isect_line_line_v2(p1, p2, v1, v2) || isect_line_line_v2(p1, p2, v2, v3)) ||
                        (isect_line_line_v2(p2, p3, v1, v2) || isect_line_line_v2(p2, p3, v2, v3)) ||
@@ -3078,8 +3096,8 @@ static void project_paint_begin(ProjPaintState *ps)
                        }
 
                        /* same as view3d_get_object_project_mat */
-                       mul_m4_m4m4(vmat, ps->ob->obmat, viewmat);
-                       mul_m4_m4m4(ps->projectMat, vmat, winmat);
+                       mult_m4_m4m4(vmat, viewmat, ps->ob->obmat);
+                       mult_m4_m4m4(ps->projectMat, winmat, vmat);
                }
 
 
@@ -4844,7 +4862,7 @@ static int texture_paint_init(bContext *C, wmOperator *op)
                image_undo_restore, image_undo_free);
 
        /* create painter */
-       pop->painter= brush_painter_new(pop->s.brush);
+       pop->painter= brush_painter_new(scene, pop->s.brush);
 
        return 1;
 }
@@ -4950,6 +4968,7 @@ static int paint_exec(bContext *C, wmOperator *op)
 
 static void paint_apply_event(bContext *C, wmOperator *op, wmEvent *event)
 {
+       const Scene *scene = CTX_data_scene(C);
        PaintOperation *pop= op->customdata;
        wmTabletData *wmtab;
        PointerRNA itemptr;
@@ -4981,13 +5000,13 @@ static void paint_apply_event(bContext *C, wmOperator *op, wmEvent *event)
 
                /* special exception here for too high pressure values on first touch in
                   windows for some tablets, then we just skip first touch ..  */
-               if (tablet && (pressure >= 0.99f) && ((pop->s.brush->flag & BRUSH_SPACING_PRESSURE) || brush_use_alpha_pressure(pop->s.brush) || brush_use_size_pressure(pop->s.brush)))
+               if (tablet && (pressure >= 0.99f) && ((pop->s.brush->flag & BRUSH_SPACING_PRESSURE) || brush_use_alpha_pressure(scene, pop->s.brush) || brush_use_size_pressure(scene, pop->s.brush)))
                        return;
 
                /* This can be removed once fixed properly in
                 brush_painter_paint(BrushPainter *painter, BrushFunc func, float *pos, double time, float pressure, void *user) 
                 at zero pressure we should do nothing 1/2^12 is .0002 which is the sensitivity of the most sensitive pen tablet available*/
-               if (tablet && (pressure < .0002f) && ((pop->s.brush->flag & BRUSH_SPACING_PRESSURE) || brush_use_alpha_pressure(pop->s.brush) || brush_use_size_pressure(pop->s.brush)))
+               if (tablet && (pressure < .0002f) && ((pop->s.brush->flag & BRUSH_SPACING_PRESSURE) || brush_use_alpha_pressure(scene, pop->s.brush) || brush_use_size_pressure(scene, pop->s.brush)))
                        return;
        
        }