Browse Source

Add postprocessor setting dropdown (MR 18)

Martijn Braam 2 years ago
parent
commit
ee26b8e6f7
4 changed files with 127 additions and 18 deletions
  1. 27 0
      data/camera.ui
  2. 28 15
      src/main.c
  3. 70 3
      src/process_pipeline.c
  4. 2 0
      src/process_pipeline.h

+ 27 - 0
data/camera.ui

@@ -1,6 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk" version="4.0"/>
+  <object class="GtkListStore" id="list-postprocessors">
+    <columns>
+      <column type="gchararray"/>
+      <column type="gchararray"/>
+    </columns>
+  </object>
   <object class="GtkWindow" id="window">
     <property name="can-focus">0</property>
     <property name="default-width">360</property>
@@ -247,6 +253,27 @@
                             </child>
                           </object>
                         </child>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="visible">True</property>
+                            <property name="halign">start</property>
+                            <property name="label">Postprocessor</property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkComboBox" id="setting-processor">
+                            <property name="visible">True</property>
+                            <property name="model">list-postprocessors</property>
+                            <property name="entry-text-column">1</property>
+                            <property name="id-column">0</property>
+                            <child>
+                              <object class="GtkCellRendererText"/>
+                              <attributes>
+                                <attribute name="text">1</attribute>
+                              </attributes>
+                            </child>
+                          </object>
+                        </child>
                         <child>
                           <object class="GtkCheckButton" id="setting-raw">
                             <property name="label">Save raw files</property>

+ 28 - 15
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");
-
-	// 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);
-	}
+        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);
+        }
+
+        // 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 =

+ 70 - 3
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) {

+ 2 - 0
src/process_pipeline.h

@@ -2,6 +2,7 @@
 
 #include "camera.h"
 #include "camera_config.h"
+#include <gtk/gtk.h>
 
 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();