[Bf-blender-cvs] [d2c95bd7e4d] soc-2021-vse-strip-thumbnails: Strip thumbnail drawing Fix : Thumbnails crop to exact width of strip
Aditya Y Jeppu
noreply at git.blender.org
Sat Jun 26 20:23:45 CEST 2021
Commit: d2c95bd7e4dc59cd79513792e100a04b01a14c3a
Author: Aditya Y Jeppu
Date: Sat Jun 26 23:51:15 2021 +0530
Branches: soc-2021-vse-strip-thumbnails
https://developer.blender.org/rBd2c95bd7e4dc59cd79513792e100a04b01a14c3a
Strip thumbnail drawing Fix : Thumbnails crop to exact width of strip
The end thumbnails crop to the exact left and right edges of the strip.
The previous version had poor clipping of thumbnails.
===================================================================
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 f3ffa45a23f..30b1d68f9a2 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -1091,7 +1091,6 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
float y1,
float x2,
float y2,
- float handsize_clamped,
float pixelx,
float pixely)
{
@@ -1099,9 +1098,9 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
struct Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
SeqRenderData context = {0};
ImBuf *ibuf;
- float strip_x2 = x2;
- bool min_size;
- float aspect_ratio;
+ bool min_size, clipped = false;
+ float aspect_ratio, image_x, image_y, cropx_min, cropx_max;
+ rctf crop;
/* if thumbs too small ignore */
min_size = ((y2 - y1) / pixely) > 40 * U.dpi_fac;
@@ -1116,7 +1115,9 @@ 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);
+ ibuf = SEQ_render_thumbnail(&context, seq, seq->startdisp, v2d, &crop, clipped);
+ image_x = ibuf->x;
+ image_y = ibuf->y;
/*Calculate thumb dimensions */
float thumb_h = (SEQ_STRIP_OFSTOP - SEQ_STRIP_OFSBOTTOM) - (20 * U.dpi_fac * pixely);
@@ -1132,12 +1133,14 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
x1 = seq->start;
float cut_off = 0;
- float upper_thumb_bound = strip_x2;
+ float upper_thumb_bound = seq->endstill ? seq->enddisp - seq->endstill : seq->enddisp;
- while (x1 < upper_thumb_bound - 1) {
+ while (x1 < upper_thumb_bound) {
x2 = x1 + thumb_w;
+ clipped = false;
- /* Checks to make sure that thumbs are loaded only when in view */
+ /* Checks to make sure that thumbs are loaded only when in view and within the confines of the
+ * strip */
if (x1 > v2d->cur.xmax)
break;
@@ -1149,6 +1152,7 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
/* set the clipping bound to show the left handle moving over thumbs and not shift thumbs */
if (IN_RANGE_INCL(seq->startdisp, x1, x2)) {
cut_off = seq->startdisp - x1;
+ clipped = true;
}
/* ignore thumbs to the left of strip */
@@ -1159,20 +1163,28 @@ static void draw_seq_strip_thumbnail(View2D *v2d,
/* clip if full thumbnail cannot be displayed */
- if (x2 >= (upper_thumb_bound - 1)) {
- x2 = (upper_thumb_bound - 1);
+ if (x2 > (upper_thumb_bound)) {
+ x2 = upper_thumb_bound;
+ clipped = true;
if (x2 - x1 < 1)
break;
}
+ 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 */
- ibuf = SEQ_render_thumbnail(&context, seq, x1 + (int)(cut_off), v2d);
+ ibuf = SEQ_render_thumbnail(&context, seq, x1 + (int)(cut_off), v2d, &crop, clipped);
+
+ GPU_blend(GPU_BLEND_ALPHA);
if (ibuf) {
- ED_draw_imbuf_ctx_clipping(C, ibuf, x1, y1, true, x1 + cut_off, y1, x2, y2, zoom_x, zoom_y);
+ ED_draw_imbuf_ctx_clipping(C, ibuf, x1, y1, false, x1 + cut_off, y1, x2, y2, zoom_x, zoom_y);
IMB_freeImBuf(ibuf);
}
+ GPU_blend(GPU_BLEND_NONE);
+
cut_off = 0;
x1 = x2;
}
@@ -1278,8 +1290,7 @@ static void draw_seq_strip(const bContext *C,
}
if (seq->type == SEQ_TYPE_MOVIE || seq->type == SEQ_TYPE_IMAGE) {
- draw_seq_strip_thumbnail(
- v2d, C, sseq, scene, seq, x1, y1, x2, y2, handsize_clamped, pixelx, pixely);
+ draw_seq_strip_thumbnail(v2d, C, sseq, scene, seq, x1, y1, x2, y2, pixelx, pixely);
}
pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
diff --git a/source/blender/sequencer/SEQ_render.h b/source/blender/sequencer/SEQ_render.h
index e3346d35aa4..06ebbfac36d 100644
--- a/source/blender/sequencer/SEQ_render.h
+++ b/source/blender/sequencer/SEQ_render.h
@@ -71,7 +71,9 @@ 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);
+ View2D *v2d,
+ rctf *crop,
+ bool clipped);
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 21897d0685a..defefcd7fed 100644
--- a/source/blender/sequencer/intern/render.c
+++ b/source/blender/sequencer/intern/render.c
@@ -544,11 +544,9 @@ static void sequencer_thumbnail_transform(ImBuf *in, ImBuf *out, const SeqRender
const float scale_y = 1 * image_scale_factor;
const float image_center_offs_x = (out->x - in->x) / 2;
const float image_center_offs_y = (out->y - in->y) / 2;
- const float translate_x = 0 * preview_scale_factor + image_center_offs_x;
- const float translate_y = 0 * preview_scale_factor + image_center_offs_y;
const float pivot[2] = {in->x / 2, in->y / 2};
loc_rot_size_to_mat3(transform_matrix,
- (const float[]){translate_x, translate_y},
+ (const float[]){image_center_offs_x, image_center_offs_y},
0,
(const float[]){scale_x, scale_y});
transform_pivot_set_m3(transform_matrix, pivot);
@@ -2031,16 +2029,46 @@ ImBuf *SEQ_render_give_ibuf_direct(const SeqRenderData *context,
ImBuf *SEQ_render_thumbnail(SeqRenderData *context,
Sequence *seq,
float timeline_frame,
- View2D *v2d)
+ View2D *v2d,
+ rctf *crop,
+ bool clipped)
{
SeqRenderState state;
seq_render_state_init(&state);
- ImBuf *ibuf = NULL, *scaled_ibuf = NULL;
+ ImBuf *ibuf = NULL, *scaled_ibuf = NULL, *cropped_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) {
+ /* do clipping */ // TODO(AYJ) : Move to separate function
+ 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);
+ IMB_freeImBuf(ibuf);
+ if (cropped_ibuf != NULL)
+ return cropped_ibuf;
+ }
return ibuf;
}
@@ -2067,12 +2095,41 @@ ImBuf *SEQ_render_thumbnail(SeqRenderData *context,
IMB_freeImBuf(ibuf);
}
- if (scaled_ibuf)
+ if (scaled_ibuf) {
seq_cache_thumbnail_put(
context, seq, timeline_frame, SEQ_CACHE_STORE_THUMBNAIL, scaled_ibuf, v2d);
+ /* do clipping */ // TODO(AYJ) : Move to separate function
+ if (clipped) {
+ cropped_ibuf = IMB_allocImBuf(rectx, recty, 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 - scaled_ibuf->x) / 2;
+ const float image_center_offs_y = (cropped_ibuf->y - scaled_ibuf->y) / 2;
+ const float pivot[2] = {scaled_ibuf->x / 2, scaled_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(scaled_ibuf, cropped_ibuf, transform_matrix, crop, filter);
+
+ seq_imbuf_assign_spaces(context->scene, cropped_ibuf);
+ IMB_metadata_copy(cropped_ibuf, scaled_ibuf);
+ IMB_freeImBuf(scaled_ibuf);
+ if (cropped_ibuf != NULL)
+ return cropped_ibuf;
+ }
+ }
+
if (scaled_ibuf == NULL) {
- ibuf = IMB_allocImBuf(rectx, recty, 32, IB_rect);
+ scaled_ibuf = IMB_allocImBuf(rectx, recty, 32, IB_rect);
seq_imbuf_assign_spaces(context->scene, scaled_ibuf);
}
More information about the Bf-blender-cvs
mailing list