aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'src/gstdsp66videokernel.c')
-rw-r--r--src/gstdsp66videokernel.c251
1 files changed, 251 insertions, 0 deletions
diff --git a/src/gstdsp66videokernel.c b/src/gstdsp66videokernel.c
new file mode 100644
index 0000000..b273e4b
--- /dev/null
+++ b/src/gstdsp66videokernel.c
@@ -0,0 +1,251 @@
1/* GStreamer
2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#ifdef HAVE_CONFIG_H
21#include "config.h"
22#endif
23#include <string.h>
24#include "gstdsp66videokernel.h"
25
26static GstStaticPadTemplate dsp66_video_kernel_src_factory =
27GST_STATIC_PAD_TEMPLATE ("src",
28 GST_PAD_SRC,
29 GST_PAD_ALWAYS,
30 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ I420, YV12 }"))
31 );
32
33static GstStaticPadTemplate dsp66_video_kernel_sink_factory =
34GST_STATIC_PAD_TEMPLATE ("sink",
35 GST_PAD_SINK,
36 GST_PAD_ALWAYS,
37 GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("{ I420, YV12 }"))
38 );
39
40/* Kernel signals and args */
41enum
42{
43 /* FILL ME */
44 LAST_SIGNAL
45};
46
47#define DEFAULT_FILTERSIZE 5
48#define DEFAULT_LUM_ONLY TRUE
49#define DEFAULT_KERNELTYPE GST_DSP66_VIDEO_KERNELTYPE_MEDIAN
50enum
51{
52 PROP_0,
53 PROP_FILTERSIZE,
54 PROP_LUM_ONLY,
55 PROP_KERNELTYPE
56};
57
58#define GST_TYPE_VIDEO_KERNEL_SIZE (gst_dsp66_video_kernel_size_get_type())
59#define GST_TYPE_VIDEO_KERNELTYPE_SIZE (gst_dsp66_video_kerneltype_size_get_type())
60
61static const GEnumValue dsp66_video_kernel_sizes[] = {
62 {GST_DSP66_VIDEO_KERNEL_SIZE_5, "Kernel of 5 neighbour pixels", "5"},
63 {GST_DSP66_VIDEO_KERNEL_SIZE_9, "Kernel of 9 neighbour pixels", "9"},
64 {0, NULL, NULL},
65};
66static const GEnumValue dsp66_video_kerneltype_sizes[] = {
67 {GST_DSP66_VIDEO_KERNELTYPE_MEDIAN, "Kernel median", "0"},
68 {GST_DSP66_VIDEO_KERNELTYPE_SOBEL, "Kernel sobel", "1"},
69 {0, NULL, NULL},
70};
71
72static GType
73gst_dsp66_video_kernel_size_get_type (void)
74{
75 static GType dsp66_video_kernel_size_type = 0;
76
77 if (!dsp66_video_kernel_size_type) {
78 dsp66_video_kernel_size_type = g_enum_register_static ("GstDsp66VideoKernelSize",
79 dsp66_video_kernel_sizes);
80 }
81 return dsp66_video_kernel_size_type;
82}
83
84static GType
85gst_dsp66_video_kerneltype_size_get_type (void)
86{
87 static GType dsp66_video_kerneltype_size_type = 0;
88
89 if (!dsp66_video_kerneltype_size_type) {
90 dsp66_video_kerneltype_size_type = g_enum_register_static ("GstDsp66VideoKernelTypeSize",
91 dsp66_video_kerneltype_sizes);
92 }
93 return dsp66_video_kerneltype_size_type;
94}
95
96#define gst_dsp66_video_kernel_parent_class parent_class
97G_DEFINE_TYPE (GstDsp66VideoKernel, gst_dsp66_video_kernel, GST_TYPE_VIDEO_FILTER);
98
99static GstFlowReturn gst_dsp66_video_kernel_transform_frame (GstVideoFilter * filter,
100 GstVideoFrame * in_frame, GstVideoFrame * out_frame);
101
102static void gst_dsp66_video_kernel_set_property (GObject * object, guint prop_id,
103 const GValue * value, GParamSpec * pspec);
104static void gst_dsp66_video_kernel_get_property (GObject * object, guint prop_id,
105 GValue * value, GParamSpec * pspec);
106
107static void
108gst_dsp66_video_kernel_class_init (GstDsp66VideoKernelClass * klass)
109{
110 GObjectClass *gobject_class;
111 GstElementClass *gstelement_class;
112 GstVideoFilterClass *vfilter_class;
113
114 gobject_class = (GObjectClass *) klass;
115 gstelement_class = (GstElementClass *) klass;
116 vfilter_class = (GstVideoFilterClass *) klass;
117
118 gobject_class->set_property = gst_dsp66_video_kernel_set_property;
119 gobject_class->get_property = gst_dsp66_video_kernel_get_property;
120
121 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_FILTERSIZE,
122 g_param_spec_enum ("filtersize", "Filtersize", "The size of the filter (5 or 9)",
123 GST_TYPE_VIDEO_KERNEL_SIZE, DEFAULT_FILTERSIZE,
124 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
125
126 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_KERNELTYPE,
127 g_param_spec_enum ("kerneltype", "Kerneltype", "Type of kernel (0=median, 1=sobel)",
128 GST_TYPE_VIDEO_KERNELTYPE_SIZE, DEFAULT_KERNELTYPE,
129 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
130
131 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_LUM_ONLY,
132 g_param_spec_boolean ("lum-only", "Lum Only", "Only apply filter on "
133 "luminance", DEFAULT_LUM_ONLY,
134 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
135
136 gst_element_class_add_pad_template (gstelement_class,
137 gst_static_pad_template_get (&dsp66_video_kernel_sink_factory));
138 gst_element_class_add_pad_template (gstelement_class,
139 gst_static_pad_template_get (&dsp66_video_kernel_src_factory));
140 gst_element_class_set_static_metadata (gstelement_class, "Video kernels (choose: kerneltype, filtersize, lum-only)",
141 "Video Kernel",
142 "Apply a kernel via DSP C66 offload to an image",
143 "based on work by: Wim Taymans <wim.taymans@gmail.com>");
144
145 vfilter_class->transform_frame =
146 GST_DEBUG_FUNCPTR (gst_dsp66_video_kernel_transform_frame);
147}
148
149void
150gst_dsp66_video_kernel_init (GstDsp66VideoKernel * kernel)
151{
152 kernel->filtersize = DEFAULT_FILTERSIZE;
153 kernel->kerneltype = DEFAULT_KERNELTYPE;
154 kernel->lum_only = DEFAULT_LUM_ONLY;
155}
156
157extern int oclconv_kernel(int kernel_type, int kernel_size, unsigned char *src, unsigned char *dest, int width, int height, int sstride, int dstride);
158
159static int
160imgproc (gint kerneltype, gint filtersize,
161 guint8 * dest, gint dstride,
162 const guint8 * src, gint sstride,
163 gint width, gint height)
164{
165 return oclconv_kernel(kerneltype, filtersize, (unsigned char *)src, (unsigned char *)dest, width, height, sstride, dstride);
166}
167
168static GstFlowReturn
169gst_dsp66_video_kernel_transform_frame (GstVideoFilter * filter,
170 GstVideoFrame * in_frame, GstVideoFrame * out_frame)
171{
172 GstDsp66VideoKernel *kernel = GST_DSP66_VIDEO_KERNEL (filter);
173
174 if(imgproc (kernel->kerneltype, kernel->filtersize,
175 GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0),
176 GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 0),
177 GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0),
178 GST_VIDEO_FRAME_PLANE_STRIDE (in_frame, 0),
179 GST_VIDEO_FRAME_WIDTH (in_frame), GST_VIDEO_FRAME_HEIGHT (in_frame)) < 0)
180 {
181 gst_video_frame_copy_plane (out_frame, in_frame, 0);
182 gst_video_frame_copy_plane (out_frame, in_frame, 1);
183 gst_video_frame_copy_plane (out_frame, in_frame, 2);
184 }
185 if (kernel->lum_only) {
186 gst_video_frame_copy_plane (out_frame, in_frame, 1);
187 gst_video_frame_copy_plane (out_frame, in_frame, 2);
188 } else {
189 imgproc (kernel->kerneltype, kernel->filtersize,
190 GST_VIDEO_FRAME_PLANE_DATA (out_frame, 1),
191 GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 1),
192 GST_VIDEO_FRAME_PLANE_DATA (in_frame, 1),
193 GST_VIDEO_FRAME_PLANE_STRIDE (in_frame, 1),
194 GST_VIDEO_FRAME_WIDTH (in_frame) / 2,
195 GST_VIDEO_FRAME_HEIGHT (in_frame) / 2);
196 imgproc (kernel->kerneltype, kernel->filtersize,
197 GST_VIDEO_FRAME_PLANE_DATA (out_frame, 2),
198 GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 2),
199 GST_VIDEO_FRAME_PLANE_DATA (in_frame, 2),
200 GST_VIDEO_FRAME_PLANE_STRIDE (in_frame, 2),
201 GST_VIDEO_FRAME_WIDTH (in_frame) / 2,
202 GST_VIDEO_FRAME_HEIGHT (in_frame) / 2);
203 }
204
205 return GST_FLOW_OK;
206}
207
208static void
209gst_dsp66_video_kernel_set_property (GObject * object, guint prop_id,
210 const GValue * value, GParamSpec * pspec)
211{
212 GstDsp66VideoKernel *kernel;
213
214 kernel = GST_DSP66_VIDEO_KERNEL (object);
215
216 switch (prop_id) {
217 case PROP_FILTERSIZE:
218 kernel->filtersize = g_value_get_enum (value);
219 break;
220 case PROP_LUM_ONLY:
221 kernel->lum_only = g_value_get_boolean (value);
222 break;
223 case PROP_KERNELTYPE:
224 kernel->kerneltype = g_value_get_enum (value);
225 break;
226 default:
227 break;
228 }
229}
230
231static void
232gst_dsp66_video_kernel_get_property (GObject * object, guint prop_id, GValue * value,
233 GParamSpec * pspec)
234{
235 GstDsp66VideoKernel *kernel;
236
237 kernel = GST_DSP66_VIDEO_KERNEL (object);
238
239 switch (prop_id) {
240 case PROP_FILTERSIZE:
241 g_value_set_enum (value, kernel->filtersize);
242 break;
243 case PROP_LUM_ONLY:
244 g_value_set_boolean (value, kernel->lum_only);
245 break;
246 default:
247 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
248 break;
249 }
250}
251/** nothing past this point **/