Index: trunk/ReleaseNotes
===================================================================
--- trunk/ReleaseNotes	(revision 123)
+++ trunk/ReleaseNotes	(revision 124)
@@ -1,4 +1,5 @@
 * Actual Version:
 
+- added lib/FlairCore/src/Semaphore.cpp
 - added fixed cameras in simulator, see $FLAIR_ROOT/flair-bin/models/indoor_fligh
 t_arena.xml for an exemple
Index: trunk/demos/OpticalFlow/uav/src/DemoOpticalFlow.cpp
===================================================================
--- trunk/demos/OpticalFlow/uav/src/DemoOpticalFlow.cpp	(revision 123)
+++ trunk/demos/OpticalFlow/uav/src/DemoOpticalFlow.cpp	(revision 124)
@@ -26,4 +26,5 @@
 #include <GroupBox.h>
 #include <DoubleSpinBox.h>
+#include <PushButton.h>
 #include <FrameworkManager.h>
 #include <MetaDualShock3.h>
@@ -49,51 +50,54 @@
 uav->GetVerticalCamera()->SetLogFormat(Camera::LogFormat::JPG);
 getFrameworkManager()->AddDeviceToLog(uav->GetVerticalCamera());
-    greyCameraImage=new CvtColor(uav->GetVerticalCamera(),"gray",CvtColor::Conversion_t::GRAY);
+	
+	startOpticalflow=new PushButton(GetButtonsLayout()->NewRow(),"start optical flow");
 
-    uav->GetVerticalCamera()->UseDefaultPlot(greyCameraImage->Output()); // Le defaultPlot de la caméra peut afficher n'importe quoi?
+	greyCameraImage=new CvtColor(uav->GetVerticalCamera(),"gray",CvtColor::Conversion_t::ToGray);
 
-    //optical flow stack
-    opticalFlow=new OpticalFlow(greyCameraImage,uav->GetVerticalCamera()->GetLayout()->NewRow(),"flux optique");
-    opticalFlowSpeed=new OpticalFlowSpeed(opticalFlow,"vitesse du flux optique");
+	uav->GetVerticalCamera()->UseDefaultPlot(greyCameraImage->Output()); // Le defaultPlot de la caméra peut afficher n'importe quoi?
 
-    cvmatrix_descriptor* desc=new cvmatrix_descriptor(2,1);
-    for(int i=0;i<2;i++) {
-        desc->SetElementName(i,0,opticalFlowSpeed->Output()->Name(i,0));
-    }
-    cvmatrix* prev_value=new cvmatrix((const Thread*)this,desc,floatType,uav->ObjectName()); // diamond inheritance
-    for(int i=0;i<2;i++) {
-        prev_value->SetValue(i,0,0);
-    }
+	//optical flow stack
+	opticalFlow=new OpticalFlow(greyCameraImage,uav->GetVerticalCamera()->GetLayout()->NewRow(),"flux optique");
+	opticalFlowSpeed=new OpticalFlowSpeed(opticalFlow,"vitesse du flux optique");
 
-    opticalFlowSpeedFiltered=new LowPassFilter(opticalFlowSpeed,uav->GetVerticalCamera()->GetLayout()->NewRow(),"passe bas",prev_value);
+	cvmatrix_descriptor* desc=new cvmatrix_descriptor(2,1);
+	for(int i=0;i<2;i++) {
+			desc->SetElementName(i,0,opticalFlowSpeed->Output()->Name(i,0));
+	}
+	cvmatrix* prev_value=new cvmatrix((const Thread*)this,desc,floatType,uav->ObjectName()); // diamond inheritance
+	for(int i=0;i<2;i++) {
+			prev_value->SetValue(i,0,0);
+	}
+
+	opticalFlowSpeedFiltered=new LowPassFilter(opticalFlowSpeed,uav->GetVerticalCamera()->GetLayout()->NewRow(),"passe bas",prev_value);
 // delete prev_value?
 
