[Bf-blender-cvs] [2bf4c74130f] blender-v2.82-release: Fix T74425: Cannot texture paint an images sequence anymore

Philipp Oeser noreply at git.blender.org
Tue Mar 10 14:07:25 CET 2020


Commit: 2bf4c74130ff47c8442f23f1a9f039997dea1710
Author: Philipp Oeser
Date:   Wed Mar 4 14:40:21 2020 +0100
Branches: blender-v2.82-release
https://developer.blender.org/rB2bf4c74130ff47c8442f23f1a9f039997dea1710

Fix T74425: Cannot texture paint an images sequence anymore

Caused by the introduction of UDIM (rBc30d6571bb47).

We need to make sure the tiles ImageUser is set up correctly [especially
the framenr], otherwise BKE_image_acquire_ibuf() and friends will fail
to find the correct ImBuf.

Also instead of initializing a minimal BKE_imageuser_default, now use
an appropriate ImageUser if avaliable and pass this around (instead of
just the tile_number). 2D painting can reuse the Image Editor ImageUser,
for 3D painting we still rely on a default ImageUser in most places, but
at least set the framenr correctly].

This also fixes crashes when doing image operations such as inverting or
resizing on images in a sequence in the Image Editor.

This also fixes color sampling (S) from the 3DView going wrong for image
sequences (would fallback to OpenGL sampling because an ImBuf could not
be found).

Maniphest Tasks: T74425

Differential Revision: https://developer.blender.org/D7022

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

M	source/blender/editors/include/ED_paint.h
M	source/blender/editors/sculpt_paint/paint_image.c
M	source/blender/editors/sculpt_paint/paint_image_2d.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/sculpt_paint/paint_utils.c
M	source/blender/editors/space_image/image_ops.c
M	source/blender/editors/space_image/image_undo.c

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

diff --git a/source/blender/editors/include/ED_paint.h b/source/blender/editors/include/ED_paint.h
index e15e4c45c4a..8188ec59cff 100644
--- a/source/blender/editors/include/ED_paint.h
+++ b/source/blender/editors/include/ED_paint.h
@@ -23,6 +23,7 @@
 
 struct ImBuf;
 struct Image;
+struct ImageUser;
 struct UndoStep;
 struct UndoType;
 struct bContext;
@@ -38,7 +39,7 @@ void ED_keymap_paint(struct wmKeyConfig *keyconf);
 void ED_imapaint_clear_partial_redraw(void);
 void ED_imapaint_dirty_region(struct Image *ima,
                               struct ImBuf *ibuf,
-                              int tile_number,
+                              struct ImageUser *iuser,
                               int x,
                               int y,
                               int w,
@@ -54,7 +55,7 @@ void ED_image_undo_push_begin(const char *name, int paint_mode);
 void ED_image_undo_push_begin_with_image(const char *name,
                                          struct Image *image,
                                          struct ImBuf *ibuf,
-                                         int tile_number);
+                                         struct ImageUser *iuser);
 
 void ED_image_undo_push_end(void);
 void ED_image_undo_restore(struct UndoStep *us);
