[Bf-blender-cvs] [bad23a721f5] soc-2021-vse-strip-thumbnails: Thumbnail Code Cleanup
Aditya Y Jeppu
noreply at git.blender.org
Sun Jun 27 15:11:10 CEST 2021
Commit: bad23a721f547a6bb6151b6f33e9f85ac05ce5c8
Author: Aditya Y Jeppu
Date: Sun Jun 27 18:39:06 2021 +0530
Branches: soc-2021-vse-strip-thumbnails
https://developer.blender.org/rBbad23a721f547a6bb6151b6f33e9f85ac05ce5c8
Thumbnail Code Cleanup
Improved from the hacky way of cropping using the same process for scaling
to thumb size to using dedicated IMB_rect_crop method. Cleaned up
unnecessary code and variables.
===================================================================
M source/blender/editors/space_sequencer/sequencer_draw.c
M source/blender/sequencer/SEQ_render.h
M source/blender/sequencer/intern/image_cache.c
M source/blender/sequencer/intern/image_cache.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 30b1d68f9a2..03ef414d9e6 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -1099,8 +1099,11 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
SeqRenderData context = {0};
ImBuf *ibuf;
bool min_size, clipped = false;
- float aspect_ratio, image_x, image_y, cropx_min, cropx_max;
- rctf crop;
+ float aspect_ratio, image_y, cropx_min, cropx_max;
+ rcti crop;
+
+ /* Not sending v2d directly to have Drawing and Internal code separation */
+ float cache_limits[4] = {v2d->tot.xmin, v2d->tot.xmax, v2d->cur.xmin, v2d->cur.xmax};
/* if thumbs too small ignore */
min_size = ((y2 - y1) / pixely) > 40 * U.dpi_fac;
@@ -1115,8 +1118,7 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
context.is_proxy_render = false;
context.is_thumb = true;
- ibuf = SEQ_render_thumbnail(&context, seq, seq->startdisp, v2d, &crop, clipped);
- image_x = ibuf->x;
+ ibuf = SEQ_render_thumbnail(&context, seq, seq->startdisp, cache_limits, &crop, false);
image_y = ibuf->y;
/*Calculate thumb dimensions */
@@ -1133,7 +1135,7 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
x1 = seq->start;
float cut_off = 0;
- float upper_thumb_bound = seq->endstill ? seq->enddisp - seq->endstill : seq->enddisp;
+ float upper_thumb_bound = (seq->endstill) ? (seq->start + seq->len) : seq->enddisp;
while (x1 < upper_thumb_bound) {
x2 = x1 + thumb_w;
@@ -1162,7 +1164,6 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
}
/* clip if full thumbnail cannot be displayed */
-
if (x2 > (upper_thumb_bound)) {
x2 = upper_thumb_bound;
clipped = true;
@@ -1172,19 +1173,17 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
cropx_min = (cut_off / pixelx) / (zoom_y / pixely);
cropx_max = ((x2 - x1) / pixelx) / (zoom_y / pixely);
- BLI_rctf_init(&crop, cropx_min, cropx_max, 0, image_y);
- /* Get the image */
+ BLI_rcti_init(&crop, (int)(cropx_min), (int)(cropx_max)-1, 0, (int)(image_y)-1);
- ibuf = SEQ_render_thumbnail(&context, seq, x1 + (int)(cut_off), v2d, &crop, clipped);
+ /* Get the image */
+ ibuf = SEQ_render_thumbnail(&context, seq, x1 + (int)(cut_off), cache_limits, &crop, clipped);
- GPU_blend(GPU_BLEND_ALPHA);
if (ibuf) {
- ED_draw_imbuf_ctx_clipping(C, ibuf, x1, y1, false, x1 + cut_off, y1, x2, y2, zoom_x, zoom_y);
+ ED_draw_imbuf_ctx_clipping(
+ C, ibuf, x1 + cut_off, y1, true, x1 + cut_off, y1, x2, y2, zoom_x, zoom_y);
IMB_freeImBuf(ibuf);
}
- GPU_blend(GPU_BLEND_NONE);
-
cut_off = 0;
x1 = x2;
}
diff --git a/source/blender/sequencer/SEQ_render.h b/source/blender/sequencer/SEQ_render.h
index 06ebbfac36d..6860b2c15d2 100644
--- a/source/blender/sequencer/SEQ_render.h
+++ b/source/blender/sequencer/SEQ_render.h
@@ -71,8 +71,8 @@ struct ImBuf *SEQ_render_give_ibuf_direct(const SeqRenderData *context,
struct ImBuf *SEQ_render_thumbnail(SeqRenderData *context,
struct Sequence *seq,
float timeline_frame,
- View2D *v2d,
- rctf *crop,
+ float *cache_limits,
+ rcti *crop,
bool clipped);
void SEQ_render_init_colorspace(struct Sequence *seq);
void SEQ_render_new_render_data(struct Main *bmain,
diff --git a/source/blender/sequencer/intern/image_cache.c b/source/blender/sequencer/intern/image_cache.c
index 06c081c1ba1..8d0d6a28941 100644
--- a/source/blender/sequencer/intern/image_cache.c
+++ b/source/blender/sequencer/intern/image_cache.c
@@ -1339,7 +1339,7 @@ void seq_cache_cleanup_sequence(Scene *scene,
seq_cache_unlock(scene);
}
-void seq_cache_thumbnail_cleanup(Scene *scene, Sequence *seq, Sequence *seq_changed)
+void seq_cache_thumbnail_cleanup(Scene *scene, Sequence *seq_changed)
{
SeqCache *cache = seq_cache_get_from_scene(scene);
if (!cache) {
@@ -1465,7 +1465,7 @@ void seq_cache_thumbnail_put(const SeqRenderData *context,
float timeline_frame,
int type,
ImBuf *i,
- View2D *v2d)
+ float *cache_limits)
{
if (i == NULL || context->skip_cache || context->is_proxy_render || !seq) {
return;
@@ -1495,22 +1495,22 @@ void seq_cache_thumbnail_put(const SeqRenderData *context,
SeqCache *cache = seq_cache_get_from_scene(scene);
SeqCacheKey *key = seq_cache_allocate_key(cache, context, seq, timeline_frame, type);
- /* Limit cache to 1000 images stored. */
- if (cache->count >= 1000) {
- float safe_ofs = 20;
+ /* Limit cache to 5000 images stored. */
+ if (cache->count >= 5000) {
+ float safe_ofs = 200;
Sequence cut = *seq;
/* Frames to the left */
- cut.startdisp = (int)v2d->tot.xmin;
- cut.enddisp = (int)v2d->cur.xmin - (int)safe_ofs;
+ cut.startdisp = (int)cache_limits[0];
+ cut.enddisp = (int)cache_limits[2] - (int)safe_ofs;
if (cut.startdisp < cut.enddisp) {
- seq_cache_thumbnail_cleanup(scene, seq, &cut);
+ seq_cache_thumbnail_cleanup(scene, &cut);
}
/* Frames to the right */
- cut.startdisp = v2d->cur.xmax + safe_ofs;
- cut.enddisp = v2d->tot.xmax;
+ cut.startdisp = cache_limits[3] + safe_ofs;
+ cut.enddisp = cache_limits[1];
if (cut.startdisp < cut.enddisp) {
- seq_cache_thumbnail_cleanup(scene, seq, &cut);
+ seq_cache_thumbnail_cleanup(scene, &cut);
}
}
diff --git a/source/blender/sequencer/intern/image_cache.h b/source/blender/sequencer/intern/image_cache.h
index fbe47f3edd0..f59a0859c2a 100644
--- a/source/blender/sequencer/intern/image_cache.h
+++ b/source/blender/sequencer/intern/image_cache.h
@@ -51,7 +51,7 @@ void seq_cache_thumbnail_put(const struct SeqRenderData *context,
float timeline_frame,
int type,
struct ImBuf *i,
- struct View2D *v2d);
+ float *cache_limits);
bool seq_cache_put_if_possible(const struct SeqRenderData *context,
struct Sequence *seq,
float timeline_frame,
@@ -66,7 +66,7 @@ void seq_cache_cleanup_sequence(struct Scene *scene,
struct Sequence *seq_changed,
int invalidate_types,
bool force_seq_changed_range);
-void seq_cache_thumbnail_cleanup(Scene *scene, Sequence *seq, Sequence *seq_changed);
+void seq_cache_thumbnail_cleanup(Scene *scene, Sequence *seq_changed);
bool seq_cache_is_full(void);
#ifdef __cplusplus
diff --git a/source/blender/sequencer/intern/render.c b/source/blender/sequencer/intern/render.c
index defefcd7fed..3b4ff5c87d3 100644
--- a/source/blender/sequencer/intern/render.c
+++ b/source/blender/sequencer/intern/render.c
@@ -530,12 +530,6 @@ static void sequencer_image_crop_init(const Sequence *seq,
static void sequencer_thumbnail_transform(ImBuf *in, ImBuf *out, const SeqRenderData *context)
{
- const Scene *scene = context->scene;
- const float preview_scale_factor = context->preview_render_size == SEQ_RENDER_SIZE_SCENE ?
- (float)scene->r.size / 100 :
- SEQ_rendersize_to_scale_factor(
- context->preview_render_size);
-
float image_scale_factor = (float)out->x / in->x;
float transform_matrix[3][3];
@@ -2029,45 +2023,29 @@ ImBuf *SEQ_render_give_ibuf_direct(const SeqRenderData *context,
ImBuf *SEQ_render_thumbnail(SeqRenderData *context,
Sequence *seq,
float timeline_frame,
- View2D *v2d,
- rctf *crop,
+ float *cache_limits,
+ rcti *crop,
bool clipped)
{
SeqRenderState state;
seq_render_state_init(&state);
- ImBuf *ibuf = NULL, *scaled_ibuf = NULL, *cropped_ibuf = NULL;
+ ImBuf *ibuf = NULL, *scaled_ibuf = NULL, *temp = NULL;
bool is_proxy_image = false;
float rectx, recty;
ibuf = seq_cache_get(context, seq, timeline_frame, SEQ_CACHE_STORE_THUMBNAIL);
if (ibuf != NULL) {
- /* do clipping */ // TODO(AYJ) : Move to separate function
+ /* Do clipping */
if (clipped) {
- cropped_ibuf = IMB_allocImBuf(
- ibuf->x, ibuf->y, 32, ibuf->rect_float ? IB_rectfloat : IB_rect);
-
- float transform_matrix[3][3];
- const float scale_x = 1;
- const float scale_y = 1;
- const float image_center_offs_x = (cropped_ibuf->x - ibuf->x) / 2;
- const float image_center_offs_y = (cropped_ibuf->y - ibuf->y) / 2;
- const float pivot[2] = {ibuf->x / 2, ibuf->y / 2};
- loc_rot_size_to_mat3(transform_matrix,
- (const float[]){image_center_offs_x, image_center_offs_y},
- 0,
- (const float[]){scale_x, scale_y});
- transform_pivot_set_m3(transform_matrix, pivot);
- invert_m3(transform_matrix);
-
- const eIMBInterpolationFilterMode filter = context->for_render ? IMB_FILTER_BILINEAR :
- IMB_FILTER_NEAREST;
- IMB_transform(ibuf, cropped_ibuf, transform_matrix, crop, filter);
-
- seq_imbuf_assign_spaces(context->scene, cropped_ibuf);
- IMB_metadata_copy(cropped_ibuf, ibuf);
+ temp = IMB_dupImBuf(ibuf);
+ if (crop->xmin < 0 && crop->ymin < 0) {
+ crop->xmin = 0;
+ crop->ymin = 0;
+ }
+ IMB_rect_crop(temp, crop);
IMB_freeImBuf(ibuf);
- if (cropped_ibuf != NULL)
- return cropped_ibuf;
+ if (temp != NULL)
+ return temp;
}
return
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list