-    getFrameworkManager()->AddDeviceToLog(opticalFlowSpeed);
+	getFrameworkManager()->AddDeviceToLog(opticalFlowSpeed);
 
-    Tab* opticalFlowTab=new Tab(getFrameworkManager()->GetTabWidget(),"flux optique");
-    DataPlot1D* xVelocityPlot=new DataPlot1D(opticalFlowTab->NewRow(),"x_velocity",-5,5);
-    DataPlot1D* yVelocityPlot=new DataPlot1D(opticalFlowTab->LastRowLastCol(),"y_velocity",-5,5);
+	Tab* opticalFlowTab=new Tab(getFrameworkManager()->GetTabWidget(),"flux optique");
+	DataPlot1D* xVelocityPlot=new DataPlot1D(opticalFlowTab->NewRow(),"x_velocity",-5,5);
+	DataPlot1D* yVelocityPlot=new DataPlot1D(opticalFlowTab->LastRowLastCol(),"y_velocity",-5,5);
 
-    xVelocityPlot->AddCurve(opticalFlowSpeed->Output()->Element(0,0));
-    xVelocityPlot->AddCurve(opticalFlowSpeedFiltered->Matrix()->Element(0,0),DataPlot::Blue);
-    yVelocityPlot->AddCurve(opticalFlowSpeed->Output()->Element(1,0));
-    yVelocityPlot->AddCurve(opticalFlowSpeedFiltered->Matrix()->Element(1,0),DataPlot::Blue);
+	xVelocityPlot->AddCurve(opticalFlowSpeed->Output()->Element(0,0));
+	xVelocityPlot->AddCurve(opticalFlowSpeedFiltered->Matrix()->Element(0,0),DataPlot::Blue);
+	yVelocityPlot->AddCurve(opticalFlowSpeed->Output()->Element(1,0));
+	yVelocityPlot->AddCurve(opticalFlowSpeedFiltered->Matrix()->Element(1,0),DataPlot::Blue);
 
-    u_x=new Pid(setupLawTab->At(1,0),"u_x");
-    u_x->UseDefaultPlot(graphLawTab->NewRow());
-    u_y=new Pid(setupLawTab->At(1,1),"u_y");
-    u_y->UseDefaultPlot(graphLawTab->LastRowLastCol());
+	u_x=new Pid(setupLawTab->At(1,0),"u_x");
+	u_x->UseDefaultPlot(graphLawTab->NewRow());
+	u_y=new Pid(setupLawTab->At(1,1),"u_y");
+	u_y->UseDefaultPlot(graphLawTab->LastRowLastCol());
 
-    opticalFlowGroupBox=new GroupBox(GetJoystick()->GetTab()->NewRow(),"consignes fo");
-    maxXSpeed=new DoubleSpinBox(opticalFlowGroupBox->NewRow(),"debattement x"," m/s",-5,5,0.1,1);
-    maxYSpeed=new DoubleSpinBox(opticalFlowGroupBox->LastRowLastCol(),"debattement y"," m/s",-5,5,0.1,1);
+	opticalFlowGroupBox=new GroupBox(GetJoystick()->GetTab()->NewRow(),"consignes fo");
+	maxXSpeed=new DoubleSpinBox(opticalFlowGroupBox->NewRow(),"debattement x"," m/s",-5,5,0.1,1);
+	maxYSpeed=new DoubleSpinBox(opticalFlowGroupBox->LastRowLastCol(),"debattement y"," m/s",-5,5,0.1,1);
 
-    opticalFlowReference=new cvmatrix((const Thread*)this,2,1,floatType);
-    xVelocityPlot->AddCurve(opticalFlowReference->Element(0,0),DataPlot::Green,"consigne");
-    yVelocityPlot->AddCurve(opticalFlowReference->Element(1,0),DataPlot::Green,"consigne");
+	opticalFlowReference=new cvmatrix((const Thread*)this,2,1,floatType);
+	xVelocityPlot->AddCurve(opticalFlowReference->Element(0,0),DataPlot::Green,"consigne");
+	yVelocityPlot->AddCurve(opticalFlowReference->Element(1,0),DataPlot::Green,"consigne");
 
