2004-05-15 13:16:40 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* Copyright (C) <2004> Jan Schmidt <thaytan@mad.scientist.com>
|
2005-01-12 05:53:46 +00:00
|
|
|
* Copyright (C) <2004> Tim-Philipp Mueller <t.i.m@orange.net>
|
2004-05-15 13:16:40 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
#include <pixbufscale.h>
|
|
|
|
#include <gst/video/video.h>
|
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
|
|
|
2005-01-12 05:53:46 +00:00
|
|
|
#define ROUND_UP_2(x) (((x)+1)&~1)
|
|
|
|
#define ROUND_UP_4(x) (((x)+3)&~3)
|
|
|
|
#define ROUND_UP_8(x) (((x)+7)&~7)
|
|
|
|
|
|
|
|
/* These match the ones gstffmpegcolorspace uses (Tim) */
|
|
|
|
#define GST_RGB24_ROWSTRIDE(width) (ROUND_UP_4 ((width)*3))
|
|
|
|
#define GST_RGB24_SIZE(width,height) ((height)*GST_RGB24_ROWSTRIDE(width))
|
|
|
|
|
|
|
|
|
2004-05-15 13:16:40 +00:00
|
|
|
GST_DEBUG_CATEGORY (pixbufscale_debug);
|
|
|
|
#define GST_CAT_DEFAULT pixbufscale_debug
|
|
|
|
|
|
|
|
/* elementfactory information */
|
Define GstElementDetails as const and also static (when defined as global)
Original commit message from CVS:
* ext/aalib/gstaasink.c:
* ext/annodex/gstcmmldec.c:
* ext/annodex/gstcmmlenc.c:
* ext/cairo/gsttextoverlay.c:
* ext/cairo/gsttimeoverlay.c:
* ext/cdio/gstcdiocddasrc.c:
* ext/dv/gstdvdec.c:
* ext/dv/gstdvdemux.c:
* ext/esd/esdmon.c:
* ext/esd/esdsink.c:
* ext/flac/gstflacenc.c:
* ext/flac/gstflactag.c:
* ext/gconf/gstgconfaudiosink.c: (gst_gconf_audio_sink_base_init):
* ext/gconf/gstgconfaudiosrc.c: (gst_gconf_audio_src_base_init):
* ext/gconf/gstgconfvideosink.c: (gst_gconf_video_sink_base_init):
* ext/gconf/gstgconfvideosrc.c: (gst_gconf_video_src_base_init):
* ext/gdk_pixbuf/pixbufscale.c:
* ext/hal/gsthalaudiosink.c: (gst_hal_audio_sink_base_init):
* ext/hal/gsthalaudiosrc.c: (gst_hal_audio_src_base_init):
* ext/jpeg/gstjpegdec.c:
* ext/jpeg/gstjpegenc.c:
* ext/jpeg/gstsmokedec.c:
* ext/jpeg/gstsmokeenc.c:
* ext/libcaca/gstcacasink.c:
* ext/libmng/gstmngdec.c:
* ext/libmng/gstmngenc.c:
* ext/libpng/gstpngdec.c:
* ext/libpng/gstpngenc.c:
* ext/mikmod/gstmikmod.c:
* ext/raw1394/gstdv1394src.c:
* ext/shout2/gstshout2.c: (gst_shout2send_init):
* ext/shout2/gstshout2.h:
* ext/speex/gstspeexdec.c:
* ext/speex/gstspeexenc.c:
* gst/alpha/gstalpha.c:
* gst/alpha/gstalphacolor.c:
* gst/apetag/gstapedemux.c:
* gst/auparse/gstauparse.c:
* gst/autodetect/gstautoaudiosink.c:
(gst_auto_audio_sink_base_init):
* gst/autodetect/gstautovideosink.c:
(gst_auto_video_sink_base_init):
* gst/avi/gstavidemux.c: (gst_avi_demux_base_init):
* gst/avi/gstavimux.c: (gst_avimux_base_init):
* gst/cutter/gstcutter.c:
* gst/debug/breakmydata.c:
* gst/debug/efence.c:
* gst/debug/gstnavigationtest.c:
* gst/debug/gstnavseek.c:
* gst/debug/negotiation.c:
* gst/debug/progressreport.c:
* gst/debug/testplugin.c:
* gst/effectv/gstaging.c:
* gst/effectv/gstdice.c:
* gst/effectv/gstedge.c:
* gst/effectv/gstquark.c:
* gst/effectv/gstrev.c:
* gst/effectv/gstshagadelic.c:
* gst/effectv/gstvertigo.c:
* gst/effectv/gstwarp.c:
* gst/flx/gstflxdec.c:
* gst/goom/gstgoom.c:
* gst/icydemux/gsticydemux.c:
* gst/id3demux/gstid3demux.c:
* gst/interleave/deinterleave.c:
* gst/interleave/interleave.c:
* gst/law/alaw-decode.c: (gst_alawdec_base_init):
* gst/law/alaw-encode.c: (gst_alawenc_base_init):
* gst/law/mulaw-decode.c: (gst_mulawdec_base_init):
* gst/law/mulaw-encode.c: (gst_mulawenc_base_init):
* gst/level/gstlevel.c:
* gst/matroska/matroska-demux.c: (gst_matroska_demux_base_init):
* gst/matroska/matroska-mux.c: (gst_matroska_mux_base_init):
* gst/median/gstmedian.c:
* gst/monoscope/gstmonoscope.c:
* gst/multipart/multipartdemux.c:
* gst/multipart/multipartmux.c:
* gst/oldcore/gstaggregator.c:
* gst/oldcore/gstfdsink.c:
* gst/oldcore/gstmd5sink.c:
* gst/oldcore/gstmultifilesrc.c:
* gst/oldcore/gstpipefilter.c:
* gst/oldcore/gstshaper.c:
* gst/oldcore/gststatistics.c:
* gst/rtp/gstasteriskh263.c:
* gst/rtp/gstrtpL16depay.c:
* gst/rtp/gstrtpL16pay.c:
* gst/rtp/gstrtpamrdepay.c:
* gst/rtp/gstrtpamrpay.c:
* gst/rtp/gstrtpdepay.c:
* gst/rtp/gstrtpgsmpay.c:
* gst/rtp/gstrtph263pay.c:
* gst/rtp/gstrtph263pdepay.c:
* gst/rtp/gstrtph263ppay.c:
* gst/rtp/gstrtpilbcdepay.c:
* gst/rtp/gstrtpmp4gpay.c:
* gst/rtp/gstrtpmp4vdepay.c:
* gst/rtp/gstrtpmp4vpay.c:
* gst/rtp/gstrtpmpadepay.c:
* gst/rtp/gstrtpmpapay.c:
* gst/rtp/gstrtppcmadepay.c:
* gst/rtp/gstrtppcmapay.c:
* gst/rtp/gstrtppcmudepay.c:
* gst/rtp/gstrtppcmupay.c:
* gst/rtp/gstrtpspeexdepay.c:
* gst/rtp/gstrtpspeexpay.c:
* gst/rtsp/gstrtpdec.c:
* gst/rtsp/gstrtspsrc.c:
* gst/smpte/gstsmpte.c:
* gst/udp/gstdynudpsink.c:
* gst/udp/gstmultiudpsink.c:
* gst/udp/gstudpsink.c:
* gst/udp/gstudpsrc.c:
* gst/videobox/gstvideobox.c:
* gst/videofilter/gstgamma.c: (gst_gamma_base_init):
* gst/videofilter/gstvideobalance.c:
* gst/videofilter/gstvideoflip.c:
* gst/videofilter/gstvideotemplate.c:
(gst_videotemplate_base_init):
* gst/videomixer/videomixer.c:
* gst/wavparse/gstwavparse.c: (gst_wavparse_base_init),
(gst_wavparse_class_init), (gst_wavparse_dispose),
(gst_wavparse_reset), (gst_wavparse_init),
(gst_wavparse_perform_seek), (gst_wavparse_peek_chunk_info),
(gst_wavparse_peek_chunk), (gst_wavparse_stream_headers),
(gst_wavparse_parse_stream_init), (gst_wavparse_send_event),
(gst_wavparse_add_src_pad), (gst_wavparse_stream_data),
(gst_wavparse_chain), (gst_wavparse_srcpad_event),
(gst_wavparse_sink_activate), (gst_wavparse_sink_activate_pull),
(gst_wavparse_change_state):
* gst/wavparse/gstwavparse.h:
* sys/oss/gstossmixerelement.c:
* sys/oss/gstosssink.c:
* sys/oss/gstosssrc.c:
* sys/osxaudio/gstosxaudioelement.c:
* sys/osxaudio/gstosxaudiosink.c:
* sys/osxaudio/gstosxaudiosrc.c:
* sys/sunaudio/gstsunaudiomixer.c:
* sys/sunaudio/gstsunaudiosink.c:
Define GstElementDetails as const and also static (when defined as
global)
2006-04-25 21:39:46 +00:00
|
|
|
static const GstElementDetails pixbufscale_details =
|
2006-03-30 15:37:05 +00:00
|
|
|
GST_ELEMENT_DETAILS ("GdkPixbuf image scaler",
|
2004-05-15 13:16:40 +00:00
|
|
|
"Filter/Effect/Video",
|
|
|
|
"Resizes video",
|
2006-02-24 19:51:29 +00:00
|
|
|
"Jan Schmidt <thaytan@mad.scientist.com>\n"
|
|
|
|
"Wim Taymans <wim.taymans@chello.be>\n"
|
|
|
|
"Renato Filho <renato.filho@indt.org.br>");
|
2004-05-15 13:16:40 +00:00
|
|
|
|
|
|
|
/* GstPixbufScale signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
2004-05-21 23:28:57 +00:00
|
|
|
ARG_METHOD
|
|
|
|
/* FILL ME */
|
2004-05-15 13:16:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_pixbufscale_src_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB)
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_pixbufscale_sink_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB)
|
|
|
|
);
|
|
|
|
|
|
|
|
#define GST_TYPE_PIXBUFSCALE_METHOD (gst_pixbufscale_method_get_type())
|
|
|
|
static GType
|
|
|
|
gst_pixbufscale_method_get_type (void)
|
|
|
|
{
|
|
|
|
static GType pixbufscale_method_type = 0;
|
|
|
|
static GEnumValue pixbufscale_methods[] = {
|
2006-02-24 19:51:29 +00:00
|
|
|
{GST_PIXBUFSCALE_NEAREST, "0", "Nearest Neighbour"},
|
|
|
|
{GST_PIXBUFSCALE_TILES, "1", "Tiles"},
|
|
|
|
{GST_PIXBUFSCALE_BILINEAR, "2", "Bilinear"},
|
|
|
|
{GST_PIXBUFSCALE_HYPER, "3", "Hyper"},
|
2004-05-15 13:16:40 +00:00
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!pixbufscale_method_type) {
|
|
|
|
pixbufscale_method_type =
|
|
|
|
g_enum_register_static ("GstPixbufScaleMethod", pixbufscale_methods);
|
|
|
|
}
|
|
|
|
return pixbufscale_method_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gst_pixbufscale_base_init (gpointer g_class);
|
|
|
|
static void gst_pixbufscale_class_init (GstPixbufScaleClass * klass);
|
2006-02-24 19:51:29 +00:00
|
|
|
static void gst_pixbufscale_init (GstPixbufScale * pixbufscale,
|
|
|
|
GstPixbufScaleClass * kclass);
|
2004-05-15 13:16:40 +00:00
|
|
|
static void gst_pixbufscale_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_pixbufscale_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
static GstCaps *gst_pixbufscale_transform_caps (GstBaseTransform * trans,
|
|
|
|
GstPadDirection direction, GstCaps * caps);
|
|
|
|
static gboolean gst_pixbufscale_set_caps (GstBaseTransform * trans,
|
|
|
|
GstCaps * in, GstCaps * out);
|
|
|
|
static gboolean gst_pixbufscale_get_unit_size (GstBaseTransform * trans,
|
|
|
|
GstCaps * caps, guint * size);
|
|
|
|
static void gst_pixbufscale_fixate_caps (GstBaseTransform * base,
|
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * othercaps);
|
|
|
|
static GstFlowReturn gst_pixbufscale_transform (GstBaseTransform * trans,
|
|
|
|
GstBuffer * in, GstBuffer * out);
|
|
|
|
static gboolean gst_pixbufscale_handle_src_event (GstPad * pad,
|
|
|
|
GstEvent * event);
|
2004-05-15 13:16:40 +00:00
|
|
|
|
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
static gboolean parse_caps (GstCaps * caps, gint * width, gint * height);
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
GST_BOILERPLATE (GstPixbufScale, gst_pixbufscale, GstBaseTransform,
|
2006-05-06 00:14:09 +00:00
|
|
|
GST_TYPE_BASE_TRANSFORM);
|
2006-02-24 19:51:29 +00:00
|
|
|
|
2006-05-06 00:14:09 +00:00
|
|
|
static void
|
|
|
|
gst_pixbufscale_base_init (gpointer g_class)
|
2004-05-15 13:16:40 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &pixbufscale_details);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&gst_pixbufscale_src_template));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&gst_pixbufscale_sink_template));
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
gst_pixbufscale_class_init (GstPixbufScaleClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2006-02-24 19:51:29 +00:00
|
|
|
GstBaseTransformClass *trans_class;
|
2004-05-15 13:16:40 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
2006-02-24 19:51:29 +00:00
|
|
|
trans_class = (GstBaseTransformClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_pixbufscale_set_property;
|
|
|
|
gobject_class->get_property = gst_pixbufscale_get_property;
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
ARG_METHOD,
|
2004-05-15 13:16:40 +00:00
|
|
|
g_param_spec_enum ("method", "method", "method",
|
|
|
|
GST_TYPE_PIXBUFSCALE_METHOD, GST_PIXBUFSCALE_BILINEAR,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
trans_class->transform_caps =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_pixbufscale_transform_caps);
|
|
|
|
trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_pixbufscale_set_caps);
|
|
|
|
trans_class->get_unit_size =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_pixbufscale_get_unit_size);
|
|
|
|
trans_class->transform = GST_DEBUG_FUNCPTR (gst_pixbufscale_transform);
|
|
|
|
trans_class->fixate_caps = GST_DEBUG_FUNCPTR (gst_pixbufscale_fixate_caps);
|
|
|
|
trans_class->passthrough_on_same_caps = TRUE;
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2004-05-15 13:16:40 +00:00
|
|
|
}
|
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
static void
|
|
|
|
gst_pixbufscale_init (GstPixbufScale * pixbufscale,
|
|
|
|
GstPixbufScaleClass * kclass)
|
|
|
|
{
|
2006-05-08 10:59:05 +00:00
|
|
|
GstBaseTransform *trans;
|
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
GST_DEBUG_OBJECT (pixbufscale, "_init");
|
2006-05-08 10:59:05 +00:00
|
|
|
trans = GST_BASE_TRANSFORM (pixbufscale);
|
2006-02-24 19:51:29 +00:00
|
|
|
|
|
|
|
gst_pad_set_event_function (trans->srcpad, gst_pixbufscale_handle_src_event);
|
|
|
|
|
|
|
|
pixbufscale->method = GST_PIXBUFSCALE_TILES;
|
|
|
|
pixbufscale->gdk_method = GDK_INTERP_TILES;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_pixbufscale_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstPixbufScale *src;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_PIXBUFSCALE (object));
|
|
|
|
src = GST_PIXBUFSCALE (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_METHOD:
|
|
|
|
src->method = g_value_get_enum (value);
|
|
|
|
switch (src->method) {
|
|
|
|
case GST_PIXBUFSCALE_NEAREST:
|
|
|
|
src->gdk_method = GDK_INTERP_NEAREST;
|
|
|
|
break;
|
|
|
|
case GST_PIXBUFSCALE_TILES:
|
|
|
|
src->gdk_method = GDK_INTERP_TILES;
|
|
|
|
break;
|
|
|
|
case GST_PIXBUFSCALE_BILINEAR:
|
|
|
|
src->gdk_method = GDK_INTERP_BILINEAR;
|
|
|
|
break;
|
|
|
|
case GST_PIXBUFSCALE_HYPER:
|
|
|
|
src->gdk_method = GDK_INTERP_HYPER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_pixbufscale_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstPixbufScale *src;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_PIXBUFSCALE (object));
|
|
|
|
src = GST_PIXBUFSCALE (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_METHOD:
|
|
|
|
g_value_set_enum (value, src->method);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-05-15 13:16:40 +00:00
|
|
|
static GstCaps *
|
2006-02-24 19:51:29 +00:00
|
|
|
gst_pixbufscale_transform_caps (GstBaseTransform * trans,
|
|
|
|
GstPadDirection direction, GstCaps * caps)
|
2004-05-15 13:16:40 +00:00
|
|
|
{
|
|
|
|
GstPixbufScale *pixbufscale;
|
2006-02-24 19:51:29 +00:00
|
|
|
GstCaps *ret;
|
2004-09-22 15:03:08 +00:00
|
|
|
int i;
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
pixbufscale = GST_PIXBUFSCALE (trans);
|
|
|
|
ret = gst_caps_copy (caps);
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
for (i = 0; i < gst_caps_get_size (ret); i++) {
|
|
|
|
GstStructure *structure = gst_caps_get_structure (ret, i);
|
2004-09-22 15:03:08 +00:00
|
|
|
|
|
|
|
gst_structure_set (structure,
|
|
|
|
"width", GST_TYPE_INT_RANGE, 16, 4096,
|
|
|
|
"height", GST_TYPE_INT_RANGE, 16, 4096, NULL);
|
|
|
|
gst_structure_remove_field (structure, "pixel-aspect-ratio");
|
|
|
|
}
|
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
GST_DEBUG_OBJECT (trans, "returning caps: %", ret);
|
|
|
|
return ret;
|
2004-05-15 13:16:40 +00:00
|
|
|
}
|
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
static gboolean
|
|
|
|
parse_caps (GstCaps * caps, gint * width, gint * height)
|
2004-05-15 13:16:40 +00:00
|
|
|
{
|
2006-02-24 19:51:29 +00:00
|
|
|
gboolean ret;
|
2004-05-15 13:16:40 +00:00
|
|
|
GstStructure *structure;
|
2005-02-22 12:04:16 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
ret = gst_structure_get_int (structure, "width", width);
|
|
|
|
ret &= gst_structure_get_int (structure, "height", height);
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
static gboolean
|
|
|
|
gst_pixbufscale_set_caps (GstBaseTransform * trans, GstCaps * in, GstCaps * out)
|
|
|
|
{
|
|
|
|
GstPixbufScale *pixbufscale;
|
|
|
|
gboolean ret;
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
pixbufscale = GST_PIXBUFSCALE (trans);
|
|
|
|
ret = parse_caps (in, &pixbufscale->from_width, &pixbufscale->from_height);
|
|
|
|
ret &= parse_caps (out, &pixbufscale->to_width, &pixbufscale->to_height);
|
|
|
|
if (!ret)
|
|
|
|
goto done;
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
pixbufscale->from_stride = GST_ROUND_UP_4 (pixbufscale->from_width * 3);
|
|
|
|
pixbufscale->from_buf_size =
|
|
|
|
pixbufscale->from_stride * pixbufscale->from_height;
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
pixbufscale->to_stride = GST_ROUND_UP_4 (pixbufscale->to_width * 3);
|
|
|
|
pixbufscale->to_buf_size = pixbufscale->to_stride * pixbufscale->to_height;
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
GST_DEBUG_OBJECT (pixbufscale, "from=%dx%d, size %d -> to=%dx%d, size %d",
|
|
|
|
pixbufscale->from_width, pixbufscale->from_height,
|
|
|
|
pixbufscale->from_buf_size, pixbufscale->to_width, pixbufscale->to_height,
|
|
|
|
pixbufscale->to_buf_size);
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
done:
|
|
|
|
return ret;
|
|
|
|
}
|
2004-05-15 13:16:40 +00:00
|
|
|
|
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
static gboolean
|
|
|
|
gst_pixbufscale_get_unit_size (GstBaseTransform * trans,
|
|
|
|
GstCaps * caps, guint * size)
|
|
|
|
{
|
|
|
|
GstPixbufScale *pixbufscale;
|
|
|
|
gint width, height;
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
g_return_val_if_fail (size, FALSE);
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
pixbufscale = GST_PIXBUFSCALE (trans);
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
if (!parse_caps (caps, &width, &height))
|
|
|
|
return FALSE;
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
*size = GST_ROUND_UP_4 (width * 3) * height;
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
return TRUE;
|
2004-05-15 13:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-02-24 19:51:29 +00:00
|
|
|
gst_pixbufscale_fixate_caps (GstBaseTransform * base, GstPadDirection direction,
|
|
|
|
GstCaps * caps, GstCaps * othercaps)
|
2004-05-15 13:16:40 +00:00
|
|
|
{
|
2006-02-24 19:51:29 +00:00
|
|
|
GstStructure *ins, *outs;
|
|
|
|
const GValue *from_par, *to_par;
|
|
|
|
|
|
|
|
g_return_if_fail (gst_caps_is_fixed (caps));
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (base, "trying to fixate othercaps %" GST_PTR_FORMAT
|
|
|
|
" based on caps %" GST_PTR_FORMAT, othercaps, caps);
|
|
|
|
|
|
|
|
ins = gst_caps_get_structure (caps, 0);
|
|
|
|
outs = gst_caps_get_structure (othercaps, 0);
|
|
|
|
|
|
|
|
from_par = gst_structure_get_value (ins, "pixel-aspect-ratio");
|
|
|
|
to_par = gst_structure_get_value (outs, "pixel-aspect-ratio");
|
|
|
|
|
|
|
|
if (from_par && to_par) {
|
|
|
|
GValue to_ratio = { 0, }; /* w/h of output video */
|
|
|
|
int from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d;
|
|
|
|
int count = 0, w = 0, h = 0, num, den;
|
|
|
|
|
|
|
|
/* if both width and height are already fixed, we can't do anything
|
|
|
|
* * about it anymore */
|
|
|
|
if (gst_structure_get_int (outs, "width", &w))
|
|
|
|
++count;
|
|
|
|
if (gst_structure_get_int (outs, "height", &h))
|
|
|
|
++count;
|
|
|
|
if (count == 2) {
|
|
|
|
GST_DEBUG_OBJECT (base, "dimensions already set to %dx%d, not fixating",
|
|
|
|
w, h);
|
|
|
|
return;
|
|
|
|
}
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
gst_structure_get_int (ins, "width", &from_w);
|
|
|
|
gst_structure_get_int (ins, "height", &from_h);
|
|
|
|
from_par_n = gst_value_get_fraction_numerator (from_par);
|
|
|
|
from_par_d = gst_value_get_fraction_denominator (from_par);
|
|
|
|
to_par_n = gst_value_get_fraction_numerator (to_par);
|
|
|
|
to_par_d = gst_value_get_fraction_denominator (to_par);
|
|
|
|
|
|
|
|
g_value_init (&to_ratio, GST_TYPE_FRACTION);
|
|
|
|
gst_value_set_fraction (&to_ratio, from_w * from_par_n * to_par_d,
|
|
|
|
from_h * from_par_d * to_par_n);
|
|
|
|
num = gst_value_get_fraction_numerator (&to_ratio);
|
|
|
|
den = gst_value_get_fraction_denominator (&to_ratio);
|
|
|
|
GST_DEBUG_OBJECT (base,
|
|
|
|
"scaling input with %dx%d and PAR %d/%d to output PAR %d/%d",
|
|
|
|
from_w, from_h, from_par_n, from_par_d, to_par_n, to_par_d);
|
|
|
|
GST_DEBUG_OBJECT (base,
|
|
|
|
"resulting output should respect ratio of %d/%d", num, den);
|
|
|
|
|
|
|
|
/* now find a width x height that respects this display ratio.
|
|
|
|
* * prefer those that have one of w/h the same as the incoming video
|
|
|
|
* * using wd / hd = num / den */
|
|
|
|
|
|
|
|
/* start with same height, because of interlaced video */
|
|
|
|
/* check hd / den is an integer scale factor, and scale wd with the PAR */
|
|
|
|
if (from_h % den == 0) {
|
|
|
|
GST_DEBUG_OBJECT (base, "keeping video height");
|
|
|
|
h = from_h;
|
|
|
|
w = h * num / den;
|
|
|
|
} else if (from_w % num == 0) {
|
|
|
|
GST_DEBUG_OBJECT (base, "keeping video width");
|
|
|
|
w = from_w;
|
|
|
|
h = w * den / num;
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (base, "approximating but keeping video height");
|
|
|
|
h = from_h;
|
|
|
|
w = h * num / den;
|
|
|
|
}
|
|
|
|
GST_DEBUG_OBJECT (base, "scaling to %dx%d", w, h);
|
|
|
|
/* now fixate */
|
|
|
|
gst_structure_fixate_field_nearest_int (outs, "width", w);
|
|
|
|
gst_structure_fixate_field_nearest_int (outs, "height", h);
|
|
|
|
} else {
|
|
|
|
gint width, height;
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
if (gst_structure_get_int (ins, "width", &width)) {
|
|
|
|
if (gst_structure_has_field (outs, "width")) {
|
|
|
|
gst_structure_fixate_field_nearest_int (outs, "width", width);
|
2004-05-15 13:16:40 +00:00
|
|
|
}
|
2006-02-24 19:51:29 +00:00
|
|
|
}
|
|
|
|
if (gst_structure_get_int (ins, "height", &height)) {
|
|
|
|
if (gst_structure_has_field (outs, "height")) {
|
|
|
|
gst_structure_fixate_field_nearest_int (outs, "height", height);
|
2004-05-15 13:16:40 +00:00
|
|
|
}
|
2006-02-24 19:51:29 +00:00
|
|
|
}
|
2004-05-15 13:16:40 +00:00
|
|
|
}
|
2006-02-24 19:51:29 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (base, "fixated othercaps to %" GST_PTR_FORMAT, othercaps);
|
2004-05-15 13:16:40 +00:00
|
|
|
}
|
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_pixbufscale_transform (GstBaseTransform * trans,
|
|
|
|
GstBuffer * in, GstBuffer * out)
|
2004-05-15 13:16:40 +00:00
|
|
|
{
|
2006-02-24 19:51:29 +00:00
|
|
|
GstPixbufScale *scale;
|
2004-05-15 13:16:40 +00:00
|
|
|
GdkPixbuf *src_pixbuf, *dest_pixbuf;
|
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
scale = GST_PIXBUFSCALE (trans);
|
|
|
|
|
|
|
|
src_pixbuf =
|
|
|
|
gdk_pixbuf_new_from_data (GST_BUFFER_DATA (in), GDK_COLORSPACE_RGB, FALSE,
|
2004-05-15 13:16:40 +00:00
|
|
|
8, scale->from_width, scale->from_height,
|
2005-01-12 05:53:46 +00:00
|
|
|
GST_RGB24_ROWSTRIDE (scale->from_width), NULL, NULL);
|
2006-02-24 19:51:29 +00:00
|
|
|
|
|
|
|
dest_pixbuf =
|
|
|
|
gdk_pixbuf_new_from_data (GST_BUFFER_DATA (out), GDK_COLORSPACE_RGB,
|
|
|
|
FALSE, 8, scale->to_width, scale->to_height,
|
2005-01-12 05:53:46 +00:00
|
|
|
GST_RGB24_ROWSTRIDE (scale->to_width), NULL, NULL);
|
2006-02-24 19:51:29 +00:00
|
|
|
|
|
|
|
gdk_pixbuf_scale (src_pixbuf, dest_pixbuf, 0, 0,
|
|
|
|
scale->to_width,
|
2004-05-15 13:16:40 +00:00
|
|
|
scale->to_height, 0, 0,
|
|
|
|
(double) scale->to_width / scale->from_width,
|
|
|
|
(double) scale->to_height / scale->from_height, scale->gdk_method);
|
|
|
|
|
|
|
|
g_object_unref (src_pixbuf);
|
|
|
|
g_object_unref (dest_pixbuf);
|
2006-02-24 19:51:29 +00:00
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
2004-05-15 13:16:40 +00:00
|
|
|
}
|
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
static gboolean
|
|
|
|
gst_pixbufscale_handle_src_event (GstPad * pad, GstEvent * event)
|
2004-05-15 13:16:40 +00:00
|
|
|
{
|
|
|
|
GstPixbufScale *pixbufscale;
|
2006-02-24 19:51:29 +00:00
|
|
|
gboolean ret;
|
|
|
|
double a;
|
|
|
|
GstStructure *structure;
|
2004-05-15 13:16:40 +00:00
|
|
|
|
|
|
|
pixbufscale = GST_PIXBUFSCALE (gst_pad_get_parent (pad));
|
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
GST_DEBUG_OBJECT (pixbufscale, "handling %s event",
|
|
|
|
GST_EVENT_TYPE_NAME (event));
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_NAVIGATION:
|
|
|
|
event =
|
|
|
|
GST_EVENT (gst_mini_object_make_writable (GST_MINI_OBJECT (event)));
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
structure = (GstStructure *) gst_event_get_structure (event);
|
|
|
|
if (gst_structure_get_double (structure, "pointer_x", &a)) {
|
|
|
|
gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE,
|
|
|
|
a * pixbufscale->from_width / pixbufscale->to_width, NULL);
|
|
|
|
}
|
|
|
|
if (gst_structure_get_double (structure, "pointer_y", &a)) {
|
|
|
|
gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE,
|
|
|
|
a * pixbufscale->from_height / pixbufscale->to_height, NULL);
|
2004-05-15 13:16:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
ret = gst_pad_event_default (pad, event);
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
gst_object_unref (pixbufscale);
|
2004-05-15 13:16:40 +00:00
|
|
|
|
2006-02-24 19:51:29 +00:00
|
|
|
return ret;
|
2004-05-15 13:16:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
pixbufscale_init (GstPlugin * plugin)
|
|
|
|
{
|
2004-05-16 16:06:42 +00:00
|
|
|
if (!gst_element_register (plugin, "gdkpixbufscale", GST_RANK_NONE,
|
2004-05-15 13:16:40 +00:00
|
|
|
GST_TYPE_PIXBUFSCALE))
|
|
|
|
return FALSE;
|
|
|
|
|
2004-05-16 16:06:42 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (pixbufscale_debug, "gdkpixbufscale", 0,
|
2004-05-15 13:16:40 +00:00
|
|
|
"pixbufscale element");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|