gnomemm r1523 - in geglmm/trunk: . examples
- From: hub svn gnome org
- To: svn-commits-list gnome org
- Subject: gnomemm r1523 - in geglmm/trunk: . examples
- Date: Thu, 22 May 2008 04:21:17 +0000 (UTC)
Author: hub
Date: Thu May 22 04:21:16 2008
New Revision: 1523
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1523&view=rev
Log:
* examples/geglbuffer-add-image.cc:
* examples/geglbuffer-clock.cc:
* examples/Makefile.am:
* examples/hello-world.cc:
* examples/2geglbuffer.cc:
Examples for Geglmm. Only hello-world work, the
others need API updates.
Added:
geglmm/trunk/examples/2geglbuffer.cc
geglmm/trunk/examples/geglbuffer-add-image.cc
geglmm/trunk/examples/geglbuffer-clock.cc
Modified:
geglmm/trunk/ChangeLog
geglmm/trunk/examples/ (props changed)
geglmm/trunk/examples/Makefile.am
geglmm/trunk/examples/hello-world.cc
Added: geglmm/trunk/examples/2geglbuffer.cc
==============================================================================
--- (empty file)
+++ geglmm/trunk/examples/2geglbuffer.cc Thu May 22 04:21:16 2008
@@ -0,0 +1,36 @@
+#include <glib.h>
+#include <libgeglmm/buffer.h>
+#include <libgeglmm/init.h>
+#include <libgeglmm/node.h>
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ Glib::RefPtr<Gegl::Buffer> buffer;
+ Glib::RefPtr<Gegl::Node> gegl, load_file, save_file;
+
+ Gegl::init (&argc, &argv);
+
+
+ if (argv[1]==NULL ||
+ argv[2]==NULL)
+ {
+ g_print ("\nusage: %s in.png out.gegl\n\nCreates a GeglBuffer from an image file.\n\n", argv[0]);
+ exit (-1);
+ }
+
+ gegl = Gegl::Node::create();
+ load_file = gegl->new_child ( "operation", "load");
+ load_file->set("path", argv[1], NULL);
+ save_file = gegl->new_child ( "operation", "save-buffer");
+ save_file->set("buffer", buffer->gobj(), NULL);
+
+ load_file->link (save_file);
+ save_file->process ();
+
+
+// New API in 0.0.17.
+// buffer->save (argv[2]);
+ return 0;
+}
Modified: geglmm/trunk/examples/Makefile.am
==============================================================================
--- geglmm/trunk/examples/Makefile.am (original)
+++ geglmm/trunk/examples/Makefile.am Thu May 22 04:21:16 2008
@@ -4,9 +4,10 @@
include Makefile.am_fragment
-noinst_PROGRAMS = hello-world
+noinst_PROGRAMS = hello-world geglbuffer-clock 2geglbuffer geglbuffer-add-image
hello_world_SOURCES = hello-world.cc
+
#hello_world_LDFLAGS = $(common_ldflags)
#hello_world_LDADD = $(LIBGEGLMM_LIBS)
Added: geglmm/trunk/examples/geglbuffer-add-image.cc
==============================================================================
--- (empty file)
+++ geglmm/trunk/examples/geglbuffer-add-image.cc Thu May 22 04:21:16 2008
@@ -0,0 +1,58 @@
+#include <libgeglmm/node.h>
+#include <libgeglmm/init.h>
+#include <libgeglmm/buffer.h>
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ Gegl::init(&argc, &argv); /* initialize the GEGL library */
+ Glib::RefPtr<Gegl::Buffer> buffer; /* instantiate a graph */
+ Glib::RefPtr<Gegl::Node> gegl; /* the gegl graph we're using as a node factor */
+ Glib::RefPtr<Gegl::Node> write_buffer,
+ shift,
+ load;
+ gchar *in_file;
+ gchar *buf_file;
+ gdouble x;
+ gdouble y;
+
+
+
+ if (argv[1]==NULL ||
+ argv[2]==NULL ||
+ argv[3]==NULL ||
+ argv[4]==NULL)
+ {
+ g_print ("\nUsage: %s <gegl buffer> <image file> <x> <y>\n"
+ "\nWrites an image into the GeglBuffer at the specified coordinates\n",
+ argv[0]);
+ return -1;
+ }
+ buf_file = argv[1];
+ in_file = argv[2];
+ x = atof (argv[3]);
+ y = atof (argv[4]);
+
+// buffer = Gegl::Buffer::create_from_file (buf_file);
+ gegl = Gegl::Node::create();
+
+ write_buffer = gegl->new_child ("operation", "write-buffer");
+ write_buffer->set("buffer", buffer->gobj(), NULL);
+ shift = gegl->new_child ("operation", "shift");
+ shift->set ( "x", x, "y", y, NULL);
+ load = gegl->new_child ("operation", "load");
+ load->set ("path", in_file, NULL);
+
+ load->link(shift);
+ load->link(write_buffer);
+ write_buffer->process ();
+
+ /* free resources used by the graph and the nodes it owns */
+ // nothing to do, this is C++ :-)
+
+ /* free resources globally used by GEGL */
+// gegl_exit ();
+
+ return 0;
+}
Added: geglmm/trunk/examples/geglbuffer-clock.cc
==============================================================================
--- (empty file)
+++ geglmm/trunk/examples/geglbuffer-clock.cc Thu May 22 04:21:16 2008
@@ -0,0 +1,79 @@
+#include <libgeglmm/node.h>
+#include <libgeglmm/init.h>
+#include <libgeglmm/color.h>
+
+#include <sys/time.h>
+#include <time.h>
+
+gint
+main (gint argc,
+ gchar **argv)
+{
+ if (argv[1]==NULL)
+ {
+ g_print ("\nUsage: %s <GeglBuffer>\n"
+ "\n"
+ "Continously writes a timestamp to 0,0 in the buffer\n", argv[0]);
+ exit (-1);
+ }
+
+ Gegl::init (&argc, &argv); /* initialize the GEGL library */
+
+ Glib::RefPtr<Gegl::Node> gegl; /* the gegl graph we're using as a node factor */
+ Glib::RefPtr<Gegl::Node> display,
+ text,
+ layer,
+ crop,
+ shift,
+ blank;
+
+ gegl = Gegl::Node::create ();
+
+
+ blank = gegl->new_child ("operation", "color");
+ blank->set ("value", Gegl::Color::create ("rgba(0.0,0.0,0.0,0.4)")->gobj(), NULL);
+
+ crop = gegl->new_child ("operation", "crop");
+ crop->set ("x", 0.0, "y", 0.0, "width", 260.0, "height", 22.0, NULL);
+
+ layer = gegl->new_child ("operation", "layer");
+
+ shift = gegl->new_child ("operation", "shift");
+ shift->set("x", 0.0, "y", 0.0, NULL);
+
+ text = gegl->new_child ("operation", "text");
+ text->set ("size", 20.0, NULL);
+ /* "color", gegl_color_new ("rgb(0.0,0.0,0.0)"),*/
+ display = gegl->new_child ("operation", "composite-buffer");
+ display->set ("path", argv[1], NULL);
+
+ blank->link(crop);
+ blank->link(layer);
+ blank->link(shift);
+ blank->link(display);
+ text->connect_to("output", layer, "aux");
+
+ /* request that the save node is processed, all dependencies will
+ * be processed as well
+ */
+ {
+ gint frame;
+ gint frames = 1024;
+ GTimeVal val;
+
+ for (frame=0; frame<frames; frame++)
+ {
+ gchar string[512];
+ struct timeval tv;
+
+ int t = gettimeofday(&tv, NULL);
+ text->set("string", ctime((const time_t*)&t), NULL);
+ display->process();
+ g_usleep (1000000);
+ }
+ }
+ /* free resources globally used by GEGL */
+// gegl_exit ();
+
+ return 0;
+}
Modified: geglmm/trunk/examples/hello-world.cc
==============================================================================
--- geglmm/trunk/examples/hello-world.cc (original)
+++ geglmm/trunk/examples/hello-world.cc Thu May 22 04:21:16 2008
@@ -39,14 +39,11 @@
/*< The image nodes representing operations we want to perform */
Glib::RefPtr<Gegl::Node> display = gegl->create_child("display");
Glib::RefPtr<Gegl::Node> layer = gegl->new_child("operation", "layer");
- layer->set_property ("x", 2.0);
- layer->set_property ("y", 4.0);
+ layer->set ("x", 2.0, "y", 4.0, NULL);
Glib::RefPtr<Gegl::Node> text = gegl->new_child("operation", "text");
- text->set_property ("size", 10.0);
- text->set_property ("color", Glib::RefPtr<Gegl::Color>(Gegl::Color::create ("rgb(1.0,1.0,1.0)")));
+ text->set ("size", 10.0, "color", Glib::RefPtr<Gegl::Color>(Gegl::Color::create ("rgb(1.0,1.0,1.0)"))->gobj(), NULL);
Glib::RefPtr<Gegl::Node> mandelbrot = gegl->new_child ("operation", "fractal-explorer");
- mandelbrot->set_property ("width", 512);
- mandelbrot->set_property ("height", 384);
+ mandelbrot->set ("width", 512, "height", 384, NULL);
mandelbrot->link (layer);
mandelbrot->link (display);
@@ -62,28 +59,26 @@
for (frame=0; frame<frames; frame++)
{
gchar string[512];
- gdouble t = frame * 1.0/frames;
- gdouble cx = -1.76;
- gdouble cy = 0.0;
+ double t = frame * 1.0/frames;
+ double cx = -1.76;
+ double cy = 0.0;
#define INTERPOLATE(min,max) ((max)*(t)+(min)*(1.0-t))
- gdouble xmin = INTERPOLATE( cx-0.02, cx-2.5);
- gdouble ymin = INTERPOLATE( cy-0.02, cy-2.5);
- gdouble xmax = INTERPOLATE( cx+0.02, cx+2.5);
- gdouble ymax = INTERPOLATE( cy+0.02, cy+2.5);
+ double xmin = INTERPOLATE( cx-0.02, cx-2.5);
+ double ymin = INTERPOLATE( cy-0.02, cy-2.5);
+ double xmax = INTERPOLATE( cx+-1.02, cx+2.5);
+ double ymax = INTERPOLATE( cy+0.02, cy+2.5);
if (xmin<-3.0)
xmin=-3.0;
if (ymin<-3.0)
ymin=-3.0;
- mandelbrot->set_property ("xmin", xmin);
- mandelbrot->set_property ("ymin", ymin);
- mandelbrot->set_property ("xmax", xmax);
- mandelbrot->set_property ("ymax", ymax);
+
+ mandelbrot->set ("xmin", xmin, "ymin", ymin, "xmax", xmax, "ymax", ymax, NULL);
snprintf (string, sizeof string, "%1.3f,%1.3f %1.3fÃ%1.3f", xmin, ymin, xmax-xmin, ymax-ymin);
- text->set_property ("string", &string);
+ text->set ("string", string, NULL);
display->process ();
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]