[niepce] Get rid of Geglmm and use the direct C API



commit df42b18cd207628fb55d6fe9df7a5569d68d6a34
Author: Hubert FiguiÃre <hub figuiere net>
Date:   Tue Jul 17 21:29:58 2012 -0700

    Get rid of Geglmm and use the direct C API

 README                                  |   11 +-
 configure.ac                            |    9 +-
 src/ncr/Makefile.am                     |    4 +-
 src/ncr/image.cpp                       |  316 ++++++++++++++++++-------------
 src/ncr/image.hpp                       |    2 +-
 src/ncr/init.cpp                        |    4 +-
 src/ncr/ncr.cpp                         |   10 +-
 src/ncr/ncr.hpp                         |    4 +-
 src/niepce/Makefile.am                  |    2 +-
 src/niepce/modules/darkroom/Makefile.am |    2 +-
 10 files changed, 200 insertions(+), 164 deletions(-)
---
diff --git a/README b/README
index 46a23d9..bdb7b7b 100644
--- a/README
+++ b/README
@@ -1,7 +1,7 @@
 Niepce Digital
 ==============
 
-This software is licensed under GPL version 3. See file 
+This software is licensed under GPL version 3. See file
 COPYING for details.
 Some files maybe under GPL version 2 or later.
 
@@ -31,8 +31,7 @@ boost 1.34
  -boost test (for the unit test)
 exempi >= 2.2.0
 libopenraw >= 0.1.0
-geglmm >= 0.1.0
-gegl >= 0.1.0
+gegl >= 0.2.0
 babl
 libgphoto2
 
@@ -44,11 +43,7 @@ Working on Debian
 ~~~~~~~~~~~~~~~~~
 In order to get Niepce working on Debian you should have to install:
 aptitude install \
-> libexempi-dev libopenraw-dev libopenrawgnome-dev libgtkmm-3-dev 
-
-Debian (nor Ubuntu) do not still pack geglmm. In order to get it visit 
-to get the latest version:
-http://ftp.gnome.org/pub/gnome/sources/geglmm/
+> libexempi-dev libopenraw-dev libopenrawgnome-dev libgtkmm-3-dev
 
 Working on SUSE
 ~~~~~~~~~~~~~~~
diff --git a/configure.ac b/configure.ac
index 0068f39..2a3d55b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,8 +25,7 @@ LIBGTKMM_VERSION=3.2
 LIBGNOMEUI_VERSION=2.0.0
 EXEMPI_VERSION=2.2.0
 SQLITE_VERSION=3.0
-GEGL_VERSION=0.1.0
-GEGLMM_VERSION=0.2.0
+GEGL_VERSION=0.2.0
 LIBOPENRAW_VERSION=0.1.0
 LIBGPHOTO_VERSION=2.4
 dnl need at least 2.5.0 because of xmlTextReader
@@ -77,10 +76,8 @@ AC_SUBST(OPENRAW_CFLAGS)
 AC_SUBST(OPENRAW_LIBS)
 
 PKG_CHECK_MODULES(GEGL, gegl-0.2 >= $GEGL_VERSION)
-dnl we want to use geglmm.
-PKG_CHECK_MODULES(GEGLMM, geglmm-0.2 >= $GEGLMM_VERSION)
-AC_SUBST(GEGLMM_CFLAGS)
-AC_SUBST(GEGLMM_LIBS)
+AC_SUBST(GEGL_CFLAGS)
+AC_SUBST(GEGL_LIBS)
 
 
 BOOST_REQUIRE([$BOOST_VERSION])
diff --git a/src/ncr/Makefile.am b/src/ncr/Makefile.am
index 1f89bcf..aecf568 100644
--- a/src/ncr/Makefile.am
+++ b/src/ncr/Makefile.am
@@ -3,7 +3,7 @@
 
 INCLUDES = -I$(top_srcdir)/src  \
 	@LIBGTKMM_CFLAGS@ \
-	@BABL_CFLAGS@ @GEGLMM_CFLAGS@ @OPENRAW_CFLAGS@
+	@BABL_CFLAGS@ @GEGL_CFLAGS@ @OPENRAW_CFLAGS@
 
 niepcelibdir = @libdir@/niepce/
 #niepcelib_LTLIBRARIES = libncr.la
