From 153d8c93e25767d5d50958f2fc6a4579d38c0a1d Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 6 Jan 2021 19:12:11 +1100 Subject: [PATCH] Wait for postprocess process to complete before updating preview Fixes #27 Fixes #28 --- main.c | 4 ++-- postprocess.sh | 3 +++ process_pipeline.c | 48 +++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 675f565..90bf1af 100644 --- a/main.c +++ b/main.c @@ -169,7 +169,7 @@ draw_surface_scaled_centered(cairo_t *cr, uint32_t dst_width, uint32_t dst_heigh static bool capture_completed(const char *fname) { - strncpy(last_path, fname, 260); + strncpy(last_path, fname, 259); // Create a thumbnail from the current surface cairo_surface_t *thumb = @@ -330,7 +330,7 @@ on_open_last_clicked(GtkWidget *widget, gpointer user_data) if (strlen(last_path) == 0) { return; } - sprintf(uri, "file://%s.tiff", last_path); + sprintf(uri, "file://%s", last_path); if (!g_app_info_launch_default_for_uri(uri, NULL, &error)) { g_printerr("Could not launch image viewer: %s\n", error->message); } diff --git a/postprocess.sh b/postprocess.sh index 02bcac4..5d43223 100755 --- a/postprocess.sh +++ b/postprocess.sh @@ -65,8 +65,11 @@ if [ -n "$DCRAW" ]; then -overwrite_original "$TARGET_NAME.jpg" fi + echo "$TARGET_NAME.jpg" else cp "$MAIN_PICTURE.$TIFF_EXT" "$TARGET_NAME.tiff" + + echo "$TARGET_NAME.tiff" fi fi diff --git a/process_pipeline.c b/process_pipeline.c index a706176..4dae415 100644 --- a/process_pipeline.c +++ b/process_pipeline.c @@ -301,6 +301,28 @@ process_image_for_capture(const MPImage *image, int count) TIFFClose(tif); } +static void +post_process_finished(GSubprocess *proc, GAsyncResult *res, gpointer user_data) +{ + char *stdout; + g_subprocess_communicate_utf8_finish(proc, res, &stdout, NULL, NULL); + + // The last line contains the file name + int end = strlen(stdout); + // Skip the newline at the end + stdout[--end] = '\0'; + + char *path = path = stdout + end - 1; + do { + if (*path == '\n') { + break; + } + --path; + } while (path > stdout); + + mp_main_capture_completed(path); +} + static void process_capture_burst() { @@ -315,9 +337,27 @@ process_capture_burst() // Start post-processing the captured burst g_print("Post process %s to %s.ext\n", burst_dir, capture_fname); - char command[1024]; - sprintf(command, "%s %s %s &", processing_script, burst_dir, capture_fname); - system(command); + GError *error = NULL; + GSubprocess *proc = g_subprocess_new( + G_SUBPROCESS_FLAGS_STDOUT_PIPE, + &error, + processing_script, + burst_dir, + capture_fname, + NULL); + + if (!proc) { + g_printerr("Failed to spawn postprocess process: %s\n", + error->message); + return; + } + + g_subprocess_communicate_utf8_async( + proc, + NULL, + NULL, + (GAsyncReadyCallback)post_process_finished, + NULL); } static void @@ -335,8 +375,6 @@ process_image(MPPipeline *pipeline, const MPImage *image) if (captures_remaining == 0) { process_capture_burst(); - - mp_main_capture_completed(capture_fname); } }