summaryrefslogtreecommitdiff
path: root/noncore/multimedia/camera/mainwindow.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/camera/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/camera/mainwindow.cpp162
1 files changed, 139 insertions, 23 deletions
diff --git a/noncore/multimedia/camera/mainwindow.cpp b/noncore/multimedia/camera/mainwindow.cpp
index 6141fd1..e27a50e 100644
--- a/noncore/multimedia/camera/mainwindow.cpp
+++ b/noncore/multimedia/camera/mainwindow.cpp
@@ -19,2 +19,3 @@
19#include "imageio.h" 19#include "imageio.h"
20#include "avi.h"
20 21
@@ -52,5 +53,9 @@ using namespace Opie;
52#define CAPTUREFILE "/tmp/capture.dat" 53#define CAPTUREFILE "/tmp/capture.dat"
54#define OUTPUTFILE "/tmp/output.avi"
53 55
54CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) 56CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f )
55 :QMainWindow( parent, name, f ), _capturing( false ), _pics( 0 ) 57 :QMainWindow( parent, name, f ),
58 _rotation( 270 ), // FIXME: get this from current settings (ODevice?)
59 _capturing( false ),
60 _pics( 0 ), _videos( 0 )
56{ 61{
@@ -107,4 +112,4 @@ void CameraMainWindow::init()
107 zoom = 1; 112 zoom = 1;
108 captureX = 640; 113 captureX = 480;
109 captureY = 480; 114 captureY = 640;
110 captureFormat = "JPEG"; 115 captureFormat = "JPEG";
@@ -163,2 +168,4 @@ void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& dat
163{ 168{
169 int _newrotation;
170
164 QDataStream stream( data, IO_ReadOnly ); 171 QDataStream stream( data, IO_ReadOnly );
@@ -167,6 +174,6 @@ void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& dat
167 { 174 {
168 stream >> _rotation; 175 stream >> _newrotation;
169 odebug << "received setCurrentRotation(" << _rotation << ")" << oendl; 176 odebug << "received setCurrentRotation(" << _newrotation << ")" << oendl;
170 177
171 switch ( _rotation ) 178 switch ( _newrotation )
172 { 179 {
@@ -178,2 +185,13 @@ void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& dat
178 } 185 }
186
187 if ( _newrotation != _rotation )
188 {
189 int tmp = captureX;
190 captureX = captureY;
191 captureY = tmp;
192 _rotation = _newrotation;
193 }
194
195 updateCaption();
196
179 } 197 }
@@ -225,2 +243,7 @@ void CameraMainWindow::showContextMenu()
225 m.insertItem( "&Output As", &output ); 243 m.insertItem( "&Output As", &output );
244
245 #ifndef QT_NO_DEBUG
246 m.insertItem( "&Debug!", this, SLOT( doSomething() ) );
247 #endif
248
226 m.exec( QCursor::pos() ); 249 m.exec( QCursor::pos() );
@@ -231,4 +254,16 @@ void CameraMainWindow::resoMenuItemClicked( QAction* a )
231{ 254{
232 captureX = a->text().left(3).toInt(); 255 switch ( _rotation )
233 captureY = a->text().right(3).toInt(); 256 {
257 case 270:
258 captureY = a->text().left(3).toInt();
259 captureX = a->text().right(3).toInt();
260 break;
261 case 180:
262 captureX = a->text().left(3).toInt();
263 captureY = a->text().right(3).toInt();
264 break;
265 default: QMessageBox::warning( this, "opie-camera",
266 "This rotation is not supported.\n"
267 "Supported are 180° and 270°" );
268 }
234 odebug << "Capture Resolution now: " << captureX << ", " << captureY << oendl; 269 odebug << "Capture Resolution now: " << captureX << ", " << captureY << oendl;
@@ -327,3 +362,3 @@ void CameraMainWindow::startVideoCapture()
327 362
328 _capturefd = ::open( CAPTUREFILE, O_WRONLY | O_CREAT ); 363 _capturefd = ::open( CAPTUREFILE, O_WRONLY | O_CREAT | O_TRUNC );
329 if ( _capturefd == -1 ) 364 if ( _capturefd == -1 )
@@ -337,2 +372,3 @@ void CameraMainWindow::startVideoCapture()
337 _videopics = 0; 372 _videopics = 0;
373 _framerate = 0;
338 updateCaption(); 374 updateCaption();
@@ -348,3 +384,3 @@ void CameraMainWindow::timerEvent( QTimerEvent* )
348 { 384 {
349 owarn << "timer event in CameraMainWindow without capturing video ?" << oendl; 385 odebug << "timer event in CameraMainWindow without capturing video ?" << oendl;
350 return; 386 return;
@@ -352,2 +388,4 @@ void CameraMainWindow::timerEvent( QTimerEvent* )
352 388
389 odebug << "timer event during video - now capturing frame #" << _videopics+1 << oendl;
390
353 ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, _capturebuf ); 391 ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, _capturebuf );
@@ -368,4 +406,5 @@ void CameraMainWindow::stopVideoCapture()
368 ::close( _capturefd ); 406 ::close( _capturefd );
407 _framerate = 1000.0 / (_time.elapsed()/_videopics);
369 408
370 //postProcessVideo(); 409 postProcessVideo( CAPTUREFILE, QString().sprintf( "/tmp/video-%d_%d_%d_q%d-%dfps.avi", _videos++, captureX, captureY, quality, _framerate ) );
371 410
@@ -380,3 +419,3 @@ void CameraMainWindow::stopVideoCapture()
380 419
381void CameraMainWindow::postProcessVideo() 420void CameraMainWindow::postProcessVideo( const QString& infile, const QString& outfile )
382{ 421{
@@ -385,4 +424,16 @@ void CameraMainWindow::postProcessVideo()
385 /* 424 /*
425 unsigned char buf[153600];
386 426
387 QDialog* fr = new QDialog( this, "splash" ); //, false, QWidget::WStyle_NoBorder | QWidget::WStyle_Customize ); 427 int fd = ::open( "/var/compile/opie/noncore/multimedia/camera/capture-320x240.dat", O_RDONLY );
428 ::read( fd, &buf, 153600 );
429 QImage i;
430 bufferToImage( 240, 320, (unsigned char*) &buf, &i );
431 QPixmap p;
432 p.convertFromImage( i );
433 preview->setPixmap( p );
434 imageToFile( &i, "/tmp/tmpfile", "JPEG", 100 );
435 return;
436 */
437
438 QDialog* fr = new QDialog( this, "splash", false, QWidget::WStyle_StaysOnTop ); //, false, QWidget::WStyle_NoBorder | QWidget::WStyle_Customize );
388 fr->setCaption( "Please wait..." ); 439 fr->setCaption( "Please wait..." );
@@ -396,14 +447,10 @@ void CameraMainWindow::postProcessVideo()
396 fr->show(); 447 fr->show();
448 label->show();
449 bar->show();
450 fr->repaint();
397 qApp->processEvents(); 451 qApp->processEvents();
398 452
399 for ( int i = 0; i < _videopics; ++i ) 453 // open files
400 {
401 label->setText( QString().sprintf( "Post processing frame %d / %d", i+1, _videopics ) );
402 bar->setProgress( i );
403 qApp->processEvents();
404 }
405
406 */
407 454
408 int infd = ::open( CAPTUREFILE, O_RDONLY ); 455 int infd = ::open( (const char*) infile, O_RDONLY );
409 if ( infd == -1 ) 456 if ( infd == -1 )
@@ -414,3 +461,3 @@ void CameraMainWindow::postProcessVideo()
414 461
415 int outfd = ::open( "/tmp/output.avi", O_WRONLY ); 462 int outfd = ::open( (const char*) outfile, O_CREAT | O_WRONLY | O_TRUNC, 0644 );
416 if ( outfd == -1 ) 463 if ( outfd == -1 )
@@ -421,4 +468,60 @@ void CameraMainWindow::postProcessVideo()
421 468
469 int framesize = captureX*captureY*2;
470
471 unsigned char* inbuffer = new unsigned char[ framesize ];
472 QImage image;
422 473
474 avi_start( outfd, _videopics ); // write preambel
423 475
476 // post process
477
478 for ( int i = 0; i < _videopics; ++i )
479 {
480 odebug << "processing frame " << i << oendl;
481
482 // <gui>
483 label->setText( QString().sprintf( "Post processing frame %d / %d", i+1, _videopics ) );
484 bar->setProgress( i );
485 bar->repaint();
486 qApp->processEvents();
487 // </gui>
488
489 int read = ::read( infd, inbuffer, framesize );
490 odebug << "read " << read << " bytes" << oendl;
491 bufferToImage( captureX, captureY, inbuffer, &image );
492
493 QPixmap p;
494 p.convertFromImage( image );
495 preview->setPixmap( p );
496 preview->repaint();
497 qApp->processEvents();
498
499 QString tmpfilename( "/tmp/tempfile" );
500 //tmpfilename.sprintf( "/tmp/test/%d.jpg", i );
501
502 imageToFile( &image, tmpfilename, "JPEG", quality );
503
504 QFile framefile( tmpfilename );
505 if ( !framefile.open( IO_ReadOnly ) )
506 {
507 oerr << "can't process file: %s" << strerror(errno) << oendl;
508 return; // TODO: clean up temp ressources
509 }
510
511 int filesize = framefile.size();
512 odebug << "filesize for frame " << i << " = " << filesize << oendl;
513
514 unsigned char* tempbuffer = new unsigned char[ filesize ];
515 framefile.readBlock( (char*) tempbuffer, filesize );
516 avi_add( outfd, tempbuffer, filesize );
517 delete tempbuffer;
518 framefile.close();
519 }
520
521 avi_end( outfd, captureX, captureY, _framerate );
522
523 fr->hide();
524 delete fr;
525
526 updateCaption();
424 527
@@ -426,2 +529,3 @@ void CameraMainWindow::postProcessVideo()
426 529
530
427void CameraMainWindow::updateCaption() 531void CameraMainWindow::updateCaption()
@@ -435 +539,13 @@ void CameraMainWindow::updateCaption()
435 539
540#ifndef QT_NO_DEBUG
541void CameraMainWindow::doSomething()
542{
543 captureX = 240;
544 captureY = 320;
545 _videopics = 176;
546 _framerate = 5;
547 postProcessVideo( "/var/compile/opie/noncore/multimedia/camera/capture-320x240.dat",
548 "/tmp/output.avi" );
549}
550#endif
551