VSE: replace Subsampled3x3 filter by a general Box filter

Part of overall "improve filtering situation" (#116980): replace Subsampled3x3
(added for blender 3.5 in f210842a72 et al.) strip scaling filter with a
general Box filter.

Subsampled3x3 is really a Box filter ("average pixel values over NxM region"),
hardcoded to 3x3 size. As such, it works pretty well when downscaling images by
3x on each axis. But starts to break down and introduce aliasing at other
scaling factors. Also when scaling up or scaling down by less than 3x, using
total of 9 samples is a bit of overkill and hurts performance.

So instead, calculate the amount of NxM samples needed by looking at scaling
factors on X/Y axes. Note: use at least 2 samples on each axis, so that when
rotation is present, the result edges will get some anti-aliasing, just like it
was happening in previous filter implementation.

Images in PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/117584
This commit is contained in:
Aras Pranckevicius
2024-01-29 18:41:31 +01:00
committed by Aras Pranckevicius
parent 1aafb6802b
commit 5bd1e0bb22
7 changed files with 66 additions and 82 deletions

View File

@@ -465,14 +465,8 @@ static void sequencer_thumbnail_transform(ImBuf *in, ImBuf *out)
blender::float3{scale_x, scale_y, 1.0f});
transform_pivot_set_m4(transform_matrix, pivot);
invert_m4(transform_matrix);
const int num_subsamples = 1;
IMB_transform(in,
out,
IMB_TRANSFORM_MODE_REGULAR,
IMB_FILTER_NEAREST,
num_subsamples,
transform_matrix,
nullptr);
IMB_transform(
in, out, IMB_TRANSFORM_MODE_REGULAR, IMB_FILTER_NEAREST, transform_matrix, nullptr);
}
/* Check whether transform introduces transparent ares in the result (happens when the transformed
@@ -537,7 +531,6 @@ static void sequencer_preprocess_transform_crop(
const StripTransform *transform = seq->strip->transform;
eIMBInterpolationFilterMode filter = IMB_FILTER_NEAREST;
int num_subsamples = 1;
switch (transform->filter) {
case SEQ_TRANSFORM_FILTER_NEAREST:
filter = IMB_FILTER_NEAREST;
@@ -551,19 +544,12 @@ static void sequencer_preprocess_transform_crop(
case SEQ_TRANSFORM_FILTER_CUBIC_MITCHELL:
filter = IMB_FILTER_CUBIC_MITCHELL;
break;
case SEQ_TRANSFORM_FILTER_NEAREST_3x3:
filter = IMB_FILTER_NEAREST;
num_subsamples = 3;
case SEQ_TRANSFORM_FILTER_BOX:
filter = IMB_FILTER_BOX;
break;
}
IMB_transform(in,
out,
IMB_TRANSFORM_MODE_CROP_SRC,
filter,
num_subsamples,
transform_matrix,
&source_crop);
IMB_transform(in, out, IMB_TRANSFORM_MODE_CROP_SRC, filter, transform_matrix, &source_crop);
if (!seq_image_transform_transparency_gained(context, seq)) {
out->planes = in->planes;