iCub-main
FirewireCameraDC1394-DR2_2.cpp
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4  * Copyright (C) 2007 RobotCub Consortium
5  * Author: Alessandro Scalzo alessandro.scalzo@iit.it
6  * CopyPolicy: Released under the terms of the GNU GPL v2.0.
7  *
8  */
9 
10 // W W I N N
11 // W W I NN N
12 // W W W I N N N
13 // WW WW I N NN
14 // W W I N N
15 
17 #include <string.h>
18 
19 #define NOT_PRESENT -1
20 int CFWCamera_DR2_2::DC2Fly(int feature)
21 {
22  switch (feature)
23  {
24  case YARP_FEATURE_BRIGHTNESS: return FlyCapture2::BRIGHTNESS;
25  case YARP_FEATURE_EXPOSURE: return FlyCapture2::AUTO_EXPOSURE;
26  case YARP_FEATURE_SHARPNESS: return FlyCapture2::SHARPNESS;
27  case YARP_FEATURE_WHITE_BALANCE: return FlyCapture2::WHITE_BALANCE;
28  case YARP_FEATURE_HUE: return FlyCapture2::HUE;
29  case YARP_FEATURE_SATURATION: return FlyCapture2::SATURATION;
30  case YARP_FEATURE_GAMMA: return FlyCapture2::GAMMA;
31  case YARP_FEATURE_SHUTTER: return FlyCapture2::SHUTTER;
32  case YARP_FEATURE_GAIN: return FlyCapture2::GAIN;
33  case YARP_FEATURE_IRIS: return FlyCapture2::IRIS;
34  case YARP_FEATURE_FOCUS: return FlyCapture2::FOCUS;
35  case YARP_FEATURE_TEMPERATURE: return FlyCapture2::TEMPERATURE;
36  case YARP_FEATURE_TRIGGER: return FlyCapture2::TRIGGER_MODE;
37  case YARP_FEATURE_TRIGGER_DELAY: return FlyCapture2::TRIGGER_DELAY;
38  case YARP_FEATURE_FRAME_RATE: return FlyCapture2::FRAME_RATE;
39  case YARP_FEATURE_ZOOM: return FlyCapture2::ZOOM;
40  case YARP_FEATURE_PAN: return FlyCapture2::PAN;
41  case YARP_FEATURE_TILT: return FlyCapture2::TILT;
42  }
43 
44  return NOT_PRESENT;
45 }
46 
47 int CFWCamera_DR2_2::maxFPS(FlyCapture2::Mode mode,FlyCapture2::PixelFormat pixelFormat)
48 {
49  if (mHires)
50  {
51  switch (mode)
52  {
53  case FlyCapture2::MODE_0:
54  switch (pixelFormat)
55  {
56  case FlyCapture2::PIXEL_FORMAT_MONO8: return 31;
57  case FlyCapture2::PIXEL_FORMAT_RAW8: return 31;
58  case FlyCapture2::PIXEL_FORMAT_411YUV8: return 26;
59 
60  case FlyCapture2::PIXEL_FORMAT_MONO16: return 15;
61  case FlyCapture2::PIXEL_FORMAT_RAW16: return 15;
62  case FlyCapture2::PIXEL_FORMAT_422YUV8: return 15;
63 
64  case FlyCapture2::PIXEL_FORMAT_444YUV8: return 11;
65  case FlyCapture2::PIXEL_FORMAT_RGB8: return 11;
66  }
67  return 0;
68  case FlyCapture2::MODE_1:
69  switch (pixelFormat)
70  {
71  case FlyCapture2::PIXEL_FORMAT_MONO8: return 54;
72  case FlyCapture2::PIXEL_FORMAT_MONO16: return 54;
73 
74  case FlyCapture2::PIXEL_FORMAT_411YUV8: return 31;
75  case FlyCapture2::PIXEL_FORMAT_422YUV8: return 31;
76  case FlyCapture2::PIXEL_FORMAT_444YUV8: return 31;
77  case FlyCapture2::PIXEL_FORMAT_RGB8: return 31;
78  }
79  return 0;
80  case FlyCapture2::MODE_2:
81  switch (pixelFormat)
82  {
83  case FlyCapture2::PIXEL_FORMAT_MONO8: return 31;
84  case FlyCapture2::PIXEL_FORMAT_MONO16: return 26;
85  case FlyCapture2::PIXEL_FORMAT_411YUV8: return 31;
86  case FlyCapture2::PIXEL_FORMAT_422YUV8: return 26;
87  case FlyCapture2::PIXEL_FORMAT_444YUV8: return 17;
88  case FlyCapture2::PIXEL_FORMAT_RGB8: return 17;
89  }
90  return 0;
91  }
92  }
93  else // lores
94  {
95  switch (mode)
96  {
97  case FlyCapture2::MODE_0:
98  switch (pixelFormat)
99  {
100  case FlyCapture2::PIXEL_FORMAT_MONO8:
101  case FlyCapture2::PIXEL_FORMAT_RAW8:
102  case FlyCapture2::PIXEL_FORMAT_411YUV8: return 59;
103 
104  case FlyCapture2::PIXEL_FORMAT_MONO16:
105  case FlyCapture2::PIXEL_FORMAT_RAW16:
106  case FlyCapture2::PIXEL_FORMAT_422YUV8: return 47;
107 
108  case FlyCapture2::PIXEL_FORMAT_444YUV8:
109  case FlyCapture2::PIXEL_FORMAT_RGB8: return 31;
110  }
111  return 0;
112  case FlyCapture2::MODE_1:
113  switch (pixelFormat)
114  {
115  case FlyCapture2::PIXEL_FORMAT_MONO8:
116  case FlyCapture2::PIXEL_FORMAT_MONO16: return 100;
117 
118  case FlyCapture2::PIXEL_FORMAT_411YUV8:
119  case FlyCapture2::PIXEL_FORMAT_422YUV8:
120  case FlyCapture2::PIXEL_FORMAT_444YUV8:
121  case FlyCapture2::PIXEL_FORMAT_RGB8: return 59;
122  }
123  return 0;
124  case FlyCapture2::MODE_2:
125  switch (pixelFormat)
126  {
127  case FlyCapture2::PIXEL_FORMAT_MONO8:
128  case FlyCapture2::PIXEL_FORMAT_MONO16:
129  case FlyCapture2::PIXEL_FORMAT_411YUV8:
130  case FlyCapture2::PIXEL_FORMAT_422YUV8:
131  case FlyCapture2::PIXEL_FORMAT_444YUV8:
132  case FlyCapture2::PIXEL_FORMAT_RGB8: return 59;
133  }
134  return 0;
135  }
136  }
137 
138  return 0;
139 }
140 
141 double CFWCamera_DR2_2::bytesPerPixel(FlyCapture2::PixelFormat pixelFormat)
142 {
143  switch (pixelFormat)
144  {
145  case FlyCapture2::PIXEL_FORMAT_MONO8: return 1.0;
146  case FlyCapture2::PIXEL_FORMAT_MONO16: return 2.0;
147  case FlyCapture2::PIXEL_FORMAT_411YUV8: return 1.5;
148  case FlyCapture2::PIXEL_FORMAT_422YUV8: return 2.0;
149  case FlyCapture2::PIXEL_FORMAT_444YUV8: return 3.0;
150  case FlyCapture2::PIXEL_FORMAT_RGB8: return 3.0;
151  case FlyCapture2::PIXEL_FORMAT_RAW8: return 1.0;
152  case FlyCapture2::PIXEL_FORMAT_RAW16: return 2.0;
153  }
154 
155  return 0.0;
156 }
157 
158 unsigned int CFWCamera_DR2_2::NormToValue(double& dVal,int feature)
159 {
160  if (dVal<0.0) dVal=0.0;
161  if (dVal>1.0) dVal=1.0;
162 
163  unsigned int iVal=m_iMin[feature]+(unsigned int)(dVal*double(m_iMax[feature]-m_iMin[feature]));
164 
165  if (iVal<m_iMin[feature]) iVal=m_iMin[feature];
166  if (iVal>m_iMax[feature]) iVal=m_iMax[feature];
167 
168  return iVal;
169 }
170 
171 double CFWCamera_DR2_2::ValueToNorm(unsigned int iVal,int feature)
172 {
173  double dVal=double(iVal-m_iMin[feature])/double(m_iMax[feature]-m_iMin[feature]);
174 
175  if (dVal<0.0) return 0.0;
176  if (dVal>1.0) return 1.0;
177 
178  return dVal;
179 }
180 
181 bool CFWCamera_DR2_2::Create(yarp::os::Searchable& config)
182 {
183  int size_x=checkInt(config,"width");
184  int size_y=checkInt(config,"height");
185  int off_x=checkInt(config,"xoff");
186  int off_y=checkInt(config,"yoff");
187  int format=checkInt(config,"video_type");
188  unsigned int idCamera=0;
189 
190  m_pFrame=new FlyCapture2::Image();
191  m_pBayer=new FlyCapture2::Image();
192 
193  //FlyCapture2::Image::SetDefaultColorProcessing(FlyCapture2::HQ_LINEAR);
194 
195  m_bCameraOn=false;
196  m_bFrameIsValid=false;
197  m_pCamera=NULL;
198  m_pBusManager=NULL;
199  m_nNumCameras=0;
200  m_bTxOn=true;
201 
202  if (!(m_pBusManager=new FlyCapture2::BusManager()))
203  {
204  yError("failed to open Firewire Bus Manager\n");
205  return false;
206  }
207 
208  error=m_pBusManager->GetNumOfCameras(&m_nNumCameras);
209  if (manage(error)) return false;
210 
211  if (!m_nNumCameras)
212  {
213  yError("no active cameras\n");
214  return false;
215  }
216 
217  FlyCapture2::PGRGuid Guid;
218 
219  /*
220  if (config.check("guid"))
221  {
222  std::string sguid=config.find("guid").asString();
223 
224  Guid.value[0]=strtoul(sguid.substr(0,8).c_str(),NULL,16);
225  Guid.value[1]=strtoul(sguid.substr(8,8).c_str(),NULL,16);
226  Guid.value[2]=0;
227  Guid.value[3]=0;
228  }
229  else
230  */
231  {
232  if (config.check("d"))
233  {
234  //yWarning("WARNING: --d <unit_number> parameter is deprecated, use --guid <64_bit_global_unique_identifier> instead\n");
235  //idCamera=config.find("d").asInt32();
236 
237  if (idCamera<0 || idCamera>=m_nNumCameras)
238  {
239  yError("invalid camera number\n");
240  return false;
241  }
242  }
243 
244  error=m_pBusManager->GetCameraFromIndex(idCamera,&Guid);
245  if (manage(error)) return false;
246  }
247 
248  if (!(m_pCamera=new FlyCapture2::Camera()))
249  {
250  yError("failed to create camera\n");
251  return false;
252  }
253 
254  error=m_pCamera->Connect(&Guid);
255  if (manage(error)) return false;
256 
257  error=m_pCamera->GetCameraInfo(&m_CameraInfo);
258  if (manage(error)) return false;
259 
260  yInfo("GUID = %x%x",Guid.value[0],Guid.value[1]);
261  yInfo("%x%x\n",Guid.value[2],Guid.value[3]);
262 
263  mHires=(strcmp("1032x776",m_CameraInfo.sensorResolution)==0);
264 
265  switch (m_CameraInfo.maximumBusSpeed)
266  {
267  case FlyCapture2::BUSSPEED_S100: m_BusSpeedBS= 10000000; break;
268  case FlyCapture2::BUSSPEED_S200: m_BusSpeedBS= 20000000; break;
269  case FlyCapture2::BUSSPEED_S400: m_BusSpeedBS= 40000000; break;
270  case FlyCapture2::BUSSPEED_S480: m_BusSpeedBS= 48000000; break;
271  case FlyCapture2::BUSSPEED_S800: m_BusSpeedBS= 80000000; break;
272  case FlyCapture2::BUSSPEED_S1600: m_BusSpeedBS=160000000; break;
273  case FlyCapture2::BUSSPEED_S3200: m_BusSpeedBS=320000000; break;
274  default: m_BusSpeedBS=0;
275  }
276 
277  error=m_pCamera->GetConfiguration(&m_CamConfig);
278  if (manage(error)) return false;
279 
280  // CONFIGURE
281 
282  //error=m_pCamera->RestoreFromMemoryChannel(0);
283  //if (manage(error)) return false;
284 
285  m_CamConfig.isochBusSpeed=FlyCapture2::BUSSPEED_S_FASTEST;
286  m_CamConfig.asyncBusSpeed=FlyCapture2::BUSSPEED_S_FASTEST;
287  m_CamConfig.grabMode=FlyCapture2::DROP_FRAMES;
288  m_CamConfig.grabTimeout=2000; //FlyCapture2::TIMEOUT_INFINITE;
289  m_CamConfig.bandwidthAllocation=FlyCapture2::BANDWIDTH_ALLOCATION_ON;
290  m_CamConfig.numBuffers=NUM_DMA_BUFFERS;
291  m_CamConfig.numImageNotifications=1;
292 
293  error=m_pCamera->SetConfiguration(&m_CamConfig);
294  if (manage(error)) return false;
295 
296  if (mRawDriver) format=DR_BAYER_FULL_RES;
297 
298  switch (format)
299  {
300  case DR_UNINIT:
301  break;
302 
303  case DR_RGB_HALF_RES:
304  if (mHires)
305  {
306  if (!size_x) { size_x=512; }
307  if (!size_y) { size_y=384; }
308  }
309  else
310  {
311  if (!size_x) { size_x=320; }
312  if (!size_y) { size_y=240; }
313  }
314  SetF7(FlyCapture2::MODE_1,size_x,size_y,FlyCapture2::PIXEL_FORMAT_RGB,50,off_x,off_y);
315  break;
316 
317  case DR_RGB_FULL_RES:
318  if (mHires)
319  {
320  if (!size_x) { size_x=1024; }
321  if (!size_y) { size_y=768; }
322  /*
323  if (size_x==1024 && size_y==768)
324  {
325  SetVideoMode(FlyCapture2::VIDEOMODE_1024x768RGB);
326  }
327  else
328  */
329  {
330  SetF7(FlyCapture2::MODE_0,size_x,size_y,FlyCapture2::PIXEL_FORMAT_RGB,50,off_x,off_y);
331  }
332  }
333  else
334  {
335  if (!size_x) { size_x=640; }
336  if (!size_y) { size_y=480; }
337 
338  if (size_x==640 && size_y==480)
339  {
340  SetVideoMode(FlyCapture2::VIDEOMODE_640x480RGB);
341  }
342  else
343  {
344  SetF7(FlyCapture2::MODE_0,size_x,size_y,FlyCapture2::PIXEL_FORMAT_RGB,50,off_x,off_y);
345  }
346  }
347  break;
348 
349  case DR_BAYER_FULL_RES:
350  if (mHires)
351  {
352  if (!size_x) { size_x=1024; }
353  if (!size_y) { size_y=768; }
354  }
355  else
356  {
357  if (!size_x) { size_x=640; }
358  if (!size_y) { size_y=480; }
359  }
360  SetF7(FlyCapture2::MODE_0,size_x,size_y,FlyCapture2::PIXEL_FORMAT_RAW8,50,off_x,off_y);
361  break;
362 
363  default:
364  yInfo("Reading video format from camera\n");
365  }
366 
367  for (int f=FlyCapture2::BRIGHTNESS; f<=FlyCapture2::TEMPERATURE; ++f)
368  {
369  FlyCapture2::PropertyInfo propInfo;
370  propInfo.type=(FlyCapture2::PropertyType)f;
371  error=m_pCamera->GetPropertyInfo(&propInfo);
372  if (error.GetType()==FlyCapture2::PGRERROR_OK)
373  {
374  m_iMin[f]=(int)propInfo.min;
375  m_iMax[f]=(int)propInfo.max;
376 
377  if (propInfo.present)
378  {
379  FlyCapture2::Property prop;
380  prop.type=(FlyCapture2::PropertyType)f;
381  error=m_pCamera->GetProperty(&prop);
382  if (error.GetType()!=FlyCapture2::PGRERROR_OK)
383  {
384  yWarning("feature %d %s\n",f,error.GetDescription());
385  }
386  prop.onOff=(f!=FlyCapture2::AUTO_EXPOSURE && f!=FlyCapture2::IRIS && f<FlyCapture2::TRIGGER_MODE);
387  prop.autoManualMode=false;
388  prop.absControl=false;
389  error=m_pCamera->SetProperty(&prop);
390  if (error.GetType()!=FlyCapture2::PGRERROR_OK)
391  {
392  yWarning("feature %d %s\n",f,error.GetDescription());
393  }
394  }
395  else
396  {
397  yInfo("Feature %d not supported by this camera model.\n", f);
398  }
399  }
400  else
401  {
402  yError("Feature %d %s\n",f,error.GetDescription());
403  }
404  }
405 
406  error=m_pCamera->GetConfiguration(&m_CamConfig);
407  if (manage(error)) return false;
408 
409  error=m_pCamera->StartCapture();
410  if (manage(error)) return false;
411 
412  m_bFrameIsValid=true;
413  m_bCameraOn=true;
414 
415  // parameters
416 
417  setBrightness(checkDouble(config,"brightness"));
418  setExposure(checkDouble(config,"exposure"));
419  setSharpness(checkDouble(config,"sharpness"));
420  yarp::os::Bottle& white_balance=config.findGroup("white_balance");
421  if (!white_balance.isNull())
422  {
423  setWhiteBalance(white_balance.get(2).asFloat64(),white_balance.get(1).asFloat64());
424  }
425  setHue(checkDouble(config,"hue"));
426  setSaturation(checkDouble(config,"saturation"));
427  setGamma(checkDouble(config,"gamma"));
428  setShutter(checkDouble(config,"shutter"));
429  setGain(checkDouble(config,"gain"));
430  setIris(checkDouble(config,"iris"));
431 
432  return true;
433 }
434 
436 {
437  if (m_pCamera)
438  {
439  m_pCamera->StopCapture();
440  m_pCamera->Disconnect();
441  delete m_pCamera;
442  m_pCamera=0;
443  }
444 
445  if (m_pFrame)
446  {
447  delete m_pFrame;
448  m_pFrame=0;
449  }
450 
451  if (m_pBayer)
452  {
453  delete m_pBayer;
454  m_pBayer=0;
455  }
456 
457  if (m_pBusManager)
458  {
459  delete m_pBusManager;
460  m_pBusManager=0;
461  }
462 }
463 
464 bool CFWCamera_DR2_2::SetVideoMode(FlyCapture2::VideoMode video_mode)
465 {
466  if (!m_pCamera) return false;
467 
468  if (mRawDriver) return false;
469 
470  int xdim,ydim,buff_dim;
471 
472  // calculate raw image size at given video mode
473  switch (video_mode)
474  {
475  case FlyCapture2::VIDEOMODE_160x120YUV444: xdim=160; ydim=120; buff_dim= xdim*ydim*3; break;
476 
477  case FlyCapture2::VIDEOMODE_320x240YUV422: xdim=320; ydim=240; buff_dim= xdim*ydim*2; break;
478 
479  case FlyCapture2::VIDEOMODE_640x480YUV411: xdim=640; ydim=480; buff_dim=(xdim*ydim*3)/2; break;
480 
481  case FlyCapture2::VIDEOMODE_640x480YUV422: xdim=640; ydim=480; buff_dim= xdim*ydim*2; break;
482  case FlyCapture2::VIDEOMODE_640x480RGB: xdim=640; ydim=480; buff_dim= xdim*ydim*3; break;
483  case FlyCapture2::VIDEOMODE_640x480Y8: xdim=640; ydim=480; buff_dim= xdim*ydim; break;
484  case FlyCapture2::VIDEOMODE_640x480Y16: xdim=640; ydim=480; buff_dim= xdim*ydim*2; break;
485 
486  case FlyCapture2::VIDEOMODE_800x600YUV422: xdim=800; ydim=600; buff_dim= xdim*ydim*2; break;
487  case FlyCapture2::VIDEOMODE_800x600RGB: xdim=800; ydim=600; buff_dim= xdim*ydim*3; break;
488  case FlyCapture2::VIDEOMODE_800x600Y8: xdim=800; ydim=600; buff_dim= xdim*ydim; break;
489  case FlyCapture2::VIDEOMODE_800x600Y16: xdim=800; ydim=600; buff_dim= xdim*ydim*2; break;
490 
491  case FlyCapture2::VIDEOMODE_1024x768YUV422: xdim=1024; ydim=768; buff_dim= xdim*ydim*2; break;
492  case FlyCapture2::VIDEOMODE_1024x768RGB: xdim=1024; ydim=768; buff_dim= xdim*ydim*3; break;
493  case FlyCapture2::VIDEOMODE_1024x768Y8: xdim=1024; ydim=768; buff_dim= xdim*ydim; break;
494  case FlyCapture2::VIDEOMODE_1024x768Y16: xdim=1024; ydim=768; buff_dim= xdim*ydim*2; break;
495 
496  default: return false;
497  }
498 
499  error=m_pCamera->GetConfiguration(&m_CamConfig);
500  if (manage(error)) return false;
501 
502  // get ISO bandwidth
503  switch (m_CamConfig.isochBusSpeed)
504  {
505  case FlyCapture2::BUSSPEED_S100: m_BusSpeedBS= 10000000; break;
506  case FlyCapture2::BUSSPEED_S200: m_BusSpeedBS= 20000000; break;
507  case FlyCapture2::BUSSPEED_S400: m_BusSpeedBS= 40000000; break;
508  case FlyCapture2::BUSSPEED_S480: m_BusSpeedBS= 48000000; break;
509  case FlyCapture2::BUSSPEED_S800: m_BusSpeedBS= 80000000; break;
510  case FlyCapture2::BUSSPEED_S1600: m_BusSpeedBS=160000000; break;
511  case FlyCapture2::BUSSPEED_S3200: m_BusSpeedBS=320000000; break;
512  default: m_BusSpeedBS=0;
513  }
514 
515  // calculate maximum allowed framerate at given image format
516  static const double two_cams=0.5; // only half bandwith available with two cams
517  double fpsMax=two_cams*double(m_BusSpeedBS)/double(buff_dim);
518 
519  FlyCapture2::FrameRate frame_rate;
520 
521  // choose framerate according to maximum allowed
522  if (fpsMax<1.785){ return false; }
523  else if (fpsMax<3.75) { frame_rate=FlyCapture2::FRAMERATE_1_875; }
524  else if (fpsMax<7.5) { frame_rate=FlyCapture2::FRAMERATE_3_75; }
525  else if (fpsMax<15.0) { frame_rate=FlyCapture2::FRAMERATE_7_5; }
526  else if (fpsMax<30.0) { frame_rate=FlyCapture2::FRAMERATE_15; }
527  else if (fpsMax<60.0) { frame_rate=FlyCapture2::FRAMERATE_30; }
528  else if (fpsMax<120.0){ frame_rate=FlyCapture2::FRAMERATE_60; }
529  else if (fpsMax<240.0){ frame_rate=FlyCapture2::FRAMERATE_120; }
530  else { frame_rate=FlyCapture2::FRAMERATE_240; }
531 
532  // is frame_rate supported? choose the best
533  for (int fr=frame_rate; fr>=FlyCapture2::FRAMERATE_1_875; --fr)
534  {
535  bool bSupported;
536  error=m_pCamera->GetVideoModeAndFrameRateInfo(video_mode,(FlyCapture2::FrameRate)fr,&bSupported);
537  if (manage(error)) return false;
538 
539  if (bSupported)
540  {
541  error=m_pCamera->SetVideoModeAndFrameRate(video_mode,(FlyCapture2::FrameRate)fr);
542 
543  printf("video mode=%d framerate=%d\n",video_mode,fr);
544 
545  if (manage(error)) return false;
546 
547  m_XDim=xdim;
548  m_YDim=ydim;
549 
550  return true;
551  }
552  }
553 
554  return false;
555 }
556 
557 #define SKIP 0x80000000
558 bool CFWCamera_DR2_2::SetF7(int mode,int xdim,int ydim,int pixel_format,int speed,int x0,int y0)
559 {
560  if (!m_pCamera) return false;
561 
562  if (mRawDriver)
563  {
564  if (mode!=FlyCapture2::MODE_0 || pixel_format!=FlyCapture2::PIXEL_FORMAT_RAW8) return false;
565  }
566 
567  FlyCapture2::VideoMode vm;
568  FlyCapture2::FrameRate fr;
569  error=m_pCamera->GetVideoModeAndFrameRate(&vm,&fr);
570  if (manage(error)) return false;
571 
572  m_F7PercentSpeed=0.5f;
573 
574  if (vm==FlyCapture2::VIDEOMODE_FORMAT7)
575  {
576  error=m_pCamera->GetFormat7Configuration(&m_F7ImageSettings,&m_F7PacketSize,&m_F7PercentSpeed);
577  if (manage(error)) return false;
578  }
579  else
580  {
581  if (mode==SKIP) // we're not in F7 mode and no mode is specified!
582  {
583  yError("no format 7 mode specified\n");
584  return false;
585  }
586 
587  m_F7ImageSettings.pixelFormat=FlyCapture2::PIXEL_FORMAT_RGB8;
588  }
589 
590  m_F7Info.mode= mode==SKIP ? m_F7ImageSettings.mode : (FlyCapture2::Mode)mode;
591 
592  bool bSupported;
593  error=m_pCamera->GetFormat7Info(&m_F7Info,&bSupported);
594  if (manage(error)) return false;
595 
596  // is given mode supported?
597  if (!bSupported)
598  {
599  yError("format 7 mode %d not supported\n",m_F7Info.mode);
600  return false;
601  }
602 
603  // is given pixel format supported?
604  if (! (m_F7ImageSettings.pixelFormat & m_F7Info.pixelFormatBitField))
605  {
606  if (pixel_format==SKIP)
607  {
608  pixel_format=FlyCapture2::PIXEL_FORMAT_RGB8;
609  }
610  else
611  {
612  yError("invalid format 7 pixel format %d\n",m_F7ImageSettings.pixelFormat);
613  return false;
614  }
615  }
616 
617  if (pixel_format==SKIP) pixel_format=m_F7ImageSettings.pixelFormat;
618 
619  if (vm!=FlyCapture2::VIDEOMODE_FORMAT7)
620  {
621  if (xdim==SKIP) xdim=(int)m_F7Info.maxWidth;
622  if (ydim==SKIP) ydim=(int)m_F7Info.maxHeight;
623  if (x0==SKIP) x0=0;
624  if (y0==SKIP) y0=0;
625  }
626  else
627  {
628  if (xdim==SKIP) xdim=m_F7ImageSettings.width;
629  if (ydim==SKIP) ydim=m_F7ImageSettings.height;
630  if (x0==SKIP) x0=m_F7ImageSettings.offsetX;
631  if (y0==SKIP) y0=m_F7ImageSettings.offsetY;
632  }
633 
634  // adjust image size to allowed in this format
635  if (xdim>(int)m_F7Info.maxWidth) { xdim=m_F7Info.maxWidth; }
636  if (ydim>(int)m_F7Info.maxHeight) { ydim=m_F7Info.maxHeight; }
637 
638  if (m_F7Info.mode==FlyCapture2::MODE_1)
639  {
640  xdim=(xdim/(2*m_F7Info.imageHStepSize))*(2*m_F7Info.imageHStepSize);
641  }
642  else
643  {
644  xdim=(xdim/m_F7Info.imageHStepSize)*m_F7Info.imageHStepSize;
645  }
646  ydim=(ydim/m_F7Info.imageVStepSize)*m_F7Info.imageVStepSize;
647 
648  // calculate offset
649  int xoff=(m_F7Info.maxWidth -xdim)/2+x0;
650  int yoff=(m_F7Info.maxHeight-ydim)/2+y0;
651 
652  if (xoff<0) xoff=0;
653  if (yoff<0) yoff=0;
654 
655  if (xoff+xdim>(int)m_F7Info.maxWidth) xoff=m_F7Info.maxWidth-xdim;
656  if (yoff+ydim>(int)m_F7Info.maxHeight) yoff=m_F7Info.maxHeight-ydim;
657 
658  xoff=(xoff/m_F7Info.offsetHStepSize)*m_F7Info.offsetHStepSize;
659  yoff=(yoff/m_F7Info.offsetVStepSize)*m_F7Info.offsetVStepSize;
660 
661  // prepare image settings
662  m_F7ImageSettings.mode=m_F7Info.mode;
663  if (pixel_format!=SKIP) m_F7ImageSettings.pixelFormat=(FlyCapture2::PixelFormat)pixel_format;
664  m_F7ImageSettings.width=(unsigned)xdim;
665  m_F7ImageSettings.offsetX=xoff;
666  m_F7ImageSettings.height=(unsigned)ydim;
667  m_F7ImageSettings.offsetY=yoff;
668 
669  // validate image settings
670  bool bSettingsAreValid;
671  FlyCapture2::Format7PacketInfo packetInfo;
672  error=m_pCamera->ValidateFormat7Settings(&m_F7ImageSettings,&bSettingsAreValid,&packetInfo);
673  if (manage(error)) return false;
674 
675  if (!bSettingsAreValid)
676  {
677  yError("invalid format 7 settings\n");
678  return false;
679  }
680 
681  // speed
682 
683  error=m_pCamera->GetConfiguration(&m_CamConfig);
684  if (manage(error)) return false;
685 
686  // get ISO bandwidth
687  switch (m_CamConfig.isochBusSpeed)
688  {
689  case FlyCapture2::BUSSPEED_S100: m_BusSpeedBS= 10000000; break;
690  case FlyCapture2::BUSSPEED_S200: m_BusSpeedBS= 20000000; break;
691  case FlyCapture2::BUSSPEED_S400: m_BusSpeedBS= 40000000; break;
692  case FlyCapture2::BUSSPEED_S480: m_BusSpeedBS= 48000000; break;
693  case FlyCapture2::BUSSPEED_S800: m_BusSpeedBS= 80000000; break;
694  case FlyCapture2::BUSSPEED_S1600: m_BusSpeedBS=160000000; break;
695  case FlyCapture2::BUSSPEED_S3200: m_BusSpeedBS=320000000; break;
696  default: m_BusSpeedBS=0;
697  }
698 
699  int fps=maxFPS(m_F7ImageSettings.mode,m_F7ImageSettings.pixelFormat);
700  double bpp=bytesPerPixel(m_F7ImageSettings.pixelFormat);
701  double maxBandOcc=double(fps*xdim*ydim)*bpp;
702 
703  double margin=double(m_BusSpeedBS)/maxBandOcc;
704 
705  if (speed==SKIP)
706  {
707  m_F7PacketSize=(unsigned int)(m_F7PercentSpeed*packetInfo.maxBytesPerPacket);
708  }
709  else
710  {
711  m_F7PacketSize=(unsigned int)(0.01*double(speed*packetInfo.maxBytesPerPacket)*margin);
712  //m_F7PacketSize=(unsigned int)((speed*packetInfo.maxBytesPerPacket)/100);
713  //printf("maxBandOcc=%f m_BusSpeedBS=%d margin=%f m_F7PacketSize=%d\n",maxBandOcc,m_BusSpeedBS,margin,m_F7PacketSize);
714  }
715 
716  m_F7PacketSize=(m_F7PacketSize/packetInfo.unitBytesPerPacket)*packetInfo.unitBytesPerPacket;
717  if (m_F7PacketSize>packetInfo.maxBytesPerPacket)
718  {
719  m_F7PacketSize=packetInfo.maxBytesPerPacket;
720  }
721 
722  // set image configuration
723  error=m_pCamera->SetFormat7Configuration(&m_F7ImageSettings,m_F7PacketSize);
724  if (manage(error)) return false;
725 
726  error=m_pCamera->GetFormat7Configuration(&m_F7ImageSettings,&m_F7PacketSize,&m_F7PercentSpeed);
727  if (manage(error)) return false;
728 
729  //printf("\n 1 Packet size=%d - Speed=%f\n\n",m_F7PacketSize,m_F7PercentSpeed);
730 
732  m_YDim=m_F7ImageSettings.height;
733 
734  return true;
735 }
736 
737 bool CFWCamera_DR2_2::Capture(yarp::sig::ImageOf<yarp::sig::PixelRgb>* pImage,unsigned char *pBuffer,bool bRaw)
738 {
739  m_AcqMutex.wait();
740 
741  if (!m_bCameraOn)
742  {
743  m_AcqMutex.post();
744  return false;
745  }
746 
747  error=m_pCamera->RetrieveBuffer(m_pFrame);
748  if (manage(error,&m_AcqMutex)) return false;
749 
750  if (!m_bFrameIsValid)
751  {
752  m_bFrameIsValid=true;
753  m_AcqMutex.post();
754  return false;
755  }
756 
757  m_Stamp.update();
758 
759  if (pImage)
760  {
761  pImage->resize(m_pFrame->GetCols(),m_pFrame->GetRows());
762  pBuffer=pImage->getRawImage();
763  }
764 
765  if (m_pFrame->GetPixelFormat()==FlyCapture2::PIXEL_FORMAT_RGB8 || bRaw)
766  {
767  memcpy(pBuffer,m_pFrame->GetData(),m_pFrame->GetRows()*m_pFrame->GetCols()*(bRaw?1:3));
768  }
769  else
770  {
771  error=m_pFrame->Convert(FlyCapture2::PIXEL_FORMAT_RGB8,m_pBayer);
772  if (manage(error,&m_AcqMutex))
773  {
774  return false;
775  }
776  else
777  {
778  memcpy(pBuffer,m_pBayer->GetData(),m_pBayer->GetRows()*m_pBayer->GetCols()*3);
779  }
780  }
781 
782  m_AcqMutex.post();
783  return true;
784 }
785 
786 bool CFWCamera_DR2_2::Capture(yarp::sig::ImageOf<yarp::sig::PixelMono>* pImage)
787 {
788  m_AcqMutex.wait();
789 
790  if (!m_bCameraOn)
791  {
792  m_AcqMutex.post();
793  return false;
794  }
795 
796  error=m_pCamera->RetrieveBuffer(m_pFrame);
797  if (manage(error,&m_AcqMutex)) return false;
798 
799  if (!m_bFrameIsValid)
800  {
801  m_bFrameIsValid=true;
802  m_AcqMutex.post();
803  return false;
804  }
805 
806  m_Stamp.update();
807 
808  if (pImage)
809  {
810  pImage->resize(m_pFrame->GetCols(),m_pFrame->GetRows());
811  memcpy(pImage->getRawImage(),m_pFrame->GetData(),m_pFrame->GetRows()*m_pFrame->GetCols());
812  }
813 
814  m_AcqMutex.post();
815  return true;
816 }
817 
819 // feature functions
821 
822 // 00
823 bool CFWCamera_DR2_2::hasFeatureDC1394(int feature)
824 {
825  if ((feature=DC2Fly(feature))==NOT_PRESENT) return false;
826  FlyCapture2::PropertyInfo info;
827  info.type=(FlyCapture2::PropertyType)feature;
828  error=m_pCamera->GetPropertyInfo(&info);
829  if (error.GetType()!=FlyCapture2::PGRERROR_OK) return false;
830  return info.present;
831 }
832 // 01
833 bool CFWCamera_DR2_2::setFeatureDC1394(int feature,double value)
834 {
835  if (value<0.0 || value>1.0) return false;
836 
837  m_AcqMutex.wait();
838 
839  if (!m_pCamera)
840  {
841  m_AcqMutex.post();
842  return false;
843  }
844 
845  if ((feature=DC2Fly(feature))==NOT_PRESENT)
846  {
847  m_AcqMutex.post();
848  return false;
849  }
850 
851  FlyCapture2::Property prop;
852  prop.type=(FlyCapture2::PropertyType)feature;
853  error=m_pCamera->GetProperty(&prop);
854  if (manage(error,&m_AcqMutex)) return false;
855 
856  prop.valueA=NormToValue(value,feature);
857  error=m_pCamera->SetProperty(&prop);
858  if (manage(error,&m_AcqMutex)) return false;
859 
860  m_AcqMutex.post();
861  return true;
862 }
863 // 02
864 double CFWCamera_DR2_2::getFeatureDC1394(int feature)
865 {
866  if ((feature=DC2Fly(feature))==NOT_PRESENT) return -1.0;
867  if (!m_pCamera) return -1.0;
868  FlyCapture2::Property prop;
869  prop.type=(FlyCapture2::PropertyType)feature;
870  error=m_pCamera->GetProperty(&prop);
871  if (manage(error)) return -1.0;
872  return ValueToNorm(prop.valueA,feature);
873 }
874 
875 // 03
876 bool CFWCamera_DR2_2::hasOnOffDC1394(int feature)
877 {
878  if ((feature=DC2Fly(feature))==NOT_PRESENT) return false;
879  if (!m_pCamera) return false;
880  FlyCapture2::PropertyInfo info;
881  info.type=(FlyCapture2::PropertyType)feature;
882  error=m_pCamera->GetPropertyInfo(&info);
883  if (manage(error)) return false;
884  return info.onOffSupported;
885 }
886 // 04
887 bool CFWCamera_DR2_2::setActiveDC1394(int feature, bool onoff)
888 {
889  if ((feature=DC2Fly(feature))==NOT_PRESENT) return false;
890  if (!m_pCamera) return false;
891  FlyCapture2::Property prop;
892  prop.type=(FlyCapture2::PropertyType)feature;
893  error=m_pCamera->GetProperty(&prop);
894  if (manage(error)) return false;
895  prop.onOff=onoff;
896  m_pCamera->SetProperty(&prop);
897  if (manage(error)) return false;
898  return true;
899 }
900 // 05
901 bool CFWCamera_DR2_2::getActiveDC1394(int feature)
902 {
903  if ((feature=DC2Fly(feature))==NOT_PRESENT) return false;
904  if (!m_pCamera) return false;
905  FlyCapture2::Property prop;
906  prop.type=(FlyCapture2::PropertyType)feature;
907  error=m_pCamera->GetProperty(&prop);
908  if (manage(error)) return false;
909  return prop.onOff;
910 }
911 
912 // 06
913 bool CFWCamera_DR2_2::hasManualDC1394(int feature)
914 {
915  if ((feature=DC2Fly(feature))==NOT_PRESENT) return false;
916  if (!m_pCamera) return false;
917  FlyCapture2::PropertyInfo info;
918  info.type=(FlyCapture2::PropertyType)feature;
919  error=m_pCamera->GetPropertyInfo(&info);
920  if (manage(error)) return false;
921  return info.manualSupported;
922 }
923 // 07
924 bool CFWCamera_DR2_2::hasAutoDC1394(int feature)
925 {
926  if ((feature=DC2Fly(feature))==NOT_PRESENT) return false;
927  if (!m_pCamera) return false;
928  FlyCapture2::PropertyInfo info;
929  info.type=(FlyCapture2::PropertyType)feature;
930  error=m_pCamera->GetPropertyInfo(&info);
931  if (manage(error)) return false;
932  return info.autoSupported;
933 }
934 // 08
935 bool CFWCamera_DR2_2::hasOnePushDC1394(int feature)
936 {
937  if ((feature=DC2Fly(feature))==NOT_PRESENT) return false;
938  if (!m_pCamera) return false;
939  FlyCapture2::PropertyInfo info;
940  info.type=(FlyCapture2::PropertyType)feature;
941  error=m_pCamera->GetPropertyInfo(&info);
942  if (manage(error)) return false;
943  return info.onePushSupported;
944 }
945 
946 // 09
947 bool CFWCamera_DR2_2::setModeDC1394(int feature, bool auto_onoff)
948 {
949  if ((feature=DC2Fly(feature))==NOT_PRESENT) return false;
950  if (!m_pCamera) return false;
951  FlyCapture2::Property prop;
952  prop.type=(FlyCapture2::PropertyType)feature;
953  error=m_pCamera->GetProperty(&prop);
954  if (manage(error)) return false;
955  prop.autoManualMode=auto_onoff;
956  error=m_pCamera->SetProperty(&prop);
957  if (manage(error)) return false;
958  return true;
959 }
960 // 10
961 bool CFWCamera_DR2_2::getModeDC1394(int feature)
962 {
963  if ((feature=DC2Fly(feature))==NOT_PRESENT) return false;
964  if (!m_pCamera) return false;
965  FlyCapture2::Property prop;
966  prop.type=(FlyCapture2::PropertyType)feature;
967  error=m_pCamera->GetProperty(&prop);
968  if (manage(error)) return false;
969  return prop.autoManualMode;
970 }
971 // 11
972 bool CFWCamera_DR2_2::setOnePushDC1394(int feature)
973 {
974  if ((feature=DC2Fly(feature))==NOT_PRESENT) return false;
975  if (!m_pCamera) return false;
976  FlyCapture2::Property prop;
977  prop.type=(FlyCapture2::PropertyType)feature;
978  error=m_pCamera->GetProperty(&prop);
979  if (manage(error)) return false;
980  prop.onePush=true;
981  error=m_pCamera->SetProperty(&prop);
982  if (manage(error)) return false;
983  return true;
984 }
985 
986 // 23
987 bool CFWCamera_DR2_2::setWhiteBalanceDC1394(double b, double r)
988 {
989  if (b<0.0 || b>1.0 || r<0.0 || r>1.0) return false;
990  if (!m_pCamera) return false;
991  FlyCapture2::Property prop;
992  prop.type=FlyCapture2::WHITE_BALANCE;
993  error=m_pCamera->GetProperty(&prop);
994  if (manage(error)) return false;
995  prop.valueA=NormToValue(r,FlyCapture2::WHITE_BALANCE);
996  prop.valueB=NormToValue(b,FlyCapture2::WHITE_BALANCE);
997  error=m_pCamera->SetProperty(&prop);
998  if (manage(error)) return false;
999  return true;
1000 }
1001 // 24
1002 bool CFWCamera_DR2_2::getWhiteBalanceDC1394(double &b, double &r)
1003 {
1004  if (!m_pCamera) return false;
1005  FlyCapture2::Property prop;
1006  prop.type=FlyCapture2::WHITE_BALANCE;
1007  error=m_pCamera->GetProperty(&prop);
1008  if (manage(error)) return false;
1009  r=ValueToNorm(prop.valueA,FlyCapture2::WHITE_BALANCE);
1010  b=ValueToNorm(prop.valueB,FlyCapture2::WHITE_BALANCE);
1011  return true;
1012 }
1013 
1015 // end feature functions
1017 
1018 // 12
1020 {
1021  if (mRawDriver)
1022  {
1023  return 1<<(1+FlyCapture2::MODE_0+FlyCapture2::VIDEOMODE_FORMAT7);
1024  }
1025 
1026  bool bSupported;
1027  unsigned int mask=0;
1028 
1029  for (int m=FlyCapture2::VIDEOMODE_160x120YUV444; m<FlyCapture2::NUM_VIDEOMODES; ++m)
1030  {
1031  for (int f=FlyCapture2::FRAMERATE_1_875; f<FlyCapture2::NUM_FRAMERATES; ++f)
1032  {
1033  error=m_pCamera->GetVideoModeAndFrameRateInfo((FlyCapture2::VideoMode)m,(FlyCapture2::FrameRate)f,&bSupported);
1034 
1035  if (error.GetType()==FlyCapture2::PGRERROR_OK && bSupported)
1036  {
1037  int vm=m;
1038 
1039  switch (vm)
1040  {
1041  case 11: vm=10; break;
1042  case 12: vm=11; break;
1043  case 13: vm=12; break;
1044  case 10: vm=13; break;
1045 
1046  case 19: vm=18; break;
1047  case 20: vm=19; break;
1048  case 21: vm=20; break;
1049  case 18: vm=21; break;
1050  }
1051 
1052  mask|=1<<vm;
1053  break;
1054  }
1055  }
1056  }
1057 
1058  if (mask & FlyCapture2::VIDEOMODE_FORMAT7)
1059  {
1060  mask &= ~(1<<FlyCapture2::VIDEOMODE_FORMAT7);
1061 
1062  bool bSupported;
1063 
1064  for (int m=FlyCapture2::MODE_0; m<FlyCapture2::NUM_MODES; ++m)
1065  {
1066  m_F7Info.mode=(FlyCapture2::Mode)m;
1067 
1068  error=m_pCamera->GetFormat7Info(&m_F7Info,&bSupported);
1069  if (manage(error)) return 0;
1070 
1071  if (bSupported) mask|=1<<(1+m+FlyCapture2::VIDEOMODE_FORMAT7);
1072  }
1073  }
1074 
1075  printf("video mode mask: %x\n",mask);
1076  fflush(stdout);
1077 
1078  return mask;
1079 }
1080 // 13
1081 bool CFWCamera_DR2_2::setVideoModeDC1394(int video_mode)
1082 {
1083  if (mRawDriver) return false;
1084 
1085  m_AcqMutex.wait();
1086 
1087  printf("setVideoModeDC1394(%d)\n",video_mode);
1088 
1089  if (!m_pCamera)
1090  {
1091  m_AcqMutex.post();
1092  return false;
1093  }
1094 
1095  m_bFrameIsValid=false;
1096 
1097  error=m_pCamera->StopCapture();
1098  if (manage(error,&m_AcqMutex)) return false;
1099 
1100  if (video_mode<FlyCapture2::VIDEOMODE_FORMAT7)
1101  {
1102  switch (video_mode)
1103  {
1104  case 10: video_mode=FlyCapture2::VIDEOMODE_1024x768YUV422; break;
1105  case 11: video_mode=FlyCapture2::VIDEOMODE_1024x768RGB; break;
1106  case 12: video_mode=FlyCapture2::VIDEOMODE_1024x768Y8; break;
1107  case 13: video_mode=FlyCapture2::VIDEOMODE_800x600Y16; break;
1108 
1109  case 18: video_mode=FlyCapture2::VIDEOMODE_1600x1200YUV422; break;
1110  case 19: video_mode=FlyCapture2::VIDEOMODE_1600x1200RGB; break;
1111  case 20: video_mode=FlyCapture2::VIDEOMODE_1600x1200Y8; break;
1112  case 21: video_mode=FlyCapture2::VIDEOMODE_1280x960Y16; break;
1113  }
1114 
1115  if (!SetVideoMode((FlyCapture2::VideoMode)video_mode))
1116  {
1117  m_AcqMutex.post();
1118  return false;
1119  }
1120  }
1121  else
1122  {
1123  FlyCapture2::Mode mode=(FlyCapture2::Mode)((int)video_mode-1-(int)FlyCapture2::VIDEOMODE_FORMAT7);
1124  if (!SetF7(mode,SKIP,SKIP,SKIP,SKIP,SKIP,SKIP))
1125  {
1126  m_AcqMutex.post();
1127  return false;
1128  }
1129  }
1130 
1131  error=m_pCamera->StartCapture();
1132  if (manage(error,&m_AcqMutex)) return false;
1133 
1134  m_AcqMutex.post();
1135  return true;
1136 }
1137 // 14
1139 {
1140  FlyCapture2::VideoMode vm;
1141  FlyCapture2::FrameRate fr;
1142  error=m_pCamera->GetVideoModeAndFrameRate(&vm,&fr);
1143  if (manage(error)) return 0;
1144 
1145  if (vm==FlyCapture2::VIDEOMODE_FORMAT7)
1146  {
1147  error=m_pCamera->GetFormat7Configuration(&m_F7ImageSettings,&m_F7PacketSize,&m_F7PercentSpeed);
1148  if (manage(error)) return 0;
1149 
1150  return 1+vm+m_F7ImageSettings.mode;
1151  }
1152 
1153  switch (vm)
1154  {
1155  case 11: return 10;
1156  case 12: return 11;
1157  case 13: return 12;
1158  case 10: return 13;
1159 
1160  case 19: return 18;
1161  case 20: return 19;
1162  case 21: return 20;
1163  case 18: return 21;
1164  }
1165 
1166  return vm;
1167 }
1168 
1169 // 15
1170 unsigned int CFWCamera_DR2_2::getFPSMaskDC1394()
1171 {
1172  if (!m_pCamera) return 0;
1173 
1174  FlyCapture2::VideoMode vm;
1175  FlyCapture2::FrameRate fr;
1176  error=m_pCamera->GetVideoModeAndFrameRate(&vm,&fr);
1177  if (manage(error)) return 0;
1178 
1179  if (vm==FlyCapture2::VIDEOMODE_FORMAT7)
1180  {
1181  return 0;
1182  }
1183 
1184  bool bSupported;
1185  unsigned int mask=0;
1186 
1187  for (int f=FlyCapture2::FRAMERATE_1_875; f<FlyCapture2::NUM_FRAMERATES; ++f)
1188  {
1189  error=m_pCamera->GetVideoModeAndFrameRateInfo(vm,(FlyCapture2::FrameRate)f,&bSupported);
1190  if (error.GetType()==FlyCapture2::PGRERROR_OK && bSupported)
1191  {
1192  mask|=1<<f;
1193  }
1194  }
1195 
1196  return mask;
1197 }
1198 // 16
1199 unsigned int CFWCamera_DR2_2::getFPSDC1394()
1200 {
1201  if (!m_pCamera) return 0;
1202 
1203  FlyCapture2::VideoMode vm;
1204  FlyCapture2::FrameRate fr;
1205  error=m_pCamera->GetVideoModeAndFrameRate(&vm,&fr);
1206  if (manage(error)) return 0;
1207 
1208  if (vm==FlyCapture2::VIDEOMODE_FORMAT7)
1209  {
1210  return 0;
1211  }
1212 
1213  return fr;
1214 }
1215 // 17
1216 bool CFWCamera_DR2_2::setFPSDC1394(int fps)
1217 {
1218  m_AcqMutex.wait();
1219 
1220  if (!m_pCamera)
1221  {
1222  m_AcqMutex.post();
1223  return false;
1224  }
1225 
1226  FlyCapture2::VideoMode vm;
1227  FlyCapture2::FrameRate fr;
1228  error=m_pCamera->GetVideoModeAndFrameRate(&vm,&fr);
1229  if (manage(error,&m_AcqMutex)) return false;
1230 
1231  if (vm==FlyCapture2::VIDEOMODE_FORMAT7)
1232  {
1233  m_AcqMutex.post();
1234  return false;
1235  }
1236 
1237  error=m_pCamera->StopCapture();
1238  if (manage(error,&m_AcqMutex)) return false;
1239 
1240  error=m_pCamera->SetVideoModeAndFrameRate(vm,(FlyCapture2::FrameRate)fps);
1241  if (manage(error,&m_AcqMutex)) return false;
1242 
1243  error=m_pCamera->StartCapture();
1244  if (manage(error,&m_AcqMutex)) return false;
1245 
1246  m_AcqMutex.post();
1247  return true;
1248 }
1249 
1250 // 18
1252 {
1253  if (!m_pCamera) return 0;
1254 
1255  error=m_pCamera->GetConfiguration(&m_CamConfig);
1256  if (manage(error)) return 0;
1257 
1258  if (m_CamConfig.isochBusSpeed>FlyCapture2::BUSSPEED_S400)
1259  {
1260  return (int)m_CamConfig.isochBusSpeed-1;
1261  }
1262 
1263  return (int)m_CamConfig.isochBusSpeed;
1264 }
1265 // 19
1266 bool CFWCamera_DR2_2::setISOSpeedDC1394(int speed)
1267 {
1268  m_AcqMutex.wait();
1269 
1270  if (!m_pCamera)
1271  {
1272  m_AcqMutex.post();
1273  return false;
1274  }
1275 
1276  m_bFrameIsValid=false;
1277 
1278  error=m_pCamera->StopCapture();
1279  if (manage(error,&m_AcqMutex)) return false;
1280 
1281  FlyCapture2::VideoMode vm;
1282  FlyCapture2::FrameRate fr;
1283  error=m_pCamera->GetVideoModeAndFrameRate(&vm,&fr);
1284  if (manage(error,&m_AcqMutex)) return false;
1285 
1286  error=m_pCamera->GetConfiguration(&m_CamConfig);
1287  if (manage(error,&m_AcqMutex)) return false;
1288 
1289  if (speed>FlyCapture2::BUSSPEED_S400) ++speed;
1290 
1291  m_CamConfig.isochBusSpeed=(FlyCapture2::BusSpeed)speed;
1292 
1293  error=m_pCamera->SetConfiguration(&m_CamConfig);
1294  if (manage(error,&m_AcqMutex)) return false;
1295 
1296  if (vm<FlyCapture2::VIDEOMODE_FORMAT7)
1297  {
1298  if (!SetVideoMode(vm))
1299  {
1300  m_AcqMutex.post();
1301  return false;
1302  }
1303  }
1304  else
1305  {
1306  if (!SetF7(SKIP,SKIP,SKIP,SKIP,SKIP,SKIP,SKIP))
1307  {
1308  m_AcqMutex.post();
1309  return false;
1310  }
1311  }
1312 
1313  error=m_pCamera->StartCapture();
1314  if (manage(error,&m_AcqMutex)) return false;
1315 
1316  m_AcqMutex.post();
1317  return true;
1318 }
1319 
1320 // 20
1321 unsigned int CFWCamera_DR2_2::getColorCodingMaskDC1394(unsigned int video_mode)
1322 {
1323  if (!m_pCamera) return 0;
1324 
1325  if (mRawDriver) return 1<<9;
1326 
1327  if (video_mode<FlyCapture2::VIDEOMODE_FORMAT7)
1328  {
1329  return 0;
1330  }
1331 
1332  bool bSupported;
1333  m_F7Info.mode=(FlyCapture2::Mode)(video_mode-1-FlyCapture2::VIDEOMODE_FORMAT7);
1334 
1335  error=m_pCamera->GetFormat7Info(&m_F7Info,&bSupported);
1336  if (manage(error)) return 0;
1337 
1338  if (!bSupported)
1339  {
1340  return 0;
1341  }
1342 
1343  unsigned int mask=0;
1344 
1345  for (int i=0; i<32; ++i)
1346  {
1347  if (m_F7Info.pixelFormatBitField & (1<<i))
1348  {
1349  mask |= (1<<(31-i));
1350  }
1351  }
1352 
1353  return mask;
1354 }
1355 
1357 {
1358  if (!m_pCamera) return 0;
1359 
1360  if (mRawDriver) return 1<<9;
1361 
1362  FlyCapture2::VideoMode vm;
1363  FlyCapture2::FrameRate fr;
1364  error=m_pCamera->GetVideoModeAndFrameRate(&vm,&fr);
1365  if (manage(error)) return 0;
1366 
1367  if (vm<FlyCapture2::VIDEOMODE_FORMAT7)
1368  {
1369  return 0;
1370  }
1371 
1372  error=m_pCamera->GetFormat7Configuration(&m_F7ImageSettings,&m_F7PacketSize,&m_F7PercentSpeed);
1373  if (manage(error)) return 0;
1374 
1375  bool bSupported;
1376  m_F7Info.mode=m_F7ImageSettings.mode;
1377 
1378  error=m_pCamera->GetFormat7Info(&m_F7Info,&bSupported);
1379  if (manage(error)) return 0;
1380 
1381  if (!bSupported)
1382  {
1383  return 0;
1384  }
1385 
1386  return m_F7Info.pixelFormatBitField;
1387 }
1388 
1389 // 21
1391 {
1392  if (!m_pCamera) return 0;
1393 
1394  FlyCapture2::VideoMode vm;
1395  FlyCapture2::FrameRate fr;
1396  error=m_pCamera->GetVideoModeAndFrameRate(&vm,&fr);
1397  if (manage(error)) return 0;
1398 
1399  if (vm!=FlyCapture2::VIDEOMODE_FORMAT7)
1400  {
1401  return 0;
1402  }
1403 
1404  error=m_pCamera->GetFormat7Configuration(&m_F7ImageSettings,&m_F7PacketSize,&m_F7PercentSpeed);
1405  if (manage(error)) return 0;
1406 
1407  for (int i=0; i<32; ++i)
1408  {
1409  if ((1<<i) & m_F7ImageSettings.pixelFormat)
1410  {
1411  return 31-i;
1412  }
1413  }
1414 
1415  return 0;
1416 }
1417 // 22
1419 {
1420  if (mRawDriver) return false;
1421 
1422  m_AcqMutex.wait();
1423 
1424  fprintf(stdout,"setColorCodingDC1394(%d)\n",coding);
1425 
1426  if (!m_pCamera)
1427  {
1428  m_AcqMutex.post();
1429  return false;
1430  }
1431 
1432  m_bFrameIsValid=false;
1433 
1434  error=m_pCamera->StopCapture();
1435  if (manage(error,&m_AcqMutex)) return false;
1436 
1437  FlyCapture2::PixelFormat pixel_format=(FlyCapture2::PixelFormat)(1<<(31-coding));
1438 
1439  if (!SetF7(SKIP,SKIP,SKIP,pixel_format,SKIP,SKIP,SKIP))
1440  {
1441  m_AcqMutex.post();
1442  return false;
1443  }
1444 
1445  error=m_pCamera->StartCapture();
1446  if (manage(error,&m_AcqMutex)) return false;
1447 
1448  m_AcqMutex.post();
1449  return true;
1450 }
1451 
1452 // 25
1453 bool CFWCamera_DR2_2::getFormat7MaxWindowDC1394(unsigned int &xdim,unsigned int &ydim,unsigned int &xstep,unsigned int &ystep,unsigned int &xoffstep,unsigned int &yoffstep)
1454 {
1455  if (!m_pCamera) return false;
1456 
1457  FlyCapture2::VideoMode vm;
1458  FlyCapture2::FrameRate fr;
1459  error=m_pCamera->GetVideoModeAndFrameRate(&vm,&fr);
1460  if (manage(error)) return false;
1461 
1462  if (vm!=FlyCapture2::VIDEOMODE_FORMAT7)
1463  {
1464  xdim=ydim=xstep=ystep=0;
1465  return true;
1466  }
1467 
1468  error=m_pCamera->GetFormat7Configuration(&m_F7ImageSettings,&m_F7PacketSize,&m_F7PercentSpeed);
1469  if (manage(error)) return false;
1470 
1471  m_F7Info.mode=m_F7ImageSettings.mode;
1472  bool m_bSupported;
1473  error=m_pCamera->GetFormat7Info(&m_F7Info,&m_bSupported);
1474  if (manage(error)) return false;
1475 
1476  if (!m_bSupported)
1477  {
1478  return false;
1479  }
1480 
1481  xdim=m_F7Info.maxWidth;
1482  ydim=m_F7Info.maxHeight;
1483 
1484  xstep=m_F7Info.imageHStepSize;
1485  ystep=m_F7Info.imageVStepSize;
1486 
1487  xoffstep=m_F7Info.offsetHStepSize;
1488  yoffstep=m_F7Info.offsetVStepSize;
1489 
1490  if (m_F7Info.mode==1) xstep*=2;
1491 
1492  return true;
1493 }
1494 // 26
1495 bool CFWCamera_DR2_2::setFormat7WindowDC1394(unsigned int xdim,unsigned int ydim,int x0,int y0)
1496 {
1497  m_AcqMutex.wait();
1498 
1499  yInfo("setFormat7WindowDC1394(%d,%d)\n",xdim,ydim);
1500 
1501  if (!m_pCamera)
1502  {
1503  m_AcqMutex.post();
1504  return false;
1505  }
1506 
1507  m_bFrameIsValid=false;
1508 
1509  error=m_pCamera->StopCapture();
1510  if (manage(error,&m_AcqMutex)) return false;
1511 
1512  if (!SetF7(SKIP,xdim,ydim,SKIP,SKIP,x0,y0))
1513  {
1514  m_AcqMutex.post();
1515  return false;
1516  }
1517 
1518  error=m_pCamera->StartCapture();
1519  if (manage(error,&m_AcqMutex)) return false;
1520 
1521  m_AcqMutex.post();
1522  return true;
1523 }
1524 // 27
1525 bool CFWCamera_DR2_2::getFormat7WindowDC1394(unsigned int &xdim,unsigned int &ydim,int &x0,int &y0)
1526 {
1527  if (!m_pCamera) return false;
1528 
1529  FlyCapture2::VideoMode vm;
1530  FlyCapture2::FrameRate fr;
1531  error=m_pCamera->GetVideoModeAndFrameRate(&vm,&fr);
1532  if (manage(error)) return false;
1533 
1534  if (vm!=FlyCapture2::VIDEOMODE_FORMAT7)
1535  {
1536  xdim=ydim=0;
1537  return true;
1538  }
1539 
1540  error=m_pCamera->GetFormat7Configuration(&m_F7ImageSettings,&m_F7PacketSize,&m_F7PercentSpeed);
1541  if (manage(error)) return false;
1542 
1543  xdim=m_F7ImageSettings.width;
1544  ydim=m_F7ImageSettings.height;
1545  x0=m_F7ImageSettings.offsetX-(m_F7Info.maxWidth -xdim)/2;
1546  y0=m_F7ImageSettings.offsetY-(m_F7Info.maxHeight-ydim)/2;
1547 
1548  return true;
1549 }
1550 
1551 // 28
1553 {
1554  return true;
1555 }
1556 
1557 // 29
1559 {
1560  return true;
1561 }
1562 
1563 // 30
1565 {
1566  if (!m_pCamera) return false;
1567 
1568  if (bTxON)
1569  {
1570  error=m_pCamera->StartCapture();
1571  if (manage(error)) return false;
1572  m_bTxOn=true;
1573  }
1574  else
1575  {
1576  error=m_pCamera->StopCapture();
1577  if (manage(error)) return false;
1578  m_bTxOn=false;
1579  }
1580 
1581  return true;
1582 }
1583 
1584 // 31
1586 {
1587  if (!m_pCamera) return false;
1588 
1589  return m_bTxOn;
1590 }
1591 
1592 // 32 setBayer
1593 // 33 getBayer
1594 
1595 // 34
1596 bool CFWCamera_DR2_2::setBroadcastDC1394(bool onoff)
1597 {
1598  if (!m_pCamera) return false;
1599  return false;
1600 }
1601 // 35
1603 {
1604  m_AcqMutex.wait();
1605 
1606  if (!m_pCamera)
1607  {
1608  m_AcqMutex.post();
1609  return false;
1610  }
1611 
1612  m_bFrameIsValid=false;
1613 
1614  error=m_pCamera->StopCapture();
1615  if (manage(error,&m_AcqMutex)) return false;
1616 
1617  error=m_pCamera->RestoreFromMemoryChannel(0);
1618  if (manage(error,&m_AcqMutex)) return false;
1619 
1620  error=m_pCamera->StartCapture();
1621  if (manage(error,&m_AcqMutex)) return false;
1622 
1623  m_AcqMutex.post();
1624  return true;
1625 }
1626 // 36
1628 {
1629  return false;
1630 }
1631 // 37
1632 bool CFWCamera_DR2_2::setPowerDC1394(bool onoff)
1633 {
1634  return false;
1635 }
1636 
1637 // 38
1638 bool CFWCamera_DR2_2::setCaptureDC1394(bool bON)
1639 {
1640  if (!m_pCamera) return false;
1641 
1642  if (bON)
1643  {
1644  error=m_pCamera->StartCapture();
1645  if (manage(error)) return false;
1646  m_bTxOn=true;
1647  }
1648  else
1649  {
1650  error=m_pCamera->StopCapture();
1651  if (manage(error)) return false;
1652  m_bTxOn=false;
1653  }
1654 
1655  return true;
1656 }
1657 
1658 // 39
1660 {
1661  if (!m_pCamera) return 0;
1662 
1663  FlyCapture2::VideoMode vm;
1664  FlyCapture2::FrameRate fr;
1665  error=m_pCamera->GetVideoModeAndFrameRate(&vm,&fr);
1666  if (manage(error)) return 0;
1667 
1668  if (vm!=FlyCapture2::VIDEOMODE_FORMAT7)
1669  {
1670  return 0;
1671  }
1672 
1673  error=m_pCamera->GetFormat7Configuration(&m_F7ImageSettings,&m_F7PacketSize,&m_F7PercentSpeed);
1674  if (manage(error)) return 0;
1675 
1676  //printf("\n 2 Packet size=%d - Speed=%f\n\n",m_F7PacketSize,m_F7PercentSpeed);
1677 
1678  return (unsigned int)(m_F7PercentSpeed);
1679 }
1680 
1681 // 40
1682 bool CFWCamera_DR2_2::setBytesPerPacketDC1394(unsigned int bpp)
1683 {
1684  m_AcqMutex.wait();
1685 
1686  yInfo("setBytesPerPacketDC1394(%d)\n",bpp);
1687 
1688  if (!m_pCamera)
1689  {
1690  m_AcqMutex.post();
1691  return false;
1692  }
1693 
1694  m_bFrameIsValid=false;
1695 
1696  error=m_pCamera->StopCapture();
1697  if (manage(error,&m_AcqMutex)) return false;
1698 
1699  if (!SetF7(SKIP,SKIP,SKIP,SKIP,(int)bpp,SKIP,SKIP))
1700  {
1701  m_AcqMutex.post();
1702  return false;
1703  }
1704 
1705  error=m_pCamera->StartCapture();
1706  if (manage(error,&m_AcqMutex)) return false;
1707 
1708  m_AcqMutex.post();
1709  return true;
1710 }
1711 
1712 // base class implementation
1713 
1714 bool CFWCamera_DR2_2::setBrightness(double v)
1715 {
1716  if (v<0.0 || v>1.0) return false;
1717  setActiveDC1394(YARP_FEATURE_BRIGHTNESS,true);
1718  setModeDC1394(YARP_FEATURE_BRIGHTNESS,false);
1719  return setFeatureDC1394(YARP_FEATURE_BRIGHTNESS,v);
1720 }
1721 bool CFWCamera_DR2_2::setExposure(double v)
1722 {
1723  if (v<0.0 || v>1.0) return false;
1724  setActiveDC1394(YARP_FEATURE_EXPOSURE,true);
1725  setModeDC1394(YARP_FEATURE_EXPOSURE,false);
1726  return setFeatureDC1394(YARP_FEATURE_EXPOSURE,v);
1727 }
1728 bool CFWCamera_DR2_2::setSharpness(double v)
1729 {
1730  if (v<0.0 || v>1.0) return false;
1731  setActiveDC1394(YARP_FEATURE_SHARPNESS,true);
1732  setModeDC1394(YARP_FEATURE_SHARPNESS,false);
1733  return setFeatureDC1394(YARP_FEATURE_SHARPNESS,v);
1734 }
1735 bool CFWCamera_DR2_2::setWhiteBalance(double blue, double red)
1736 {
1737  if (blue<0.0 || blue>1.0 || red<0.0 || red>1.0) return false;
1738  setActiveDC1394(YARP_FEATURE_WHITE_BALANCE,true);
1739  setModeDC1394(YARP_FEATURE_WHITE_BALANCE,false);
1740  return setWhiteBalanceDC1394(blue,red);
1741 }
1742 bool CFWCamera_DR2_2::setHue(double v)
1743 {
1744  if (v<0.0 || v>1.0) return false;
1745  setActiveDC1394(YARP_FEATURE_HUE,true);
1746  setModeDC1394(YARP_FEATURE_HUE,false);
1747  return setFeatureDC1394(YARP_FEATURE_HUE,v);
1748 }
1749 bool CFWCamera_DR2_2::setSaturation(double v)
1750 {
1751  if (v<0.0 || v>1.0) return false;
1752  setActiveDC1394(YARP_FEATURE_SATURATION,true);
1753  setModeDC1394(YARP_FEATURE_SATURATION,false);
1754  return setFeatureDC1394(YARP_FEATURE_SATURATION,v);
1755 }
1756 bool CFWCamera_DR2_2::setGamma(double v)
1757 {
1758  if (v<0.0 || v>1.0) return false;
1759  setActiveDC1394(YARP_FEATURE_GAMMA,true);
1760  setModeDC1394(YARP_FEATURE_GAMMA,false);
1761  return setFeatureDC1394(YARP_FEATURE_GAMMA,v);
1762 }
1763 bool CFWCamera_DR2_2::setShutter(double v)
1764 {
1765  if (v<0.0 || v>1.0) return false;
1766  setActiveDC1394(YARP_FEATURE_SHUTTER,true);
1767  setModeDC1394(YARP_FEATURE_SHUTTER,false);
1768  return setFeatureDC1394(YARP_FEATURE_SHUTTER,v);
1769 }
1770 bool CFWCamera_DR2_2::setGain(double v)
1771 {
1772  if (v<0.0 || v>1.0) return false;
1773  setActiveDC1394(YARP_FEATURE_GAIN,true);
1774  setModeDC1394(YARP_FEATURE_GAIN,false);
1775  return setFeatureDC1394(YARP_FEATURE_GAIN,v);
1776 }
1777 bool CFWCamera_DR2_2::setIris(double v)
1778 {
1779  if (v<0.0 || v>1.0) return false;
1780  setActiveDC1394(YARP_FEATURE_IRIS,true);
1781  setModeDC1394(YARP_FEATURE_IRIS,false);
1782  return setFeatureDC1394(YARP_FEATURE_IRIS,v);
1783 }
1784 
1785 // GET
1786 
1788 {
1789  return getFeatureDC1394(YARP_FEATURE_BRIGHTNESS);
1790 }
1792 {
1793  return getFeatureDC1394(YARP_FEATURE_EXPOSURE);
1794 }
1796 {
1797  return getFeatureDC1394(YARP_FEATURE_SHARPNESS);
1798 }
1799 bool CFWCamera_DR2_2::getWhiteBalance(double &blue, double &red)
1800 {
1801  return getWhiteBalance(blue,red);
1802 }
1804 {
1805  return getFeatureDC1394(YARP_FEATURE_HUE);
1806 }
1808 {
1809  return CFWCamera_DR2_2::getFeatureDC1394(YARP_FEATURE_SATURATION);
1810 }
1812 {
1813  return getFeatureDC1394(YARP_FEATURE_GAMMA);
1814 }
1816 {
1817  return getFeatureDC1394(YARP_FEATURE_SHUTTER);
1818 }
1819 double CFWCamera_DR2_2::getGain()
1820 {
1821  return getFeatureDC1394(YARP_FEATURE_GAIN);
1822 }
1823 double CFWCamera_DR2_2::getIris()
1824 {
1825  return getFeatureDC1394(YARP_FEATURE_IRIS);
1826 }
virtual bool setModeDC1394(int feature, bool auto_onoff)
virtual bool setTransmissionDC1394(bool bTxON)
virtual unsigned int getISOSpeedDC1394()
bool Capture(yarp::sig::ImageOf< yarp::sig::PixelRgb > *pImage, unsigned char *pBuffer=0, bool bRaw=false)
virtual unsigned int getFPSDC1394()
FlyCapture2::Error error
virtual unsigned int getColorCodingDC1394()
bool SetVideoMode(dc1394video_mode_t videoMode)
uint32_t m_iMax[DC1394_FEATURE_NUM]
FlyCapture2::BusManager * m_pBusManager
double checkDouble(yarp::os::Searchable &config, const char *key)
uint32_t NormToValue(double &dVal, int feature)
virtual bool hasFeatureDC1394(int feature)
virtual bool getWhiteBalanceDC1394(double &b, double &r)
bool SetF7(int newVideoMode, int newXdim, int newYdim, int newColorCoding, int newSpeed, int x0, int y0)
virtual unsigned int getVideoModeMaskDC1394()
virtual bool setPowerDC1394(bool onoff)
virtual bool setHue(double v)
virtual bool setShutter(double v)
virtual unsigned int getBytesPerPacketDC1394()
virtual bool setWhiteBalanceDC1394(double b, double r)
virtual unsigned int getVideoModeDC1394()
virtual bool setCaptureDC1394(bool bON)
virtual bool setBrightness(double v)
bool manage(dc1394error_t error)
FlyCapture2::Format7ImageSettings m_F7ImageSettings
virtual bool setFeatureDC1394(int feature, double value)
virtual bool getWhiteBalance(double &blue, double &red)
virtual bool hasOnePushDC1394(int feature)
double ValueToNorm(uint32_t iVal, int feature)
virtual bool getFormat7WindowDC1394(unsigned int &xdim, unsigned int &ydim, int &x0, int &y0)
virtual bool setOperationModeDC1394(bool b1394b)
virtual bool setBytesPerPacketDC1394(unsigned int bpp)
virtual unsigned int getFPSMaskDC1394()
FlyCapture2::Image * m_pBayer
virtual bool hasAutoDC1394(int feature)
FlyCapture2::Format7Info m_F7Info
virtual bool setBroadcastDC1394(bool onoff)
FlyCapture2::CameraInfo m_CameraInfo
double bytesPerPixel(dc1394color_coding_t pixelFormat)
virtual bool setExposure(double v)
virtual bool setSharpness(double v)
uint32_t m_iMin[DC1394_FEATURE_NUM]
int checkInt(yarp::os::Searchable &config, const char *key)
virtual bool hasManualDC1394(int feature)
virtual double getFeatureDC1394(int feature)
virtual unsigned int getActualColorCodingMaskDC1394()
virtual bool getFormat7MaxWindowDC1394(unsigned int &xdim, unsigned int &ydim, unsigned int &xstep, unsigned int &ystep, unsigned int &xoffstep, unsigned int &yoffstep)
dc1394video_frame_t * m_pFrame
virtual bool setGamma(double v)
virtual bool setActiveDC1394(int feature, bool onoff)
virtual bool setIris(double v)
virtual bool setFPSDC1394(int fps)
virtual unsigned int getColorCodingMaskDC1394(unsigned int video_mode)
virtual bool hasOnOffDC1394(int feature)
virtual bool getActiveDC1394(int feature)
virtual bool setISOSpeedDC1394(int speed)
virtual bool setColorCodingDC1394(int coding)
virtual bool getModeDC1394(int feature)
FlyCapture2::FC2Config m_CamConfig
virtual bool setFormat7WindowDC1394(unsigned int xdim, unsigned int ydim, int x0, int y0)
virtual bool setWhiteBalance(double blue, double red)
virtual bool setVideoModeDC1394(int video_mode)
int maxFPS(dc1394video_mode_t mode, dc1394color_coding_t pixelFormat)
virtual bool setOnePushDC1394(int feature)
virtual bool setSaturation(double v)
bool Create(yarp::os::Searchable &config)
virtual bool setGain(double v)
#define NUM_DMA_BUFFERS
#define DR_UNINIT
fprintf(fid,'\n')
#define NOT_PRESENT
#define DR_RGB_FULL_RES
#define DR_BAYER_FULL_RES
#define DR_RGB_HALF_RES