Author: akv
Date: 2013-05-06 10:41:18 +0200 (Mon, 06 May 2013)
New Revision: 4390

Modified:
   branches/4175-enfuse/src/application.c
   branches/4175-enfuse/src/application.h
   branches/4175-enfuse/src/rs-actions.c
   branches/4175-enfuse/src/rs-enfuse.c
Log:
Added caching for Enfuseing - makes everything go a little bit snappier, but 
will take up a lot of memory if enfusing a lot of photos.

Modified: branches/4175-enfuse/src/application.c
===================================================================
--- branches/4175-enfuse/src/application.c      2013-05-06 08:15:01 UTC (rev 
4389)
+++ branches/4175-enfuse/src/application.c      2013-05-06 08:41:18 UTC (rev 
4390)
@@ -212,6 +212,7 @@
        rs->queue = rs_batch_new_queue(rs);
        rs->current_setting = 0;
        rs->signal = MAIN_SIGNAL_NONE;
+       rs->enfuse_cache = NULL;
 
        /* Build basic filter chain */
        rs->filter_input = rs_filter_new("RSInputImage16", NULL);

Modified: branches/4175-enfuse/src/application.h
===================================================================
--- branches/4175-enfuse/src/application.h      2013-05-06 08:15:01 UTC (rev 
4389)
+++ branches/4175-enfuse/src/application.h      2013-05-06 08:41:18 UTC (rev 
4390)
@@ -81,6 +81,7 @@
        RSStore *store;
        RS_MAIN_SIGNAL signal; 
        gchar *post_open_event;
+       GHashTable *enfuse_cache;
 
        /* These should be moved to a future RS_WINDOW */
        GtkWidget *window;

Modified: branches/4175-enfuse/src/rs-actions.c
===================================================================
--- branches/4175-enfuse/src/rs-actions.c       2013-05-06 08:15:01 UTC (rev 
4389)
+++ branches/4175-enfuse/src/rs-actions.c       2013-05-06 08:41:18 UTC (rev 
4390)
@@ -1546,6 +1546,14 @@
   return TRUE;
 }
 
+guint enfuse_cache_hash (gconstpointer key) {
+  return g_str_hash(key);
+}
+
+gboolean enfuse_cache_hash_equal (gconstpointer a, gconstpointer b) {
+  return g_str_equal(a, b);
+}
+
 ACTION(enfuse)
 {
   rs_preview_widget_blank((RSPreviewWidget *) rs->preview);
@@ -1576,6 +1584,10 @@
   rs_preview_widget_lock_renderer((RSPreviewWidget *) rs->preview);
   GUI_CATCHUP();
 
+  /* initialize cache system */
+  if (!rs->enfuse_cache)
+    rs->enfuse_cache = g_hash_table_new(enfuse_cache_hash, 
enfuse_cache_hash_equal);
+
   gui_set_busy(TRUE);
   GList *thumbs = get_thumbnails_from_list(selected_names);
   gchar *thumb = rs_enfuse(rs, thumbs, TRUE, 250);
@@ -1673,6 +1685,8 @@
   gchar *filename = rs_enfuse(rs, selected_names, FALSE, -1);
   gui_set_busy(FALSE);
 
+  /* FIXME: cleanup rs->enfuse_cache and free everything in it */
+
   g_list_free(selected_names);
   rs_cache_save_flags(filename, &priority, NULL, &enfuse);
 

Modified: branches/4175-enfuse/src/rs-enfuse.c
===================================================================
--- branches/4175-enfuse/src/rs-enfuse.c        2013-05-06 08:15:01 UTC (rev 
4389)
+++ branches/4175-enfuse/src/rs-enfuse.c        2013-05-06 08:41:18 UTC (rev 
4390)
@@ -88,9 +88,15 @@
       return (gint) (sum/num);
 }
 
-gint export_image(gchar *filename, RSOutput *output, RSFilter *filter, gint 
snapshot, double exposure, gchar *outputname, gint boundingbox, RSFilter 
*resample) {
+gint export_image(gchar *filename, GHashTable *cache, RSOutput *output, 
RSFilter *filter, gint snapshot, double exposure, gchar *outputname, gint 
boundingbox, RSFilter *resample) {
+  RS_PHOTO *photo = (RS_PHOTO *) g_hash_table_lookup(cache, filename);
+  if (!photo)
+    {
+      photo = rs_photo_load_from_file(filename);
+      g_hash_table_insert(cache, filename, photo);
+      printf("Adding %s to cache\n", filename);
+    }
 
-  RS_PHOTO *photo = rs_photo_load_from_file(filename);
   if (photo)
     {
       rs_metadata_load_from_file(photo->metadata, filename);
@@ -125,7 +131,6 @@
 
       rs_output_set_from_conf(output, "batch");
       rs_output_execute(output, filter);
-      g_object_unref(photo);
 
       gint value = calculate_lightness(filter);
       printf("%s: %d\n", filename, value);
@@ -180,7 +185,7 @@
          output_unique = g_string_new(output_str->str);
          g_string_append_printf(output_unique, "%d", i);
          output_unique = g_string_append(output_unique, ".png");
-         lightness = export_image(name, output, fend, 0, 0.0, 
output_unique->str, boundingbox, fresample); /* FIXME: snapshot hardcoded */
+         lightness = export_image(name, rs->enfuse_cache, output, fend, 0, 
0.0, output_unique->str, boundingbox, fresample); /* FIXME: snapshot hardcoded 
*/
          exported_names = g_list_append(exported_names, 
g_strdup(output_unique->str));
          g_string_free(output_unique, TRUE);
 
@@ -208,7 +213,7 @@
          g_string_append_printf(output_unique, "_%.1f", (darkstep*n*-1));
          output_unique = g_string_append(output_unique, ".png");
          exported_names = g_list_append(exported_names, 
g_strdup(output_unique->str));
-         export_image(darkest, output, fend, 0, (darkstep*n*-1), 
output_unique->str, boundingbox, fresample); /* FIXME: snapshot hardcoded */
+         export_image(darkest, rs->enfuse_cache, output, fend, 0, 
(darkstep*n*-1), output_unique->str, boundingbox, fresample); /* FIXME: 
snapshot hardcoded */
          g_string_free(output_unique, TRUE);
          i++;
        }
@@ -220,7 +225,7 @@
          g_string_append_printf(output_unique, "_%.1f", (brightstep*n));
          output_unique = g_string_append(output_unique, ".png");
          exported_names = g_list_append(exported_names, 
g_strdup(output_unique->str));
-         export_image(brightest, output, fend, 0, (brightstep*n), 
output_unique->str, boundingbox, fresample); /* FIXME: snapshot hardcoded */
+         export_image(brightest, rs->enfuse_cache, output, fend, 0, 
(brightstep*n), output_unique->str, boundingbox, fresample); /* FIXME: snapshot 
hardcoded */
          g_string_free(output_unique, TRUE);
          i++;
        }


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to