Blame synfig-core/src/synfig/target.h

Carlos Lopez a09598
/* === S Y N F I G ========================================================= */
Carlos Lopez a09598
/*!	\file target.h
Carlos Lopez a09598
**	\brief Target Class Implementation
Carlos Lopez a09598
**
Carlos Lopez a09598
**	$Id$
Carlos Lopez a09598
**
Carlos Lopez a09598
**	\legal
Carlos Lopez a09598
**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
Carlos Lopez a09598
**	Copyright (c) 2007 Chris Moore
Diego Barrios Romero 6202fa
**	Copyright (c) 2010 Diego Barrios Romero
Carlos Lopez a09598
**
Carlos Lopez a09598
**	This package is free software; you can redistribute it and/or
Carlos Lopez a09598
**	modify it under the terms of the GNU General Public License as
Carlos Lopez a09598
**	published by the Free Software Foundation; either version 2 of
Carlos Lopez a09598
**	the License, or (at your option) any later version.
Carlos Lopez a09598
**
Carlos Lopez a09598
**	This package is distributed in the hope that it will be useful,
Carlos Lopez a09598
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
Carlos Lopez a09598
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Carlos Lopez a09598
**	General Public License for more details.
Carlos Lopez a09598
**	\endlegal
Carlos Lopez a09598
*/
Carlos Lopez a09598
/* ========================================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
/* === S T A R T =========================================================== */
Carlos Lopez a09598
Carlos Lopez a09598
#ifndef __SYNFIG_TARGET_H
Carlos Lopez a09598
#define __SYNFIG_TARGET_H
Carlos Lopez a09598
Carlos Lopez a09598
/* === H E A D E R S ======================================================= */
Carlos Lopez a09598
Carlos Lopez a09598
#include <map></map>
bw 94d8a6
#include <utility></utility>
bw 94d8a6
bw 94d8a6
#include <sigc++ signal.h=""></sigc++>
bw 94d8a6
Carlos Lopez a09598
#include <etl handle=""></etl>
bw 94d8a6
Carlos Lopez a09598
#include "canvas.h"
bw 94d8a6
#include "color.h"
bw 94d8a6
#include "progresscallback.h"
bw 94d8a6
#include "renddesc.h"
bw 94d8a6
#include "string.h"
Diego Barrios Romero 6202fa
#include "targetparam.h"
Carlos Lopez a09598
Carlos Lopez a09598
/* === M A C R O S ========================================================= */
Carlos Lopez a09598
Carlos Lopez eb5f6e
//! Defines various variables and the create method, common for all Targets.
Carlos Lopez eb5f6e
//! To be used in the private part of the target class definition.
Carlos Lopez eb5f6e
#define SYNFIG_TARGET_MODULE_EXT \
Carlos Lopez eb5f6e
		public: static const char name__[], version__[], ext__[], cvs_id__[];\
Carlos Lopez eb5f6e
		static Target* create (const char *filename, synfig::TargetParam p);
Carlos Lopez a09598
Carlos Lopez a09598
//! Sets the name of the target
Carlos Lopez a09598
#define SYNFIG_TARGET_SET_NAME(class,x) const char class::name__[]=x
Carlos Lopez a09598
Carlos Lopez eb5f6e
//! Sets the primary file extension of the target
Carlos Lopez a09598
#define SYNFIG_TARGET_SET_EXT(class,x) const char class::ext__[]=x
Carlos Lopez a09598
Carlos Lopez a09598
//! Sets the version of the target
Carlos Lopez a09598
#define SYNFIG_TARGET_SET_VERSION(class,x) const char class::version__[]=x
Carlos Lopez a09598
Carlos Lopez a09598
//! Sets the CVS ID of the target
Carlos Lopez a09598
#define SYNFIG_TARGET_SET_CVS_ID(class,x) const char class::cvs_id__[]=x
Carlos Lopez a09598
[d.j.a.y] Jerome Blanchi e804b3
//! Defines implementation of the create method for the target
Carlos Lopez eb5f6e
//! \param filename The file name to be created by the target.
[d.j.a.y] Jerome Blanchi e804b3
//! \param p The parameters passed to the target (bit rate and vcodec)
Diego Barrios Romero 6202fa
#define SYNFIG_TARGET_INIT(class)										\
Diego Barrios Romero 6202fa
	synfig::Target* class::create (const char *filename,				\
Diego Barrios Romero 6202fa
								   synfig::TargetParam p)				\
