2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) 2005 David Schleef <ds@schleef.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * SECTION:element-videoscale
23 * @see_also: videorate, ffmpegcolorspace
25 * This element resizes video frames. By default the element will try to
26 * negotiate to the same size on the source and sinkpad so that no scaling
27 * is needed. It is therefore safe to insert this element in a pipeline to
28 * get more robust behaviour without any cost if no scaling is needed.
30 * This element supports a wide range of color spaces including various YUV and
31 * RGB formats and is therefore generally able to operate anywhere in a
35 * <title>Example pipelines</title>
37 * gst-launch -v filesrc location=videotestsrc.ogg ! oggdemux ! theoradec ! ffmpegcolorspace ! videoscale ! ximagesink
38 * ]| Decode an Ogg/Theora and display the video using ximagesink. Since
39 * ximagesink cannot perform scaling, the video scaling will be performed by
40 * videoscale when you resize the video window.
41 * To create the test Ogg/Theora file refer to the documentation of theoraenc.
43 * gst-launch -v filesrc location=videotestsrc.ogg ! oggdemux ! theoradec ! videoscale ! video/x-raw-yuv, width=50 ! xvimagesink
44 * ]| Decode an Ogg/Theora and display the video using xvimagesink with a width
48 * Last reviewed on 2006-03-02 (0.10.4)
52 * Formulas for PAR, DAR, width and height relations:
63 * w = h * ----- * -----
67 * h = w * ----- * -----
79 #include <gst/video/video.h>
81 #include "gstvideoscale.h"
82 #include "gstvideoscaleorc.h"
85 #include "vs_fill_borders.h"
87 /* debug variable definition */
88 GST_DEBUG_CATEGORY (video_scale_debug);
90 #define DEFAULT_PROP_METHOD GST_VIDEO_SCALE_BILINEAR
91 #define DEFAULT_PROP_ADD_BORDERS FALSE
101 #undef GST_VIDEO_SIZE_RANGE
102 #define GST_VIDEO_SIZE_RANGE "(int) [ 1, 32767]"
104 static GstStaticCaps gst_video_scale_format_caps[] = {
105 GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBA),
106 GST_STATIC_CAPS (GST_VIDEO_CAPS_ARGB),
107 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRA),
108 GST_STATIC_CAPS (GST_VIDEO_CAPS_ABGR),
109 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AYUV")),
110 GST_STATIC_CAPS (GST_VIDEO_CAPS_RGBx),
111 GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB),
112 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx),
113 GST_STATIC_CAPS (GST_VIDEO_CAPS_xBGR),
114 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y444")),
115 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("v308")),
116 GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB),
117 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGR),
118 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y42B")),
119 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("YUY2")),
120 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("YVYU")),
121 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("UYVY")),
122 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420")),
123 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("YV12")),
124 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y41B")),
125 GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB_16),
126 GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB_15),
127 GST_STATIC_CAPS (GST_VIDEO_CAPS_GRAY16 ("BYTE_ORDER")),
128 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y16 ")),
129 GST_STATIC_CAPS (GST_VIDEO_CAPS_GRAY8),
130 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y800")),
131 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("Y8 ")),
132 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("GREY")),
133 GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("AY64")),
134 GST_STATIC_CAPS (GST_VIDEO_CAPS_ARGB_64)
137 #define GST_TYPE_VIDEO_SCALE_METHOD (gst_video_scale_method_get_type())
139 gst_video_scale_method_get_type (void)
141 static GType video_scale_method_type = 0;
143 static const GEnumValue video_scale_methods[] = {
144 {GST_VIDEO_SCALE_NEAREST, "Nearest Neighbour", "nearest-neighbour"},
145 {GST_VIDEO_SCALE_BILINEAR, "Bilinear", "bilinear"},
146 {GST_VIDEO_SCALE_4TAP, "4-tap", "4-tap"},
150 if (!video_scale_method_type) {
151 video_scale_method_type =
152 g_enum_register_static ("GstVideoScaleMethod", video_scale_methods);
154 return video_scale_method_type;
158 gst_video_scale_get_capslist (void)
160 static GstCaps *caps = NULL;
161 static volatile gsize inited = 0;
163 if (g_once_init_enter (&inited)) {
166 g_assert (caps == NULL);
168 caps = gst_caps_new_empty ();
169 for (i = 0; i < G_N_ELEMENTS (gst_video_scale_format_caps); i++)
170 gst_caps_append (caps,
171 gst_caps_make_writable
172 (gst_static_caps_get (&gst_video_scale_format_caps[i])));
173 g_once_init_leave (&inited, 1);
179 static GstPadTemplate *
180 gst_video_scale_src_template_factory (void)
182 return gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
183 gst_video_scale_get_capslist ());
186 static GstPadTemplate *
187 gst_video_scale_sink_template_factory (void)
189 return gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
190 gst_video_scale_get_capslist ());
194 static void gst_video_scale_finalize (GstVideoScale * videoscale);
195 static gboolean gst_video_scale_src_event (GstBaseTransform * trans,
198 /* base transform vmethods */
199 static GstCaps *gst_video_scale_transform_caps (GstBaseTransform * trans,
200 GstPadDirection direction, GstCaps * caps, GstCaps * filter);
201 static gboolean gst_video_scale_set_caps (GstBaseTransform * trans,
202 GstCaps * in, GstCaps * out);
203 static gboolean gst_video_scale_get_unit_size (GstBaseTransform * trans,
204 GstCaps * caps, gsize * size);
205 static GstFlowReturn gst_video_scale_transform (GstBaseTransform * trans,
206 GstBuffer * in, GstBuffer * out);
207 static void gst_video_scale_fixate_caps (GstBaseTransform * base,
208 GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
210 static void gst_video_scale_set_property (GObject * object, guint prop_id,
211 const GValue * value, GParamSpec * pspec);
212 static void gst_video_scale_get_property (GObject * object, guint prop_id,
213 GValue * value, GParamSpec * pspec);
215 #define gst_video_scale_parent_class parent_class
216 G_DEFINE_TYPE (GstVideoScale, gst_video_scale, GST_TYPE_VIDEO_FILTER);
219 gst_video_scale_class_init (GstVideoScaleClass * klass)
221 GObjectClass *gobject_class = (GObjectClass *) klass;
222 GstElementClass *element_class = (GstElementClass *) klass;
223 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
225 gobject_class->finalize = (GObjectFinalizeFunc) gst_video_scale_finalize;
226 gobject_class->set_property = gst_video_scale_set_property;
227 gobject_class->get_property = gst_video_scale_get_property;
229 g_object_class_install_property (gobject_class, PROP_METHOD,
230 g_param_spec_enum ("method", "method", "method",
231 GST_TYPE_VIDEO_SCALE_METHOD, DEFAULT_PROP_METHOD,
232 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
234 g_object_class_install_property (gobject_class, PROP_ADD_BORDERS,
235 g_param_spec_boolean ("add-borders", "Add Borders",
236 "Add black borders if necessary to keep the display aspect ratio",
237 DEFAULT_PROP_ADD_BORDERS,
238 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
240 gst_element_class_set_details_simple (element_class,
241 "Video scaler", "Filter/Converter/Video/Scaler",
242 "Resizes video", "Wim Taymans <wim.taymans@chello.be>");
244 gst_element_class_add_pad_template (element_class,
245 gst_video_scale_sink_template_factory ());
246 gst_element_class_add_pad_template (element_class,
247 gst_video_scale_src_template_factory ());
249 trans_class->transform_caps =
250 GST_DEBUG_FUNCPTR (gst_video_scale_transform_caps);
251 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_video_scale_set_caps);
252 trans_class->get_unit_size =
253 GST_DEBUG_FUNCPTR (gst_video_scale_get_unit_size);
254 trans_class->transform = GST_DEBUG_FUNCPTR (gst_video_scale_transform);
255 trans_class->fixate_caps = GST_DEBUG_FUNCPTR (gst_video_scale_fixate_caps);
256 trans_class->src_event = GST_DEBUG_FUNCPTR (gst_video_scale_src_event);
260 gst_video_scale_init (GstVideoScale * videoscale)
262 videoscale->tmp_buf = NULL;
263 videoscale->method = DEFAULT_PROP_METHOD;
264 videoscale->add_borders = DEFAULT_PROP_ADD_BORDERS;
268 gst_video_scale_finalize (GstVideoScale * videoscale)
270 if (videoscale->tmp_buf)
271 g_free (videoscale->tmp_buf);
273 G_OBJECT_CLASS (parent_class)->finalize (G_OBJECT (videoscale));
277 gst_video_scale_set_property (GObject * object, guint prop_id,
278 const GValue * value, GParamSpec * pspec)
280 GstVideoScale *vscale = GST_VIDEO_SCALE (object);
284 GST_OBJECT_LOCK (vscale);
285 vscale->method = g_value_get_enum (value);
286 GST_OBJECT_UNLOCK (vscale);
288 case PROP_ADD_BORDERS:
289 GST_OBJECT_LOCK (vscale);
290 vscale->add_borders = g_value_get_boolean (value);
291 GST_OBJECT_UNLOCK (vscale);
292 gst_base_transform_reconfigure (GST_BASE_TRANSFORM_CAST (vscale));
295 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
301 gst_video_scale_get_property (GObject * object, guint prop_id, GValue * value,
304 GstVideoScale *vscale = GST_VIDEO_SCALE (object);
308 GST_OBJECT_LOCK (vscale);
309 g_value_set_enum (value, vscale->method);
310 GST_OBJECT_UNLOCK (vscale);
312 case PROP_ADD_BORDERS:
313 GST_OBJECT_LOCK (vscale);
314 g_value_set_boolean (value, vscale->add_borders);
315 GST_OBJECT_UNLOCK (vscale);
318 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
324 gst_video_scale_transform_caps (GstBaseTransform * trans,
325 GstPadDirection direction, GstCaps * caps, GstCaps * filter)
328 GstStructure *structure;
331 GST_DEBUG_OBJECT (trans,
332 "Transforming caps %" GST_PTR_FORMAT " in direction %s", caps,
333 (direction == GST_PAD_SINK) ? "sink" : "src");
335 ret = gst_caps_new_empty ();
336 n = gst_caps_get_size (caps);
337 for (i = 0; i < n; i++) {
338 structure = gst_caps_get_structure (caps, i);
340 /* If this is already expressed by the existing caps
341 * skip this structure */
342 if (i > 0 && gst_caps_is_subset_structure (ret, structure))
345 structure = gst_structure_copy (structure);
346 gst_structure_set (structure,
347 "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
348 "height", GST_TYPE_INT_RANGE, 1, G_MAXINT, NULL);
350 /* if pixel aspect ratio, make a range of it */
351 if (gst_structure_has_field (structure, "pixel-aspect-ratio")) {
352 gst_structure_set (structure, "pixel-aspect-ratio",
353 GST_TYPE_FRACTION_RANGE, 1, G_MAXINT, G_MAXINT, 1, NULL);
355 gst_caps_append_structure (ret, structure);
359 GstCaps *intersection;
362 gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST);
363 gst_caps_unref (ret);
367 GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, ret);
373 gst_video_scale_set_caps (GstBaseTransform * trans, GstCaps * in, GstCaps * out)
375 GstVideoScale *videoscale = GST_VIDEO_SCALE (trans);
377 gint from_dar_n, from_dar_d, to_dar_n, to_dar_d;
378 gint from_par_n, from_par_d, to_par_n, to_par_d;
381 gst_video_format_parse_caps (in, &videoscale->format,
382 &videoscale->from_width, &videoscale->from_height);
384 gst_video_format_parse_caps (out, NULL, &videoscale->to_width,
385 &videoscale->to_height);
389 videoscale->src_size = gst_video_format_get_size (videoscale->format,
390 videoscale->from_width, videoscale->from_height);
391 videoscale->dest_size = gst_video_format_get_size (videoscale->format,
392 videoscale->to_width, videoscale->to_height);
394 if (!gst_video_parse_caps_pixel_aspect_ratio (in, &from_par_n, &from_par_d))
395 from_par_n = from_par_d = 1;
396 if (!gst_video_parse_caps_pixel_aspect_ratio (out, &to_par_n, &to_par_d))
397 to_par_n = to_par_d = 1;
399 if (!gst_util_fraction_multiply (videoscale->from_width,
400 videoscale->from_height, from_par_n, from_par_d, &from_dar_n,
402 from_dar_n = from_dar_d = -1;
405 if (!gst_util_fraction_multiply (videoscale->to_width,
406 videoscale->to_height, to_par_n, to_par_d, &to_dar_n, &to_dar_d)) {
407 to_dar_n = to_dar_d = -1;
410 videoscale->borders_w = videoscale->borders_h = 0;
411 if (to_dar_n != from_dar_n || to_dar_d != from_dar_d) {
412 if (videoscale->add_borders) {
413 gint n, d, to_h, to_w;
415 if (from_dar_n != -1 && from_dar_d != -1
416 && gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_n,
418 to_h = gst_util_uint64_scale_int (videoscale->to_width, d, n);
419 if (to_h <= videoscale->to_height) {
420 videoscale->borders_h = videoscale->to_height - to_h;
421 videoscale->borders_w = 0;
423 to_w = gst_util_uint64_scale_int (videoscale->to_height, n, d);
424 g_assert (to_w <= videoscale->to_width);
425 videoscale->borders_h = 0;
426 videoscale->borders_w = videoscale->to_width - to_w;
429 GST_WARNING_OBJECT (videoscale, "Can't calculate borders");
432 GST_WARNING_OBJECT (videoscale, "Can't keep DAR!");
436 if (videoscale->tmp_buf)
437 g_free (videoscale->tmp_buf);
438 videoscale->tmp_buf = g_malloc (videoscale->to_width * 8 * 4);
440 gst_base_transform_set_passthrough (trans,
441 (videoscale->from_width == videoscale->to_width
442 && videoscale->from_height == videoscale->to_height));
444 GST_DEBUG_OBJECT (videoscale, "from=%dx%d (par=%d/%d dar=%d/%d), size %d "
445 "-> to=%dx%d (par=%d/%d dar=%d/%d borders=%d:%d), size %d",
446 videoscale->from_width, videoscale->from_height, from_par_n, from_par_d,
447 from_dar_n, from_dar_d, videoscale->src_size, videoscale->to_width,
448 videoscale->to_height, to_par_n, to_par_d, to_dar_n, to_dar_d,
449 videoscale->borders_w, videoscale->borders_h, videoscale->dest_size);
456 gst_video_scale_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
459 GstVideoFormat format;
462 if (!gst_video_format_parse_caps (caps, &format, &width, &height))
465 *size = gst_video_format_get_size (format, width, height);
471 gst_video_scale_fixate_caps (GstBaseTransform * base, GstPadDirection direction,
472 GstCaps * caps, GstCaps * othercaps)
474 GstStructure *ins, *outs;
475 const GValue *from_par, *to_par;
476 GValue fpar = { 0, }, tpar = {
479 g_return_if_fail (gst_caps_is_fixed (caps));
481 GST_DEBUG_OBJECT (base, "trying to fixate othercaps %" GST_PTR_FORMAT
482 " based on caps %" GST_PTR_FORMAT, othercaps, caps);
484 ins = gst_caps_get_structure (caps, 0);
485 outs = gst_caps_get_structure (othercaps, 0);
487 from_par = gst_structure_get_value (ins, "pixel-aspect-ratio");
488 to_par = gst_structure_get_value (outs, "pixel-aspect-ratio");
490 /* If we're fixating from the sinkpad we always set the PAR and
491 * assume that missing PAR on the sinkpad means 1/1 and
492 * missing PAR on the srcpad means undefined
494 if (direction == GST_PAD_SINK) {
496 g_value_init (&fpar, GST_TYPE_FRACTION);
497 gst_value_set_fraction (&fpar, 1, 1);
501 g_value_init (&tpar, GST_TYPE_FRACTION_RANGE);
502 gst_value_set_fraction_range_full (&tpar, 1, G_MAXINT, G_MAXINT, 1);
507 g_value_init (&tpar, GST_TYPE_FRACTION);
508 gst_value_set_fraction (&tpar, 1, 1);
511 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
515 g_value_init (&fpar, GST_TYPE_FRACTION);
516 gst_value_set_fraction (&fpar, 1, 1);
521 /* we have both PAR but they might not be fixated */
523 gint from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d;
525 gint from_dar_n, from_dar_d;
528 /* from_par should be fixed */
529 g_return_if_fail (gst_value_is_fixed (from_par));
531 from_par_n = gst_value_get_fraction_numerator (from_par);
532 from_par_d = gst_value_get_fraction_denominator (from_par);
534 gst_structure_get_int (ins, "width", &from_w);
535 gst_structure_get_int (ins, "height", &from_h);
537 gst_structure_get_int (outs, "width", &w);
538 gst_structure_get_int (outs, "height", &h);
540 /* if both width and height are already fixed, we can't do anything
541 * about it anymore */
545 GST_DEBUG_OBJECT (base, "dimensions already set to %dx%d, not fixating",
547 if (!gst_value_is_fixed (to_par)) {
548 if (gst_video_calculate_display_ratio (&n, &d, from_w, from_h,
549 from_par_n, from_par_d, w, h)) {
550 GST_DEBUG_OBJECT (base, "fixating to_par to %dx%d", n, d);
551 if (gst_structure_has_field (outs, "pixel-aspect-ratio"))
552 gst_structure_fixate_field_nearest_fraction (outs,
553 "pixel-aspect-ratio", n, d);
555 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
562 /* Calculate input DAR */
563 if (!gst_util_fraction_multiply (from_w, from_h, from_par_n, from_par_d,
564 &from_dar_n, &from_dar_d)) {
565 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
566 ("Error calculating the output scaled size - integer overflow"));
570 GST_DEBUG_OBJECT (base, "Input DAR is %d/%d", from_dar_n, from_dar_d);
572 /* If either width or height are fixed there's not much we
573 * can do either except choosing a height or width and PAR
574 * that matches the DAR as good as possible
578 gint set_w, set_par_n, set_par_d;
580 GST_DEBUG_OBJECT (base, "height is fixed (%d)", h);
582 /* If the PAR is fixed too, there's not much to do
583 * except choosing the width that is nearest to the
584 * width with the same DAR */
585 if (gst_value_is_fixed (to_par)) {
586 to_par_n = gst_value_get_fraction_numerator (to_par);
587 to_par_d = gst_value_get_fraction_denominator (to_par);
589 GST_DEBUG_OBJECT (base, "PAR is fixed %d/%d", to_par_n, to_par_d);
591 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_d,
592 to_par_n, &num, &den)) {
593 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
594 ("Error calculating the output scaled size - integer overflow"));
598 w = (guint) gst_util_uint64_scale_int (h, num, den);
599 gst_structure_fixate_field_nearest_int (outs, "width", w);
604 /* The PAR is not fixed and it's quite likely that we can set
605 * an arbitrary PAR. */
607 /* Check if we can keep the input width */
608 tmp = gst_structure_copy (outs);
609 gst_structure_fixate_field_nearest_int (tmp, "width", from_w);
610 gst_structure_get_int (tmp, "width", &set_w);
612 /* Might have failed but try to keep the DAR nonetheless by
613 * adjusting the PAR */
614 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, h, set_w,
615 &to_par_n, &to_par_d)) {
616 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
617 ("Error calculating the output scaled size - integer overflow"));
618 gst_structure_free (tmp);
622 if (!gst_structure_has_field (tmp, "pixel-aspect-ratio"))
623 gst_structure_set_value (tmp, "pixel-aspect-ratio", to_par);
624 gst_structure_fixate_field_nearest_fraction (tmp, "pixel-aspect-ratio",
626 gst_structure_get_fraction (tmp, "pixel-aspect-ratio", &set_par_n,
628 gst_structure_free (tmp);
630 /* Check if the adjusted PAR is accepted */
631 if (set_par_n == to_par_n && set_par_d == to_par_d) {
632 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
633 set_par_n != set_par_d)
634 gst_structure_set (outs, "width", G_TYPE_INT, set_w,
635 "pixel-aspect-ratio", GST_TYPE_FRACTION, set_par_n, set_par_d,
640 /* Otherwise scale the width to the new PAR and check if the
641 * adjusted with is accepted. If all that fails we can't keep
643 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_par_d,
644 set_par_n, &num, &den)) {
645 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
646 ("Error calculating the output scaled size - integer overflow"));
650 w = (guint) gst_util_uint64_scale_int (h, num, den);
651 gst_structure_fixate_field_nearest_int (outs, "width", w);
652 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
653 set_par_n != set_par_d)
654 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
655 set_par_n, set_par_d, NULL);
660 gint set_h, set_par_n, set_par_d;
662 GST_DEBUG_OBJECT (base, "width is fixed (%d)", w);
664 /* If the PAR is fixed too, there's not much to do
665 * except choosing the height that is nearest to the
666 * height with the same DAR */
667 if (gst_value_is_fixed (to_par)) {
668 to_par_n = gst_value_get_fraction_numerator (to_par);
669 to_par_d = gst_value_get_fraction_denominator (to_par);
671 GST_DEBUG_OBJECT (base, "PAR is fixed %d/%d", to_par_n, to_par_d);
673 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_d,
674 to_par_n, &num, &den)) {
675 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
676 ("Error calculating the output scaled size - integer overflow"));
680 h = (guint) gst_util_uint64_scale_int (w, den, num);
681 gst_structure_fixate_field_nearest_int (outs, "height", h);
686 /* The PAR is not fixed and it's quite likely that we can set
687 * an arbitrary PAR. */
689 /* Check if we can keep the input height */
690 tmp = gst_structure_copy (outs);
691 gst_structure_fixate_field_nearest_int (tmp, "height", from_h);
692 gst_structure_get_int (tmp, "height", &set_h);
694 /* Might have failed but try to keep the DAR nonetheless by
695 * adjusting the PAR */
696 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_h, w,
697 &to_par_n, &to_par_d)) {
698 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
699 ("Error calculating the output scaled size - integer overflow"));
700 gst_structure_free (tmp);
703 if (!gst_structure_has_field (tmp, "pixel-aspect-ratio"))
704 gst_structure_set_value (tmp, "pixel-aspect-ratio", to_par);
705 gst_structure_fixate_field_nearest_fraction (tmp, "pixel-aspect-ratio",
707 gst_structure_get_fraction (tmp, "pixel-aspect-ratio", &set_par_n,
709 gst_structure_free (tmp);
711 /* Check if the adjusted PAR is accepted */
712 if (set_par_n == to_par_n && set_par_d == to_par_d) {
713 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
714 set_par_n != set_par_d)
715 gst_structure_set (outs, "height", G_TYPE_INT, set_h,
716 "pixel-aspect-ratio", GST_TYPE_FRACTION, set_par_n, set_par_d,
721 /* Otherwise scale the height to the new PAR and check if the
722 * adjusted with is accepted. If all that fails we can't keep
724 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_par_d,
725 set_par_n, &num, &den)) {
726 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
727 ("Error calculating the output scaled size - integer overflow"));
731 h = (guint) gst_util_uint64_scale_int (w, den, num);
732 gst_structure_fixate_field_nearest_int (outs, "height", h);
733 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
734 set_par_n != set_par_d)
735 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
736 set_par_n, set_par_d, NULL);
739 } else if (gst_value_is_fixed (to_par)) {
741 gint set_h, set_w, f_h, f_w;
743 to_par_n = gst_value_get_fraction_numerator (to_par);
744 to_par_d = gst_value_get_fraction_denominator (to_par);
746 /* Calculate scale factor for the PAR change */
747 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, to_par_n,
748 to_par_d, &num, &den)) {
749 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
750 ("Error calculating the output scaled size - integer overflow"));
754 /* Try to keep the input height (because of interlacing) */
755 tmp = gst_structure_copy (outs);
756 gst_structure_fixate_field_nearest_int (tmp, "height", from_h);
757 gst_structure_get_int (tmp, "height", &set_h);
759 /* This might have failed but try to scale the width
760 * to keep the DAR nonetheless */
761 w = (guint) gst_util_uint64_scale_int (set_h, num, den);
762 gst_structure_fixate_field_nearest_int (tmp, "width", w);
763 gst_structure_get_int (tmp, "width", &set_w);
764 gst_structure_free (tmp);
766 /* We kept the DAR and the height is nearest to the original height */
768 gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
769 G_TYPE_INT, set_h, NULL);
776 /* If the former failed, try to keep the input width at least */
777 tmp = gst_structure_copy (outs);
778 gst_structure_fixate_field_nearest_int (tmp, "width", from_w);
779 gst_structure_get_int (tmp, "width", &set_w);
781 /* This might have failed but try to scale the width
782 * to keep the DAR nonetheless */
783 h = (guint) gst_util_uint64_scale_int (set_w, den, num);
784 gst_structure_fixate_field_nearest_int (tmp, "height", h);
785 gst_structure_get_int (tmp, "height", &set_h);
786 gst_structure_free (tmp);
788 /* We kept the DAR and the width is nearest to the original width */
790 gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
791 G_TYPE_INT, set_h, NULL);
795 /* If all this failed, keep the height that was nearest to the orignal
796 * height and the nearest possible width. This changes the DAR but
797 * there's not much else to do here.
799 gst_structure_set (outs, "width", G_TYPE_INT, f_w, "height", G_TYPE_INT,
804 gint set_h, set_w, set_par_n, set_par_d, tmp2;
806 /* width, height and PAR are not fixed but passthrough is not possible */
808 /* First try to keep the height and width as good as possible
810 tmp = gst_structure_copy (outs);
811 gst_structure_fixate_field_nearest_int (tmp, "height", from_h);
812 gst_structure_get_int (tmp, "height", &set_h);
813 gst_structure_fixate_field_nearest_int (tmp, "width", from_w);
814 gst_structure_get_int (tmp, "width", &set_w);
816 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_h, set_w,
817 &to_par_n, &to_par_d)) {
818 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
819 ("Error calculating the output scaled size - integer overflow"));
823 if (!gst_structure_has_field (tmp, "pixel-aspect-ratio"))
824 gst_structure_set_value (tmp, "pixel-aspect-ratio", to_par);
825 gst_structure_fixate_field_nearest_fraction (tmp, "pixel-aspect-ratio",
827 gst_structure_get_fraction (tmp, "pixel-aspect-ratio", &set_par_n,
829 gst_structure_free (tmp);
831 if (set_par_n == to_par_n && set_par_d == to_par_d) {
832 gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
833 G_TYPE_INT, set_h, NULL);
835 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
836 set_par_n != set_par_d)
837 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
838 set_par_n, set_par_d, NULL);
842 /* Otherwise try to scale width to keep the DAR with the set
844 if (!gst_util_fraction_multiply (from_dar_n, from_dar_d, set_par_d,
845 set_par_n, &num, &den)) {
846 GST_ELEMENT_ERROR (base, CORE, NEGOTIATION, (NULL),
847 ("Error calculating the output scaled size - integer overflow"));
851 w = (guint) gst_util_uint64_scale_int (set_h, num, den);
852 tmp = gst_structure_copy (outs);
853 gst_structure_fixate_field_nearest_int (tmp, "width", w);
854 gst_structure_get_int (tmp, "width", &tmp2);
855 gst_structure_free (tmp);
858 gst_structure_set (outs, "width", G_TYPE_INT, tmp2, "height",
859 G_TYPE_INT, set_h, NULL);
860 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
861 set_par_n != set_par_d)
862 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
863 set_par_n, set_par_d, NULL);
867 /* ... or try the same with the height */
868 h = (guint) gst_util_uint64_scale_int (set_w, den, num);
869 tmp = gst_structure_copy (outs);
870 gst_structure_fixate_field_nearest_int (tmp, "height", h);
871 gst_structure_get_int (tmp, "height", &tmp2);
872 gst_structure_free (tmp);
875 gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
876 G_TYPE_INT, tmp2, NULL);
877 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
878 set_par_n != set_par_d)
879 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
880 set_par_n, set_par_d, NULL);
884 /* If all fails we can't keep the DAR and take the nearest values
885 * for everything from the first try */
886 gst_structure_set (outs, "width", G_TYPE_INT, set_w, "height",
887 G_TYPE_INT, set_h, NULL);
888 if (gst_structure_has_field (outs, "pixel-aspect-ratio") ||
889 set_par_n != set_par_d)
890 gst_structure_set (outs, "pixel-aspect-ratio", GST_TYPE_FRACTION,
891 set_par_n, set_par_d, NULL);
896 GST_DEBUG_OBJECT (base, "fixated othercaps to %" GST_PTR_FORMAT, othercaps);
898 if (from_par == &fpar)
899 g_value_unset (&fpar);
901 g_value_unset (&tpar);
905 gst_video_scale_setup_vs_image (VSImage * image, GstVideoFormat format,
906 gint component, gint width, gint height, gint b_w, gint b_h, uint8_t * data)
909 gst_video_format_get_component_width (format, component, width);
911 gst_video_format_get_component_height (format, component, height);
913 gst_video_format_get_component_width (format, component, MAX (1,
916 gst_video_format_get_component_height (format, component, MAX (1,
918 image->stride = gst_video_format_get_row_stride (format, component, width);
920 image->border_top = (image->real_height - image->height) / 2;
921 image->border_bottom = image->real_height - image->height - image->border_top;
923 if (format == GST_VIDEO_FORMAT_YUY2 || format == GST_VIDEO_FORMAT_YVYU
924 || format == GST_VIDEO_FORMAT_UYVY) {
925 g_assert (component == 0);
927 image->border_left = (image->real_width - image->width) / 2;
929 if (image->border_left % 2 == 1)
930 image->border_left--;
931 image->border_right = image->real_width - image->width - image->border_left;
933 image->border_left = (image->real_width - image->width) / 2;
934 image->border_right = image->real_width - image->width - image->border_left;
937 if (format == GST_VIDEO_FORMAT_I420
938 || format == GST_VIDEO_FORMAT_YV12
939 || format == GST_VIDEO_FORMAT_Y444
940 || format == GST_VIDEO_FORMAT_Y42B || format == GST_VIDEO_FORMAT_Y41B) {
941 image->real_pixels = data + gst_video_format_get_component_offset (format,
942 component, width, height);
944 g_assert (component == 0);
945 image->real_pixels = data;
949 image->real_pixels + image->border_top * image->stride +
950 image->border_left * gst_video_format_get_pixel_stride (format,
954 static const guint8 *
955 _get_black_for_format (GstVideoFormat format)
957 static const guint8 black[][4] = {
958 {255, 0, 0, 0}, /* 0 = ARGB, ABGR, xRGB, xBGR */
959 {0, 0, 0, 255}, /* 1 = RGBA, BGRA, RGBx, BGRx */
960 {255, 16, 128, 128}, /* 2 = AYUV */
961 {0, 0, 0, 0}, /* 3 = RGB and BGR */
962 {16, 128, 128, 0}, /* 4 = v301 */
963 {16, 128, 16, 128}, /* 5 = YUY2, YUYV */
964 {128, 16, 128, 16}, /* 6 = UYVY */
965 {16, 0, 0, 0}, /* 7 = Y */
966 {0, 0, 0, 0} /* 8 = RGB565, RGB666 */
970 case GST_VIDEO_FORMAT_ARGB:
971 case GST_VIDEO_FORMAT_ABGR:
972 case GST_VIDEO_FORMAT_xRGB:
973 case GST_VIDEO_FORMAT_xBGR:
974 case GST_VIDEO_FORMAT_ARGB64:
976 case GST_VIDEO_FORMAT_RGBA:
977 case GST_VIDEO_FORMAT_BGRA:
978 case GST_VIDEO_FORMAT_RGBx:
979 case GST_VIDEO_FORMAT_BGRx:
981 case GST_VIDEO_FORMAT_AYUV:
982 case GST_VIDEO_FORMAT_AYUV64:
984 case GST_VIDEO_FORMAT_RGB:
985 case GST_VIDEO_FORMAT_BGR:
987 case GST_VIDEO_FORMAT_v308:
989 case GST_VIDEO_FORMAT_YUY2:
990 case GST_VIDEO_FORMAT_YVYU:
992 case GST_VIDEO_FORMAT_UYVY:
994 case GST_VIDEO_FORMAT_Y800:
995 case GST_VIDEO_FORMAT_GRAY8:
997 case GST_VIDEO_FORMAT_GRAY16_LE:
998 case GST_VIDEO_FORMAT_GRAY16_BE:
999 case GST_VIDEO_FORMAT_Y16:
1000 return NULL; /* Handled by the caller */
1001 case GST_VIDEO_FORMAT_I420:
1002 case GST_VIDEO_FORMAT_YV12:
1003 case GST_VIDEO_FORMAT_Y444:
1004 case GST_VIDEO_FORMAT_Y42B:
1005 case GST_VIDEO_FORMAT_Y41B:
1006 return black[4]; /* Y, U, V, 0 */
1007 case GST_VIDEO_FORMAT_RGB16:
1008 case GST_VIDEO_FORMAT_RGB15:
1015 static GstFlowReturn
1016 gst_video_scale_transform (GstBaseTransform * trans, GstBuffer * in,
1019 GstVideoScale *videoscale = GST_VIDEO_SCALE (trans);
1020 GstFlowReturn ret = GST_FLOW_OK;
1021 VSImage dest = { NULL, };
1022 VSImage src = { NULL, };
1023 VSImage dest_u = { NULL, };
1024 VSImage dest_v = { NULL, };
1025 VSImage src_u = { NULL, };
1026 VSImage src_v = { NULL, };
1028 const guint8 *black = _get_black_for_format (videoscale->format);
1029 gboolean add_borders;
1030 guint8 *in_data, *out_data;
1031 gsize in_size, out_size;
1033 GST_OBJECT_LOCK (videoscale);
1034 method = videoscale->method;
1035 add_borders = videoscale->add_borders;
1036 GST_OBJECT_UNLOCK (videoscale);
1038 if (videoscale->from_width == 1) {
1039 method = GST_VIDEO_SCALE_NEAREST;
1041 if (method == GST_VIDEO_SCALE_4TAP &&
1042 (videoscale->from_width < 4 || videoscale->from_height < 4)) {
1043 method = GST_VIDEO_SCALE_BILINEAR;
1046 in_data = gst_buffer_map (in, &in_size, NULL, GST_MAP_READ);
1047 out_data = gst_buffer_map (out, &out_size, NULL, GST_MAP_WRITE);
1049 gst_video_scale_setup_vs_image (&src, videoscale->format, 0,
1050 videoscale->from_width, videoscale->from_height, 0, 0, in_data);
1051 gst_video_scale_setup_vs_image (&dest, videoscale->format, 0,
1052 videoscale->to_width, videoscale->to_height, videoscale->borders_w,
1053 videoscale->borders_h, out_data);
1055 if (videoscale->format == GST_VIDEO_FORMAT_I420
1056 || videoscale->format == GST_VIDEO_FORMAT_YV12
1057 || videoscale->format == GST_VIDEO_FORMAT_Y444
1058 || videoscale->format == GST_VIDEO_FORMAT_Y42B
1059 || videoscale->format == GST_VIDEO_FORMAT_Y41B) {
1060 gst_video_scale_setup_vs_image (&src_u, videoscale->format, 1,
1061 videoscale->from_width, videoscale->from_height, 0, 0, in_data);
1062 gst_video_scale_setup_vs_image (&src_v, videoscale->format, 2,
1063 videoscale->from_width, videoscale->from_height, 0, 0, in_data);
1064 gst_video_scale_setup_vs_image (&dest_u, videoscale->format, 1,
1065 videoscale->to_width, videoscale->to_height, videoscale->borders_w,
1066 videoscale->borders_h, out_data);
1067 gst_video_scale_setup_vs_image (&dest_v, videoscale->format, 2,
1068 videoscale->to_width, videoscale->to_height, videoscale->borders_w,
1069 videoscale->borders_h, out_data);
1072 switch (videoscale->format) {
1073 case GST_VIDEO_FORMAT_RGBx:
1074 case GST_VIDEO_FORMAT_xRGB:
1075 case GST_VIDEO_FORMAT_BGRx:
1076 case GST_VIDEO_FORMAT_xBGR:
1077 case GST_VIDEO_FORMAT_RGBA:
1078 case GST_VIDEO_FORMAT_ARGB:
1079 case GST_VIDEO_FORMAT_BGRA:
1080 case GST_VIDEO_FORMAT_ABGR:
1081 case GST_VIDEO_FORMAT_AYUV:
1083 vs_fill_borders_RGBA (&dest, black);
1085 case GST_VIDEO_SCALE_NEAREST:
1086 vs_image_scale_nearest_RGBA (&dest, &src, videoscale->tmp_buf);
1088 case GST_VIDEO_SCALE_BILINEAR:
1089 vs_image_scale_linear_RGBA (&dest, &src, videoscale->tmp_buf);
1091 case GST_VIDEO_SCALE_4TAP:
1092 vs_image_scale_4tap_RGBA (&dest, &src, videoscale->tmp_buf);
1098 case GST_VIDEO_FORMAT_ARGB64:
1099 case GST_VIDEO_FORMAT_AYUV64:
1101 vs_fill_borders_AYUV64 (&dest, black);
1103 case GST_VIDEO_SCALE_NEAREST:
1104 vs_image_scale_nearest_AYUV64 (&dest, &src, videoscale->tmp_buf);
1106 case GST_VIDEO_SCALE_BILINEAR:
1107 vs_image_scale_linear_AYUV64 (&dest, &src, videoscale->tmp_buf);
1109 case GST_VIDEO_SCALE_4TAP:
1110 vs_image_scale_4tap_AYUV64 (&dest, &src, videoscale->tmp_buf);
1116 case GST_VIDEO_FORMAT_RGB:
1117 case GST_VIDEO_FORMAT_BGR:
1118 case GST_VIDEO_FORMAT_v308:
1120 vs_fill_borders_RGB (&dest, black);
1122 case GST_VIDEO_SCALE_NEAREST:
1123 vs_image_scale_nearest_RGB (&dest, &src, videoscale->tmp_buf);
1125 case GST_VIDEO_SCALE_BILINEAR:
1126 vs_image_scale_linear_RGB (&dest, &src, videoscale->tmp_buf);
1128 case GST_VIDEO_SCALE_4TAP:
1129 vs_image_scale_4tap_RGB (&dest, &src, videoscale->tmp_buf);
1135 case GST_VIDEO_FORMAT_YUY2:
1136 case GST_VIDEO_FORMAT_YVYU:
1138 vs_fill_borders_YUYV (&dest, black);
1140 case GST_VIDEO_SCALE_NEAREST:
1141 vs_image_scale_nearest_YUYV (&dest, &src, videoscale->tmp_buf);
1143 case GST_VIDEO_SCALE_BILINEAR:
1144 vs_image_scale_linear_YUYV (&dest, &src, videoscale->tmp_buf);
1146 case GST_VIDEO_SCALE_4TAP:
1147 vs_image_scale_4tap_YUYV (&dest, &src, videoscale->tmp_buf);
1153 case GST_VIDEO_FORMAT_UYVY:
1155 vs_fill_borders_UYVY (&dest, black);
1157 case GST_VIDEO_SCALE_NEAREST:
1158 vs_image_scale_nearest_UYVY (&dest, &src, videoscale->tmp_buf);
1160 case GST_VIDEO_SCALE_BILINEAR:
1161 vs_image_scale_linear_UYVY (&dest, &src, videoscale->tmp_buf);
1163 case GST_VIDEO_SCALE_4TAP:
1164 vs_image_scale_4tap_UYVY (&dest, &src, videoscale->tmp_buf);
1170 case GST_VIDEO_FORMAT_Y800:
1171 case GST_VIDEO_FORMAT_GRAY8:
1173 vs_fill_borders_Y (&dest, black);
1175 case GST_VIDEO_SCALE_NEAREST:
1176 vs_image_scale_nearest_Y (&dest, &src, videoscale->tmp_buf);
1178 case GST_VIDEO_SCALE_BILINEAR:
1179 vs_image_scale_linear_Y (&dest, &src, videoscale->tmp_buf);
1181 case GST_VIDEO_SCALE_4TAP:
1182 vs_image_scale_4tap_Y (&dest, &src, videoscale->tmp_buf);
1188 case GST_VIDEO_FORMAT_GRAY16_LE:
1189 case GST_VIDEO_FORMAT_GRAY16_BE:
1190 case GST_VIDEO_FORMAT_Y16:
1192 vs_fill_borders_Y16 (&dest, 0);
1194 case GST_VIDEO_SCALE_NEAREST:
1195 vs_image_scale_nearest_Y16 (&dest, &src, videoscale->tmp_buf);
1197 case GST_VIDEO_SCALE_BILINEAR:
1198 vs_image_scale_linear_Y16 (&dest, &src, videoscale->tmp_buf);
1200 case GST_VIDEO_SCALE_4TAP:
1201 vs_image_scale_4tap_Y16 (&dest, &src, videoscale->tmp_buf);
1207 case GST_VIDEO_FORMAT_I420:
1208 case GST_VIDEO_FORMAT_YV12:
1209 case GST_VIDEO_FORMAT_Y444:
1210 case GST_VIDEO_FORMAT_Y42B:
1211 case GST_VIDEO_FORMAT_Y41B:
1213 vs_fill_borders_Y (&dest, black);
1214 vs_fill_borders_Y (&dest_u, black + 1);
1215 vs_fill_borders_Y (&dest_v, black + 2);
1218 case GST_VIDEO_SCALE_NEAREST:
1219 vs_image_scale_nearest_Y (&dest, &src, videoscale->tmp_buf);
1220 vs_image_scale_nearest_Y (&dest_u, &src_u, videoscale->tmp_buf);
1221 vs_image_scale_nearest_Y (&dest_v, &src_v, videoscale->tmp_buf);
1223 case GST_VIDEO_SCALE_BILINEAR:
1224 vs_image_scale_linear_Y (&dest, &src, videoscale->tmp_buf);
1225 vs_image_scale_linear_Y (&dest_u, &src_u, videoscale->tmp_buf);
1226 vs_image_scale_linear_Y (&dest_v, &src_v, videoscale->tmp_buf);
1228 case GST_VIDEO_SCALE_4TAP:
1229 vs_image_scale_4tap_Y (&dest, &src, videoscale->tmp_buf);
1230 vs_image_scale_4tap_Y (&dest_u, &src_u, videoscale->tmp_buf);
1231 vs_image_scale_4tap_Y (&dest_v, &src_v, videoscale->tmp_buf);
1237 case GST_VIDEO_FORMAT_RGB16:
1239 vs_fill_borders_RGB565 (&dest, black);
1241 case GST_VIDEO_SCALE_NEAREST:
1242 vs_image_scale_nearest_RGB565 (&dest, &src, videoscale->tmp_buf);
1244 case GST_VIDEO_SCALE_BILINEAR:
1245 vs_image_scale_linear_RGB565 (&dest, &src, videoscale->tmp_buf);
1247 case GST_VIDEO_SCALE_4TAP:
1248 vs_image_scale_4tap_RGB565 (&dest, &src, videoscale->tmp_buf);
1254 case GST_VIDEO_FORMAT_RGB15:
1256 vs_fill_borders_RGB555 (&dest, black);
1258 case GST_VIDEO_SCALE_NEAREST:
1259 vs_image_scale_nearest_RGB555 (&dest, &src, videoscale->tmp_buf);
1261 case GST_VIDEO_SCALE_BILINEAR:
1262 vs_image_scale_linear_RGB555 (&dest, &src, videoscale->tmp_buf);
1264 case GST_VIDEO_SCALE_4TAP:
1265 vs_image_scale_4tap_RGB555 (&dest, &src, videoscale->tmp_buf);
1275 GST_LOG_OBJECT (videoscale, "pushing buffer of %d bytes",
1276 gst_buffer_get_size (out));
1279 gst_buffer_unmap (in, in_data, in_size);
1280 gst_buffer_unmap (out, out_data, out_size);
1287 GST_ELEMENT_ERROR (videoscale, STREAM, NOT_IMPLEMENTED, (NULL),
1288 ("Unsupported format %d for scaling method %d",
1289 videoscale->format, method));
1290 ret = GST_FLOW_ERROR;
1295 GST_ELEMENT_ERROR (videoscale, STREAM, NOT_IMPLEMENTED, (NULL),
1296 ("Unknown scaling method %d", videoscale->method));
1297 ret = GST_FLOW_ERROR;
1303 gst_video_scale_src_event (GstBaseTransform * trans, GstEvent * event)
1305 GstVideoScale *videoscale = GST_VIDEO_SCALE (trans);
1308 GstStructure *structure;
1310 GST_DEBUG_OBJECT (videoscale, "handling %s event",
1311 GST_EVENT_TYPE_NAME (event));
1313 switch (GST_EVENT_TYPE (event)) {
1314 case GST_EVENT_NAVIGATION:
1316 GST_EVENT (gst_mini_object_make_writable (GST_MINI_OBJECT (event)));
1318 structure = (GstStructure *) gst_event_get_structure (event);
1319 if (gst_structure_get_double (structure, "pointer_x", &a)) {
1320 gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE,
1321 a * videoscale->from_width / videoscale->to_width, NULL);
1323 if (gst_structure_get_double (structure, "pointer_y", &a)) {
1324 gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE,
1325 a * videoscale->from_height / videoscale->to_height, NULL);
1332 ret = GST_BASE_TRANSFORM_CLASS (parent_class)->src_event (trans, event);
1338 plugin_init (GstPlugin * plugin)
1340 gst_videoscale_orc_init ();
1342 if (!gst_element_register (plugin, "videoscale", GST_RANK_NONE,
1343 GST_TYPE_VIDEO_SCALE))
1346 GST_DEBUG_CATEGORY_INIT (video_scale_debug, "videoscale", 0,
1347 "videoscale element");
1354 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1357 "Resizes video", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME,