layer.c 4.01 KB
Newer Older
Øyvind Kolås's avatar
Øyvind Kolås committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* This file is an image processing operation for GEGL
 *
 * GEGL is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * GEGL is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with GEGL; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * Copyright 2006 Øyvind Kolås <pippin@gimp.org>
 */
20
#ifdef GEGL_CHANT_PROPERTIES
Øyvind Kolås's avatar
Øyvind Kolås committed
21

22 23 24 25 26 27
gegl_chant_string(composite_op, "over", "Composite operation to use")
gegl_chant_double(opacity, 0.0, 1.0, 1.0, "Opacity")
gegl_chant_double(x, -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, "horizontal position")
gegl_chant_double(y, -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, "vertical position")
gegl_chant_string(src, "", "source datafile (png, jpg, raw, svg, bmp, tif, ..)")
gegl_chant_pointer(private, "private stuff do not touch")
Øyvind Kolås's avatar
Øyvind Kolås committed
28 29 30

#else

31 32 33 34
#define GEGL_CHANT_GRAPH
#define GEGL_CHANT_NAME            layer
#define GEGL_CHANT_DESCRIPTION     "A layer in the traditional sense"
#define GEGL_CHANT_SELF            "layer.c"
Øyvind Kolås's avatar
Øyvind Kolås committed
35
#define GEGL_CHANT_CLASS_INIT
Øyvind Kolås's avatar
Øyvind Kolås committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#include "gegl-chant.h"

typedef struct _Priv Priv;
struct _Priv
{
  GeglNode *self;
  GeglNode *input;
  GeglNode *aux;
  GeglNode *output;

  GeglNode *composite_op;
    GeglNode *shift;
    GeglNode *opacity;
    GeglNode *load;
};

static void
prepare (GeglOperation *operation)
{
55
  GeglChantOperation *self = GEGL_CHANT_OPERATION (operation);
Øyvind Kolås's avatar
Øyvind Kolås committed
56 57 58 59 60 61 62 63
  Priv *priv;
  priv = (Priv*)self->priv;

  /* warning: this might trigger regeneration of the graph,
   *          for now this is evaded by just ignoring additional
   *          requests to be made into members of the graph
   */
  gegl_node_set (priv->composite_op,
64
                 "operation", self->composite_op,
Øyvind Kolås's avatar
Øyvind Kolås committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
                 NULL);
  if (self->src[0])
    {
      gegl_node_set (priv->load, 
                     "path",  self->src,
                     NULL);
    }
  else
    {
      gegl_node_connect (priv->opacity, "input", priv->aux, "output");
    }

  gegl_node_set (priv->opacity, 
                 "value",  self->opacity,
                 NULL);
  gegl_node_set (priv->shift, 
                 "x",  self->x,
                 "y",  self->y,
                 NULL);
}

static void associate (GeglOperation *operation)
{
88
  GeglChantOperation *self = GEGL_CHANT_OPERATION (operation);
Øyvind Kolås's avatar
Øyvind Kolås committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
  Priv *priv = (Priv*)self->priv;
  GeglGraph *graph;
  g_assert (priv == NULL);

  priv = g_malloc0 (sizeof (Priv));
  self->priv = (void*) priv;

  priv->self = GEGL_OPERATION (self)->node;
  graph = GEGL_GRAPH (priv->self);

  priv->input = gegl_graph_input (graph, "input");
  priv->aux = gegl_graph_input (graph, "aux");
  priv->output = gegl_graph_output (graph, "output");

  priv->composite_op = gegl_graph_create_node (graph,
104
                                         "operation", self->composite_op,
Øyvind Kolås's avatar
Øyvind Kolås committed
105 106
                                         NULL);

107 108
  priv->shift = gegl_graph_create_node (graph, "operation", "shift", NULL);
  priv->opacity = gegl_graph_create_node (graph, "operation", "opacity", NULL);
Øyvind Kolås's avatar
Øyvind Kolås committed
109 110
  
  priv->load = gegl_graph_create_node (graph,
111
                                       "operation", "load",
Øyvind Kolås's avatar
Øyvind Kolås committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
                                       NULL);

  gegl_node_connect (priv->opacity, "input", priv->load, "output");
  gegl_node_connect (priv->shift, "input", priv->opacity, "output");
  gegl_node_connect (priv->composite_op, "aux", priv->shift, "output");
  gegl_node_connect (priv->composite_op, "input", priv->input, "output");
  gegl_node_connect (priv->output, "input", priv->composite_op, "output");
}

static void class_init (GeglOperationClass *klass)
{
  klass->prepare = prepare;
  klass->associate = associate;
}

#endif