Blame gegl/operation/gegl-operation-point-composer3.c

Packit bc1512
/* This file is part of GEGL
Packit bc1512
 *
Packit bc1512
 * GEGL is free software; you can redistribute it and/or
Packit bc1512
 * modify it under the terms of the GNU Lesser General Public
Packit bc1512
 * License as published by the Free Software Foundation; either
Packit bc1512
 * version 3 of the License, or (at your option) any later version.
Packit bc1512
 *
Packit bc1512
 * GEGL is distributed in the hope that it will be useful,
Packit bc1512
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit bc1512
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit bc1512
 * Lesser General Public License for more details.
Packit bc1512
 *
Packit bc1512
 * You should have received a copy of the GNU Lesser General Public
Packit bc1512
 * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
Packit bc1512
 *
Packit bc1512
 * Copyright 2006 Øyvind Kolås
Packit bc1512
 */
Packit bc1512
Packit bc1512
Packit bc1512
#include "config.h"
Packit bc1512
Packit bc1512
#include <glib-object.h>
Packit bc1512
Packit bc1512
#include "gegl.h"
Packit bc1512
#include "gegl-types-internal.h"
Packit bc1512
#include "gegl-operation-point-composer3.h"
Packit bc1512
#include "gegl-utils.h"
Packit bc1512
#include "graph/gegl-node.h"
Packit bc1512
#include "graph/gegl-pad.h"
Packit bc1512
#include <string.h>
Packit bc1512
Packit bc1512
static gboolean gegl_operation_point_composer3_process
Packit bc1512
                              (GeglOperation       *operation,
Packit bc1512
                               GeglBuffer          *input,
Packit bc1512
                               GeglBuffer          *aux,
Packit bc1512
                               GeglBuffer          *aux2,
Packit bc1512
                               GeglBuffer          *output,
Packit bc1512
                               const GeglRectangle *result,
Packit bc1512
                               gint                 level);
Packit bc1512
Packit bc1512
static gboolean
Packit bc1512
gegl_operation_composer3_process2 (GeglOperation        *operation,
Packit bc1512
                                   GeglOperationContext *context,
Packit bc1512
                                   const gchar          *output_prop,
Packit bc1512
                                   const GeglRectangle  *result,
Packit bc1512
                                   gint                  level);
Packit bc1512
Packit bc1512
G_DEFINE_TYPE (GeglOperationPointComposer3, gegl_operation_point_composer3, GEGL_TYPE_OPERATION_COMPOSER3)
Packit bc1512
Packit bc1512
static void prepare (GeglOperation *operation)
Packit bc1512
{
Packit bc1512
  const Babl *format = babl_format ("RGBA float");
Packit bc1512
  gegl_operation_set_format (operation, "input", format);
Packit bc1512
  gegl_operation_set_format (operation, "aux", format);
Packit bc1512
  gegl_operation_set_format (operation, "aux2", format);
Packit bc1512
  gegl_operation_set_format (operation, "output", format);
Packit bc1512
}
Packit bc1512
Packit bc1512
static void
Packit bc1512
gegl_operation_point_composer3_class_init (GeglOperationPointComposer3Class *klass)
Packit bc1512
{
Packit bc1512
  /*GObjectClass       *object_class    = G_OBJECT_CLASS (klass);*/
Packit bc1512
  GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
Packit bc1512
  GeglOperationComposer3Class *composer_class = GEGL_OPERATION_COMPOSER3_CLASS (klass);
Packit bc1512
Packit bc1512
  composer_class->process = gegl_operation_point_composer3_process;
Packit bc1512
  operation_class->prepare = prepare;
Packit bc1512
  operation_class->no_cache =TRUE;
Packit bc1512
  operation_class->process = gegl_operation_composer3_process2;
Packit bc1512
}
Packit bc1512
Packit bc1512
static void
Packit bc1512
gegl_operation_point_composer3_init (GeglOperationPointComposer3 *self)
Packit bc1512
{
Packit bc1512
Packit bc1512
}
Packit bc1512
Packit bc1512
/* we replicate the process function from GeglOperationComposer3 to be
Packit bc1512
 * able to bail out earlier for some common processing time pitfalls
Packit bc1512
 */
Packit bc1512
static gboolean
Packit bc1512
gegl_operation_composer3_process2 (GeglOperation        *operation,
Packit bc1512
                                   GeglOperationContext *context,
Packit bc1512
                                   const gchar          *output_prop,
Packit bc1512
                                   const GeglRectangle  *result,
Packit bc1512
                                   gint                  level)
