1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
5 ** $Id: surfacenew.h,v 1.1 2005/01/21 19:29:10 darco Exp $
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === S T A R T =========================================================== */
25 #ifndef __SYNFIG_SURFACENEW_H
26 #define __SYNFIG_SURFACENEW_H
28 /* === H E A D E R S ======================================================= */
31 #include <ETL/ref_count>
36 /* === M A C R O S ========================================================= */
38 /* === T Y P E D E F S ===================================================== */
40 /* === C L A S S E S & S T R U C T S ======================================= */
45 class SurfaceChannelLock;
46 class SurfaceChannelLockConst;
49 enum SurfaceColorSystem
55 }; // END of enum SurfaceColorSystem
70 }; // END of enum SurfaceChannel
72 class SurfaceNew : etl::shared_object
74 friend class SurfaceChannelLock;
77 -- ** -- T Y P E S -----------------------------------------------------------
83 typedef etl::handle<SurfaceNew> Handle;
86 typedef etl::handle<const SurfaceNew> HandleConst;
89 typedef etl::loose_handle<SurfaceNew> LooseHandle;
92 typedef SurfaceChannel;
95 typedef SurfaceChannelLock ChannelLock;
98 typedef SurfaceChannelLockConst ChannelLockConst;
101 typedef SurfaceColorSystem;
108 Lock(const Handle& x):x(x) { x->lock(); }
109 void unlock() { if(x){ x->unlock(); x=0; } }
110 ~Lock() { unlock(); }
111 }; // END of class Lock
120 -- ** -- D A T A -------------------------------------------------------------
132 ColorSystem color_system_;
138 std::map<Channel,ChannelData> channel_map_;
141 -- ** -- S I G N A L S -------------------------------------------------------
147 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
153 -- ** -- C O N S T R U C T O R S ---------------------------------------------
164 virtual ~SurfaceNew();
167 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
179 void set_wh(int w, int h);
182 ColorSystem get_color_system()const;
185 void set_color_system(ColorSystem x);
187 //! Should only be used in certain circumstances
188 Color get_color(int x, int y)const;
200 ChannelLock lock_channel(Channel chan);
203 ChannelLockConst lock_channel_const(Channel chan)const;
206 ChannelLock lock_channel_alpha(Channel chan);
209 ChannelLockConst lock_channel_alpha_const(Channel chan)const;
212 bool is_channel_defined(Channel chan)const;
215 bool get_premult()const;
221 -- ** -- S T A T I C F U N C T I O N S -------------------------------------
226 //! Normal SurfaceNew Constructor
227 static Handle create(int w=0, int h=0, ColorSystem sys=COLORSYS_RGB);
229 //! Converts an old Surface to a SurfaceNew
230 static Handle create(const Surface&);
232 //! Dupilcates a surface
233 static Handle create(HandleConst);
235 //! Creates a cropped copy of a surface
236 static Handle crop(HandleConst, int x, int y, int w, int h);
244 Color::BlendMethod bm=Color::BLEND_COMPOSITE
257 Color::BlendMethod bm=Color::BLEND_COMPOSITE
261 static void chan_mlt(ChannelLock& dest, float x);
262 static void chan_mlt(ChannelLock& dest, const ChannelLockConst& x);
264 static void chan_div(ChannelLock& dest, float x);
265 static void chan_div(ChannelLock& dest, const ChannelLockConst& x);
267 static void chan_add(ChannelLock& dest, float x);
268 static void chan_add(ChannelLock& dest, const ChannelLockConst& x);
270 static void chan_sub(ChannelLock& dest, float x);
271 static void chan_sub(ChannelLock& dest, const ChannelLockConst& x);
272 }; // END of class SurfaceNew
275 class SurfaceChannelLockConst
277 friend class SurfaceNew;
280 -- ** -- T Y P E S -----------------------------------------------------------
286 -- ** -- D A T A -------------------------------------------------------------
292 SurfaceNew::Handle surface_;
295 etl::reference_counter ref_count_;
298 SurfaceChannel channel_;
301 bool data_ptr_checked_out_;
304 -- ** -- C O N S T R U C T O R S ---------------------------------------------
309 SurfaceChannelLockConst();
312 ~SurfaceChannelLockConst();
315 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
321 SurfaceChannel get_channel()const;
330 float get_value(int x, int y);
333 const float* get_data_ptr()const;
336 int get_data_ptr_stride()const;
338 //! Releases the pointer obtained with get_data_ptr()
339 void release_data_ptr()const;
342 operator bool()const;
343 }; // END of class SurfaceChannelLockConst
347 class SurfaceChannelLock : public SurfaceChannelLockConst
349 friend class SurfaceNew;
351 using SurfaceChannelLock::get_data_ptr;
354 -- ** -- T Y P E S -----------------------------------------------------------
360 -- ** -- D A T A -------------------------------------------------------------
366 -- ** -- C O N S T R U C T O R S ---------------------------------------------
372 SurfaceChannelLock();
375 ~SurfaceChannelLock();
378 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
387 void fill(float value);
390 void set_value(int x, int y, float v);
392 float* get_data_ptr();
393 }; // END of class ChannelLock
396 }; // END of namespace synfig
398 /* === E N D =============================================================== */