static gboolean process (GeglOperation *operation, GeglBuffer *input, GeglBuffer *output, const GeglRectangle *result, gint level) { GeglChantO *o = GEGL_CHANT_PROPERTIES (operation); GeglRectangle compute; gboolean has_alpha; compute = gegl_operation_get_required_for_output (operation, "input", result); has_alpha = babl_format_has_alpha (gegl_operation_get_format (operation, "output")); if (gegl_operation_use_opencl (operation)) if (cl_process (operation, input, output, result, has_alpha)) return TRUE; edge_sobel (input, &compute, output, result, o->horizontal, o->vertical, o->keep_signal, has_alpha); return TRUE; }
static gboolean process (GeglOperation *operation, GeglBuffer *input, GeglBuffer *output, const GeglRectangle *roi, gint level) { GeglProperties *o = GEGL_PROPERTIES (operation); const Babl *format = gegl_operation_get_format (operation, "output"); gint components = babl_format_get_n_components (format); gboolean has_alpha = babl_format_has_alpha (format); gfloat *src_buff; gfloat *dst_buff; GeglRectangle rect; gint x, y, ix, iy, b, idx; rect = gegl_operation_get_required_for_output (operation, "input", roi); src_buff = g_new (gfloat, rect.width * rect.height * components); dst_buff = g_new0 (gfloat, roi->width * roi->height * components); gegl_buffer_get (input, &rect, 1.0, format, src_buff, GEGL_AUTO_ROWSTRIDE, o->border_behavior); for (y = 0; y < roi->height; y++) { iy = y + 1; for (x = 0; x < roi->width; x++) { ix = x + 1; for (b = 0; b < 3; b++) { #define SRCPIX(X,Y,B) src_buff[((X) + (Y) * rect.width) * components + B] gfloat window[9]; window[0] = SRCPIX(ix - 1, iy - 1, b); window[1] = SRCPIX(ix, iy - 1, b); window[2] = SRCPIX(ix + 1, iy - 1, b); window[3] = SRCPIX(ix - 1, iy, b); window[4] = SRCPIX(ix, iy, b); window[5] = SRCPIX(ix + 1, iy, b); window[6] = SRCPIX(ix - 1, iy + 1, b); window[7] = SRCPIX(ix, iy + 1, b); window[8] = SRCPIX(ix + 1, iy + 1, b); idx = (x + y * roi->width) * components + b; switch (o->algorithm) { default: case GEGL_EDGE_SOBEL: dst_buff[idx] = edge_sobel (window, o->amount); break; case GEGL_EDGE_PREWITT: dst_buff[idx] = edge_prewitt (window, o->amount); break; case GEGL_EDGE_GRADIENT: dst_buff[idx] = edge_gradient (window, o->amount); break; case GEGL_EDGE_ROBERTS: dst_buff[idx] = edge_roberts (window, o->amount); break; case GEGL_EDGE_DIFFERENTIAL: dst_buff[idx] = edge_differential (window, o->amount); break; case GEGL_EDGE_LAPLACE: dst_buff[idx] = edge_laplace (window, o->amount); break; } } if (has_alpha) dst_buff[idx + 1] = SRCPIX(ix, iy, 3); } #undef SRCPIX } gegl_buffer_set (output, roi, level, format, dst_buff, GEGL_AUTO_ROWSTRIDE); g_free (src_buff); g_free (dst_buff); return TRUE; }