207 dt_loc_init(NULL, NULL, NULL, NULL, NULL, NULL, NULL);
214 if(!gtk_parse_args(&argc, &arg)) exit(1);
217 char *input_filename = NULL;
218 char *xmp_filename = NULL;
219 gchar *output_filename = NULL;
220 gchar *output_ext = NULL;
222 int file_counter = 0;
224 gboolean verbose =
FALSE, custom_presets =
TRUE, export_masks =
FALSE,
225 output_to_dir =
FALSE;
227 GList* inputs = 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],
"--icc-type") && argc >
k + 1)
335 gchar *str = g_ascii_strup(arg[
k], -1);
339 fprintf(stderr, _(
"incorrect ICC type for --icc-type: '%s'\n"), arg[
k]);
345 else if(!strcmp(arg[
k],
"--icc-file") && argc >
k + 1)
348 if(g_file_test(arg[
k], G_FILE_TEST_EXISTS) && ! g_file_test(arg[
k], G_FILE_TEST_IS_DIR))
352 icc_filename = g_strdup(arg[
k]);
355 fprintf(stderr, _(
"notice: ICC file '%s' doesn't exist, skipping\n"), arg[
k]);
357 else if(!strcmp(arg[
k],
"--icc-intent") && argc >
k + 1)
360 gchar *str = g_ascii_strup(arg[
k], -1);
364 fprintf(stderr, _(
"incorrect ICC intent for --icc-intent: '%s'\n"), arg[
k]);
370 else if(!strcmp(arg[
k],
"-v") || !strcmp(arg[
k],
"--verbose"))
374 else if(!strcmp(arg[
k],
"--core"))
382 fprintf(stderr, _(
"warning: unknown option '%s'\n"), arg[
k]);
387 if(file_counter == 0)
388 input_filename = arg[
k];
389 else if(file_counter == 1)
390 xmp_filename = arg[
k];
391 else if(file_counter == 2)
393 output_filename = g_strdup(arg[
k]);
400 char **m_arg = malloc(
sizeof(
char *) * (5 + argc -
k + 1));
401 m_arg[m_argc++] =
"ansel-cli";
402 m_arg[m_argc++] =
"--library";
403 m_arg[m_argc++] =
":memory:";
404 m_arg[m_argc++] =
"--conf";
405 m_arg[m_argc++] =
"write_sidecar_files=FALSE";
406 for(;
k < argc;
k++) m_arg[m_argc++] = arg[
k];
407 m_arg[m_argc] = NULL;
409 if( (inputs && file_counter < 1) || (
IS_NULL_PTR(inputs) && file_counter < 2) || file_counter > 3)
428 else if(inputs && file_counter == 1)
433 output_filename = g_strdup(input_filename);
434 input_filename = xmp_filename = NULL;
436 else if (inputs && file_counter == 2)
441 output_filename = g_strdup(xmp_filename);
442 xmp_filename = input_filename;
443 input_filename = NULL;
445 else if (inputs && file_counter == 3)
447 fprintf(stderr, _(
"error: input file and import opts specified! that's not supported!\n"));
462 else if(file_counter == 2)
467 output_filename = g_strdup(xmp_filename);
474 inputs = g_list_prepend(inputs, g_strdup(input_filename));
475 input_filename = NULL;
478 if(g_file_test(output_filename, G_FILE_TEST_IS_DIR))
480 output_to_dir =
TRUE;
483 output_ext = g_strdup(
"jpg");
485 fprintf(stderr, _(
"notice: output location is a directory. assuming '%s/$(FILE_NAME).%s' output pattern"), output_filename, output_ext);
486 fprintf(stderr,
"\n");
487 gchar* temp_of = g_strdup(output_filename);
489 if(g_str_has_suffix(temp_of,
"/"))
490 temp_of[strlen(temp_of) - 1] =
'\0';
491 output_filename = g_strconcat(temp_of,
"/$(FILE_NAME)", NULL);
496 if(g_file_test(output_filename, G_FILE_TEST_EXISTS) && !output_to_dir)
498 if(
IS_NULL_PTR(output_ext) || (output_ext && g_str_has_suffix(output_filename, output_ext) && !g_strcmp0(output_ext,strrchr(output_filename,
'.')+1))){
500 fprintf(stderr,
"%s\n", _(
"output file already exists, it will get renamed"));
523 GList *id_list = NULL;
525 for(GList *l = inputs; !
IS_NULL_PTR(l); l=g_list_next(l))
527 gchar* input = l->data;
529 if(g_file_test(input, G_FILE_TEST_IS_DIR))
535 fprintf(stderr, _(
"error: can't open folder %s"), input);
536 fprintf(stderr,
"\n");
546 gchar *directory = g_path_get_dirname(input);
552 fprintf(stderr, _(
"error: can't open file %s"), input);
553 fprintf(stderr,
"\n");
556 id_list = g_list_append(id_list, GINT_TO_POINTER(
id));
567 const int total = g_list_length(id_list);
571 fprintf(stderr, _(
"no images to export, aborting\n"));
584 for(GList *iter = id_list; iter; iter = g_list_next(iter))
586 int id = GPOINTER_TO_INT(iter->data);
590 fprintf(stderr, _(
"error: can't open xmp file %s"), xmp_filename);
591 fprintf(stderr,
"\n");
608 int id = GPOINTER_TO_INT(id_list->data);
611 printf(
"%s\n", history);
613 printf(
"[%s]\n", _(
"empty history stack"));
621 char *ext = strrchr(output_filename,
'.');
625 fprintf(stderr, _(
"too long output file extension: %s\n"), ext);
630 else if(!ext || strlen(ext) <= 1)
633 fprintf(stderr, _(
"no output file extension given\n"));
640 output_ext = g_strdup(ext);
643 char *ext = strrchr(output_filename,
'.');
644 if(ext && !strcmp(output_ext, ext+1))
650 if(!strcmp(output_ext,
"jpg"))
653 output_ext = g_strdup(
"jpeg");
656 if(!strcmp(output_ext,
"tif"))
659 output_ext = g_strdup(
"tiff");
672 _(
"cannot find disk storage module. please check your installation, something seems to be broken."));
679 sdata = storage->get_params(storage);
682 fprintf(stderr,
"%s\n", _(
"failed to get parameters from storage module, aborting export ..."));
698 fprintf(stderr, _(
"unknown extension '.%s'"), output_ext);
699 fprintf(stderr,
"\n");
705 fdata = format->get_params(format);
708 fprintf(stderr,
"%s\n", _(
"failed to get parameters from format module, aborting export ..."));
714 uint32_t w, h, fw, fh, sw, sh;
715 fw = fh = sw = sh = 0;
716 storage->dimension(storage, sdata, &sw, &sh);
717 format->dimension(format, fdata, &fw, &fh);
719 if(sw == 0 || fw == 0)
720 w = sw > fw ? sw : fw;
722 w = sw < fw ? sw : fw;
724 if(sh == 0 || fh == 0)
725 h = sh > fh ? sh : fh;
727 h = sh < fh ? sh : fh;
733 fdata->
style[0] =
'\0';
738 fdata->
style[127] =
'\0';
741 if(storage->initialize_store)
743 storage->initialize_store(storage, sdata, &format, &fdata, &id_list,
TRUE);
745 format->set_params(format, fdata, format->params_size(format));
746 storage->set_params(storage, sdata, storage->params_size(storage));
751 int num = 1, res = 0;
752 for(GList *iter = id_list; iter; iter = g_list_next(iter), num++)
754 const int id = GPOINTER_TO_INT(iter->data);
758 metadata.
list = NULL;
759 if(storage->store(storage, sdata,
id, format, fdata, num, total,
TRUE, export_masks,
760 icc_type, icc_filename, icc_intent, &metadata) != 0)
765 if(storage->finalize_store) storage->finalize_store(storage, sdata);
766 storage->free_params(storage, sdata);
767 format->free_params(format, fdata);
768 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)