1 /* === S Y N F I G ========================================================= */
3 ** \brief Target Class Implementation
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
10 ** Copyright (c) 2010 Diego Barrios Romero
12 ** This package is free software; you can redistribute it and/or
13 ** modify it under the terms of the GNU General Public License as
14 ** published by the Free Software Foundation; either version 2 of
15 ** the License, or (at your option) any later version.
17 ** This package is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ** General Public License for more details.
23 /* ========================================================================= */
25 /* === S T A R T =========================================================== */
27 #ifndef __SYNFIG_TARGET_H
28 #define __SYNFIG_TARGET_H
30 /* === H E A D E R S ======================================================= */
32 #include <sigc++/signal.h>
33 #include "string_decl.h"
40 #include "targetparam.h"
42 /* === M A C R O S ========================================================= */
44 //! Defines various variables and the create method, common for all Targets.
45 //! To be used in the private part of the target class definition.
46 #define SYNFIG_TARGET_MODULE_EXT \
47 public: static const char name__[], version__[], ext__[], cvs_id__[];\
48 static Target* create (const char *filename, synfig::TargetParam p);
50 //! Sets the name of the target
51 #define SYNFIG_TARGET_SET_NAME(class,x) const char class::name__[]=x
53 //! Sets the primary file extension of the target
54 #define SYNFIG_TARGET_SET_EXT(class,x) const char class::ext__[]=x
56 //! Sets the version of the target
57 #define SYNFIG_TARGET_SET_VERSION(class,x) const char class::version__[]=x
59 //! Sets the CVS ID of the target
60 #define SYNFIG_TARGET_SET_CVS_ID(class,x) const char class::cvs_id__[]=x
62 //! Defines de implementation of the create method for the target
63 //! \param filename The file name to be created by the target.
64 //! |param p The parameters passed to the target (bit rate and vcodec)
65 #define SYNFIG_TARGET_INIT(class) \
66 synfig::Target* class::create (const char *filename, \
67 synfig::TargetParam p) \
68 { return new class(filename, p); }
70 /* === T Y P E D E F S ===================================================== */
72 /* === C L A S S E S & S T R U C T S ======================================= */
79 class ProgressCallback;
83 ** \brief Used to produce rendered animations of the documents
85 * It is the base class for all the target renderers. It defines the has a static Book
86 * pointer class that is a map for the targets factory creators and the strings
87 * of the extension that the renderer can understand. It allows to create the a
88 * pointer to a particular renderer just by using the extension of the name of file
89 * to import. Also it creates a virtual member render() that must be declared in
90 * the inherited classes.
92 class Target : public etl::shared_object
95 typedef etl::handle<Target> Handle;
96 typedef etl::loose_handle<Target> LooseHandle;
97 typedef etl::handle<const Target> ConstHandle;
100 -- ** -- S I G N A L S -------------------------------------------------------
105 sigc::signal<void> signal_progress_;
108 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
113 sigc::signal<void>& signal_progress() { return signal_progress_; }
116 -- ** -- C O N S T R U C T O R S ---------------------------------------------
120 //! Type that represents a pointer to a Target's constructor.
121 /*! As a pointer to the constructor, it represents a "factory" of targets.
122 ** Receives the output filename (including path) and the parameters of the target.
124 typedef Target* (*Factory)(const char *filename, TargetParam p);
129 String filename; ///< Output filename including path
130 TargetParam target_param; ///< Target module parameters
133 //! Book of types of targets indexed by the name of the Target.
134 typedef std::map<String,BookEntry> Book;
136 //! Book of types of targets indexed by the file extension
137 typedef std::map<String,String> ExtBook;
139 //! Target Book, indexed by the target's name
142 //! Map of target names indexed by associated file extension
143 static ExtBook* ext_book_;
146 static ExtBook& ext_book();
148 //! Initializes the Target module by creating a book of targets names
150 static bool subsys_init();
151 //! Stops the Target module by deleting the book and the extension book
152 static bool subsys_stop();
154 //! Adjusted Render description set by set_rend_desc()
157 //! Canvas being rendered in this target module
158 //! \see set_canvas()
159 etl::handle<Canvas> canvas;
161 //! Render quality used for the render process of the target.
163 //! Gamma value used for the render process of the target
166 //! Used by non alpha supported targets to decide if the background
167 //! must be filled or not
170 //! When set to true, the target doesn't sync to canvas time.
171 bool avoid_time_sync_;
174 //! Default constructor
178 virtual ~Target() { }
179 //! Gets the target quality
180 int get_quality()const { return quality_; }
181 //! Sets the target quality
182 void set_quality(int q) { quality_=q; }
183 //! Sets the target avoid time synchronization
184 void set_avoid_time_sync(bool x=true) { avoid_time_sync_=x; }
185 //! Gets the target avoid time synchronization
186 bool get_avoid_time_sync()const { return avoid_time_sync_; }
187 //! Gets the target remove alpha
188 bool get_remove_alpha()const { return remove_alpha; }
189 //! Sets the target remove alpha
190 void set_remove_alpha(bool x=true) { remove_alpha=x; }
191 //! Gets the target gamma
192 Gamma &gamma() { return gamma_; }
193 //! Sets the target gamma
194 const Gamma &gamma()const { return gamma_; }
195 //! Sets the target canvas. Must be defined by derived targets
196 virtual void set_canvas(etl::handle<Canvas> c);
197 //! Gets the target canvas.
198 const etl::handle<Canvas> &get_canvas()const { return canvas; }
199 //! Gets the target particular render description
200 RendDesc &rend_desc() { return desc; }
201 //! Gets the target particular render description
202 const RendDesc &rend_desc()const { return desc; }
203 //! Sets the RendDesc for the Target to \a desc.
204 /*! If there are any parts of \a desc that the render target
205 ** is not capable of doing, the render target will adjust
206 ** \a desc to fit its needs.
208 virtual bool set_rend_desc(RendDesc *d) { desc=*d; return true; }
209 //! Renders the canvas to the target
210 virtual bool render(ProgressCallback *cb=NULL)=0;
211 //! Initialization tasks of the derived target.
212 //! @returns true if the initialization has no errors
213 virtual bool init() { return true; }
215 //! Creates a new Target described by \a type, outputting to a file described by \a filename.
216 static Handle create(const String &type, const String &filename,
217 synfig::TargetParam params);
218 }; // END of class Target
220 }; // END of namespace synfig
222 /* === E N D =============================================================== */