grab_v4l.C

Go to the documentation of this file.
00001 /* Gnome gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  *
00005  * Gxsm Hardware Interface Plugin Name: grab_v4l.C
00006  * ===============================================
00007  * 
00008  * Copyright (C) 1999 The Free Software Foundation
00009  *
00010  * Authors: Percy Zahl <zahl@fkp.uni-hannover.de>
00011  * additional features: Andreas Klust <klust@fkp.uni-hannover.de>
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00026  */
00027 
00028 
00029 /* Please do not change the Begin/End lines of this comment section!
00030  * this is a LaTeX style section used for auto generation of the PlugIn Manual 
00031  * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks!
00032  * All "% PlugInXXX" commentary tags are mandatory
00033  * All "% OptPlugInXXX" tags are optional and can be removed or commented in
00034  * --------------------------------------------------------------------------------
00035 % BeginPlugInDocuSection
00036 % PlugInDocuCaption: Video4Linux Grabber (experimental, to be ported)
00037 % PlugInName: grab_v4l
00038 % PlugInAuthor: Percy Zahl
00039 % PlugInAuthorEmail: zahl@users.sf.net
00040 % PlugInMenuPath: Hardware/video4linux-HwI
00041 
00042 % PlugInDescription
00043 This is an experimental hardware interface plugin.
00044 Grabbing video data using the Video4Linux (v4l) device.
00045 
00046 It's using v4l, so set Hardware/Device to the desired /dev/videoXX device!
00047 
00048 % PlugInUsage
00049 Set the \GxsmPref{Hardware}{Card} to ''grab\_v4l''.
00050 
00051 % OptPlugInSources
00052 v4l device, i.e. (S)-Video/TV/\dots
00053 
00054 % OptPlugInDest
00055 Usual scan destination channel.
00056 
00057 % OptPlugInNote
00058 Experimental.
00059 
00060 % EndPlugInDocuSection
00061  * -------------------------------------------------------------------------------- 
00062  */
00063 
00064 #include "config.h"
00065 #include "gxsm/plugin.h"
00066 #include "gxsm/xsmhard.h"
00067 
00068 // Define HwI PlugIn reference name here, this is what is listed later within "Preferenced Dialog"
00069 // i.e. the string selected for "Hardware/Card"!
00070 #define THIS_HWI_PLUGIN_NAME "video4linux"
00071 
00072 // Plugin Prototypes
00073 static void grab_v4l_init( void );
00074 static void grab_v4l_about( void );
00075 static void grab_v4l_configure( void );
00076 static void grab_v4l_cleanup( void );
00077 
00078 extern "C" gint gxsm_v4l_open_video4l ();
00079 extern "C" gint gxsm_v4l_close_video4l ();
00080 extern "C" gint gxsm_v4l_maxwidth  ();
00081 extern "C" gint gxsm_v4l_maxheight ();
00082 extern "C" gint gxsm_v4l_win_width  ();
00083 extern "C" gint gxsm_v4l_win_height ();
00084 extern "C" gint gxsm_v4l_grab_video4l ();
00085 extern "C" gint gxsm_v4l_get_pixel (int *r, int *g, int *b);
00086 
00087 // Fill in the GxsmPlugin Description here
00088 GxsmPlugin grab_v4l_pi = {
00089   NULL,                   // filled in and used by Gxsm, don't touch !
00090   NULL,                   // filled in and used by Gxsm, don't touch !
00091   0,                      // filled in and used by Gxsm, don't touch !
00092   NULL,                   // The Gxsm-App Class Ref.pointer (called "gapp" in Gxsm) is 
00093                           // filled in here by Gxsm on Plugin load, 
00094                           // just after init() is called !!!
00095   // ----------------------------------------------------------------------
00096   // Plugins Name, CodeStly is like: Name-M1S|M2S-BG|F1D|F2D|ST|TR|Misc
00097   "grab_v4l-"
00098   "HW-INT-1S-RGB",
00099   // Plugin's Category - used to autodecide on Pluginloading or ignoring
00100   // In this case of Hardware-Interface-Plugin here is the interface-name required
00101   // this is the string selected for "Hardware/Card"!
00102   THIS_HWI_PLUGIN_NAME,
00103   // Description, is shown by PluginViewer (Plugin: listplugin, Tools->Plugin Details)
00104   "Video for Linux interface.",                   
00105   // Author(s)
00106   "Percy Zahl",
00107   // Menupath to position where it is appendet to -- not used by HwI PIs
00108   N_("Hardware/"),
00109   // Menuentry -- not used by HwI PIs
00110   N_(THIS_HWI_PLUGIN_NAME"-HwI"),
00111   // help text shown on menu
00112   N_("This is a "THIS_HWI_PLUGIN_NAME" - GXSM Hardware Interface"),
00113   // more info...
00114   "N/A",
00115   NULL,          // error msg, plugin may put error status msg here later
00116   NULL,          // Plugin Status, managed by Gxsm, plugin may manipulate it too
00117   // init-function pointer, can be "NULL", 
00118   // called if present at plugin load
00119   grab_v4l_init,  
00120   // query-function pointer, can be "NULL", 
00121   // called if present after plugin init to let plugin manage it install itself
00122   NULL, // query should be "NULL" for Gxsm-Math-Plugin !!!
00123   // about-function, can be "NULL"
00124   // can be called by "Plugin Details"
00125   grab_v4l_about,
00126   // configure-function, can be "NULL"
00127   // can be called by "Plugin Details"
00128   grab_v4l_configure,
00129   // run-function, can be "NULL", if non-Zero and no query defined, 
00130   // it is called on menupath->"plugin"
00131   NULL, // run should be "NULL" for Gxsm-Math-Plugin !!!
00132   // cleanup-function, can be "NULL"
00133   // called if present at plugin removeal
00134   grab_v4l_cleanup
00135 };
00136 
00137 
00138 // Text used in Aboutbox, please update!!
00139 static const char *about_text = N_("GXSM grab_v4l Plugin\n\n"
00140                                    "Video for Linux frame grabber.");
00141 
00142 /* Here we go... */
00143 
00144 /*
00145  * GXSM V4L Hardware Interface Class
00146  * ============================================================
00147  */
00148 
00149 class gxsm_v4l : public XSM_Hardware{
00150 public:
00151         gxsm_v4l();
00152         virtual ~gxsm_v4l();
00153         
00154         virtual void PutParameter(void *src, int grp=0); /* universelle Parameterübergabe */
00155         virtual void ExecCmd(int Cmd);
00156         virtual int  WaitExec(int data);
00157         
00158         /* Parameter  */
00159         virtual long GetMaxPointsPerLine(){ return gxsm_v4l_maxwidth (); };
00160         virtual long GetMaxLines(){ return gxsm_v4l_maxheight (); };
00161         virtual long GetMaxChannels(){ return 1L; };
00162         virtual void SetDxDy(int dx, int dy);
00163         virtual void SetOffset(long x, long y);
00164         virtual void SetNx(long nx);
00165         virtual void SetAlpha(double alpha);
00166         
00167         virtual void MovetoXY(long x, long y);
00168         virtual void StartScan2D();
00169         virtual void ScanLineM(int yindex, int xdir, int muxmode, Mem2d *Mob[MAX_SRCS_CHANNELS], int ix0=0 );
00170         virtual void EndScan2D();
00171         virtual gchar* get_info(){ 
00172                 return g_strdup("*--GXSM HwI Plugin: v4l::XSM_Hardware --*\n"
00173                                 "video4linux on /dev/video0 is connected!\n"
00174                                 "*--Features--*\n"
00175                                 "SCAN: Yes\n"
00176                                 "*--ExecCMD options--*\n"
00177                                 "*--EOF--*\n"
00178                         );
00179         };
00180         
00181 private:
00182         DSP_Param dspPar;
00183 
00184 
00185 };
00186 
00187 /*
00188  * PI global
00189  */
00190 
00191 gxsm_v4l *v4l_hardware = NULL;
00192 
00193 /* Konstruktor: device open
00194  * ==================================================
00195  */
00196 gxsm_v4l::gxsm_v4l():XSM_Hardware(){
00197         // open device?? or just on demand?
00198         gxsm_v4l_open_video4l();        
00199 }
00200 
00201 /* Destruktor:
00202  * ==================================================
00203  * Hardware "abtrennen"
00204  */
00205 gxsm_v4l::~gxsm_v4l(){
00206         gxsm_v4l_close_video4l ();
00207 }
00208 
00209 /* Übergeordnete Parameterübergabefunktionen PC => PC31/DSP
00210  * ========================================================
00211  * virtual !
00212  */
00213 void gxsm_v4l::PutParameter(void *src, int grp){
00214 }
00215 
00216 void gxsm_v4l::ExecCmd(int Cmd){
00217 }
00218 int  gxsm_v4l::WaitExec(int data){ return 0; }
00219 void gxsm_v4l::MovetoXY(long x, long y){ rx=x; ry=y; }
00220 void gxsm_v4l::SetDxDy(int dx, int dy){  
00221   Dx = dx; 
00222   Dy = dy;
00223 }
00224 void gxsm_v4l::SetOffset(long x, long y){
00225   rotoffx = x; rotoffy = y;
00226 }
00227 void gxsm_v4l::SetAlpha(double alpha){ 
00228   Alpha=M_PI*alpha/180.;
00229   rotmyy = rotmxx = cos(Alpha);
00230   rotmyx = -(rotmxy = sin(Alpha));
00231 }
00232 void gxsm_v4l::SetNx(long nx){ 
00233   Nx=nx;
00234 }
00235 
00236 
00237 void gxsm_v4l::StartScan2D(){ 
00238         // Grab Frame from V4L
00239         gxsm_v4l_grab_video4l ();
00240 }
00241 
00242 void gxsm_v4l::EndScan2D(){ 
00243         ;
00244 }
00245 
00246 
00247 
00248 
00249 void gxsm_v4l::ScanLineM(int yindex, int xdir, int muxmode, Mem2d *Mob[MAX_SRCS_CHANNELS], int ix0 ){
00250         int r,g,b;
00251         if (yindex < 0){ // 2D capture
00252                 if (yindex != -1) return; // XP/XM init cycle
00253                 if(Mob[0])
00254                         for(int j=0; j < gxsm_v4l_win_height () && j<Mob[0]->GetNy (); j++){
00255                                 for(int i=0; i<gxsm_v4l_win_width  () && i < Mob[0]->GetNx (); i++)
00256                                         Mob[0]->PutDataPkt ((double)i*j, i, j);
00257                                 if(!(j%32))
00258                                         gapp->check_events();
00259                         }
00260                 return;
00261         }
00262 
00263         if(yindex >=  gxsm_v4l_win_height ()) 
00264                 return;
00265 
00266         if(Mob[0])
00267                 for(int i=0; i < gxsm_v4l_win_width () && i < Mob[0]->GetNx (); i++)
00268                         Mob[0]->PutDataPkt((double) gxsm_v4l_get_pixel (&r, &g, &b), i, yindex);
00269 
00270         if(!(yindex%32))
00271                 gapp->check_events();
00272 }
00273 
00274 
00275 /* 
00276  * PI essential members
00277  */
00278 
00279 // Symbol "get_gxsm_plugin_info" is resolved by dlsym from Gxsm, used to get Plugin's info!! 
00280 // Essential Plugin Function!!
00281 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00282   grab_v4l_pi.description = g_strdup_printf(N_("GXSM HwI grab_v4l plugin %s"), VERSION);
00283   return &grab_v4l_pi; 
00284 }
00285 
00286 // Symbol "get_gxsm_hwi_hardware_class" is resolved by dlsym from Gxsm for all HwI type PIs, 
00287 // Essential Plugin Function!!
00288 XSM_Hardware *get_gxsm_hwi_hardware_class ( void *data ) {
00289         return v4l_hardware;
00290 }
00291 
00292 // init-Function
00293 static void grab_v4l_init(void)
00294 {
00295         PI_DEBUG (DBG_L2, "grab_v4l Plugin Init");
00296         v4l_hardware = new gxsm_v4l ();
00297  }
00298 
00299 // about-Function
00300 static void grab_v4l_about(void)
00301 {
00302         const gchar *authors[] = { grab_v4l_pi.authors, NULL};
00303         gtk_widget_show(gnome_about_new ( grab_v4l_pi.name,
00304                                           VERSION,
00305                                           N_("(C) 2000 the Free Software Foundation"),
00306                                           about_text,
00307                                           authors,
00308                                           NULL, NULL, NULL
00309                                 ));
00310 }
00311 
00312 // configure-Function
00313 static void grab_v4l_configure(void)
00314 {
00315         if(grab_v4l_pi.app)
00316                 grab_v4l_pi.app->message("grab_v4l Plugin Configuration");
00317 }
00318 
00319 // cleanup-Function
00320 static void grab_v4l_cleanup(void)
00321 {
00322         PI_DEBUG (DBG_L2, "grab_v4l Plugin Cleanup");
00323         delete v4l_hardware;
00324         v4l_hardware = NULL;
00325 }
00326 
00327 
00328 

Generated on Sat Apr 1 09:04:15 2006 for GXSM by  doxygen 1.4.6