resampler: make shift easier to use

This commit is contained in:
Wim Taymans 2014-10-27 10:13:47 +01:00
parent 716b91d86e
commit fcc7fbd460
3 changed files with 19 additions and 15 deletions

View file

@ -166,7 +166,7 @@ resampler_calculate_taps (ResamplerParams * params)
max_taps = resampler->max_taps;
tap_offs = (max_taps - 1) / 2;
corr = (max_taps == 1 ? 0.5 : 0.0);
corr = (max_taps == 1 ? 0.0 : 0.5);
shift = params->shift;
@ -176,17 +176,19 @@ resampler_calculate_taps (ResamplerParams * params)
phase = resampler->phase = g_malloc (sizeof (guint) * out_size);
for (j = 0; j < out_size; j++) {
gdouble x;
gdouble ox, x;
gint xi;
gint l;
gdouble weight;
gdouble *taps;
/* center of the output pixel */
ox = (0.5 + (gdouble) j - shift) / out_size;
/* x is the source pixel to use, can be fractional */
x = shift + (in_size * j) / (gdouble) out_size;
x = ox * (gdouble) in_size - corr;
x = CLAMP (x, 0, in_size - 1);
/* this is the first source pixel to use */
xi = floor (x + corr) - tap_offs;
xi = floor (x - tap_offs);
offset[j] = xi;
phase[j] = j;
@ -354,17 +356,18 @@ gst_resampler_init (GstResampler * resampler,
max_taps = resampler->max_taps;
for (i = 0; i < out_size; i++) {
gint j, o, n_taps;
gint j, o, phase, n_taps;
gdouble sum;
o = resampler->offsets[i];
o = resampler->offset[i];
n_taps = resampler->n_taps[i];
phase = resampler->phase[i];
printf ("%u: \t%d ", i, o);
sum = 0;
for (j = 0; j < n_taps; j++) {
gdouble tap;
tap = resampler->taps[i * max_taps + j];
tap = resampler->taps[phase * max_taps + j];
printf ("\t%f ", tap);
sum += tap;
}

View file

@ -108,7 +108,6 @@ gst_video_scaler_new (GstResamplerMethod method, GstVideoScalerFlags flags,
guint n_taps, guint in_size, guint out_size, GstStructure * options)
{
GstVideoScaler *scale;
gdouble shift;
g_return_val_if_fail (in_size != 0, NULL);
g_return_val_if_fail (out_size != 0, NULL);
@ -120,16 +119,14 @@ gst_video_scaler_new (GstResamplerMethod method, GstVideoScalerFlags flags,
scale->method = method;
scale->flags = flags;
shift = (in_size / (gdouble) out_size) / 2 - 0.5;
if (flags & GST_VIDEO_SCALER_FLAG_INTERLACED) {
GstResampler tresamp, bresamp;
gst_resampler_init (&tresamp, method, 0, (out_size + 1) / 2, n_taps,
shift, (in_size + 1) / 2, (out_size + 1) / 2, options);
0.0, (in_size + 1) / 2, (out_size + 1) / 2, options);
gst_resampler_init (&bresamp, method, 0, out_size - tresamp.out_size,
n_taps, shift - 1.0, in_size - tresamp.in_size,
n_taps, -1.0, in_size - tresamp.in_size,
out_size - tresamp.out_size, options);
resampler_zip (&scale->resampler, &tresamp, &bresamp);
@ -137,7 +134,7 @@ gst_video_scaler_new (GstResamplerMethod method, GstVideoScalerFlags flags,
gst_resampler_clear (&bresamp);
} else {
gst_resampler_init (&scale->resampler, method, flags, out_size, n_taps,
shift, in_size, out_size, options);
0.0, in_size, out_size, options);
}
return scale;
}

View file

@ -1698,9 +1698,13 @@ GST_START_TEST (test_video_scaler)
GstVideoScaler *scale;
scale = gst_video_scaler_new (GST_RESAMPLER_METHOD_LINEAR,
GST_VIDEO_SCALER_FLAG_NONE, 2, 100, 50, NULL);
GST_VIDEO_SCALER_FLAG_NONE, 2, 10, 5, NULL);
gst_video_scaler_free (scale);
scale = gst_video_scaler_new (GST_RESAMPLER_METHOD_LINEAR,
GST_VIDEO_SCALER_FLAG_NONE, 2, 15, 5, NULL);
gst_video_scaler_free (scale);
}
GST_END_TEST;