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