Add option to GUI to load rendered images from different prefix
authorAndreas Eversberg <jolly@eversberg.eu>
Mon, 19 Oct 2015 20:04:25 +0000 (22:04 +0200)
committerAndreas Eversberg <jolly@eversberg.eu>
Sat, 14 May 2016 10:55:54 +0000 (12:55 +0200)
gui/image.c
gui/main.c
gui/main.h

index bd5804c..6a971ef 100644 (file)
@@ -101,10 +101,14 @@ void create_rendered(const char *filename)
 
        p = filename;
        while((q = strchr(p, DIR_SEPERATOR)))
-       p = q + 1;
-       strcpy(imgfile, filename);
-       imgfile[p - filename] = '\0';
-       strcat(imgfile, "colorized_");
+               p = q + 1;
+       if (output_prefix[0] == '\0') {
+               strcpy(imgfile, filename);
+               imgfile[p - filename] = '\0';
+               strcat(imgfile, "colorized_");
+       } else {
+               strcpy(imgfile, output_prefix);
+       }
        strcat(imgfile, p);
 
        img_preview_buffer = load_img(&width, &height, imgfile, 0);
index 4a04a8e..8349476 100644 (file)
@@ -3,6 +3,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <getopt.h>
 #include "../src/mark.h"
 #ifdef WITH_OPENCV
 #include "../src/opticalflow.h"
@@ -38,6 +39,7 @@ int last_x = 0, last_y = 0; /* where mouse is over scrolled view */
 int brush_size;
 int mark = 1, highlight = 0, preview = 0, rendered = 0, draw_mode = 1, move_mode = 0, fill_mode = 0, pick_mode = 0, flowview = 0;
 int mouse_over_palette_area = 0, mouse_over_drawing_area = 0, mouse_over_timeline_area = 0;
+char output_prefix[256] = "";
 #define min(x,y) ((x < y) ? x : y)
 #define abs(x,y) ((x < y) ? y - x : x - y)
 
@@ -562,6 +564,57 @@ void palette_edited(GtkCellRendererText *renderer, gchar *path, gchar *new_text,
 }
 
 /*
+ * commandline help
+ */
+static void print_help(const char *app)
+{
+       printf("Colorize version %s\n\n",
+#include "../version.h"
+       );
+       printf("Usage: %s [options] [<image file>]\n", app);
+       printf("        Run colorize editor optionally with given image file.\n");
+       printf("\nOptions:\n");
+       printf(" -h --help                           This help\n");
+       printf(" -O --output-prefix <path>/<prefix>  Store rendered image using this prefix instead of \"colorized_\"\n");
+}
+
+/*
+ * command line options
+ */
+static int handle_options(int argc, char **argv)
+{
+       int skip_args = 0;
+
+       while (1) {
+               int option_index = 0, c;
+               static struct option long_options[] = {
+                       {"help", 0, 0, 'h'},
+                       {"output-prefix", 1, 0, 'O'},
+                       {0, 0, 0, 0},
+               };
+
+               c = getopt_long(argc, argv, "hO:", long_options, &option_index);
+
+               if (c == -1)
+                       break;
+
+               switch (c) {
+               case 'h':
+                       print_help(argv[0]);
+                       exit(0);
+               case 'O':
+                       strcpy(output_prefix, optarg);
+                       skip_args += 2;
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       return skip_args;
+}
+
+/*
  * creation of main window
  */
 
@@ -574,6 +627,11 @@ int main(int argc, char *argv[])
        GtkTreeSelection *selection;
        GtkTreeViewColumn *palette_column;
        GtkCellRenderer *palette_renderer;
+       int skip_args;
+
+       skip_args = handle_options(argc, argv);
+       argc -= skip_args;
+       argv += skip_args;
 
 //     g_thread_init(NULL); (not required, it is done automatically)
        gdk_threads_init();
index 5f8faa1..a28dd70 100644 (file)
@@ -28,4 +28,4 @@ void set_button_toggel_by_label(enum toggle_label label, gboolean active);
 
 extern int brush_size;
 extern int mark, highlight, preview, rendered, draw_mode, move_mode, fill_mode, pick_mode, flowview;
-
+extern char output_prefix[];