Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_04 / 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: target.cpp,v 1.1.1.1 2005/01/04 01:23:15 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #define SYNFIG_NO_ANGLE
26
27 #ifdef HAVE_CONFIG_H
28 # include <config.h>
29 #endif
30
31 #include "target.h"
32 #include "string.h"
33 #include "canvas.h"
34 #include "target_null.h"
35 #include "target_null_tile.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         book()["null"]=std::pair<synfig::Target::Factory,String>(Target_Null::create,"null");
58         ext_book()["null"]="null";
59         book()["null-tile"]=std::pair<synfig::Target::Factory,String>(Target_Null_Tile::create,"null-tile");
60         ext_book()["null-tile"]="null-tile";
61
62         return true;
63 }
64
65 bool
66 Target::subsys_stop()
67 {
68         delete book_;
69         delete ext_book_;
70         delete default_gamma_;
71         return true;
72 }
73
74 Target::Book&
75 Target::book()
76 {
77         return *book_;
78 }
79
80 Target::ExtBook&
81 Target::ext_book()
82 {
83         return *ext_book_;
84 }
85
86
87 /* === M E T H O D S ======================================================= */
88
89 Target::Target():
90         quality_(4),
91         gamma_(*default_gamma_),
92         remove_alpha(false)
93 {
94 }
95
96 void
97 synfig::Target::set_canvas(Canvas::Handle c)
98 {
99         canvas=c;
100         RendDesc desc=canvas->rend_desc();
101         set_rend_desc(&desc);
102 }
103
104
105 Target::Handle
106 Target::create(const String &name, const String &filename)
107 {
108         if(!book().count(name))
109                 return handle<Target>();
110                 
111         return Target::Handle(book()[name].first(filename.c_str()));
112 }