summaryrefslogtreecommitdiff
path: root/noncore/multimedia/camera/mainwindow.cpp
Side-by-side diff
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 @@
#include "imageio.h"
+#include "avi.h"
@@ -52,5 +53,9 @@ using namespace Opie;
#define CAPTUREFILE "/tmp/capture.dat"
+#define OUTPUTFILE "/tmp/output.avi"
CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f )
- :QMainWindow( parent, name, f ), _capturing( false ), _pics( 0 )
+ :QMainWindow( parent, name, f ),
+ _rotation( 270 ), // FIXME: get this from current settings (ODevice?)
+ _capturing( false ),
+ _pics( 0 ), _videos( 0 )
{
@@ -107,4 +112,4 @@ void CameraMainWindow::init()
zoom = 1;
- captureX = 640;
- captureY = 480;
+ captureX = 480;
+ captureY = 640;
captureFormat = "JPEG";
@@ -163,2 +168,4 @@ void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& dat
{
+ int _newrotation;
+
QDataStream stream( data, IO_ReadOnly );
@@ -167,6 +174,6 @@ void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& dat
{
- stream >> _rotation;
- odebug << "received setCurrentRotation(" << _rotation << ")" << oendl;
+ stream >> _newrotation;
+ odebug << "received setCurrentRotation(" << _newrotation << ")" << oendl;
- switch ( _rotation )
+ switch ( _newrotation )
{
@@ -178,2 +185,13 @@ void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& dat
}
+
+ if ( _newrotation != _rotation )
+ {
+ int tmp = captureX;
+ captureX = captureY;
+ captureY = tmp;
+ _rotation = _newrotation;
+ }
+
+ updateCaption();
+
}
@@ -225,2 +243,7 @@ void CameraMainWindow::showContextMenu()
m.insertItem( "&Output As", &output );
+
+ #ifndef QT_NO_DEBUG
+ m.insertItem( "&Debug!", this, SLOT( doSomething() ) );
+ #endif
+
m.exec( QCursor::pos() );
@@ -231,4 +254,16 @@ void CameraMainWindow::resoMenuItemClicked( QAction* a )
{
- captureX = a->text().left(3).toInt();
- captureY = a->text().right(3).toInt();
+ switch ( _rotation )
+ {
+ case 270:
+ captureY = a->text().left(3).toInt();
+ captureX = a->text().right(3).toInt();
+ break;
+ case 180:
+ captureX = a->text().left(3).toInt();
+ captureY = a->text().right(3).toInt();
+ break;
+ default: QMessageBox::warning( this, "opie-camera",
+ "This rotation is not supported.\n"
+ "Supported are 180° and 270°" );
+ }
odebug << "Capture Resolution now: " << captureX << ", " << captureY << oendl;
@@ -327,3 +362,3 @@ void CameraMainWindow::startVideoCapture()
- _capturefd = ::open( CAPTUREFILE, O_WRONLY | O_CREAT );
+ _capturefd = ::open( CAPTUREFILE, O_WRONLY | O_CREAT | O_TRUNC );
if ( _capturefd == -1 )
@@ -337,2 +372,3 @@ void CameraMainWindow::startVideoCapture()
_videopics = 0;
+ _framerate = 0;
updateCaption();
@@ -348,3 +384,3 @@ void CameraMainWindow::timerEvent( QTimerEvent* )
{
- owarn << "timer event in CameraMainWindow without capturing video ?" << oendl;
+ odebug << "timer event in CameraMainWindow without capturing video ?" << oendl;
return;
@@ -352,2 +388,4 @@ void CameraMainWindow::timerEvent( QTimerEvent* )
+ odebug << "timer event during video - now capturing frame #" << _videopics+1 << oendl;
+
ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, _capturebuf );
@@ -368,4 +406,5 @@ void CameraMainWindow::stopVideoCapture()
::close( _capturefd );
+ _framerate = 1000.0 / (_time.elapsed()/_videopics);
- //postProcessVideo();
+ postProcessVideo( CAPTUREFILE, QString().sprintf( "/tmp/video-%d_%d_%d_q%d-%dfps.avi", _videos++, captureX, captureY, quality, _framerate ) );
@@ -380,3 +419,3 @@ void CameraMainWindow::stopVideoCapture()
-void CameraMainWindow::postProcessVideo()
+void CameraMainWindow::postProcessVideo( const QString& infile, const QString& outfile )
{
@@ -385,4 +424,16 @@ void CameraMainWindow::postProcessVideo()
/*
+ unsigned char buf[153600];
- QDialog* fr = new QDialog( this, "splash" ); //, false, QWidget::WStyle_NoBorder | QWidget::WStyle_Customize );
+ int fd = ::open( "/var/compile/opie/noncore/multimedia/camera/capture-320x240.dat", O_RDONLY );
+ ::read( fd, &buf, 153600 );
+ QImage i;
+ bufferToImage( 240, 320, (unsigned char*) &buf, &i );
+ QPixmap p;
+ p.convertFromImage( i );
+ preview->setPixmap( p );
+ imageToFile( &i, "/tmp/tmpfile", "JPEG", 100 );
+ return;
+ */
+
+ QDialog* fr = new QDialog( this, "splash", false, QWidget::WStyle_StaysOnTop ); //, false, QWidget::WStyle_NoBorder | QWidget::WStyle_Customize );
fr->setCaption( "Please wait..." );
@@ -396,14 +447,10 @@ void CameraMainWindow::postProcessVideo()
fr->show();
+ label->show();
+ bar->show();
+ fr->repaint();
qApp->processEvents();
- for ( int i = 0; i < _videopics; ++i )
- {
- label->setText( QString().sprintf( "Post processing frame %d / %d", i+1, _videopics ) );
- bar->setProgress( i );
- qApp->processEvents();
- }
-
- */
+ // open files
- int infd = ::open( CAPTUREFILE, O_RDONLY );
+ int infd = ::open( (const char*) infile, O_RDONLY );
if ( infd == -1 )
@@ -414,3 +461,3 @@ void CameraMainWindow::postProcessVideo()
- int outfd = ::open( "/tmp/output.avi", O_WRONLY );
+ int outfd = ::open( (const char*) outfile, O_CREAT | O_WRONLY | O_TRUNC, 0644 );
if ( outfd == -1 )
@@ -421,4 +468,60 @@ void CameraMainWindow::postProcessVideo()
+ int framesize = captureX*captureY*2;
+
+ unsigned char* inbuffer = new unsigned char[ framesize ];
+ QImage image;
+ avi_start( outfd, _videopics ); // write preambel
+ // post process
+
+ for ( int i = 0; i < _videopics; ++i )
+ {
+ odebug << "processing frame " << i << oendl;
+
+ // <gui>
+ label->setText( QString().sprintf( "Post processing frame %d / %d", i+1, _videopics ) );
+ bar->setProgress( i );
+ bar->repaint();
+ qApp->processEvents();
+ // </gui>
+
+ int read = ::read( infd, inbuffer, framesize );
+ odebug << "read " << read << " bytes" << oendl;
+ bufferToImage( captureX, captureY, inbuffer, &image );
+
+ QPixmap p;
+ p.convertFromImage( image );
+ preview->setPixmap( p );
+ preview->repaint();
+ qApp->processEvents();
+
+ QString tmpfilename( "/tmp/tempfile" );
+ //tmpfilename.sprintf( "/tmp/test/%d.jpg", i );
+
+ imageToFile( &image, tmpfilename, "JPEG", quality );
+
+ QFile framefile( tmpfilename );
+ if ( !framefile.open( IO_ReadOnly ) )
+ {
+ oerr << "can't process file: %s" << strerror(errno) << oendl;
+ return; // TODO: clean up temp ressources
+ }
+
+ int filesize = framefile.size();
+ odebug << "filesize for frame " << i << " = " << filesize << oendl;
+
+ unsigned char* tempbuffer = new unsigned char[ filesize ];
+ framefile.readBlock( (char*) tempbuffer, filesize );
+ avi_add( outfd, tempbuffer, filesize );
+ delete tempbuffer;
+ framefile.close();
+ }
+
+ avi_end( outfd, captureX, captureY, _framerate );
+
+ fr->hide();
+ delete fr;
+
+ updateCaption();
@@ -426,2 +529,3 @@ void CameraMainWindow::postProcessVideo()
+
void CameraMainWindow::updateCaption()
@@ -435 +539,13 @@ void CameraMainWindow::updateCaption()
+#ifndef QT_NO_DEBUG
+void CameraMainWindow::doSomething()
+{
+ captureX = 240;
+ captureY = 320;
+ _videopics = 176;
+ _framerate = 5;
+ postProcessVideo( "/var/compile/opie/noncore/multimedia/camera/capture-320x240.dat",
+ "/tmp/output.avi" );
+}
+#endif
+