From 46b07c6c4d41665e6a3177089796a059e19dc651 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Fri, 24 Jun 2022 14:10:01 +0200 Subject: [PATCH] Move postprocessor script to a gsetting (MR 18) --- data/org.postmarketos.Megapixels.gschema.xml | 9 +++++++ src/io_pipeline.c | 4 --- src/io_pipeline.h | 1 - src/main.c | 26 +++++++++++--------- src/process_pipeline.c | 21 +++++++--------- src/process_pipeline.h | 4 +-- 6 files changed, 34 insertions(+), 31 deletions(-) diff --git a/data/org.postmarketos.Megapixels.gschema.xml b/data/org.postmarketos.Megapixels.gschema.xml index b175f7e..a581bc9 100644 --- a/data/org.postmarketos.Megapixels.gschema.xml +++ b/data/org.postmarketos.Megapixels.gschema.xml @@ -11,5 +11,14 @@ up after processing. + + '' + Path to the postprocessor script + + When set this will define the absolute path to a postprocessor to use after + taking a picture. When empty megapixels will default to the legacy + postprocess.sh lookup + + diff --git a/src/io_pipeline.c b/src/io_pipeline.c index dd7bf63..12a26a8 100644 --- a/src/io_pipeline.c +++ b/src/io_pipeline.c @@ -81,8 +81,6 @@ static int preview_height; static int device_rotation; -static bool save_dng; - struct control_state { bool gain_is_manual; int gain; @@ -344,7 +342,6 @@ update_process_pipeline() .camera = camera, .mode = mode, .burst_length = burst_length, - .save_dng = save_dng, .preview_width = preview_width, .preview_height = preview_height, .device_rotation = device_rotation, @@ -691,7 +688,6 @@ update_state(MPPipeline *pipeline, const struct mp_io_pipeline_state *state) preview_width = state->preview_width; preview_height = state->preview_height; device_rotation = state->device_rotation; - save_dng = state->save_dng; if (camera) { struct control_state previous_desired = desired_controls; diff --git a/src/io_pipeline.h b/src/io_pipeline.h index cecb2dc..00671c5 100644 --- a/src/io_pipeline.h +++ b/src/io_pipeline.h @@ -18,7 +18,6 @@ struct mp_io_pipeline_state { bool exposure_is_manual; int exposure; - bool save_dng; bool flash_enabled; }; diff --git a/src/main.c b/src/main.c index 68494c6..4eafd4d 100644 --- a/src/main.c +++ b/src/main.c @@ -55,8 +55,6 @@ static bool has_auto_focus_start; static bool flash_enabled = false; -static bool setting_save_dng; - static MPProcessPipelineBuffer *current_preview_buffer = NULL; static int preview_buffer_width = -1; static int preview_buffer_height = -1; @@ -110,7 +108,6 @@ update_io_pipeline() .gain = gain, .exposure_is_manual = exposure_is_manual, .exposure = exposure, - .save_dng = setting_save_dng, .flash_enabled = flash_enabled, }; mp_io_pipeline_update_state(&io_state); @@ -701,14 +698,6 @@ static void run_close_settings_action(GSimpleAction *action, GVariant *param, gpointer user_data) { gtk_stack_set_visible_child_name(GTK_STACK(main_stack), "main"); - - // Update settings - bool save_dng = g_settings_get_boolean(settings, "save-raw"); - - if (save_dng != setting_save_dng) { - setting_save_dng = save_dng; - update_io_pipeline(); - } } static void @@ -1061,13 +1050,26 @@ activate(GtkApplication *app, gpointer data) // Setup settings settings = g_settings_new("org.postmarketos.Megapixels"); + char* setting_postproc = g_settings_get_string(settings, "postprocessor"); + + // Initialize the postprocessing gsetting to the old processor if + // it was not set yet + if(setting_postproc == NULL || setting_postproc[0] == '\0') { + printf("Initializing postprocessor gsetting\n"); + setting_postproc = malloc(512); + if(!mp_process_find_processor(setting_postproc)) { + printf("No processor found\n"); + exit(1); + } + g_settings_set_string(settings, "postprocessor", setting_postproc); + printf("Initialized postprocessor to %s\n", setting_postproc); + } g_settings_bind(settings, "save-raw", setting_dng_button, "active", G_SETTINGS_BIND_DEFAULT); - setting_save_dng = g_settings_get_boolean(settings, "save-raw"); // Listen for phosh rotation GDBusConnection *conn = diff --git a/src/process_pipeline.c b/src/process_pipeline.c index 7bd3e4a..194b899 100644 --- a/src/process_pipeline.c +++ b/src/process_pipeline.c @@ -22,7 +22,6 @@ static const float colormatrix_srgb[] = { 3.2409, -1.5373, -0.4986, -0.9692, 1.8 static MPPipeline *pipeline; static char burst_dir[23]; -static char processing_script[512]; static volatile bool is_capturing = false; static volatile int frames_processed = 0; @@ -53,10 +52,10 @@ static int exposure; static bool flash_enabled; -static bool save_dng; - static char capture_fname[255]; +static GSettings *settings; + static void register_custom_tiff_tags(TIFF *tif) { @@ -77,8 +76,8 @@ register_custom_tiff_tags(TIFF *tif) sizeof(custom_fields) / sizeof(custom_fields[0])); } -static bool -find_processor(char *script) +bool +mp_process_find_processor(char *script) { char filename[] = "postprocess.sh"; @@ -118,11 +117,7 @@ static void setup(MPPipeline *pipeline, const void *data) { TIFFSetTagExtender(register_custom_tiff_tags); - - if (!find_processor(processing_script)) { - g_printerr("Could not find any post-process script\n"); - exit(1); - } + settings = g_settings_new("org.postmarketos.Megapixels"); } void @@ -655,6 +650,9 @@ process_capture_burst(GdkTexture *thumb) timestamp); } + bool save_dng = g_settings_get_boolean(settings, "save-raw"); + char* postprocessor = g_settings_get_string(settings, "postprocessor"); + char save_dng_s[2] = "0"; if (save_dng) { save_dng_s[0] = '1'; @@ -668,7 +666,7 @@ process_capture_burst(GdkTexture *thumb) g_autoptr(GError) error = NULL; GSubprocess *proc = g_subprocess_new(G_SUBPROCESS_FLAGS_STDOUT_PIPE, &error, - processing_script, + postprocessor, burst_dir, capture_fname, save_dng_s, @@ -863,7 +861,6 @@ update_state(MPPipeline *pipeline, const struct mp_process_pipeline_state *state device_rotation = state->device_rotation; burst_length = state->burst_length; - save_dng = state->save_dng; // gain_is_manual = state->gain_is_manual; gain = state->gain; diff --git a/src/process_pipeline.h b/src/process_pipeline.h index 1225db9..4ed3a7a 100644 --- a/src/process_pipeline.h +++ b/src/process_pipeline.h @@ -27,10 +27,10 @@ struct mp_process_pipeline_state { bool has_auto_focus_start; bool flash_enabled; - - bool save_dng; }; +bool mp_process_find_processor(char *script); + void mp_process_pipeline_start(); void mp_process_pipeline_stop(); void mp_process_pipeline_sync();