/* gcc gegl-pixbuf.c $(pkg-config --cflags --libs gegl-0.3
   gdk-pixbuf-2.0 babl) */

#include <string.h>

#include <babl/babl.h>
#include <gegl.h>
#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>

static const gchar *FILE_PATH = "/home/rishi/Pictures/test-case.jpg";

int
main (void)
{
  GeglNode *source;
  GeglNode *sink;
  GeglNode *graph;
  GdkPixbuf *pixbuf_in;
  GdkPixbuf *pixbuf_out;
  guint i;

  gegl_init (NULL, NULL);

  pixbuf_in = gdk_pixbuf_new_from_file (FILE_PATH, NULL);

  graph = gegl_node_new ();
  source = gegl_node_new_child (graph,
                                "operation", "gegl:pixbuf",
                                "pixbuf", pixbuf_in,
                                NULL);
  sink = gegl_node_new_child (graph,
                              "operation", "gegl:save-pixbuf",
                              "pixbuf", &pixbuf_out,
                              NULL);

  gegl_node_link_many (source, sink, NULL);
  gegl_node_process (sink);

  gdk_pixbuf_save (pixbuf_in, "/tmp/bar.png", "png", NULL, NULL);
  gdk_pixbuf_save (pixbuf_out, "/tmp/foo.png", "png", NULL, NULL);

  g_object_unref (pixbuf_in);
  g_object_unref (pixbuf_out);
  g_object_unref (graph);
  return 0;
}
