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