e5516d4a7c023995a2e7b145be6aa4ff8386ddfd
[synfig.git] / synfig-core / src / tool / main.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file tool/main.cpp
3 **      \brief SYNFIG Tool
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007, 2008 Chris Moore
10 **
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.
15 **
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.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include <iostream>
34 #include <ETL/stringf>
35 #include <list>
36 #include <ETL/clock>
37 #include <algorithm>
38 #include <cstring>
39
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"
56 #include "progress.h"
57 #include "renderprogress.h"
58 #include "job.h"
59 #endif
60
61 using namespace std;
62 using namespace etl;
63 using namespace synfig;
64
65 /* === G L O B A L S ======================================================= */
66
67 const char *progname;
68 int verbosity=0;
69 bool be_quiet=false;
70 bool print_benchmarks=false;
71
72 //! Allowed video codecs
73 /*! \warning This variable is linked to allowed_video_codecs_description,
74  *  if you change this you must change the other acordingly.
75  *  \warning These codecs are linked to the filename extensions for
76  *  mod_ffmpeg. If you change this you must change the others acordingly.
77  */
78 const char* allowed_video_codecs[] =
79 {
80         "flv", "gif", "h263", "h263p", "huffyuv", "libtheora",
81         "libx264", "libxvid", "ljpeg", "mjpeg", "mpeg1video", "mpeg2video",
82         "mpeg4", "msmpeg4",     "msmpeg4v1", "msmpeg4v2", "wmv1", "wmv2", NULL
83 };
84
85 //! Allowed video codecs description.
86 /*! \warning This variable is linked to allowed_video_codecs,
87  *  if you change this you must change the other acordingly.
88  */
89 const char* allowed_video_codecs_description[] =
90 {
91         "Flash Video (FLV) / Sorenson Spark / Sorenson H.263.",
92         "GIF (Graphics Interchange Format).",
93         "H.263 / H.263-1996.",
94         "H.263+ / H.263-1998 / H.263 version 2.",
95         "Huffyuv / HuffYUV.",
96         "libtheora Theora.",
97         "libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10.",
98         "libxvidcore MPEG-4 part 2.",
99         "Lossless JPEG.",
100         "MJPEG (Motion JPEG).",
101         "raw MPEG-1 video.",
102         "raw MPEG-2 video.",
103         "MPEG-4 part 2.",
104         "MPEG-4 part 2 Microsoft variant version 3.",
105         "MPEG-4 part 2 Microsoft variant version 1.",
106         "MPEG-4 part 2 Microsoft variant version 2.",
107         "Windows Media Video 7.",
108         "Windows Media Video 8.",
109         NULL
110 };
111
112 /* === T Y P E D E F S ===================================================== */
113
114 typedef list<String> arg_list_t;
115 typedef list<Job> job_list_t;
116
117 /* === M E T H O D S ======================================================= */
118
119 void guid_test()
120 {
121         cout<<"GUID Test"<<endl;
122         for(int i=20;i;i--)
123                 cout<<synfig::GUID().get_string()<<' '<<synfig::GUID().get_string()<<endl;
124 }
125
126 void signal_test_func()
127 {
128         cout<<"**SIGNAL CALLED**"<<endl;
129 }
130
131 void signal_test()
132 {
133         sigc::signal<void> sig;
134         sigc::connection conn;
135         cout<<"Signal Test"<<endl;
136         conn=sig.connect(sigc::ptr_fun(signal_test_func));
137         cout<<"Next line should exclaim signal called."<<endl;
138         sig();
139         conn.disconnect();
140         cout<<"Next line should NOT exclaim signal called."<<endl;
141         sig();
142         cout<<"done."<<endl;
143 }
144
145 /* === P R O C E D U R E S ================================================= */
146
147 void display_help_option(const char *flag, const char *arg, string description)
148 {
149         const char spaces[]="                      ";
150         if(arg)
151                 cerr << strprintf(" %s %s %s", flag, arg, spaces+strlen(arg)+strlen(flag)+1)+description << endl;
152         else
153                 cerr << strprintf(" %s %s", flag, spaces+strlen(flag))+description << endl;
154 }
155
156 void display_help(bool full)
157 {
158         cerr << endl << _("syntax: ") << progname << " [DEFAULT OPTIONS] ([SIF FILE] [SPECIFIC OPTIONS])..." << endl << endl;
159
160         if(full)
161         {
162                 display_help_option("-t", "<output type>", _("Specify output target (Default:unknown)"));
163                 display_help_option("-w", "<pixel width>", _("Set the image width (Use zero for file default)"));
164                 display_help_option("-h", "<pixel height>", _("Set the image height (Use zero for file default)"));
165                 display_help_option("-s", "<image dist>", _("Set the diagonal size of image window (Span)"));
166                 display_help_option("-a", "<1...30>", _("Set antialias amount for parametric renderer."));
167                 display_help_option("-Q", "<0...10>", strprintf(_("Specify image quality for accelerated renderer (default=%d)"), DEFAULT_QUALITY).c_str());
168                 display_help_option("-g", "<amount>", _("Gamma (default=2.2)"));
169                 display_help_option("-v", NULL, _("Verbose Output (add more for more verbosity)"));
170                 display_help_option("-q", NULL, _("Quiet mode (No progress/time-remaining display)"));
171                 display_help_option("-c", "<canvas id>", _("Render the canvas with the given id instead of the root."));
172                 display_help_option("-o", "<output file>", _("Specify output filename"));
173                 display_help_option("-T", "<# of threads>", _("Enable multithreaded renderer using specified # of threads"));
174                 display_help_option("-b", NULL, _("Print Benchmarks"));
175                 display_help_option("--fps", "<framerate>", _("Set the frame rate"));
176                 display_help_option("--time", "<time>", _("Render a single frame at <seconds>"));
177                 display_help_option("--begin-time", "<time>", _("Set the starting time"));
178                 display_help_option("--start-time", "<time>", _("Set the starting time"));
179                 display_help_option("--end-time", "<time>", _("Set the ending time"));
180                 display_help_option("--dpi", "<res>", _("Set the physical resolution (dots-per-inch)"));
181                 display_help_option("--dpi-x", "<res>", _("Set the physical X resolution (dots-per-inch)"));
182                 display_help_option("--dpi-y", "<res>", _("Set the physical Y resolution (dots-per-inch)"));
183
184                 display_help_option("--list-canvases", NULL, _("List the exported canvases in the composition"));
185                 display_help_option("--canvas-info", "<fields>", _("Print out specified details of the root canvas"));
186                 display_help_option("--append", "<filename>", _("Append layers in <filename> to composition"));
187
188                 display_help_option("--layer-info", "<layer>", _("Print out layer's description, parameter info, etc."));
189                 display_help_option("--layers", NULL, _("Print out the list of available layers"));
190                 display_help_option("--targets", NULL, _("Print out the list of available targets"));
191                 display_help_option("--target-video-codecs", NULL, _("Print out the list of available target video codecs"));
192                 display_help_option("--importers", NULL, _("Print out the list of available importers"));
193                 display_help_option("--valuenodes", NULL, _("Print out the list of available ValueNodes"));
194                 display_help_option("--modules", NULL, _("Print out the list of loaded modules"));
195                 display_help_option("--version", NULL, _("Print out version information"));
196                 display_help_option("--info", NULL, _("Print out misc build information"));
197                 display_help_option("--license", NULL, _("Print out license information"));
198
199 #ifdef _DEBUG
200                 display_help_option("--guid-test", NULL, _("Test GUID generation"));
201                 display_help_option("--signal-test", NULL, _("Test signal implementation"));
202 #endif
203         }
204         else
205                 display_help_option("--help", NULL, _("Print out usage and syntax info"));
206
207         cerr << endl;
208 }
209
210 void display_target_video_codecs_help ()
211 {
212         for (int i = 0; allowed_video_codecs[i] != NULL &&
213                                         allowed_video_codecs_description[i] != NULL; i++)
214                 cout << " " << allowed_video_codecs[i] << ":   \t"
215                          << allowed_video_codecs_description[i]
216                          << endl;
217 }
218
219 int process_global_flags(arg_list_t &arg_list)
220 {
221         arg_list_t::iterator iter, next;
222
223         for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
224         {
225                 if(*iter == "--")
226                         return SYNFIGTOOL_OK;
227
228                 if(*iter == "--signal-test")
229                 {
230                         signal_test();
231                         return SYNFIGTOOL_HELP;
232                 }
233
234                 if(*iter == "--guid-test")
235                 {
236                         guid_test();
237                         return SYNFIGTOOL_HELP;
238                 }
239
240                 if(*iter == "--help")
241                 {
242                         display_help(true);
243                         return SYNFIGTOOL_HELP;
244                 }
245
246                 if(*iter == "--info")
247                 {
248                         cout<<PACKAGE"-"VERSION<<endl;
249                         #ifdef DEVEL_VERSION
250                                 cout<<endl<<DEVEL_VERSION<<endl<<endl;
251                         #endif
252                         cout<<"Compiled on "__DATE__ /* " at "__TIME__ */;
253 #ifdef __GNUC__
254                         cout<<" with GCC "<<__VERSION__;
255 #endif
256 #ifdef _MSC_VER
257                         cout<<" with Microsoft Visual C++ "<<(_MSC_VER>>8)<<'.'<<(_MSC_VER&255);
258 #endif
259 #ifdef __TCPLUSPLUS__
260                         cout<<" with Borland Turbo C++ "<<(__TCPLUSPLUS__>>8)<<'.'<<((__TCPLUSPLUS__&255)>>4)<<'.'<<(__TCPLUSPLUS__&15);
261 #endif
262                         cout<<endl<<SYNFIG_COPYRIGHT<<endl;
263                         cout<<endl;
264                         return SYNFIGTOOL_HELP;
265                 }
266
267                 if(*iter == "--layers")
268                 {
269                         Progress p(PACKAGE);
270                         synfig::Main synfig_main(dirname(progname),&p);
271                         synfig::Layer::Book::iterator iter=synfig::Layer::book().begin();
272                         for(;iter!=synfig::Layer::book().end();iter++)
273                                 if (iter->second.category != CATEGORY_DO_NOT_USE)
274                                         cout<<iter->first<<endl;
275
276                         return SYNFIGTOOL_HELP;
277                 }
278
279                 if(*iter == "--layer-info")
280                 {
281                         Progress p(PACKAGE);
282                         synfig::Main synfig_main(dirname(progname),&p);
283                         iter=next++;
284                         if (iter==arg_list.end())
285                         {
286                                 error("The `%s' flag requires a value.  Use --help for a list of options.", "--layer-info");
287                                 return SYNFIGTOOL_MISSINGARGUMENT;
288                         }
289                         Layer::Handle layer=synfig::Layer::create(*iter);
290                         cout<<"Layer Name: "<<layer->get_name()<<endl;
291                         cout<<"Localized Layer Name: "<<layer->get_local_name()<<endl;
292                         cout<<"Version: "<<layer->get_version()<<endl;
293                         Layer::Vocab vocab=layer->get_param_vocab();
294                         for(;!vocab.empty();vocab.pop_front())
295                         {
296                                 cout<<"param - "<<vocab.front().get_name();
297                                 if(!vocab.front().get_critical())
298                                         cout<<" (not critical)";
299                                 cout<<endl<<"\tLocalized Name: "<<vocab.front().get_local_name()<<endl;
300                                 if(!vocab.front().get_description().empty())
301                                         cout<<"\tDescription: "<<vocab.front().get_description()<<endl;
302                                 if(!vocab.front().get_hint().empty())
303                                         cout<<"\tHint: "<<vocab.front().get_hint()<<endl;
304                         }
305
306                         return SYNFIGTOOL_HELP;
307                 }
308
309                 if(*iter == "--modules")
310                 {
311                         Progress p(PACKAGE);
312                         synfig::Main synfig_main(dirname(progname),&p);
313                         synfig::Module::Book::iterator iter=synfig::Module::book().begin();
314                         for(;iter!=synfig::Module::book().end();iter++)
315                                 cout<<iter->first<<endl;
316                         return SYNFIGTOOL_HELP;
317                 }
318
319                 if(*iter == "--targets")
320                 {
321                         Progress p(PACKAGE);
322                         synfig::Main synfig_main(dirname(progname),&p);
323                         synfig::Target::Book::iterator iter=synfig::Target::book().begin();
324                         for(;iter!=synfig::Target::book().end();iter++)
325                                 cout<<iter->first<<endl;
326                         return SYNFIGTOOL_HELP;
327                 }
328
329                 if(*iter == "--target-video-codecs")
330                 {
331                         display_target_video_codecs_help();
332
333                         return SYNFIGTOOL_HELP;
334                 }
335
336                 if(*iter == "--valuenodes")
337                 {
338                         Progress p(PACKAGE);
339                         synfig::Main synfig_main(dirname(progname),&p);
340                         synfig::LinkableValueNode::Book::iterator iter=synfig::LinkableValueNode::book().begin();
341                         for(;iter!=synfig::LinkableValueNode::book().end();iter++)
342                                 cout<<iter->first<<endl;
343                         return SYNFIGTOOL_HELP;
344                 }
345
346                 if(*iter == "--importers")
347                 {
348                         Progress p(PACKAGE);
349                         synfig::Main synfig_main(dirname(progname),&p);
350                         synfig::Importer::Book::iterator iter=synfig::Importer::book().begin();
351                         for(;iter!=synfig::Importer::book().end();iter++)
352                                 cout<<iter->first<<endl;
353                         return SYNFIGTOOL_HELP;
354                 }
355
356                 if(*iter == "--version")
357                 {
358                         cerr<<PACKAGE<<" "<<VERSION<<endl;
359                         arg_list.erase(iter);
360                         return SYNFIGTOOL_HELP;
361                 }
362
363                 if(*iter == "--license")
364                 {
365                         cerr<<PACKAGE<<" "<<VERSION<<endl;
366                         cout<<SYNFIG_COPYRIGHT<<endl<<endl;
367                         cerr<<"\
368 **      This package is free software; you can redistribute it and/or\n\
369 **      modify it under the terms of the GNU General Public License as\n\
370 **      published by the Free Software Foundation; either version 2 of\n\
371 **      the License, or (at your option) any later version.\n\
372 **\n\
373 **      " << endl << endl;
374                         arg_list.erase(iter);
375                         return SYNFIGTOOL_HELP;
376                 }
377
378                 if(*iter == "-v")
379                 {
380                         verbosity++;
381                         arg_list.erase(iter);
382                         continue;
383                 }
384
385                 if(*iter == "-q")
386                 {
387                         be_quiet=true;
388                         arg_list.erase(iter);
389                         continue;
390                 }
391                 if(*iter == "-b")
392                 {
393                         print_benchmarks=true;
394                         arg_list.erase(iter);
395                         continue;
396                 }
397         }
398
399         return SYNFIGTOOL_OK;
400 }
401
402 /* true if the given flag takes an extra parameter */
403 bool flag_requires_value(String flag)
404 {
405         return (flag=="-a"                      || flag=="-c"                   || flag=="-g"                   || flag=="-h"                   || flag=="-o"                   ||
406                         flag=="-Q"                      || flag=="-s"                   || flag=="-t"                   || flag=="-T"                   || flag=="-w"                   ||
407                         flag=="--append"        || flag=="--begin-time" || flag=="--canvas-info"|| flag=="--dpi"                || flag=="--dpi-x"              ||
408                         flag=="--dpi-y"         || flag=="--end-time"   || flag=="--fps"                || flag=="--layer-info" || flag=="--start-time" ||
409                         flag=="--time"          || flag=="-vc"                  || flag=="-vb");
410 }
411
412 int extract_arg_cluster(arg_list_t &arg_list,arg_list_t &cluster)
413 {
414         arg_list_t::iterator iter, next;
415
416         for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
417         {
418                 if(*iter->begin() != '-')
419                 {
420                         //cerr<<*iter->begin()<<"-----------"<<endl;
421                         return SYNFIGTOOL_OK;
422                 }
423
424                 if (flag_requires_value(*iter))
425                 {
426                         cluster.push_back(*iter);
427                         arg_list.erase(iter);
428                         iter=next++;
429                         if (iter==arg_list.end())
430                         {
431                                 error("The `%s' flag requires a value.  Use --help for a list of options.", cluster.back().c_str());
432                                 return SYNFIGTOOL_MISSINGARGUMENT;
433                         }
434                 }
435
436                 cluster.push_back(*iter);
437                 arg_list.erase(iter);
438         }
439
440         return SYNFIGTOOL_OK;
441 }
442
443 /*! Extract a parameter from the argument list
444  *
445  * \param arg_list Argument list from wich the parameter is extracted.
446  * \param iter Iterator pointing to the argument list parameter to be
447  * extracted.
448  * \param next Iterator pointing to the next argument.
449  */
450 string extract_parameter (arg_list_t& arg_list,
451                                                   arg_list_t::iterator& iter,
452                                                   arg_list_t::iterator& next)
453 {
454         string parameter;
455         arg_list.erase(iter);
456         iter = next++;
457         parameter = *iter;
458         arg_list.erase(iter);
459         return parameter;
460 }
461
462 int extract_RendDesc(arg_list_t &arg_list,RendDesc &desc)
463 {
464         arg_list_t::iterator iter, next;
465         int w=0,h=0;
466         float span=0;
467         for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
468         {
469                 if(*iter=="-w")
470                 {
471                         w = atoi(extract_parameter(arg_list, iter, next).c_str());
472                 }
473                 else if(*iter=="-h")
474                 {
475                         h = atoi(extract_parameter(arg_list, iter, next).c_str());
476                 }
477                 else if(*iter=="-a")
478                 {
479             int a;
480                         a = atoi(extract_parameter(arg_list, iter, next).c_str());
481                         desc.set_antialias(a);
482                         VERBOSE_OUT(1)<<strprintf(_("Antialiasing set to %d, (%d samples per pixel)"),a,a*a)<<endl;
483                 }
484                 else if(*iter=="-s")
485                 {
486                         span = atoi(extract_parameter(arg_list, iter, next).c_str());
487                         VERBOSE_OUT(1)<<strprintf(_("Span set to %d units"),span)<<endl;
488                 }
489                 else if(*iter=="--fps")
490                 {
491                         float fps = atof(extract_parameter(arg_list, iter, next).c_str());
492                         desc.set_frame_rate(fps);
493                         VERBOSE_OUT(1)<<strprintf(_("Frame rate set to %d frames per second"),fps)<<endl;
494                 }
495                 else if(*iter=="--dpi")
496                 {
497                         float dpi = atof(extract_parameter(arg_list, iter, next).c_str());
498                         float dots_per_meter=dpi*39.3700787402;
499                         desc.set_x_res(dots_per_meter).set_y_res(dots_per_meter);
500                         VERBOSE_OUT(1)<<strprintf(_("Physical resolution set to %f dpi"),dpi)<<endl;
501                 }
502                 else if(*iter=="--dpi-x")
503                 {
504                         float dpi = atof(extract_parameter(arg_list, iter, next).c_str());
505                         float dots_per_meter=dpi*39.3700787402;
506                         desc.set_x_res(dots_per_meter);
507                         VERBOSE_OUT(1)<<strprintf(_("Physical X resolution set to %f dpi"),dpi)<<endl;
508                 }
509                 else if(*iter=="--dpi-y")
510                 {
511                         float dpi = atof(extract_parameter(arg_list, iter, next).c_str());
512                         float dots_per_meter=dpi*39.3700787402;
513                         desc.set_y_res(dots_per_meter);
514                         VERBOSE_OUT(1)<<strprintf(_("Physical Y resolution set to %f dpi"),dpi)<<endl;
515                 }
516                 else if(*iter=="--start-time" || *iter=="--begin-time")
517                 {
518                         desc.set_time_start(Time(extract_parameter(arg_list, iter, next),
519                                                                 desc.get_frame_rate()));
520                 }
521                 else if(*iter=="--end-time")
522                 {
523                         desc.set_time_end(Time(extract_parameter(arg_list, iter, next),
524                                                                    desc.get_frame_rate()));
525                 }
526                 else if(*iter=="--time")
527                 {
528                         desc.set_time(Time(extract_parameter(arg_list, iter, next),
529                                                            desc.get_frame_rate()));
530                         VERBOSE_OUT(1)<<_("Rendering frame at ")<<desc.get_time_start().get_string(desc.get_frame_rate())<<endl;
531                 }
532                 else if(*iter=="-g")
533                 {
534                         synfig::warning("Gamma argument is currently ignored");
535                         //desc.set_gamma(Gamma(atoi(extract_parameter(arg_list, iter, next).c_str())));
536                 }
537                 else if (flag_requires_value(*iter))
538                         iter++;
539         }
540         if (w||h)
541         {
542                 if (!w)
543                         w = desc.get_w() * h / desc.get_h();
544                 else if (!h)
545                         h = desc.get_h() * w / desc.get_w();
546
547                 desc.set_wh(w,h);
548                 VERBOSE_OUT(1)<<strprintf(_("Resolution set to %dx%d"),w,h)<<endl;
549         }
550         if(span)
551                 desc.set_span(span);
552         return SYNFIGTOOL_OK;
553 }
554
555 int extract_quality(arg_list_t &arg_list,int &quality)
556 {
557         arg_list_t::iterator iter, next;
558         for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
559         {
560                 if(*iter=="-Q")
561                 {
562                         quality = atoi(extract_parameter(arg_list, iter, next).c_str());
563                         VERBOSE_OUT(1)<<strprintf(_("Quality set to %d"),quality)<<endl;
564                 }
565                 else if (flag_requires_value(*iter))
566                         iter++;
567         }
568
569         return SYNFIGTOOL_OK;
570 }
571
572 int extract_threads(arg_list_t &arg_list,int &threads)
573 {
574         arg_list_t::iterator iter, next;
575         for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
576         {
577                 if(*iter=="-T")
578                 {
579                         threads = atoi(extract_parameter(arg_list, iter, next).c_str());
580                         VERBOSE_OUT(1)<<strprintf(_("Threads set to %d"),threads)<<endl;
581                 }
582                 else if (flag_requires_value(*iter))
583                         iter++;
584         }
585
586         return SYNFIGTOOL_OK;
587 }
588
589 int extract_target(arg_list_t &arg_list,string &type)
590 {
591         arg_list_t::iterator iter, next;
592         type.clear();
593
594         for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
595         {
596                 if(*iter=="-t")
597                 {
598                         type = extract_parameter(arg_list, iter, next);
599                         VERBOSE_OUT(1)<<strprintf(_("Target set to %s"), type.c_str())<<endl;
600                 }
601                 else if (flag_requires_value(*iter))
602                         iter++;
603         }
604
605         return SYNFIGTOOL_OK;
606 }
607
608 int extract_target_params(arg_list_t& arg_list,
609                                                   TargetParam& params)
610 {
611         int ret;
612         ret = SYNFIGTOOL_OK;
613         // If -vc parameter is provided, -vb parameter is needed.
614         bool need_bitrate_parameter = false;
615         arg_list_t::iterator iter, next;
616
617         for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
618         {
619                 if(*iter=="-vc")
620                 {
621                         // Target video codec
622                         params.video_codec = extract_parameter(arg_list, iter, next);
623
624                         // video_codec string to lowercase
625                         transform (params.video_codec.begin(),
626                                            params.video_codec.end(),
627                                            params.video_codec.begin(),
628                                            ::tolower);
629
630                         int local_ret;
631                         local_ret = SYNFIGTOOL_UNKNOWNARGUMENT;
632
633                         // Check if the given video codec is allowed.
634                         for (int i = 0; local_ret != SYNFIGTOOL_OK &&
635                                                         allowed_video_codecs[i] != NULL; i++)
636                                 if (params.video_codec == allowed_video_codecs[i])
637                                         local_ret = SYNFIGTOOL_OK;
638
639                         ret = local_ret;
640
641                         if (ret == SYNFIGTOOL_OK)
642                         {
643                                 VERBOSE_OUT(1)<<strprintf(_("Target video codec set to %s"), params.video_codec.c_str())<<endl;
644                                 need_bitrate_parameter = true;
645                         }
646                 }
647                 else if(*iter=="-vb")
648                 {
649                         need_bitrate_parameter = false;
650                         // Target bitrate
651                         params.bitrate =
652                                 atoi(extract_parameter(arg_list, iter, next).c_str());
653                         VERBOSE_OUT(1)<<strprintf(_("Target bitrate set to %dk"),params.bitrate)<<endl;
654                 }
655                 else if (flag_requires_value(*iter))
656                         iter++;
657         }
658
659         if (need_bitrate_parameter)
660                 ret = SYNFIGTOOL_MISSINGARGUMENT;
661
662         return ret;
663 }
664
665 int extract_append(arg_list_t &arg_list,string &filename)
666 {
667         arg_list_t::iterator iter, next;
668         filename.clear();
669
670         for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
671         {
672                 if(*iter=="--append")
673                 {
674                         filename = extract_parameter(arg_list, iter, next);
675                 }
676                 else if (flag_requires_value(*iter))
677                         iter++;
678         }
679
680         return SYNFIGTOOL_OK;
681 }
682
683 int extract_outfile(arg_list_t &arg_list,string &outfile)
684 {
685         arg_list_t::iterator iter, next;
686         int ret=SYNFIGTOOL_FILENOTFOUND;
687         outfile.clear();
688
689         for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
690         {
691                 if(*iter=="-o")
692                 {
693                         outfile = extract_parameter(arg_list, iter, next);
694                         ret=SYNFIGTOOL_OK;
695                 }
696                 else if (flag_requires_value(*iter))
697                         iter++;
698         }
699
700         return ret;
701 }
702
703 int extract_canvasid(arg_list_t &arg_list,string &canvasid)
704 {
705         arg_list_t::iterator iter, next;
706         //canvasid.clear();
707
708         for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
709         {
710                 if(*iter=="-c")
711                 {
712                         canvasid = extract_parameter(arg_list, iter, next);
713                 }
714                 else if (flag_requires_value(*iter))
715                         iter++;
716         }
717
718         return SYNFIGTOOL_OK;
719 }
720
721 int extract_list_canvases(arg_list_t &arg_list,bool &list_canvases)
722 {
723         arg_list_t::iterator iter, next;
724
725         for(next=arg_list.begin(), iter = next++; iter!=arg_list.end();
726                 iter = next++)
727                 if(*iter=="--list-canvases")
728                 {
729                         list_canvases = true;
730                         arg_list.erase(iter);
731                 }
732
733         return SYNFIGTOOL_OK;
734 }
735
736 void extract_canvas_info(arg_list_t &arg_list, Job &job)
737 {
738         arg_list_t::iterator iter, next;
739
740         for(next=arg_list.begin(),iter=next++;iter!=arg_list.end();iter=next++)
741                 if(*iter=="--canvas-info")
742                 {
743                         job.canvas_info = true;
744                         String values(extract_parameter(arg_list, iter, next)), value;
745
746                         std::string::size_type pos;
747                         while (!values.empty())
748                         {
749                                 pos = values.find_first_of(',');
750                                 if (pos == std::string::npos)
751                                 {
752                                         value = values;
753                                         values = "";
754                                 }
755                                 else
756                                 {
757                                         value = values.substr(0, pos);
758                                         values = values.substr(pos+1);
759                                 }
760                                 if (value == "all")
761                                 {
762                                         job.canvas_info_all = true;
763                                         return;
764                                 }
765
766                                 if (value == "time_start")                      job.canvas_info_time_start              = true;
767                                 else if (value == "time_end")           job.canvas_info_time_end                = true;
768                                 else if (value == "frame_rate")         job.canvas_info_frame_rate              = true;
769                                 else if (value == "frame_start")        job.canvas_info_frame_start             = true;
770                                 else if (value == "frame_end")          job.canvas_info_frame_end               = true;
771                                 else if (value == "w")                          job.canvas_info_w                               = true;
772                                 else if (value == "h")                          job.canvas_info_h                               = true;
773                                 else if (value == "image_aspect")       job.canvas_info_image_aspect    = true;
774                                 else if (value == "pw")                         job.canvas_info_pw                              = true;
775                                 else if (value == "ph")                         job.canvas_info_ph                              = true;
776                                 else if (value == "pixel_aspect")       job.canvas_info_pixel_aspect    = true;
777                                 else if (value == "tl")                         job.canvas_info_tl                              = true;
778                                 else if (value == "br")                         job.canvas_info_br                              = true;
779                                 else if (value == "physical_w")         job.canvas_info_physical_w              = true;
780                                 else if (value == "physical_h")         job.canvas_info_physical_h              = true;
781                                 else if (value == "x_res")                      job.canvas_info_x_res                   = true;
782                                 else if (value == "y_res")                      job.canvas_info_y_res                   = true;
783                                 else if (value == "span")                       job.canvas_info_span                    = true;
784                                 else if (value == "interlaced")         job.canvas_info_interlaced              = true;
785                                 else if (value == "antialias")          job.canvas_info_antialias               = true;
786                                 else if (value == "clamp")                      job.canvas_info_clamp                   = true;
787                                 else if (value == "flags")                      job.canvas_info_flags                   = true;
788                                 else if (value == "focus")                      job.canvas_info_focus                   = true;
789                                 else if (value == "bg_color")           job.canvas_info_bg_color                = true;
790                                 else if (value == "metadata")           job.canvas_info_metadata                = true;
791                                 else
792                                 {
793                                         cerr<<_("Unrecognised canvas variable: ") << "'" << value << "'" << endl;
794                                         cerr<<_("Recognized variables are:") << endl <<
795                                                 "  all, time_start, time_end, frame_rate, frame_start, frame_end, w, h," << endl <<
796                                                 "  image_aspect, pw, ph, pixel_aspect, tl, br, physical_w, physical_h," << endl <<
797                                                 "  x_res, y_res, span, interlaced, antialias, clamp, flags," << endl <<
798                                                 "  focus, bg_color, metadata" << endl;
799                                 }
800
801                                 if (pos == std::string::npos)
802                                         break;
803                         };
804                 }
805 }
806
807 void list_child_canvases(string prefix, Canvas::Handle canvas)
808 {
809         Canvas::Children children(canvas->children());
810         for (Canvas::Children::iterator iter = children.begin(); iter != children.end(); iter++)
811         {
812                 cout << prefix << ":" << (*iter)->get_id() << endl;
813                 list_child_canvases(prefix + ":" + (*iter)->get_id(), *iter);
814         }
815 }
816
817 void list_canvas_info(Job job)
818 {
819         Canvas::Handle canvas(job.canvas);
820         const RendDesc &rend_desc(canvas->rend_desc());
821
822         if (job.canvas_info_all || job.canvas_info_time_start)
823         {
824                 cout << endl << "# " << _("Start Time") << endl;
825                 cout << "time_start"    << "=" << rend_desc.get_time_start().get_string().c_str() << endl;
826         }
827
828         if (job.canvas_info_all || job.canvas_info_time_end)
829         {
830                 cout << endl << "# " << _("End Time") << endl;
831                 cout << "time_end"              << "=" << rend_desc.get_time_end().get_string().c_str() << endl;
832         }
833
834         if (job.canvas_info_all || job.canvas_info_frame_rate)
835         {
836                 cout << endl << "# " << _("Frame Rate") << endl;
837                 cout << "frame_rate"    << "=" << rend_desc.get_frame_rate() << endl;
838         }
839
840         if (job.canvas_info_all || job.canvas_info_frame_start)
841         {
842                 cout << endl << "# " << _("Start Frame") << endl;
843                 cout << "frame_start"   << "=" << rend_desc.get_frame_start() << endl;
844         }
845
846         if (job.canvas_info_all || job.canvas_info_frame_end)
847         {
848                 cout << endl << "# " << _("End Frame") << endl;
849                 cout << "frame_end"             << "=" << rend_desc.get_frame_end() << endl;
850         }
851
852         if (job.canvas_info_all)
853                 cout << endl;
854
855         if (job.canvas_info_all || job.canvas_info_w)
856         {
857                 cout << endl << "# " << _("Width") << endl;
858                 cout << "w"                             << "=" << rend_desc.get_w() << endl;
859         }
860
861         if (job.canvas_info_all || job.canvas_info_h)
862         {
863                 cout << endl << "# " << _("Height") << endl;
864                 cout << "h"                             << "=" << rend_desc.get_h() << endl;
865         }
866
867         if (job.canvas_info_all || job.canvas_info_image_aspect)
868         {
869                 cout << endl << "# " << _("Image Aspect Ratio") << endl;
870                 cout << "image_aspect"  << "=" << rend_desc.get_image_aspect() << endl;
871         }
872
873         if (job.canvas_info_all)
874                 cout << endl;
875
876         if (job.canvas_info_all || job.canvas_info_pw)
877         {
878                 cout << endl << "# " << _("Pixel Width") << endl;
879                 cout << "pw"                    << "=" << rend_desc.get_pw() << endl;
880         }
881
882         if (job.canvas_info_all || job.canvas_info_ph)
883         {
884                 cout << endl << "# " << _("Pixel Height") << endl;
885                 cout << "ph"                    << "=" << rend_desc.get_ph() << endl;
886         }
887
888         if (job.canvas_info_all || job.canvas_info_pixel_aspect)
889         {
890                 cout << endl << "# " << _("Pixel Aspect Ratio") << endl;
891                 cout << "pixel_aspect"  << "=" << rend_desc.get_pixel_aspect() << endl;
892         }
893
894         if (job.canvas_info_all)
895                 cout << endl;
896
897         if (job.canvas_info_all || job.canvas_info_tl)
898         {
899                 cout << endl << "# " << _("Top Left") << endl;
900                 cout << "tl"                    << "=" << rend_desc.get_tl()[0]
901                          << " " << rend_desc.get_tl()[1] << endl;
902         }
903
904         if (job.canvas_info_all || job.canvas_info_br)
905         {
906                 cout << endl << "# " << _("Bottom Right") << endl;
907                 cout << "br"                    << "=" << rend_desc.get_br()[0]
908                          << " " << rend_desc.get_br()[1] << endl;
909         }
910
911         if (job.canvas_info_all || job.canvas_info_physical_w)
912         {
913                 cout << endl << "# " << _("Physical Width") << endl;
914                 cout << "physical_w"    << "=" << rend_desc.get_physical_w() << endl;
915         }
916
917         if (job.canvas_info_all || job.canvas_info_physical_h)
918         {
919                 cout << endl << "# " << _("Physical Height") << endl;
920                 cout << "physical_h"    << "=" << rend_desc.get_physical_h() << endl;
921         }
922
923         if (job.canvas_info_all || job.canvas_info_x_res)
924         {
925                 cout << endl << "# " << _("X Resolution") << endl;
926                 cout << "x_res"                 << "=" << rend_desc.get_x_res() << endl;
927         }
928
929         if (job.canvas_info_all || job.canvas_info_y_res)
930         {
931                 cout << endl << "# " << _("Y Resolution") << endl;
932                 cout << "y_res"                 << "=" << rend_desc.get_y_res() << endl;
933         }
934
935         if (job.canvas_info_all || job.canvas_info_span)
936         {
937                 cout << endl << "# " << _("Diagonal Image Span") << endl;
938                 cout << "span"                  << "=" << rend_desc.get_span() << endl;
939         }
940
941         if (job.canvas_info_all)
942                 cout << endl;
943
944         if (job.canvas_info_all || job.canvas_info_interlaced)
945         {
946                 cout << endl << "# " << _("Interlaced") << endl;
947                 cout << "interlaced"    << "=" << rend_desc.get_interlaced() << endl;
948         }
949
950         if (job.canvas_info_all || job.canvas_info_antialias)
951         {
952                 cout << endl << "# " << _("Antialias") << endl;
953                 cout << "antialias"             << "=" << rend_desc.get_antialias() << endl;
954         }
955
956         if (job.canvas_info_all || job.canvas_info_clamp)
957         {
958                 cout << endl << "# " << _("Clamp") << endl;
959                 cout << "clamp"                 << "=" << rend_desc.get_clamp() << endl;
960         }
961
962         if (job.canvas_info_all || job.canvas_info_flags)
963         {
964                 cout << endl << "# " << _("Flags") << endl;
965                 cout << "flags"                 << "=" << rend_desc.get_flags() << endl;
966         }
967
968         if (job.canvas_info_all || job.canvas_info_focus)
969         {
970                 cout << endl << "# " << _("Focus") << endl;
971                 cout << "focus"                 << "=" << rend_desc.get_focus()[0]
972                          << " " << rend_desc.get_focus()[1] << endl;
973         }
974
975         if (job.canvas_info_all || job.canvas_info_bg_color)
976         {
977                 cout << endl << "# " << _("Background Color") << endl;
978                 cout << "bg_color"              << "=" << rend_desc.get_bg_color().get_string().c_str() << endl;
979         }
980
981         if (job.canvas_info_all)
982                 cout << endl;
983
984         if (job.canvas_info_all || job.canvas_info_metadata)
985         {
986                 std::list<String> keys(canvas->get_meta_data_keys());
987                 cout << endl << "# " << _("Metadata") << endl;
988                 for (std::list<String>::iterator iter = keys.begin(); iter != keys.end(); iter++)
989                         cout << *iter << "=" << canvas->get_meta_data(*iter) << endl;
990         }
991 }
992
993 /* === M E T H O D S ======================================================= */
994
995 /* === E N T R Y P O I N T ================================================= */
996
997 int main(int argc, char *argv[])
998 {
999         int i;
1000         arg_list_t arg_list;
1001         job_list_t job_list;
1002
1003         setlocale(LC_ALL, "");
1004
1005 #ifdef ENABLE_NLS
1006         bindtextdomain("synfig", LOCALEDIR);
1007         bind_textdomain_codeset("synfig", "UTF-8");
1008         textdomain("synfig");
1009 #endif
1010
1011         progname=argv[0];
1012         Progress p(argv[0]);
1013
1014         if(!SYNFIG_CHECK_VERSION())
1015         {
1016                 cerr<<_("FATAL: Synfig Version Mismatch")<<endl;
1017                 return SYNFIGTOOL_BADVERSION;
1018         }
1019
1020         if(argc==1)
1021         {
1022                 display_help(false);
1023                 return SYNFIGTOOL_BLANK;
1024         }
1025
1026         for(i=1;i<argc;i++)
1027                 arg_list.push_back(argv[i]);
1028
1029         if((i=process_global_flags(arg_list)))
1030                 return i;
1031
1032         VERBOSE_OUT(1)<<_("verbosity set to ")<<verbosity<<endl;
1033         synfig::Main synfig_main(dirname(progname),&p);
1034
1035         {
1036                 arg_list_t defaults, imageargs;
1037                 int ret;
1038
1039                 // Grab the defaults before the first file
1040                 if ((ret = extract_arg_cluster(arg_list,defaults)) != SYNFIGTOOL_OK)
1041                   return ret;
1042
1043                 while(arg_list.size())
1044                 {
1045                         string target_name;
1046                         job_list.push_front(Job());
1047                         int threads=0;
1048
1049                         imageargs=defaults;
1050                         job_list.front().filename=arg_list.front();
1051                         arg_list.pop_front();
1052
1053                         if ((ret = extract_arg_cluster(arg_list,imageargs)) != SYNFIGTOOL_OK)
1054                           return ret;
1055
1056                         // Open the composition
1057                         String errors, warnings;
1058                         try
1059                         {
1060                                 job_list.front().root=open_canvas(job_list.front().filename, errors, warnings);
1061                         }
1062                         catch(runtime_error x)
1063                         {
1064                                 job_list.front().root = 0;
1065                         }
1066
1067                         if(!job_list.front().root)
1068                         {
1069                                 cerr<<_("Unable to load '")<<job_list.front().filename<<"'."<<endl;
1070                                 cerr<<_("Throwing out job...")<<endl;
1071                                 job_list.pop_front();
1072                                 continue;
1073                         }
1074
1075                         bool list_canvases = false;
1076                         extract_list_canvases(imageargs, list_canvases);
1077                         job_list.front().list_canvases = list_canvases;
1078
1079                         extract_canvas_info(imageargs, job_list.front());
1080
1081                         job_list.front().root->set_time(0);
1082
1083                         string canvasid;
1084                         extract_canvasid(imageargs,canvasid);
1085                         if(!canvasid.empty())
1086                         {
1087                                 try
1088                                 {
1089                                         String warnings;
1090                                         job_list.front().canvas=job_list.front().root->find_canvas(canvasid, warnings);
1091                                 }
1092                                 catch(Exception::IDNotFound)
1093                                 {
1094                                         cerr<<_("Unable to find canvas with ID \"")<<canvasid<<_("\" in ")<<job_list.front().filename<<"."<<endl;
1095                                         cerr<<_("Throwing out job...")<<endl;
1096                                         job_list.pop_front();
1097                                         continue;
1098
1099                                 }
1100                                 catch(Exception::BadLinkName)
1101                                 {
1102                                         cerr<<_("Invalid canvas name \"")<<canvasid<<_("\" in ")<<job_list.front().filename<<"."<<endl;
1103                                         cerr<<_("Throwing out job...")<<endl;
1104                                         job_list.pop_front();
1105                                         continue;
1106                                 }
1107                         }
1108                         else
1109                                 job_list.front().canvas=job_list.front().root;
1110
1111                         extract_RendDesc(imageargs,job_list.front().canvas->rend_desc());
1112                         extract_target(imageargs,target_name);
1113                         extract_threads(imageargs,threads);
1114                         job_list.front().quality=DEFAULT_QUALITY;
1115                         extract_quality(imageargs,job_list.front().quality);
1116                         VERBOSE_OUT(2)<<_("Quality set to ")<<job_list.front().quality<<endl;
1117                         job_list.front().desc=job_list.front().canvas->rend_desc();
1118                         extract_outfile(imageargs,job_list.front().outfilename);
1119
1120                         // Extract composite
1121                         do{
1122                                 string composite_file;
1123                                 extract_append(imageargs,composite_file);
1124                                 if(!composite_file.empty())
1125                                 {
1126                                         String errors, warnings;
1127                                         Canvas::Handle composite(open_canvas(composite_file, errors, warnings));
1128                                         if(!composite)
1129                                         {
1130                                                 cerr<<_("Unable to append '")<<composite_file<<"'."<<endl;
1131                                                 break;
1132                                         }
1133                                         Canvas::reverse_iterator iter;
1134                                         for(iter=composite->rbegin();iter!=composite->rend();++iter)
1135                                         {
1136                                                 Layer::Handle layer(*iter);
1137                                                 if(layer->active())
1138                                                         job_list.front().canvas->push_front(layer->clone());
1139                                         }
1140                                         VERBOSE_OUT(2)<<_("Appended contents of ")<<composite_file<<endl;
1141                                 }
1142                         } while(false);
1143
1144                         VERBOSE_OUT(4)<<_("Attempting to determine target/outfile...")<<endl;
1145
1146                         // If the target type is not yet defined,
1147                         // try to figure it out from the outfile.
1148                         if(target_name.empty() && !job_list.front().outfilename.empty())
1149                         {
1150                                 VERBOSE_OUT(3)<<_("Target name undefined, attempting to figure it out")<<endl;
1151                                 string ext = filename_extension(job_list.front().outfilename);
1152                                 if (ext.length()) ext = ext.substr(1);
1153                                 if(Target::ext_book().count(ext))
1154                                 {
1155                                         target_name=Target::ext_book()[ext];
1156                                         info("target name not specified - using %s", target_name.c_str());
1157                                 }
1158                                 else
1159                                 {
1160                                         string lower_ext(ext);
1161
1162                                         for(unsigned int i=0;i<ext.length();i++)
1163                                                 lower_ext[i] = tolower(ext[i]);
1164
1165                                         if(Target::ext_book().count(lower_ext))
1166                                         {
1167                                                 target_name=Target::ext_book()[lower_ext];
1168                                                 info("target name not specified - using %s", target_name.c_str());
1169                                         }
1170                                         else
1171                                                 target_name=ext;
1172                                 }
1173                         }
1174
1175                         TargetParam target_parameters;
1176                         // Extract the extra parameters for the targets that
1177                         // need them.
1178                         if (target_name == "ffmpeg")
1179                         {
1180                                 int status;
1181                                 status = extract_target_params(imageargs, target_parameters);
1182                                 if (status == SYNFIGTOOL_UNKNOWNARGUMENT)
1183                                 {
1184                                         cerr << strprintf(_("Unknown target video codec: %s."),
1185                                                                          target_parameters.video_codec.c_str())
1186                                                  << endl;
1187                                         cerr << _("Available target video codecs are:")
1188                                                  << endl;
1189                                         display_target_video_codecs_help();
1190
1191                                         return SYNFIGTOOL_UNKNOWNARGUMENT;
1192                                 }
1193                                 else if (status == SYNFIGTOOL_MISSINGARGUMENT)
1194                                 {
1195                                         cerr << _("Missing argument: \"-vb\".") << endl;
1196
1197                                         return SYNFIGTOOL_MISSINGARGUMENT;
1198                                 }
1199                         }
1200
1201                         // If the target type is STILL not yet defined, then
1202                         // set it to a some sort of default
1203                         if(target_name.empty())
1204                         {
1205                                 VERBOSE_OUT(2)<<_("Defaulting to PNG target...")<<endl;
1206                                 target_name="png";
1207                         }
1208
1209                         // If no output filename was provided, then
1210                         // create a output filename based on the
1211                         // given input filename. (ie: change the extension)
1212                         if(job_list.front().outfilename.empty())
1213                         {
1214                                 job_list.front().outfilename = filename_sans_extension(job_list.front().filename) + '.';
1215                                 if(Target::book().count(target_name))
1216                                         job_list.front().outfilename+=Target::book()[target_name].filename;
1217                                 else
1218                                         job_list.front().outfilename+=target_name;
1219                         }
1220
1221                         VERBOSE_OUT(4)<<"target_name="<<target_name<<endl;
1222                         VERBOSE_OUT(4)<<"outfile_name="<<job_list.front().outfilename<<endl;
1223
1224                         VERBOSE_OUT(4)<<_("Creating the target...")<<endl;
1225                         job_list.front().target =
1226                                 synfig::Target::create(target_name,
1227                                                                            job_list.front().outfilename,
1228                                                                            target_parameters);
1229
1230                         if(target_name=="sif")
1231                                 job_list.front().sifout=true;
1232                         else
1233                         {
1234                                 if(!job_list.front().target)
1235                                 {
1236                                         cerr<<_("Unknown target for ")<<job_list.front().filename<<": "<<target_name<<endl;
1237                                         cerr<<_("Throwing out job...")<<endl;
1238                                         job_list.pop_front();
1239                                         continue;
1240                                 }
1241                                 job_list.front().sifout=false;
1242                         }
1243
1244                         // Set the Canvas on the Target
1245                         if(job_list.front().target)
1246                         {
1247                                 VERBOSE_OUT(4)<<_("Setting the canvas on the target...")<<endl;
1248                                 job_list.front().target->set_canvas(job_list.front().canvas);
1249                                 VERBOSE_OUT(4)<<_("Setting the quality of the target...")<<endl;
1250                                 job_list.front().target->set_quality(job_list.front().quality);
1251                         }
1252
1253                         // Set the threads for the target
1254                         if(job_list.front().target && Target_Scanline::Handle::cast_dynamic(job_list.front().target))
1255                                 Target_Scanline::Handle::cast_dynamic(job_list.front().target)->set_threads(threads);
1256
1257                         if(imageargs.size())
1258                         {
1259                                 cerr<<_("Unidentified arguments for ")<<job_list.front().filename<<": ";
1260                                 for(;imageargs.size();imageargs.pop_front())
1261                                         cerr<<' '<<imageargs.front();
1262                                 cerr<<endl;
1263                                 cerr<<_("Throwing out job...")<<endl;
1264                                 job_list.pop_front();
1265                                 continue;
1266                         }
1267                 }
1268         }
1269
1270         if(arg_list.size())
1271         {
1272                 cerr<<_("Unidentified arguments:");
1273                 for(;arg_list.size();arg_list.pop_front())
1274                         cerr<<' '<<arg_list.front();
1275                 cerr<<endl;
1276                 return SYNFIGTOOL_UNKNOWNARGUMENT;
1277         }
1278
1279         if(!job_list.size())
1280         {
1281                 cerr<<_("Nothing to do!")<<endl;
1282                 return SYNFIGTOOL_BORED;
1283         }
1284
1285         for(;job_list.size();job_list.pop_front())
1286         {
1287                 VERBOSE_OUT(3)<<job_list.front().filename<<" -- "<<endl<<'\t'<<
1288                 strprintf("w:%d, h:%d, a:%d, pxaspect:%f, imaspect:%f, span:%f",
1289                         job_list.front().desc.get_w(),
1290                         job_list.front().desc.get_h(),
1291                         job_list.front().desc.get_antialias(),
1292                         job_list.front().desc.get_pixel_aspect(),
1293                         job_list.front().desc.get_image_aspect(),
1294                         job_list.front().desc.get_span()
1295                         )<<endl<<'\t'<<
1296                 strprintf("tl:[%f,%f], br:[%f,%f], focus:[%f,%f]",
1297                         job_list.front().desc.get_tl()[0],job_list.front().desc.get_tl()[1],
1298                         job_list.front().desc.get_br()[0],job_list.front().desc.get_br()[1],
1299                         job_list.front().desc.get_focus()[0],job_list.front().desc.get_focus()[1]
1300                         )<<endl;
1301
1302                 RenderProgress p;
1303                 p.task(job_list.front().filename+" ==> "+job_list.front().outfilename);
1304                 if(job_list.front().sifout)
1305                 {
1306                         if(!save_canvas(job_list.front().outfilename,job_list.front().canvas))
1307                         {
1308                                 cerr<<"Render Failure."<<endl;
1309                                 return SYNFIGTOOL_RENDERFAILURE;
1310                         }
1311                 }
1312                 else if (job_list.front().list_canvases)
1313                 {
1314                         list_child_canvases(job_list.front().filename + "#", job_list.front().canvas);
1315                         cerr << endl;
1316                 }
1317                 else if (job_list.front().canvas_info)
1318                 {
1319                         list_canvas_info(job_list.front());
1320                         cerr << endl;
1321                 }
1322                 else
1323                 {
1324                         VERBOSE_OUT(1)<<_("Rendering...")<<endl;
1325                         etl::clock timer;
1326                         timer.reset();
1327                         // Call the render member of the target
1328                         if(!job_list.front().target->render(&p))
1329                         {
1330                                 cerr<<"Render Failure."<<endl;
1331                                 return SYNFIGTOOL_RENDERFAILURE;
1332                         }
1333                         if(print_benchmarks)
1334                                 cout<<job_list.front().filename+": Rendered in "<<timer()<<" seconds."<<endl;
1335                 }
1336         }
1337
1338         job_list.clear();
1339
1340         VERBOSE_OUT(1)<<_("Done.")<<endl;
1341
1342         return SYNFIGTOOL_OK;
1343 }