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