b6aa1c435b9f1f84c1422d70aa26e3f6929c5462
[synfig.git] / synfig-core / src / synfig / target.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file target.cpp
3 **      \brief Target Class Implementation
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **  Copyright (c) 2010 Diego Barrios Romero
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 #define SYNFIG_NO_ANGLE
27
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31
32 #include "target.h"
33 #include "string.h"
34 #include "canvas.h"
35 #include "target_null.h"
36 #include "target_null_tile.h"
37 #include "targetparam.h"
38
39 using namespace synfig;
40 using namespace etl;
41 using namespace std;
42
43 synfig::Target::Book* synfig::Target::book_;
44 synfig::Target::ExtBook* synfig::Target::ext_book_;
45
46 static synfig::Gamma* default_gamma_;
47
48 /* === P R O C E D U R E S ================================================= */
49
50 bool
51 Target::subsys_init()
52 {
53         book_=new synfig::Target::Book();
54         ext_book_=new synfig::Target::ExtBook();
55
56         default_gamma_=new synfig::Gamma(1.0/2.2);
57         //default_gamma_->set_black_level(0.05); // Default to 5% black level.
58
59         // At least one target must be available.
60         book()["null"].factory =
61                 reinterpret_cast<synfig::Target::Factory>(&Target_Null::create);
62         book()["null"].filename = "null";
63         book()["null"].target_param = TargetParam();
64         ext_book()["null"]="null";
65
66         book()["null-tile"].factory =
67                 reinterpret_cast<synfig::Target::Factory>(&Target_Null_Tile::create);
68         book()["null-tile"].filename = "null-tile";
69         book()["null-tile"].target_param = TargetParam();
70         ext_book()["null-tile"]="null-tile";
71
72         return true;
73 }
74
75 bool
76 Target::subsys_stop()
77 {
78         delete book_;
79         delete ext_book_;
80         delete default_gamma_;
81         return true;
82 }
83
84 Target::Book&
85 Target::book()
86 {
87         return *book_;
88 }
89
90 Target::ExtBook&
91 Target::ext_book()
92 {
93         return *ext_book_;
94 }
95
96
97 /* === M E T H O D S ======================================================= */
98
99 Target::Target():
100         quality_(4),
101         gamma_(*default_gamma_),
102         remove_alpha(false),
103         avoid_time_sync_(false)
104 {
105 }
106
107 void
108 synfig::Target::set_canvas(etl::handle<Canvas> c)
109 {
110         canvas=c;
111         RendDesc desc=canvas->rend_desc();
112         set_rend_desc(&desc);
113 }
114
115
116 Target::Handle
117 Target::create(const String &name, const String &filename,
118                            synfig::TargetParam params)
119 {
120         if(!book().count(name))
121                 return handle<Target>();
122
123         return Target::Handle(book()[name].factory(filename.c_str(), params));
124 }