|
@@ -10,14 +10,13 @@
|
|
|
#include <ufo/ufo-resource-manager.h>
|
|
|
|
|
|
#include "ufo-filter-scale.h"
|
|
|
-int a;
|
|
|
/**
|
|
|
* SECTION:ufo-filter-scale
|
|
|
* @Short_description: Scale image values
|
|
|
* @Title: scale
|
|
|
*
|
|
|
* Scale input image values. The output
|
|
|
- * is a new image. git check
|
|
|
+ * is a new image.
|
|
|
* #UfoFilterScale: params.
|
|
|
*/
|
|
|
|
|
@@ -44,35 +43,37 @@ static GParamSpec *scale_properties[N_PROPERTIES] = { NULL, };
|
|
|
/*
|
|
|
* virtual methods
|
|
|
*/
|
|
|
-static void ufo_filter_scale_initialize(UfoFilter *filter)
|
|
|
+static void
|
|
|
+ufo_filter_scale_initialize(UfoFilter *filter, UfoBuffer *params[], guint **dim_sizes, GError **error)
|
|
|
{
|
|
|
- UfoFilterScale *self = UFO_FILTER_SCALE(filter);
|
|
|
- UfoResourceManager *manager = ufo_resource_manager();
|
|
|
- GError *error = NULL;
|
|
|
- self->priv->kernel = NULL;
|
|
|
-
|
|
|
- /*ufo_resource_manager_add_program(manager, "scale.cl", NULL, &error);
|
|
|
- if (error != NULL) {
|
|
|
- g_warning("%s", error->message);
|
|
|
- g_error_free(error);
|
|
|
- return;
|
|
|
- }*/
|
|
|
+ UfoFilterScalePrivate *priv = UFO_FILTER_SCALE_GET_PRIVATE(filter);
|
|
|
+ UfoResourceManager *manager = ufo_filter_get_resource_manager(filter);
|
|
|
+ GError *tmp_error = NULL;
|
|
|
|
|
|
- self->priv->kernel = ufo_resource_manager_get_kernel(manager, "scale.cl", "scale", &error);
|
|
|
- if (error != NULL) {
|
|
|
- g_warning("%s", error->message);
|
|
|
- g_error_free(error);
|
|
|
+ priv->kernel = ufo_resource_manager_get_kernel(manager, "scale.cl", "scale", &tmp_error);
|
|
|
+ if (tmp_error != NULL) {
|
|
|
+ g_propagate_error (error, tmp_error);
|
|
|
+ return;
|
|
|
}
|
|
|
+
|
|
|
+ guint xs, ys;
|
|
|
+ ufo_buffer_get_2d_dimensions (params[0], &xs, &ys);
|
|
|
+ dim_sizes[0][0] = xs;
|
|
|
+ dim_sizes[0][1] = ys;
|
|
|
}
|
|
|
|
|
|
-static void ufo_filter_scale_process(UfoFilter *filter)
|
|
|
+/*
|
|
|
+ * This is the main method in which the filter processes one buffer after
|
|
|
+ * another.
|
|
|
+ */
|
|
|
+static void ufo_filter_scale_process_gpu(UfoFilter *filter, UfoBuffer *input[], UfoBuffer *output[], GError **error)
|
|
|
{
|
|
|
g_return_if_fail(UFO_IS_FILTER(filter));
|
|
|
- UfoFilterScale *self = UFO_FILTER_SCALE(filter);
|
|
|
+ cl_command_queue command_queue = (cl_command_queue) ufo_filter_get_command_queue(filter);
|
|
|
+ UfoFilterScalePrivate *priv = UFO_FILTER_SCALE_GET_PRIVATE(filter);
|
|
|
|
|
|
- UfoChannel *input_channel = ufo_filter_get_input_channel(filter);
|
|
|
+ /*UfoChannel *input_channel = ufo_filter_get_input_channel(filter);
|
|
|
UfoChannel *output_channel = ufo_filter_get_output_channel(filter);
|
|
|
- cl_command_queue command_queue = (cl_command_queue) ufo_filter_get_command_queue(filter);
|
|
|
|
|
|
UfoBuffer *input = ufo_channel_get_input_buffer(input_channel);
|
|
|
|
|
@@ -84,45 +85,50 @@ static void ufo_filter_scale_process(UfoFilter *filter)
|
|
|
size_t global_work_size[2] = { (size_t) dim_size[0], (size_t) dim_size[1] };
|
|
|
int width = dim_size[0];
|
|
|
|
|
|
- float scale = (float) self->priv->scale;
|
|
|
-
|
|
|
- cl_kernel kernel = self->priv->kernel;
|
|
|
|
|
|
|
|
|
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 *) &output_mem));
|
|
|
- CHECK_OPENCL_ERROR(clSetKernelArg(kernel, 2, sizeof(int), &width));
|
|
|
- CHECK_OPENCL_ERROR(clSetKernelArg(kernel, 3, sizeof(float), &scale));
|
|
|
-
|
|
|
- cl_event event;
|
|
|
- CHECK_OPENCL_ERROR(clEnqueueNDRangeKernel(command_queue, kernel,
|
|
|
+ {*/
|
|
|
+ //UfoBuffer *output = ufo_channel_get_output_buffer(output_channel);
|
|
|
+ //
|
|
|
+ guint xs, ys;
|
|
|
+ ufo_buffer_get_2d_dimensions (input[0], &xs, &ys);
|
|
|
+ size_t global_work_size[2] = {(size_t) xs, (size_t) ys};
|
|
|
+
|
|
|
+
|
|
|
+ cl_mem input_mem = (cl_mem) ufo_buffer_get_device_array(input[0], command_queue);
|
|
|
+ cl_mem output_mem = (cl_mem) ufo_buffer_get_device_array(output[0], command_queue);
|
|
|
+
|
|
|
+ float scale = (float) priv->scale;
|
|
|
+ cl_kernel kernel = priv->kernel;
|
|
|
+
|
|
|
+ CHECK_OPENCL_ERROR(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *) &input_mem));
|
|
|
+ CHECK_OPENCL_ERROR(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *) &output_mem));
|
|
|
+ CHECK_OPENCL_ERROR(clSetKernelArg(kernel, 2, sizeof(int), &xs));
|
|
|
+ CHECK_OPENCL_ERROR(clSetKernelArg(kernel, 3, sizeof(float), &scale));
|
|
|
+
|
|
|
+ cl_event event;
|
|
|
+ CHECK_OPENCL_ERROR(clEnqueueNDRangeKernel(command_queue, kernel,
|
|
|
2, NULL, global_work_size, NULL,
|
|
|
0, NULL, &event));
|
|
|
- ufo_buffer_attach_event(output, event);
|
|
|
+ //ufo_buffer_attach_event(output, event);
|
|
|
// ufo_filter_account_gpu_time(filter, (void **) &event);
|
|
|
|
|
|
- g_message("ufo-filter-scale: processing is completed");
|
|
|
+ //g_message("ufo-filter-scale: processing is completed");
|
|
|
|
|
|
- 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(input_channel, input);
|
|
|
+ //ufo_channel_finalize_output_buffer(output_channel, output);
|
|
|
+ //input = ufo_channel_get_input_buffer(input_channel);
|
|
|
|
|
|
- }
|
|
|
+ clFinish(command_queue);
|
|
|
+ /* }
|
|
|
ufo_channel_finish(output_channel);
|
|
|
- g_free(dim_size);
|
|
|
+ g_free(dim_size);*/
|
|
|
|
|
|
}
|
|
|
|
|
|
-static void ufo_filter_scale_set_property(GObject *object,
|
|
|
- guint property_id,
|
|
|
- const GValue *value,
|
|
|
- GParamSpec *pspec)
|
|
|
+static void
|
|
|
+ufo_filter_scale_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
|
|
|
{
|
|
|
UfoFilterScale *self = UFO_FILTER_SCALE(object);
|
|
|
|
|
@@ -136,10 +142,8 @@ static void ufo_filter_scale_set_property(GObject *object,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static void ufo_filter_scale_get_property(GObject *object,
|
|
|
- guint property_id,
|
|
|
- GValue *value,
|
|
|
- GParamSpec *pspec)
|
|
|
+static void
|
|
|
+ufo_filter_scale_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
|
|
|
{
|
|
|
UfoFilterScale *self = UFO_FILTER_SCALE(object);
|
|
|
|
|
@@ -153,7 +157,8 @@ static void ufo_filter_scale_get_property(GObject *object,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static void ufo_filter_scale_class_init(UfoFilterScaleClass *klass)
|
|
|
+static void
|
|
|
+ufo_filter_scale_class_init(UfoFilterScaleClass *klass)
|
|
|
{
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
|
|
UfoFilterClass *filter_class = UFO_FILTER_CLASS(klass);
|
|
@@ -161,7 +166,7 @@ static void ufo_filter_scale_class_init(UfoFilterScaleClass *klass)
|
|
|
gobject_class->set_property = ufo_filter_scale_set_property;
|
|
|
gobject_class->get_property = ufo_filter_scale_get_property;
|
|
|
filter_class->initialize = ufo_filter_scale_initialize;
|
|
|
- filter_class->process = ufo_filter_scale_process;
|
|
|
+ filter_class->process_gpu = ufo_filter_scale_process_gpu;
|
|
|
|
|
|
scale_properties[PROP_SCALE] =
|
|
|
g_param_spec_double("scale",
|
|
@@ -178,14 +183,18 @@ static void ufo_filter_scale_class_init(UfoFilterScaleClass *klass)
|
|
|
g_type_class_add_private(gobject_class, sizeof(UfoFilterScalePrivate));
|
|
|
}
|
|
|
|
|
|
-static void ufo_filter_scale_init(UfoFilterScale *self)
|
|
|
+static void
|
|
|
+ufo_filter_scale_init(UfoFilterScale *self)
|
|
|
{
|
|
|
UfoFilterScalePrivate *priv = self->priv = UFO_FILTER_SCALE_GET_PRIVATE(self);
|
|
|
+ UfoInputParameter input_params[] = {{2, UFO_FILTER_INFINITE_INPUT}};
|
|
|
+ UfoOutputParameter output_params[] = {{2}};
|
|
|
+
|
|
|
priv->scale = 1.0;
|
|
|
priv->kernel = NULL;
|
|
|
|
|
|
- ufo_filter_register_input (UFO_FILTER(self), "image", 2);
|
|
|
- ufo_filter_register_output(UFO_FILTER(self), "image", 2);
|
|
|
+ ufo_filter_register_inputs (UFO_FILTER(self), 1, input_params);
|
|
|
+ ufo_filter_register_outputs(UFO_FILTER(self), 1, output_params);
|
|
|
}
|
|
|
|
|
|
G_MODULE_EXPORT UfoFilter *ufo_filter_plugin_new(void)
|