@@ -64,7 +65,7 @@ void ED_image_undosys_type(struct UndoType *ut);
 void *ED_image_paint_tile_find(struct ListBase *undo_tiles,
                                struct Image *ima,
                                struct ImBuf *ibuf,
-                               int tile_number,
+                               struct ImageUser *iuser,
                                int x_tile,
                                int y_tile,
                                unsigned short **r_mask,
@@ -73,7 +74,7 @@ void *ED_image_paint_tile_push(struct ListBase *undo_tiles,
                                struct Image *ima,
                                struct ImBuf *ibuf,
                                struct ImBuf **tmpibuf,
-                               int tile_number,
+                               struct ImageUser *iuser,
                                int x_tile,
                                int y_tile,
                                unsigned short **r_mask,
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 6d1a32d1c45..2e53663672b 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -120,7 +120,7 @@ void imapaint_region_tiles(
 }
 
 void ED_imapaint_dirty_region(
-    Image *ima, ImBuf *ibuf, int tile_number, int x, int y, int w, int h, bool find_old)
+    Image *ima, ImBuf *ibuf, ImageUser *iuser, int x, int y, int w, int h, bool find_old)
 {
   ImBuf *tmpibuf = NULL;
   int tilex, tiley, tilew, tileh, tx, ty;
@@ -153,7 +153,7 @@ void ED_imapaint_dirty_region(
   for (ty = tiley; ty <= tileh; ty++) {
     for (tx = tilex; tx <= tilew; tx++) {
       ED_image_paint_tile_push(
-          undo_tiles, ima, ibuf, &tmpibuf, tile_number, tx, ty, NULL, NULL, false, find_old);
+          undo_tiles, ima, ibuf, &tmpibuf, iuser, tx, ty, NULL, NULL, false, find_old);
     }
   }
 
diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c
index a667c7062e6..d00f439d457 100644
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@ -1335,11 +1335,11 @@ static void paint_2d_do_making_brush(ImagePaintState *s,
 
       if (tile->canvas->rect_float) {
         tmpbuf.rect_float = ED_image_paint_tile_find(
-            undo_tiles, s->image, tile->canvas, tile->iuser.tile, tx, ty, &mask, false);
+            undo_tiles, s->image, tile->canvas, &tile->iuser, tx, ty, &mask, false);
       }
       else {
         tmpbuf.rect = ED_image_paint_tile_find(
-            undo_tiles, s->image, tile->canvas, tile->iuser.tile, tx, ty, &mask, false);
+            undo_tiles, s->image, tile->canvas, &tile->iuser, tx, ty, &mask, false);
       }
 
       IMB_rectblend(tile->canvas,
@@ -1448,7 +1448,7 @@ static int paint_2d_op(void *state,
   for (a = 0; a < tot; a++) {
     ED_imapaint_dirty_region(s->image,
                              canvas,
-                             tile->iuser.tile,
+                             &tile->iuser,
                              region[a].destx,
                              region[a].desty,
                              region[a].width,
@@ -1667,6 +1667,7 @@ void paint_2d_stroke(void *ps,
 void *paint_2d_new_stroke(bContext *C, wmOperator *op, int mode)
 {
   Scene *scene = CTX_data_scene(C);
+  SpaceImage *sima = CTX_wm_space_image(C);
   ToolSettings *settings = scene->toolsettings;
   Brush *brush = BKE_paint_brush(&settings->imapaint.paint);
 
@@ -1697,7 +1698,7 @@ void *paint_2d_new_stroke(bContext *C, wmOperator *op, int mode)
   s->num_tiles = BLI_listbase_count(&s->image->tiles);
   s->tiles = MEM_callocN(sizeof(ImagePaintTile) * s->num_tiles, "ImagePaintTile");
   for (int i = 0; i < s->num_tiles; i++) {
-    BKE_imageuser_default(&s->tiles[i].iuser);
+    s->tiles[i].iuser = sima->iuser;
   }
   s->tiles[0].iuser.ok = true;
 
@@ -1941,7 +1942,7 @@ void paint_2d_bucket_fill(const bContext *C,
 
   if (!mouse_final || !br) {
     /* first case, no image UV, fill the whole image */
-    ED_imapaint_dirty_region(ima, ibuf, tile_number, 0, 0, ibuf->x, ibuf->y, false);
+    ED_imapaint_dirty_region(ima, ibuf, iuser, 0, 0, ibuf->x, ibuf->y, false);
 
     if (do_float) {
       for (x_px = 0; x_px < ibuf->x; x_px++) {
@@ -1984,7 +1985,7 @@ void paint_2d_bucket_fill(const bContext *C,
     }
 
     /* change image invalidation method later */
-    ED_imapaint_dirty_region(ima, ibuf, tile_number, 0, 0, ibuf->x, ibuf->y, false);
+    ED_imapaint_dirty_region(ima, ibuf, iuser, 0, 0, ibuf->x, ibuf->y, false);
 
     stack = BLI_stack_new(sizeof(size_t), __func__);
     touched = BLI_BITMAP_NEW(((size_t)ibuf->x) * ibuf->y, "bucket_fill_bitmap");
@@ -2157,7 +2158,7 @@ void paint_2d_gradient_fill(
   do_float = (ibuf->rect_float != NULL);
 
   /* this will be substituted by something else when selection is available */
-  ED_imapaint_dirty_region(ima, ibuf, tile_number, 0, 0, ibuf->x, ibuf->y, false);
+  ED_imapaint_dirty_region(ima, ibuf, iuser, 0, 0, ibuf->x, ibuf->y, false);
 
   if (do_float) {
     for (x_px = 0; x_px < ibuf->x; x_px++) {
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index d649f5017eb..20d11999000 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -743,9 +743,11 @@ static bool project_paint_PickColor(const ProjPaintState *ps,
   ima = project_paint_face_paint_image(ps, tri_index);
   /** we must have got the imbuf before getting here. */
   int tile_number = project_paint_face_paint_tile(ima, lt_tri_uv[0]);
+  /* XXX get appropriate ImageUser instead */
   ImageUser iuser;
   BKE_imageuser_default(&iuser);
   iuser.tile = tile_number;
+  iuser.framenr = ima->lastframe;
   ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
   if (ibuf == NULL) {
     return false;
@@ -1837,7 +1839,7 @@ static int project_paint_undo_subtiles(const TileInfo *tinf, int tx, int ty)
                                           pjIma->ima,
                                           pjIma->ibuf,
                                           tinf->tmpibuf,
-                                          pjIma->iuser.tile,
+                                          &pjIma->iuser,
                                           tx,
                                           ty,
                                           &pjIma->maskRect[tile_index],
@@ -1850,7 +1852,7 @@ static int project_paint_undo_subtiles(const TileInfo *tinf, int tx, int ty)
                                           pjIma->ima,
                                           pjIma->ibuf,
                                           tinf->tmpibuf,
-                                          pjIma->iuser.tile,
+                                          &pjIma->iuser,
                                           tx,
                                           ty,
                                           NULL,
@@ -4266,7 +4268,7 @@ static bool project_paint_winclip(const ProjPaintState *ps, const ProjPaintFaceC
 typedef struct PrepareImageEntry {
   struct PrepareImageEntry *next, *prev;
   Image *ima;
-  int tile;
+  ImageUser iuser;
 } PrepareImageEntry;
 
 static void project_paint_build_proj_ima(ProjPaintState *ps,
@@ -4281,9 +4283,7 @@ static void project_paint_build_proj_ima(ProjPaintState *ps,
   projIma = ps->projImages = BLI_memarena_alloc(arena, sizeof(ProjPaintImage) * ps->image_tot);
 
   for (entry = used_images->first, i = 0; entry; entry = entry->next, i++, projIma++) {
-    memset(&projIma->iuser, 0, sizeof(ImageUser));
-    BKE_imageuser_default(&projIma->iuser);
-    projIma->iuser.tile = entry->tile;
+    projIma->iuser = entry->iuser;
     int size;
     projIma->ima = entry->ima;
     projIma->touch = 0;
@@ -4435,19 +4435,21 @@ static void project_paint_prepare_all_faces(ProjPaintState *ps,
       if (tpage_last != tpage || tile_last != tile) {
         image_index = 0;
         for (PrepareImageEntry *e = used_images.first; e; e = e->next, image_index++) {
-          if (e->ima == tpage && e->tile == tile) {
+          if (e->ima == tpage && e->iuser.tile == tile) {
             break;
           }
         }
 
         if (image_index == ps->image_tot) {
+          /* XXX get appropriate ImageUser instead */
           ImageUser iuser;
           BKE_imageuser_default(&iuser);
           iuser.tile = tile;
+          iuser.framenr = tpage->lastframe;
           if (BKE_image_has_ibuf(tpage, &iuser)) {
             PrepareImageEntry *e = MEM_callocN(sizeof(PrepareImageEntry), "PrepareImageEntry");
             e->ima = tpage;
-            e->tile = tile;
+            e->iuser = iuser;
             BLI_addtail(&used_images, e);
             ps->image_tot++;
           }
diff --git a/source/blender/editors/sculpt_paint

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list