|
@@ -0,0 +1,192 @@
|
|
|
+#include <gmodule.h>
|
|
|
+#ifdef __APPLE__
|
|
|
+#include <OpenCL/cl.h>
|
|
|
+#else
|
|
|
+#include <CL/cl.h>
|
|
|
+#endif
|
|
|
+
|
|
|
+#include <ufo/ufo-resource-manager.h>
|
|
|
+#include <ufo/ufo-filter.h>
|
|
|
+#include <ufo/ufo-buffer.h>
|
|
|
+#include "ufo-filter-lamino-ft-conv.h"
|
|
|
+
|
|
|
+/**
|
|
|
+ * SECTION:ufo-filter-lamino-f-t-conv
|
|
|
+ * @Short_description:
|
|
|
+ * @Title: laminoftconv
|
|
|
+ *
|
|
|
+ * Detailed description.
|
|
|
+ */
|
|
|
+
|
|
|
+struct _UfoFilterLaminoFTConvPrivate {
|
|
|
+ // float example;
|
|
|
+ cl_kernel kernel;
|
|
|
+};
|
|
|
+
|
|
|
+G_DEFINE_TYPE(UfoFilterLaminoFTConv, ufo_filter_lamino_ft_conv, UFO_TYPE_FILTER)
|
|
|
+
|
|
|
+#define UFO_FILTER_LAMINO_FT_CONV_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), UFO_TYPE_FILTER_LAMINO_FT_CONV, UfoFilterLaminoFTConvPrivate))
|
|
|
+
|
|
|
+enum {
|
|
|
+ PROP_0,
|
|
|
+// PROP_EXAMPLE,
|
|
|
+ N_PROPERTIES
|
|
|
+};
|
|
|
+
|
|
|
+// static GParamSpec *lamino_ft_conv_properties[N_PROPERTIES] = { NULL, };
|
|
|
+
|
|
|
+
|
|
|
+static void ufo_filter_lamino_ft_conv_initialize(UfoFilter *filter)
|
|
|
+{
|
|
|
+
|
|
|
+ UfoFilterLaminoFTConv *self = UFO_FILTER_LAMINO_FT_CONV(filter);
|
|
|
+ UfoResourceManager *manager = ufo_resource_manager();
|
|
|
+ GError *error = NULL;
|
|
|
+ self->priv->kernel = ufo_resource_manager_get_kernel(manager, "lamino_ft_conv.cl", "lamino_c", &error);
|
|
|
+
|
|
|
+
|
|
|
+ if (error != NULL) {
|
|
|
+ g_warning("%s", error->message);
|
|
|
+ g_error_free(error);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+static void ufo_filter_lamino_ft_conv_process(UfoFilter *flt)
|
|
|
+{
|
|
|
+
|
|
|
+ g_return_if_fail(UFO_IS_FILTER(flt));
|
|
|
+ UfoFilterLaminoFTConv *self = UFO_FILTER_LAMINO_FT_CONV(flt);
|
|
|
+
|
|
|
+
|
|
|
+ UfoChannel *input_channel = ufo_filter_get_input_channel_by_name(flt, "image");
|
|
|
+ UfoChannel *filter_channel = ufo_filter_get_input_channel_by_name(flt, "filter");
|
|
|
+ UfoChannel *output_channel = ufo_filter_get_output_channel(flt);
|
|
|
+ cl_command_queue command_queue = (cl_command_queue) ufo_filter_get_command_queue(flt);
|
|
|
+
|
|
|
+ UfoBuffer *input = ufo_channel_get_input_buffer(input_channel);
|
|
|
+ UfoBuffer *filter = ufo_channel_get_input_buffer(filter_channel);
|
|
|
+
|
|
|
+ guint num_dims = 0;
|
|
|
+ guint *dim_size = NULL;
|
|
|
+ ufo_buffer_get_dimensions(input, &num_dims, &dim_size);
|
|
|
+ ufo_channel_allocate_output_buffers(output_channel, 2, dim_size);
|
|
|
+
|
|
|
+ guint *fdim_size= NULL;
|
|
|
+ ufo_buffer_get_dimensions(input, &num_dims, &fdim_size);
|
|
|
+
|
|
|
+ if( (dim_size[0] != fdim_size[0]) || (dim_size[1] != fdim_size[1]))
|
|
|
+ g_error("Filter and image sizes are different");
|
|
|
+
|
|
|
+ size_t global_work_size[2] = { (size_t) dim_size[0], (size_t) dim_size[1] };
|
|
|
+ guint width = dim_size[0];
|
|
|
+ cl_kernel kernel = self->priv->kernel;
|
|
|
+
|
|
|
+ cl_mem filter_mem = (cl_mem) ufo_buffer_get_device_array(filter, command_queue);
|
|
|
+
|
|
|
+ while (input != NULL)
|
|
|
+ {
|
|
|
+ UfoBuffer *output = ufo_channel_get_output_buffer(output_channel);
|
|
|
+ cl_mem input_mem = (cl_mem) ufo_buffer_get_device_array(input, command_queue);
|
|
|
+ cl_mem output_mem = (cl_mem) ufo_buffer_get_device_array(output, command_queue);
|
|
|
+
|
|
|
+ CHECK_OPENCL_ERROR(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *) &input_mem));
|
|
|
+ CHECK_OPENCL_ERROR(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *) &filter_mem));
|
|
|
+ CHECK_OPENCL_ERROR(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *) &output_mem));
|
|
|
+ CHECK_OPENCL_ERROR(clSetKernelArg(kernel, 3, sizeof(int), &width));
|
|
|
+
|
|
|
+ cl_event event;
|
|
|
+ CHECK_OPENCL_ERROR(clEnqueueNDRangeKernel(command_queue, kernel,
|
|
|
+ 2, NULL, global_work_size, NULL,
|
|
|
+ 0, NULL, &event));
|
|
|
+ clFinish(command_queue);
|
|
|
+ //ufo_buffer_attach_event(output, event);
|
|
|
+
|
|
|
+
|
|
|
+ ufo_channel_finalize_input_buffer(input_channel, input);
|
|
|
+ ufo_channel_finalize_output_buffer(output_channel, output);
|
|
|
+ input = ufo_channel_get_input_buffer(input_channel);
|
|
|
+ }
|
|
|
+
|
|
|
+ ufo_channel_finalize_input_buffer(filter_channel, filter);
|
|
|
+ ufo_channel_finish(output_channel);
|
|
|
+
|
|
|
+ g_free(dim_size);
|
|
|
+ g_free(fdim_size);
|
|
|
+}
|
|
|
+
|
|
|
+static void ufo_filter_lamino_ft_conv_set_property(GObject *object,
|
|
|
+ guint property_id,
|
|
|
+ const GValue *value,
|
|
|
+ GParamSpec *pspec)
|
|
|
+{
|
|
|
+
|
|
|
+ // UfoFilterLaminoFTConv *self = UFO_FILTER_LAMINO_FT_CONV(object);
|
|
|
+
|
|
|
+ switch (property_id) {
|
|
|
+ /*case PROP_EXAMPLE:
|
|
|
+ self->priv->example = g_value_get_double(value);
|
|
|
+ break;*/
|
|
|
+ default:
|
|
|
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static void ufo_filter_lamino_ft_conv_get_property(GObject *object,
|
|
|
+ guint property_id,
|
|
|
+ GValue *value,
|
|
|
+ GParamSpec *pspec)
|
|
|
+{
|
|
|
+ // UfoFilterLaminoFTConv *self = UFO_FILTER_LAMINO_FT_CONV(object);
|
|
|
+
|
|
|
+ switch (property_id) {
|
|
|
+ /*case PROP_EXAMPLE:
|
|
|
+ g_value_set_double(value, self->priv->example);
|
|
|
+ break;*/
|
|
|
+ default:
|
|
|
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static void ufo_filter_lamino_ft_conv_class_init(UfoFilterLaminoFTConvClass *klass)
|
|
|
+{
|
|
|
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
|
|
+ UfoFilterClass *filter_class = UFO_FILTER_CLASS(klass);
|
|
|
+
|
|
|
+ gobject_class->set_property = ufo_filter_lamino_ft_conv_set_property;
|
|
|
+ gobject_class->get_property = ufo_filter_lamino_ft_conv_get_property;
|
|
|
+ filter_class->initialize = ufo_filter_lamino_ft_conv_initialize;
|
|
|
+ filter_class->process = ufo_filter_lamino_ft_conv_process;
|
|
|
+
|
|
|
+ /* lamino_ft_conv_properties[PROP_EXAMPLE] =
|
|
|
+ g_param_spec_double("example",
|
|
|
+ "This is an example property",
|
|
|
+ "You should definately replace this with some meaningful property",
|
|
|
+ -1.0,
|
|
|
+ 1.0,
|
|
|
+ 1.0,
|
|
|
+ G_PARAM_READWRITE);
|
|
|
+
|
|
|
+ g_object_class_install_property(gobject_class, PROP_EXAMPLE, lamino_ft_conv_properties[PROP_EXAMPLE]); */
|
|
|
+
|
|
|
+ g_type_class_add_private(gobject_class, sizeof(UfoFilterLaminoFTConvPrivate));
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+static void ufo_filter_lamino_ft_conv_init(UfoFilterLaminoFTConv *self)
|
|
|
+{
|
|
|
+ UfoFilterLaminoFTConvPrivate *priv = self->priv = UFO_FILTER_LAMINO_FT_CONV_GET_PRIVATE(self);
|
|
|
+ // priv->example = 1.0;
|
|
|
+ priv->kernel = NULL;
|
|
|
+
|
|
|
+ ufo_filter_register_input(UFO_FILTER(self), "filter", 2);
|
|
|
+ ufo_filter_register_input(UFO_FILTER(self), "image", 2);
|
|
|
+ ufo_filter_register_output(UFO_FILTER(self), "oimage", 2);
|
|
|
+}
|
|
|
+
|
|
|
+G_MODULE_EXPORT UfoFilter *ufo_filter_plugin_new(void)
|
|
|
+{
|
|
|
+ return g_object_new(UFO_TYPE_FILTER_LAMINO_FT_CONV, NULL);
|
|
|
+}
|