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 {
00011 namespace F2 {
00012
00013 Shot::Shot(): FCam::Shot(),
00014 rowSkip(RowSkip::none), colSkip(ColSkip::none),
00015 rowBin(RowBin::none), colBin(ColBin::none),
00016 roiCentered(false), roiStartX(0), roiStartY(0) {
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 const Shot &Shot::operator=(const FCam::Shot &other) {
00038 FCam::Shot::operator=(other);
00039
00040 roiRegionSmaller(Sensor::activeArrayRect());
00041
00042 return *this;
00043 }
00044
00045 const Shot &Shot::operator=(const Shot &other) {
00046 FCam::Shot::operator=(static_cast<const FCam::Shot &>(other));
00047
00048 rowSkip = other.rowSkip;
00049 colSkip = other.colSkip;
00050 rowBin = other.rowBin;
00051 colBin = other.colBin;
00052
00053 roiCentered = other.roiCentered;
00054 roiStartX = other.roiStartX;
00055 roiStartY = other.roiStartY;
00056
00057 return *this;
00058 }
00059
00060 void Shot::roiRegionSmaller(const Rect &maxRegion, bool useBinning) {
00061
00062
00063 int scaleX = maxRegion.width / image.width();
00064 int scaleY = maxRegion.height / image.height();
00065
00066 scaleX = std::max(1, std::min(scaleX, 7));
00067 scaleY = std::max(1, std::min(scaleY, 8));
00068
00069 colSkip = static_cast<ColSkip::e>(scaleX);
00070 rowSkip = static_cast<RowSkip::e>(scaleY);
00071
00072 if (useBinning) {
00073 int binX = std::max(1, std::min(scaleX, 4));
00074 int binY = std::max(1, std::min(scaleY, 4));
00075
00076 if (binX == 3) { binX = 2; }
00077
00078 colBin = static_cast<ColBin::e>(binX);
00079 rowBin = static_cast<RowBin::e>(binY);
00080 } else {
00081 colBin = ColBin::none;
00082 rowBin = RowBin::none;
00083 }
00084
00085 roiCentered = false;
00086 roiStartX = maxRegion.x;
00087 roiStartY = maxRegion.y;
00088 }
00089
00090 void Shot::roiRegionSmaller(const Size &maxSize, bool useBinning) {
00091 FCam::Rect region(0,0, maxSize.width, maxSize.height);
00092 roiRegionSmaller(region, useBinning);
00093 }
00094
00095 void Shot::roiRegionLarger(const Rect &minRegion, bool useBinning) {
00096
00097
00098 int scaleX = (minRegion.width / image.width()) + 1;
00099 int scaleY = (minRegion.height / image.height()) + 1;
00100
00101 scaleX = std::max(1, std::min(scaleX, 7));
00102 scaleY = std::max(1, std::min(scaleY, 8));
00103
00104 colSkip = static_cast<ColSkip::e>(scaleX);
00105 rowSkip = static_cast<RowSkip::e>(scaleY);
00106
00107 if (useBinning) {
00108 int binX = std::max(1, std::min(scaleX, 4));
00109 int binY = std::max(1, std::min(scaleY, 4));
00110
00111 if (binX == 3) {
00112 binX = 4;
00113 colSkip = ColSkip::x4;
00114 }
00115
00116 colBin = static_cast<ColBin::e>(binX);
00117 rowBin = static_cast<RowBin::e>(binY);
00118 } else {
00119 colBin = ColBin::none;
00120 rowBin = RowBin::none;
00121 }
00122
00123 roiCentered = false;
00124 roiStartX = minRegion.x;
00125 roiStartY = minRegion.y;
00126 }
00127
00128 void Shot::roiRegionLarger(const Size &minSize, bool useBinning) {
00129 FCam::Rect region(0,0, minSize.width, minSize.height);
00130 roiRegionLarger(region, useBinning);
00131 }
00132
00133 }
00134 }