-    customReferenceOrientation= new AhrsData(this,"reference");
-    uav->GetAhrs()->AddPlot(customReferenceOrientation,DataPlot::Yellow);
-    AddDataToControlLawLog(customReferenceOrientation);
+	customReferenceOrientation= new AhrsData(this,"reference");
+	uav->GetAhrs()->AddPlot(customReferenceOrientation,DataPlot::Yellow);
+	AddDataToControlLawLog(customReferenceOrientation);
 }
 
@@ -107,4 +111,22 @@
 }
 
+void DemoOpticalFlow::StartOpticalFlow(void) {
+	if (SetOrientationMode(OrientationMode_t::Custom)) {
+			Thread::Info("(Re)entering optical flow mode\n");
+			u_x->Reset();
+			u_y->Reset();
+	} else {
+			Thread::Warn("Could not enter optical flow mode\n");
+	}
+}
+
+void DemoOpticalFlow::ExtraCheckPushButton(void) {
+	if(startOpticalflow->Clicked()) {
+        //StartOpticalFlow();
+				GetUav()->GetVerticalCamera()->SavePictureToFile("./toto.jpg");
+				
+	}
+}
+
 void DemoOpticalFlow::ExtraCheckJoystick(void) {
     static bool wasOpticalFlowModeButtonPressed=false;
@@ -113,11 +135,5 @@
         if (!wasOpticalFlowModeButtonPressed) {
             wasOpticalFlowModeButtonPressed=true;
-            if (SetOrientationMode(OrientationMode_t::Custom)) {
-                Thread::Info("(Re)entering optical flow mode\n");
-                u_x->Reset();
-                u_y->Reset();
-            } else {
-                Thread::Warn("Could not enter optical flow mode\n");
-            }
+            StartOpticalFlow();
         }
     } else {
Index: trunk/demos/OpticalFlow/uav/src/DemoOpticalFlow.h
===================================================================
--- trunk/demos/OpticalFlow/uav/src/DemoOpticalFlow.h	(revision 123)
+++ trunk/demos/OpticalFlow/uav/src/DemoOpticalFlow.h	(revision 124)
@@ -25,4 +25,5 @@
         class GroupBox;
         class DoubleSpinBox;
+        class PushButton;
     }
     namespace filter {
@@ -46,4 +47,5 @@
         void SignalEvent(Event_t event);
         void ExtraCheckJoystick(void);
+				void ExtraCheckPushButton(void);
         const flair::core::AhrsData *GetReferenceOrientation(void);
 
@@ -59,4 +61,6 @@
         flair::filter::OpticalFlow *opticalFlow;
         flair::filter::OpticalFlowSpeed *opticalFlowSpeed;
+				flair::gui::PushButton *startOpticalflow,*stopOpticalflow;
+				void StartOpticalFlow(void);
 };
 
Index: trunk/lib/FlairCore/src/cvimage.cpp
===================================================================
--- trunk/lib/FlairCore/src/cvimage.cpp	(revision 123)
+++ trunk/lib/FlairCore/src/cvimage.cpp	(revision 124)
@@ -36,5 +36,5 @@
       img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
       break;
-    case Type::Format::GRAY:
+    case Type::Format::Gray:
       img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
       break;
@@ -55,5 +55,5 @@
       img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 3);
       break;
-    case Type::Format::GRAY:
+    case Type::Format::Gray:
       img = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 1);
       break;
Index: trunk/lib/FlairCore/src/cvimage.h
===================================================================
--- trunk/lib/FlairCore/src/cvimage.h	(revision 123)
+++ trunk/lib/FlairCore/src/cvimage.h	(revision 124)
@@ -39,5 +39,5 @@
       UYVY, /*!< UYVY 16 bits */
       BGR,  /*!< BGR 24 bits */
-      GRAY, /*!< gray 8 bits */
+      Gray, /*!< gray 8 bits */
     };
     Type(uint16_t _width, uint16_t _height, Format _format)
