video-scaler: add extra options

This commit is contained in:
Wim Taymans 2014-10-24 16:51:37 +02:00
parent c409a45d13
commit 32047eaac0
6 changed files with 57 additions and 14 deletions

View file

@ -3,7 +3,8 @@ ORC_SOURCE=video-orc
include $(top_srcdir)/common/orc.mak
glib_enum_headers = video.h video-format.h video-color.h video-info.h \
colorbalance.h navigation.h video-chroma.h video-tile.h video-converter.h
colorbalance.h navigation.h video-chroma.h video-tile.h video-converter.h \
resampler.h
glib_enum_define = GST_VIDEO
glib_gen_prefix = gst_video
glib_gen_basename = video

View file

@ -302,12 +302,25 @@ chain_convert (GstVideoConverter * convert, GstLineCacheNeedLineFunc need_line)
static GstLineCacheNeedLineFunc
chain_hscale (GstVideoConverter * convert, GstLineCacheNeedLineFunc need_line)
{
gint method;
guint taps;
convert->hscale_lines = gst_line_cache_new ();
gst_line_cache_set_need_line_func (convert->hscale_lines,
need_line, convert, NULL);
if (!gst_structure_get_enum (convert->config,
GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD, GST_TYPE_RESAMPLER_METHOD,
&method))
method = GST_RESAMPLER_METHOD_LINEAR;
if (!gst_structure_get_uint (convert->config,
GST_VIDEO_CONVERTER_OPT_RESAMPLER_TAPS, &taps))
taps = 0;
convert->h_scaler =
gst_video_scaler_new (GST_RESAMPLER_METHOD_BICUBIC,
GST_VIDEO_SCALER_FLAG_NONE, 4, convert->in_width, convert->out_width);
gst_video_scaler_new (method, GST_VIDEO_SCALER_FLAG_NONE, taps,
convert->in_width, convert->out_width, convert->config);
return (GstLineCacheNeedLineFunc) do_hscale_lines;
}
@ -315,6 +328,8 @@ static GstLineCacheNeedLineFunc
chain_vscale (GstVideoConverter * convert, GstLineCacheNeedLineFunc need_line)
{
GstVideoScalerFlags flags;
gint method;
guint taps;
flags = GST_VIDEO_INFO_IS_INTERLACED (&convert->in_info) ?
GST_VIDEO_SCALER_FLAG_INTERLACED : 0;
@ -322,9 +337,19 @@ chain_vscale (GstVideoConverter * convert, GstLineCacheNeedLineFunc need_line)
convert->vscale_lines = gst_line_cache_new ();
gst_line_cache_set_need_line_func (convert->vscale_lines,
need_line, convert, NULL);
if (!gst_structure_get_enum (convert->config,
GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD, GST_TYPE_RESAMPLER_METHOD,
&method))
method = GST_RESAMPLER_METHOD_LINEAR;
if (!gst_structure_get_uint (convert->config,
GST_VIDEO_CONVERTER_OPT_RESAMPLER_TAPS, &taps))
taps = 0;
convert->v_scaler =
gst_video_scaler_new (GST_RESAMPLER_METHOD_BICUBIC, flags, 4,
convert->in_height, convert->out_height);
gst_video_scaler_new (method, flags, taps, convert->in_height,
convert->out_height, convert->config);
return (GstLineCacheNeedLineFunc) do_vscale_lines;
}

View file

@ -41,13 +41,20 @@ typedef enum {
} GstVideoDitherMethod;
/**
* GST_VIDEO_CONVERTER_OPT_RESAMPLE_METHOD:
* GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD:
*
* #GST_TYPE_RESAMPLER_METHOD, The resampler method to use for
* resampling. Other options for the resampler can be used, see
* the #GstResampler.
* the #GstResampler. Default is #GST_RESAMPLER_METHOD_LINEAR.
*/
#define GST_VIDEO_CONVERTER_OPT_RESAMPLE_METHOD "GstVideoConverter.resample-method"
#define GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD "GstVideoConverter.resampler-method"
/**
* GST_VIDEO_CONVERTER_OPT_RESAMPLER_TAPS:
*
* #G_TYPE_UINT, The number of taps for the resampler.
* Default is 0: let the resampler choose a good value.
*/
#define GST_VIDEO_CONVERTER_OPT_RESAMPLER_TAPS "GstVideoConverter.resampler-taps"
/**
* GST_VIDEO_CONVERTER_OPT_DITHER_METHOD:

View file

@ -92,6 +92,7 @@ resampler_zip (GstResampler * resampler, const GstResampler * r1,
* @n_taps: number of taps to use
* @in_size: number of source elements
* @out_size: number of destination elements
* @options: (allow none): extra options
*
* Make a new @method video scaler. @in_size source lines/pixels will
* be scaled to @out_size destination lines/pixels.
@ -104,7 +105,7 @@ resampler_zip (GstResampler * resampler, const GstResampler * r1,
*/
GstVideoScaler *
gst_video_scaler_new (GstResamplerMethod method, GstVideoScalerFlags flags,
guint n_taps, guint in_size, guint out_size)
guint n_taps, guint in_size, guint out_size, GstStructure * options)
{
GstVideoScaler *scale;
gdouble shift;
@ -125,18 +126,18 @@ gst_video_scaler_new (GstResamplerMethod method, GstVideoScalerFlags flags,
GstResampler tresamp, bresamp;
gst_resampler_init (&tresamp, method, 0, (out_size + 1) / 2, n_taps,
shift, (in_size + 1) / 2, (out_size + 1) / 2, NULL);
shift, (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,
out_size - tresamp.out_size, NULL);
out_size - tresamp.out_size, options);
resampler_zip (&scale->resampler, &tresamp, &bresamp);
gst_resampler_clear (&tresamp);
gst_resampler_clear (&bresamp);
} else {
gst_resampler_init (&scale->resampler, method, flags, out_size, n_taps,
shift, in_size, out_size, NULL);
shift, in_size, out_size, options);
}
return scale;
}

View file

@ -28,6 +28,14 @@
G_BEGIN_DECLS
/**
* GST_VIDEO_SCALER_OPT_DITHER_METHOD:
*
* #GST_TYPE_VIDEO_DITHER_METHOD, The dither method to use for propagating
* quatization errors.
*/
#define GST_VIDEO_SCALER_OPT_DITHER_METHOD "GstVideoScaler.dither-method"
/**
* GstVideoScalerFlags:
* @GST_VIDEO_SCALER_FLAG_NONE: no flags
@ -45,7 +53,8 @@ typedef struct _GstVideoScaler GstVideoScaler;
GstVideoScaler * gst_video_scaler_new (GstResamplerMethod method,
GstVideoScalerFlags flags,
guint n_taps,
guint in_size, guint out_size);
guint in_size, guint out_size,
GstStructure * options);
void gst_video_scaler_free (GstVideoScaler *scale);
const gdouble * gst_video_scaler_get_coeff (GstVideoScaler *scale,

View file

@ -1698,7 +1698,7 @@ 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);
GST_VIDEO_SCALER_FLAG_NONE, 2, 100, 50, NULL);
gst_video_scaler_free (scale);
}