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