Diego Barrios Romero 6202fa
	{ return new class(filename, p); }
Carlos Lopez a09598
Carlos Lopez a09598
/* === T Y P E D E F S ===================================================== */
Carlos Lopez a09598
Carlos Lopez a09598
/* === C L A S S E S & S T R U C T S ======================================= */
Carlos Lopez a09598
Carlos Lopez a09598
namespace synfig {
Carlos Lopez a09598
Carlos Lopez a09598
class Surface;
Nikita Kitaev cba007
class CairoSurface;
Carlos Lopez a09598
class RendDesc;
Carlos Lopez a09598
class Canvas;
Carlos Lopez a09598
class ProgressCallback;
Diego Barrios Romero a6f9bd
struct TargetParam;
Carlos Lopez a09598
dc451c
enum TargetAlphaMode
dc451c
{
dc451c
	TARGET_ALPHA_MODE_KEEP,          // 0
dc451c
	TARGET_ALPHA_MODE_FILL,          // 1
dc451c
	TARGET_ALPHA_MODE_REDUCE,        // 2
dc451c
	TARGET_ALPHA_MODE_EXTRACT        // 3
dc451c
}; // END enum TargetAlphaMode
dc451c
Carlos Lopez a09598
/*!	\class Target
Carlos Lopez eb5f6e
**	\brief Used to produce rendered animations of the documents
Carlos Lopez eb5f6e
**
Carlos Lopez eb5f6e
*	It is the base class for all the target renderers. It defines the has a static Book
Carlos Lopez eb5f6e
*	pointer class that is a map for the targets factory creators and the strings
Carlos Lopez eb5f6e
*	of the extension that the renderer can understand. It allows to create the a
Carlos Lopez eb5f6e
*	pointer to a particular renderer just by using the extension of the name of file
Carlos Lopez eb5f6e
*	to import. Also it creates a virtual member render() that must be declared in
Carlos Lopez eb5f6e
*	the inherited classes.
Carlos Lopez a09598
*/
Carlos Lopez a09598
class Target : public etl::shared_object
Carlos Lopez a09598
{
Carlos Lopez a09598
public:
Carlos Lopez a09598
	typedef etl::handle<target> Handle;</target>
Carlos Lopez a09598
	typedef etl::loose_handle<target> LooseHandle;</target>
Carlos Lopez a09598
	typedef etl::handle<const target=""> ConstHandle;</const>
Carlos Lopez a09598
Carlos Lopez a09598
	/*
Carlos Lopez a09598
 -- ** -- S I G N A L S -------------------------------------------------------
Carlos Lopez a09598
	*/
Carlos Lopez a09598
Carlos Lopez a09598
private:
Carlos Lopez a09598
Carlos Lopez a09598
	sigc::signal<void> signal_progress_;</void>
Carlos Lopez a09598
Carlos Lopez a09598
	/*
Carlos Lopez a09598
 -- ** -- S I G N A L   I N T E R F A C E -------------------------------------
Carlos Lopez a09598
	*/
Carlos Lopez a09598
Carlos Lopez a09598
public:
Carlos Lopez a09598
Carlos Lopez a09598
	sigc::signal<void>& signal_progress() { return signal_progress_; }</void>
Carlos Lopez a09598
Carlos Lopez a09598
	/*
Carlos Lopez a09598
 --	** -- C O N S T R U C T O R S ---------------------------------------------
Carlos Lopez a09598
	*/
Carlos Lopez a09598
Carlos Lopez a09598
public:
Diego Barrios Romero 5dcab4
	//! Type that represents a pointer to a Target's constructor.
Diego Barrios Romero 5dcab4
	/*! As a pointer to the constructor, it represents a "factory" of targets.
Carlos Lopez eb5f6e
	**  Receives the output filename (including path) and the parameters of the target.
Diego Barrios Romero 5dcab4
	*/
Diego Barrios Romero 6202fa
	typedef Target* (*Factory)(const char *filename, TargetParam p);
Diego Barrios Romero 6202fa
Diego Barrios Romero 8289fa
	struct BookEntry
Diego Barrios Romero 8289fa
	{
Diego Barrios Romero 8289fa
		Factory factory;
Diego Barrios Romero 8289fa
		String filename; ///< Output filename including path
Diego Barrios Romero 6202fa
		TargetParam target_param; ///< Target module parameters
Diego Barrios Romero 8289fa
	};
Carlos Lopez a09598
Diego Barrios Romero 5dcab4
	//! Book of types of targets indexed by the name of the Target.
Diego Barrios Romero 8289fa
	typedef std::map<string,bookentry> Book;</string,bookentry>
Carlos Lopez a09598
Carlos Lopez eb5f6e
	//! Book of types of targets indexed by the file extension
Carlos Lopez a09598
	typedef std::map<string,string> ExtBook;</string,string>
Carlos Lopez a09598
Carlos Lopez a09598
	//! Target Book, indexed by the target's name
Carlos Lopez a09598
	static Book* book_;
Carlos Lopez a09598
Carlos Lopez a09598
	//! Map of target names indexed by associated file extension
Carlos Lopez a09598
	static ExtBook* ext_book_;
Carlos Lopez a09598
Carlos Lopez a09598
	static Book& book();
Carlos Lopez a09598
	static ExtBook& ext_book();
Carlos Lopez a09598
Carlos Lopez eb5f6e
	//! Initializes the Target module by creating a book of targets names
Carlos Lopez eb5f6e
	//! and its creators
Carlos Lopez a09598
	static bool subsys_init();
Carlos Lopez eb5f6e
	//! Stops the Target module by deleting the book and the extension book
Carlos Lopez a09598
	static bool subsys_stop();
Carlos Lopez a09598
Carlos Lopez a09598
	//! Adjusted Render description set by set_rend_desc()
Carlos Lopez a09598
	RendDesc desc;
Carlos Lopez a09598
Carlos Lopez eb5f6e
	//! Canvas being rendered in this target module
[d.j.a.y] Jerome Blanchi e804b3
	/*!
[d.j.a.y] Jerome Blanchi e804b3
	 ** \sa set_canvas()
[d.j.a.y] Jerome Blanchi e804b3
	 */
Carlos Lopez a09598
	etl::handle<canvas> canvas;</canvas>
Carlos Lopez a09598
Carlos Lopez eb5f6e
	//! Render quality used for the render process of the target.
Carlos Lopez a09598
	int quality_;
dc451c
	
[d.j.a.y] Jerome Blanchi e804b3
	//! Tells how to handle alpha. Used by non alpha supported targets to decide if the background must be filled or not
dc451c
	TargetAlphaMode alpha_mode;
Carlos Lopez a09598
Carlos Lopez eb5f6e
	//! When set to true, the target doesn't sync to canvas time.
Carlos Lopez a09598
	bool avoid_time_sync_;
Carlos Lopez 4a0029
	
Carlos Lopez 4a0029
	//! The current frame being rendered
Carlos Lopez 4a0029
	int curr_frame_;
Carlos Lopez a09598
Carlos Lopez a09598
protected:
Carlos Lopez eb5f6e
	//! Default constructor
Carlos Lopez a09598
	Target();
Carlos Lopez a09598
Carlos Lopez a09598
public:
Carlos Lopez a09598
	virtual ~Target() { }
Carlos Lopez eb5f6e
	//! Gets the target quality
Carlos Lopez a09598
	int get_quality()const { return quality_; }
Carlos Lopez eb5f6e
	//! Sets the target quality
Carlos Lopez a09598
	void set_quality(int q) { quality_=q; }
Carlos Lopez eb5f6e
	//! Sets the target avoid time synchronization
Carlos Lopez a09598
	void set_avoid_time_sync(bool x=true) { avoid_time_sync_=x; }
Carlos Lopez eb5f6e
	//! Gets the target avoid time synchronization
Carlos Lopez a09598
	bool get_avoid_time_sync()const { return avoid_time_sync_; }
dc451c
	//! Tells how to handle alpha
[d.j.a.y] Jerome Blanchi e804b3
	/*! Used by non alpha supported targets to decide if the background
[d.j.a.y] Jerome Blanchi e804b3
	 ** must be filled or not
[d.j.a.y] Jerome Blanchi e804b3
	 */
dc451c
	TargetAlphaMode get_alpha_mode()const { return alpha_mode; }
dc451c
	//! Sets how to handle alpha
dc451c
	void set_alpha_mode(TargetAlphaMode x=TARGET_ALPHA_MODE_KEEP) { alpha_mode=x; }
Carlos Lopez eb5f6e
	//! Sets the target canvas. Must be defined by derived targets
Carlos Lopez a09598
	virtual void set_canvas(etl::handle<canvas> c);</canvas>
Carlos Lopez eb5f6e
	//! Gets the target canvas.
Carlos Lopez a09598
	const etl::handle<canvas> &get_canvas()const { return canvas; }</canvas>
Carlos Lopez eb5f6e
	//! Gets the target particular render description
Carlos Lopez a09598
	RendDesc &rend_desc() { return desc; }
Carlos Lopez eb5f6e
	//! Gets the target particular render description
Carlos Lopez a09598
	const RendDesc &rend_desc()const { return desc; }
Carlos Lopez a09598
	//! Sets the RendDesc for the Target to \a desc.
Carlos Lopez a09598
	/*!	If there are any parts of \a desc that the render target
[d.j.a.y] Jerome Blanchi e804b3
	 ** is not capable of doing, the render target will adjust
[d.j.a.y] Jerome Blanchi e804b3
	 ** \a desc to fit its needs.
[d.j.a.y] Jerome Blanchi e804b3
	 ** \param d an RendDesc pointer.
[d.j.a.y] Jerome Blanchi e804b3
	 ** \return true on success
Carlos Lopez a09598
	*/
Carlos Lopez a09598
	virtual bool set_rend_desc(RendDesc *d) { desc=*d; return true; }
Carlos Lopez eb5f6e
	//! Renders the canvas to the target
Carlos Lopez eb5f6e
	virtual bool render(ProgressCallback *cb=NULL)=0;
Carlos Lopez eb5f6e
	//! Initialization tasks of the derived target.
[d.j.a.y] Jerome Blanchi e804b3
	/*!
[d.j.a.y] Jerome Blanchi e804b3
	 ** \returns true if the initialization has no errors
[d.j.a.y] Jerome Blanchi e804b3
	*/
trizer f95ec0
	virtual bool init(ProgressCallback *cb=NULL) { (void)cb; return true; }
Carlos Lopez a09598
Carlos Lopez a09598
	//! Creates a new Target described by \a type, outputting to a file described by \a filename.
Diego Barrios Romero 6202fa
	static Handle create(const String &type, const String &filename,
Diego Barrios Romero 6202fa
						 synfig::TargetParam params);
Carlos Lopez 4fdecc
	
Carlos Lopez 4fdecc
	//!	Sets the time for the next frame at \a time
[d.j.a.y] Jerome Blanchi e804b3
	/*! It modifies the curr_frame_ member which has to be set to zero when next_frame is called for the first time
[d.j.a.y] Jerome Blanchi e804b3
	 ** \param time The time reference to be modified
Carlos Lopez 4fdecc
	 **	\return The number of remainig frames to render
Carlos Lopez 4fdecc
	 **	\sa curr_frame_
Carlos Lopez 4fdecc
	*/
Carlos Lopez 4a0029
	virtual int	next_frame(Time& time);
Carlos Lopez a09598
}; // END of class Target
Carlos Lopez a09598
Carlos Lopez a09598
}; // END of namespace synfig
Carlos Lopez a09598
Carlos Lopez a09598
/* === E N D =============================================================== */
Carlos Lopez a09598
Carlos Lopez a09598
#endif