@@ -16,4 +16,4 @@ libncr_a_SOURCES = ncr.hpp ncr.cpp \
 	$(NULL)
 
 #libncr_la_SOURCES = ncr.h ncr.cpp
-#libncr_la_LIBADD = @OPENRAW_LIBS@ @GEGLMM_LIBS@
+#libncr_la_LIBADD = @OPENRAW_LIBS@ @GEGL_LIBS@
diff --git a/src/ncr/image.cpp b/src/ncr/image.cpp
index 8bfdc47..8a2246b 100644
--- a/src/ncr/image.cpp
+++ b/src/ncr/image.cpp
@@ -21,64 +21,55 @@
 
 extern "C" {
 #include <babl/babl.h>
+#include <gegl.h>
 }
 
 #include <libopenraw/libopenraw.h>
 
-#include <geglmm/node.h>
-#include <geglmm/operation.h>
-
 #include "fwk/base/debug.hpp"
 #include "ncr.hpp"
 #include "image.hpp"
 
 namespace ncr {
 
-namespace {
-
-const Babl * format_for_cairo_argb32()
-{
-    // TODO not endian neutral
-    return babl_format_new(babl_model("R'G'B'A"),
-                           babl_type ("u8"),
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-                           babl_component ("B'"),
-                           babl_component ("G'"),
-                           babl_component ("R'"),
-                           babl_component ("A"),
-#elif G_BYTE_ORDER == G_BIG_ENDIAN
-                           babl_component ("A"),
-                           babl_component ("R'"),
-                           babl_component ("G'"),
-                           babl_component ("B'"),
-#else
-#error unknown endian
-#endif
-                           NULL);
-}
-
-
-}
-
 struct Image::Private {
     Private()
         : m_width(0)
         , m_height(0)
-        , m_orientation(0)
+        , m_orientation(0), m_vertical(false)
         , m_flip(false)
         , m_tilt(0.0)
+        , m_graph(NULL), m_rgb(NULL), m_rotate_n(NULL)
+        , m_scale(NULL)
+        , m_sink_buffer(NULL)
+        {
+        }
+    ~Private()
         {
+            if(m_graph) {
+                g_object_unref(m_graph);
+            }
+            if(m_sink_buffer) {
+                g_object_unref(m_sink_buffer);
+            }
         }
 
     int m_width, m_height; /**< the native dimension, with orientation */
     int m_orientation;     /**< EXIF orientation in degrees */
+    bool m_vertical;
     bool m_flip;           /**< EXIF flip */
     double m_tilt;         /**< User rotation */
-    Glib::RefPtr<Gegl::Node> m_node;
-    Glib::RefPtr<Gegl::Node> m_rgb;    /**< RGB pixmap */
-    Glib::RefPtr<Gegl::Node> m_rotate_n;
-    Glib::RefPtr<Gegl::Node> m_scale;
-    Glib::RefPtr<Gegl::Node> m_output;
+    GeglNode* m_graph;
+    GeglNode* m_rgb;    /**< RGB pixmap */
+    GeglNode* m_rotate_n;
+    GeglNode* m_scale;
+    // sink
+    GeglNode*   m_sink;
+    GeglBuffer* m_sink_buffer;
+
+    GeglNode* _rotate_node(int orientation);
+    GeglNode* _scale_node();
+    GeglNode* _load_raw(const std::string &path);
 };
 
 Image::Image()
@@ -91,116 +82,165 @@ Image::~Image()
     delete priv;
 }
 
