static GstFlowReturn gst_video_median_transform_frame (GstVideoFilter * filter, GstVideoFrame * in_frame, GstVideoFrame * out_frame) { GstVideoMedian *median = GST_VIDEO_MEDIAN (filter); if (median->filtersize == 5) { median_5 (GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0), GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 0), GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0), GST_VIDEO_FRAME_PLANE_STRIDE (in_frame, 0), GST_VIDEO_FRAME_WIDTH (in_frame), GST_VIDEO_FRAME_HEIGHT (in_frame)); if (median->lum_only) { gst_video_frame_copy_plane (out_frame, in_frame, 1); gst_video_frame_copy_plane (out_frame, in_frame, 2); } else { median_5 (GST_VIDEO_FRAME_PLANE_DATA (out_frame, 1), GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 1), GST_VIDEO_FRAME_PLANE_DATA (in_frame, 1), GST_VIDEO_FRAME_PLANE_STRIDE (in_frame, 1), GST_VIDEO_FRAME_WIDTH (in_frame) / 2, GST_VIDEO_FRAME_HEIGHT (in_frame) / 2); median_5 (GST_VIDEO_FRAME_PLANE_DATA (out_frame, 2), GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 2), GST_VIDEO_FRAME_PLANE_DATA (in_frame, 2), GST_VIDEO_FRAME_PLANE_STRIDE (in_frame, 2), GST_VIDEO_FRAME_WIDTH (in_frame) / 2, GST_VIDEO_FRAME_HEIGHT (in_frame) / 2); } } else { median_9 (GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0), GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 0), GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0), GST_VIDEO_FRAME_PLANE_STRIDE (in_frame, 0), GST_VIDEO_FRAME_WIDTH (in_frame), GST_VIDEO_FRAME_HEIGHT (in_frame)); if (median->lum_only) { gst_video_frame_copy_plane (out_frame, in_frame, 1); gst_video_frame_copy_plane (out_frame, in_frame, 2); } else { median_9 (GST_VIDEO_FRAME_PLANE_DATA (out_frame, 1), GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 1), GST_VIDEO_FRAME_PLANE_DATA (in_frame, 1), GST_VIDEO_FRAME_PLANE_STRIDE (in_frame, 1), GST_VIDEO_FRAME_WIDTH (in_frame) / 2, GST_VIDEO_FRAME_HEIGHT (in_frame) / 2); median_9 (GST_VIDEO_FRAME_PLANE_DATA (out_frame, 2), GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 2), GST_VIDEO_FRAME_PLANE_DATA (in_frame, 2), GST_VIDEO_FRAME_PLANE_STRIDE (in_frame, 2), GST_VIDEO_FRAME_WIDTH (in_frame) / 2, GST_VIDEO_FRAME_HEIGHT (in_frame) / 2); } } return GST_FLOW_OK; }
static void gst_median_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstMedian *median; guchar *data; gulong size; GstBuffer *outbuf; /* GstMeta *meta; */ int lumsize, chromsize; g_return_if_fail (pad != NULL); g_return_if_fail (GST_IS_PAD (pad)); g_return_if_fail (buf != NULL); median = GST_MEDIAN (GST_OBJECT_PARENT (pad)); if (!median->active) { gst_pad_push (median->srcpad, GST_DATA (buf)); return; } data = GST_BUFFER_DATA (buf); size = GST_BUFFER_SIZE (buf); GST_DEBUG ("median: have buffer of %d", GST_BUFFER_SIZE (buf)); outbuf = gst_buffer_new (); GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (buf)); GST_BUFFER_SIZE (outbuf) = GST_BUFFER_SIZE (buf); lumsize = median->width * median->height; chromsize = lumsize / 4; if (median->filtersize == 5) { median_5 (data, GST_BUFFER_DATA (outbuf), median->width, median->height); if (!median->lum_only) { median_5 (data + lumsize, GST_BUFFER_DATA (outbuf) + lumsize, median->width / 2, median->height / 2); median_5 (data + lumsize + chromsize, GST_BUFFER_DATA (outbuf) + lumsize + chromsize, median->width / 2, median->height / 2); } else { memcpy (GST_BUFFER_DATA (outbuf) + lumsize, data + lumsize, chromsize * 2); } } else { median_9 (data, GST_BUFFER_DATA (outbuf), median->width, median->height); if (!median->lum_only) { median_9 (data + lumsize, GST_BUFFER_DATA (outbuf) + lumsize, median->width / 2, median->height / 2); median_9 (data + lumsize + chromsize, GST_BUFFER_DATA (outbuf) + lumsize + chromsize, median->width / 2, median->height / 2); } else { memcpy (GST_BUFFER_DATA (outbuf) + lumsize, data + lumsize, chromsize * 2); } } GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf); gst_buffer_unref (buf); gst_pad_push (median->srcpad, GST_DATA (outbuf)); }