surfacenew.h

Go to the documentation of this file.
00001 /* === S Y N F I G ========================================================= */
00021 /* ========================================================================= */
00022 
00023 /* === S T A R T =========================================================== */
00024 
00025 #ifndef __SYNFIG_SURFACENEW_H
00026 #define __SYNFIG_SURFACENEW_H
00027 
00028 /* === H E A D E R S ======================================================= */
00029 
00030 #include <ETL/handle>
00031 #include <ETL/ref_count>
00032 #include "color.h"
00033 #include "mutex.h"
00034 #include <map>
00035 
00036 /* === M A C R O S ========================================================= */
00037 
00038 /* === T Y P E D E F S ===================================================== */
00039 
00040 /* === C L A S S E S & S T R U C T S ======================================= */
00041 
00042 namespace synfig {
00043 
00044 class Surface;
00045 class SurfaceChannelLock;
00046 class SurfaceChannelLockConst;
00047 
00049 enum SurfaceColorSystem
00050 {
00051     COLORSYS_RGB,
00052     COLORSYS_YUV,
00053     
00054     COLORSYS_END
00055 }; // END of enum SurfaceColorSystem
00056 
00058 enum SurfaceChannel
00059 {
00060     CHAN_A,
00061     CHAN_R,
00062     CHAN_G,
00063     CHAN_B,
00064 
00065     CHAN_Y,
00066     CHAN_U,
00067     CHAN_V,
00068 
00069     CHAN_END
00070 }; // END of enum SurfaceChannel
00071 
00072 class SurfaceNew : etl::shared_object
00073 {
00074     friend class SurfaceChannelLock;
00075 
00076     /*
00077  -- ** -- T Y P E S -----------------------------------------------------------
00078     */
00079 
00080 public: 
00081 
00083     typedef etl::handle<SurfaceNew> Handle;
00084 
00086     typedef etl::handle<const SurfaceNew> HandleConst;
00087     
00089     typedef etl::loose_handle<SurfaceNew> LooseHandle;
00090 
00092     typedef SurfaceChannel;
00093 
00095     typedef SurfaceChannelLock ChannelLock;
00096 
00098     typedef SurfaceChannelLockConst ChannelLockConst;
00099 
00101     typedef SurfaceColorSystem;
00102     
00104     class Lock
00105     {
00106         Handle x;
00107     public:
00108         Lock(const Handle& x):x(x) { x->lock(); }
00109         void unlock() { if(x){ x->unlock(); x=0; } }
00110         ~Lock() { unlock(); }       
00111     }; // END of class Lock
00112     friend class Lock;
00113     
00114 private:
00115 
00117     class ChannelData;
00118     
00119     /*
00120  -- ** -- D A T A -------------------------------------------------------------
00121     */
00122 
00123 private:
00124     
00126     RecMutex mutex_;
00127     
00129     int w_,h_;
00130 
00132     ColorSystem color_system_;
00133     
00135     bool premult_flag_;
00136 
00138     std::map<Channel,ChannelData> channel_map_;
00139     
00140     /*
00141  -- ** -- S I G N A L S -------------------------------------------------------
00142     */
00143 
00144 private:
00145 
00146     /*
00147  -- ** -- S I G N A L   I N T E R F A C E -------------------------------------
00148     */
00149 
00150 public:
00151 
00152     /*
00153  -- ** -- C O N S T R U C T O R S ---------------------------------------------
00154     */
00155 
00156 protected:
00157     
00159     SurfaceNew();
00160 
00161 public:
00162 
00164     virtual ~SurfaceNew();
00165 
00166     /*
00167  -- ** -- M E M B E R   F U N C T I O N S -------------------------------------
00168     */
00169 
00170 public:
00171 
00173     int get_w()const;
00174     
00176     int get_h()const;
00177     
00179     void set_wh(int w, int h);
00180 
00182     ColorSystem get_color_system()const;
00183 
00185     void set_color_system(ColorSystem x);
00186 
00188     Color get_color(int x, int y)const;
00189     
00191     void lock();
00192     
00194     void unlock();
00195     
00197     bool trylock();
00198     
00200     ChannelLock lock_channel(Channel chan);
00201 
00203     ChannelLockConst lock_channel_const(Channel chan)const;
00204 
00206     ChannelLock lock_channel_alpha(Channel chan);
00207 
00209     ChannelLockConst lock_channel_alpha_const(Channel chan)const;
00210 
00212     bool is_channel_defined(Channel chan)const;
00213     
00215     bool get_premult()const;
00216 
00218     void set_premult();
00219     
00220     /*
00221  -- ** -- S T A T I C   F U N C T I O N S -------------------------------------
00222     */
00223 
00224 public:
00225 
00227     static Handle create(int w=0, int h=0, ColorSystem sys=COLORSYS_RGB);
00228 
00230     static Handle create(const Surface&);
00231 
00233     static Handle create(HandleConst);
00234 
00236     static Handle crop(HandleConst, int x, int y, int w, int h);
00237     
00238     static void blit(
00239         Handle dest,
00240         int x_dest,
00241         int y_dest,
00242         HandleConst src,
00243         float amount=1.0,
00244         Color::BlendMethod bm=Color::BLEND_COMPOSITE
00245     );
00246     
00247     static void blit(
00248         Handle dest,
00249         int x_dest,
00250         int y_dest,
00251         Handle src,
00252         int x_src,
00253         int y_src,
00254         int w_src,
00255         int h_src,
00256         float amount=1.0,
00257         Color::BlendMethod bm=Color::BLEND_COMPOSITE
00258     );
00259     
00260     
00261     static void chan_mlt(ChannelLock& dest, float x);
00262     static void chan_mlt(ChannelLock& dest, const ChannelLockConst& x);
00263 
00264     static void chan_div(ChannelLock& dest, float x);
00265     static void chan_div(ChannelLock& dest, const ChannelLockConst& x);
00266 
00267     static void chan_add(ChannelLock& dest, float x);
00268     static void chan_add(ChannelLock& dest, const ChannelLockConst& x);
00269 
00270     static void chan_sub(ChannelLock& dest, float x);
00271     static void chan_sub(ChannelLock& dest, const ChannelLockConst& x);
00272 }; // END of class SurfaceNew
00273 
00275 class SurfaceChannelLockConst
00276 {
00277     friend class SurfaceNew;
00278 
00279     /*
00280  -- ** -- T Y P E S -----------------------------------------------------------
00281     */
00282 
00283 public: 
00284 
00285     /*
00286  -- ** -- D A T A -------------------------------------------------------------
00287     */
00288 
00289 protected:
00290     
00292     SurfaceNew::Handle surface_;
00293     
00295     etl::reference_counter ref_count_;
00296 
00298     SurfaceChannel channel_;
00299 
00301     bool data_ptr_checked_out_;
00302     
00303     /*
00304  -- ** -- C O N S T R U C T O R S ---------------------------------------------
00305     */
00306 
00307 public:
00308 
00309     SurfaceChannelLockConst();
00310     
00312     ~SurfaceChannelLockConst();
00313 
00314     /*
00315  -- ** -- M E M B E R   F U N C T I O N S -------------------------------------
00316     */
00317 
00318 public:
00319     
00321     SurfaceChannel get_channel()const;
00322     
00324     int get_w()const;
00325     
00327     int get_h()const;
00328     
00330     float get_value(int x, int y);
00331     
00333     const float* get_data_ptr()const;
00334     
00336     int get_data_ptr_stride()const;
00337     
00339     void release_data_ptr()const;
00340     
00342     operator bool()const;
00343 }; // END of class SurfaceChannelLockConst
00344 
00345 
00347 class SurfaceChannelLock : public SurfaceChannelLockConst
00348 {
00349     friend class SurfaceNew;
00350 
00351     using SurfaceChannelLock::get_data_ptr;
00352     
00353     /*
00354  -- ** -- T Y P E S -----------------------------------------------------------
00355     */
00356 
00357 public: 
00358 
00359     /*
00360  -- ** -- D A T A -------------------------------------------------------------
00361     */
00362 
00363 private:
00364     
00365     /*
00366  -- ** -- C O N S T R U C T O R S ---------------------------------------------
00367     */
00368 
00369 public:
00370 
00372     SurfaceChannelLock();
00373 
00375     ~SurfaceChannelLock();
00376 
00377     /*
00378  -- ** -- M E M B E R   F U N C T I O N S -------------------------------------
00379     */
00380 
00381 public:
00382 
00384     void clear();
00385     
00387     void fill(float value);
00388         
00390     void set_value(int x, int y, float v);
00391 
00392     float* get_data_ptr();
00393 }; // END of class ChannelLock
00394 
00395 
00396 }; // END of namespace synfig
00397 
00398 /* === E N D =============================================================== */
00399 
00400 #endif

Generated on Fri Jun 23 15:20:50 2006 for synfig by  doxygen 1.4.6