Add option to GUI to load rendered images from different prefix
[colorize.git] / gui / main.c
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();