[Bf-blender-cvs] [ebe7abb677e] soc-2021-vse-strip-thumbnails: Pushed all thumbnail rendering and caching code to new function. Cleaned up all conditions using context->is_thumb.

Aditya Y Jeppu noreply at git.blender.org
Tue Jun 22 19:45:31 CEST 2021


Commit: ebe7abb677e538f5e3ec9c13dfd8dcc73eb31564
Author: Aditya Y Jeppu
Date:   Tue Jun 22 23:13:18 2021 +0530
Branches: soc-2021-vse-strip-thumbnails
https://developer.blender.org/rBebe7abb677e538f5e3ec9c13dfd8dcc73eb31564

Pushed all thumbnail rendering and caching code to new function. Cleaned up
all conditions using context->is_thumb.

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

M	source/blender/editors/space_sequencer/sequencer_draw.c
M	source/blender/sequencer/SEQ_render.h
M	source/blender/sequencer/intern/render.c

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

diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c
index ca7115104c9..7baf98f64d9 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -1099,51 +1099,38 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
   struct Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
   SeqRenderData context = {0};
   ImBuf *ibuf;
-  int rectx, recty;
-  double render_size;
   float strip_x2 = x2;
   bool min_size;
   float aspect_ratio;
 
-  /* Fix size of obtained ibuf to max 256 for any dimension keeping aspect ratio same. Depends upon
-   * the scene set resolution for uniformity in all strips */
-  aspect_ratio = (float)scene->r.xsch / scene->r.ysch;
-
-  if (scene->r.xsch > scene->r.ysch) {
-    rectx = 256;
-    recty = roundf(rectx / aspect_ratio);
-  }
-  else {
-    recty = 256;
-    rectx = roundf(recty * aspect_ratio);
-  }
-
   /* if thumbs too small ignore */
   min_size = ((y2 - y1) / pixely) > 40 * U.dpi_fac;
 
   if (!min_size)
     return;
 
-  SEQ_render_new_render_data(
-      bmain, depsgraph, scene, rectx, recty, sseq->render_size, false, &context);
+  SEQ_render_new_render_data(bmain, depsgraph, scene, 0, 0, sseq->render_size, false, &context);
   context.view_id = BKE_scene_multiview_view_id_get(&scene->r, STEREO_LEFT_NAME);
   context.use_proxies = false;
   context.is_prefetch_render = false;
   context.is_proxy_render = false;
   context.is_thumb = true;
 
+  ibuf = SEQ_render_thumbnail(&context, seq, seq->startdisp);
+
   /*Calculate thumb dimensions */
   float thumb_h = (SEQ_STRIP_OFSTOP - SEQ_STRIP_OFSBOTTOM) - (20 * U.dpi_fac * pixely);
-  aspect_ratio = ((float)rectx) / recty;
+  aspect_ratio = ((float)ibuf->x) / ibuf->y;
   float thumb_h_px = thumb_h / pixely;
   float thumb_w = aspect_ratio * thumb_h_px * pixelx;
-  float zoom_x = thumb_w / rectx;
-  float zoom_y = thumb_h / recty;
+  float zoom_x = thumb_w / ibuf->x;
+  float zoom_y = thumb_h / ibuf->y;
+
+  IMB_freeImBuf(ibuf);
 
   y2 = y1 + thumb_h - pixely;
   x1 = seq->start;
 
-  int frame_factor = 0;
   float cut_off = 0;
   float upper_thumb_bound = strip_x2;
 
@@ -1156,7 +1143,6 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
 
     if (x2 < v2d->cur.xmin) {
       x1 = x2;
-      frame_factor++;
       continue;
     }
 
@@ -1180,7 +1166,7 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
     }
 
     /* Get the image */
-    ibuf = SEQ_render_give_ibuf_direct(&context, x1 + (int)(cut_off), seq);
+    ibuf = SEQ_render_thumbnail(&context, seq, x1 + (int)(cut_off));
 
     if (ibuf) {
       ED_draw_imbuf_ctx_clipping(C, ibuf, x1, y1, true, x1 + cut_off, y1, x2, y2, zoom_x, zoom_y);
@@ -1188,7 +1174,6 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
     }
 
     cut_off = 0;
-    frame_factor++;
     x1 = x2;
   }
 }
