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