libcvd-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libcvd-members] libcvd cvd_src/videosource.cpp cvd/videosource....


From: Edward Rosten
Subject: [libcvd-members] libcvd cvd_src/videosource.cpp cvd/videosource....
Date: Fri, 02 Sep 2011 12:26:32 +0000

CVSROOT:        /cvsroot/libcvd
Module name:    libcvd
Changes by:     Edward Rosten <edrosten>        11/09/02 12:26:32

Modified files:
        cvd_src        : videosource.cpp 
        cvd            : videosource.h deinterlacebuffer.h 

Log message:
        Add deinterlacing to open_video_source as a chainable buffer.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd_src/videosource.cpp?cvsroot=libcvd&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/videosource.h?cvsroot=libcvd&r1=1.31&r2=1.32
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/deinterlacebuffer.h?cvsroot=libcvd&r1=1.9&r2=1.10

Patches:
Index: cvd_src/videosource.cpp
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd_src/videosource.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- cvd_src/videosource.cpp     20 Mar 2010 17:21:11 -0000      1.18
+++ cvd_src/videosource.cpp     2 Sep 2011 12:26:31 -0000       1.19
@@ -265,6 +265,27 @@
                }
        }
 
+       void get_deinterlace_options(const VideoSource& vs, 
DeinterlaceBufferFields::Fields& fields)
+       {
+               for (VideoSource::option_list::const_iterator 
it=vs.options.begin(); it != vs.options.end(); ++it)
+               {               
+                       if(it != vs.options.begin())
+                               throw VideoSourceException("invalid option for 
files protocol: multiple field specifications");
+
+                       if(it->first == "oddonly" && parseBoolFlag(it->second) 
== true)
+                               fields = DeinterlaceBufferFields::OddOnly;
+                       else if(it->first == "evenonly" && 
parseBoolFlag(it->second) == true)
+                               fields = DeinterlaceBufferFields::EvenOnly;
+                       else if(it->first == "oddeven" && 
parseBoolFlag(it->second) == true)
+                               fields = DeinterlaceBufferFields::OddEven;
+                       else if(it->first == "evenodd" && 
parseBoolFlag(it->second) == true)
+                               fields = DeinterlaceBufferFields::EvenOdd;
+                       else
+                               throw VideoSourceException("invalid option for 
files protocol: "+it->first +
+                                                                               
   "\n\t valid options: oddonly, evenonly, oddeven, evenodd");
+               }
+       }
+
        void get_colourspace_options(const VideoSource& vs, string& colourspace)
        {
                colourspace = "mono";

Index: cvd/videosource.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/videosource.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- cvd/videosource.h   6 Apr 2011 17:50:36 -0000       1.31
+++ cvd/videosource.h   2 Sep 2011 12:26:32 -0000       1.32
@@ -11,6 +11,7 @@
 #include <cvd/config.h>
 
 #include <cvd/colourspacebuffer.h>
+#include <cvd/deinterlacebuffer.h>
 #include <cvd/colourspaces.h>
 #include <cvd/videobufferwithdata.h>
 #include <cvd/readaheadvideobuffer.h>
@@ -74,6 +75,26 @@
  
     
////////////////////////////////////////////////////////////////////////////////
        //
+       // Deinterlace buffer
+       //
+       void get_deinterlace_options(const VideoSource& vs, 
DeinterlaceBufferFields::Fields& fields);
+
+       template<class T> struct makeDeinterlaceBuffer
+       {
+               static VideoBuffer<T>* make(DeinterlaceBufferFields::Fields f, 
const std::string& url)
+               {
+                       std::auto_ptr<VideoBuffer<T> > source  = 
std::auto_ptr<VideoBuffer<T> > 
(static_cast<VideoBuffer<T>*>(open_video_source<T>(url)));
+                       std::auto_ptr<VideoBuffer<T> > de_int  = 
std::auto_ptr<VideoBuffer<T> > (static_cast<DeinterlaceBuffer<T>*>(new 
DeinterlaceBuffer<T>(*source, f)));
+
+
+
+                       return new VideoBufferWithData<T, VideoBuffer<T> 
>(de_int, source);
+               }
+       };
+
+ 
+    
////////////////////////////////////////////////////////////////////////////////
+       //
        // Colourspace conversion buffer
        //
     
@@ -296,6 +317,14 @@
                                return new VideoBufferWithData<T, 
VideoBuffer<T> >(b, jpeg_buffer);
                        }
                }
