From ee26b8e6f7956def3ae8cc8382a614d162d1cc6e Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Fri, 24 Jun 2022 14:53:30 +0200 Subject: [PATCH] Add postprocessor setting dropdown (MR 18) --- data/camera.ui | 27 ++++++++++++++++ src/main.c | 41 ++++++++++++++++-------- src/process_pipeline.c | 73 ++++++++++++++++++++++++++++++++++++++++-- src/process_pipeline.h | 2 ++ 4 files changed, 126 insertions(+), 17 deletions(-) diff --git a/data/camera.ui b/data/camera.ui index b895e5c..daea9c7 100644 --- a/data/camera.ui +++ b/data/camera.ui @@ -1,6 +1,12 @@ + + + + + + 0 360 @@ -247,6 +253,27 @@ + + + True + start + Postprocessor + + + + + True + list-postprocessors + 1 + 0 + + + + 1 + + + + Save raw files diff --git a/src/main.c b/src/main.c index 4eafd4d..ea867ee 100644 --- a/src/main.c +++ b/src/main.c @@ -1001,6 +1001,10 @@ activate(GtkApplication *app, gpointer data) GTK_WIDGET(gtk_builder_get_object(builder, "flash-controls-button")); GtkWidget *setting_dng_button = GTK_WIDGET(gtk_builder_get_object(builder, "setting-raw")); + GtkWidget *setting_postprocessor_combo = + GTK_WIDGET(gtk_builder_get_object(builder, "setting-processor")); + GtkListStore *setting_postprocessor_list = GTK_LIST_STORE( + gtk_builder_get_object(builder, "list-postprocessors")); preview = GTK_WIDGET(gtk_builder_get_object(builder, "preview")); main_stack = GTK_WIDGET(gtk_builder_get_object(builder, "main_stack")); open_last_stack = @@ -1050,26 +1054,35 @@ activate(GtkApplication *app, gpointer data) // Setup settings settings = g_settings_new("org.postmarketos.Megapixels"); - char* setting_postproc = g_settings_get_string(settings, "postprocessor"); + 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); - } + // 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); + } + + // Find all postprocessors for the settings list + mp_process_find_all_processors(setting_postprocessor_list); + + // Bind settings widgets to the actual settings g_settings_bind(settings, "save-raw", setting_dng_button, "active", G_SETTINGS_BIND_DEFAULT); - + g_settings_bind(settings, + "postprocessor", + setting_postprocessor_combo, + "active-id", + G_SETTINGS_BIND_DEFAULT); // Listen for phosh rotation GDBusConnection *conn = diff --git a/src/process_pipeline.c b/src/process_pipeline.c index 194b899..e6db37e 100644 --- a/src/process_pipeline.c +++ b/src/process_pipeline.c @@ -76,6 +76,73 @@ register_custom_tiff_tags(TIFF *tif) sizeof(custom_fields) / sizeof(custom_fields[0])); } +void +mp_process_find_all_processors(GtkListStore *store) +{ + GtkTreeIter iter; + char buffer[512]; + // Find all the original postprocess.sh locations + + // Check postprocess.sh in the current working directory + if (access("./data/postprocess.sh", F_OK) != -1) { + gtk_list_store_insert(store, &iter, -1); + gtk_list_store_set(store, + &iter, + 0, + "./data/postprocess.sh", + 1, + "(cwd) postprocess.sh", + -1); + } + + // Check for a script in XDG_CONFIG_HOME + sprintf(buffer, "%s/megapixels/postprocess.sh", g_get_user_config_dir()); + if (access(buffer, F_OK) != -1) { + gtk_list_store_insert(store, &iter, -1); + gtk_list_store_set( + store, &iter, 0, buffer, 1, "(user) postprocess.sh", -1); + } + + // Check user overridden /etc/megapixels/postprocessor.sh + sprintf(buffer, "%s/megapixels/postprocess.sh", SYSCONFDIR); + if (access(buffer, F_OK) != -1) { + gtk_list_store_insert(store, &iter, -1); + gtk_list_store_set( + store, &iter, 0, buffer, 1, "(system) postprocess.sh", -1); + } + + // Check user overridden /usr/share/megapixels/postprocessor.sh + sprintf(buffer, "%s/megapixels/postprocess.sh", DATADIR); + if (access(buffer, F_OK) != -1) { + gtk_list_store_insert(store, &iter, -1); + gtk_list_store_set( + store, &iter, 0, buffer, 1, "(built-in) postprocess.sh", -1); + } + + // Find extra packaged postprocessor scripts + // These should be packaged in + // /usr/share/megapixels/postprocessor.d/executable + sprintf(buffer, "%s/megapixels/postprocessor.d", DATADIR); + DIR *d; + struct dirent *dir; + d = opendir(buffer); + if (d) { + while ((dir = readdir(d)) != NULL) { + if (dir->d_name[0] == '.') { + continue; + } + sprintf(buffer, + "%s/megapixels/postprocessor.d/%s", + DATADIR, + dir->d_name); + gtk_list_store_insert(store, &iter, -1); + gtk_list_store_set( + store, &iter, 0, buffer, 1, dir->d_name, -1); + } + closedir(d); + } +} + bool mp_process_find_processor(char *script) { @@ -117,7 +184,7 @@ static void setup(MPPipeline *pipeline, const void *data) { TIFFSetTagExtender(register_custom_tiff_tags); - settings = g_settings_new("org.postmarketos.Megapixels"); + settings = g_settings_new("org.postmarketos.Megapixels"); } void @@ -650,8 +717,8 @@ process_capture_burst(GdkTexture *thumb) timestamp); } - bool save_dng = g_settings_get_boolean(settings, "save-raw"); - char* postprocessor = g_settings_get_string(settings, "postprocessor"); + 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) { diff --git a/src/process_pipeline.h b/src/process_pipeline.h index 4ed3a7a..cbc1724 100644 --- a/src/process_pipeline.h +++ b/src/process_pipeline.h @@ -2,6 +2,7 @@ #include "camera.h" #include "camera_config.h" +#include typedef struct _GdkSurface GdkSurface; @@ -30,6 +31,7 @@ struct mp_process_pipeline_state { }; bool mp_process_find_processor(char *script); +void mp_process_find_all_processors(GtkListStore *store); void mp_process_pipeline_start(); void mp_process_pipeline_stop();