213 if(!gtk_parse_args(&argc, &arg)) exit(1);
216 char *input_filename = NULL;
217 char *xmp_filename = NULL;
218 gchar *output_filename = NULL;
219 gchar *output_ext = NULL;
221 int file_counter = 0;
223 gboolean verbose =
FALSE, custom_presets =
TRUE, export_masks =
FALSE,
224 output_to_dir =
FALSE;
226 GList* inputs = NULL;
227 GList* imgids = NULL;
230 gchar *icc_filename = NULL;
234 for(
k = 1;
k < argc;
k++)
238 if(!strcmp(arg[
k],
"--help") || !strcmp(arg[
k],
"-h"))
242 if(!strcmp(arg[
k+1],
"icc-type"))
244 if(!strcmp(arg[
k+1],
"icc-intent"))
249 else if(!strcmp(arg[
k],
"--version"))
251 printf(
"this is ansel-cli %s\ncopyright (c) 2012-%s johannes hanika, tobias ellinghaus\n",
255 else if(!strcmp(arg[
k],
"--width") && argc >
k + 1)
260 else if(!strcmp(arg[
k],
"--height") && argc >
k + 1)
265 else if(!strcmp(arg[
k],
"--bpp") && argc >
k + 1)
269 fprintf(stderr, _(
"TODO: sorry, due to API restrictions we currently cannot set the BPP to %d.\n"),
bpp);
271 else if(!strcmp(arg[
k],
"--export_masks") && argc >
k + 1)
274 gchar *str = g_ascii_strup(arg[
k], -1);
275 if(!g_strcmp0(str,
"0") || !g_strcmp0(str,
"FALSE"))
276 export_masks =
FALSE;
277 else if(!g_strcmp0(str,
"1") || !g_strcmp0(str,
"TRUE"))
281 fprintf(stderr, _(
"unknown option for --export_masks: %s.\n"), arg[
k]);
287 else if(!strcmp(arg[
k],
"--style") && argc >
k + 1)
292 else if(!strcmp(arg[
k],
"--apply-custom-presets") && argc >
k + 1)
295 gchar *str = g_ascii_strup(arg[
k], -1);
296 if(!g_strcmp0(str,
"0") || !g_strcmp0(str,
"FALSE"))
297 custom_presets =
FALSE;
298 else if(!g_strcmp0(str,
"1") || !g_strcmp0(str,
"TRUE"))
299 custom_presets =
TRUE;
302 fprintf(stderr, _(
"unknown option for --apply-custom-presets: %s.\n"), arg[
k]);
308 else if(!strcmp(arg[
k],
"--out-ext") && argc >
k + 1)
313 fprintf(stderr, _(
"too long ext for --out-ext: %s.\n"), arg[
k]);
322 output_ext = g_strdup(arg[
k]);
324 else if(!strcmp(arg[
k],
"--import") && argc >
k + 1)
327 if(g_file_test(arg[
k], G_FILE_TEST_EXISTS))
328 inputs = g_list_prepend(inputs, g_strdup(arg[
k]));
330 fprintf(stderr, _(
"notice: input file or dir '%s' doesn't exist, skipping\n"), arg[
k]);
332 else if(!strcmp(arg[
k],
"--imgid") && argc >
k + 1)
335 const int imgid = atoi(arg[
k]);
338 imgids = g_list_append(imgids, GINT_TO_POINTER(imgid));
341 fprintf(stderr, _(
"incorrect image id for --imgid: '%s'\n"), arg[
k]);
346 else if(!strcmp(arg[
k],
"--icc-type") && argc >
k + 1)
349 gchar *str = g_ascii_strup(arg[
k], -1);
353 fprintf(stderr, _(
"incorrect ICC type for --icc-type: '%s'\n"), arg[
k]);
359 else if(!strcmp(arg[
k],
"--icc-file") && argc >
k + 1)
362 if(g_file_test(arg[
k], G_FILE_TEST_EXISTS) && ! g_file_test(arg[
k], G_FILE_TEST_IS_DIR))
366 icc_filename = g_strdup(arg[
k]);
369 fprintf(stderr, _(
"notice: ICC file '%s' doesn't exist, skipping\n"), arg[
k]);
371 else if(!strcmp(arg[
k],
"--icc-intent") && argc >
k + 1)
374 gchar *str = g_ascii_strup(arg[
k], -1);
378 fprintf(stderr, _(
"incorrect ICC intent for --icc-intent: '%s'\n"), arg[
k]);
384 else if(!strcmp(arg[
k],
"-v") || !strcmp(arg[
k],
"--verbose"))
388 else if(!strcmp(arg[
k],
"--core"))
396 fprintf(stderr, _(
"warning: unknown option '%s'\n"), arg[
k]);
401 if(file_counter == 0)
402 input_filename = arg[
k];
403 else if(file_counter == 1)
404 xmp_filename = arg[
k];
405 else if(file_counter == 2)
407 output_filename = g_strdup(arg[
k]);
414 char **m_arg = malloc(
sizeof(
char *) * (5 + argc -
k + 1));
415 m_arg[m_argc++] =
"ansel-cli";
421 m_arg[m_argc++] =
"--library";
422 m_arg[m_argc++] =
":memory:";
425 m_arg[m_argc++] =
"--conf";
426 m_arg[m_argc++] =
"write_sidecar_files=FALSE";
427 for(;
k < argc;
k++) m_arg[m_argc++] = arg[
k];
428 m_arg[m_argc] = NULL;
430 if(imgids && (inputs || file_counter != 1))
433 if(inputs || file_counter > 1)
434 fprintf(stderr, _(
"error: --imgid cannot be combined with input files or an XMP (history comes from library.db)\n"));
436 fprintf(stderr, _(
"error: --imgid requires an output destination\n"));
461 output_filename = g_strdup(input_filename);
462 input_filename = xmp_filename = NULL;
464 else if( (inputs && file_counter < 1) || (
IS_NULL_PTR(inputs) && file_counter < 2) || file_counter > 3)
483 else if(inputs && file_counter == 1)
488 output_filename = g_strdup(input_filename);
489 input_filename = xmp_filename = NULL;
491 else if (inputs && file_counter == 2)
496 output_filename = g_strdup(xmp_filename);
497 xmp_filename = input_filename;
498 input_filename = NULL;
500 else if (inputs && file_counter == 3)
502 fprintf(stderr, _(
"error: input file and import opts specified! that's not supported!\n"));
517 else if(file_counter == 2)
522 output_filename = g_strdup(xmp_filename);
529 inputs = g_list_prepend(inputs, g_strdup(input_filename));
530 input_filename = NULL;
533 if(g_file_test(output_filename, G_FILE_TEST_IS_DIR))
535 output_to_dir =
TRUE;
538 output_ext = g_strdup(
"jpg");
540 fprintf(stderr, _(
"notice: output location is a directory. assuming '%s/$(FILE_NAME).%s' output pattern"), output_filename, output_ext);
541 fprintf(stderr,
"\n");
542 gchar* temp_of = g_strdup(output_filename);
544 if(g_str_has_suffix(temp_of,
"/"))
545 temp_of[strlen(temp_of) - 1] =
'\0';
546 output_filename = g_strconcat(temp_of,
"/$(FILE_NAME)", NULL);
551 if(g_file_test(output_filename, G_FILE_TEST_EXISTS) && !output_to_dir)
553 if(
IS_NULL_PTR(output_ext) || (output_ext && g_str_has_suffix(output_filename, output_ext) && !g_strcmp0(output_ext,strrchr(output_filename,
'.')+1))){
555 fprintf(stderr,
"%s\n", _(
"output file already exists, it will get renamed"));
578 GList *id_list = NULL;
581 for(GList *l = imgids; !
IS_NULL_PTR(l); l = g_list_next(l))
583 const int imgid = GPOINTER_TO_INT(l->data);
586 if(image && image->
id == imgid)
589 id_list = g_list_append(id_list, GINT_TO_POINTER(imgid));
595 fprintf(stderr, _(
"error: no image with id %d in the library"), imgid);
596 fprintf(stderr,
"\n");
603 for(GList *l = inputs; !
IS_NULL_PTR(l); l=g_list_next(l))
605 gchar* input = l->data;
607 if(g_file_test(input, G_FILE_TEST_IS_DIR))
613 fprintf(stderr, _(
"error: can't open folder %s"), input);
614 fprintf(stderr,
"\n");
624 gchar *
directory = g_path_get_dirname(input);
630 fprintf(stderr, _(
"error: can't open file %s"), input);
631 fprintf(stderr,
"\n");
634 id_list = g_list_append(id_list, GINT_TO_POINTER(
id));
645 const int total = g_list_length(id_list);
649 fprintf(stderr, _(
"no images to export, aborting\n"));
662 for(GList *iter = id_list; iter; iter = g_list_next(iter))
664 int id = GPOINTER_TO_INT(iter->data);
667 fprintf(stderr,
"%s", _(
"Could not read image information from the database."));
669 fprintf(stderr, _(
"error: can't open xmp file %s"), xmp_filename);
676 fprintf(stderr,
"\n");
690 int id = GPOINTER_TO_INT(id_list->data);
693 printf(
"%s\n", history);
695 printf(
"[%s]\n", _(
"empty history stack"));
703 char *ext = strrchr(output_filename,
'.');
707 fprintf(stderr, _(
"too long output file extension: %s\n"), ext);
712 else if(!ext || strlen(ext) <= 1)
715 fprintf(stderr, _(
"no output file extension given\n"));
722 output_ext = g_strdup(ext);
725 char *ext = strrchr(output_filename,
'.');
726 if(ext && !strcmp(output_ext, ext+1))
732 if(!strcmp(output_ext,
"jpg"))
735 output_ext = g_strdup(
"jpeg");
738 if(!strcmp(output_ext,
"tif"))
741 output_ext = g_strdup(
"tiff");
754 _(
"cannot find disk storage module. please check your installation, something seems to be broken."));
764 fprintf(stderr,
"%s\n", _(
"failed to get parameters from storage module, aborting export ..."));
780 fprintf(stderr, _(
"unknown extension '.%s'"), output_ext);
781 fprintf(stderr,
"\n");
790 fprintf(stderr,
"%s\n", _(
"failed to get parameters from format module, aborting export ..."));
796 uint32_t w, h, fw, fh, sw, sh;
797 fw = fh = sw = sh = 0;
798 storage->
dimension(storage, sdata, &sw, &sh);
799 format->
dimension(format, fdata, &fw, &fh);
801 if(sw == 0 || fw == 0)
802 w = sw > fw ? sw : fw;
804 w = sw < fw ? sw : fw;
806 if(sh == 0 || fh == 0)
807 h = sh > fh ? sh : fh;
809 h = sh < fh ? sh : fh;
815 fdata->
style[0] =
'\0';
820 fdata->
style[127] =
'\0';
833 int num = 1,
res = 0;
834 for(GList *iter = id_list; iter; iter = g_list_next(iter), num++)
836 const int id = GPOINTER_TO_INT(iter->data);
840 metadata.
list = NULL;
842 if(storage->
store(storage, sdata,
id, format, fdata, 0.0, num, total,
TRUE, export_masks,
843 icc_type, icc_filename, icc_intent, &metadata) != 0)
851 g_list_free(id_list);
static void usage(const char *progname)
static dt_iop_color_intent_t get_icc_intent(const char *option)
static dt_colorspaces_color_profile_type_t get_icc_type(const char *option)
int(* store)(struct dt_imageio_module_storage_t *self, struct dt_imageio_module_data_t *self_data, const int32_t imgid, struct dt_imageio_module_format_t *format, struct dt_imageio_module_data_t *fdata, const double scale_factor, const int num, const int total, const gboolean high_quality, const gboolean export_masks, const enum dt_colorspaces_color_profile_type_t icc_type, const gchar *icc_filename, enum dt_iop_color_intent_t icc_intent, struct dt_export_metadata_t *metadata)