Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

/home/slang/XVision2/src/Pipes/PipeImage.h

00001 # ifndef _PIPEIMAGE_H_
00002 # define _PIPEIMAGE_H_
00003 
00004 # include <config.h>
00005 # include "PipeModules.h"
00006 # include <Video.h>
00007 # include <XVImageScalar.h>
00008 # include <XVWindowX.h>
00009 
00010 // Video source pipe class, basically a wrapper of Video class
00011 
00012 template<class T>
00013 class PipeVideoSource : public PipeLift0<XVImageRGB<T> > {
00014   typedef PipeVideoSource<T> ThisType ;
00015   typedef PipeLift0<ReturnType> BaseType ;
00016 
00017  protected:  
00018   Video<T> * v ;
00019   
00020   ThisType * duplicate(void) const { return new ThisType(*this); }
00021   inline void check(void) { PipeModule<ReturnType>::check( v ); }
00022 
00023  public:
00024 
00025   PipeVideoSource( Video<T>& vin ) : BaseType(), v(&vin) {}
00026   PipeVideoSource( const ThisType& p ) : BaseType(p), v(p.v) {}
00027 
00028   ReturnType compute_local_fn( int fc )
00029     {
00030       check();
00031       // Some checks should be done at this point to see if the source
00032       // is drained so as to throw out a BrokenPipe exception, but this
00033       // cannot achived without support from Video classes (i.e. a sepcial
00034       // return value from request_frame_continues()
00035       return v->next_frame_continuous();
00036     }
00037 
00038   operator ResultType () const { return ResultType(duplicate()) ; }
00039 
00040   ResultType operator () (void) const { return ResultType(duplicate()) ; }
00041 };
00042 
00043 // Video display class which is drawable
00044 // This class doesn't work within PipeFun
00045 
00046 class PipeShowable {
00047  public:
00048   virtual void show( int fc, XVDrawable& ) = 0 ;
00049 };
00050 
00051 template<class T>
00052 class PipeShowableClass : public PipeShowable {
00053   T * t ;
00054  public:
00055   PipeShowableClass( T& obj ) : t(&obj) {}
00056   virtual void show( int fc, XVDrawable& d ) { t->show(d) ; }
00057 };
00058 
00059 template<class T>
00060 class PipeShowablePipe : public PipeShowable {
00061   Pipe<T> * t ;
00062  public:
00063   PipeShowablePipe( const Pipe<T>& p ) : t( new Pipe<T>(p) ) {}
00064   virtual void show( int fc, XVDrawable& d ) { t->get_value(fc).show(d) ; }
00065 };
00066 
00067 template<class T>
00068 class PipeDrawDisplay: public PipeLift1<XVImageRGB<T>, XVImageRGB<T> > {
00069   typedef PipeDrawDisplay<T> ThisType ;
00070   typedef PipeLift1<XVImageRGB<T>, XVImageRGB<T> > BaseType ;
00071  protected:
00072   struct ShowItem {
00073     PipeShowable * item ;
00074     ShowItem * next ;
00075     ShowItem( PipeShowable * i, ShowItem * n = 0 ) : item(i), next(n) {}
00076     ~ShowItem() { delete item ; delete next ; }
00077   } * head, ** tail ;
00078 
00079  protected:
00080   XVDrawWindowX<T> * w;
00081   Pipe<XVImageRGB<T> > *pred;
00082 
00083  protected:
00084   void setDependency(void) { addDependency((DependencyUnit**)&pred); }
00085   ThisType * duplicate(void) const { return new ThisType(*this); }
00086   inline void check(void) { PipeModule<XVImageRGB<T> >::check( pred ); }
00087 
00088 public:
00089   PipeDrawDisplay() : head(0), tail(0), w(0), pred(0) 
00090     { tail = &head ; setDependency() ; }
00091   // memory leaks here: get it fixed when have time
00092   PipeDrawDisplay( const ThisType& p ) : BaseType(p), head(p.head), 
00093     tail(p.tail), w(p.w), pred(p.pred) { setDependency() ; }
00094 
00095   ResultType operator () ( const Pipe<XVImageRGB<T> >& x ) const
00096     {
00097       ThisType *p = duplicate();
00098       p->pred = new Pipe<XVImageRGB<T> >(x);
00099       return ResultType(p);
00100     }
00101 
00102   ReturnType compute_local_fn(int fc) 
00103     {
00104       check();
00105       ReturnType image = (*pred)->get_value(fc);
00106       if (!w) {
00107      w = new XVDrawWindowX<T>(&image) ;
00108      w->map();
00109      w->setCOPY();
00110       }
00111       w->CopySubImage(&image);
00112       for( ShowItem * p = head ; p != *tail ; p = p -> next ) {
00113      p->item->show(fc,*w) ;
00114       }
00115       w->swap_buffers();
00116       w->flush();
00117       return image;
00118     }
00119 
00120   ThisType& operator << ( PipeShowable* x ) 
00121     { 
00122       *tail = new ShowItem(x,*tail) ; 
00123       tail = &((*tail)->next) ; 
00124       return *this ; 
00125     }
00126 
00127   template<class D> 
00128   ThisType operator << ( const Pipe<D>& p ) 
00129     { return (*this) << new PipeShowablePipe<D>(p) ; }
00130 
00131   template<class D>
00132   ThisType operator << ( D& d )
00133     { return (*this) << new PipeShowableClass<D>(d) ; }
00134 };
00135 
00136 // Video display class that is not drawable, so basically useless
00137 
00138 template<class T>
00139 class PipeVideoDisplay: public PipeModule<XVImageRGB<T> > {
00140  protected:
00141   XVWindowX<T> * w;
00142   Pipe<XVImageRGB<T> > *pred;
00143 
00144  protected:
00145   
00146   inline void check(void) { PipeModule<XVImageRGB<T> >::check( pred ); }
00147 
00148 public:
00149   PipeVideoDisplay() : w(0), pred(0) {}
00150 
00151   operator Pipe<T> () const 
00152     { return Pipe<XVImageRGB<T> >(new PipeVideoDisplay<T>(*this)) ; }
00153 
00154   Pipe<XVImageRGB<T> > operator () ( const Pipe<XVImageRGB<T> >& x ) const
00155     {
00156       PipeVideoDisplay *p = new PipeVideoDisplay<T>();
00157       p->pred = new Pipe<XVImageRGB<T> >(x);
00158       return Pipe<XVImageRGB<T> >(p);
00159     }
00160 
00161   XVImageRGB<T> compute_local_fn(int fc) 
00162     {
00163       check();
00164       XVImageRGB<XV_RGB> image = (*pred)->get_value(fc);
00165       if (!w) {
00166      w = new XVWindowX<T>(&image) ;
00167      w->map();
00168       }
00169       w->CopySubImage(&image);
00170       w->swap_buffers();
00171       w->flush();
00172       return image;
00173     }
00174 };
00175 
00176 // Shorthands for pure image lifts
00177 
00178 template<class Tout, class Tin>
00179 class ScalarImageLift1 {
00180  public:
00181   typedef PipeModuleLift1< XVImageScalar<Tout>, XVImageScalar<Tin>, 
00182     XVImageScalar<Tout> (*)(const XVImageScalar<Tin>&)> Type ;
00183 };
00184 
00185 template<class Tout, class Tin1, class Tin2>
00186 class ScalarImageLift2 { 
00187  public:
00188   typedef PipeModuleLift2< XVImageScalar<Tout>, XVImageScalar<Tin1>, 
00189     XVImageScalar<Tin2>, XVImageScalar<Tout> (*)
00190     (const XVImageScalar<Tin1>&,const XVImageScalar<Tin1>&)> Type ;
00191 };
00192 
00193 // Lifted operators
00194 
00195 //extern ScalarImageLift1<int,int>::Type Prewitt_xP;
00196 //extern ScalarImageLift1<int,int>::Type Prewitt_yP;
00197 extern PipeModuleLift2Types<XVImageScalar<int>, XVImageScalar<int>, 
00198                             XVImageGeneric>::Ref SubImageG;
00199 extern PipeModuleLift3Types<XVImageScalar<int>, XVImageScalar<int>, 
00200                             XVSize, XVPosition>::Ref SubImageSP;
00201 
00202 
00203 # endif //_PIPEIMAGE_H_

Generated at Thu Mar 29 22:37:28 2001 for XVision by doxygen1.2.0 written by Dimitri van Heesch, © 1997-2000