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