+               else if(vs.protocol == "deinterlace")
+               {
+                       DeinterlaceBufferFields::Fields 
f=DeinterlaceBufferFields::OddEven;
+
+                       get_deinterlace_options(vs, f);
+
+                       return makeDeinterlaceBuffer<T>::make(f, vs.identifier);
+               }
                else if(vs.protocol == "colourspace")
                {
                        std::string from = "byte";
@@ -386,10 +415,13 @@
 access to the controls. The underlying buffer can be accessed with 
 VideoBuffer::root_buffer().
 
+Threre are also several pseudo buffers (such as deinterlacing and colorspace
+conversion) which are chained to other buffers by taking a URL as an argument.
+
 The url syntax is the following:
 @verbatim
 url             := protocol ':' [ '[' options ']' ] // identifier
-protocol := "files" | "file" | "v4l2" | "v4l1" | "jpegstream" | "dc1394" | 
"qt" | "colourspace"
+protocol := "files" | "file" | "v4l2" | "v4l1" | "jpegstream" | "dc1394" | 
"qt" | "colourspace" | "deinterlace"
 options  := option [ ',' options ]
 option  := name [ '=' value ]
 @endverbatim
@@ -494,6 +526,12 @@
 'jpegstream' protocol (ServerPushJpegBuffer): identifier is path to file
          read_ahead  [= <number>] (default is 50 if specified without value)
 
+'deinterlace' protcol (DeinterlaceBuffer): identifier is a video URL
+      oddonly  [ = <bool> ]
+      evenonly [ = <bool> ]
+      oddeven  [ = <bool> ]
+      evenodd  [ = <bool> ]
+
 'colourspace' protcol (ColourspaceBuffer): identifier is a video URL
       from = byte | mono | gray | grey | yuv411 | yuv422 | rgb<byte> 
                 | rgb | bayer_bggr | bayer_gbrg | bayer_grbg | bayer_rggb  
(default mono)

Index: cvd/deinterlacebuffer.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/deinterlacebuffer.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- cvd/deinterlacebuffer.h     2 Dec 2008 17:30:39 -0000       1.9
+++ cvd/deinterlacebuffer.h     2 Sep 2011 12:26:32 -0000       1.10
@@ -19,9 +19,8 @@
     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
 // PAS 17/6/04 (revised 16/2/05)
-
-#ifndef __CVD_DEINTERLACEBUFFER_H
-#define __CVD_DEINTERLACEBUFFER_H
+#ifndef CVD_INCLUDE_DEINTERLACEBUFFER_H
+#define CVD_INCLUDE_DEINTERLACEBUFFER_H
 
 #include <cvd/videobuffer.h>
 #include <cvd/deinterlaceframe.h>
@@ -73,23 +72,27 @@
 /// CVD::Exceptions::DeinterlaceBuffer
 /// @param T The pixel type of the original VideoBuffer
 /// @ingroup gVideoBuffer
-template <typename T>
-class DeinterlaceBuffer : public VideoBuffer<T>
+
+/// Used to select which fields, and in which order, to extract from the frame
+struct DeinterlaceBufferFields
 {
-       public:
-               /// Used to select which fields, and in which order, to extract 
from the frame
                enum Fields{
                        OddOnly, ///< Odd fields only
                        EvenOnly, ///< Even fields only
                        OddEven, ///< Both fields, presenting the odd lines 
from each frame first 
                        EvenOdd ///< Both fields, presenting the even lines 
from each frame first
                }; 
+};
                
+template <typename T>
+class DeinterlaceBuffer : public VideoBuffer<T>
+{
        public:
+               typedef DeinterlaceBufferFields Fields;
                /// Construct a DeinterlaceBuffer by wrapping it around another 
VideoBuffer
                /// @param buf The buffer that will provide the raw frames
                /// @param fields The fields to 
-               DeinterlaceBuffer(CVD::VideoBuffer<T>& buf, Fields fields = 
OddEven);
+               DeinterlaceBuffer(CVD::VideoBuffer<T>& buf, Fields::Fields 
fields = Fields::OddEven);
  
                /// The size of the VideoFrames returns by this buffer. This 
will be half the 
                /// height of the original frames.
@@ -110,7 +113,7 @@
                /// buffer's rate.
                virtual double frame_rate()
                {
-                       if(m_fields == OddOnly || m_fields == EvenOnly)
+                       if(m_fields == Fields::OddOnly || m_fields == 
Fields::EvenOnly)
                                return m_vidbuf.frame_rate();
                        else
                                return m_vidbuf.frame_rate() * 2.0;
@@ -119,7 +122,7 @@
    private:
                CVD::VideoFrame<T>* my_realframe;
                CVD::VideoBuffer<T>& m_vidbuf;
-               Fields m_fields;
+               Fields::Fields m_fields;
                bool m_loadnewframe;
                ImageRef m_size;
                unsigned int m_linebytes;
@@ -129,7 +132,7 @@
 // CONSTRUCTOR
 //
 template <typename T>
-DeinterlaceBuffer<T>::DeinterlaceBuffer(CVD::VideoBuffer<T>& vidbuf, Fields 
fields) :
+DeinterlaceBuffer<T>::DeinterlaceBuffer(CVD::VideoBuffer<T>& vidbuf, 
Fields::Fields fields) :
        VideoBuffer<T>(vidbuf.type()),
        m_vidbuf(vidbuf),
        m_fields(fields),
@@ -165,9 +168,9 @@
        
        T* data = new T[m_size.x * m_size.y];
        DeinterlaceFrame<T>* frame = new DeinterlaceFrame<T>(time, data, 
m_size);
-       if(m_fields == OddOnly || 
-               (m_fields == OddEven && m_loadnewframe) ||
-               (m_fields == EvenOdd && !m_loadnewframe))
+       if(m_fields == Fields::OddOnly || 
+               (m_fields == Fields::OddEven && m_loadnewframe) ||
+               (m_fields == Fields::EvenOdd && !m_loadnewframe))
        {
                // We want the odd field
                CVD::byte* podd = reinterpret_cast<CVD::byte*>(frame->data());
@@ -193,7 +196,7 @@
        }
        frame->real_frame = my_realframe;
        
-       if(m_fields == OddEven || m_fields == EvenOdd)
+       if(m_fields == Fields::OddEven || m_fields == Fields::EvenOdd)
        {
                // If we're taking both fields, we only load a frame every 
other field
                m_loadnewframe = !m_loadnewframe;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]