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/targetparam.h>
49 #include <synfig/time.h>
50 #include <synfig/string.h>
51 #include <synfig/paramdesc.h>
52 #include <synfig/main.h>
53 #include <synfig/guid.h>
54 #include <autorevision.h>
55 #include "definitions.h"
57 #include "renderprogress.h"
63 using namespace synfig;
65 /* === G L O B A L S ======================================================= */
70 bool print_benchmarks=false;
72 /* === T Y P E D E F S ===================================================== */
74 typedef list<String> arg_list_t;
75 typedef list<Job> job_list_t;
77 /* === M E T H O D S ======================================================= */
81 cout<<"GUID Test"<<endl;
83 cout<<synfig::GUID().get_string()<<' '<<synfig::GUID().get_string()<<endl;
86 void signal_test_func()
88 cout<<"**SIGNAL CALLED**"<<endl;
93 sigc::signal<void> sig;
94 sigc::connection conn;
95 cout<<"Signal Test"<<endl;
96 conn=sig.connect(sigc::ptr_fun(signal_test_func));
97 cout<<"Next line should exclaim signal called."<<endl;
100 cout<<"Next line should NOT exclaim signal called."<<endl;
105 /* === P R O C E D U R E S ================================================= */
107 void display_help_option(const char *flag, const char *arg, string description)
109 const char spaces[]=" ";
111 cerr << strprintf(" %s %s %s", flag, arg, spaces+strlen(arg)+strlen(flag)+1)+description << endl;
113 cerr << strprintf(" %s %s", flag, spaces+strlen(flag))+description << endl;
116 void display_help(bool full)
118 cerr << endl << _("syntax: ") << progname << " [DEFAULT OPTIONS] ([SIF FILE] [SPECIFIC OPTIONS])..." << endl << endl;
122 display_help_option("-t", "<output type>", _("Specify output target (Default:unknown)"));
123 display_help_option("-w", "<pixel width>", _("Set the image width (Use zero for file default)"));
124 display_help_option("-h", "<pixel height>", _("Set the image height (Use zero for file default)"));
125 display_help_option("-s", "<image dist>", _("Set the diagonal size of image window (Span)"));
126 display_help_option("-a", "<1...30>", _("Set antialias amount for parametric renderer."));
127 display_help_option("-Q", "<0...10>", strprintf(_("Specify image quality for accelerated renderer (default=%d)"), DEFAULT_QUALITY).c_str());
128 display_help_option("-g", "<amount>", _("Gamma (default=2.2)"));
129 display_help_option("-v", NULL, _("Verbose Output (add more for more verbosity)"));
130 display_help_option("-q", NULL, _("Quiet mode (No progress/time-remaining display)"));
131 display_help_option("-c", "<canvas id>", _("Render the canvas with the given id instead of the root."));
132 display_help_option("-o", "<output file>", _("Specify output filename"));
133 display_help_option("-T", "<# of threads>", _("Enable multithreaded renderer using specified # of threads"));
134 display_help_option("-b", NULL, _("Print Benchmarks"));
135 display_help_option("--fps", "<framerate>", _("Set the frame rate"));
136 display_help_option("--time", "<time>", _("Render a single frame at <seconds>"));
137 display_help_option("--begin-time", "<time>", _("Set the starting time"));
138 display_help_option("--start-time", "<time>", _("Set the starting time"));
139 display_help_option("--end-time", "<time>", _("Set the ending time"));
140 display_help_option("--dpi", "<res>", _("Set the physical resolution (dots-per-inch)"));
141 display_help_option("--dpi-x", "<res>", _("Set the physical X resolution (dots-per-inch)"));
142 display_help_option("--dpi-y", "<res>", _("Set the physical Y resolution (dots-per-inch)"));
144 display_help_option("--list-canvases", NULL, _("List the exported canvases in the composition"));
145 display_help_option("--canvas-info", "<fields>", _("Print out specified details of the root canvas"));
146 display_help_option("--append", "<filename>", _("Append layers in <filename> to composition"));
148 display_help_option("--layer-info", "<layer>", _("Print out layer's description, parameter info, etc."));
149 display_help_option("--layers", NULL, _("Print out the list of available layers"));
150 display_help_option("--targets", NULL, _("Print out the list of available targets"));
151 display_help_option("--importers", NULL, _("Print out the list of available importers"));
152 display_help_option("--valuenodes", NULL, _("Print out the list of available ValueNodes"));
153 display_help_option("--modules", NULL, _("Print out the list of loaded modules"));
154 display_help_option("--version", NULL, _("Print out version information"));
155 display_help_option("--info", NULL, _("Print out misc build information"));
156 display_help_option("--license", NULL, _("Print out license information"));
159 display_help_option("--guid-test", NULL, _("Test GUID generation"));
160 display_help_option("--signal-test", NULL, _("Test signal implementation"));
164 display_help_option("--help", NULL, _("Print out usage and syntax info"));
169 int process_global_flags(arg_list_t &arg_list)
171 arg_list_t::iterator iter, next;
173 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
176 return SYNFIGTOOL_OK;
178 if(*iter == "--signal-test")
181 return SYNFIGTOOL_HELP;
184 if(*iter == "--guid-test")
187 return SYNFIGTOOL_HELP;
190 if(*iter == "--help")
193 return SYNFIGTOOL_HELP;
196 if(*iter == "--info")
198 cout<<PACKAGE"-"VERSION<<endl;
200 cout<<endl<<DEVEL_VERSION<<endl<<endl;
202 cout<<"Compiled on "__DATE__ /* " at "__TIME__ */;
204 cout<<" with GCC "<<__VERSION__;
207 cout<<" with Microsoft Visual C++ "<<(_MSC_VER>>8)<<'.'<<(_MSC_VER&255);
209 #ifdef __TCPLUSPLUS__
210 cout<<" with Borland Turbo C++ "<<(__TCPLUSPLUS__>>8)<<'.'<<((__TCPLUSPLUS__&255)>>4)<<'.'<<(__TCPLUSPLUS__&15);
212 cout<<endl<<SYNFIG_COPYRIGHT<<endl;
214 return SYNFIGTOOL_HELP;
217 if(*iter == "--layers")
220 synfig::Main synfig_main(dirname(progname),&p);
221 synfig::Layer::Book::iterator iter=synfig::Layer::book().begin();
222 for(;iter!=synfig::Layer::book().end();iter++)
223 if (iter->second.category != CATEGORY_DO_NOT_USE)
224 cout<<iter->first<<endl;
226 return SYNFIGTOOL_HELP;
229 if(*iter == "--layer-info")
232 synfig::Main synfig_main(dirname(progname),&p);
234 if (iter==arg_list.end())
236 error("The `%s' flag requires a value. Use --help for a list of options.", "--layer-info");
237 return SYNFIGTOOL_MISSINGARGUMENT;
239 Layer::Handle layer=synfig::Layer::create(*iter);
240 cout<<"Layer Name: "<<layer->get_name()<<endl;
241 cout<<"Localized Layer Name: "<<layer->get_local_name()<<endl;
242 cout<<"Version: "<<layer->get_version()<<endl;
243 Layer::Vocab vocab=layer->get_param_vocab();
244 for(;!vocab.empty();vocab.pop_front())
246 cout<<"param - "<<vocab.front().get_name();
247 if(!vocab.front().get_critical())
248 cout<<" (not critical)";
249 cout<<endl<<"\tLocalized Name: "<<vocab.front().get_local_name()<<endl;
250 if(!vocab.front().get_description().empty())
251 cout<<"\tDescription: "<<vocab.front().get_description()<<endl;
252 if(!vocab.front().get_hint().empty())
253 cout<<"\tHint: "<<vocab.front().get_hint()<<endl;
256 return SYNFIGTOOL_HELP;
259 if(*iter == "--modules")
262 synfig::Main synfig_main(dirname(progname),&p);
263 synfig::Module::Book::iterator iter=synfig::Module::book().begin();
264 for(;iter!=synfig::Module::book().end();iter++)
265 cout<<iter->first<<endl;
266 return SYNFIGTOOL_HELP;
269 if(*iter == "--targets")
272 synfig::Main synfig_main(dirname(progname),&p);
273 synfig::Target::Book::iterator iter=synfig::Target::book().begin();
274 for(;iter!=synfig::Target::book().end();iter++)
275 cout<<iter->first<<endl;
276 return SYNFIGTOOL_HELP;
279 if(*iter == "--valuenodes")
282 synfig::Main synfig_main(dirname(progname),&p);
283 synfig::LinkableValueNode::Book::iterator iter=synfig::LinkableValueNode::book().begin();
284 for(;iter!=synfig::LinkableValueNode::book().end();iter++)
285 cout<<iter->first<<endl;
286 return SYNFIGTOOL_HELP;
289 if(*iter == "--importers")
292 synfig::Main synfig_main(dirname(progname),&p);
293 synfig::Importer::Book::iterator iter=synfig::Importer::book().begin();
294 for(;iter!=synfig::Importer::book().end();iter++)
295 cout<<iter->first<<endl;
296 return SYNFIGTOOL_HELP;
299 if(*iter == "--version")
301 cerr<<PACKAGE<<" "<<VERSION<<endl;
302 arg_list.erase(iter);
303 return SYNFIGTOOL_HELP;
306 if(*iter == "--license")
308 cerr<<PACKAGE<<" "<<VERSION<<endl;
309 cout<<SYNFIG_COPYRIGHT<<endl<<endl;
311 ** This package is free software; you can redistribute it and/or\n\
312 ** modify it under the terms of the GNU General Public License as\n\
313 ** published by the Free Software Foundation; either version 2 of\n\
314 ** the License, or (at your option) any later version.\n\
316 ** " << endl << endl;
317 arg_list.erase(iter);
318 return SYNFIGTOOL_HELP;
324 arg_list.erase(iter);
331 arg_list.erase(iter);
336 print_benchmarks=true;
337 arg_list.erase(iter);
342 return SYNFIGTOOL_OK;
345 /* true if the given flag takes an extra parameter */
346 bool flag_requires_value(String flag)
348 return (flag=="-a" || flag=="-c" || flag=="-g" || flag=="-h" || flag=="-o" ||
349 flag=="-Q" || flag=="-s" || flag=="-t" || flag=="-T" || flag=="-w" ||
350 flag=="--append" || flag=="--begin-time" || flag=="--canvas-info"|| flag=="--dpi" || flag=="--dpi-x" ||
351 flag=="--dpi-y" || flag=="--end-time" || flag=="--fps" || flag=="--layer-info" || flag=="--start-time" ||
352 flag=="--time" || flag=="-vc" || flag=="-vb");
355 int extract_arg_cluster(arg_list_t &arg_list,arg_list_t &cluster)
357 arg_list_t::iterator iter, next;
359 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
361 if(*iter->begin() != '-')
363 //cerr<<*iter->begin()<<"-----------"<<endl;
364 return SYNFIGTOOL_OK;
367 if (flag_requires_value(*iter))
369 cluster.push_back(*iter);
370 arg_list.erase(iter);
372 if (iter==arg_list.end())
374 error("The `%s' flag requires a value. Use --help for a list of options.", cluster.back().c_str());
375 return SYNFIGTOOL_MISSINGARGUMENT;
379 cluster.push_back(*iter);
380 arg_list.erase(iter);
383 return SYNFIGTOOL_OK;
386 /*! Extract a parameter from the argument list
388 * \param arg_list Argument list from wich the parameter is extracted.
389 * \param iter Iterator pointing to the argument list parameter to be
391 * \param next Iterator pointing to the next argument.
393 string extract_parameter (arg_list_t& arg_list,
394 arg_list_t::iterator& iter,
395 arg_list_t::iterator& next)
398 arg_list.erase(iter);
401 arg_list.erase(iter);
405 int extract_RendDesc(arg_list_t &arg_list,RendDesc &desc)
407 arg_list_t::iterator iter, next;
410 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
414 w = atoi(extract_parameter(arg_list, iter, next).c_str());
418 h = atoi(extract_parameter(arg_list, iter, next).c_str());
423 a = atoi(extract_parameter(arg_list, iter, next).c_str());
424 desc.set_antialias(a);
425 VERBOSE_OUT(1)<<strprintf(_("Antialiasing set to %d, (%d samples per pixel)"),a,a*a)<<endl;
429 span = atoi(extract_parameter(arg_list, iter, next).c_str());
430 VERBOSE_OUT(1)<<strprintf(_("Span set to %d units"),span)<<endl;
432 else if(*iter=="--fps")
434 float fps = atof(extract_parameter(arg_list, iter, next).c_str());
435 desc.set_frame_rate(fps);
436 VERBOSE_OUT(1)<<strprintf(_("Frame rate set to %d frames per second"),fps)<<endl;
438 else if(*iter=="--dpi")
440 float dpi = atof(extract_parameter(arg_list, iter, next).c_str());
441 float dots_per_meter=dpi*39.3700787402;
442 desc.set_x_res(dots_per_meter).set_y_res(dots_per_meter);
443 VERBOSE_OUT(1)<<strprintf(_("Physical resolution set to %f dpi"),dpi)<<endl;
445 else if(*iter=="--dpi-x")
447 float dpi = atof(extract_parameter(arg_list, iter, next).c_str());
448 float dots_per_meter=dpi*39.3700787402;
449 desc.set_x_res(dots_per_meter);
450 VERBOSE_OUT(1)<<strprintf(_("Physical X resolution set to %f dpi"),dpi)<<endl;
452 else if(*iter=="--dpi-y")
454 float dpi = atof(extract_parameter(arg_list, iter, next).c_str());
455 float dots_per_meter=dpi*39.3700787402;
456 desc.set_y_res(dots_per_meter);
457 VERBOSE_OUT(1)<<strprintf(_("Physical Y resolution set to %f dpi"),dpi)<<endl;
459 else if(*iter=="--start-time" || *iter=="--begin-time")
461 desc.set_time_start(Time(extract_parameter(arg_list, iter, next),
462 desc.get_frame_rate()));
464 else if(*iter=="--end-time")
466 desc.set_time_end(Time(extract_parameter(arg_list, iter, next),
467 desc.get_frame_rate()));
469 else if(*iter=="--time")
471 desc.set_time(Time(extract_parameter(arg_list, iter, next),
472 desc.get_frame_rate()));
473 VERBOSE_OUT(1)<<_("Rendering frame at ")<<desc.get_time_start().get_string(desc.get_frame_rate())<<endl;
477 synfig::warning("Gamma argument is currently ignored");
478 //desc.set_gamma(Gamma(atoi(extract_parameter(arg_list, iter, next).c_str())));
480 else if (flag_requires_value(*iter))
486 w = desc.get_w() * h / desc.get_h();
488 h = desc.get_h() * w / desc.get_w();
491 VERBOSE_OUT(1)<<strprintf(_("Resolution set to %dx%d"),w,h)<<endl;
495 return SYNFIGTOOL_OK;
498 int extract_quality(arg_list_t &arg_list,int &quality)
500 arg_list_t::iterator iter, next;
501 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
505 quality = atoi(extract_parameter(arg_list, iter, next).c_str());
506 VERBOSE_OUT(1)<<strprintf(_("Quality set to %d"),quality)<<endl;
508 else if (flag_requires_value(*iter))
512 return SYNFIGTOOL_OK;
515 int extract_threads(arg_list_t &arg_list,int &threads)
517 arg_list_t::iterator iter, next;
518 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
522 threads = atoi(extract_parameter(arg_list, iter, next).c_str());
523 VERBOSE_OUT(1)<<strprintf(_("Threads set to %d"),threads)<<endl;
525 else if (flag_requires_value(*iter))
529 return SYNFIGTOOL_OK;
532 int extract_target(arg_list_t &arg_list,string &type)
534 arg_list_t::iterator iter, next;
537 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
541 type = extract_parameter(arg_list, iter, next);
543 else if (flag_requires_value(*iter))
547 return SYNFIGTOOL_OK;
550 int extract_target_params(arg_list_t& arg_list,
553 arg_list_t::iterator iter, next;
555 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
559 // Target video codec
560 params.video_codec = extract_parameter(arg_list, iter, next);
562 else if(*iter=="-vb")
566 atoi(extract_parameter(arg_list, iter, next).c_str());
568 else if (flag_requires_value(*iter))
572 return SYNFIGTOOL_OK;
575 int extract_append(arg_list_t &arg_list,string &filename)
577 arg_list_t::iterator iter, next;
580 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
582 if(*iter=="--append")
584 filename = extract_parameter(arg_list, iter, next);
586 else if (flag_requires_value(*iter))
590 return SYNFIGTOOL_OK;
593 int extract_outfile(arg_list_t &arg_list,string &outfile)
595 arg_list_t::iterator iter, next;
596 int ret=SYNFIGTOOL_FILENOTFOUND;
599 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
603 outfile = extract_parameter(arg_list, iter, next);
606 else if (flag_requires_value(*iter))
613 int extract_canvasid(arg_list_t &arg_list,string &canvasid)
615 arg_list_t::iterator iter, next;
618 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
622 canvasid = extract_parameter(arg_list, iter, next);
624 else if (flag_requires_value(*iter))
628 return SYNFIGTOOL_OK;
631 int extract_list_canvases(arg_list_t &arg_list,bool &list_canvases)
633 arg_list_t::iterator iter, next;
635 for(next=arg_list.begin(), iter = next++; iter!=arg_list.end();
637 if(*iter=="--list-canvases")
639 list_canvases = true;
640 arg_list.erase(iter);
643 return SYNFIGTOOL_OK;
646 void extract_canvas_info(arg_list_t &arg_list, Job &job)
648 arg_list_t::iterator iter, next;
650 for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
651 if(*iter=="--canvas-info")
653 job.canvas_info = true;
654 String values(extract_parameter(arg_list, iter, next)), value;
656 std::string::size_type pos;
657 while (!values.empty())
659 pos = values.find_first_of(',');
660 if (pos == std::string::npos)
667 value = values.substr(0, pos);
668 values = values.substr(pos+1);
672 job.canvas_info_all = true;
676 if (value == "time_start") job.canvas_info_time_start = true;
677 else if (value == "time_end") job.canvas_info_time_end = true;
678 else if (value == "frame_rate") job.canvas_info_frame_rate = true;
679 else if (value == "frame_start") job.canvas_info_frame_start = true;
680 else if (value == "frame_end") job.canvas_info_frame_end = true;
681 else if (value == "w") job.canvas_info_w = true;
682 else if (value == "h") job.canvas_info_h = true;
683 else if (value == "image_aspect") job.canvas_info_image_aspect = true;
684 else if (value == "pw") job.canvas_info_pw = true;
685 else if (value == "ph") job.canvas_info_ph = true;
686 else if (value == "pixel_aspect") job.canvas_info_pixel_aspect = true;
687 else if (value == "tl") job.canvas_info_tl = true;
688 else if (value == "br") job.canvas_info_br = true;
689 else if (value == "physical_w") job.canvas_info_physical_w = true;
690 else if (value == "physical_h") job.canvas_info_physical_h = true;
691 else if (value == "x_res") job.canvas_info_x_res = true;
692 else if (value == "y_res") job.canvas_info_y_res = true;
693 else if (value == "span") job.canvas_info_span = true;
694 else if (value == "interlaced") job.canvas_info_interlaced = true;
695 else if (value == "antialias") job.canvas_info_antialias = true;
696 else if (value == "clamp") job.canvas_info_clamp = true;
697 else if (value == "flags") job.canvas_info_flags = true;
698 else if (value == "focus") job.canvas_info_focus = true;
699 else if (value == "bg_color") job.canvas_info_bg_color = true;
700 else if (value == "metadata") job.canvas_info_metadata = true;
703 cerr<<_("Unrecognised canvas variable: ") << "'" << value << "'" << endl;
704 cerr<<_("Recognized variables are:") << endl <<
705 " all, time_start, time_end, frame_rate, frame_start, frame_end, w, h," << endl <<
706 " image_aspect, pw, ph, pixel_aspect, tl, br, physical_w, physical_h," << endl <<
707 " x_res, y_res, span, interlaced, antialias, clamp, flags," << endl <<
708 " focus, bg_color, metadata" << endl;
711 if (pos == std::string::npos)
717 void list_child_canvases(string prefix, Canvas::Handle canvas)
719 Canvas::Children children(canvas->children());
720 for (Canvas::Children::iterator iter = children.begin(); iter != children.end(); iter++)
722 cout << prefix << ":" << (*iter)->get_id() << endl;
723 list_child_canvases(prefix + ":" + (*iter)->get_id(), *iter);
727 void list_canvas_info(Job job)
729 Canvas::Handle canvas(job.canvas);
730 const RendDesc &rend_desc(canvas->rend_desc());
732 if (job.canvas_info_all || job.canvas_info_time_start)
734 cout << endl << "# " << _("Start Time") << endl;
735 cout << "time_start" << "=" << rend_desc.get_time_start().get_string().c_str() << endl;
738 if (job.canvas_info_all || job.canvas_info_time_end)
740 cout << endl << "# " << _("End Time") << endl;
741 cout << "time_end" << "=" << rend_desc.get_time_end().get_string().c_str() << endl;
744 if (job.canvas_info_all || job.canvas_info_frame_rate)
746 cout << endl << "# " << _("Frame Rate") << endl;
747 cout << "frame_rate" << "=" << rend_desc.get_frame_rate() << endl;
750 if (job.canvas_info_all || job.canvas_info_frame_start)
752 cout << endl << "# " << _("Start Frame") << endl;
753 cout << "frame_start" << "=" << rend_desc.get_frame_start() << endl;
756 if (job.canvas_info_all || job.canvas_info_frame_end)
758 cout << endl << "# " << _("End Frame") << endl;
759 cout << "frame_end" << "=" << rend_desc.get_frame_end() << endl;
762 if (job.canvas_info_all)
765 if (job.canvas_info_all || job.canvas_info_w)
767 cout << endl << "# " << _("Width") << endl;
768 cout << "w" << "=" << rend_desc.get_w() << endl;
771 if (job.canvas_info_all || job.canvas_info_h)
773 cout << endl << "# " << _("Height") << endl;
774 cout << "h" << "=" << rend_desc.get_h() << endl;
777 if (job.canvas_info_all || job.canvas_info_image_aspect)
779 cout << endl << "# " << _("Image Aspect Ratio") << endl;
780 cout << "image_aspect" << "=" << rend_desc.get_image_aspect() << endl;
783 if (job.canvas_info_all)
786 if (job.canvas_info_all || job.canvas_info_pw)
788 cout << endl << "# " << _("Pixel Width") << endl;
789 cout << "pw" << "=" << rend_desc.get_pw() << endl;
792 if (job.canvas_info_all || job.canvas_info_ph)
794 cout << endl << "# " << _("Pixel Height") << endl;
795 cout << "ph" << "=" << rend_desc.get_ph() << endl;
798 if (job.canvas_info_all || job.canvas_info_pixel_aspect)
800 cout << endl << "# " << _("Pixel Aspect Ratio") << endl;
801 cout << "pixel_aspect" << "=" << rend_desc.get_pixel_aspect() << endl;
804 if (job.canvas_info_all)
807 if (job.canvas_info_all || job.canvas_info_tl)
809 cout << endl << "# " << _("Top Left") << endl;
810 cout << "tl" << "=" << rend_desc.get_tl()[0]
811 << " " << rend_desc.get_tl()[1] << endl;
814 if (job.canvas_info_all || job.canvas_info_br)
816 cout << endl << "# " << _("Bottom Right") << endl;
817 cout << "br" << "=" << rend_desc.get_br()[0]
818 << " " << rend_desc.get_br()[1] << endl;
821 if (job.canvas_info_all || job.canvas_info_physical_w)
823 cout << endl << "# " << _("Physical Width") << endl;
824 cout << "physical_w" << "=" << rend_desc.get_physical_w() << endl;
827 if (job.canvas_info_all || job.canvas_info_physical_h)
829 cout << endl << "# " << _("Physical Height") << endl;
830 cout << "physical_h" << "=" << rend_desc.get_physical_h() << endl;
833 if (job.canvas_info_all || job.canvas_info_x_res)
835 cout << endl << "# " << _("X Resolution") << endl;
836 cout << "x_res" << "=" << rend_desc.get_x_res() << endl;
839 if (job.canvas_info_all || job.canvas_info_y_res)
841 cout << endl << "# " << _("Y Resolution") << endl;
842 cout << "y_res" << "=" << rend_desc.get_y_res() << endl;
845 if (job.canvas_info_all || job.canvas_info_span)
847 cout << endl << "# " << _("Diagonal Image Span") << endl;
848 cout << "span" << "=" << rend_desc.get_span() << endl;
851 if (job.canvas_info_all)
854 if (job.canvas_info_all || job.canvas_info_interlaced)
856 cout << endl << "# " << _("Interlaced") << endl;
857 cout << "interlaced" << "=" << rend_desc.get_interlaced() << endl;
860 if (job.canvas_info_all || job.canvas_info_antialias)
862 cout << endl << "# " << _("Antialias") << endl;
863 cout << "antialias" << "=" << rend_desc.get_antialias() << endl;
866 if (job.canvas_info_all || job.canvas_info_clamp)
868 cout << endl << "# " << _("Clamp") << endl;
869 cout << "clamp" << "=" << rend_desc.get_clamp() << endl;
872 if (job.canvas_info_all || job.canvas_info_flags)
874 cout << endl << "# " << _("Flags") << endl;
875 cout << "flags" << "=" << rend_desc.get_flags() << endl;
878 if (job.canvas_info_all || job.canvas_info_focus)
880 cout << endl << "# " << _("Focus") << endl;
881 cout << "focus" << "=" << rend_desc.get_focus()[0]
882 << " " << rend_desc.get_focus()[1] << endl;
885 if (job.canvas_info_all || job.canvas_info_bg_color)
887 cout << endl << "# " << _("Background Color") << endl;
888 cout << "bg_color" << "=" << rend_desc.get_bg_color().get_string().c_str() << endl;
891 if (job.canvas_info_all)
894 if (job.canvas_info_all || job.canvas_info_metadata)
896 std::list<String> keys(canvas->get_meta_data_keys());
897 cout << endl << "# " << _("Metadata") << endl;
898 for (std::list<String>::iterator iter = keys.begin(); iter != keys.end(); iter++)
899 cout << *iter << "=" << canvas->get_meta_data(*iter) << endl;
903 /* === M E T H O D S ======================================================= */
905 /* === E N T R Y P O I N T ================================================= */
907 int main(int argc, char *argv[])
913 setlocale(LC_ALL, "");
916 bindtextdomain("synfig", LOCALEDIR);
917 bind_textdomain_codeset("synfig", "UTF-8");
918 textdomain("synfig");
924 if(!SYNFIG_CHECK_VERSION())
926 cerr<<_("FATAL: Synfig Version Mismatch")<<endl;
927 return SYNFIGTOOL_BADVERSION;
933 return SYNFIGTOOL_BLANK;
937 arg_list.push_back(argv[i]);
939 if((i=process_global_flags(arg_list)))
942 VERBOSE_OUT(1)<<_("verbosity set to ")<<verbosity<<endl;
943 synfig::Main synfig_main(dirname(progname),&p);
946 arg_list_t defaults, imageargs;
949 // Grab the defaults before the first file
950 if ((ret = extract_arg_cluster(arg_list,defaults)) != SYNFIGTOOL_OK)
953 while(arg_list.size())
956 job_list.push_front(Job());
960 job_list.front().filename=arg_list.front();
961 arg_list.pop_front();
963 if ((ret = extract_arg_cluster(arg_list,imageargs)) != SYNFIGTOOL_OK)
966 // Open the composition
967 String errors, warnings;
970 job_list.front().root=open_canvas(job_list.front().filename, errors, warnings);
972 catch(runtime_error x)
974 job_list.front().root = 0;
977 if(!job_list.front().root)
979 cerr<<_("Unable to load '")<<job_list.front().filename<<"'."<<endl;
980 cerr<<_("Throwing out job...")<<endl;
981 job_list.pop_front();
985 bool list_canvases = false;
986 extract_list_canvases(imageargs, list_canvases);
987 job_list.front().list_canvases = list_canvases;
989 extract_canvas_info(imageargs, job_list.front());
991 job_list.front().root->set_time(0);
994 extract_canvasid(imageargs,canvasid);
995 if(!canvasid.empty())
1000 job_list.front().canvas=job_list.front().root->find_canvas(canvasid, warnings);
1002 catch(Exception::IDNotFound)
1004 cerr<<_("Unable to find canvas with ID \"")<<canvasid<<_("\" in ")<<job_list.front().filename<<"."<<endl;
1005 cerr<<_("Throwing out job...")<<endl;
1006 job_list.pop_front();
1010 catch(Exception::BadLinkName)
1012 cerr<<_("Invalid canvas name \"")<<canvasid<<_("\" in ")<<job_list.front().filename<<"."<<endl;
1013 cerr<<_("Throwing out job...")<<endl;
1014 job_list.pop_front();
1019 job_list.front().canvas=job_list.front().root;
1021 extract_RendDesc(imageargs,job_list.front().canvas->rend_desc());
1022 extract_target(imageargs,target_name);
1023 extract_threads(imageargs,threads);
1024 job_list.front().quality=DEFAULT_QUALITY;
1025 extract_quality(imageargs,job_list.front().quality);
1026 VERBOSE_OUT(2)<<_("Quality set to ")<<job_list.front().quality<<endl;
1027 job_list.front().desc=job_list.front().canvas->rend_desc();
1028 extract_outfile(imageargs,job_list.front().outfilename);
1030 // Extract composite
1032 string composite_file;
1033 extract_append(imageargs,composite_file);
1034 if(!composite_file.empty())
1036 String errors, warnings;
1037 Canvas::Handle composite(open_canvas(composite_file, errors, warnings));
1040 cerr<<_("Unable to append '")<<composite_file<<"'."<<endl;
1043 Canvas::reverse_iterator iter;
1044 for(iter=composite->rbegin();iter!=composite->rend();++iter)
1046 Layer::Handle layer(*iter);
1048 job_list.front().canvas->push_front(layer->clone());
1050 VERBOSE_OUT(2)<<_("Appended contents of ")<<composite_file<<endl;
1054 VERBOSE_OUT(4)<<_("Attempting to determine target/outfile...")<<endl;
1056 // If the target type is not yet defined,
1057 // try to figure it out from the outfile.
1058 if(target_name.empty() && !job_list.front().outfilename.empty())
1060 VERBOSE_OUT(3)<<_("Target name undefined, attempting to figure it out")<<endl;
1061 string ext = filename_extension(job_list.front().outfilename);
1062 if (ext.length()) ext = ext.substr(1);
1063 if(Target::ext_book().count(ext))
1065 target_name=Target::ext_book()[ext];
1066 info("target name not specified - using %s", target_name.c_str());
1070 string lower_ext(ext);
1072 for(unsigned int i=0;i<ext.length();i++)
1073 lower_ext[i] = tolower(ext[i]);
1075 if(Target::ext_book().count(lower_ext))
1077 target_name=Target::ext_book()[lower_ext];
1078 info("target name not specified - using %s", target_name.c_str());
1085 TargetParam target_parameters;
1086 // Extract the extra parameters for the targets that
1088 if (target_name == "ffmpeg")
1089 extract_target_params(imageargs, target_parameters);
1091 // If the target type is STILL not yet defined, then
1092 // set it to a some sort of default
1093 if(target_name.empty())
1095 VERBOSE_OUT(2)<<_("Defaulting to PNG target...")<<endl;
1099 // If no output filename was provided, then
1100 // create a output filename based on the
1101 // given input filename. (ie: change the extension)
1102 if(job_list.front().outfilename.empty())
1104 job_list.front().outfilename = filename_sans_extension(job_list.front().filename) + '.';
1105 if(Target::book().count(target_name))
1106 job_list.front().outfilename+=Target::book()[target_name].filename;
1108 job_list.front().outfilename+=target_name;
1111 VERBOSE_OUT(4)<<"target_name="<<target_name<<endl;
1112 VERBOSE_OUT(4)<<"outfile_name="<<job_list.front().outfilename<<endl;
1114 VERBOSE_OUT(4)<<_("Creating the target...")<<endl;
1115 job_list.front().target =
1116 synfig::Target::create(target_name,
1117 job_list.front().outfilename,
1120 if(target_name=="sif")
1121 job_list.front().sifout=true;
1124 if(!job_list.front().target)
1126 cerr<<_("Unknown target for ")<<job_list.front().filename<<": "<<target_name<<endl;
1127 cerr<<_("Throwing out job...")<<endl;
1128 job_list.pop_front();
1131 job_list.front().sifout=false;
1134 // Set the Canvas on the Target
1135 if(job_list.front().target)
1137 VERBOSE_OUT(4)<<_("Setting the canvas on the target...")<<endl;
1138 job_list.front().target->set_canvas(job_list.front().canvas);
1139 VERBOSE_OUT(4)<<_("Setting the quality of the target...")<<endl;
1140 job_list.front().target->set_quality(job_list.front().quality);
1143 // Set the threads for the target
1144 if(job_list.front().target && Target_Scanline::Handle::cast_dynamic(job_list.front().target))
1145 Target_Scanline::Handle::cast_dynamic(job_list.front().target)->set_threads(threads);
1147 if(imageargs.size())
1149 cerr<<_("Unidentified arguments for ")<<job_list.front().filename<<": ";
1150 for(;imageargs.size();imageargs.pop_front())
1151 cerr<<' '<<imageargs.front();
1153 cerr<<_("Throwing out job...")<<endl;
1154 job_list.pop_front();
1162 cerr<<_("Unidentified arguments:");
1163 for(;arg_list.size();arg_list.pop_front())
1164 cerr<<' '<<arg_list.front();
1166 return SYNFIGTOOL_UNKNOWNARGUMENT;
1169 if(!job_list.size())
1171 cerr<<_("Nothing to do!")<<endl;
1172 return SYNFIGTOOL_BORED;
1175 for(;job_list.size();job_list.pop_front())
1177 VERBOSE_OUT(3)<<job_list.front().filename<<" -- "<<endl<<'\t'<<
1178 strprintf("w:%d, h:%d, a:%d, pxaspect:%f, imaspect:%f, span:%f",
1179 job_list.front().desc.get_w(),
1180 job_list.front().desc.get_h(),
1181 job_list.front().desc.get_antialias(),
1182 job_list.front().desc.get_pixel_aspect(),
1183 job_list.front().desc.get_image_aspect(),
1184 job_list.front().desc.get_span()
1186 strprintf("tl:[%f,%f], br:[%f,%f], focus:[%f,%f]",
1187 job_list.front().desc.get_tl()[0],job_list.front().desc.get_tl()[1],
1188 job_list.front().desc.get_br()[0],job_list.front().desc.get_br()[1],
1189 job_list.front().desc.get_focus()[0],job_list.front().desc.get_focus()[1]
1193 p.task(job_list.front().filename+" ==> "+job_list.front().outfilename);
1194 if(job_list.front().sifout)
1196 if(!save_canvas(job_list.front().outfilename,job_list.front().canvas))
1198 cerr<<"Render Failure."<<endl;
1199 return SYNFIGTOOL_RENDERFAILURE;
1202 else if (job_list.front().list_canvases)
1204 list_child_canvases(job_list.front().filename + "#", job_list.front().canvas);
1207 else if (job_list.front().canvas_info)
1209 list_canvas_info(job_list.front());
1214 VERBOSE_OUT(1)<<_("Rendering...")<<endl;
1217 // Call the render member of the target
1218 if(!job_list.front().target->render(&p))
1220 cerr<<"Render Failure."<<endl;
1221 return SYNFIGTOOL_RENDERFAILURE;
1223 if(print_benchmarks)
1224 cout<<job_list.front().filename+": Rendered in "<<timer()<<" seconds."<<endl;
1230 VERBOSE_OUT(1)<<_("Done.")<<endl;
1232 return SYNFIGTOOL_OK;