00001 #include <pthread.h>
00002
00003 #include "FCam/Shot.h"
00004 #include "FCam/Action.h"
00005 #include "FCam/Sensor.h"
00006
00007 #include "Debug.h"
00008
00009
00010 namespace FCam {
00011
00012 pthread_mutex_t Shot::_idLock = PTHREAD_MUTEX_INITIALIZER;
00013 int Shot::_id = 0;
00014
00015 Shot::Shot(): exposure(0), frameTime(0), gain(0), whiteBalance(5000) {
00016 pthread_mutex_lock(&_idLock);
00017 id = ++_id;
00018 pthread_mutex_unlock(&_idLock);
00019
00020
00021 wanted = true;
00022
00023 };
00024
00025 Shot::~Shot() {
00026 clearActions();
00027 }
00028
00029 void Shot::clearActions() {
00030 for (std::set<Action *>::iterator i = _actions.begin();
00031 i != _actions.end(); i++) {
00032 delete *i;
00033 }
00034 _actions.clear();
00035 }
00036
00037 void Shot::addAction(const Action &action) {
00038 _actions.insert(action.copy());
00039 }
00040
00041 Shot::Shot(const Shot &other) :
00042 image(other.image),
00043 exposure(other.exposure),
00044 frameTime(other.frameTime),
00045 gain(other.gain),
00046 whiteBalance(other.whiteBalance),
00047 histogram(other.histogram),
00048 sharpness(other.sharpness),
00049 wanted(other.wanted),
00050 _colorMatrix(other._colorMatrix) {
00051
00052 pthread_mutex_lock(&_idLock);
00053 id = ++_id;
00054 pthread_mutex_unlock(&_idLock);
00055
00056 clearActions();
00057
00058 for (std::set<Action *>::iterator i = other._actions.begin();
00059 i != other._actions.end(); i++) {
00060 Action *a = (*i)->copy();
00061 _actions.insert(a);
00062 }
00063 };
00064
00065
00066 void Shot::setColorMatrix(const float *m) {
00067 if (!m) {
00068 clearColorMatrix();
00069 return;
00070 }
00071 _colorMatrix.resize(12);
00072 for (int i = 0; i < 12; i++) { _colorMatrix[i] = m[i]; }
00073 }
00074
00075 void Shot::clearColorMatrix() {
00076 _colorMatrix.clear();
00077 }
00078
00079 const Shot &Shot::operator=(const Shot &other) {
00080 clearActions();
00081
00082 for (std::set<Action *>::iterator i = other._actions.begin();
00083 i != other._actions.end(); i++) {
00084 Action *a = (*i)->copy();
00085 _actions.insert(a);
00086 }
00087
00088 pthread_mutex_lock(&_idLock);
00089 id = ++_id;
00090 pthread_mutex_unlock(&_idLock);
00091
00092 exposure = other.exposure;
00093 frameTime = other.frameTime;
00094 whiteBalance = other.whiteBalance;
00095 gain = other.gain;
00096 histogram = other.histogram;
00097 sharpness = other.sharpness;
00098 image = other.image;
00099 wanted = other.wanted;
00100 _colorMatrix = other._colorMatrix;
00101
00102 return *this;
00103 }
00104 };