summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/camera/imageio.cpp4
-rw-r--r--noncore/multimedia/camera/mainwindow.cpp46
-rw-r--r--noncore/multimedia/camera/opie-camera.control2
3 files changed, 40 insertions, 12 deletions
diff --git a/noncore/multimedia/camera/imageio.cpp b/noncore/multimedia/camera/imageio.cpp
index f8f5dd0..ed0d39f 100644
--- a/noncore/multimedia/camera/imageio.cpp
+++ b/noncore/multimedia/camera/imageio.cpp
@@ -1,55 +1,55 @@
/**********************************************************************
** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
**
** This file is part of Opie Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
**********************************************************************/
#include "imageio.h"
#include <opie2/odebug.h>
#include <qimage.h>
void bufferToImage( int _width, int _height, unsigned char* bp, QImage* image )
{
unsigned char* p;
image->create( _width, _height, 16 );
for ( int i = 0; i < _height; ++i )
{
p = image->scanLine( i );
for ( int j = 0; j < _width; j++ )
{
*p = *bp;
p++;
bp++;
*p = *bp;
p++;
bp++;
}
}
}
void imageToFile( QImage* i, const QString& name, const QString& format, int quality )
{
QImage im = i->convertDepth( 32 );
bool result = im.save( name, format, quality );
if ( !result )
{
- oerr << "imageio-Problem while writing." << oendl;
+ oerr << "imageio-Problem while writing to " << name << oendl;
}
else
{
odebug << format << "-image has been successfully captured" << oendl;
}
-} \ No newline at end of file
+}
diff --git a/noncore/multimedia/camera/mainwindow.cpp b/noncore/multimedia/camera/mainwindow.cpp
index 16ee8bc..49c7cbf 100644
--- a/noncore/multimedia/camera/mainwindow.cpp
+++ b/noncore/multimedia/camera/mainwindow.cpp
@@ -113,99 +113,99 @@ void CameraMainWindow::init()
{
// TODO: Save this stuff in config
flip = 'A'; // auto
quality = 50;
zoom = 1;
captureX = 480;
captureY = 640;
captureFormat = "JPEG";
outputTo = "Documents Folder";
prefix = "Untitled";
appendSettings = true;
resog = new QActionGroup( 0, "reso", true );
resog->setToggleAction( true );
new QAction( " 64 x 48", 0, 0, resog, 0, true );
new QAction( "128 x 96", 0, 0, resog, 0, true );
new QAction( "192 x 144", 0, 0, resog, 0, true );
new QAction( "256 x 192", 0, 0, resog, 0, true );
new QAction( "320 x 240", 0, 0, resog, 0, true );
new QAction( "384 x 288", 0, 0, resog, 0, true );
new QAction( "448 x 336", 0, 0, resog, 0, true );
new QAction( "512 x 384", 0, 0, resog, 0, true );
new QAction( "576 x 432", 0, 0, resog, 0, true );
( new QAction( "640 x 480", 0, 0, resog, 0, true ) )->setOn( true );
qualityg = new QActionGroup( 0, "quality", true );
qualityg->setToggleAction( true );
new QAction( " 0 (&minimal)", 0, 0, qualityg, 0, true );
new QAction( " 25 (&low)", 0, 0, qualityg, 0, true );
( new QAction( " 50 (&good)", 0, 0, qualityg, 0, true ) )->setOn( true );
new QAction( " 75 (&better)", 0, 0, qualityg, 0, true );
new QAction( "100 (bes&t)", 0, 0, qualityg, 0, true );
zoomg = new QActionGroup( 0, "zoom", true );
zoomg->setToggleAction( true );
( new QAction( "x 1", 0, 0, zoomg, 0, true ) )->setOn( true );
new QAction( "x 2", 0, 0, zoomg, 0, true );
flipg = new QActionGroup( 0, "flip", true );
flipg->setToggleAction( true );
( new QAction( "Auto (recommended)", 0, 0, flipg, 0, true ) )->setOn( true );
new QAction( "0 (always off)", 0, 0, flipg, 0, true );
new QAction( "X (always horizontal)", 0, 0, flipg, 0, true );
new QAction( "Y (always vertical)", 0, 0, flipg, 0, true );
new QAction( "* (always both)", 0, 0, flipg, 0, true );
outputTog = new QActionGroup( 0, "output", true );
outputTog->setToggleAction( true );
- new QAction( "/tmp", 0, 0, outputTog, 0, true );
+ new QAction( "/tmp/", 0, 0, outputTog, 0, true );
new QAction( "/mnt/card/", 0, 0, outputTog, 0, true );
- new QAction( "/mnt/sd/", 0, 0, outputTog, 0, true );
+ new QAction( "/mnt/cf/", 0, 0, outputTog, 0, true );
docfolder = new QAction( "Documents Folder", 0, 0, outputTog, 0, true );
docfolder->setOn( true );
custom = new QAction( "&Custom...", 0, 0, outputTog, 0, true );
outputg = new QActionGroup( 0, "output", true );
outputg->setToggleAction( true );
( new QAction( "JPEG", 0, 0, outputg, 0, true ) )->setOn( true );
new QAction( "PNG", 0, 0, outputg, 0, true );
new QAction( "BMP", 0, 0, outputg, 0, true );
new QAction( "AVI", 0, 0, outputg, 0, true );
connect( resog, SIGNAL( selected(QAction*) ), this, SLOT( resoMenuItemClicked(QAction*) ) );
connect( qualityg, SIGNAL( selected(QAction*) ), this, SLOT( qualityMenuItemClicked(QAction*) ) );
connect( zoomg, SIGNAL( selected(QAction*) ), this, SLOT( zoomMenuItemClicked(QAction*) ) );
connect( flipg, SIGNAL( selected(QAction*) ), this, SLOT( flipMenuItemClicked(QAction*) ) );
connect( outputTog, SIGNAL( selected(QAction*) ), this, SLOT( outputToMenuItemClicked(QAction*) ) );
connect( outputg, SIGNAL( selected(QAction*) ), this, SLOT( outputMenuItemClicked(QAction*) ) );
}
void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data )
{
int _newrotation;
QDataStream stream( data, IO_ReadOnly );
odebug << "received system message: " << msg << oendl;
if ( msg == "setCurrentRotation(int)" )
{
stream >> _newrotation;
odebug << "received setCurrentRotation(" << _newrotation << ")" << oendl;
switch ( _newrotation )
{
case 270: preview->resize( QSize( 240, 288 ) ); break;
case 180: preview->resize( QSize( 320, 208 ) ); break;
default: QMessageBox::warning( this, "opie-camera",
"This rotation is not supported.\n"
"Supported are 180° and 270°" );
}
if ( _newrotation != _rotation )
{
int tmp = captureX;
captureX = captureY;
captureY = tmp;
_rotation = _newrotation;
}
@@ -377,288 +377,316 @@ void CameraMainWindow::outputMenuItemClicked( QAction* a )
}
void CameraMainWindow::prefixItemChoosen()
{
QDialog* d = new QDialog( this, "dialog", true );
d->setCaption( "Enter Prefix..." );
QVBoxLayout* v = new QVBoxLayout( d );
QLineEdit* le = new QLineEdit( prefix, d );
v->addWidget( le );
le->setFixedWidth( 150 ); //FIXME: 'tis a bit dirty
if ( d->exec() == QDialog::Accepted )
prefix = le->text();
odebug << "Prefix now: " << prefix << oendl;
}
void CameraMainWindow::appendSettingsChoosen()
{
appendSettings = !appendSettings;
odebug << "appendSettings now: " << appendSettings << oendl;
}
void CameraMainWindow::shutterClicked()
{
if ( captureFormat != "AVI" ) // capture one photo per shutterClick
{
Global::statusMessage( "CAPTURING..." );
qApp->processEvents();
odebug << "Shutter has been pressed" << oendl;
ODevice::inst()->touchSound();
performCapture( captureFormat );
}
else // capture video! start with one shutter click and stop with the next
{
!_capturing ? startVideoCapture() : stopVideoCapture();
}
}
void CameraMainWindow::performCapture( const QString& format )
{
QString name;
if ( outputTo == "Documents Folder" )
- name.sprintf( "%s/Documents/image/%s/", (const char*) QDir::homeDirPath(), (const char*) captureFormat.lower() );
+ {
+ name.sprintf( "%s/Documents/image/%s/", (const char*) QDir::homeDirPath(), (const char*) captureFormat.lower() );
+ if ( !QDir( name ).exists() )
+ {
+ odebug << "creating directory " << name << oendl;
+ QString msg = "mkdir -p " + name;
+ system( msg.latin1() );
+ }
+ }
else
name = outputTo;
name.append( prefix );
if ( appendSettings )
{
name.append( QString().sprintf( "_%d_%d_q%d", captureX, captureY, quality ) );
}
name.append( QString().sprintf( "-%d.%s", _pics++, (const char*) captureFormat.lower() ) );
QImage i;
ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, &i );
QImage im = i.convertDepth( 32 );
bool result = im.save( name, format, quality );
if ( !result )
{
oerr << "imageio-Problem while writing." << oendl;
Global::statusMessage( "Error!" );
}
else
{
odebug << captureFormat << "-image has been successfully captured" << oendl;
Global::statusMessage( "Ok." );
}
}
void CameraMainWindow::startVideoCapture()
{
//ODevice::inst()->touchSound();
ODevice::inst()->setLedState( Led_Mail, Led_BlinkSlow );
_capturefd = ::open( CAPTUREFILE, O_WRONLY | O_CREAT | O_TRUNC );
if ( _capturefd == -1 )
{
owarn << "can't open capture file: " << strerror(errno) << oendl;
return;
}
_capturebuf = new unsigned char[captureX*captureY*2];
_capturing = true;
_videopics = 0;
_framerate = 0;
updateCaption();
_time.start();
preview->setRefreshingRate( 1000 );
startTimer( 100 ); // too fast but that is ok
}
void CameraMainWindow::timerEvent( QTimerEvent* )
{
if ( !_capturing )
{
odebug << "timer event in CameraMainWindow without capturing video ?" << oendl;
return;
}
odebug << "timer event during video - now capturing frame #" << _videopics+1 << oendl;
ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, _capturebuf );
_videopics++;
::write( _capturefd, _capturebuf, captureX*captureY*2 );
setCaption( QString().sprintf( "Capturing %dx%d @ %.2f fps %d",
captureX, captureY, 1000.0 / (_time.elapsed()/_videopics), _videopics ) );
}
void CameraMainWindow::stopVideoCapture()
{
killTimers();
//ODevice::inst()->touchSound();
ODevice::inst()->setLedState( Led_Mail, Led_Off );
_capturing = false;
updateCaption();
::close( _capturefd );
_framerate = 1000.0 / (_time.elapsed()/_videopics);
- QString name( outputTo );
- name.append( "/prefix" );
+ QString name;
+ if ( outputTo == "Documents Folder" )
+ {
+ name.sprintf( "%s/Documents/video/%s/", (const char*) QDir::homeDirPath(), (const char*) captureFormat.lower() );
+ if ( !QDir( name ).exists() )
+ {
+ odebug << "creating directory " << name << oendl;
+ QString msg = "mkdir -p " + name;
+ system( msg.latin1() );
+ }
+ }
+ else
+ name = outputTo;
+
+ name.append( "/" ); // sure is sure and safe is safe ;-)
+ name.append( prefix );
if ( appendSettings )
name.append( QString().sprintf( "_%d_%d_q%d_%dfps", captureX, captureY, quality, _framerate ) );
name.append( QString().sprintf( "-%d.%s", _videos++, (const char*) captureFormat.lower() ) );
postProcessVideo( CAPTUREFILE, name );
#ifndef QT_NO_DEBUG
preview->setRefreshingRate( 1500 );
#else
preview->setRefreshingRate( 200 );
#endif
//delete[] _capturebuf; //FIXME: close memory leak
}
void CameraMainWindow::postProcessVideo( const QString& infile, const QString& outfile )
{
+ odebug << "post processing " << infile << " --> " << outfile << oendl;
+
preview->setRefreshingRate( 0 );
/*
unsigned char buf[153600];
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..." );
QVBoxLayout* box = new QVBoxLayout( fr, 2, 2 );
QProgressBar* bar = new QProgressBar( fr );
bar->setCenterIndicator( true );
bar->setTotalSteps( _videopics-1 );
QLabel* label = new QLabel( "Post processing frame bla/bla", fr );
box->addWidget( bar );
box->addWidget( label );
fr->show();
label->show();
bar->show();
fr->repaint();
qApp->processEvents();
// open files
int infd = ::open( (const char*) infile, O_RDONLY );
if ( infd == -1 )
{
owarn << "couldn't open capture file: " << strerror(errno) << oendl;
return;
}
int outfd = ::open( (const char*) outfile, O_CREAT | O_WRONLY | O_TRUNC, 0644 );
if ( outfd == -1 )
{
owarn << "couldn't open output file: " << strerror(errno) << oendl;
return;
}
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();
- #ifndef QT_NO_DEBUG
+ #ifdef CAMERA_EXTRA_DEBUG
QString tmpfilename;
tmpfilename.sprintf( "/tmp/test/%04d.jpg", i );
#else
QString tmpfilename( "/tmp/tempfile" );
#endif
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();
- odebug << "deleting temporary capturefile " << infile << oendl;
- ::close( infd );
- QFile::remove( infile );
}
avi_end( outfd, captureX, captureY, _framerate );
::close( outfd );
+ ::close( infd );
+
+ label->setText( "deleting temp files..." );
+ qApp->processEvents();
+ odebug << "deleting temporary capturefile " << infile << oendl;
+ QFile::remove( infile );
fr->hide();
delete fr;
updateCaption();
}
void CameraMainWindow::updateCaption()
{
if ( !_capturing )
setCaption( QString().sprintf( "Opie-Camera: %dx%d %s q%d z%d (%s)", captureX, captureY, (const char*) captureFormat.lower(), quality, zoom, (const char*) flip ) );
else
setCaption( "Opie-Camera: => CAPTURING <=" );
+ qApp->processEvents();
}
#ifndef QT_NO_DEBUG
void CameraMainWindow::doSomething()
{
captureX = 240;
captureY = 320;
_videopics = 50;
_framerate = 5;
postProcessVideo( "/var/compile/opie/noncore/multimedia/camera/capture.dat",
"/tmp/output.avi" );
}
#else
void CameraMainWindow::doSomething()
{
}
#endif
diff --git a/noncore/multimedia/camera/opie-camera.control b/noncore/multimedia/camera/opie-camera.control
index a33de38..1731ad2 100644
--- a/noncore/multimedia/camera/opie-camera.control
+++ b/noncore/multimedia/camera/opie-camera.control
@@ -1,10 +1,10 @@
Package: opie-camera
Files: bin/opiecam pics/camera apps/Applications/camera.desktop
Priority: optional
Section: opie/applications
Maintainer: Michael 'Mickey' Lauer <mickeyl@handhelds.org>
Architecture: arm
-Version: $QPE_VERSION-$SUB_VERSION
+Version: 1.0
Depends: task-opie-minimal, libopie2 (1.8.1)
Description: A Camera Application
A Camera Application to use with the Sharp CE-AG06.