more updates
[synfig.git] / synfig-core / trunk / src / synfig / target.cpp
1 /* === S I N F 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 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #define SINFG_NO_ANGLE
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
36 using namespace sinfg;
37 using namespace etl;
38 using namespace std;
39
40 sinfg::Target::Book* sinfg::Target::book_;
41 sinfg::Target::ExtBook* sinfg::Target::ext_book_;
42
43 static sinfg::Gamma* default_gamma_;
44
45 /* === P R O C E D U R E S ================================================= */
46
47 bool
48 Target::subsys_init()
49 {
50         book_=new sinfg::Target::Book();
51         ext_book_=new sinfg::Target::ExtBook();
52         
53         default_gamma_=new sinfg::Gamma(1.0/2.2);
54         //default_gamma_->set_black_level(0.05); // Default to 5% black level.
55         
56         book()["null"]=std::pair<sinfg::Target::Factory,String>(Target_Null::create,"null");
57         ext_book()["null"]="null";
58         book()["null-tile"]=std::pair<sinfg::Target::Factory,String>(Target_Null_Tile::create,"null-tile");
59         ext_book()["null-tile"]="null-tile";
60
61         return true;
62 }
63
64 bool
65 Target::subsys_stop()
66 {
67         delete book_;
68         delete ext_book_;
69         delete default_gamma_;
70         return true;
71 }
72
73 Target::Book&
74 Target::book()
75 {
76         return *book_;
77 }
78
79 Target::ExtBook&
80 Target::ext_book()
81 {
82         return *ext_book_;
83 }
84
85
86 /* === M E T H O D S ======================================================= */
87
88 Target::Target():
89         quality_(4),
90         gamma_(*default_gamma_),
91         remove_alpha(false)
92 {
93 }
94
95 void
96 sinfg::Target::set_canvas(Canvas::Handle c)
97 {
98         canvas=c;
99         RendDesc desc=canvas->rend_desc();
100         set_rend_desc(&desc);
101 }
102
103
104 Target::Handle
105 Target::create(const String &name, const String &filename)
106 {
107         if(!book().count(name))
108                 return handle<Target>();
109                 
110         return Target::Handle(book()[name].first(filename.c_str()));
111 }