• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

src/F2/Shot.cpp

00001 #include <algorithm>
00002 
00003 #include "FCam/F2/Shot.h"
00004 #include "FCam/F2/Sensor.h"
00005 
00006 #include "../Debug.h"
00007 #include "linux/mt9p031.h"
00008 
00009 
00010 namespace FCam{ namespace F2{
00011 
00012     Shot::Shot(): FCam::Shot(), 
00013                   rowSkip(RowSkip::none), colSkip(ColSkip::none),
00014                   rowBin(RowBin::none), colBin(ColBin::none),
00015                   roiCentered(false), roiStartX(0), roiStartY(0)
00016     {
00017     }
00018 
00019     Shot::Shot(const FCam::Shot &shot): FCam::Shot(shot) {
00020         // Need to create a F2::Shot from a base FCam::Shot.
00021         // Assume the entire image frame is desired.
00022         roiRegionSmaller(Sensor::activeArrayRect());
00023     }
00024 
00025     Shot::Shot(const Shot &other): FCam::Shot(static_cast<const FCam::Shot&>(other)),
00026                                    rowSkip(other.rowSkip),
00027                                    colSkip(other.colSkip),
00028                                    rowBin(other.rowBin),
00029                                    colBin(other.colBin),
00030                                    roiCentered(other.roiCentered),
00031                                    roiStartX(other.roiStartX),
00032                                    roiStartY(other.roiStartY)
00033     {
00034         // The FCam::Shot constructor should have taken care of the id increment,
00035         // all other fields are considered valid
00036     }
00037 
00038     const Shot &Shot::operator=(const FCam::Shot &other) {        
00039         FCam::Shot::operator=(other);
00040         // Assume the entire image frame is desired.
00041         roiRegionSmaller(Sensor::activeArrayRect());
00042 
00043         return *this;
00044     }
00045 
00046     const Shot &Shot::operator=(const Shot &other) {
00047         FCam::Shot::operator=(static_cast<const FCam::Shot&>(other));
00048         
00049         rowSkip = other.rowSkip;
00050         colSkip = other.colSkip;
00051         rowBin = other.rowBin;
00052         colBin = other.colBin;
00053 
00054         roiCentered = other.roiCentered;
00055         roiStartX = other.roiStartX;
00056         roiStartY = other.roiStartY;
00057 
00058         return *this;
00059     }
00060 
00061     void Shot::roiRegionSmaller(const Rect &maxRegion, bool useBinning) {
00062         // Won't take real pixel array limits into account here, just the current requested size
00063 
00064         int scaleX = maxRegion.width / image.width();  // Truncate down to be smaller than requested
00065         int scaleY = maxRegion.height / image.height();
00066 
00067         scaleX = std::max(1, std::min(scaleX, 7));
00068         scaleY = std::max(1, std::min(scaleY, 8));
00069 
00070         colSkip = static_cast<ColSkip::e>(scaleX);
00071         rowSkip = static_cast<RowSkip::e>(scaleY);
00072         
00073         if (useBinning) {
00074             int binX = std::max(1, std::min(scaleX, 4));
00075             int binY = std::max(1, std::min(scaleY, 4));
00076 
00077             if (binX == 3) binX = 2;
00078 
00079             colBin = static_cast<ColBin::e>(binX);
00080             rowBin = static_cast<RowBin::e>(binY);
00081         } else {
00082             colBin = ColBin::none;
00083             rowBin = RowBin::none;
00084         }
00085 
00086         roiCentered = false;
00087         roiStartX = maxRegion.x;
00088         roiStartY = maxRegion.y;               
00089     }
00090 
00091     void Shot::roiRegionSmaller(const Size &maxSize, bool useBinning) {
00092         FCam::Rect region(0,0, maxSize.width, maxSize.height);
00093         roiRegionSmaller(region, useBinning);
00094     }
00095 
00096     void Shot::roiRegionLarger(const Rect &minRegion, bool useBinning) {
00097         // Won't take real pixel array limits into account here, just the current requested size
00098 
00099         int scaleX = (minRegion.width / image.width()) + 1;  // Round up to be larger than requested
00100         int scaleY = (minRegion.height / image.height()) + 1;
00101 
00102         scaleX = std::max(1, std::min(scaleX, 7));
00103         scaleY = std::max(1, std::min(scaleY, 8));
00104 
00105         colSkip = static_cast<ColSkip::e>(scaleX);
00106         rowSkip = static_cast<RowSkip::e>(scaleY);
00107 
00108         if (useBinning) {
00109             int binX = std::max(1, std::min(scaleX, 4));
00110             int binY = std::max(1, std::min(scaleY, 4));
00111 
00112             if (binX == 3) {
00113                 binX = 4;  // Round up to ensure region is larger than requested
00114                 colSkip = ColSkip::x4; // Skip must at least equal bin
00115             }
00116 
00117             colBin = static_cast<ColBin::e>(binX);
00118             rowBin = static_cast<RowBin::e>(binY);
00119         } else {
00120             colBin = ColBin::none;
00121             rowBin = RowBin::none;
00122         }
00123 
00124         roiCentered = false;
00125         roiStartX = minRegion.x;
00126         roiStartY = minRegion.y;
00127     }
00128 
00129     void Shot::roiRegionLarger(const Size &minSize, bool useBinning) {
00130         FCam::Rect region(0,0, minSize.width, minSize.height);
00131         roiRegionLarger(region, useBinning);
00132     }
00133 
00134 }}

Generated on Mon Aug 16 2010 14:25:45 for FCam by  doxygen 1.7.1