-void Image::reload(const std::string & p, bool is_raw,
-    int orientation)
+GeglNode* Image::Private::_rotate_node(int orientation)
 {
-    Glib::RefPtr<Gegl::Node> load_file;
-
-    priv->m_node = Gegl::Node::create();
-    priv->m_node->set("format", babl_format("RGB u16"));
-
-    if(!is_raw) {
-        load_file = priv->m_node->new_child("operation", "gegl:load");
-        load_file->set("path", p);
-        priv->m_rgb = load_file;
-    }
-    else {
-        ORRawDataRef rawdata;
-        or_get_extract_rawdata(p.c_str(), 0, &rawdata);
-        Glib::RefPtr<Gegl::Buffer> buffer = ncr::load_rawdata(rawdata);
-        // @todo can return a NULL buffer if load failed. Deal with that.
-        load_file = priv->m_node->new_child("operation", "gegl:load-buffer");
-        load_file->set("buffer", buffer);
-        or_cfa_pattern pattern = or_rawdata_get_cfa_pattern(rawdata);
-        or_rawdata_release(rawdata);
-
-        Glib::RefPtr<Gegl::Node> stretch = priv->m_node->new_child(
-            "operation", "gegl:stretch-contrast");
-        
-        Glib::RefPtr<Gegl::Node> demosaic = priv->m_node->new_child(
-            "operation", "gegl:demosaic-bimedian");
-        // @todo refactor somewhere.
-        int npattern = 0;
-        switch(pattern) {
-        case OR_CFA_PATTERN_GRBG:
-            npattern = 0;
-            break;
-        case OR_CFA_PATTERN_BGGR:
-            npattern = 1;
-            break;
-        case OR_CFA_PATTERN_GBRG:
-            npattern = 2;
-            break;
-        case OR_CFA_PATTERN_RGGB:
-            npattern = 3;
-            break;
-        default:
-            break;
-        }
-
-        demosaic->set("pattern", npattern);
-
-        priv->m_rgb = load_file->link(stretch)->link(demosaic);
-    }
-    
-    Glib::RefPtr<Gegl::Node> current;
+//    GeglNode* rotateNode = gegl_node_new_child(m_graph, NULL, NULL);
 
     DBG_OUT("rotation is %d", orientation);
-    bool vertical = false;
     switch(orientation) {
     case 0:
     case 1:
         break;
     case 2:
-        priv->m_flip = true;
+        m_flip = true;
         break;
     case 4:
-        priv->m_flip = true;
+        m_flip = true;
         // fall through
     case 3:
-        priv->m_orientation = 180;
+        m_orientation = 180;
         break;
     case 5:
-        priv->m_flip = true;
+        m_flip = true;
         // fall through
     case 6:
-        priv->m_orientation = 270;
-        vertical = true;
+        m_orientation = 270;
+        m_vertical = true;
         break;
     case 7:
-        priv->m_flip = true;
+        m_flip = true;
         // fall through
     case 8:
-        priv->m_orientation = 90;
-        vertical = true;
+        m_orientation = 90;
+        m_vertical = true;
         break;
     }
+
     // @todo ideally we would have a plain GEGL op for that.
-    if(priv->m_flip) {
-        // @todo find a test case.
-        priv->m_rotate_n =  priv->m_node->new_child("operation", 
-                                                    "gegl:reflect");
-        priv->m_rotate_n->set("x", -1.0);
-        current = priv->m_rgb->link(priv->m_rotate_n);
+    // @todo find a test case.
+//    GeglNode* flipNode = gegl_node_new_child(rotateNode,
+//                                             "operation", "gegl:reflect",
+//                                             "x", (m_flip ? -1.0 : 1.0), NULL);
+
+    GeglNode* rotationNode = NULL;
+    double rotate = m_orientation + m_tilt;
+    rotationNode = gegl_node_new_child(m_graph,
+                                       "operation", "gegl:rotate",
+                                       "degrees", rotate, NULL);
+//    gegl_node_link(flipNode, rotationNode);
+
+    return rotationNode;
+}
+
+/** create the RAW pipeline */
+GeglNode* Image::Private::_load_raw(const std::string &p)
+{
+    GeglNode* rgb = NULL;
+
+    ORRawDataRef rawdata;
+    or_get_extract_rawdata(p.c_str(), 0, &rawdata);
+    GeglBuffer* buffer = ncr::load_rawdata(rawdata);
+    // @todo can return a NULL buffer if load failed. Deal with that.
+    GeglNode* load_file = gegl_node_new_child(m_graph,
+                                              "operation", "gegl:buffer-source",
+                                              "buffer", buffer, NULL);
+    or_cfa_pattern pattern = or_rawdata_get_cfa_pattern(rawdata);
+    or_rawdata_release(rawdata);
+
+    GeglNode* stretch =
+        gegl_node_new_child(m_graph,
+                            "operation", "gegl:stretch-contrast",
+                            NULL);
+    GeglNode* demosaic =
+        gegl_node_new_child(m_graph,
+                            "operation", "gegl:demosaic-bimedian",
+                            NULL);
+    // @todo refactor somewhere.
+    int npattern = 0;
+    switch(pattern) {
+    case OR_CFA_PATTERN_GRBG:
+        npattern = 0;
+        break;
+    case OR_CFA_PATTERN_BGGR:
+        npattern = 1;
+        break;
+    case OR_CFA_PATTERN_GBRG:
+        npattern = 2;
+        break;
+    case OR_CFA_PATTERN_RGGB:
+        npattern = 3;
+        break;
+    default:
+        break;
+    }
+    gegl_node_set(demosaic, "pattern", npattern, NULL);
+
+    gegl_node_link_many(load_file, stretch, demosaic, NULL);
+
+    rgb = demosaic;
+    return rgb;
+}
+
+GeglNode* Image::Private::_scale_node()
+{
+    return gegl_node_new_child(m_graph, "operation", "gegl:scale", NULL);
+}
+
+void Image::reload(const std::string & p, bool is_raw,
+    int orientation)
+{
+    GeglNode* load_file;
+
+    priv->m_graph = gegl_node_new();
+//    priv->m_graph->set("format", babl_format("RGB u16"));
+
+    DBG_OUT("loading file %s", p.c_str());
+
+    if(!is_raw) {
+        load_file = gegl_node_new_child(priv->m_graph,
+                                        "operation", "gegl:load",
+                                        "path", p.c_str(), NULL);
     }
     else {
-        current = priv->m_rgb;
+        load_file = priv->_load_raw(p);
     }
-    priv->m_rotate_n = priv->m_node->new_child("operation", "gegl:rotate");
-    priv->m_rotate_n->set("degrees", priv->m_orientation + priv->m_tilt);
-    current = current->link(priv->m_rotate_n);
-
-    priv->m_scale = priv->m_node->new_child("operation", "gegl:scale");
-    current->link(priv->m_scale);
-    priv->m_output = priv->m_scale;
-    
+
+    priv->m_rotate_n = priv->_rotate_node(orientation);
+    priv->m_scale = priv->_scale_node();
+    priv->m_sink = gegl_node_create_child (priv->m_graph, "gegl:display");
+
+//        gegl_node_new_child(priv->m_graph,
+//                            "operation", "gegl:buffer-sink",
+//                            "format", babl_format("RGB u8"),
+//                            "buffer", &(priv->m_sink_buffer), NULL);
+
+    gegl_node_link_many(load_file, priv->m_rotate_n,
+                        priv->m_scale, priv->m_sink, NULL);
+
+//    gegl_node_process(priv->m_sink);
+    // DEBUG
+#if 0
+    GeglNode* debugsink;
+    GeglNode* graph =
+        gegl_graph (debugsink=gegl_node ("gegl:save",
+                                         "path", "/tmp/gegl.png", NULL,
+                                         gegl_node ("gegl:buffer-source",
+                                                    "buffer",
+                                                    priv->m_sink_buffer,
+                                                    NULL)
+                        )
+            );
+    gegl_node_process (debugsink);
+    g_object_unref (graph);
+#endif
+    // END DEBUG
+
     int width, height;
-    Gegl::Rectangle rect;
-    rect = load_file->get_bounding_box();
-    width = rect.gobj()->width;
-    height = rect.gobj()->height;
+    GeglRectangle rect = gegl_node_get_bounding_box(load_file);
+    width = rect.width;
+    height = rect.height;
     DBG_OUT("width %d height %d", width, height);
-    if(vertical) {
+    if(priv->m_vertical) {
         priv->m_width = height;
         priv->m_height = width;
     }
@@ -219,8 +259,7 @@ void Image::set_output_scale(double scale)
         DBG_OUT("nothing loaded");
         return;
     }
-    priv->m_scale->set("x", scale);
-    priv->m_scale->set("y", scale);    
+    gegl_node_set(priv->m_scale, "x", scale, "y", scale, NULL);
 
     signal_update();
 }
@@ -234,9 +273,10 @@ void Image::set_tilt(double angle)
         return;
     }
     priv->m_tilt = angle;
-    priv->m_rotate_n->set("degrees", priv->m_orientation + priv->m_tilt);
+    gegl_node_set(priv->m_rotate_n, "degrees",
+                  priv->m_orientation + priv->m_tilt, NULL);
 
-    signal_update();    
+    signal_update();
 }
 
 
@@ -267,7 +307,7 @@ void Image::rotate_by(int degree)
         // within 0..359 degrees anyway
         priv->m_orientation %= 360;
     }
-    priv->m_rotate_n->set("degrees", priv->m_orientation + priv->m_tilt);
+    gegl_node_set(priv->m_rotate_n, "degrees", priv->m_orientation + priv->m_tilt, NULL);
     signal_update();
 }
 
@@ -275,23 +315,27 @@ void Image::rotate_by(int degree)
 
 Cairo::RefPtr<Cairo::Surface> Image::cairo_surface_for_display()
 {
-    if(!priv->m_output) {
+    if(!priv->m_sink) {
         DBG_OUT("nothing loaded");
         return Cairo::RefPtr<Cairo::Surface>();
     }
-    priv->m_output->process();
-    Gegl::Rectangle roi = priv->m_output->get_bounding_box();
+    DBG_OUT("processing");
+    gegl_node_process(priv->m_scale);
+    GeglRectangle roi = gegl_node_get_bounding_box(priv->m_scale);
     int w, h;
-    w = roi.gobj()->width;
-    h = roi.gobj()->height;
+    w = roi.width;
+    h = roi.height;
+
+    DBG_OUT("surface w=%d, h=%d", w, h);
 
-    const Babl * format = format_for_cairo_argb32();
+    const Babl* format = babl_format("B'aG'aR'aA u8");
 
-    Cairo::RefPtr<Cairo::ImageSurface> surface 
+    Cairo::RefPtr<Cairo::ImageSurface> surface
         = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, w, h);
-    priv->m_output->blit(1.0, roi, format,
-                         (void*)surface->get_data(), surface->get_stride(),
-                         (Gegl::BLIT_CACHE | Gegl::BLIT_DIRTY));
+    gegl_node_blit(priv->m_scale, 1.0, &roi, format,
+                   (void*)surface->get_data(), surface->get_stride(),
+                   (GeglBlitFlags)(GEGL_BLIT_CACHE | GEGL_BLIT_DIRTY));
+
     return surface;
 }
 
