[niepce] Reset the view in the darkroom module when nothing is selected Put up a placeholder.



commit d86ce18de32b8041433cbf5745461ce216d47b5f
Author: Hubert Figuière <hub figuiere net>
Date:   Sat Jun 29 13:38:44 2013 -0400

    Reset the view in the darkroom module when nothing is selected
    Put up a placeholder.

 src/ncr/image.cpp                              |   41 ++++++++++++++++++++---
 src/ncr/image.hpp                              |   11 ++++++
 src/niepce/modules/darkroom/darkroommodule.cpp |   18 +++++++---
 3 files changed, 58 insertions(+), 12 deletions(-)
---
diff --git a/src/ncr/image.cpp b/src/ncr/image.cpp
index 02572d3..1669619 100644
--- a/src/ncr/image.cpp
+++ b/src/ncr/image.cpp
@@ -73,6 +73,8 @@ struct Image::Private {
     GeglNode* _scale_node();
     GeglNode* _load_dcraw(const std::string &path);
     GeglNode* _load_raw(const std::string &path);
+
+    Glib::RefPtr<Gdk::Pixbuf> m_pixbuf_cache;
 };
 
 Image::Image()
@@ -197,15 +199,36 @@ GeglNode* Image::Private::_scale_node()
     return gegl_node_new_child(m_graph, "operation", "gegl:scale", nullptr);
 }
 
-void Image::reload(const std::string & p, bool is_raw,
-    int orientation)
-{
-    GeglNode* load_file;
 
+void Image::prepare_reload()
+{
     priv->m_status = STATUS_LOADING;
+    priv->m_pixbuf_cache.reset();
 
+    if(priv->m_graph) {
+        g_object_unref(priv->m_graph);
+    }
     priv->m_graph = gegl_node_new();
 //    priv->m_graph->set("format", babl_format("RGB u16"));
+}
+
+void Image::reload(const Glib::RefPtr<Gdk::Pixbuf> & p)
+{
+    prepare_reload();
+    priv->m_pixbuf_cache = p;
+    GeglNode* load_file = gegl_node_new_child(priv->m_graph,
+                                              "operation", "gegl:pixbuf",
+                                              "pixbuf", p->gobj(), nullptr);
+
+    reload_node(load_file, 0);
+}
+
+void Image::reload(const std::string & p, bool is_raw,
+    int orientation)
+{
+    prepare_reload();
+
+    GeglNode* load_file;
 
     DBG_OUT("loading file %s", p.c_str());
 
@@ -217,6 +240,12 @@ void Image::reload(const std::string & p, bool is_raw,
     else {
         load_file = priv->_load_dcraw(p);
     }
+    reload_node(load_file, orientation);
+}
+
+void Image::reload_node(GeglNode* node, int orientation)
+{
+    DBG_ASSERT(priv->m_status == STATUS_LOADING, "prepare_reload() might not have been called");
 
     priv->m_rotate_n = priv->_rotate_node(orientation);
     priv->m_scale = priv->_scale_node();
@@ -227,7 +256,7 @@ void Image::reload(const std::string & p, bool is_raw,
 //                            "format", babl_format("RGB u8"),
 //                            "buffer", &(priv->m_sink_buffer), nullptr);
 
-    gegl_node_link_many(load_file, priv->m_rotate_n,
+    gegl_node_link_many(node, priv->m_rotate_n,
                         priv->m_scale, priv->m_sink, nullptr);
 
 //    gegl_node_process(priv->m_sink);
@@ -249,7 +278,7 @@ void Image::reload(const std::string & p, bool is_raw,
     // END DEBUG
 
     int width, height;
-    GeglRectangle rect = gegl_node_get_bounding_box(load_file);
+    GeglRectangle rect = gegl_node_get_bounding_box(node);
     width = rect.width;
     height = rect.height;
     DBG_OUT("width %d height %d", width, height);
diff --git a/src/ncr/image.hpp b/src/ncr/image.hpp
index ee85c12..5242fd3 100644
--- a/src/ncr/image.hpp
+++ b/src/ncr/image.hpp
@@ -27,6 +27,8 @@
 
 #include <gdkmm/pixbuf.h>
 
+typedef struct _GeglNode  GeglNode;
+
 namespace ncr {
 
 class Image
@@ -61,6 +63,7 @@ public:
 
     void reload(const std::string & p, bool is_raw,
         int orientation);
+    void reload(const Glib::RefPtr<Gdk::Pixbuf> & p);
     /** set the output scale */
     void set_output_scale(double scale);
 
@@ -86,6 +89,14 @@ public:
     sigc::signal<void> signal_update;
 private:
 
+    /** Call this to initialise the reload process */
+    void prepare_reload();
+    /** continue the reload
+     * @param node the node for the loaded image
+     * @param orientation the exif orientation.
+     */
+    void reload_node(GeglNode* node, int orientation);
+
     /** rotate by x degrees (orientation)
      *  ensure the end results is within 0..359.
      */
diff --git a/src/niepce/modules/darkroom/darkroommodule.cpp b/src/niepce/modules/darkroom/darkroommodule.cpp
index 77bf9ff..59cf615 100644
--- a/src/niepce/modules/darkroom/darkroommodule.cpp
+++ b/src/niepce/modules/darkroom/darkroommodule.cpp
@@ -1,7 +1,7 @@
 /*
  * niepce - ui/darkroommodule.cpp
  *
- * Copyright (C) 2008 Hubert Figuiere
+ * Copyright (C) 2008-2013 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -56,21 +56,27 @@ void DarkroomModule::reload_image()
         const std::string& path = file->path();
         m_image->reload(path, isRaw,
                         file->orientation());
-        m_need_reload = false;
     }
     else {
         // reset
+        Glib::RefPtr<Gdk::Pixbuf> p = Gdk::Pixbuf::create_from_file(
+            DATADIR"/niepce/pixmaps/niepce-image-generic.png");
+        m_image->reload(p);
     }
+    m_need_reload = false;
 }
 
 void DarkroomModule::set_image(const eng::LibFile::Ptr & file)
 {
     if(m_imagefile.expired() || (file != m_imagefile.lock())) {
         m_imagefile = eng::LibFile::WeakPtr(file);
-        m_need_reload = true;
-        if(m_active) {
-            reload_image();
-        }
+    }
+    else {
+        m_imagefile.reset();
+    }
+    m_need_reload = true;
+    if(m_active) {
+        reload_image();
     }
 }
 


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