VCCapture.cpp
Go to the documentation of this file.
00001 // ****************************************************************************
00002 // This file is part of the Integrating Vision Toolkit (IVT).
00003 //
00004 // The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
00005 // (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
00006 //
00007 // Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
00008 // All rights reserved.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are met:
00012 //
00013 // 1. Redistributions of source code must retain the above copyright
00014 //    notice, this list of conditions and the following disclaimer.
00015 //
00016 // 2. Redistributions in binary form must reproduce the above copyright
00017 //    notice, this list of conditions and the following disclaimer in the
00018 //    documentation and/or other materials provided with the distribution.
00019 //
00020 // 3. Neither the name of the KIT nor the names of its contributors may be
00021 //    used to endorse or promote products derived from this software
00022 //    without specific prior written permission.
00023 //
00024 // THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
00025 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00026 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027 // DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
00028 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00029 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00031 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00033 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 // ****************************************************************************
00035 // ****************************************************************************
00036 // Filename:  VCCapture.cpp
00037 // Author:    Moritz Hassert
00038 // Date:      2008
00039 // ****************************************************************************
00040 
00041 
00042 // ****************************************************************************
00043 // Includes
00044 // ****************************************************************************
00045 
00046 #include <new> // for explicitly using correct new/delete operators on VC DSPs
00047 
00048 #include "Helpers/helpers.h"
00049 
00050 #define NEW_IMAGE_VAR
00051 #include <vcrt.h>
00052 #include <macros.h>
00053 #include <sysvar.h>
00054 
00055 #include "VCCapture.h"
00056 
00057 #include <algorithm>
00058 
00059 
00060 
00061 // ****************************************************************************
00062 // Constructor / Destructor
00063 // ****************************************************************************
00064 
00065 CVCCapture::CVCCapture() : m_width(ScrGetColumns), m_height(ScrGetRows), m_pitch(ScrGetPitch)
00066 {
00067 }
00068 
00069 CVCCapture::~CVCCapture()
00070 {
00071         CloseCamera();
00072 }
00073 
00074 
00075 // ****************************************************************************
00076 // Methods
00077 // ****************************************************************************
00078 
00079 bool CVCCapture::OpenCamera()
00080 {
00081         //no cyclic image aquisition, keep current overlay status
00082         vmode( getvar(OVLY_ACTIVE) ? vmOvlStill : vmStill);
00083         tpwait(); //wait for vmode change. else first call to tpp() may fail
00084         return true;
00085 }
00086 
00087 void CVCCapture::CloseCamera()
00088 {
00089         //restore live mode, keep current overlay status
00090         //setvar(IMODE, 0); does not work. WHY?
00091         vmode( getvar(OVLY_ACTIVE) ? vmOvlLive : vmLive);
00092 }
00093 
00094 bool CVCCapture::CaptureImage(CByteImage ** ppImages)
00095 {
00096         //TODO: allow background image capture
00097         if (tpp() == -1)
00098                 return false;
00099 
00100         //get the capture buffer address here and not in constructor as someone might have changed the location
00101         unsigned char* restrict scr_pixels = (unsigned char*) ScrGetCaptPage;
00102         unsigned char* restrict img_pixels = ppImages[0]->pixels;
00103         
00104         int h = std::min(m_height, ppImages[0]->height);
00105         int w = std::min(m_width,  ppImages[0]->width);
00106 
00107         //copy row by row as width may differ and pitch most likely will
00108         for (int row=0; row<h; row++) {
00109                 std::copy(scr_pixels, scr_pixels+w, img_pixels);
00110 
00111                 scr_pixels += m_pitch;
00112                 img_pixels += ppImages[0]->width;
00113         }
00114 
00115         return true;
00116 }
00117 
00118 int CVCCapture::GetWidth()
00119 {
00120         return m_width;
00121 }
00122 
00123 int CVCCapture::GetHeight()
00124 {
00125         return m_height;
00126 }
00127 
00128 CByteImage::ImageType CVCCapture::GetType()
00129 {
00130         //TODO: what about rgb vc cams?
00131         return CByteImage::eGrayScale;
00132 }
00133 
00134 int CVCCapture::GetNumberOfCameras()
00135 {
00136         return 1;
00137 }


asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Thu Jun 6 2019 21:46:58