source: pacpusframework/branches/2.0-beta1/src/TestComponents/Video/sensor/Camera1394.cpp@ 94

Last change on this file since 94 was 94, checked in by DHERBOMEZ Gérald, 11 years ago

fix windows

  • Property svn:executable set to *
File size: 22.8 KB
Line 
1/*********************************************************************
2// created: 2006/06/08 - 21:47
3// filename: Camera1394.cpp
4//
5// author: Gerald Dherbomez
6// Copyright Heudiasyc UMR UTC/CNRS 6599
7//
8// version: $Id$
9//
10// purpose: Definition of the Camera1394 class
11//
12// todo:
13*********************************************************************/
14
15#include "Camera1394.h"
16
17#include <cassert>
18#include <iostream>
19#include <qimagewriter.h>
20
21#include "kernel/ComponentFactory.h"
22#include "kernel/DbiteException.h"
23#include "kernel/DbiteFileTypes.h"
24#include "kernel/Log.h"
25#include "PacpusTools/ShMem.h"
26
27using namespace pacpus;
28using namespace std;
29
30DECLARE_STATIC_LOGGER("pacpus.base.Camera1394");
31
32/// Construct the factory
33ComponentFactory<Camera1394> sFactory("Camera1394");
34
35Camera1394::Camera1394(QString name)
36 : ComponentBase(name)
37{
38 image_ = NULL;
39 qimage_ = NULL;
40 acquiring_ = FALSE;
41 recording_ = FALSE;
42
43 tr_ = 0;
44}
45
46Camera1394::~Camera1394()
47{
48 // verify that the camera has been initialized
49 if (theCamera->m_cameraInitialized)
50 if (theCamera->StopImageAcquisition() != CAM_SUCCESS)
51 qFatal("Problem Stopping Image Acquisition");
52
53 delete theCamera;
54 theCamera = NULL;
55 delete[] image_;
56 image_ = NULL;
57 delete qimage_;
58 qimage_ = NULL;
59}
60
61//////////////////////////////////////////////////////////////////////////
62// Configure the component
63// Parameters are:
64// - node: the number of the camera in the driver list. Normally, node 0
65// is for the first camera connected, node is incremented for other
66//////////////////////////////////////////////////////////////////////////
67ComponentBase::COMPONENT_CONFIGURATION Camera1394::configureComponent(XmlComponentConfig config)
68{
69 cameraNode_ = param.getProperty("node").toInt();
70 videoFormat_ = param.getProperty("format").toInt();
71 videoMode_ = param.getProperty("mode").toInt();
72 frameRate_ = param.getProperty("framerate").toInt();
73 recording_ = (param.getProperty("recording") == "true" ? true : false );
74 recordFormat_ = param.getProperty("recordFormat");
75 reverseImage_ = (param.getProperty("reverseImage") == "true" ? true : false);
76 displaying_ = (param.getProperty("display") == "true" ? true : false);
77 zoom_ = param.getProperty("zoom").toInt();
78
79 imageMutex_ = new QMutex;
80
81/* if (displaying_)
82 {
83 viewer_ = new ImageViewer;
84 viewer_->setMutex(imageMutex_);
85 viewer_->show();
86 viewer_->setWindowTitle(componentName);
87 connect(this, SIGNAL( newImage(QImage*) ), viewer_, SLOT( display(QImage*) ) );
88 }*/
89
90 return ComponentBase::CONFIGURED_OK;
91}
92
93//////////////////////////////////////////////////////////////////////////
94// Stop the acquisition of data
95//////////////////////////////////////////////////////////////////////////
96void Camera1394::stopActivity()
97{
98 stopAcquiring();
99
100 // wait the thread termination
101 if (!wait(1000)) {
102 LOG_ERROR(componentName << ":The thread doesn't respond for 1 second, it has been terminated");
103 terminate();
104 }
105
106 file_.close();
107}
108
109//////////////////////////////////////////////////////////////////////////
110// Start the camera
111// Set all video parameters (resolution, mode and framerate)
112//////////////////////////////////////////////////////////////////////////
113void Camera1394::startActivity()
114{
115 try {
116 QString dbtFileName_ = componentName + ".dbt";
117 file_.open(dbtFileName_.toStdString(), WriteMode, FILE_JPEG, MAX_CHAR_DIRECTORY_NAME + MAX_CHAR_PICTURE_NAME);
118 } catch (DbiteException & e) {
119 cerr << "error opening dbt file: " << e.what() << endl;
120 return;
121 }
122
123 initCamera();
124
125 if (theCamera->m_videoFlags[videoFormat_][videoMode_][frameRate_])
126 {
127 // set the camera parameters
128 theCamera->SetVideoFormat(videoFormat_);
129 theCamera->SetVideoMode(videoMode_);
130 theCamera->SetVideoFrameRate(frameRate_);
131 }
132 else
133 qFatal("Video format, mode or rate are bad !");
134
135 theCamera->StartImageAcquisition();
136
137 // switch some controls in Automatic mode
138 theCamera->m_controlWhiteBalance.SetAutoMode(TRUE);
139 theCamera->m_controlShutter.SetAutoMode(TRUE);
140 theCamera->m_controlGain.SetAutoMode(TRUE);
141 theCamera->m_controlIris.SetAutoMode(TRUE);
142
143 theCamera->SetZoom(zoom_);
144
145 // alloc images
146 if (!image_)
147 image_ = new unsigned char [ theCamera->m_width * theCamera->m_height * 3];
148 if (!qimage_)
149 qimage_ = new QImage( theCamera->m_width , theCamera->m_height, QImage::Format_RGB32 );
150
151 startAcquiring();
152 start();
153}
154
155
156
157
158//////////////////////////////////////////////////////////////////////////
159// Initialize the C1394Camera Driver
160// Verify the presence of a compatible camera and select it
161// If it doesn't work, please have a look on the Windows driver in the
162// hardware manager
163//////////////////////////////////////////////////////////////////////////
164bool Camera1394::initCamera()
165{
166 theCamera = new C1394Camera;
167
168 qDebug("Verifying camera presence...");
169 if(theCamera->CheckLink() != CAM_SUCCESS)
170 qFatal("No camera detected !");
171
172 qDebug("Selecting Camera...");
173 switch (theCamera->SelectCamera(cameraNode_))
174 {
175 case CAM_SUCCESS :
176 qDebug("The camera has been selected and verified");
177 break;
178 case CAM_ERROR_PARAM_OUT_OF_RANGE :
179 qFatal("The node value is invalid !");
180 case CAM_ERROR :
181 qFatal("No camera available !");
182 default :
183 qFatal("Problem with SelectCamera() method");
184 }
185
186 qDebug("Initializing Camera...");
187 if (theCamera->InitCamera() != CAM_SUCCESS)
188 qFatal("Error during camera initialization !");
189
190 qDebug("Checking Feature Presence...");
191 theCamera->InquireControlRegisters();
192
193 qDebug("Checking Feature Status...");
194 theCamera->StatusControlRegisters();
195
196 qDebug("Camera Initialized");
197 char commandline[64];
198 sprintf(commandline,"mkdir %s\n",componentName.toLatin1().data());
199 system(commandline);
200 puts(commandline);
201
202 return TRUE;
203}
204
205bool Camera1394::recordImage(QString format)
206{
207 ++imageCounter_;
208
209 format = format.toLower();
210 if (format == "jpeg") {
211 format = "jpg";
212 }
213
214 bool formatSupported = false;
215 QImageWriter imageWriter;
216 if (imageWriter.supportedImageFormats().contains(format.toLatin1())) {
217 formatSupported = true;
218 }
219
220 if (!formatSupported) {
221 LOG_ERROR("Format" << format << "not supported for recording");
222 } else {
223 // write in the dbt file
224 sprintf( imageName_, componentName.toLatin1().data() );
225 sprintf( imageName_, "%s/image%d.%s", imageName_, imageCounter_, format.toLatin1().data() );
226 imageWriter.setFileName(imageName_);
227 imageWriter.setFormat( format.toLatin1() );
228 imageWriter.write(*qimage_);
229
230 // record the data in a dbt file. The dbt data is only the structure AlascaXT
231 // scan data are recording in the alasca_data.utc file
232 try {
233 file_.writeRecord(time_, tr_, reinterpret_cast<const char *>(&imageName_), MAX_CHAR_DIRECTORY_NAME + MAX_CHAR_PICTURE_NAME);
234 } catch (DbiteException & e) {
235 cerr << "error writing data: " << e.what() << endl;
236 return false;
237 }
238 }
239 return formatSupported;
240}
241
242//#define MEASURE_TIME
243
244//////////////////////////////////////////////////////////////////////////
245// Main loop for acquisition
246//////////////////////////////////////////////////////////////////////////
247void Camera1394::run()
248{
249 bool firstTime = true;
250 ShMem * shMem;
251 imageCounter_ = 0;
252 time_ = road_time();
253
254 road_time_t t;
255
256 while (acquiring_)
257 {
258 if (theCamera->AcquireImage())
259 qFatal("Problem Acquiring Image !");
260 prevTime_ = time_;
261 time_ = road_time();
262
263 // verify that the acquisition period is good relatively to the selected format
264 if ( isPeriodGood((int)(time_ - prevTime_)) )
265 setState(MONITOR_OK);
266 else
267 setState(MONITOR_NOK);
268
269 t = road_time();
270 if ( !fillRGB32Image(qimage_->bits()) ) continue;
271
272#ifdef MEASURE_TIME
273 qDebug() << componentName << "duration conversion: " << (int)(road_time() - t) ;
274#endif
275
276 imageMutex_->lock();
277
278 t = road_time();
279 if (reverseImage_)
280 *qimage_ = qimage_->mirrored(true,true);
281
282 // send image in shared memory
283 if (firstTime) {
284// shMem = new ShMem("IMAGE", qimage_->numBytes());
285 firstTime = false;
286 }
287 assert(shMem);
288// shMem->write(qimage_->bits(), qimage_->numBytes());
289
290#ifdef MEASURE_TIME
291 qDebug() << componentName << "duration mirror: " << (int)(road_time() - t) ;
292#endif
293
294 imageMutex_->unlock();
295 emit newImage(qimage_);
296
297 t = road_time();
298 if (recording_)
299 {
300 recordImage(recordFormat_);
301 }
302#ifdef MEASURE_TIME
303 qDebug() << componentName << "duration record: " << (int)(road_time() - t) ;
304#endif
305
306 } // END while (acquiring_)
307
308 LOG_INFO(":Stopping the camera");
309 if (theCamera->StopImageAcquisition() != CAM_SUCCESS)
310 LOG_FATAL("Problem Stopping Image Acquisition");
311 if (!firstTime)
312 delete shMem;
313 setState(STOPPED);
314}
315
316
317
318
319//////////////////////////////////////////////////////////////////////////
320// return the actual period in µs corresponding to the framerate code
321//////////////////////////////////////////////////////////////////////////
322double Camera1394::getPeriod()
323{
324 switch(frameRate_) {
325 case 0:
326 return 1.0e6/1.875;
327 break;
328
329 case 1:
330 return 1.0e6/3.75;
331 break;
332
333 case 2:
334 return 1.0e6/7.5;
335 break;
336
337 case 3:
338 return 1.0e6/15;
339 break;
340
341 case 4:
342 return 1.0e6/30;
343 break;
344
345 case 5:
346 return 1.0e6/60;
347 break;
348
349 default:
350 LOG_WARN("Unknown framerate. The component " << componentName << " may encounter a problem !");
351 return 0;
352 }
353}
354
355//////////////////////////////////////////////////////////////////////////
356// retrn true if the period T corresponds to the framerate (at +/-20%)
357// T is given in microseconds
358//////////////////////////////////////////////////////////////////////////
359bool Camera1394::isPeriodGood(int T)
360{
361 float period = getPeriod();
362 if ( (T < period*0.8) || (T > period*1.2) )
363 return false;
364 else
365 return true;
366}
367
368
369
370
371//////////////////////////////////////////////////////////////////////////
372// useful macro to keep 'a' between 0 and 255
373//////////////////////////////////////////////////////////////////////////
374#define CLAMP_TO_UCHAR(a) (unsigned char)((a) < 0 ? 0 : ((a) > 255 ? 255 : (a)))
375
376
377//////////////////////////////////////////////////////////////////////////
378// Convert the image from YUV444 to RGB32
379// The image is stored using a 32-bit RGB format (0xffRRGGBB)
380//////////////////////////////////////////////////////////////////////////
381void Camera1394::YUV444toRGB32(unsigned char* buffer)
382{
383 long Y, U, V, deltaG;
384 unsigned char *srcptr, *srcend, *destptr;
385
386 // single-stage idiotproofing
387 if(theCamera->m_pData == NULL || buffer == NULL)
388 return;
389
390 srcptr = theCamera->m_pData;
391 srcend = srcptr + (theCamera->m_width * theCamera->m_height * 3);
392 destptr = buffer;
393
394 // data pattern: UYV
395 // unroll it to 4 pixels/round
396
397 while(srcptr < srcend)
398 {
399 U = (*srcptr++) - 128;
400 Y = (*srcptr++);
401 V = (*srcptr++) - 128;
402
403 deltaG = (12727 * U + 33384 * V);
404 deltaG += (deltaG > 0 ? 32768 : -32768);
405 deltaG >>= 16;
406
407 *destptr++ = CLAMP_TO_UCHAR( Y + U );
408 *destptr++ = CLAMP_TO_UCHAR( Y - deltaG );
409 *destptr++ = CLAMP_TO_UCHAR( Y + V );
410 destptr++;//A
411
412 U = (*srcptr++) - 128;
413 Y = (*srcptr++);
414 V = (*srcptr++) - 128;
415
416 deltaG = (12727 * U + 33384 * V);
417 deltaG += (deltaG > 0 ? 32768 : -32768);
418 deltaG >>= 16;
419
420 *destptr++ = CLAMP_TO_UCHAR( Y + U );
421 *destptr++ = CLAMP_TO_UCHAR( Y - deltaG );
422 *destptr++ = CLAMP_TO_UCHAR( Y + V );
423 destptr++;//A
424
425 U = (*srcptr++) - 128;
426 Y = (*srcptr++);
427 V = (*srcptr++) - 128;
428
429 deltaG = (12727 * U + 33384 * V);
430 deltaG += (deltaG > 0 ? 32768 : -32768);
431 deltaG >>= 16;
432
433 *destptr++ = CLAMP_TO_UCHAR( Y + U );
434 *destptr++ = CLAMP_TO_UCHAR( Y - deltaG );
435 *destptr++ = CLAMP_TO_UCHAR( Y + V );
436 destptr++;//A
437
438 U = (*srcptr++) - 128;
439 Y = (*srcptr++);
440 V = (*srcptr++) - 128;
441
442 deltaG = (12727 * U + 33384 * V);
443 deltaG += (deltaG > 0 ? 32768 : -32768);
444 deltaG >>= 16;
445
446 *destptr++ = CLAMP_TO_UCHAR( Y + U );
447 *destptr++ = CLAMP_TO_UCHAR( Y - deltaG );
448 *destptr++ = CLAMP_TO_UCHAR( Y + V );
449 destptr++;//A
450 }
451}
452
453
454
455//////////////////////////////////////////////////////////////////////////
456// Convert the image from YUV422 to RGB32
457// The image is stored using a 32-bit RGB format (0xffRRGGBB)
458//////////////////////////////////////////////////////////////////////////
459void Camera1394::YUV422toRGB32(unsigned char *buffer)
460{
461 long Y, U, V, deltaG;
462 unsigned char *srcptr, *srcend, *destptr;
463
464 srcptr = theCamera->m_pData;
465 srcend = srcptr + ((theCamera->m_width * theCamera->m_height) << 1);
466 destptr = buffer;
467
468 // single-stage idiotproofing
469 if(theCamera->m_pData == NULL || buffer == NULL)
470 {
471 return;
472 }
473
474 // data pattern: UYVY
475
476 while(srcptr < srcend)
477 {
478 U = *srcptr;
479 U -= 128;
480 V = *(srcptr+2);
481 V -= 128;
482
483 deltaG = (12727 * U + 33384 * V);
484 deltaG += (deltaG > 0 ? 32768 : -32768);
485 deltaG >>= 16;
486
487 Y = *(srcptr + 1);
488 *destptr++ = CLAMP_TO_UCHAR( Y + U );
489 *destptr++ = CLAMP_TO_UCHAR( Y - deltaG );
490 *destptr++ = CLAMP_TO_UCHAR( Y + V );
491 destptr++;//A
492
493
494 Y = *(srcptr + 3);
495 *destptr++ = CLAMP_TO_UCHAR( Y + U );
496 *destptr++ = CLAMP_TO_UCHAR( Y - deltaG );
497 *destptr++ = CLAMP_TO_UCHAR( Y + V );
498 destptr++;//A
499
500 srcptr += 4;
501
502 // twice in the same loop... just like halving the loop overhead
503
504 U = (*srcptr) - 128;
505 V = (*(srcptr+2)) - 128;
506
507 deltaG = (12727 * U + 33384 * V);
508 deltaG += (deltaG > 0 ? 32768 : -32768);
509 deltaG >>= 16;
510
511 Y = *(srcptr + 1);
512 *destptr++ = CLAMP_TO_UCHAR( Y + U );
513 *destptr++ = CLAMP_TO_UCHAR( Y - deltaG );
514 *destptr++ = CLAMP_TO_UCHAR( Y + V );
515 destptr++;//A
516
517 Y = *(srcptr + 3);
518 *destptr++ = CLAMP_TO_UCHAR( Y + U );
519 *destptr++ = CLAMP_TO_UCHAR( Y - deltaG );
520 *destptr++ = CLAMP_TO_UCHAR( Y + V );
521 destptr++;//A
522
523 srcptr += 4;
524
525 }
526}
527
528//////////////////////////////////////////////////////////////////////////
529// Convert the image from YUV411 to RGB32
530// The image is stored using a 32-bit RGB format (0xffRRGGBB)
531//////////////////////////////////////////////////////////////////////////
532void Camera1394::YUV411toRGB32(unsigned char *buffer)
533{
534 long Y, U, V, deltaG;
535 unsigned char *srcptr, *srcend, *destptr;
536
537 // single-stage idiotproofing
538 if(theCamera->m_pData == NULL || buffer == NULL)
539 return;
540
541 // data pattern: UYYVYY
542
543 srcptr = theCamera->m_pData;
544 srcend = srcptr + ((theCamera->m_width * theCamera->m_height * 3) >> 1);
545 destptr = buffer;
546
547 while(srcptr < srcend)
548 {
549 U = (*srcptr) - 128;
550 V = (*(srcptr+3)) - 128;
551
552 deltaG = (12727 * U + 33384 * V);
553 deltaG += (deltaG > 0 ? 32768 : -32768);
554 deltaG >>= 16;
555
556 Y = *(srcptr + 1);
557 *destptr++ = CLAMP_TO_UCHAR( Y + U );
558 *destptr++ = CLAMP_TO_UCHAR( Y - deltaG );
559 *destptr++ = CLAMP_TO_UCHAR( Y + V );
560 destptr++;//A
561
562 Y = *(srcptr + 2);
563 *destptr++ = CLAMP_TO_UCHAR( Y + U );
564 *destptr++ = CLAMP_TO_UCHAR( Y - deltaG );
565 *destptr++ = CLAMP_TO_UCHAR( Y + V );
566 destptr++;//A
567
568 Y = *(srcptr + 4);
569 *destptr++ = CLAMP_TO_UCHAR( Y + U );
570 *destptr++ = CLAMP_TO_UCHAR( Y - deltaG );
571 *destptr++ = CLAMP_TO_UCHAR( Y + V );
572 destptr++;//A
573
574 Y = *(srcptr + 5);
575 *destptr++ = CLAMP_TO_UCHAR( Y + U );
576 *destptr++ = CLAMP_TO_UCHAR( Y - deltaG );
577 *destptr++ = CLAMP_TO_UCHAR( Y + V );
578 destptr++;//A
579
580 srcptr += 6;
581 }
582}
583
584
585//////////////////////////////////////////////////////////////////////////
586// Convert the image from Y to RGB32
587// The image is stored using a 32-bit RGB format (0xffRRGGBB)
588//////////////////////////////////////////////////////////////////////////
589void Camera1394::YtoRGB32(unsigned char * buffer)
590{
591 unsigned char *srcptr, *srcend, *destptr;
592
593 srcptr = theCamera->m_pData;
594 srcend = srcptr + (theCamera->m_width * theCamera->m_height);
595 destptr = buffer;
596
597 // single-stage idiotproofing
598 if(theCamera->m_pData == NULL || buffer == NULL)
599 return;
600
601 // just Y's (monochrome)
602
603 // unroll it to 4 per cycle
604
605 while(srcptr < srcend)
606 {
607 *destptr++ = *srcptr;
608 *destptr++ = *srcptr;
609 *destptr++ = *srcptr;
610 destptr++;//A
611 srcptr++;
612
613 *destptr++ = *srcptr;
614 *destptr++ = *srcptr;
615 *destptr++ = *srcptr;
616 destptr++;//A
617 srcptr++;
618
619 *destptr++ = *srcptr;
620 *destptr++ = *srcptr;
621 *destptr++ = *srcptr;
622 destptr++;//A
623 srcptr++;
624
625 *destptr++ = *srcptr;
626 *destptr++ = *srcptr;
627 *destptr++ = *srcptr;
628 destptr++;//A
629 srcptr++;
630 }
631}
632
633
634//////////////////////////////////////////////////////////////////////////
635// Convert the image from Y16 to RGB32
636// The image is stored using a 32-bit RGB format (0xffRRGGBB)
637// 16-bit monochrome (new to spec 1.3)
638// the first of each pair of bytes is the high byte, so just copy those to RGB
639//////////////////////////////////////////////////////////////////////////
640void Camera1394::Y16toRGB32(unsigned char *buffer)
641{
642 unsigned char *srcptr, *srcend, *destptr;
643
644 srcptr = theCamera->m_pData;
645 srcend = srcptr + 2 * (theCamera->m_width * theCamera->m_height);
646 destptr = buffer;
647
648 // single-stage idiotproofing
649 if(theCamera->m_pData == NULL || buffer == NULL)
650 return;
651
652 // just Y's (monochrome, 16-bit little endian)
653
654 // unroll it to 4 per cycle
655
656 while(srcptr < srcend)
657 {
658 *destptr++ = *srcptr;
659 *destptr++ = *srcptr;
660 *destptr++ = *srcptr;
661 destptr++;//A
662 srcptr += 2;
663
664 *destptr++ = *srcptr;
665 *destptr++ = *srcptr;
666 *destptr++ = *srcptr;
667 destptr++;//A
668 srcptr += 2;
669
670 *destptr++ = *srcptr;
671 *destptr++ = *srcptr;
672 *destptr++ = *srcptr;
673 destptr++;//A
674 srcptr += 2;
675
676 *destptr++ = *srcptr;
677 *destptr++ = *srcptr;
678 *destptr++ = *srcptr;
679 destptr++;//A
680 srcptr += 2;
681 }
682}
683
684
685
686//////////////////////////////////////////////////////////////////////////
687// Convert the image from RGB16 to RGB32
688// The image is stored using a 32-bit RGB format (0xffRRGGBB)
689// 16-bit RGB (new to spec 1.3)
690// the first of each pair of bytes is the high byte, so just copy those to RGB
691// near duplicate of Y16toRGB
692//////////////////////////////////////////////////////////////////////////
693void Camera1394::RGB16toRGB32(unsigned char * buffer)
694{
695 unsigned char *srcptr, *srcend, *destptr;
696
697 srcptr = theCamera->m_pData;
698 srcend = srcptr + 6 * (theCamera->m_width * theCamera->m_height);
699 destptr = buffer;
700
701 // single-stage idiotproofing
702 if(theCamera->m_pData == NULL || buffer == NULL)
703 return;
704
705 // R,G,B are 16-bit source, chop of the top 8 and feed
706
707 // unroll it to 3 per cycle
708
709 while(srcptr < srcend)
710 {
711 *destptr++ = *srcptr;
712 *destptr++ = *srcptr;
713 *destptr++ = *srcptr;
714 destptr++;//A
715 srcptr += 2;
716
717 *destptr++ = *srcptr;
718 *destptr++ = *srcptr;
719 *destptr++ = *srcptr;
720 destptr++;//A
721 srcptr += 2;
722
723 *destptr++ = *srcptr;
724 *destptr++ = *srcptr;
725 *destptr++ = *srcptr;
726 destptr++;//A
727 srcptr += 2;
728 }
729}
730
731
732
733//////////////////////////////////////////////////////////////////////////
734// Convert the image from RGB24 to RGB32
735// The image is stored using a 32-bit RGB format (0xffRRGGBB)
736//////////////////////////////////////////////////////////////////////////
737void Camera1394::RGB24toRGB32(unsigned char * buffer)
738{
739 unsigned char *srcptr, *srcend, *destptr;
740
741 srcptr = theCamera->m_pData;
742 srcend = srcptr + 3 * (theCamera->m_width * theCamera->m_height);
743 destptr = buffer;
744
745 // single-stage idiotproofing
746 if(theCamera->m_pData == NULL || buffer == NULL)
747 return;
748
749 // unroll it to 3 per cycle
750
751 while(srcptr < srcend)
752 {
753 *destptr++ = *(srcptr+2); //B
754 *destptr++ = *(srcptr+1); //G
755 *destptr++ = *srcptr; //R
756 destptr++;//A
757 srcptr += 3;
758
759 *destptr++ = *(srcptr+2);
760 *destptr++ = *(srcptr+1);
761 *destptr++ = *srcptr;
762 destptr++;//A
763 srcptr += 3;
764
765 *destptr++ = *(srcptr+2);
766 *destptr++ = *(srcptr+1);
767 *destptr++ = *srcptr;
768 destptr++;//A
769 srcptr += 3;
770 }
771}
772
773
774bool Camera1394::fillRGB32Image(unsigned char * buffer)
775{
776 if(buffer == NULL)
777 return false;
778
779 bool retValue = true;
780
781 switch(videoFormat_)
782 {
783 case 0:
784 switch(videoMode_)
785 {
786 case 0:
787 // 160x120 YUV444
788 YUV444toRGB32(buffer);
789 break;
790 case 1:
791 // 320x240 YUV222
792 YUV422toRGB32(buffer);
793 break;
794 case 2:
795 // 640x480 YUV411
796 YUV411toRGB32(buffer);
797 break;
798 case 3:
799 // 640x480 YUV422
800 YUV422toRGB32(buffer);
801 break;
802 case 4:
803 // 640x480 RGB
804 RGB24toRGB32(buffer);
805 //memcpy(buffer,theCamera->m_pData,640 * 480 * 3);
806 break;
807 case 5:
808 // 640x480 MONO
809 YtoRGB32(buffer);
810 break;
811 case 6:
812 // 640x480 MONO16
813 Y16toRGB32(buffer);
814 break;
815 default:
816 retValue = false;
817 qWarning("Current video mode is not supported for display and recording");
818 break;
819 } break;
820
821 case 1:
822 switch(videoMode_)
823 {
824 case 0:
825 // 800x600 YUV422
826 YUV422toRGB32(buffer);
827 break;
828 case 1:
829 // 800x600 RGB
830 memcpy(buffer,theCamera->m_pData,800 * 600 * 3);
831 break;
832 case 2:
833 // 800x600 MONO
834 YtoRGB32(buffer);
835 break;
836 case 3:
837 // 1024x768 YUV422
838 YUV422toRGB32(buffer);
839 break;
840 case 4:
841 // 1024x768 RGB
842 memcpy(buffer,theCamera->m_pData,1024 * 768 * 3);
843 break;
844 case 5:
845 // 1024x768 MONO
846 YtoRGB32(buffer);
847 break;
848 case 6:
849 // 800x600 MONO16
850 case 7:
851 // 1024x768 MONO16
852 Y16toRGB32(buffer);
853 break;
854 default:
855 retValue = false;
856 qWarning("Current video mode is not supported for display and recording");
857 break;
858 } break;
859
860 case 2:
861 switch(videoMode_)
862 {
863 case 0:
864 // 1280x960 YUV422
865 YUV422toRGB32(buffer);
866 break;
867 case 1:
868 // 1280x960 RGB
869 memcpy(buffer,theCamera->m_pData,1280 * 960 * 3);
870 break;
871 case 2:
872 // 1280x960 MONO
873 YtoRGB32(buffer);
874 break;
875 case 3:
876 // 1600x1200 YUV422
877 YUV422toRGB32(buffer);
878 break;
879 case 4:
880 // 1600x1200 RGB
881 memcpy(buffer,theCamera->m_pData,1600 * 1200 * 3);
882 break;
883 case 5:
884 // 1600x1200 MONO
885 YtoRGB32(buffer);
886 break;
887 case 6:
888 // 1280x1024 MONO16
889 case 7:
890 // 1600x1200 MONO16
891 Y16toRGB32(buffer);
892 break;
893 default:
894 retValue = false;
895 qWarning("Current video mode is not supported for display and recording");
896 break;
897 } break;
898
899 case 7:
900 switch(theCamera->m_controlSize.m_colorCode)
901 {
902 case 0:
903 // Mono8
904 YtoRGB32(buffer);
905 break;
906 case 1:
907 // YUV 411
908 YUV411toRGB32(buffer);
909 break;
910 case 2:
911 // YUV 422
912 YUV422toRGB32(buffer);
913 break;
914 case 3:
915 // YUV 444
916 YUV444toRGB32(buffer);
917 break;
918 case 4:
919 // RGB8
920 memcpy(buffer,theCamera->m_pData,1280 * 960 * 3);
921 break;
922 case 5:
923 // Mono16
924 Y16toRGB32(buffer);
925 break;
926 case 6:
927 // RGB16
928 RGB16toRGB32(buffer);
929 break;
930 default:
931 // unsupported
932 retValue = false;
933 qWarning("Current video mode is not supported for display and recording");
934 break;
935 } break;
936
937 default:
938 retValue = false;
939 qWarning("Current video mode is not supported for display and recording");
940 break;
941 }
942
943 return retValue;
944}
Note: See TracBrowser for help on using the repository browser.