summaryrefslogtreecommitdiff
path: root/examples/testbed.c
blob: 6975b4691e21d4f90833ad8b50e3233349afe839 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <gegl.h>
#include <glib/gprintf.h>


gint
main (gint    argc,
      gchar **argv)
{
  gegl_init (&argc, &argv);  /* initialize the GEGL library */

  /* license for this application, needed by fractal-explorer */
  g_object_set (gegl_config (),
                "application-license", "GPL3",
                NULL);

  {
    /* instantiate a graph */
    GeglNode *gegl = gegl_node_new ();

/*
This is the graph we're going to construct:

.-----------.
| display   |
`-----------'
    |
.--------.
|  crop  |
`--------'
    |
.----------------------.
|  motion-blur-linear  |
`----------------------'
    |
.------------------.
| fractal-explorer |
`------------------'

*/

    /*< The image nodes representing operations we want to perform */
    GeglNode *display    = gegl_node_create_child (gegl, "gegl:display");
    GeglNode *crop       = gegl_node_new_child (gegl,
                                 "operation", "gegl:crop",
                                 "width", 512.0,
                                 "height", 384.0,
                                  NULL);
    GeglNode *pixelize   = gegl_node_new_child (gegl,
                                 "operation", "gegl:pixelize",
                                 "norm", 1,
                                 "ratio_x", 0.4,
                                 "ratio_y", 0.4,
                                 NULL);
    GeglNode *mandelbrot = gegl_node_new_child (gegl,
                                "operation", "gegl:fractal-explorer",
                                "shiftx", -256.0,
                                "fractaltype", 1,
                                "redmode", 2,
                                "greenmode", 2,
                                "bluemode", 2,
                                "redinvert", TRUE,
                                "greeninvert", TRUE,
                                "blueinvert", TRUE,
                                NULL);

    gegl_node_link_many (mandelbrot, pixelize, crop, display, NULL);

    /* request that the save node is processed, all dependencies will
     * be processed as well
     */
    {
      gint frame;
      gint frames = 200;

      for (frame=0; frame<frames; frame++)
        {
          gdouble t = frame * 1.0/frames;

#define INTERPOLATE(min,max) ((max)*(t)+(min)*(1.0-t))

          gdouble shiftx = INTERPOLATE(-256.0, -512.0);
          gdouble shifty = INTERPOLATE(0.0,    -256.0);
          gdouble zoom   = INTERPOLATE(300.0,   400.0);

          gegl_node_set (mandelbrot, "shiftx", shiftx,
                                     "shifty", shifty,
                                     "zoom", zoom,
                                     NULL);
          gegl_node_process (display);
        }
    }

    /* free resources used by the graph and the nodes it owns */
    g_object_unref (gegl);
  }

  /* free resources globally used by GEGL */
  gegl_exit ();

  return 0;
}