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