1 /* === S I N F G =========================================================== */
3 ** \brief Template Header
5 ** $Id: surfacenew.h,v 1.1 2005/01/21 19:29:10 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
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.
20 /* ========================================================================= */
22 /* === S T A R T =========================================================== */
24 #ifndef __SINFG_SURFACENEW_H
25 #define __SINFG_SURFACENEW_H
27 /* === H E A D E R S ======================================================= */
30 #include <ETL/ref_count>
35 /* === M A C R O S ========================================================= */
37 /* === T Y P E D E F S ===================================================== */
39 /* === C L A S S E S & S T R U C T S ======================================= */
44 class SurfaceChannelLock;
45 class SurfaceChannelLockConst;
48 enum SurfaceColorSystem
54 }; // END of enum SurfaceColorSystem
69 }; // END of enum SurfaceChannel
71 class SurfaceNew : etl::shared_object
73 friend class SurfaceChannelLock;
76 -- ** -- T Y P E S -----------------------------------------------------------
82 typedef etl::handle<SurfaceNew> Handle;
85 typedef etl::handle<const SurfaceNew> HandleConst;
88 typedef etl::loose_handle<SurfaceNew> LooseHandle;
91 typedef SurfaceChannel;
94 typedef SurfaceChannelLock ChannelLock;
97 typedef SurfaceChannelLockConst ChannelLockConst;
100 typedef SurfaceColorSystem;
107 Lock(const Handle& x):x(x) { x->lock(); }
108 void unlock() { if(x){ x->unlock(); x=0; } }
109 ~Lock() { unlock(); }
110 }; // END of class Lock
119 -- ** -- D A T A -------------------------------------------------------------
131 ColorSystem color_system_;
137 std::map<Channel,ChannelData> channel_map_;
140 -- ** -- S I G N A L S -------------------------------------------------------
146 -- ** -- S I G N A L I N T E R F A C E -------------------------------------
152 -- ** -- C O N S T R U C T O R S ---------------------------------------------
163 virtual ~SurfaceNew();
166 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
178 void set_wh(int w, int h);
181 ColorSystem get_color_system()const;
184 void set_color_system(ColorSystem x);
186 //! Should only be used in certain circumstances
187 Color get_color(int x, int y)const;
199 ChannelLock lock_channel(Channel chan);
202 ChannelLockConst lock_channel_const(Channel chan)const;
205 ChannelLock lock_channel_alpha(Channel chan);
208 ChannelLockConst lock_channel_alpha_const(Channel chan)const;
211 bool is_channel_defined(Channel chan)const;
214 bool get_premult()const;
220 -- ** -- S T A T I C F U N C T I O N S -------------------------------------
225 //! Normal SurfaceNew Constructor
226 static Handle create(int w=0, int h=0, ColorSystem sys=COLORSYS_RGB);
228 //! Converts an old Surface to a SurfaceNew
229 static Handle create(const Surface&);
231 //! Dupilcates a surface
232 static Handle create(HandleConst);
234 //! Creates a cropped copy of a surface
235 static Handle crop(HandleConst, int x, int y, int w, int h);
243 Color::BlendMethod bm=Color::BLEND_COMPOSITE
256 Color::BlendMethod bm=Color::BLEND_COMPOSITE
260 static void chan_mlt(ChannelLock& dest, float x);
261 static void chan_mlt(ChannelLock& dest, const ChannelLockConst& x);
263 static void chan_div(ChannelLock& dest, float x);
264 static void chan_div(ChannelLock& dest, const ChannelLockConst& x);
266 static void chan_add(ChannelLock& dest, float x);
267 static void chan_add(ChannelLock& dest, const ChannelLockConst& x);
269 static void chan_sub(ChannelLock& dest, float x);
270 static void chan_sub(ChannelLock& dest, const ChannelLockConst& x);
271 }; // END of class SurfaceNew
274 class SurfaceChannelLockConst
276 friend class SurfaceNew;
279 -- ** -- T Y P E S -----------------------------------------------------------
285 -- ** -- D A T A -------------------------------------------------------------
291 SurfaceNew::Handle surface_;
294 etl::reference_counter ref_count_;
297 SurfaceChannel channel_;
300 bool data_ptr_checked_out_;
303 -- ** -- C O N S T R U C T O R S ---------------------------------------------
308 SurfaceChannelLockConst();
311 ~SurfaceChannelLockConst();
314 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
320 SurfaceChannel get_channel()const;
329 float get_value(int x, int y);
332 const float* get_data_ptr()const;
335 int get_data_ptr_stride()const;
337 //! Releases the pointer obtained with get_data_ptr()
338 void release_data_ptr()const;
341 operator bool()const;
342 }; // END of class SurfaceChannelLockConst
346 class SurfaceChannelLock : public SurfaceChannelLockConst
348 friend class SurfaceNew;
350 using SurfaceChannelLock::get_data_ptr;
353 -- ** -- T Y P E S -----------------------------------------------------------
359 -- ** -- D A T A -------------------------------------------------------------
365 -- ** -- C O N S T R U C T O R S ---------------------------------------------
371 SurfaceChannelLock();
374 ~SurfaceChannelLock();
377 -- ** -- M E M B E R F U N C T I O N S -------------------------------------
386 void fill(float value);
389 void set_value(int x, int y, float v);
391 float* get_data_ptr();
392 }; // END of class ChannelLock
395 }; // END of namespace sinfg
397 /* === E N D =============================================================== */