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