예제 #1
0
static gboolean
process (GeglOperation       *operation,
         GeglBuffer          *input,
         GeglBuffer          *output,
         const GeglRectangle *result,
         gint                 level)
{
  GeglProperties          *o       = GEGL_PROPERTIES (operation);
  GeglOperationAreaFilter *op_area = GEGL_OPERATION_AREA_FILTER (operation);
  const Babl              *format  = babl_format ("RGBA float");
  GeglRectangle            rect;
  gfloat                  *src_buf;
  gfloat                  *dst_buf;
  gdouble                **matrix;
  gdouble                  matrixsum = 0.0;
  gint                     x, y;

  matrix = g_new0 (gdouble *, MATRIX_SIZE);

  for (x = 0; x < MATRIX_SIZE ;x++)
    matrix[x] = g_new0 (gdouble, MATRIX_SIZE);

  make_matrix (o, matrix);

  if (o->normalize)
    normalize_o (o, matrix);

  for (x = 0; x < MATRIX_SIZE; x++)
    for (y = 0; y < MATRIX_SIZE; y++)
      matrixsum += fabs (matrix[x][y]);

  rect.x      = result->x - op_area->left;
  rect.width  = result->width + op_area->left + op_area->right;
  rect.y      = result->y - op_area->top;
  rect.height = result->height + op_area->top + op_area->bottom;

  src_buf = g_new0 (gfloat, rect.width * rect.height * 4);
  dst_buf = g_new0 (gfloat, result->width * result->height * 4);

  gegl_buffer_get (input, &rect, 1.0, format, src_buf,
                   GEGL_AUTO_ROWSTRIDE, o->border);

  if (o->divisor != 0)
    {
      for (y = result->y; y < result->height + result->y; y++)
        for (x = result->x; x < result->width + result->x; x++)
          convolve_pixel (o, src_buf, dst_buf, result, &rect,
                          matrix, x, y, matrixsum);

      gegl_buffer_set (output, result, 0, format,
                       dst_buf, GEGL_AUTO_ROWSTRIDE);
    }
  else
    {
      gegl_buffer_set (output, &rect, 0, format,
                       src_buf, GEGL_AUTO_ROWSTRIDE);
    }

  g_free (src_buf);
  g_free (dst_buf);

  return TRUE;
}
예제 #2
0
static gboolean
process (GeglOperation       *operation,
         GeglBuffer          *input,
         GeglBuffer          *output,
         const GeglRectangle *result,
         gint                 level)
{
  GeglChantO              *o       = GEGL_CHANT_PROPERTIES (operation);
  GeglOperationAreaFilter *op_area = GEGL_OPERATION_AREA_FILTER (operation);

  GeglRectangle   rect;
  GeglRectangle   boundary = get_effective_area (operation);
  gfloat         *src_buf;
  gfloat         *dst_buf;
  gdouble       **matrix;

  gchar         *type;
  gint           x, y;
  gdouble        matrixsum = 0.0;

  type = "RGBA float";

  matrix = g_new0 (gdouble*, MATRIX_SIZE);

  for (x=0; x < MATRIX_SIZE ;x++)
    matrix[x] = g_new0 (gdouble, MATRIX_SIZE);

  make_matrix (o, matrix);

  if (o->norm)
    normalize_o (o, matrix);

  for (x=0; x < MATRIX_SIZE; x++)
    for (y=0; y < MATRIX_SIZE; y++)
      matrixsum += fabs (matrix[x][y]);

  rect.x      = result->x - op_area->left;
  rect.width  = result->width + op_area->left + op_area->right;
  rect.y      = result->y - op_area->top;
  rect.height = result->height + op_area->top + op_area->bottom;

  src_buf = g_new0 (gfloat, rect.width * rect.height * 4);
  dst_buf = g_new0 (gfloat, result->width * result->height * 4);

  gegl_buffer_get (input, &rect, 1.0, babl_format (type), src_buf,
                   GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);

  /*fill src_buf with wrap pixels if it is the case*/

  if (o->div != 0)
    {
      for (y=result->y; y < result->height + result->y; y++)
        for (x=result->x; x < result->width + result->x; x++)
          convolve_pixel (src_buf, dst_buf, result, &rect, &boundary,
                          matrix, o, input, x, y, matrixsum);

      gegl_buffer_set (output, result, 0, babl_format (type),
                       dst_buf, GEGL_AUTO_ROWSTRIDE);
    }
  else
    gegl_buffer_set (output, &rect, 0, babl_format (type),
                     src_buf, GEGL_AUTO_ROWSTRIDE);



  g_free (src_buf);
  g_free (dst_buf);

  return TRUE;
}