@@ -309,15 +353,15 @@ int Image::get_original_height() const
 
 int Image::get_output_width() const
 {
-    Gegl::Rectangle roi = priv->m_output->get_bounding_box();
-    return roi.gobj()->width;
+    GeglRectangle roi = gegl_node_get_bounding_box(priv->m_sink);
+    return roi.width;
 }
 
 
 int Image::get_output_height() const
 {
-    Gegl::Rectangle roi = priv->m_output->get_bounding_box();
-    return roi.gobj()->height;
+    GeglRectangle roi = gegl_node_get_bounding_box(priv->m_sink);
+    return roi.height;
 }
 
 
diff --git a/src/ncr/image.hpp b/src/ncr/image.hpp
index b234cf5..e3c9e56 100644
--- a/src/ncr/image.hpp
+++ b/src/ncr/image.hpp
@@ -76,7 +76,7 @@ public:
     sigc::signal<void> signal_update;
 private:
 
-    /** rotate by x degrees (orientation) 
+    /** rotate by x degrees (orientation)
      *  ensure the end results is within 0..359.
      */
     void rotate_by(int degree);
diff --git a/src/ncr/init.cpp b/src/ncr/init.cpp
index 21e71ca..f5a1a2f 100644
--- a/src/ncr/init.cpp
+++ b/src/ncr/init.cpp
@@ -20,13 +20,13 @@
 
 #include "init.hpp"
 