diff --git a/source/blender/sequencer/SEQ_render.h b/source/blender/sequencer/SEQ_render.h
index d8789eb21d0..20472650d20 100644
--- a/source/blender/sequencer/SEQ_render.h
+++ b/source/blender/sequencer/SEQ_render.h
@@ -68,6 +68,9 @@ struct ImBuf *SEQ_render_give_ibuf(const SeqRenderData *context,
 struct ImBuf *SEQ_render_give_ibuf_direct(const SeqRenderData *context,
                                           float timeline_frame,
                                           struct Sequence *seq);
+struct ImBuf *SEQ_render_thumbnail(SeqRenderData *context,
+                                   struct Sequence *seq,
+                                   float timeline_frame);
 void SEQ_render_init_colorspace(struct Sequence *seq);
 void SEQ_render_new_render_data(struct Main *bmain,
                                 struct Depsgraph *depsgraph,
diff --git a/source/blender/sequencer/intern/render.c b/source/blender/sequencer/intern/render.c
index 11feea1ddb3..c4307984adb 100644
--- a/source/blender/sequencer/intern/render.c
+++ b/source/blender/sequencer/intern/render.c
@@ -469,9 +469,6 @@ static bool seq_input_have_to_preprocess(const SeqRenderData *context,
     return true;
   }
 
-  if (context->is_thumb)
-    return true;
-
   return false;
 }
 
@@ -539,7 +536,7 @@ static void sequencer_thumbnail_transform(ImBuf *in, ImBuf *out, const SeqRender
                                          SEQ_rendersize_to_scale_factor(
                                              context->preview_render_size);
 
-  float image_scale_factor = (float)context->rectx / in->x;
+  float image_scale_factor = (float)out->x / in->x;
   float transform_matrix[3][3];
 
   /* set to keep same loc,scale,rot but change scale to thumb size limit*/
@@ -576,9 +573,7 @@ static void sequencer_preprocess_transform_crop(
                                              context->preview_render_size);
   const bool do_scale_to_render_size = seq_need_scale_to_render_size(seq, is_proxy_image);
   float image_scale_factor = do_scale_to_render_size ? 1.0f : preview_scale_factor;
-  if (context->is_thumb) {
-    image_scale_factor = (float)context->rectx / in->x;
-  }
+
   float transform_matrix[3][3];
   sequencer_image_crop_transform_matrix(
       seq, in, out, image_scale_factor, preview_scale_factor, transform_matrix);
@@ -647,21 +642,8 @@ static ImBuf *input_preprocess(const SeqRenderData *context,
     IMB_filtery(preprocessed_ibuf);
   }
 
-  /* For thumbnails only scale to low res and return. No need for other preprocess as thumbnail
-   * represents source */
-  if (context->is_thumb) {
-    preprocessed_ibuf = IMB_allocImBuf(
-        context->rectx, context->recty, 32, ibuf->rect_float ? IB_rectfloat : IB_rect);
-    sequencer_thumbnail_transform(ibuf, preprocessed_ibuf, context);
-    seq_imbuf_assign_spaces(scene, preprocessed_ibuf);
-    IMB_metadata_copy(preprocessed_ibuf, ibuf);
-    IMB_freeImBuf(ibuf);
-
-    return preprocessed_ibuf;
-  }
-
   if (sequencer_use_crop(seq) || sequencer_use_transform(seq) || context->rectx != ibuf->x ||
-      context->recty != ibuf->y || context->is_thumb) {
+      context->recty != ibuf->y) {
     const int x = context->rectx;
     const int y = context->recty;
     preprocessed_ibuf = IMB_allocImBuf(x, y, 32, ibuf->rect_float ? IB_rectfloat : IB_rect);
@@ -735,7 +717,7 @@ static ImBuf *seq_render_preprocess_ibuf(const SeqRenderData *context,
   }
 
   /* Proxies and effect strips are not stored in cache. */
-  if (!is_proxy_image && (seq->type & SEQ_TYPE_EFFECT) == 0 && !context->is_thumb) {
+  if (!is_proxy_image && (seq->type & SEQ_TYPE_EFFECT) == 0) {
     seq_cache_put(context, seq, timeline_frame, SEQ_CACHE_STORE_RAW, ibuf);
   }
 
@@ -743,11 +725,6 @@ static ImBuf *seq_render_preprocess_ibuf(const SeqRenderData *context,
     ibuf = input_preprocess(context, seq, timeline_frame, ibuf, is_proxy_image);
   }
 
-  if (context->is_thumb) {
-    seq_cache_put(context, seq, timeline_frame, SEQ_CACHE_STORE_THUMBNAIL, ibuf);
-    return ibuf;
-  }
-
   seq_cache_put(context, seq, timeline_frame, SEQ_CACHE_STORE_PREPROCESSED, ibuf);
   return ibuf;
 }
@@ -1796,22 +1773,14 @@ ImBuf *seq_render_strip(const SeqRenderData *context,
   bool use_preprocess = false;
   bool is_proxy_image = false;
 
-  if (context->is_thumb) {
-    ibuf = seq_cache_get(context, seq, timeline_frame, SEQ_CACHE_STORE_THUMBNAIL);
-    if (ibuf != NULL)
-      return ibuf;
-  }
-  else {
-    ibuf = seq_cache_get(context, seq, timeline_frame, SEQ_CACHE_STORE_PREPROCESSED);
-    if (ibuf != NULL) {
-      return ibuf;
-    }
+  ibuf = seq_cache_get(context, seq, timeline_frame, SEQ_CACHE_STORE_PREPROCESSED);
+  if (ibuf != NULL) {
+    return ibuf;
   }
 
   /* Proxies are not stored in cache. */
   if (!SEQ_can_use_proxy(
-          context, seq, SEQ_rendersize_to_proxysize(context->preview_render_size)) &&
-      !context->is_thumb) {
+          context, seq, SEQ_rendersize_to_proxysize(context->preview_render_size))) {
     ibuf = seq_cache_get(context, seq, timeline_frame, SEQ_CACHE_STORE_RAW);
   }
 
@@ -2056,7 +2025,54 @@ ImBuf *SEQ_render_give_ibuf_direct(const SeqRenderData *context,
   seq_render_state_init(&state);
 
   ImBuf *ibuf = seq_render_strip(context, &state, seq, timeline_frame);
-
   return ibuf;
 }
+
+ImBuf *SEQ_render_thumbnail(SeqRenderData *context, Sequence *seq, float timeline_frame)
+{
+  SeqRenderState state;
+  seq_render_state_init(&state);
+  ImBuf *ibuf = NULL, *scaled_ibuf = NULL;
+  bool is_proxy_image = false;
+  float rectx, recty;
+
+  ibuf = seq_cache_get(context, seq, timeline_frame, SEQ_CACHE_STORE_THUMBNAIL);
+  if (ibuf != NULL) {
+    return ibuf;
+  }
+
+  ibuf = do_render_strip_uncached(context, &state, seq, timeline_frame, &is_proxy_image);
+
+  if (ibuf) {
+    float aspect_ratio = (float)ibuf->x / ibuf->y;
+
+    /* Fix the dimensions to be max 256 for x or y */
+    if (ibuf->x > ibuf->y) {
+      rectx = 256;
+      recty = roundf(rectx / aspect_ratio);
+    }
+    else {
+      recty = 256;
+      rectx = roundf(recty * aspect_ratio);
+    }
+
+    /* perform scaling of ibuf to thumb size */
+    scaled_ibuf = IMB_allocImBuf(rectx, recty, 32, ibuf->rect_float ? IB_rectfloat : IB_rect);
+    sequencer_thumbnail_transform(ibuf, scaled_ibuf, context);
+    seq_imbuf_assign_spaces(context->scene, scaled_ibuf);
+    IMB_metadata_copy(scaled_ibuf, ibuf);
+    IMB_freeImBuf(ibuf);
+  }
+
+  if (scaled_ibuf)
+    seq_cache_put(context, seq, timeline_frame, SEQ_CACHE_STORE_THUMBNAIL, scaled_ibuf);
+
+  if (scaled_ibuf == NULL) {
+    ibuf = IMB_allocImBuf(rectx, recty, 32, IB_rect);
+    seq_imbuf_assign_spaces(context->scene, scaled_ibuf);
+  }
+
+  return scaled_ibuf;
+}
+
 /** \} */



More information about the Bf-blender-cvs mailing list