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
00021
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
00035
00036 }
00037
00038 const Shot &Shot::operator=(const FCam::Shot &other) {
00039 FCam::Shot::operator=(other);
00040
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
00063
00064 int scaleX = maxRegion.width / image.width();
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
00098
00099 int scaleX = (minRegion.width / image.width()) + 1;
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;
00114 colSkip = ColSkip::x4;
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 }}