Basic Image AlgorithmS Library 2.8.0

VideoSource_DCAM_XB3.cpp

00001 /*
00002 This file is part of the BIAS library (Basic ImageAlgorithmS).
00003 
00004 Copyright (C) 2003-2009    (see file CONTACT for details)
00005   Multimediale Systeme der Informationsverarbeitung
00006   Institut fuer Informatik
00007   Christian-Albrechts-Universitaet Kiel
00008 
00009 
00010 BIAS is free software; you can redistribute it and/or modify
00011 it under the terms of the GNU Lesser General Public License as published by
00012 the Free Software Foundation; either version 2.1 of the License, or
00013 (at your option) any later version.
00014 
00015 BIAS is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU Lesser General Public License for more details.
00019 
00020 You should have received a copy of the GNU Lesser General Public License
00021 along with BIAS; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 */
00024 
00025 #include "VideoSource_DCAM_XB3.hh"
00026 
00027 #ifdef WIN32
00028 
00029 #include <wtypes.h>
00030 #include <1394Camera.h>
00031 #include <Base/Debug/TimeMeasure.hh>
00032 #include <Base/Image/ImageConvert.hh>
00033 #include <Base/Image/ImageIO.hh>
00034 
00035 #else
00036 
00037 #include <dc1394/control.h>
00038 
00039 #include "sys/time.h"
00040 #include "unistd.h"
00041 #include <sys/stat.h>
00042 
00043 #endif // WIN32
00044 
00045 #define WIDTH 1280
00046 #define HEIGHT 960
00047 #define WIDTH_S 640
00048 #define HEIGHT_S 480
00049 
00050 using namespace BIAS;
00051 using namespace std;
00052 
00053 int j = 0;
00054 
00055 
00056 VideoSource_DCAM_XB3::VideoSource_DCAM_XB3(int Card): VideoSource_DCAM(Card)
00057 {
00058 }
00059 
00060 int VideoSource_DCAM_XB3::GrabSingle(Camera <unsigned char> &allImages,
00061                                      Camera <unsigned char> &imageLeft,
00062                                      Camera <unsigned char> &imageMiddle,
00063                                      Camera <unsigned char> &imageRight)
00064 {
00065   // fetch complete image from cam
00066   VideoSource_DCAM::GrabSingle(allImages);
00067 
00068   // create 3 images out of source image
00069   unsigned char* grabedPixels = allImages.GetImageData();
00070   unsigned char* sinkPixels = NULL;
00071   bool skip;
00072 
00073   for(unsigned int j=0; j<3; j++)
00074   {
00075     switch(j)
00076     {
00077       case 0:
00078         if(!imageRight.IsEmpty())
00079         {
00080           sinkPixels = imageRight.GetImageData();
00081           skip = false;
00082         }
00083         else
00084         {
00085 //          cout<<"\tEmpty image given: skip right image"<<endl;
00086           skip = true;
00087         }
00088         break;
00089       case 1:
00090         if(!imageMiddle.IsEmpty())
00091         {
00092           sinkPixels = imageMiddle.GetImageData();
00093           skip = false;
00094         }
00095         else
00096         {
00097 //          cout<<"\tEmpty image given: skip middle image"<<endl;
00098           skip = true;
00099         }
00100         break;
00101       case 2:
00102         if(!imageLeft.IsEmpty())
00103         {
00104           sinkPixels = imageLeft.GetImageData();
00105           skip = false;
00106         }
00107         else
00108         {
00109 //          cout<<"\tEmpty image given: skip left image"<<endl;
00110           skip = true;
00111         }
00112         break;
00113       default:
00114         skip = true;
00115         break;
00116     }
00117     if(!skip)
00118     {
00119       int
00120         size = WIDTH*HEIGHT;
00121       for(int index = 0; index < size; index++)
00122       {
00123         sinkPixels[index] = grabedPixels[index*3 + j];
00124       }
00125     }
00126   }
00127   return 0;
00128 }
00129 
00130 
00131 int VideoSource_DCAM_XB3::GrabSingleAsSmallRGB(Camera <unsigned char> &allImages,
00132                                      Camera <unsigned char> &imageLeft,
00133                                      Camera <unsigned char> &imageMiddle,
00134                                      Camera <unsigned char> &imageRight)
00135 {
00136   // fetch complete image from cam
00137   VideoSource_DCAM::GrabSingle(allImages);
00138 
00139   // create 3 images out of source image
00140   unsigned char* grabedPixels = allImages.GetImageData();
00141   unsigned char* sinkPixels = NULL;
00142   bool skip;
00143 
00144   for(unsigned int j=0; j<3; j++)
00145   {
00146     switch(j)
00147     {
00148       case 0:
00149         if(!imageRight.IsEmpty())
00150         {
00151           sinkPixels = imageRight.GetImageData();
00152           skip = false;
00153         }
00154         else
00155         {
00156 //          cout<<"\tEmpty image given: skip right image"<<endl;
00157           skip = true;
00158         }
00159         break;
00160       case 1:
00161         if(!imageMiddle.IsEmpty())
00162         {
00163           sinkPixels = imageMiddle.GetImageData();
00164           skip = false;
00165         }
00166         else
00167         {
00168 //          cout<<"\tEmpty image given: skip middle image"<<endl;
00169           skip = true;
00170         }
00171         break;
00172       case 2:
00173         if(!imageLeft.IsEmpty())
00174         {
00175           sinkPixels = imageLeft.GetImageData();
00176           skip = false;
00177         }
00178         else
00179         {
00180 //          cout<<"\tEmpty image given: skip left image"<<endl;
00181           skip = true;
00182         }
00183         break;
00184       default:
00185         skip = true;
00186         break;
00187     }
00188     if(!skip)
00189     {
00190       const int
00191         offsetR = WIDTH*3,
00192         offsetB = 3;
00193       int
00194         index = 0,
00195         indexG = j;
00196       for(int j = 0; j < HEIGHT_S; j++)
00197       {
00198         for(int i = 0; i < WIDTH_S; i++)
00199         {
00200           // R
00201           sinkPixels[index++] = grabedPixels[indexG+offsetR];
00202           // G
00203           sinkPixels[index++] = grabedPixels[indexG];
00204           // B
00205           sinkPixels[index++] = grabedPixels[indexG+offsetB];
00206           indexG += 6;
00207         }
00208         indexG += offsetR;
00209       }
00210     }
00211   }
00212   return 0;
00213 }
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends