aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDjordje Senicic2016-03-23 06:26:53 -0500
committerDjordje Senicic2016-03-23 06:26:53 -0500
commit59640b5c07f0a57abfe157547d2db6e238390213 (patch)
treec6cabcd0ae613adafd6e8dbfdfe4a29b0e2e233c
parent40631a8b48802ded9f074876d1a947af54f6e646 (diff)
downloadgst-plugin-dsp66-59640b5c07f0a57abfe157547d2db6e238390213.tar.gz
gst-plugin-dsp66-59640b5c07f0a57abfe157547d2db6e238390213.tar.xz
gst-plugin-dsp66-59640b5c07f0a57abfe157547d2db6e238390213.zip
Add arbkernel type (user defined - as an example pointing to Sobel3x3)
-rw-r--r--src/gstdsp66videokernel.c30
-rw-r--r--src/gstdsp66videokernel.h4
-rw-r--r--src/kernels/oclconv/conv.cl5
-rw-r--r--src/kernels/oclconv/oclconv.cpp5
4 files changed, 36 insertions, 8 deletions
diff --git a/src/gstdsp66videokernel.c b/src/gstdsp66videokernel.c
index 8174710..2d7bf5d 100644
--- a/src/gstdsp66videokernel.c
+++ b/src/gstdsp66videokernel.c
@@ -47,12 +47,14 @@ enum
47#define DEFAULT_FILTERSIZE 5 47#define DEFAULT_FILTERSIZE 5
48#define DEFAULT_LUM_ONLY TRUE 48#define DEFAULT_LUM_ONLY TRUE
49#define DEFAULT_KERNELTYPE GST_DSP66_VIDEO_KERNELTYPE_MEDIAN 49#define DEFAULT_KERNELTYPE GST_DSP66_VIDEO_KERNELTYPE_MEDIAN
50#define DEFAULT_ARBKERNEL "Sobel3x3"
50enum 51enum
51{ 52{
52 PROP_0, 53 PROP_0,
53 PROP_FILTERSIZE, 54 PROP_FILTERSIZE,
54 PROP_LUM_ONLY, 55 PROP_LUM_ONLY,
55 PROP_KERNELTYPE 56 PROP_KERNELTYPE,
57 PROP_ARBKERNEL
56}; 58};
57 59
58#define GST_TYPE_VIDEO_KERNEL_FILTERSIZE (gst_dsp66_video_kernel_filtersize_get_type()) 60#define GST_TYPE_VIDEO_KERNEL_FILTERSIZE (gst_dsp66_video_kernel_filtersize_get_type())
@@ -69,6 +71,7 @@ static const GEnumValue dsp66_video_kerneltype[] = {
69 {GST_DSP66_VIDEO_KERNELTYPE_SOBEL, "Kernel sobel", "1"}, 71 {GST_DSP66_VIDEO_KERNELTYPE_SOBEL, "Kernel sobel", "1"},
70 {GST_DSP66_VIDEO_KERNELTYPE_CONV, "Kernel conv", "2"}, 72 {GST_DSP66_VIDEO_KERNELTYPE_CONV, "Kernel conv", "2"},
71 {GST_DSP66_VIDEO_KERNELTYPE_CANNY, "Kernel canny", "3"}, 73 {GST_DSP66_VIDEO_KERNELTYPE_CANNY, "Kernel canny", "3"},
74 {GST_DSP66_VIDEO_KERNELTYPE_ARB, "Kernel arbitrary", "4"},
72 {0, NULL, NULL}, 75 {0, NULL, NULL},
73}; 76};
74 77
@@ -135,6 +138,11 @@ gst_dsp66_video_kernel_class_init (GstDsp66VideoKernelClass * klass)
135 "luminance", DEFAULT_LUM_ONLY, 138 "luminance", DEFAULT_LUM_ONLY,
136 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); 139 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
137 140
141 g_object_class_install_property (gobject_class, PROP_ARBKERNEL,
142 g_param_spec_string ("arbkernel", "User defined kernel",
143 "The name of the kernel invoked via OpenCL.",
144 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
145
138 gst_element_class_add_pad_template (gstelement_class, 146 gst_element_class_add_pad_template (gstelement_class,
139 gst_static_pad_template_get (&dsp66_video_kernel_sink_factory)); 147 gst_static_pad_template_get (&dsp66_video_kernel_sink_factory));
140 gst_element_class_add_pad_template (gstelement_class, 148 gst_element_class_add_pad_template (gstelement_class,
@@ -154,17 +162,19 @@ gst_dsp66_video_kernel_init (GstDsp66VideoKernel * kernel)
154 kernel->filtersize = DEFAULT_FILTERSIZE; 162 kernel->filtersize = DEFAULT_FILTERSIZE;
155 kernel->kerneltype = DEFAULT_KERNELTYPE; 163 kernel->kerneltype = DEFAULT_KERNELTYPE;
156 kernel->lum_only = DEFAULT_LUM_ONLY; 164 kernel->lum_only = DEFAULT_LUM_ONLY;
165 kernel->arbkernel = g_strdup (DEFAULT_ARBKERNEL);
157} 166}
158 167
159extern int oclconv_kernel(int kernel_type, int kernel_size, unsigned char *src, unsigned char *dest, int width, int height, int sstride, int dstride); 168extern int oclconv_kernel(int kernel_type, int kernel_size, char *arbkernel,
169 unsigned char *src, unsigned char *dest, int width, int height, int sstride, int dstride);
160 170
161static int 171static int
162imgproc (gint kerneltype, gint filtersize, 172imgproc (gint kerneltype, gint filtersize, gchar *arbkernel,
163 guint8 * dest, gint dstride, 173 guint8 * dest, gint dstride,
164 const guint8 * src, gint sstride, 174 const guint8 * src, gint sstride,
165 gint width, gint height) 175 gint width, gint height)
166{ 176{
167 return oclconv_kernel(kerneltype, filtersize, (unsigned char *)src, (unsigned char *)dest, width, height, sstride, dstride); 177 return oclconv_kernel(kerneltype, filtersize, arbkernel, (unsigned char *)src, (unsigned char *)dest, width, height, sstride, dstride);
168} 178}
169 179
170static GstFlowReturn 180static GstFlowReturn
@@ -188,14 +198,14 @@ gst_dsp66_video_kernel_transform_frame (GstVideoFilter * filter,
188 gst_video_frame_copy_plane (out_frame, in_frame, 1); 198 gst_video_frame_copy_plane (out_frame, in_frame, 1);
189 gst_video_frame_copy_plane (out_frame, in_frame, 2); 199 gst_video_frame_copy_plane (out_frame, in_frame, 2);
190 } else { 200 } else {
191 imgproc (kernel->kerneltype, kernel->filtersize, 201 imgproc (kernel->kerneltype, kernel->filtersize, kernel->arbkernel,
192 GST_VIDEO_FRAME_PLANE_DATA (out_frame, 1), 202 GST_VIDEO_FRAME_PLANE_DATA (out_frame, 1),
193 GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 1), 203 GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 1),
194 GST_VIDEO_FRAME_PLANE_DATA (in_frame, 1), 204 GST_VIDEO_FRAME_PLANE_DATA (in_frame, 1),
195 GST_VIDEO_FRAME_PLANE_STRIDE (in_frame, 1), 205 GST_VIDEO_FRAME_PLANE_STRIDE (in_frame, 1),
196 GST_VIDEO_FRAME_WIDTH (in_frame) / 2, 206 GST_VIDEO_FRAME_WIDTH (in_frame) / 2,
197 GST_VIDEO_FRAME_HEIGHT (in_frame) / 2); 207 GST_VIDEO_FRAME_HEIGHT (in_frame) / 2);
198 imgproc (kernel->kerneltype, kernel->filtersize, 208 imgproc (kernel->kerneltype, kernel->filtersize, kernel->arbkernel,
199 GST_VIDEO_FRAME_PLANE_DATA (out_frame, 2), 209 GST_VIDEO_FRAME_PLANE_DATA (out_frame, 2),
200 GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 2), 210 GST_VIDEO_FRAME_PLANE_STRIDE (out_frame, 2),
201 GST_VIDEO_FRAME_PLANE_DATA (in_frame, 2), 211 GST_VIDEO_FRAME_PLANE_DATA (in_frame, 2),
@@ -225,6 +235,14 @@ gst_dsp66_video_kernel_set_property (GObject * object, guint prop_id,
225 case PROP_KERNELTYPE: 235 case PROP_KERNELTYPE:
226 kernel->kerneltype = g_value_get_enum (value); 236 kernel->kerneltype = g_value_get_enum (value);
227 break; 237 break;
238 case PROP_ARBKERNEL:
239 if (!g_value_get_string (value)) {
240 GST_WARNING ("Arbitrary kernel string can not be NULL");
241 break;
242 }
243 g_free (kernel->arbkernel);
244 kernel->arbkernel = g_value_dup_string (value);
245 break;
228 default: 246 default:
229 break; 247 break;
230 } 248 }
diff --git a/src/gstdsp66videokernel.h b/src/gstdsp66videokernel.h
index b78354b..017d809 100644
--- a/src/gstdsp66videokernel.h
+++ b/src/gstdsp66videokernel.h
@@ -53,7 +53,8 @@ typedef enum {
53 GST_DSP66_VIDEO_KERNELTYPE_MEDIAN = 0, 53 GST_DSP66_VIDEO_KERNELTYPE_MEDIAN = 0,
54 GST_DSP66_VIDEO_KERNELTYPE_SOBEL = 1, 54 GST_DSP66_VIDEO_KERNELTYPE_SOBEL = 1,
55 GST_DSP66_VIDEO_KERNELTYPE_CONV = 2, 55 GST_DSP66_VIDEO_KERNELTYPE_CONV = 2,
56 GST_DSP66_VIDEO_KERNELTYPE_CANNY = 3 56 GST_DSP66_VIDEO_KERNELTYPE_CANNY = 3,
57 GST_DSP66_VIDEO_KERNELTYPE_ARB = 4
57} GstDsp66VideoKernelType; 58} GstDsp66VideoKernelType;
58 59
59struct _GstDsp66VideoKernel { 60struct _GstDsp66VideoKernel {
@@ -61,6 +62,7 @@ struct _GstDsp66VideoKernel {
61 GstDsp66VideoKernelFilterSize filtersize; 62 GstDsp66VideoKernelFilterSize filtersize;
62 GstDsp66VideoKernelType kerneltype; 63 GstDsp66VideoKernelType kerneltype;
63 gboolean lum_only; 64 gboolean lum_only;
65 gchar *arbkernel;
64}; 66};
65 67
66struct _GstDsp66VideoKernelClass { 68struct _GstDsp66VideoKernelClass {
diff --git a/src/kernels/oclconv/conv.cl b/src/kernels/oclconv/conv.cl
index dab866e..815b5ff 100644
--- a/src/kernels/oclconv/conv.cl
+++ b/src/kernels/oclconv/conv.cl
@@ -27,7 +27,12 @@
27 *****************************************************************************/ 27 *****************************************************************************/
28#define PIX_SORT(a,b) { if ((a)>(b)) PIX_SWAP((a),(b)); } 28#define PIX_SORT(a,b) { if ((a)>(b)) PIX_SWAP((a),(b)); }
29#define PIX_SWAP(a,b) { unsigned char temp=(a);(a)=(b);(b)=temp; } 29#define PIX_SWAP(a,b) { unsigned char temp=(a);(a)=(b);(b)=temp; }
30#define ARGS global uchar *pInput, global ushort *pBufGradX, \
31 global ushort *pBufGradY, global ushort *pBufMag, \
32 global uchar *pBufOut, global uchar *pScratch, \
33 global uint *numItems, ushort width, ushort height
30 34
35/* imglib library functions */
31void IMG_median_3x3_8 (const unsigned char *restrict in_data, int cols, unsigned char * restrict out_data); 36void IMG_median_3x3_8 (const unsigned char *restrict in_data, int cols, unsigned char * restrict out_data);
32void IMG_sobel_3x3_8 (const unsigned char *restrict in_data, unsigned char *restrict out_data, int rows, int cols); 37void IMG_sobel_3x3_8 (const unsigned char *restrict in_data, unsigned char *restrict out_data, int rows, int cols);
33void IMG_conv_3x3_i8_c8s (const unsigned char *restrict in_data, unsigned char *restrict out_data, int cols, const char *restrict mask, int shift); 38void IMG_conv_3x3_i8_c8s (const unsigned char *restrict in_data, unsigned char *restrict out_data, int cols, const char *restrict mask, int shift);
diff --git a/src/kernels/oclconv/oclconv.cpp b/src/kernels/oclconv/oclconv.cpp
index 00ef898..ed6a17d 100644
--- a/src/kernels/oclconv/oclconv.cpp
+++ b/src/kernels/oclconv/oclconv.cpp
@@ -165,7 +165,7 @@ static int ocl_canny(unsigned char *data_in, unsigned char *data_out, unsigned s
165#ifdef __cplusplus 165#ifdef __cplusplus
166extern "C" { 166extern "C" {
167#endif 167#endif
168int oclconv_kernel(int kernel_type, int filter_size, 168int oclconv_kernel(int kernel_type, int filter_size, char *arbkernel,
169 unsigned char *data_in, unsigned char *data_out, 169 unsigned char *data_in, unsigned char *data_out,
170 int width, int height, int dstride, int sstride) 170 int width, int height, int dstride, int sstride)
171{ 171{
@@ -194,6 +194,9 @@ int oclconv_kernel(int kernel_type, int filter_size,
194 /* filter size is ignored */ 194 /* filter size is ignored */
195 retval = ocl_canny (data_in, data_out, width, height); /* input and output stride assumed to be == width */ 195 retval = ocl_canny (data_in, data_out, width, height); /* input and output stride assumed to be == width */
196 break; 196 break;
197 case 4: /* user defined kernel */
198 retval = oclconv_imgproc (arbkernel, data_in, data_out, width, height, sstride, dstride);
199 break;
197 default: 200 default:
198 break; 201 break;
199 } 202 }