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>
53 #include <autorevision.h>
54 #include "definitions.h"
56 #include "renderprogress.h"
62 using namespace synfig;
64 /* === G L O B A L S ======================================================= */
69 bool print_benchmarks=false;
71 /* === T Y P E D E F S ===================================================== */
73 typedef list<String> arg_list_t;
74 typedef list<Job> job_list_t;
76 /* === M E T H O D S ======================================================= */
80 cout<<"GUID Test"<<endl;
82 cout<<synfig::GUID().get_string()<<' '<<synfig::GUID().get_string()<<endl;
85 void signal_test_func()
87 cout<<"**SIGNAL CALLED**"<<endl;
92 sigc::signal<void> sig;
93 sigc::connection conn;
94 cout<<"Signal Test"<<endl;
95 conn=sig.connect(sigc::ptr_fun(signal_test_func));
96 cout<<"Next line should exclaim signal called."<<endl;
99 cout<<"Next line should NOT exclaim signal called."<<endl;
104 /* === P R O C E D U R E S ================================================= */
106 void display_help_option(const char *flag, const char *arg, string description)
108 const char spaces[]=" ";
110 cerr << strprintf(" %s %s %s", flag, arg, spaces+strlen(arg)+strlen(flag)+1)+description << endl;
112 cerr << strprintf(" %s %s", flag, spaces+strlen(flag))+description << endl;
115 void display_help(bool full)
117 cerr << endl << _("syntax: ") << progname << " [DEFAULT OPTIONS] ([SIF FILE] [SPECIFIC OPTIONS])..." << endl << endl;
121 display_help_option("-t", "<output type>", _("Specify output target (Default:unknown)"));
122 display_help_option("-w", "<pixel width>", _("Set the image width (Use zero for file default)"));
123 display_help_option("-h", "<pixel height>", _("Set the image height (Use zero for file default)"));
124 display_help_option("-s", "<image dist>", _("Set the diagonal size of image window (Span)"));
125 display_help_option("-a", "<1...30>", _("Set antialias amount for parametric renderer."));
126 display_help_option("-Q", "<0...10>", strprintf(_("Specify image quality for accelerated renderer (default=%d)"), DEFAULT_QUALITY).c_str());
127 display_help_option("-g", "<amount>", _("Gamma (default=2.2)"));
128 display_help_option("-v", NULL, _("Verbose Output (add more for more verbosity)"));
129 display_help_option("-q", NULL, _("Quiet mode (No progress/time-remaining display)"));
130 display_help_option("-c", "<canvas id>", _("Render the canvas with the given id instead of the root."));
131 display_help_option("-o", "<output file>", _("Specify output filename"));
132 display_help_option("-T", "<# of threads>", _("Enable multithreaded renderer using specified # of threads"));
133 display_help_option("-b", NULL, _("Print Benchmarks"));
134 display_help_option("--fps", "<framerate>", _("Set the frame rate"));
135 display_help_option("--time", "<time>", _("Render a single frame at <seconds>"));
136 display_help_option("--begin-time", "<time>", _("Set the starting time"));
137 display_help_option("--start-time", "<time>", _("Set the starting time"));
138 display_help_option("--end-time", "<time>", _("Set the ending time"));
139 display_help_option("--dpi", "<res>", _("Set the physical resolution (dots-per-inch)"));
140 display_help_option("--dpi-x", "<res>", _("Set the physical X resolution (dots-per-inch)"));
141 display_help_option("--dpi-y", "<res>", _("Set the physical Y resolution (dots-per-inch)"));
143 display_help_option("--list-canvases", NULL, _("List the exported canvases in the composition"));
144 display_help_option("--canvas-info", "<fields>", _("Print out specified details of the root canvas"));
145 display_help_option("--append", "<filename>", _("Append layers in <filename> to composition"));
147 display_help_option("--layer-info", "<layer>", _("Print out layer's description, parameter info, etc."));
148 display_help_option("--layers", NULL, _("Print out the list of available layers"));
149 display_help_option("--targets", NULL, _("Print out the list of available targets"));
150 display_help_option("--importers", NULL, _("Print out the list of available importers"));
151 display_help_option("--valuenodes", NULL, _("Print out the list of available ValueNodes"));
152 display_help_option("--modules", NULL, _("Print out the list of loaded modules"));
153 display_help_option("--version", NULL, _("Print out version information"));
154 display_help_option("--info", NULL, _("Print out misc build information"));
155 display_help_option("--license", NULL, _("Print out license information"));
158 display_help_option("--guid-test", NULL, _("Test GUID generation"));
159 display_help_option("--signal-test", NULL, _("Test signal implementation"));
163 display_help_option("--help", NULL, _("Print out usage and syntax info"));
168 int process_global_flags(arg_list_t &arg_list)
170 arg_list_t::iterator iter, next;
172 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
175 return SYNFIGTOOL_OK;
177 if(*iter == "--signal-test")
180 return SYNFIGTOOL_HELP;
183 if(*iter == "--guid-test")
186 return SYNFIGTOOL_HELP;
189 if(*iter == "--help")
192 return SYNFIGTOOL_HELP;
195 if(*iter == "--info")
197 cout<<PACKAGE"-"VERSION<<endl;
199 cout<<endl<<DEVEL_VERSION<<endl<<endl;
201 cout<<"Compiled on "__DATE__ /* " at "__TIME__ */;
203 cout<<" with GCC "<<__VERSION__;
206 cout<<" with Microsoft Visual C++ "<<(_MSC_VER>>8)<<'.'<<(_MSC_VER&255);
208 #ifdef __TCPLUSPLUS__
209 cout<<" with Borland Turbo C++ "<<(__TCPLUSPLUS__>>8)<<'.'<<((__TCPLUSPLUS__&255)>>4)<<'.'<<(__TCPLUSPLUS__&15);
211 cout<<endl<<SYNFIG_COPYRIGHT<<endl;
213 return SYNFIGTOOL_HELP;
216 if(*iter == "--layers")
219 synfig::Main synfig_main(dirname(progname),&p);
220 synfig::Layer::Book::iterator iter=synfig::Layer::book().begin();
221 for(;iter!=synfig::Layer::book().end();iter++)
222 if (iter->second.category != CATEGORY_DO_NOT_USE)
223 cout<<iter->first<<endl;
225 return SYNFIGTOOL_HELP;
228 if(*iter == "--layer-info")
231 synfig::Main synfig_main(dirname(progname),&p);
233 if (iter==arg_list.end())
235 error("The `%s' flag requires a value. Use --help for a list of options.", "--layer-info");
236 return SYNFIGTOOL_MISSINGARGUMENT;
238 Layer::Handle layer=synfig::Layer::create(*iter);
239 cout<<"Layer Name: "<<layer->get_name()<<endl;
240 cout<<"Localized Layer Name: "<<layer->get_local_name()<<endl;
241 cout<<"Version: "<<layer->get_version()<<endl;
242 Layer::Vocab vocab=layer->get_param_vocab();
243 for(;!vocab.empty();vocab.pop_front())
245 cout<<"param - "<<vocab.front().get_name();
246 if(!vocab.front().get_critical())
247 cout<<" (not critical)";
248 cout<<endl<<"\tLocalized Name: "<<vocab.front().get_local_name()<<endl;
249 if(!vocab.front().get_description().empty())
250 cout<<"\tDescription: "<<vocab.front().get_description()<<endl;
251 if(!vocab.front().get_hint().empty())
252 cout<<"\tHint: "<<vocab.front().get_hint()<<endl;
255 return SYNFIGTOOL_HELP;
258 if(*iter == "--modules")
261 synfig::Main synfig_main(dirname(progname),&p);
262 synfig::Module::Book::iterator iter=synfig::Module::book().begin();
263 for(;iter!=synfig::Module::book().end();iter++)
264 cout<<iter->first<<endl;
265 return SYNFIGTOOL_HELP;
268 if(*iter == "--targets")
271 synfig::Main synfig_main(dirname(progname),&p);
272 synfig::Target::Book::iterator iter=synfig::Target::book().begin();
273 for(;iter!=synfig::Target::book().end();iter++)
274 cout<<iter->first<<endl;
275 return SYNFIGTOOL_HELP;
278 if(*iter == "--valuenodes")
281 synfig::Main synfig_main(dirname(progname),&p);
282 synfig::LinkableValueNode::Book::iterator iter=synfig::LinkableValueNode::book().begin();
283 for(;iter!=synfig::LinkableValueNode::book().end();iter++)
284 cout<<iter->first<<endl;
285 return SYNFIGTOOL_HELP;
288 if(*iter == "--importers")
291 synfig::Main synfig_main(dirname(progname),&p);
292 synfig::Importer::Book::iterator iter=synfig::Importer::book().begin();
293 for(;iter!=synfig::Importer::book().end();iter++)
294 cout<<iter->first<<endl;
295 return SYNFIGTOOL_HELP;
298 if(*iter == "--version")
300 cerr<<PACKAGE<<" "<<VERSION<<endl;
301 arg_list.erase(iter);
302 return SYNFIGTOOL_HELP;
305 if(*iter == "--license")
307 cerr<<PACKAGE<<" "<<VERSION<<endl;
308 cout<<SYNFIG_COPYRIGHT<<endl<<endl;
310 ** This package is free software; you can redistribute it and/or\n\
311 ** modify it under the terms of the GNU General Public License as\n\
312 ** published by the Free Software Foundation; either version 2 of\n\
313 ** the License, or (at your option) any later version.\n\
315 ** " << endl << endl;
316 arg_list.erase(iter);
317 return SYNFIGTOOL_HELP;
323 arg_list.erase(iter);
330 arg_list.erase(iter);
335 print_benchmarks=true;
336 arg_list.erase(iter);
341 return SYNFIGTOOL_OK;
344 /* true if the given flag takes an extra parameter */
345 bool flag_requires_value(String flag)
347 return (flag=="-a" || flag=="-c" || flag=="-g" || flag=="-h" || flag=="-o" ||
348 flag=="-Q" || flag=="-s" || flag=="-t" || flag=="-T" || flag=="-w" ||
349 flag=="--append" || flag=="--begin-time" || flag=="--canvas-info"|| flag=="--dpi" || flag=="--dpi-x" ||
350 flag=="--dpi-y" || flag=="--end-time" || flag=="--fps" || flag=="--layer-info" || flag=="--start-time" ||
354 int extract_arg_cluster(arg_list_t &arg_list,arg_list_t &cluster)
356 arg_list_t::iterator iter, next;
358 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
360 if(*iter->begin() != '-')
362 //cerr<<*iter->begin()<<"-----------"<<endl;
363 return SYNFIGTOOL_OK;
366 if (flag_requires_value(*iter))
368 cluster.push_back(*iter);
369 arg_list.erase(iter);
371 if (iter==arg_list.end())
373 error("The `%s' flag requires a value. Use --help for a list of options.", cluster.back().c_str());
374 return SYNFIGTOOL_MISSINGARGUMENT;
378 cluster.push_back(*iter);
379 arg_list.erase(iter);
382 return SYNFIGTOOL_OK;
385 /*! Extract a parameter from the argument list
387 * \param arg_list Argument list from wich the parameter is extracted.
388 * \param iter Iterator pointing to the argument list parameter to be
390 * \param next Iterator pointing to the next argument.
392 string extract_parameter (arg_list_t& arg_list,
393 arg_list_t::iterator& iter,
394 arg_list_t::iterator& next)
397 arg_list.erase(iter);
400 arg_list.erase(iter);
404 int extract_RendDesc(arg_list_t &arg_list,RendDesc &desc)
406 arg_list_t::iterator iter, next;
409 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
413 w = atoi(extract_parameter(arg_list, iter, next).c_str());
417 h = atoi(extract_parameter(arg_list, iter, next).c_str());
422 a = atoi(extract_parameter(arg_list, iter, next).c_str());
423 desc.set_antialias(a);
424 VERBOSE_OUT(1)<<strprintf(_("Antialiasing set to %d, (%d samples per pixel)"),a,a*a)<<endl;
428 span = atoi(extract_parameter(arg_list, iter, next).c_str());
429 VERBOSE_OUT(1)<<strprintf(_("Span set to %d units"),span)<<endl;
431 else if(*iter=="--fps")
433 float fps = atof(extract_parameter(arg_list, iter, next).c_str());
434 desc.set_frame_rate(fps);
435 VERBOSE_OUT(1)<<strprintf(_("Frame rate set to %d frames per second"),fps)<<endl;
437 else if(*iter=="--dpi")
439 float dpi = atof(extract_parameter(arg_list, iter, next).c_str());
440 float dots_per_meter=dpi*39.3700787402;
441 desc.set_x_res(dots_per_meter).set_y_res(dots_per_meter);
442 VERBOSE_OUT(1)<<strprintf(_("Physical resolution set to %f dpi"),dpi)<<endl;
444 else if(*iter=="--dpi-x")
446 float dpi = atof(extract_parameter(arg_list, iter, next).c_str());
447 float dots_per_meter=dpi*39.3700787402;
448 desc.set_x_res(dots_per_meter);
449 VERBOSE_OUT(1)<<strprintf(_("Physical X resolution set to %f dpi"),dpi)<<endl;
451 else if(*iter=="--dpi-y")
453 float dpi = atof(extract_parameter(arg_list, iter, next).c_str());
454 float dots_per_meter=dpi*39.3700787402;
455 desc.set_y_res(dots_per_meter);
456 VERBOSE_OUT(1)<<strprintf(_("Physical Y resolution set to %f dpi"),dpi)<<endl;
458 else if(*iter=="--start-time" || *iter=="--begin-time")
460 desc.set_time_start(Time(extract_parameter(arg_list, iter, next),
461 desc.get_frame_rate()));
463 else if(*iter=="--end-time")
465 desc.set_time_end(Time(extract_parameter(arg_list, iter, next),
466 desc.get_frame_rate()));
468 else if(*iter=="--time")
470 desc.set_time(Time(extract_parameter(arg_list, iter, next),
471 desc.get_frame_rate()));
472 VERBOSE_OUT(1)<<_("Rendering frame at ")<<desc.get_time_start().get_string(desc.get_frame_rate())<<endl;
476 synfig::warning("Gamma argument is currently ignored");
477 //desc.set_gamma(Gamma(atoi(extract_parameter(arg_list, iter, next).c_str())));
479 else if (flag_requires_value(*iter))
485 w = desc.get_w() * h / desc.get_h();
487 h = desc.get_h() * w / desc.get_w();
490 VERBOSE_OUT(1)<<strprintf(_("Resolution set to %dx%d"),w,h)<<endl;
494 return SYNFIGTOOL_OK;
497 int extract_quality(arg_list_t &arg_list,int &quality)
499 arg_list_t::iterator iter, next;
500 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
504 quality = atoi(extract_parameter(arg_list, iter, next).c_str());
505 VERBOSE_OUT(1)<<strprintf(_("Quality set to %d"),quality)<<endl;
507 else if (flag_requires_value(*iter))
511 return SYNFIGTOOL_OK;
514 int extract_threads(arg_list_t &arg_list,int &threads)
516 arg_list_t::iterator iter, next;
517 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
521 threads = atoi(extract_parameter(arg_list, iter, next).c_str());
522 VERBOSE_OUT(1)<<strprintf(_("Threads set to %d"),threads)<<endl;
524 else if (flag_requires_value(*iter))
528 return SYNFIGTOOL_OK;
531 int extract_target(arg_list_t &arg_list,string &type)
533 arg_list_t::iterator iter, next;
536 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
540 type = extract_parameter(arg_list, iter, next);
542 else if (flag_requires_value(*iter))
546 return SYNFIGTOOL_OK;
549 int extract_append(arg_list_t &arg_list,string &filename)
551 arg_list_t::iterator iter, next;
554 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
556 if(*iter=="--append")
558 filename = extract_parameter(arg_list, iter, next);
560 else if (flag_requires_value(*iter))
564 return SYNFIGTOOL_OK;
567 int extract_outfile(arg_list_t &arg_list,string &outfile)
569 arg_list_t::iterator iter, next;
570 int ret=SYNFIGTOOL_FILENOTFOUND;
573 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
577 outfile = extract_parameter(arg_list, iter, next);
580 else if (flag_requires_value(*iter))
587 int extract_canvasid(arg_list_t &arg_list,string &canvasid)
589 arg_list_t::iterator iter, next;
592 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
596 canvasid = extract_parameter(arg_list, iter, next);
598 else if (flag_requires_value(*iter))
602 return SYNFIGTOOL_OK;
605 int extract_list_canvases(arg_list_t &arg_list,bool &list_canvases)
607 arg_list_t::iterator iter, next;
609 for(next=arg_list.begin(), iter = next++; iter!=arg_list.end();
611 if(*iter=="--list-canvases")
613 list_canvases = true;
614 arg_list.erase(iter);
617 return SYNFIGTOOL_OK;
620 void extract_canvas_info(arg_list_t &arg_list, Job &job)
622 arg_list_t::iterator iter, next;
624 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
625 if(*iter=="--canvas-info")
627 job.canvas_info = true;
628 String values(extract_parameter(arg_list, iter, next)), value;
630 std::string::size_type pos;
631 while (!values.empty())
633 pos = values.find_first_of(',');
634 if (pos == std::string::npos)
641 value = values.substr(0, pos);
642 values = values.substr(pos+1);
646 job.canvas_info_all = true;
650 if (value == "time_start") job.canvas_info_time_start = true;
651 else if (value == "time_end") job.canvas_info_time_end = true;
652 else if (value == "frame_rate") job.canvas_info_frame_rate = true;
653 else if (value == "frame_start") job.canvas_info_frame_start = true;
654 else if (value == "frame_end") job.canvas_info_frame_end = true;
655 else if (value == "w") job.canvas_info_w = true;
656 else if (value == "h") job.canvas_info_h = true;
657 else if (value == "image_aspect") job.canvas_info_image_aspect = true;
658 else if (value == "pw") job.canvas_info_pw = true;
659 else if (value == "ph") job.canvas_info_ph = true;
660 else if (value == "pixel_aspect") job.canvas_info_pixel_aspect = true;
661 else if (value == "tl") job.canvas_info_tl = true;
662 else if (value == "br") job.canvas_info_br = true;
663 else if (value == "physical_w") job.canvas_info_physical_w = true;
664 else if (value == "physical_h") job.canvas_info_physical_h = true;
665 else if (value == "x_res") job.canvas_info_x_res = true;
666 else if (value == "y_res") job.canvas_info_y_res = true;
667 else if (value == "span") job.canvas_info_span = true;
668 else if (value == "interlaced") job.canvas_info_interlaced = true;
669 else if (value == "antialias") job.canvas_info_antialias = true;
670 else if (value == "clamp") job.canvas_info_clamp = true;
671 else if (value == "flags") job.canvas_info_flags = true;
672 else if (value == "focus") job.canvas_info_focus = true;
673 else if (value == "bg_color") job.canvas_info_bg_color = true;
674 else if (value == "metadata") job.canvas_info_metadata = true;
677 cerr<<_("Unrecognised canvas variable: ") << "'" << value << "'" << endl;
678 cerr<<_("Recognized variables are:") << endl <<
679 " all, time_start, time_end, frame_rate, frame_start, frame_end, w, h," << endl <<
680 " image_aspect, pw, ph, pixel_aspect, tl, br, physical_w, physical_h," << endl <<
681 " x_res, y_res, span, interlaced, antialias, clamp, flags," << endl <<
682 " focus, bg_color, metadata" << endl;
685 if (pos == std::string::npos)
691 void list_child_canvases(string prefix, Canvas::Handle canvas)
693 Canvas::Children children(canvas->children());
694 for (Canvas::Children::iterator iter = children.begin(); iter != children.end(); iter++)
696 cout << prefix << ":" << (*iter)->get_id() << endl;
697 list_child_canvases(prefix + ":" + (*iter)->get_id(), *iter);
701 void list_canvas_info(Job job)
703 Canvas::Handle canvas(job.canvas);
704 const RendDesc &rend_desc(canvas->rend_desc());
706 if (job.canvas_info_all || job.canvas_info_time_start)
708 cout << endl << "# " << _("Start Time") << endl;
709 cout << "time_start" << "=" << rend_desc.get_time_start().get_string().c_str() << endl;
712 if (job.canvas_info_all || job.canvas_info_time_end)
714 cout << endl << "# " << _("End Time") << endl;
715 cout << "time_end" << "=" << rend_desc.get_time_end().get_string().c_str() << endl;
718 if (job.canvas_info_all || job.canvas_info_frame_rate)
720 cout << endl << "# " << _("Frame Rate") << endl;
721 cout << "frame_rate" << "=" << rend_desc.get_frame_rate() << endl;
724 if (job.canvas_info_all || job.canvas_info_frame_start)
726 cout << endl << "# " << _("Start Frame") << endl;
727 cout << "frame_start" << "=" << rend_desc.get_frame_start() << endl;
730 if (job.canvas_info_all || job.canvas_info_frame_end)
732 cout << endl << "# " << _("End Frame") << endl;
733 cout << "frame_end" << "=" << rend_desc.get_frame_end() << endl;
736 if (job.canvas_info_all)
739 if (job.canvas_info_all || job.canvas_info_w)
741 cout << endl << "# " << _("Width") << endl;
742 cout << "w" << "=" << rend_desc.get_w() << endl;
745 if (job.canvas_info_all || job.canvas_info_h)
747 cout << endl << "# " << _("Height") << endl;
748 cout << "h" << "=" << rend_desc.get_h() << endl;
751 if (job.canvas_info_all || job.canvas_info_image_aspect)
753 cout << endl << "# " << _("Image Aspect Ratio") << endl;
754 cout << "image_aspect" << "=" << rend_desc.get_image_aspect() << endl;
757 if (job.canvas_info_all)
760 if (job.canvas_info_all || job.canvas_info_pw)
762 cout << endl << "# " << _("Pixel Width") << endl;
763 cout << "pw" << "=" << rend_desc.get_pw() << endl;
766 if (job.canvas_info_all || job.canvas_info_ph)
768 cout << endl << "# " << _("Pixel Height") << endl;
769 cout << "ph" << "=" << rend_desc.get_ph() << endl;
772 if (job.canvas_info_all || job.canvas_info_pixel_aspect)
774 cout << endl << "# " << _("Pixel Aspect Ratio") << endl;
775 cout << "pixel_aspect" << "=" << rend_desc.get_pixel_aspect() << endl;
778 if (job.canvas_info_all)
781 if (job.canvas_info_all || job.canvas_info_tl)
783 cout << endl << "# " << _("Top Left") << endl;
784 cout << "tl" << "=" << rend_desc.get_tl()[0]
785 << " " << rend_desc.get_tl()[1] << endl;
788 if (job.canvas_info_all || job.canvas_info_br)
790 cout << endl << "# " << _("Bottom Right") << endl;
791 cout << "br" << "=" << rend_desc.get_br()[0]
792 << " " << rend_desc.get_br()[1] << endl;
795 if (job.canvas_info_all || job.canvas_info_physical_w)
797 cout << endl << "# " << _("Physical Width") << endl;
798 cout << "physical_w" << "=" << rend_desc.get_physical_w() << endl;
801 if (job.canvas_info_all || job.canvas_info_physical_h)
803 cout << endl << "# " << _("Physical Height") << endl;
804 cout << "physical_h" << "=" << rend_desc.get_physical_h() << endl;
807 if (job.canvas_info_all || job.canvas_info_x_res)
809 cout << endl << "# " << _("X Resolution") << endl;
810 cout << "x_res" << "=" << rend_desc.get_x_res() << endl;
813 if (job.canvas_info_all || job.canvas_info_y_res)
815 cout << endl << "# " << _("Y Resolution") << endl;
816 cout << "y_res" << "=" << rend_desc.get_y_res() << endl;
819 if (job.canvas_info_all || job.canvas_info_span)
821 cout << endl << "# " << _("Diagonal Image Span") << endl;
822 cout << "span" << "=" << rend_desc.get_span() << endl;
825 if (job.canvas_info_all)
828 if (job.canvas_info_all || job.canvas_info_interlaced)
830 cout << endl << "# " << _("Interlaced") << endl;
831 cout << "interlaced" << "=" << rend_desc.get_interlaced() << endl;
834 if (job.canvas_info_all || job.canvas_info_antialias)
836 cout << endl << "# " << _("Antialias") << endl;
837 cout << "antialias" << "=" << rend_desc.get_antialias() << endl;
840 if (job.canvas_info_all || job.canvas_info_clamp)
842 cout << endl << "# " << _("Clamp") << endl;
843 cout << "clamp" << "=" << rend_desc.get_clamp() << endl;
846 if (job.canvas_info_all || job.canvas_info_flags)
848 cout << endl << "# " << _("Flags") << endl;
849 cout << "flags" << "=" << rend_desc.get_flags() << endl;
852 if (job.canvas_info_all || job.canvas_info_focus)
854 cout << endl << "# " << _("Focus") << endl;
855 cout << "focus" << "=" << rend_desc.get_focus()[0]
856 << " " << rend_desc.get_focus()[1] << endl;
859 if (job.canvas_info_all || job.canvas_info_bg_color)
861 cout << endl << "# " << _("Background Color") << endl;
862 cout << "bg_color" << "=" << rend_desc.get_bg_color().get_string().c_str() << endl;
865 if (job.canvas_info_all)
868 if (job.canvas_info_all || job.canvas_info_metadata)
870 std::list<String> keys(canvas->get_meta_data_keys());
871 cout << endl << "# " << _("Metadata") << endl;
872 for (std::list<String>::iterator iter = keys.begin(); iter != keys.end(); iter++)
873 cout << *iter << "=" << canvas->get_meta_data(*iter) << endl;
877 /* === M E T H O D S ======================================================= */
879 /* === E N T R Y P O I N T ================================================= */
881 int main(int argc, char *argv[])
887 setlocale(LC_ALL, "");
890 bindtextdomain("synfig", LOCALEDIR);
891 bind_textdomain_codeset("synfig", "UTF-8");
892 textdomain("synfig");
898 if(!SYNFIG_CHECK_VERSION())
900 cerr<<_("FATAL: Synfig Version Mismatch")<<endl;
901 return SYNFIGTOOL_BADVERSION;
907 return SYNFIGTOOL_BLANK;
911 arg_list.push_back(argv[i]);
913 if((i=process_global_flags(arg_list)))
916 VERBOSE_OUT(1)<<_("verbosity set to ")<<verbosity<<endl;
917 synfig::Main synfig_main(dirname(progname),&p);
920 arg_list_t defaults, imageargs;
923 // Grab the defaults before the first file
924 if ((ret = extract_arg_cluster(arg_list,defaults)) != SYNFIGTOOL_OK)
927 while(arg_list.size())
930 job_list.push_front(Job());
934 job_list.front().filename=arg_list.front();
935 arg_list.pop_front();
937 if ((ret = extract_arg_cluster(arg_list,imageargs)) != SYNFIGTOOL_OK)
940 // Open the composition
941 String errors, warnings;
944 job_list.front().root=open_canvas(job_list.front().filename, errors, warnings);
946 catch(runtime_error x)
948 job_list.front().root = 0;
951 if(!job_list.front().root)
953 cerr<<_("Unable to load '")<<job_list.front().filename<<"'."<<endl;
954 cerr<<_("Throwing out job...")<<endl;
955 job_list.pop_front();
959 bool list_canvases = false;
960 extract_list_canvases(imageargs, list_canvases);
961 job_list.front().list_canvases = list_canvases;
963 extract_canvas_info(imageargs, job_list.front());
965 job_list.front().root->set_time(0);
968 extract_canvasid(imageargs,canvasid);
969 if(!canvasid.empty())
974 job_list.front().canvas=job_list.front().root->find_canvas(canvasid, warnings);
976 catch(Exception::IDNotFound)
978 cerr<<_("Unable to find canvas with ID \"")<<canvasid<<_("\" in ")<<job_list.front().filename<<"."<<endl;
979 cerr<<_("Throwing out job...")<<endl;
980 job_list.pop_front();
984 catch(Exception::BadLinkName)
986 cerr<<_("Invalid canvas name \"")<<canvasid<<_("\" in ")<<job_list.front().filename<<"."<<endl;
987 cerr<<_("Throwing out job...")<<endl;
988 job_list.pop_front();
993 job_list.front().canvas=job_list.front().root;
995 extract_RendDesc(imageargs,job_list.front().canvas->rend_desc());
996 extract_target(imageargs,target_name);
997 extract_threads(imageargs,threads);
998 job_list.front().quality=DEFAULT_QUALITY;
999 extract_quality(imageargs,job_list.front().quality);
1000 VERBOSE_OUT(2)<<_("Quality set to ")<<job_list.front().quality<<endl;
1001 job_list.front().desc=job_list.front().canvas->rend_desc();
1002 extract_outfile(imageargs,job_list.front().outfilename);
1004 // Extract composite
1006 string composite_file;
1007 extract_append(imageargs,composite_file);
1008 if(!composite_file.empty())
1010 String errors, warnings;
1011 Canvas::Handle composite(open_canvas(composite_file, errors, warnings));
1014 cerr<<_("Unable to append '")<<composite_file<<"'."<<endl;
1017 Canvas::reverse_iterator iter;
1018 for(iter=composite->rbegin();iter!=composite->rend();++iter)
1020 Layer::Handle layer(*iter);
1022 job_list.front().canvas->push_front(layer->clone());
1024 VERBOSE_OUT(2)<<_("Appended contents of ")<<composite_file<<endl;
1028 VERBOSE_OUT(4)<<_("Attempting to determine target/outfile...")<<endl;
1030 // If the target type is not yet defined,
1031 // try to figure it out from the outfile.
1032 if(target_name.empty() && !job_list.front().outfilename.empty())
1034 VERBOSE_OUT(3)<<_("Target name undefined, attempting to figure it out")<<endl;
1035 string ext = filename_extension(job_list.front().outfilename);
1036 if (ext.length()) ext = ext.substr(1);
1037 if(Target::ext_book().count(ext))
1039 target_name=Target::ext_book()[ext];
1040 info("target name not specified - using %s", target_name.c_str());
1044 string lower_ext(ext);
1046 for(unsigned int i=0;i<ext.length();i++)
1047 lower_ext[i] = tolower(ext[i]);
1049 if(Target::ext_book().count(lower_ext))
1051 target_name=Target::ext_book()[lower_ext];
1052 info("target name not specified - using %s", target_name.c_str());
1059 // If the target type is STILL not yet defined, then
1060 // set it to a some sort of default
1061 if(target_name.empty())
1063 VERBOSE_OUT(2)<<_("Defaulting to PNG target...")<<endl;
1067 // If no output filename was provided, then
1068 // create a output filename based on the
1069 // given input filename. (ie: change the extension)
1070 if(job_list.front().outfilename.empty())
1072 job_list.front().outfilename = filename_sans_extension(job_list.front().filename) + '.';
1073 if(Target::book().count(target_name))
1074 job_list.front().outfilename+=Target::book()[target_name].filename;
1076 job_list.front().outfilename+=target_name;
1079 VERBOSE_OUT(4)<<"target_name="<<target_name<<endl;
1080 VERBOSE_OUT(4)<<"outfile_name="<<job_list.front().outfilename<<endl;
1082 VERBOSE_OUT(4)<<_("Creating the target...")<<endl;
1083 job_list.front().target=synfig::Target::create(target_name,job_list.front().outfilename);
1085 if(target_name=="sif")
1086 job_list.front().sifout=true;
1089 if(!job_list.front().target)
1091 cerr<<_("Unknown target for ")<<job_list.front().filename<<": "<<target_name<<endl;
1092 cerr<<_("Throwing out job...")<<endl;
1093 job_list.pop_front();
1096 job_list.front().sifout=false;
1099 // Set the Canvas on the Target
1100 if(job_list.front().target)
1102 VERBOSE_OUT(4)<<_("Setting the canvas on the target...")<<endl;
1103 job_list.front().target->set_canvas(job_list.front().canvas);
1104 VERBOSE_OUT(4)<<_("Setting the quality of the target...")<<endl;
1105 job_list.front().target->set_quality(job_list.front().quality);
1108 // Set the threads for the target
1109 if(job_list.front().target && Target_Scanline::Handle::cast_dynamic(job_list.front().target))
1110 Target_Scanline::Handle::cast_dynamic(job_list.front().target)->set_threads(threads);
1112 if(imageargs.size())
1114 cerr<<_("Unidentified arguments for ")<<job_list.front().filename<<": ";
1115 for(;imageargs.size();imageargs.pop_front())
1116 cerr<<' '<<imageargs.front();
1118 cerr<<_("Throwing out job...")<<endl;
1119 job_list.pop_front();
1127 cerr<<_("Unidentified arguments:");
1128 for(;arg_list.size();arg_list.pop_front())
1129 cerr<<' '<<arg_list.front();
1131 return SYNFIGTOOL_UNKNOWNARGUMENT;
1134 if(!job_list.size())
1136 cerr<<_("Nothing to do!")<<endl;
1137 return SYNFIGTOOL_BORED;
1140 for(;job_list.size();job_list.pop_front())
1142 VERBOSE_OUT(3)<<job_list.front().filename<<" -- "<<endl<<'\t'<<
1143 strprintf("w:%d, h:%d, a:%d, pxaspect:%f, imaspect:%f, span:%f",
1144 job_list.front().desc.get_w(),
1145 job_list.front().desc.get_h(),
1146 job_list.front().desc.get_antialias(),
1147 job_list.front().desc.get_pixel_aspect(),
1148 job_list.front().desc.get_image_aspect(),
1149 job_list.front().desc.get_span()
1151 strprintf("tl:[%f,%f], br:[%f,%f], focus:[%f,%f]",
1152 job_list.front().desc.get_tl()[0],job_list.front().desc.get_tl()[1],
1153 job_list.front().desc.get_br()[0],job_list.front().desc.get_br()[1],
1154 job_list.front().desc.get_focus()[0],job_list.front().desc.get_focus()[1]
1158 p.task(job_list.front().filename+" ==> "+job_list.front().outfilename);
1159 if(job_list.front().sifout)
1161 if(!save_canvas(job_list.front().outfilename,job_list.front().canvas))
1163 cerr<<"Render Failure."<<endl;
1164 return SYNFIGTOOL_RENDERFAILURE;
1167 else if (job_list.front().list_canvases)
1169 list_child_canvases(job_list.front().filename + "#", job_list.front().canvas);
1172 else if (job_list.front().canvas_info)
1174 list_canvas_info(job_list.front());
1179 VERBOSE_OUT(1)<<_("Rendering...")<<endl;
1182 // Call the render member of the target
1183 if(!job_list.front().target->render(&p))
1185 cerr<<"Render Failure."<<endl;
1186 return SYNFIGTOOL_RENDERFAILURE;
1188 if(print_benchmarks)
1189 cout<<job_list.front().filename+": Rendered in "<<timer()<<" seconds."<<endl;
1195 VERBOSE_OUT(1)<<_("Done.")<<endl;
1197 return SYNFIGTOOL_OK;