gboolean rs_external_editor_gimp(RS_PHOTO *photo, RSFilter *prior_to_resample, guint snapshot) { #ifdef WIN32 return FALSE; #else RSOutput *output = NULL; g_assert(RS_IS_PHOTO(photo)); // We need at least GIMP 2.4.0 to export photo if (!rs_has_gimp(2,4,0)) { return FALSE; } DBusConnection *bus; DBusMessage *message, *reply; GString *filename; bus = dbus_bus_get (DBUS_BUS_SESSION, NULL); gchar* org_name = g_path_get_basename(photo->filename); gchar* org_name_noext = g_utf8_strchr(org_name, -1, '.'); /* Terminate string there */ if (NULL != org_name_noext) org_name_noext[0] = 0; filename = g_string_new(""); g_string_printf(filename, "%s/%s-rawstudio_%.0f.png",g_get_tmp_dir(), org_name, g_random_double()*10000); g_free(org_name); /* Setup our filter chain for saving */ RSFilter *ftransform_input = rs_filter_new("RSColorspaceTransform", prior_to_resample); RSFilter *fdcp = rs_filter_new("RSDcp", ftransform_input); RSFilter *fdenoise= rs_filter_new("RSDenoise", fdcp); RSFilter *ftransform_display = rs_filter_new("RSColorspaceTransform", fdenoise); RSFilter *fend = ftransform_display; GList *filters = g_list_append(NULL, fend); rs_photo_apply_to_filters(photo, filters, snapshot); g_list_free(filters); output = rs_output_new("RSPngfile"); g_object_set(output, "filename", filename->str, NULL); g_object_set(output, "save16bit", FALSE, NULL); g_object_set(output, "copy-metadata", TRUE, NULL); rs_output_execute(output, fend); g_object_unref(output); g_object_unref(ftransform_input); g_object_unref(ftransform_display); g_object_unref(fdenoise); g_object_unref(fdcp); message = dbus_message_new_method_call("org.gimp.GIMP.UI", "/org/gimp/GIMP/UI", "org.gimp.GIMP.UI", "OpenAsNew"); dbus_message_append_args (message, DBUS_TYPE_STRING, &filename->str, DBUS_TYPE_INVALID); /* Send DBus message to GIMP */ reply = dbus_connection_send_with_reply_and_block (bus, message, -1, NULL); /* If we didn't get a reply from GIMP - we try to start it and resend the message */ if (!reply) { gint retval = system("gimp &"); if (retval != 0) { g_warning("system(\"gimp &\") returned: %d\n", retval); g_unlink(filename->str); g_string_free(filename, TRUE); dbus_message_unref (message); return FALSE; } } /* Allow GIMP to start - we send the message every one second */ while (!reply) { gint i = 0; if (i > EXPORT_TO_GIMP_TIMEOUT_SECONDS) { g_warning("Never got a reply from GIMP - deleting temporary file"); g_unlink(filename->str); g_string_free(filename, TRUE); dbus_message_unref (message); return FALSE; } sleep(1); i++; reply = dbus_connection_send_with_reply_and_block (bus, message, -1, NULL); } dbus_message_unref (message); /* Depends on GIMP DBus signal: 'Opened' */ if (rs_has_gimp(2,6,2)) { /* Connect to GIMP and listen for "Opened" signal */ dbus_bus_add_match (bus, "type='signal',interface='org.gimp.GIMP.UI'", NULL); dbus_connection_add_filter(bus, dbus_gimp_opened, filename->str , NULL); g_string_free(filename, FALSE); } else { /* Old sad way - GIMP doesn't let us know that it has opened the photo */ g_warning("You have an old version of GIMP and we suggest that you upgrade to at least 2.6.2"); g_warning("Rawstudio will stop responding for 10 seconds while it waits for GIMP to open the file"); sleep(10); g_unlink(filename->str); g_string_free(filename, TRUE); } return TRUE; #endif }
GList * export_images(RS_BLOB *rs, GList *files, gboolean extend, gint dark, gfloat darkstep, gint bright, gfloat brightstep, gint boundingbox, gboolean quick) { gint num_selected = g_list_length(files); gint i = 0; gchar *name; GString *output_str = g_string_new(g_get_tmp_dir()); output_str = g_string_append(output_str, "/"); output_str = g_string_append(output_str, ".rawstudio-enfuse-"); GString *output_unique = NULL; /* a simple chain - we wanna use the "original" image with only white balance corrected and nothing else to get the best result */ RSFilter *ftransform_input = rs_filter_new("RSColorspaceTransform", rs->filter_demosaic_cache); RSFilter *fdcp= rs_filter_new("RSDcp", ftransform_input); RSFilter *fresample= rs_filter_new("RSResample", fdcp); RSFilter *ftransform_display = rs_filter_new("RSColorspaceTransform", fresample); RSFilter *fend = ftransform_display; RSOutput *output = rs_output_new("RSPngfile"); GList *exported_names = NULL; if (g_object_class_find_property(G_OBJECT_GET_CLASS(output), "save16bit")) g_object_set(output, "save16bit", !quick, NULL); /* We get odd results if we use 16 bit output - probably due to liniearity */ if (g_object_class_find_property(G_OBJECT_GET_CLASS(output), "copy-metadata")) g_object_set(output, "copy-metadata", TRUE, NULL); /* Doesn't make sense to enable - Enfuse doesn't copy it */ if (g_object_class_find_property(G_OBJECT_GET_CLASS(output), "quick")) g_object_set(output, "quick", quick, NULL); /* Allow for quick exports when generating thumbnails */ gint lightness = 0; gint darkval = 255; gint brightval = 0; gchar *darkest = NULL; gchar *brightest = NULL; num_selected = g_list_length(files); if (g_list_length(files)) { for(i=0; i<num_selected; i++) { name = (gchar*) g_list_nth_data(files, i); 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, 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); if (lightness > brightval) { brightval = lightness; brightest = g_strdup(name); } if (lightness < darkval) { darkval = lightness; darkest = g_strdup(name); } } } if (extend) { gint n; for (n = 1; n <= dark; n++) { output_unique = g_string_new(output_str->str); g_string_append_printf(output_unique, "%d", i); 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, rs->enfuse_cache, output, fend, 0, (darkstep*n*-1), output_unique->str, boundingbox, fresample); /* FIXME: snapshot hardcoded */ g_string_free(output_unique, TRUE); i++; } g_free(darkest); for (n = 1; n <= bright; n++) { output_unique = g_string_new(output_str->str); g_string_append_printf(output_unique, "%d", i); 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, rs->enfuse_cache, output, fend, 0, (brightstep*n), output_unique->str, boundingbox, fresample); /* FIXME: snapshot hardcoded */ g_string_free(output_unique, TRUE); i++; } g_free(brightest); } /* FIXME: shouldn't 'files' be freed here? It breaks RSStore... */ return exported_names; }