summaryrefslogtreecommitdiffstats
path: root/gst/videocrop
diff options
context:
space:
mode:
authorRonald S. Bultje <rbultje@ronald.bitfreak.net>2003-07-06 20:49:52 +0000
committerRonald S. Bultje <rbultje@ronald.bitfreak.net>2003-07-06 20:49:52 +0000
commit292fec2a0bd1f221a46ad69c5100995d04c01057 (patch)
tree658db299e0e03b2454ff840730569d79539e67c4 /gst/videocrop
parenta8183e9a3fa87cf4247c7df16207f440ea4069c0 (diff)
New mimetypes gone into effect today - this commit changes all old mimetypes over to the new mimetypes spec as descri...
Original commit message from CVS: New mimetypes gone into effect today - this commit changes all old mimetypes over to the new mimetypes spec as described in the previous commit's document. Note: some plugins will break, some pipelines will break, expect HEAD to be broken or at least not 100% working for a few days, but don't forget to report bugs
Diffstat (limited to 'gst/videocrop')
-rw-r--r--gst/videocrop/gstvideocrop.c142
1 files changed, 76 insertions, 66 deletions
diff --git a/gst/videocrop/gstvideocrop.c b/gst/videocrop/gstvideocrop.c
index 53628471..6f10391b 100644
--- a/gst/videocrop/gstvideocrop.c
+++ b/gst/videocrop/gstvideocrop.c
@@ -21,6 +21,7 @@
#include "config.h"
#endif
#include <gst/gst.h>
+#include <gst/video/video.h>
#include <string.h>
@@ -47,8 +48,8 @@ struct _GstVideoCrop {
/* caps */
gint width, height;
- gint crop_x, crop_y;
- gint crop_width, crop_height;
+ gfloat fps;
+ gint crop_left, crop_right, crop_top, crop_bottom;
};
struct _GstVideoCropClass {
@@ -75,10 +76,10 @@ enum {
enum {
ARG_0,
- ARG_X,
- ARG_Y,
- ARG_WIDTH,
- ARG_HEIGHT,
+ ARG_LEFT,
+ ARG_RIGHT,
+ ARG_TOP,
+ ARG_BOTTOM,
/* FILL ME */
};
@@ -86,10 +87,11 @@ GST_PAD_TEMPLATE_FACTORY (video_crop_src_template_factory,
"src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
- GST_CAPS_NEW (
+ gst_caps_new (
"video_crop_src",
- "video/raw",
- "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("I420"))
+ "video/x-raw-yuv",
+ GST_VIDEO_YUV_PAD_TEMPLATE_PROPS(
+ GST_PROPS_FOURCC (GST_STR_FOURCC ("I420")))
)
)
@@ -97,10 +99,11 @@ GST_PAD_TEMPLATE_FACTORY (video_crop_sink_template_factory,
"sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
- GST_CAPS_NEW (
+ gst_caps_new (
"video_crop_sink",
- "video/raw",
- "format", GST_PROPS_FOURCC (GST_STR_FOURCC ("I420"))
+ "video/x-raw-yuv",
+ GST_VIDEO_YUV_PAD_TEMPLATE_PROPS(
+ GST_PROPS_FOURCC (GST_STR_FOURCC ("I420")))
)
)
@@ -157,17 +160,17 @@ gst_video_crop_class_init (GstVideoCropClass *klass)
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
- g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_X,
- g_param_spec_int ("x", "X", "X offset of image",
+ g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LEFT,
+ g_param_spec_int ("left", "Left", "Pixels to crop at left",
0, G_MAXINT, 0, G_PARAM_READWRITE));
- g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_Y,
- g_param_spec_int ("y", "Y", "Y offset of image",
+ g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_RIGHT,
+ g_param_spec_int ("right", "Right", "Pixels to crop at right",
0, G_MAXINT, 0, G_PARAM_READWRITE));
- g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_WIDTH,
- g_param_spec_int ("width", "Width", "Width of image",
+ g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TOP,
+ g_param_spec_int ("top", "Top", "Pixels to crop at top",
0, G_MAXINT, 0, G_PARAM_READWRITE));
- g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_HEIGHT,
- g_param_spec_int ("height", "Height", "Height of image",
+ g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BOTTOM,
+ g_param_spec_int ("bottom", "Bottom", "Pixels to crop at bottom",
0, G_MAXINT, 0, G_PARAM_READWRITE));
gobject_class->set_property = gst_video_crop_set_property;
@@ -190,10 +193,10 @@ gst_video_crop_init (GstVideoCrop *video_crop)
GST_PAD_TEMPLATE_GET (video_crop_src_template_factory), "src");
gst_element_add_pad (GST_ELEMENT (video_crop), video_crop->srcpad);
- video_crop->crop_x = 0;
- video_crop->crop_y = 0;
- video_crop->crop_width = 128;
- video_crop->crop_height = 128;
+ video_crop->crop_right = 0;
+ video_crop->crop_left = 0;
+ video_crop->crop_top = 0;
+ video_crop->crop_bottom = 0;
GST_FLAG_SET (video_crop, GST_ELEMENT_EVENT_AWARE);
}
@@ -210,17 +213,17 @@ gst_video_crop_set_property (GObject *object, guint prop_id, const GValue *value
video_crop = GST_VIDEO_CROP (object);
switch (prop_id) {
- case ARG_X:
- video_crop->crop_x = g_value_get_int (value);
+ case ARG_LEFT:
+ video_crop->crop_left = g_value_get_int (value);
break;
- case ARG_Y:
- video_crop->crop_y = g_value_get_int (value);
+ case ARG_RIGHT:
+ video_crop->crop_right = g_value_get_int (value);
break;
- case ARG_WIDTH:
- video_crop->crop_width = g_value_get_int (value);
+ case ARG_TOP:
+ video_crop->crop_top = g_value_get_int (value);
break;
- case ARG_HEIGHT:
- video_crop->crop_height = g_value_get_int (value);
+ case ARG_BOTTOM:
+ video_crop->crop_bottom = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -238,17 +241,17 @@ gst_video_crop_get_property (GObject *object, guint prop_id, GValue *value, GPar
video_crop = GST_VIDEO_CROP (object);
switch (prop_id) {
- case ARG_X:
- g_value_set_int (value, video_crop->crop_x);
+ case ARG_LEFT:
+ g_value_set_int (value, video_crop->crop_left);
break;
- case ARG_Y:
- g_value_set_int (value, video_crop->crop_y);
+ case ARG_RIGHT:
+ g_value_set_int (value, video_crop->crop_right);
break;
- case ARG_WIDTH:
- g_value_set_int (value, video_crop->crop_width);
+ case ARG_TOP:
+ g_value_set_int (value, video_crop->crop_top);
break;
- case ARG_HEIGHT:
- g_value_set_int (value, video_crop->crop_height);
+ case ARG_BOTTOM:
+ g_value_set_int (value, video_crop->crop_bottom);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -269,11 +272,7 @@ gst_video_crop_sink_connect (GstPad *pad, GstCaps *caps)
gst_caps_get_int (caps, "width", &video_crop->width);
gst_caps_get_int (caps, "height", &video_crop->height);
-
- if (video_crop->crop_width + video_crop->crop_x > video_crop->width)
- video_crop->crop_width = video_crop->width - video_crop->crop_x;
- if (video_crop->crop_height + video_crop->crop_y > video_crop->height)
- video_crop->crop_height = video_crop->height - video_crop->crop_y;
+ gst_caps_get_float (caps, "framerate", &video_crop->fps);
return GST_PAD_LINK_OK;
}
@@ -283,44 +282,48 @@ gst_video_crop_i420 (GstVideoCrop *video_crop, GstBuffer *src_buffer, GstBuffer
{
guint8 *srcY, *srcU, *srcV;
guint8 *destY, *destU, *destV;
- gint width = video_crop->crop_width;
- gint crop_height = video_crop->crop_height;
+ gint out_width = video_crop->width -
+ (video_crop->crop_left + video_crop->crop_right);
+ gint out_height = video_crop->height -
+ (video_crop->crop_top + video_crop->crop_bottom);
gint src_stride = video_crop->width;
- gint frame_size = video_crop->width * video_crop->height;
+ gint src_size = video_crop->width * video_crop->height;
gint j;
- srcY = GST_BUFFER_DATA (src_buffer) + (src_stride * video_crop->crop_y + video_crop->crop_x);
+ srcY = GST_BUFFER_DATA (src_buffer) +
+ (src_stride * video_crop->crop_top + video_crop->crop_left);
destY = GST_BUFFER_DATA (dest_buffer);
/* copy Y plane first */
- for (j = crop_height; j; j--) {
- memcpy (destY, srcY, width);
+ for (j = 0; j < out_height; j++) {
+ memcpy (destY, srcY, out_width);
srcY += src_stride;
- destY += width;
+ destY += out_width;
}
- width >>= 1;
+ out_width >>= 1;
src_stride >>= 1;
- crop_height >>= 1;
+ out_height >>= 1;
destU = destY;
- destV = destU + ((video_crop->crop_width * crop_height) >> 1);
+ destV = destU + ((out_width * out_height) >> 1);
- srcU = GST_BUFFER_DATA (src_buffer) + frame_size + ((src_stride * video_crop->crop_y + video_crop->crop_x) >> 1);
- srcV = srcU + (frame_size >> 2);
+ srcU = GST_BUFFER_DATA (src_buffer) + src_size +
+ ((src_stride * video_crop->crop_top + video_crop->crop_left) >> 1);
+ srcV = srcU + (src_size >> 2);
/* copy U plane */
- for (j = crop_height; j; j--) {
- memcpy (destU, srcU, width);
+ for (j = 0; j < out_height; j++) {
+ memcpy (destU, srcU, out_width);
srcU += src_stride;
- destU += width;
+ destU += out_width;
}
/* copy U plane */
- for (j = crop_height; j; j--) {
- memcpy (destV, srcV, width);
+ for (j = 0; j < out_height; j++) {
+ memcpy (destV, srcV, out_width);
srcV += src_stride;
- destV += width;
+ destV += out_width;
}
}
@@ -329,6 +332,7 @@ gst_video_crop_chain (GstPad *pad, GstBuffer *buffer)
{
GstVideoCrop *video_crop;
GstBuffer *outbuf;
+ gint new_width, new_height;
video_crop = GST_VIDEO_CROP (gst_pad_get_parent (pad));
@@ -343,14 +347,20 @@ gst_video_crop_chain (GstPad *pad, GstBuffer *buffer)
return;
}
+ new_width = video_crop->width -
+ (video_crop->crop_left + video_crop->crop_right);
+ new_height = video_crop->height -
+ (video_crop->crop_top + video_crop->crop_bottom);
+
if (GST_PAD_CAPS (video_crop->srcpad) == NULL) {
if (gst_pad_try_set_caps (video_crop->srcpad,
GST_CAPS_NEW (
"video_crop_caps",
"video/raw",
"format", GST_PROPS_FOURCC (GST_STR_FOURCC ("I420")),
- "width", GST_PROPS_INT (video_crop->crop_width),
- "height", GST_PROPS_INT (video_crop->crop_height)
+ "width", GST_PROPS_INT (new_width),
+ "height", GST_PROPS_INT (new_height),
+ "framerate", GST_PROPS_FLOAT (video_crop->fps)
)) <= 0)
{
gst_element_error (GST_ELEMENT (video_crop), "could not negotiate pads");
@@ -358,7 +368,7 @@ gst_video_crop_chain (GstPad *pad, GstBuffer *buffer)
}
}
- outbuf = gst_buffer_new_and_alloc ((video_crop->crop_width * video_crop->crop_height * 3) / 2);
+ outbuf = gst_buffer_new_and_alloc ((new_width * new_height * 3) / 2);
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buffer);
gst_video_crop_i420 (video_crop, buffer, outbuf);