-#include <geglmm/init.h>
+#include <gegl.h>
 
 namespace ncr {
 
 void init()
 {
-    Gegl::init(0, NULL);
+    gegl_init(0, NULL);
 }
 
 }
diff --git a/src/ncr/ncr.cpp b/src/ncr/ncr.cpp
index 9d46811..c3f6854 100644
--- a/src/ncr/ncr.cpp
+++ b/src/ncr/ncr.cpp
@@ -26,12 +26,12 @@ extern "C" {
 
 namespace ncr {
 
-Glib::RefPtr<Gegl::Buffer> load_rawdata(ORRawDataRef rawdata)
+GeglBuffer* load_rawdata(ORRawDataRef rawdata)
 {
     uint32_t x, y;
     void *data;
     if(or_rawdata_format(rawdata) != OR_DATA_TYPE_RAW) {
-        return Glib::RefPtr<Gegl::Buffer>();
+        return NULL;
     }
     /* TODO take the dest_x and dest_y into account */
     GeglRectangle rect = {0, 0, 0, 0};
@@ -39,11 +39,11 @@ Glib::RefPtr<Gegl::Buffer> load_rawdata(ORRawDataRef rawdata)
     rect.width = x;
     rect.height = y;
 
-    Glib::RefPtr<Gegl::Buffer> buffer
-        = Gegl::Buffer::create(Gegl::Rectangle(rect), babl_format ("Y u16"));
+    GeglBuffer* buffer
+        = gegl_buffer_new(&rect, babl_format ("Y u16"));
 
     data = or_rawdata_data(rawdata);
-    buffer->set(Gegl::Rectangle(rect), 1, babl_format ("Y u16"),
+    gegl_buffer_set(buffer, &rect, 1, babl_format ("Y u16"),
                 data, GEGL_AUTO_ROWSTRIDE);
 
     return buffer;
diff --git a/src/ncr/ncr.hpp b/src/ncr/ncr.hpp
index 968a403..75f0c10 100644
--- a/src/ncr/ncr.hpp
+++ b/src/ncr/ncr.hpp
@@ -23,13 +23,13 @@
 #define _NIEPCE_NCR_H
 
 #include <glibmm/refptr.h>
-#include <geglmm/buffer.h>
+#include <gegl.h>
 #include <libopenraw/libopenraw.h>
 
 namespace ncr {
 
 /** load RAW data into a buffer. */
-Glib::RefPtr<Gegl::Buffer> load_rawdata(ORRawDataRef rawdata); 
+GeglBuffer* load_rawdata(ORRawDataRef rawdata);
 
 }
 
diff --git a/src/niepce/Makefile.am b/src/niepce/Makefile.am
index 00598ce..d6e472d 100644
--- a/src/niepce/Makefile.am
+++ b/src/niepce/Makefile.am
@@ -28,7 +28,7 @@ niepce_LDADD = \
 	@LIBGLIBMM_LIBS@ \
 	@LIBGTKMM_LIBS@ @SQLITE3_LIBS@ \
 	@BABL_LIBS@ \
-	@GEGLMM_LIBS@ @OPENRAW_LIBS@ @EXEMPI_LIBS@
+	@GEGL_LIBS@ @OPENRAW_LIBS@ @EXEMPI_LIBS@
 
 
 niepce_SOURCES = \
diff --git a/src/niepce/modules/darkroom/Makefile.am b/src/niepce/modules/darkroom/Makefile.am
index fc850a3..846293b 100644
--- a/src/niepce/modules/darkroom/Makefile.am
+++ b/src/niepce/modules/darkroom/Makefile.am
@@ -5,7 +5,7 @@ INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/src/niepce -I$(top_srcdir)/src/ex
 	-DDATADIR=\"$(datadir)\" \
 	@LIBGLIBMM_CFLAGS@ \
 	@LIBGTKMM_CFLAGS@ \
-	@GEGLMM_CFLAGS@ @EXEMPI_CFLAGS@ @OPENRAW_CFLAGS@
+	@GEGL_CFLAGS@ @EXEMPI_CFLAGS@ @OPENRAW_CFLAGS@
 
 
 noinst_LIBRARIES=libmoduledarkroom.a



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]