214 dt_loc_init(NULL, NULL, NULL, NULL, NULL, NULL, NULL);
221 if(!gtk_parse_args(&argc, &arg)) exit(1);
224 char *input_filename = NULL;
225 char *xmp_filename = NULL;
226 gchar *output_filename = NULL;
227 gchar *output_ext = NULL;
229 int file_counter = 0;
231 gboolean verbose =
FALSE, custom_presets =
TRUE, export_masks =
FALSE,
232 output_to_dir =
FALSE;
234 GList* inputs = NULL;
235 GList* imgids = NULL;
238 gchar *icc_filename = NULL;
242 for(
k = 1;
k < argc;
k++)
246 if(!strcmp(arg[
k],
"--help") || !strcmp(arg[
k],
"-h"))
250 if(!strcmp(arg[
k+1],
"icc-type"))
252 if(!strcmp(arg[
k+1],
"icc-intent"))
257 else if(!strcmp(arg[
k],
"--version"))
259 printf(
"this is ansel-cli %s\ncopyright (c) 2012-%s johannes hanika, tobias ellinghaus\n",
263 else if(!strcmp(arg[
k],
"--width") && argc >
k + 1)
268 else if(!strcmp(arg[
k],
"--height") && argc >
k + 1)
273 else if(!strcmp(arg[
k],
"--bpp") && argc >
k + 1)
277 fprintf(stderr, _(
"TODO: sorry, due to API restrictions we currently cannot set the BPP to %d.\n"),
bpp);
279 else if(!strcmp(arg[
k],
"--export_masks") && argc >
k + 1)
282 gchar *str = g_ascii_strup(arg[
k], -1);
283 if(!g_strcmp0(str,
"0") || !g_strcmp0(str,
"FALSE"))
284 export_masks =
FALSE;
285 else if(!g_strcmp0(str,
"1") || !g_strcmp0(str,
"TRUE"))
289 fprintf(stderr, _(
"unknown option for --export_masks: %s.\n"), arg[
k]);
295 else if(!strcmp(arg[
k],
"--style") && argc >
k + 1)
300 else if(!strcmp(arg[
k],
"--apply-custom-presets") && argc >
k + 1)
303 gchar *str = g_ascii_strup(arg[
k], -1);
304 if(!g_strcmp0(str,
"0") || !g_strcmp0(str,
"FALSE"))
305 custom_presets =
FALSE;
306 else if(!g_strcmp0(str,
"1") || !g_strcmp0(str,
"TRUE"))
307 custom_presets =
TRUE;
310 fprintf(stderr, _(
"unknown option for --apply-custom-presets: %s.\n"), arg[
k]);
316 else if(!strcmp(arg[
k],
"--out-ext") && argc >
k + 1)
321 fprintf(stderr, _(
"too long ext for --out-ext: %s.\n"), arg[
k]);
330 output_ext = g_strdup(arg[
k]);
332 else if(!strcmp(arg[
k],
"--import") && argc >
k + 1)
335 if(g_file_test(arg[
k], G_FILE_TEST_EXISTS))
336 inputs = g_list_prepend(inputs, g_strdup(arg[
k]));
338 fprintf(stderr, _(
"notice: input file or dir '%s' doesn't exist, skipping\n"), arg[
k]);
340 else if(!strcmp(arg[
k],
"--imgid") && argc >
k + 1)
343 const int imgid = atoi(arg[
k]);
346 imgids = g_list_append(imgids, GINT_TO_POINTER(imgid));
349 fprintf(stderr, _(
"incorrect image id for --imgid: '%s'\n"), arg[
k]);
354 else if(!strcmp(arg[
k],
"--icc-type") && argc >
k + 1)
357 gchar *str = g_ascii_strup(arg[
k], -1);
361 fprintf(stderr, _(
"incorrect ICC type for --icc-type: '%s'\n"), arg[
k]);
367 else if(!strcmp(arg[
k],
"--icc-file") && argc >
k + 1)
370 if(g_file_test(arg[
k], G_FILE_TEST_EXISTS) && ! g_file_test(arg[
k], G_FILE_TEST_IS_DIR))
374 icc_filename = g_strdup(arg[
k]);
377 fprintf(stderr, _(
"notice: ICC file '%s' doesn't exist, skipping\n"), arg[
k]);
379 else if(!strcmp(arg[
k],
"--icc-intent") && argc >
k + 1)
382 gchar *str = g_ascii_strup(arg[
k], -1);
386 fprintf(stderr, _(
"incorrect ICC intent for --icc-intent: '%s'\n"), arg[
k]);
392 else if(!strcmp(arg[
k],
"-v") || !strcmp(arg[
k],
"--verbose"))
396 else if(!strcmp(arg[
k],
"--core"))
404 fprintf(stderr, _(
"warning: unknown option '%s'\n"), arg[
k]);
409 if(file_counter == 0)
410 input_filename = arg[
k];
411 else if(file_counter == 1)
412 xmp_filename = arg[
k];
413 else if(file_counter == 2)
415 output_filename = g_strdup(arg[
k]);
422 char **m_arg = malloc(
sizeof(
char *) * (5 + argc -
k + 1));
423 m_arg[m_argc++] =
"ansel-cli";
429 m_arg[m_argc++] =
"--library";
430 m_arg[m_argc++] =
":memory:";
433 m_arg[m_argc++] =
"--conf";
434 m_arg[m_argc++] =
"write_sidecar_files=FALSE";
435 for(;
k < argc;
k++) m_arg[m_argc++] = arg[
k];
436 m_arg[m_argc] = NULL;
438 if(imgids && (inputs || file_counter != 1))
441 if(inputs || file_counter > 1)
442 fprintf(stderr, _(
"error: --imgid cannot be combined with input files or an XMP (history comes from library.db)\n"));
444 fprintf(stderr, _(
"error: --imgid requires an output destination\n"));
469 output_filename = g_strdup(input_filename);
470 input_filename = xmp_filename = NULL;
472 else if( (inputs && file_counter < 1) || (
IS_NULL_PTR(inputs) && file_counter < 2) || file_counter > 3)
491 else if(inputs && file_counter == 1)
496 output_filename = g_strdup(input_filename);
497 input_filename = xmp_filename = NULL;
499 else if (inputs && file_counter == 2)
504 output_filename = g_strdup(xmp_filename);
505 xmp_filename = input_filename;
506 input_filename = NULL;
508 else if (inputs && file_counter == 3)
510 fprintf(stderr, _(
"error: input file and import opts specified! that's not supported!\n"));
525 else if(file_counter == 2)
530 output_filename = g_strdup(xmp_filename);
537 inputs = g_list_prepend(inputs, g_strdup(input_filename));
538 input_filename = NULL;
541 if(g_file_test(output_filename, G_FILE_TEST_IS_DIR))
543 output_to_dir =
TRUE;
546 output_ext = g_strdup(
"jpg");
548 fprintf(stderr, _(
"notice: output location is a directory. assuming '%s/$(FILE_NAME).%s' output pattern"), output_filename, output_ext);
549 fprintf(stderr,
"\n");
550 gchar* temp_of = g_strdup(output_filename);
552 if(g_str_has_suffix(temp_of,
"/"))
553 temp_of[strlen(temp_of) - 1] =
'\0';
554 output_filename = g_strconcat(temp_of,
"/$(FILE_NAME)", NULL);
559 if(g_file_test(output_filename, G_FILE_TEST_EXISTS) && !output_to_dir)
561 if(
IS_NULL_PTR(output_ext) || (output_ext && g_str_has_suffix(output_filename, output_ext) && !g_strcmp0(output_ext,strrchr(output_filename,
'.')+1))){
563 fprintf(stderr,
"%s\n", _(
"output file already exists, it will get renamed"));
586 GList *id_list = NULL;
589 for(GList *l = imgids; !
IS_NULL_PTR(l); l = g_list_next(l))
591 const int imgid = GPOINTER_TO_INT(l->data);
594 if(image && image->
id == imgid)
597 id_list = g_list_append(id_list, GINT_TO_POINTER(imgid));
603 fprintf(stderr, _(
"error: no image with id %d in the library"), imgid);
604 fprintf(stderr,
"\n");
611 for(GList *l = inputs; !
IS_NULL_PTR(l); l=g_list_next(l))
613 gchar* input = l->data;
615 if(g_file_test(input, G_FILE_TEST_IS_DIR))
621 fprintf(stderr, _(
"error: can't open folder %s"), input);
622 fprintf(stderr,
"\n");
632 gchar *directory = g_path_get_dirname(input);
638 fprintf(stderr, _(
"error: can't open file %s"), input);
639 fprintf(stderr,
"\n");
642 id_list = g_list_append(id_list, GINT_TO_POINTER(
id));
653 const int total = g_list_length(id_list);
657 fprintf(stderr, _(
"no images to export, aborting\n"));
670 for(GList *iter = id_list; iter; iter = g_list_next(iter))
672 int id = GPOINTER_TO_INT(iter->data);
676 fprintf(stderr, _(
"error: can't open xmp file %s"), xmp_filename);
677 fprintf(stderr,
"\n");
694 int id = GPOINTER_TO_INT(id_list->data);
697 printf(
"%s\n", history);
699 printf(
"[%s]\n", _(
"empty history stack"));
707 char *ext = strrchr(output_filename,
'.');
711 fprintf(stderr, _(
"too long output file extension: %s\n"), ext);
716 else if(!ext || strlen(ext) <= 1)
719 fprintf(stderr, _(
"no output file extension given\n"));
726 output_ext = g_strdup(ext);
729 char *ext = strrchr(output_filename,
'.');
730 if(ext && !strcmp(output_ext, ext+1))
736 if(!strcmp(output_ext,
"jpg"))
739 output_ext = g_strdup(
"jpeg");
742 if(!strcmp(output_ext,
"tif"))
745 output_ext = g_strdup(
"tiff");
758 _(
"cannot find disk storage module. please check your installation, something seems to be broken."));
765 sdata = storage->get_params(storage);
768 fprintf(stderr,
"%s\n", _(
"failed to get parameters from storage module, aborting export ..."));
784 fprintf(stderr, _(
"unknown extension '.%s'"), output_ext);
785 fprintf(stderr,
"\n");
791 fdata = format->get_params(format);
794 fprintf(stderr,
"%s\n", _(
"failed to get parameters from format module, aborting export ..."));
800 uint32_t w, h, fw, fh, sw, sh;
801 fw = fh = sw = sh = 0;
802 storage->dimension(storage, sdata, &sw, &sh);
803 format->dimension(format, fdata, &fw, &fh);
805 if(sw == 0 || fw == 0)
806 w = sw > fw ? sw : fw;
808 w = sw < fw ? sw : fw;
810 if(sh == 0 || fh == 0)
811 h = sh > fh ? sh : fh;
813 h = sh < fh ? sh : fh;
819 fdata->
style[0] =
'\0';
824 fdata->
style[127] =
'\0';
827 if(storage->initialize_store)
829 storage->initialize_store(storage, sdata, &format, &fdata, &id_list,
TRUE);
831 format->set_params(format, fdata, format->params_size(format));
832 storage->set_params(storage, sdata, storage->params_size(storage));
837 int num = 1, res = 0;
838 for(GList *iter = id_list; iter; iter = g_list_next(iter), num++)
840 const int id = GPOINTER_TO_INT(iter->data);
844 metadata.
list = NULL;
845 if(storage->store(storage, sdata,
id, format, fdata, num, total,
TRUE, export_masks,
846 icc_type, icc_filename, icc_intent, &metadata) != 0)
851 if(storage->finalize_store) storage->finalize_store(storage, sdata);
852 storage->free_params(storage, sdata);
853 format->free_params(format, fdata);
854 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)