Packit bc1512
{
Packit bc1512
  GeglOperationComposer3Class *klass   = GEGL_OPERATION_COMPOSER3_GET_CLASS (operation);
Packit bc1512
  GeglBuffer                  *input;
Packit bc1512
  GeglBuffer                  *aux;
Packit bc1512
  GeglBuffer                  *aux2;
Packit bc1512
  GeglBuffer                  *output;
Packit bc1512
  gboolean                     success = FALSE;
Packit bc1512
Packit bc1512
  if (strcmp (output_prop, "output"))
Packit bc1512
    {
Packit bc1512
      g_warning ("requested processing of %s pad on a composer", output_prop);
Packit bc1512
      return FALSE;
Packit bc1512
    }
Packit bc1512
Packit bc1512
  input = gegl_operation_context_get_source (context, "input");
Packit bc1512
  aux   = gegl_operation_context_get_source (context, "aux");
Packit bc1512
  aux2  = gegl_operation_context_get_source (context, "aux2");
Packit bc1512
Packit bc1512
  /* we could be even faster by not alway writing to this buffer, that
Packit bc1512
   * would potentially break other assumptions we want to make from the
Packit bc1512
   * GEGL core so we avoid doing that
Packit bc1512
   */
Packit bc1512
  output = gegl_operation_context_get_target (context, "output");
Packit bc1512
Packit bc1512
Packit bc1512
  if (input != NULL ||
Packit bc1512
      aux != NULL ||
Packit bc1512
      aux2 != NULL)
Packit bc1512
    {
Packit bc1512
      gboolean done = FALSE;
Packit bc1512
Packit bc1512
      if (result->width == 0 ||
Packit bc1512
          result->height == 0)
Packit bc1512
        done = TRUE;
Packit bc1512
Packit bc1512
      success = done;
Packit bc1512
      if (!done)
Packit bc1512
        {
Packit bc1512
          success = klass->process (operation, input, aux, aux2, output, result, context->level);
Packit bc1512
Packit bc1512
          if (output == GEGL_BUFFER (operation->node->cache))
Packit bc1512
            gegl_cache_computed (operation->node->cache, result);
Packit bc1512
        }
Packit bc1512
      if (input)
Packit bc1512
         g_object_unref (input);
Packit bc1512
      if (aux)
Packit bc1512
         g_object_unref (aux);
Packit bc1512
      if (aux2)
Packit bc1512
         g_object_unref (aux2);
Packit bc1512
    }
Packit bc1512
  else
Packit bc1512
    {
Packit bc1512
      g_warning ("%s received NULL input, aux, and aux2",
Packit bc1512
                 gegl_node_get_debug_name (operation->node));
Packit bc1512
    }
Packit bc1512
Packit bc1512
  return success;
Packit bc1512
}
Packit bc1512
Packit bc1512
static gboolean
Packit bc1512
gegl_operation_point_composer3_process (GeglOperation       *operation,
Packit bc1512
                                        GeglBuffer          *input,
Packit bc1512
                                        GeglBuffer          *aux,
Packit bc1512
                                        GeglBuffer          *aux2,
Packit bc1512
                                        GeglBuffer          *output,
Packit bc1512
                                        const GeglRectangle *result,
Packit bc1512
                                        gint                 level)
Packit bc1512
{
Packit bc1512
  GeglOperationPointComposer3Class *point_composer3_class = GEGL_OPERATION_POINT_COMPOSER3_GET_CLASS (operation);
Packit bc1512
  const Babl *in_format   = gegl_operation_get_format (operation, "input");
Packit bc1512
  const Babl *aux_format  = gegl_operation_get_format (operation, "aux");
Packit bc1512
  const Babl *aux2_format = gegl_operation_get_format (operation, "aux2");
Packit bc1512
  const Babl *out_format  = gegl_operation_get_format (operation, "output");
Packit bc1512
Packit bc1512
  if ((result->width > 0) && (result->height > 0))
Packit bc1512
    {
Packit bc1512
      GeglBufferIterator *i = gegl_buffer_iterator_new (output, result, level, out_format, GEGL_BUFFER_WRITE, GEGL_ABYSS_NONE);
Packit bc1512
      gint read  = gegl_buffer_iterator_add (i, input, result, level, in_format, GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
Packit bc1512
Packit bc1512
      if (aux)
Packit bc1512
        {
Packit bc1512
          gint foo = gegl_buffer_iterator_add (i, aux, result, level, aux_format, GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
Packit bc1512
          if (aux2)
Packit bc1512
            {
Packit bc1512
              gint bar = gegl_buffer_iterator_add (i, aux2, result, level, aux2_format, GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
Packit bc1512
Packit bc1512
              while (gegl_buffer_iterator_next (i))
Packit bc1512
                {
Packit bc1512
                   point_composer3_class->process (operation, i->data[read], i->data[foo], i->data[bar], i->data[0], i->length, &(i->roi[0]), level);
Packit bc1512
                }
Packit bc1512
            }
Packit bc1512
          else
Packit bc1512
            {
Packit bc1512
              while (gegl_buffer_iterator_next (i))
Packit bc1512
                {
Packit bc1512
                   point_composer3_class->process (operation, i->data[read], i->data[foo], NULL, i->data[0], i->length, &(i->roi[0]), level);
Packit bc1512
                }
Packit bc1512
            }
Packit bc1512
        }
Packit bc1512
      else
Packit bc1512
        {
Packit bc1512
          if (aux2)
Packit bc1512
            {
Packit bc1512
              gint bar = gegl_buffer_iterator_add (i, aux2, result, level, aux2_format, GEGL_BUFFER_READ, GEGL_ABYSS_NONE);
Packit bc1512
              while (gegl_buffer_iterator_next (i))
Packit bc1512
                {
Packit bc1512
                   point_composer3_class->process (operation, i->data[read], NULL, i->data[bar], i->data[0], i->length, &(i->roi[0]), level);
Packit bc1512
                }
Packit bc1512
            }
Packit bc1512
          else
Packit bc1512
            {
Packit bc1512
              while (gegl_buffer_iterator_next (i))
Packit bc1512
                {
Packit bc1512
                   point_composer3_class->process (operation, i->data[read], NULL, NULL, i->data[0], i->length, &(i->roi[0]), level);
Packit bc1512
                }
Packit bc1512
            }
Packit bc1512
        }
Packit bc1512
      return TRUE;
Packit bc1512
    }
Packit bc1512
  return TRUE;
Packit bc1512
}