1 /* === S Y N F I G ========================================================= */
2 /*! \file tool/main.cpp
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
34 #include <ETL/stringf>
40 #include <synfig/loadcanvas.h>
41 #include <synfig/savecanvas.h>
42 #include <synfig/target_scanline.h>
43 #include <synfig/module.h>
44 #include <synfig/importer.h>
45 #include <synfig/layer.h>
46 #include <synfig/canvas.h>
47 #include <synfig/target.h>
48 #include <synfig/time.h>
49 #include <synfig/string.h>
50 #include <synfig/paramdesc.h>
51 #include <synfig/main.h>
52 #include <synfig/guid.h>
57 using namespace synfig;
59 /* === M A C R O S ========================================================= */
63 #define _(x) gettext(x)
72 SYNFIGTOOL_FILENOTFOUND = 1,
75 SYNFIGTOOL_UNKNOWNARGUMENT = 4,
76 SYNFIGTOOL_UNKNOWNERROR = 5,
77 SYNFIGTOOL_INVALIDTARGET = 6,
78 SYNFIGTOOL_RENDERFAILURE = 7,
80 SYNFIGTOOL_BADVERSION = 9,
81 SYNFIGTOOL_MISSINGARGUMENT =10
85 #define VERSION "unknown"
86 #define PACKAGE "synfig-tool"
89 #ifdef DEFAULT_QUALITY
90 #undef DEFAULT_QUALITY
93 #define DEFAULT_QUALITY 2
94 #define VERBOSE_OUT(x) if(verbosity>=(x))std::cerr
96 /* === G L O B A L S ======================================================= */
101 bool print_benchmarks=false;
103 /* === M E T H O D S ======================================================= */
105 class Progress : public synfig::ProgressCallback
111 Progress(const char *name):program(name) { }
114 task(const String &task)
116 VERBOSE_OUT(1)<<program<<": "<<task<<std::endl;
121 error(const String &task)
123 std::cerr<<program<<": "<<_("error")<<": "<<task<<std::endl;
128 warning(const String &task)
130 std::cerr<<program<<": "<<_("warning")<<": "<<task<<std::endl;
135 amount_complete(int /*current*/, int /*total*/)
141 class RenderProgress : public synfig::ProgressCallback
146 int clk_scanline; // The scanline at which the clock was reset
152 RenderProgress():clk_scanline(0), last_time(0) { }
155 task(const String &thetask)
162 error(const String &task)
164 std::cout<<_("error")<<": "<<task<<std::endl;
169 warning(const String &task)
171 std::cout<<_("warning")<<": "<<task<<std::endl;
176 amount_complete(int scanline, int h)
178 if(be_quiet)return true;
181 const float time(clk()*(float)(h-scanline)/(float)(scanline-clk_scanline));
182 const float delta(time-last_time);
184 int weeks=0,days=0,hours=0,minutes=0,seconds=0;
196 //cerr<<"reset"<<endl;
198 clk_scanline=scanline;
204 clk_scanline=scanline;
208 minutes++,seconds-=60;
216 cerr<<taskname<<": "<<_("Line")<<" "<<scanline<<_(" of ")<<h<<" -- ";
217 //cerr<<time/(h-clk_scanline)<<" ";
219 if(delta>=-time/(h-clk_scanline) )
222 if(delta>=0 && clk()>4.0 && scanline>clk_scanline+200)
224 //cerr<<"reset"<<endl;
226 clk_scanline=scanline;
243 cerr<<taskname<<": "<<_("DONE")<<" "<<endl;;
256 Canvas::Handle canvas;
257 Target::Handle target;
264 typedef list<String> arg_list_t;
265 typedef list<Job> job_list_t;
269 cout<<"GUID Test"<<endl;
271 cout<<synfig::GUID().get_string()<<' '<<synfig::GUID().get_string()<<endl;
274 void signal_test_func()
276 cout<<"**SIGNAL CALLED**"<<endl;
281 sigc::signal<void> sig;
282 sigc::connection conn;
283 cout<<"Signal Test"<<endl;
284 conn=sig.connect(sigc::ptr_fun(signal_test_func));
285 cout<<"Next line should exclaim signal called."<<endl;
288 cout<<"Next line should NOT exclaim signal called."<<endl;
293 /* === P R O C E D U R E S ================================================= */
295 void display_help(int amount)
300 Argument(const char *flag,const char *arg, string description)
302 const char spaces[]=" ";
304 cerr<<strprintf(" %s %s %s",flag, arg, spaces+strlen(arg)+strlen(flag)+1)+description<<endl;
306 cerr<<strprintf(" %s %s",flag,spaces+strlen(flag))+description<<endl;
310 cerr << endl << _("syntax: ") << progname << " [DEFAULT OPTIONS] ([SIF FILE] [SPECIFIC OPTIONS])..." << endl << endl;
313 Argument("--help",NULL,_("Print out usage and syntax info"));
316 Argument("-t","<output type>",_("Specify output target (Default:unknown)"));
317 Argument("-w","<pixel width>",_("Set the image width (Use zero for file default)"));
318 Argument("-h","<pixel height>",_("Set the image height (Use zero for file default)"));
319 Argument("-s","<image dist>",_("Set the diagonal size of image window (Span)"));
320 Argument("-a","<1...30>",_("Set antialias amount for parametric renderer."));
321 Argument("-Q","<0...10>",strprintf(_("Specify image quality for accelerated renderer (default=%d)"),DEFAULT_QUALITY).c_str());
322 Argument("-g","<amount>",_("Gamma (default=2.2)"));
323 Argument("-v",NULL,_("Verbose Output (add more for more verbosity)"));
324 Argument("-q",NULL,_("Quiet mode (No progress/time-remaining display)"));
325 Argument("-c","<canvas id>",_("Render the canvas with the given id instead of the root."));
326 Argument("-o","<output file>",_("Specify output filename"));
327 Argument("-T","<# of threads>",_("Enable multithreaded renderer using specified # of threads"));
328 Argument("-b",NULL,_("Print Benchmarks"));
329 Argument("--fps","<framerate>",_("Set the frame rate"));
330 Argument("--time","<time>",_("Render a single frame at <seconds>"));
331 Argument("--begin-time","<time>",_("Set the starting time"));
332 Argument("--start-time","<time>",_("Set the starting time"));
333 Argument("--end-time","<time>",_("Set the ending time"));
334 Argument("--dpi","<res>",_("Set the physical resolution (dots-per-inch)"));
335 Argument("--dpi-x","<res>",_("Set the physical X resolution (dots-per-inch)"));
336 Argument("--dpi-y","<res>",_("Set the physical Y resolution (dots-per-inch)"));
338 Argument("--list-canvases",NULL,_("List the exported canvases in the composition"));
339 Argument("--append","<filename>",_("Append layers in <filename> to composition"));
341 Argument("--layer-info","<layer>",_("Print out layer's description, parameter info, etc."));
342 Argument("--layers",NULL,_("Print out the list of available layers"));
343 Argument("--targets",NULL,_("Print out the list of available targets"));
344 Argument("--importers",NULL,_("Print out the list of available importers"));
345 Argument("--valuenodes",NULL,_("Print out the list of available ValueNodes"));
346 Argument("--modules",NULL,_("Print out the list of loaded modules"));
347 Argument("--version",NULL,_("Print out version information"));
348 Argument("--info",NULL,_("Print out misc build information"));
349 Argument("--license",NULL,_("Print out license information"));
352 Argument("--guid-test",NULL,_("Test GUID generation"));
353 Argument("--signal-test",NULL,_("Test signal implementation"));
360 int process_global_flags(arg_list_t &arg_list)
362 arg_list_t::iterator iter, next;
364 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
367 return SYNFIGTOOL_OK;
369 if(*iter == "--signal-test")
372 return SYNFIGTOOL_HELP;
375 if(*iter == "--guid-test")
378 return SYNFIGTOOL_HELP;
381 if(*iter == "--help")
384 return SYNFIGTOOL_HELP;
387 if(*iter == "--info")
389 cout<<PACKAGE"-"VERSION<<endl;
390 cout<<"Compiled on "__DATE__ /* " at "__TIME__ */;
392 cout<<" with GCC "<<__VERSION__;
395 cout<<" with Microsoft Visual C++ "<<(_MSC_VER>>8)<<'.'<<(_MSC_VER&255);
397 #ifdef __TCPLUSPLUS__
398 cout<<" with Borland Turbo C++ "<<(__TCPLUSPLUS__>>8)<<'.'<<((__TCPLUSPLUS__&255)>>4)<<'.'<<(__TCPLUSPLUS__&15);
401 cout<<endl<<SYNFIG_COPYRIGHT<<endl;
403 return SYNFIGTOOL_HELP;
406 if(*iter == "--layers")
409 synfig::Main synfig_main(dirname(progname),&p);
410 synfig::Layer::Book::iterator iter=synfig::Layer::book().begin();
411 for(;iter!=synfig::Layer::book().end();iter++)
412 if (iter->second.category != CATEGORY_DO_NOT_USE)
413 cout<<iter->first<<endl;
415 return SYNFIGTOOL_HELP;
418 if(*iter == "--layer-info")
421 synfig::Main synfig_main(dirname(progname),&p);
423 if (iter==arg_list.end())
425 error("The `%s' flag requires a value. Use --help for a list of options.", "--layer-info");
426 return SYNFIGTOOL_MISSINGARGUMENT;
428 Layer::Handle layer=synfig::Layer::create(*iter);
429 cout<<"Layer Name: "<<layer->get_name()<<endl;
430 cout<<"Localized Layer Name: "<<layer->get_local_name()<<endl;
431 cout<<"Version: "<<layer->get_version()<<endl;
432 Layer::Vocab vocab=layer->get_param_vocab();
433 for(;!vocab.empty();vocab.pop_front())
435 cout<<"param - "<<vocab.front().get_name();
436 if(!vocab.front().get_critical())
437 cout<<" (not critical)";
438 cout<<endl<<"\tLocalized Name: "<<vocab.front().get_local_name()<<endl;
439 if(!vocab.front().get_description().empty())
440 cout<<"\tDescription: "<<vocab.front().get_description()<<endl;
441 if(!vocab.front().get_hint().empty())
442 cout<<"\tHint: "<<vocab.front().get_hint()<<endl;
445 return SYNFIGTOOL_HELP;
448 if(*iter == "--modules")
451 synfig::Main synfig_main(dirname(progname),&p);
452 synfig::Module::Book::iterator iter=synfig::Module::book().begin();
453 for(;iter!=synfig::Module::book().end();iter++)
454 cout<<iter->first<<endl;
455 return SYNFIGTOOL_HELP;
458 if(*iter == "--targets")
461 synfig::Main synfig_main(dirname(progname),&p);
462 synfig::Target::Book::iterator iter=synfig::Target::book().begin();
463 for(;iter!=synfig::Target::book().end();iter++)
464 cout<<iter->first<<endl;
465 return SYNFIGTOOL_HELP;
468 if(*iter == "--valuenodes")
471 synfig::Main synfig_main(dirname(progname),&p);
472 synfig::LinkableValueNode::Book::iterator iter=synfig::LinkableValueNode::book().begin();
473 for(;iter!=synfig::LinkableValueNode::book().end();iter++)
474 cout<<iter->first<<endl;
475 return SYNFIGTOOL_HELP;
478 if(*iter == "--importers")
481 synfig::Main synfig_main(dirname(progname),&p);
482 synfig::Importer::Book::iterator iter=synfig::Importer::book().begin();
483 for(;iter!=synfig::Importer::book().end();iter++)
484 cout<<iter->first<<endl;
485 return SYNFIGTOOL_HELP;
488 if(*iter == "--version")
490 cerr<<PACKAGE<<" "<<VERSION<<endl;
491 arg_list.erase(iter);
492 return SYNFIGTOOL_HELP;
495 if(*iter == "--license")
497 cerr<<PACKAGE<<" "<<VERSION<<endl;
498 cout<<SYNFIG_COPYRIGHT<<endl<<endl;
500 ** This package is free software; you can redistribute it and/or\n\
501 ** modify it under the terms of the GNU General Public License as\n\
502 ** published by the Free Software Foundation; either version 2 of\n\
503 ** the License, or (at your option) any later version.\n\
505 ** " << endl << endl;
506 arg_list.erase(iter);
507 return SYNFIGTOOL_HELP;
513 arg_list.erase(iter);
520 arg_list.erase(iter);
525 print_benchmarks=true;
526 arg_list.erase(iter);
531 return SYNFIGTOOL_OK;
534 /* true if the given flag takes an extra parameter */
535 bool flag_requires_value(String flag)
537 return (flag=="-a" || flag=="-c" || flag=="-g" || flag=="-h" || flag=="-o" ||
538 flag=="-Q" || flag=="-s" || flag=="-t" || flag=="-T" || flag=="-w" ||
539 flag=="--append" || flag=="--begin-time" || flag=="--dpi" || flag=="--dpi-x" || flag=="--dpi-y" ||
540 flag=="--end-time" || flag=="--fps" || flag=="--layer-info" || flag=="--start-time" || flag=="--time" );
543 int extract_arg_cluster(arg_list_t &arg_list,arg_list_t &cluster)
545 arg_list_t::iterator iter, next;
547 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
549 if(*iter->begin() != '-')
551 //cerr<<*iter->begin()<<"-----------"<<endl;
552 return SYNFIGTOOL_OK;
555 if (flag_requires_value(*iter))
557 cluster.push_back(*iter);
558 arg_list.erase(iter);
560 if (iter==arg_list.end())
562 error("The `%s' flag requires a value. Use --help for a list of options.", cluster.back().c_str());
563 return SYNFIGTOOL_MISSINGARGUMENT;
567 cluster.push_back(*iter);
568 arg_list.erase(iter);
571 return SYNFIGTOOL_OK;
574 int extract_RendDesc(arg_list_t &arg_list,RendDesc &desc)
576 arg_list_t::iterator iter, next;
579 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
583 arg_list.erase(iter);
585 w=atoi(iter->c_str());
586 arg_list.erase(iter);
590 arg_list.erase(iter);
592 h=atoi(iter->c_str());
593 arg_list.erase(iter);
598 arg_list.erase(iter);
600 a=atoi(iter->c_str());
601 desc.set_antialias(a);
602 VERBOSE_OUT(1)<<strprintf(_("Antialiasing set to %d, (%d samples per pixel)"),a,a*a)<<endl;
603 arg_list.erase(iter);
607 arg_list.erase(iter);
609 span=atof(iter->c_str());
610 VERBOSE_OUT(1)<<strprintf(_("Span set to %d units"),span)<<endl;
611 arg_list.erase(iter);
613 else if(*iter=="--fps")
615 arg_list.erase(iter);
617 float fps=atof(iter->c_str());
618 desc.set_frame_rate(fps);
619 arg_list.erase(iter);
620 VERBOSE_OUT(1)<<strprintf(_("Frame rate set to %d frames per second"),fps)<<endl;
622 else if(*iter=="--dpi")
624 arg_list.erase(iter);
626 float dpi=atof(iter->c_str());
627 float dots_per_meter=dpi*39.3700787402;
628 desc.set_x_res(dots_per_meter).set_y_res(dots_per_meter);
629 arg_list.erase(iter);
630 VERBOSE_OUT(1)<<strprintf(_("Physical resolution set to %f dpi"),dpi)<<endl;
632 else if(*iter=="--dpi-x")
634 arg_list.erase(iter);
636 float dpi=atof(iter->c_str());
637 float dots_per_meter=dpi*39.3700787402;
638 desc.set_x_res(dots_per_meter);
639 arg_list.erase(iter);
640 VERBOSE_OUT(1)<<strprintf(_("Physical X resolution set to %f dpi"),dpi)<<endl;
642 else if(*iter=="--dpi-y")
644 arg_list.erase(iter);
646 float dpi=atof(iter->c_str());
647 float dots_per_meter=dpi*39.3700787402;
648 desc.set_y_res(dots_per_meter);
649 arg_list.erase(iter);
650 VERBOSE_OUT(1)<<strprintf(_("Physical Y resolution set to %f dpi"),dpi)<<endl;
652 else if(*iter=="--start-time" || *iter=="--begin-time")
654 arg_list.erase(iter);
656 desc.set_time_start(Time(*iter,desc.get_frame_rate()));
657 arg_list.erase(iter);
659 else if(*iter=="--end-time")
661 arg_list.erase(iter);
663 desc.set_time_end(Time(*iter,desc.get_frame_rate()));
664 arg_list.erase(iter);
666 else if(*iter=="--time")
668 arg_list.erase(iter);
670 desc.set_time(Time(*iter,desc.get_frame_rate()));
671 VERBOSE_OUT(1)<<_("Rendering frame at ")<<desc.get_time_start().get_string(desc.get_frame_rate())<<endl;
672 arg_list.erase(iter);
676 synfig::warning("Gamma argument is currently ignored");
677 arg_list.erase(iter);
679 //desc.set_gamma(Gamma(atof(iter->c_str())));
680 arg_list.erase(iter);
682 else if (flag_requires_value(*iter))
688 VERBOSE_OUT(1)<<strprintf(_("Resolution set to %dx%d"),w,h)<<endl;
694 VERBOSE_OUT(1)<<strprintf(_("Width set to %d pixels"),w)<<endl;
699 VERBOSE_OUT(1)<<strprintf(_("Height set to %d pixels"),h)<<endl;
705 return SYNFIGTOOL_OK;
708 int extract_quality(arg_list_t &arg_list,int &quality)
710 arg_list_t::iterator iter, next;
711 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
715 arg_list.erase(iter);
717 quality=atoi(iter->c_str());
718 VERBOSE_OUT(1)<<strprintf(_("Quality set to %d"),quality)<<endl;
719 arg_list.erase(iter);
721 else if (flag_requires_value(*iter))
725 return SYNFIGTOOL_OK;
728 int extract_threads(arg_list_t &arg_list,int &threads)
730 arg_list_t::iterator iter, next;
731 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
735 arg_list.erase(iter);
737 threads=atoi(iter->c_str());
738 VERBOSE_OUT(1)<<strprintf(_("Threads set to %d"),threads)<<endl;
739 arg_list.erase(iter);
741 else if (flag_requires_value(*iter))
745 return SYNFIGTOOL_OK;
748 int extract_target(arg_list_t &arg_list,string &type)
750 arg_list_t::iterator iter, next;
753 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
757 arg_list.erase(iter);
760 arg_list.erase(iter);
762 else if (flag_requires_value(*iter))
766 return SYNFIGTOOL_OK;
769 int extract_append(arg_list_t &arg_list,string &filename)
771 arg_list_t::iterator iter, next;
774 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
776 if(*iter=="--append")
778 arg_list.erase(iter);
781 arg_list.erase(iter);
783 else if (flag_requires_value(*iter))
787 return SYNFIGTOOL_OK;
790 int extract_outfile(arg_list_t &arg_list,string &outfile)
792 arg_list_t::iterator iter, next;
793 int ret=SYNFIGTOOL_FILENOTFOUND;
796 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
800 arg_list.erase(iter);
803 arg_list.erase(iter);
806 else if (flag_requires_value(*iter))
813 int extract_canvasid(arg_list_t &arg_list,string &canvasid)
815 arg_list_t::iterator iter, next;
818 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
822 arg_list.erase(iter);
825 arg_list.erase(iter);
827 else if (flag_requires_value(*iter))
831 return SYNFIGTOOL_OK;
834 int extract_list_canvases(arg_list_t &arg_list,bool &list_canvases)
836 arg_list_t::iterator iter, next;
838 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
839 if(*iter=="--list-canvases")
841 list_canvases = true;
842 arg_list.erase(iter);
845 return SYNFIGTOOL_OK;
848 void list_child_canvases(string prefix, Canvas::Handle canvas)
850 Canvas::Children children(canvas->children());
851 for (Canvas::Children::iterator iter = children.begin(); iter != children.end(); iter++)
853 cout << prefix << ":" << (*iter)->get_id() << endl;
854 list_child_canvases(prefix + ":" + (*iter)->get_id(), *iter);
858 /* === M E T H O D S ======================================================= */
860 /* === E N T R Y P O I N T ================================================= */
862 int main(int argc, char *argv[])
868 setlocale(LC_ALL, "");
871 bindtextdomain("synfig", LOCALEDIR);
872 textdomain("synfig");
878 if(!SYNFIG_CHECK_VERSION())
880 cerr<<_("FATAL: Synfig Version Mismatch")<<endl;
881 return SYNFIGTOOL_BADVERSION;
887 return SYNFIGTOOL_BLANK;
891 arg_list.push_back(argv[i]);
893 if((i=process_global_flags(arg_list)))
896 VERBOSE_OUT(1)<<_("verbosity set to ")<<verbosity<<endl;
897 synfig::Main synfig_main(dirname(progname),&p);
900 arg_list_t defaults, imageargs;
903 // Grab the defaults before the first file
904 if ((ret = extract_arg_cluster(arg_list,defaults)) != SYNFIGTOOL_OK)
907 while(arg_list.size())
910 job_list.push_front(Job());
914 job_list.front().filename=arg_list.front();
915 arg_list.pop_front();
917 if ((ret = extract_arg_cluster(arg_list,imageargs)) != SYNFIGTOOL_OK)
920 // Open the composition
921 job_list.front().root=open_canvas(job_list.front().filename);
923 if(!job_list.front().root)
925 cerr<<_("Unable to open ")<<job_list.front().filename<<"."<<endl;
926 cerr<<_("Throwing out job...")<<endl;
927 job_list.pop_front();
931 bool list_canvases = false;
932 extract_list_canvases(imageargs, list_canvases);
933 job_list.front().list_canvases = list_canvases;
935 job_list.front().root->set_time(0);
938 extract_canvasid(imageargs,canvasid);
939 if(!canvasid.empty())
943 job_list.front().canvas=job_list.front().root->find_canvas(canvasid);
945 catch(Exception::IDNotFound)
947 cerr<<_("Unable to find canvas with ID \"")<<canvasid<<_("\" in ")<<job_list.front().filename<<"."<<endl;
948 cerr<<_("Throwing out job...")<<endl;
949 job_list.pop_front();
953 catch(Exception::BadLinkName)
955 cerr<<_("Invalid canvas name \"")<<canvasid<<_("\" in ")<<job_list.front().filename<<"."<<endl;
956 cerr<<_("Throwing out job...")<<endl;
957 job_list.pop_front();
962 job_list.front().canvas=job_list.front().root;
964 extract_RendDesc(imageargs,job_list.front().canvas->rend_desc());
965 extract_target(imageargs,target_name);
966 extract_threads(imageargs,threads);
967 job_list.front().quality=DEFAULT_QUALITY;
968 extract_quality(imageargs,job_list.front().quality);
969 VERBOSE_OUT(2)<<_("Quality set to ")<<job_list.front().quality<<endl;
970 job_list.front().desc=job_list.front().canvas->rend_desc();
971 extract_outfile(imageargs,job_list.front().outfilename);
975 string composite_file;
976 extract_append(imageargs,composite_file);
977 if(!composite_file.empty())
979 Canvas::Handle composite(open_canvas(composite_file));
982 Canvas::reverse_iterator iter;
983 for(iter=composite->rbegin();iter!=composite->rend();++iter)
985 Layer::Handle layer(*iter);
987 job_list.front().canvas->push_front(layer->clone());
989 VERBOSE_OUT(2)<<_("Appended contents of ")<<composite_file<<endl;
993 VERBOSE_OUT(4)<<_("Attempting to determine target/outfile...")<<endl;
995 // If the target type is not yet defined,
996 // try to figure it out from the outfile.
997 if(target_name.empty() && !job_list.front().outfilename.empty())
999 VERBOSE_OUT(3)<<_("Target name undefined, attempting to figure it out")<<endl;
1000 string ext = filename_extension(job_list.front().outfilename);
1001 if (ext.length()) ext = ext.substr(1);
1002 if(Target::ext_book().count(ext))
1004 target_name=Target::ext_book()[ext];
1005 info("target name not specified - using %s", target_name.c_str());
1009 string lower_ext(ext);
1011 for(unsigned int i=0;i<ext.length();i++)
1012 lower_ext[i] = tolower(ext[i]);
1014 if(Target::ext_book().count(lower_ext))
1016 target_name=Target::ext_book()[lower_ext];
1017 info("target name not specified - using %s", target_name.c_str());
1024 // If the target type is STILL not yet defined, then
1025 // set it to a some sort of default
1026 if(target_name.empty())
1028 VERBOSE_OUT(2)<<_("Defaulting to PNG target...")<<endl;
1032 // If no output filename was provided, then
1033 // create a output filename based on the
1034 // given input filename. (ie: change the extension)
1035 if(job_list.front().outfilename.empty())
1037 job_list.front().outfilename = filename_sans_extension(job_list.front().filename) + '.';
1038 if(Target::book().count(target_name))
1039 job_list.front().outfilename+=Target::book()[target_name].second;
1041 job_list.front().outfilename+=target_name;
1044 VERBOSE_OUT(4)<<"target_name="<<target_name<<endl;
1045 VERBOSE_OUT(4)<<"outfile_name="<<job_list.front().outfilename<<endl;
1047 VERBOSE_OUT(4)<<_("Creating the target...")<<endl;
1048 job_list.front().target=synfig::Target::create(target_name,job_list.front().outfilename);
1050 if(target_name=="sif")
1051 job_list.front().sifout=true;
1054 if(!job_list.front().target)
1056 cerr<<_("Unknown target for ")<<job_list.front().filename<<": "<<target_name<<endl;
1057 cerr<<_("Throwing out job...")<<endl;
1058 job_list.pop_front();
1061 job_list.front().sifout=false;
1064 // Set the Canvas on the Target
1065 if(job_list.front().target)
1067 VERBOSE_OUT(4)<<_("Setting the canvas on the target...")<<endl;
1068 job_list.front().target->set_canvas(job_list.front().canvas);
1069 VERBOSE_OUT(4)<<_("Setting the quality of the target...")<<endl;
1070 job_list.front().target->set_quality(job_list.front().quality);
1073 // Set the threads for the target
1074 if(job_list.front().target && Target_Scanline::Handle::cast_dynamic(job_list.front().target))
1075 Target_Scanline::Handle::cast_dynamic(job_list.front().target)->set_threads(threads);
1077 if(imageargs.size())
1079 cerr<<_("Unidentified arguments for ")<<job_list.front().filename<<": ";
1080 for(;imageargs.size();imageargs.pop_front())
1081 cerr<<' '<<imageargs.front();
1083 cerr<<_("Throwing out job...")<<endl;
1084 job_list.pop_front();
1092 cerr<<_("Unidentified arguments:");
1093 for(;arg_list.size();arg_list.pop_front())
1094 cerr<<' '<<arg_list.front();
1096 return SYNFIGTOOL_UNKNOWNARGUMENT;
1099 if(!job_list.size())
1101 cerr<<_("Nothing to do!")<<endl;
1102 return SYNFIGTOOL_BORED;
1105 for(;job_list.size();job_list.pop_front())
1107 VERBOSE_OUT(3)<<job_list.front().filename<<" -- "<<endl<<'\t'<<
1108 strprintf("w:%d, h:%d, a:%d, pxaspect:%f, imaspect:%f, span:%f",
1109 job_list.front().desc.get_w(),
1110 job_list.front().desc.get_h(),
1111 job_list.front().desc.get_antialias(),
1112 job_list.front().desc.get_pixel_aspect(),
1113 job_list.front().desc.get_image_aspect(),
1114 job_list.front().desc.get_span()
1116 strprintf("tl:[%f,%f], br:[%f,%f], focus:[%f,%f]",
1117 job_list.front().desc.get_tl()[0],job_list.front().desc.get_tl()[1],
1118 job_list.front().desc.get_br()[0],job_list.front().desc.get_br()[1],
1119 job_list.front().desc.get_focus()[0],job_list.front().desc.get_focus()[1]
1123 p.task(job_list.front().filename+" ==> "+job_list.front().outfilename);
1124 if(job_list.front().sifout)
1126 if(!save_canvas(job_list.front().outfilename,job_list.front().canvas))
1128 cerr<<"Render Failure."<<endl;
1129 return SYNFIGTOOL_RENDERFAILURE;
1132 else if (job_list.front().list_canvases)
1134 list_child_canvases(job_list.front().filename + "#", job_list.front().canvas);
1139 VERBOSE_OUT(1)<<_("Rendering...")<<endl;
1142 // Call the render member of the target
1143 if(!job_list.front().target->render(&p))
1145 cerr<<"Render Failure."<<endl;
1146 return SYNFIGTOOL_RENDERFAILURE;
1148 if(print_benchmarks)
1149 cout<<job_list.front().filename+": Rendered in "<<timer()<<" seconds."<<endl;
1155 VERBOSE_OUT(1)<<_("Done.")<<endl;
1157 return SYNFIGTOOL_OK;