@@ -47,5 +47,5 @@
       size_t pixelSize;
       switch (format) {
-      case Format::GRAY:
+      case Format::Gray:
         pixelSize = 1;
         break;
Index: trunk/lib/FlairSensorActuator/src/Camera.cpp
===================================================================
--- trunk/lib/FlairSensorActuator/src/Camera.cpp	(revision 123)
+++ trunk/lib/FlairSensorActuator/src/Camera.cpp	(revision 124)
@@ -116,10 +116,23 @@
 void Camera::ProcessUpdate(core::io_data* data) {
 	if(getFrameworkManager()->IsLogging() && getFrameworkManager()->IsDeviceLogged(this)) {
-		switch(logFormat) {
-			case LogFormat::JPG:
-					IplImage *img=((cvimage*)data)->img;
-					string filename=getFrameworkManager()->GetLogPath()+"/"+ObjectName()+"_"+std::to_string(data->DataTime())+".jpg";
-					saveToJpeg(img,filename);
-				break;
+		if(logFormat==LogFormat::JPG) {
+			data->GetMutex();
+			IplImage *img=((cvimage*)data)->img;
+			string filename=getFrameworkManager()->GetLogPath()+"/"+ObjectName()+"_"+std::to_string(data->DataTime())+".jpg";
+			switch(((cvimage*)data)->GetDataType().GetFormat()) {
+				case cvimage::Type::Format::Gray:
+					saveToJpeg(img,filename,PictureFormat_t::Gray,PictureFormat_t::Gray);
+					break;
+				case cvimage::Type::Format::BGR:
+					saveToJpeg(img,filename,PictureFormat_t::RGB,PictureFormat_t::RGB);
+					break;
+				case cvimage::Type::Format::UYVY:
+					saveToJpeg(img,filename,PictureFormat_t::UYVY,PictureFormat_t::UYVY);
+					break;
+				default:
+					Warn("cannot log to this format\n");
+					break;
+			}
+			data->ReleaseMutex();
 		}
 	}
@@ -127,5 +140,27 @@
 }
 
-void Camera::SaveToFile(string filename) const {
+void Camera::SavePictureToFile(std::string filename) const {
+	string::size_type idx = filename.rfind('.');
+
+	if(idx != std::string::npos) {
+		Printf("saving %s\n", filename.c_str());
+		std::string extension = filename.substr(idx+1);
+		
+		output->GetMutex();
+		if(extension=="jpg") {
+			if(output->GetDataType().GetFormat()==cvimage::Type::Format::Gray) saveToJpeg(output->img,filename,PictureFormat_t::Gray,PictureFormat_t::Gray);
+			if(output->GetDataType().GetFormat()==cvimage::Type::Format::BGR) saveToJpeg(output->img,filename,PictureFormat_t::RGB,PictureFormat_t::RGB);
+			if(output->GetDataType().GetFormat()==cvimage::Type::Format::UYVY) saveToJpeg(output->img,filename,PictureFormat_t::UYVY,PictureFormat_t::UYVY);
+		} else {
+			cvSaveImage(filename.c_str(),output->img);
+		}
+		output->ReleaseMutex();
+			
+	} else {
+		Warn("saving %s no file extension!\n", filename.c_str());
+	}
+}
+
+void Camera::SaveRawPictureToFile(string filename) const {
   Printf("saving %s, size %i\n", filename.c_str(), output->img->imageSize);
   std::ofstream pFile;
Index: trunk/lib/FlairSensorActuator/src/Camera.h
===================================================================
--- trunk/lib/FlairSensorActuator/src/Camera.h	(revision 123)
+++ trunk/lib/FlairSensorActuator/src/Camera.h	(revision 124)
@@ -92,9 +92,16 @@
 
   /*!
+  * \brief Save raw picture to file
+  *
+  * \param filename filename
+  */
+  void SaveRawPictureToFile(std::string filename) const;
+	
+	/*!
   * \brief Save picture to file
   *
   * \param filename filename
   */
-  void SaveToFile(std::string filename) const;
+  void SavePictureToFile(std::string filename) const;
 
   /*!
Index: trunk/lib/FlairSensorActuator/src/V4LCamera.cpp
===================================================================
--- trunk/lib/FlairSensorActuator/src/V4LCamera.cpp	(revision 123)
+++ trunk/lib/FlairSensorActuator/src/V4LCamera.cpp	(revision 124)
@@ -43,12 +43,11 @@
     Thread::Err("cvCaptureFromCAM error\n");
 
-  if (cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, width) < 0)
+  if (cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, width)<0)
     Thread::Err("cvSetCaptureProperty error\n");
-  if (cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, height) < 0)
+  if (cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, height)<0)
     Thread::Err("cvSetCaptureProperty error\n");
 
   if (format == cvimage::Type::Format::UYVY) {
-    if (cvSetCaptureProperty(capture, CV_CAP_PROP_FORMAT, V4L2_PIX_FMT_UYVY) <
-        0)
+    if (cvSetCaptureProperty(capture, CV_CAP_PROP_FORMAT, V4L2_PIX_FMT_UYVY)<0)
       Thread::Err("cvSetCaptureProperty error\n");
   } else if (format == cvimage::Type::Format::YUYV) {
Index: trunk/lib/FlairVisionFilter/src/CvtColor.cpp
===================================================================
--- trunk/lib/FlairVisionFilter/src/CvtColor.cpp	(revision 123)
+++ trunk/lib/FlairVisionFilter/src/CvtColor.cpp	(revision 124)
@@ -25,8 +25,8 @@
 
     switch(conversion) {
-    case Conversion_t::GRAY:
+    case Conversion_t::ToGray:
         try{
             cvimage::Type const &imageType=dynamic_cast<cvimage::Type const &>(parent->GetOutputDataType());
-            output=new cvimage(this,imageType.GetWidth(),imageType.GetHeight(),cvimage::Type::Format::GRAY,"conversion",true,2);
+            output=new cvimage(this,imageType.GetWidth(),imageType.GetHeight(),cvimage::Type::Format::Gray,"conversion",true,2);
 
         } catch(std::bad_cast& bc) {
@@ -61,5 +61,5 @@
 
     switch(conversion) {
-    case Conversion_t::GRAY:
+    case Conversion_t::ToGray:
         switch(((cvimage*)data)->GetDataType().GetFormat()) {
         case cvimage::Type::Format::YUYV:
Index: trunk/lib/FlairVisionFilter/src/CvtColor.h
===================================================================
--- trunk/lib/FlairVisionFilter/src/CvtColor.h	(revision 123)
+++ trunk/lib/FlairVisionFilter/src/CvtColor.h	(revision 124)
@@ -39,6 +39,6 @@
             */
             enum class Conversion_t {
-                BGR,/*!< BGR 24 bits */
-                GRAY,/*!< gray 8 bits */
+                ToBGR,/*!< BGR 24 bits */
+                ToGray,/*!< gray 8 bits */
                 } ;
 
Index: trunk/lib/FlairVisionFilter/src/HoughLines.cpp
===================================================================
--- trunk/lib/FlairVisionFilter/src/HoughLines.cpp	(revision 123)
+++ trunk/lib/FlairVisionFilter/src/HoughLines.cpp	(revision 124)
@@ -53,6 +53,6 @@
     try{
         cvimage::Type const &imageType=dynamic_cast<cvimage::Type const &>(parent->GetOutputDataType());
-        if(imageType.GetFormat()!=cvimage::Type::Format::GRAY) {
-            Err("input image is not grey\n");
+        if(imageType.GetFormat()!=cvimage::Type::Format::Gray) {
+            Err("input image is not gray\n");
         }
     } catch(std::bad_cast& bc) {
Index: trunk/lib/FlairVisionFilter/src/ImgThreshold.cpp
===================================================================
--- trunk/lib/FlairVisionFilter/src/ImgThreshold.cpp	(revision 123)
+++ trunk/lib/FlairVisionFilter/src/ImgThreshold.cpp	(revision 124)
@@ -32,8 +32,8 @@
     try{
         cvimage::Type const &imageType=dynamic_cast<cvimage::Type const &>(parent->GetOutputDataType());
-        if(imageType.GetFormat()==cvimage::Type::Format::GRAY) {
+        if(imageType.GetFormat()==cvimage::Type::Format::Gray) {
             output=new cvimage(this,imageType.GetWidth(),imageType.GetHeight(),imageType.GetFormat(),"threshold");
         } else {
-            Err("input image is not grey\n");
+            Err("input image is not gray\n");
         }
     } catch(std::bad_cast& bc) {
Index: trunk/lib/FlairVisionFilter/src/Sobel.cpp
===================================================================
--- trunk/lib/FlairVisionFilter/src/Sobel.cpp	(revision 123)
+++ trunk/lib/FlairVisionFilter/src/Sobel.cpp	(revision 124)
@@ -34,8 +34,8 @@
     try{
         cvimage::Type const &imageType=dynamic_cast<cvimage::Type const &>(parent->GetOutputDataType());
-        if(imageType.GetFormat()==cvimage::Type::Format::GRAY) {
+        if(imageType.GetFormat()==cvimage::Type::Format::Gray) {
             output=new cvimage(this,imageType.GetWidth(),imageType.GetHeight(),imageType.GetFormat(),"sobel");
         } else {
-            Err("input image is not grey\n");
+            Err("input image is not gray\n");
         }
 
Index: trunk/lib/FlairVisionFilter/src/VisionFilter.cpp
===================================================================
--- trunk/lib/FlairVisionFilter/src/VisionFilter.cpp	(revision 123)
+++ trunk/lib/FlairVisionFilter/src/VisionFilter.cpp	(revision 124)
@@ -9,5 +9,5 @@
 }
 
-void saveToJpeg(IplImage* src_img,std::string filename,unsigned char compression_level) {
+void saveToJpeg(IplImage* src_img,std::string filename,PictureFormat_t input_format,PictureFormat_t output_format,unsigned char compression_level) {
 	if(!cvSaveImage(filename.c_str(),src_img)) printf("Could not save.\n");
 }
Index: trunk/lib/FlairVisionFilter/src/VisionFilter.h
===================================================================
--- trunk/lib/FlairVisionFilter/src/VisionFilter.h	(revision 123)
+++ trunk/lib/FlairVisionFilter/src/VisionFilter.h	(revision 124)
@@ -12,3 +12,9 @@
 void CloseVisionFilter(void);
 
-void saveToJpeg(IplImage* src_img,std::string filename,unsigned char compression_level=95);
+enum class PictureFormat_t {
+                Gray,/*!< gray 8 bits */
+								RGB,/*!< rgb 24 bits */
+								UYVY,/*!< YUV 4:2:2 planer */
+                } ;
+								
+void saveToJpeg(IplImage* src_img,std::string filename,PictureFormat_t input_format,PictureFormat_t output_format,unsigned char compression_level=95);
Index: trunk/lib/FlairVisionFilter/src/unexported/compile_info.h
===================================================================
--- trunk/lib/FlairVisionFilter/src/unexported/compile_info.h	(revision 123)
+++ trunk/lib/FlairVisionFilter/src/unexported/compile_info.h	(revision 124)
@@ -5,9 +5,9 @@
 
 #define USER "gsanahuj@gsanahuj-Latitude-E6420"
-#define DATE "mardi 10 janvier 2017, 15:56:33 (UTC+0100)"
+#define DATE "jeudi 12 janvier 2017, 09:32:25 (UTC+0100)"
 #define GCC_REV "4.9.1"
 #define GCC_PATH "/opt/robomap3/1.7.3/armv7a-neon/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc"
 #define SVN_PATH "/home/gsanahuj/HDS/igep/flair-src_svn/trunk/lib/FlairVisionFilter"
-#define SVN_REV "122M"
+#define SVN_REV "122:123M"
 
 inline void compile_info(std::string name) { 
