[Bf-blender-cvs] [34bccaa5fc3] temp-vse-thumbnail-mod: Fix "guaranteed" images not loading. Add `SEQ_FLAG_SKIP_THUMBNAILS` flag to signify that strip did not produce thumbnail and so should be skipped when drawing.

Richard Antalik noreply at git.blender.org
Fri Sep 17 05:33:41 CEST 2021


Commit: 34bccaa5fc3fe0b3d4857d29f11eb5393cdcd7d7
Author: Richard Antalik
Date:   Fri Sep 17 05:32:02 2021 +0200
Branches: temp-vse-thumbnail-mod
https://developer.blender.org/rB34bccaa5fc3fe0b3d4857d29f11eb5393cdcd7d7

Fix "guaranteed" images not loading.
Add `SEQ_FLAG_SKIP_THUMBNAILS` flag to signify that strip did not
produce thumbnail and so should be skipped when drawing.

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

M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/editors/space_sequencer/sequencer_draw.c
M	source/blender/editors/space_sequencer/space_sequencer.c
M	source/blender/makesdna/DNA_sequence_types.h
M	source/blender/sequencer/SEQ_utils.h
M	source/blender/sequencer/intern/render.c
M	source/blender/sequencer/intern/sequencer.c
M	source/blender/sequencer/intern/utils.c

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

diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 2598c53a5e0..5eaf0f28b31 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -1774,7 +1774,7 @@ static void do_versions_seq_set_cache_defaults(Editing *ed)
 
 static bool seq_update_flags_cb(Sequence *seq, void *UNUSED(user_data))
 {
-  seq->flag &= ~(SEQ_FLAG_UNUSED_6 | SEQ_FLAG_UNUSED_18 | SEQ_FLAG_UNUSED_19 | SEQ_FLAG_UNUSED_21);
+  seq->flag &= ~((1 << 6) | (1 << 18) | (1 << 19) | (1 << 21));
   if (seq->type == SEQ_TYPE_SPEED) {
     SpeedControlVars *s = (SpeedControlVars *)seq->effectdata;
     s->flags &= ~(SEQ_SPEED_UNUSED_1);
diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c
index 82b4c478db8..60e2ec8073a 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -45,6 +45,7 @@
 #include "BKE_context.h"
 #include "BKE_fcurve.h"
 #include "BKE_global.h"
+#include "BKE_main.h"
 #include "BKE_scene.h"
 #include "BKE_sound.h"
 
@@ -1571,9 +1572,8 @@ static void last_displayed_thumbnails_list_cleanup(GSet *previously_displayed,
   }
 }
 
-static int sequencer_thumbnail_closest_guaranteed_frame_get(Sequence *seq,
-                                                            int timeline_frame,
-                                                            GSet *previously_displayed)
+static int sequencer_thumbnail_closest_previous_frame_get(int timeline_frame,
+                                                          GSet *previously_displayed)
 {
   int best_diff = INT_MAX;
   int best_frame = timeline_frame;
@@ -1590,17 +1590,55 @@ static int sequencer_thumbnail_closest_guaranteed_frame_get(Sequence *seq,
     }
     BLI_gsetIterator_step(&gset_iter);
   }
+  return best_frame;
+}
+
+static int sequencer_thumbnail_closest_guaranteed_frame_get(Sequence *seq, int timeline_frame)
+{
+  if (timeline_frame <= seq->startdisp) {
+    return seq->startdisp;
+  }
 
   /* Set of "guaranteed" thumbnails. */
   const int frame_index = timeline_frame - seq->startdisp;
   const int frame_step = SEQ_render_thumbnails_guaranteed_set_frame_step_get(seq);
   const int relative_base_frame = round_fl_to_int((frame_index / (float)frame_step)) * frame_step;
   const int nearest_guaranted_absolute_frame = relative_base_frame + seq->startdisp;
-  if (abs(nearest_guaranted_absolute_frame - timeline_frame) < best_diff) {
-    return nearest_guaranted_absolute_frame;
+  return nearest_guaranted_absolute_frame;
+}
+
+static ImBuf *sequencer_thumbnail_closest_from_memory(const SeqRenderData *context,
+                                                      Sequence *seq,
+                                                      int timeline_frame,
+                                                      GSet *previously_displayed,
+                                                      rcti *crop,
+                                                      bool clipped)
+{
+  int frame_previous = sequencer_thumbnail_closest_previous_frame_get(timeline_frame,
+                                                                      previously_displayed);
+  ImBuf *ibuf_previous = SEQ_get_thumbnail(context, seq, frame_previous, crop, clipped);
+
+  int frame_guaranteed = sequencer_thumbnail_closest_guaranteed_frame_get(seq, timeline_frame);
+  ImBuf *ibuf_guaranteed = SEQ_get_thumbnail(context, seq, frame_guaranteed, crop, clipped);
+
+  if (ibuf_previous && ibuf_guaranteed &&
+      abs(frame_previous - timeline_frame) < abs(frame_guaranteed - timeline_frame)) {
+
+    IMB_freeImBuf(ibuf_guaranteed);
+    return ibuf_previous;
+  }
+  else {
+    IMB_freeImBuf(ibuf_previous);
+    return ibuf_guaranteed;
   }
 
-  return best_frame;
+  if (ibuf_previous == NULL) {
+    return ibuf_guaranteed;
+  }
+
+  if (ibuf_guaranteed == NULL) {
+    return ibuf_previous;
+  }
 }
 
 static void draw_seq_strip_thumbnail(View2D *v2d,
@@ -1617,15 +1655,20 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
   rcti crop;
 
   /* If width of the strip too small ignore drawing thumbnails. */
-  if ((y2 - y1) / pixely <= 40 * U.dpi_fac)
+  if ((y2 - y1) / pixely <= 40 * U.dpi_fac) {
     return;
+  }
 
   SeqRenderData context = sequencer_thumbnail_context_init(C);
+
+  if ((seq->flag & SEQ_FLAG_SKIP_THUMBNAILS) != 0) {
+    return;
+  }
+
   seq_get_thumb_image_dimensions(
       seq, pixelx, pixely, &thumb_width, &thumb_height, &image_width, &image_height);
 
   float thumb_y_end = y1 + thumb_height - pixely;
-  float thumb_x_start = seq->start;
 
   float cut_off = 0;
   float upper_thumb_bound = (seq->endstill) ? (seq->start + seq->len) : seq->enddisp;
@@ -1633,7 +1676,7 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
     upper_thumb_bound = seq->enddisp;
   }
 
-  thumb_x_start = seq_thumbnail_get_start_frame(seq, thumb_width, &v2d->cur);
+  float thumb_x_start = seq_thumbnail_get_start_frame(seq, thumb_width, &v2d->cur);
   float thumb_x_end;
 
   while (thumb_x_start + thumb_width < v2d->cur.xmin) {
@@ -1691,22 +1734,14 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
 
     int timeline_frame = round_fl_to_int(thumb_x_start);
 
-    /* Override timeline frame when zooming with closest that should be kept in memory. */
-    if (sequencer_thumbnail_v2d_is_navigating(C)) {
-      timeline_frame = sequencer_thumbnail_closest_guaranteed_frame_get(
-          seq, timeline_frame, last_displayed_thumbnails);
-    }
-
     /* Get the image. */
     ImBuf *ibuf = SEQ_get_thumbnail(&context, seq, timeline_frame, &crop, clipped);
 
     if (!ibuf) {
       sequencer_thumbnail_start_job_if_necessary(C, scene->ed, v2d, true);
 
-      /* Render one of guaranteed frames, if image is not found. */
-      timeline_frame = sequencer_thumbnail_closest_guaranteed_frame_get(
-          seq, timeline_frame, last_displayed_thumbnails);
-      ibuf = SEQ_get_thumbnail(&context, seq, timeline_frame, &crop, clipped);
+      ibuf = sequencer_thumbnail_closest_from_memory(
+          &context, seq, timeline_frame, last_displayed_thumbnails, &crop, clipped);
     }
     /* Store recently rendered frames, so they can be reused when zooming. */
     else if (!sequencer_thumbnail_v2d_is_navigating(C)) {
@@ -2680,8 +2715,6 @@ static void draw_seq_strips(const bContext *C, Editing *ed, ARegion *region)
   int sel = 0, j;
   float pixelx = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask);
 
-  sequencer_thumbnail_start_job_if_necessary(C, ed, v2d, false);
-
   /* Loop through twice, first unselected, then selected. */
   for (j = 0; j < 2; j++) {
     Sequence *seq;
diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c
index 7f30dd11188..41dfe95f1a1 100644
--- a/source/blender/editors/space_sequencer/space_sequencer.c
+++ b/source/blender/editors/space_sequencer/space_sequencer.c
@@ -190,6 +190,8 @@ static SpaceLink *sequencer_create(const ScrArea *UNUSED(area), const Scene *sce
   region->v2d.keeptot = 0;
   region->v2d.align = V2D_ALIGN_NO_NEG_Y;
 
+  sseq->runtime.last_displayed_thumbnails = NULL;
+
   return (SpaceLink *)sseq;
 }
 
diff --git a/source/blender/makesdna/DNA_sequence_types.h b/source/blender/makesdna/DNA_sequence_types.h
index 6ecbefc00fa..6d9e8f64a75 100644
--- a/source/blender/makesdna/DNA_sequence_types.h
+++ b/source/blender/makesdna/DNA_sequence_types.h
@@ -516,7 +516,7 @@ enum {
   SEQ_OVERLAP = (1 << 3),
   SEQ_FILTERY = (1 << 4),
   SEQ_MUTE = (1 << 5),
-  SEQ_FLAG_UNUSED_6 = (1 << 6), /* cleared */
+  SEQ_FLAG_SKIP_THUMBNAILS = (1 << 6),
   SEQ_REVERSE_FRAMES = (1 << 7),
   SEQ_IPO_FRAME_LOCKED = (1 << 8),
   SEQ_EFFECT_NOT_LOADED = (1 << 9),
diff --git a/source/blender/sequencer/SEQ_utils.h b/source/blender/sequencer/SEQ_utils.h
index 09de7bc67e9..d30a1b2d7ae 100644
--- a/source/blender/sequencer/SEQ_utils.h
+++ b/source/blender/sequencer/SEQ_utils.h
@@ -34,6 +34,7 @@ struct Mask;
 struct Scene;
 struct Sequence;
 struct StripElem;
+struct SeqRenderData;
 
 void SEQ_sort(struct ListBase *seqbase);
 void SEQ_sequence_base_unique_name_recursive(struct Scene *scene,
@@ -57,7 +58,6 @@ void SEQ_set_scale_to_fit(const struct Sequence *seq,
                           const int preview_height,
                           const eSeqImageFitMethod fit_method);
 void SEQ_ensure_unique_name(struct Sequence *seq, struct Scene *scene);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/sequencer/intern/render.c b/source/blender/sequencer/intern/render.c
index 258bcf1f594..81333aa069b 100644
--- a/source/blender/sequencer/intern/render.c
+++ b/source/blender/sequencer/intern/render.c
@@ -2109,6 +2109,12 @@ void SEQ_render_thumbnails(const SeqRenderData *context,
     if (ibuf) {
       seq_cache_thumbnail_put(context, seq_orig, round_fl_to_int(start_frame), ibuf, view_area);
       IMB_freeImBuf(ibuf);
+      seq_orig->flag &= ~SEQ_FLAG_SKIP_THUMBNAILS;
+    }
+    else {
+      /* Can not open source file. */
+      seq_orig->flag |= SEQ_FLAG_SKIP_THUMBNAILS;
+      return;
     }
 
     start_frame += frame_step;
@@ -2119,9 +2125,13 @@ void SEQ_render_thumbnails(const SeqRenderData *context,
  * memory, so they can be used when zooming.*/
 int SEQ_render_thumbnails_guaranteed_set_frame_step_get(const Sequence *seq)
 {
-  /* Arbitrary, but due to performance reasons should be as low as possible. */
-  const int thumbnails_base_set_count = 50;
   const int content_len = (seq->enddisp - seq->startdisp - seq->startstill - seq->endstill);
+
+  /* Arbitrary, but due to performance reasons should be as low as possible. */
+  const int thumbnails_base_set_count = min_ii(content_len / 100, 30);
+  if (thumbnails_base_set_count <= 0) {
+    return 0;
+  }
   return content_len / thumbnails_base_set_count;
 }
 
@@ -2135,15 +2145,16 @@ void SEQ_render_thumbnails_base_set(
   int timeline_frame = seq->startdisp;
   const int frame_step = SEQ_render_thumbnails_guaranteed_set_frame_step_get(seq);
 
-  if (frame_step == 0) {
-    return;
-  }
-
   while (timeline_frame < seq->enddisp && !*stop)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list