Forráskód Böngészése

Wait for postprocess process to complete before updating preview

Fixes #27
Fixes #28
Benjamin Schaaf 4 éve
szülő
commit
153d8c93e2
3 módosított fájl, 48 hozzáadás és 7 törlés
  1. 2 2
      main.c
  2. 3 0
      postprocess.sh
  3. 43 5
      process_pipeline.c

+ 2 - 2
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);
 	}

+ 3 - 0
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
 

+ 43 - 5
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);
 		}
 	}