summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-19 00:40:00 (UTC)
committer mickeyl <mickeyl>2003-04-19 00:40:00 (UTC)
commit724bb4ef15cd02a360e49de9c67847a19d5ca832 (patch) (side-by-side diff)
tree0fc5f2aab63c005aa2cfd36f7517547c0aa62e1d
parent6e7112a3610c4e562f991ba6d6f33ca2fe0c605d (diff)
downloadopie-724bb4ef15cd02a360e49de9c67847a19d5ca832.zip
opie-724bb4ef15cd02a360e49de9c67847a19d5ca832.tar.gz
opie-724bb4ef15cd02a360e49de9c67847a19d5ca832.tar.bz2
- fix shutter handling
- include manually overriding xflip and yflip - prepare video capturing mode - use caption to indicate current settings
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/multimedia/camera/camera.pro6
-rw-r--r--noncore/multimedia/camera/imageio.cpp55
-rw-r--r--noncore/multimedia/camera/imageio.h26
-rw-r--r--noncore/multimedia/camera/mainwindow.cpp190
-rw-r--r--noncore/multimedia/camera/mainwindow.h19
-rw-r--r--noncore/multimedia/camera/previewwidget.cpp14
-rw-r--r--noncore/multimedia/camera/previewwidget.h3
-rw-r--r--noncore/multimedia/camera/zcameraio.cpp92
-rw-r--r--noncore/multimedia/camera/zcameraio.h11
9 files changed, 388 insertions, 28 deletions
diff --git a/noncore/multimedia/camera/camera.pro b/noncore/multimedia/camera/camera.pro
index ffd5f37..8aedcea 100644
--- a/noncore/multimedia/camera/camera.pro
+++ b/noncore/multimedia/camera/camera.pro
@@ -1,17 +1,19 @@
MOC_DIR = ./moc
OBJECTS_DIR = ./obj
DESTDIR = $(OPIEDIR)/bin
TEMPLATE = app
CONFIG = qt warn_on debug
-HEADERS = zcameraio.h \
+HEADERS = imageio.h \
+ zcameraio.h \
previewwidget.h \
mainwindow.h
-SOURCES = zcameraio.cpp \
+SOURCES = imageio.cpp \
+ zcameraio.cpp \
previewwidget.cpp \
mainwindow.cpp \
main.cpp
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
diff --git a/noncore/multimedia/camera/imageio.cpp b/noncore/multimedia/camera/imageio.cpp
new file mode 100644
index 0000000..f8f5dd0
--- a/dev/null
+++ b/noncore/multimedia/camera/imageio.cpp
@@ -0,0 +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;
+ }
+ else
+ {
+ odebug << format << "-image has been successfully captured" << oendl;
+ }
+} \ No newline at end of file
diff --git a/noncore/multimedia/camera/imageio.h b/noncore/multimedia/camera/imageio.h
new file mode 100644
index 0000000..8dba2ed
--- a/dev/null
+++ b/noncore/multimedia/camera/imageio.h
@@ -0,0 +1,26 @@
+/**********************************************************************
+** Copyright (C) 2003 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.
+**
+**********************************************************************/
+
+#ifndef IMAGEIO_H
+#define IMAGEIO_H
+
+#include <qstring.h>
+
+class QImage;
+
+void bufferToImage( int _width, int height, unsigned char* bp, QImage* image );
+void imageToFile( QImage* i, const QString& name, const QString& format, int quality );
+
+#endif
diff --git a/noncore/multimedia/camera/mainwindow.cpp b/noncore/multimedia/camera/mainwindow.cpp
index 8e89039..6141fd1 100644
--- a/noncore/multimedia/camera/mainwindow.cpp
+++ b/noncore/multimedia/camera/mainwindow.cpp
@@ -13,39 +13,49 @@
**
**********************************************************************/
#include "mainwindow.h"
#include "previewwidget.h"
#include "zcameraio.h"
+#include "imageio.h"
#include <qapplication.h>
#include <qaction.h>
#include <qvbox.h>
#include <qcombobox.h>
#include <qcursor.h>
#include <qdatastream.h>
#include <qfile.h>
#include <qimage.h>
#include <qlabel.h>
#include <qpopupmenu.h>
+#include <qprogressbar.h>
#include <qpushbutton.h>
#include <qmessagebox.h>
+#include <qlayout.h>
#include <qdirectpainter_qws.h>
#include <qpe/global.h>
#include <qpe/resource.h>
#include <qpe/qcopenvelope_qws.h>
#include <opie/ofiledialog.h>
#include <opie/odevice.h>
using namespace Opie;
-
#include <opie2/odebug.h>
#include <assert.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
+#define CAPTUREFILE "/tmp/capture.dat"
CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f )
- :QMainWindow( parent, name, f ), _pics( 0 )
+ :QMainWindow( parent, name, f ), _capturing( false ), _pics( 0 )
{
#ifdef QT_NO_DEBUG
if ( !ZCameraIO::instance()->isOpen() )
{
QVBox* v = new QVBox( this );
v->setMargin( 10 );
@@ -75,23 +85,27 @@ CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags
connect( _sysChannel, SIGNAL( received( const QCString&, const QByteArray& ) ),
this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) );
connect( preview, SIGNAL( contextMenuRequested() ), this, SLOT( showContextMenu() ) );
connect( ZCameraIO::instance(), SIGNAL( shutterClicked() ), this, SLOT( shutterClicked() ) );
+
+ updateCaption();
+
};
CameraMainWindow::~CameraMainWindow()
{
}
void CameraMainWindow::init()
{
// TODO: Save this stuff in config
+ flip = 'A'; // auto
quality = 50;
zoom = 1;
captureX = 640;
captureY = 480;
captureFormat = "JPEG";
@@ -118,22 +132,33 @@ void CameraMainWindow::init()
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 );
+
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( outputg, SIGNAL( selected(QAction*) ), this, SLOT( outputMenuItemClicked(QAction*) ) );
+
}
void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data )
{
QDataStream stream( data, IO_ReadOnly );
@@ -166,88 +191,245 @@ void CameraMainWindow::changeZoom( int zoom )
default: assert( 0 ); break;
}
ZCameraIO::instance()->setCaptureFrame( 240, 160, z );
}
+
void CameraMainWindow::showContextMenu()
{
QPopupMenu reso;
reso.setCheckable( true );
resog->addTo( &reso );
QPopupMenu quality;
quality.setCheckable( true );
qualityg->addTo( &quality );
+ QPopupMenu flip;
+ flip.setCheckable( true );
+ flipg->addTo( &flip );
+
QPopupMenu zoom;
zoom.setCheckable( true );
zoomg->addTo( &zoom );
QPopupMenu output;
output.setCheckable( true );
outputg->addTo( &output );
QPopupMenu m( this );
m.insertItem( "&Resolution", &reso );
m.insertItem( "&Zoom", &zoom );
+ m.insertItem( "&Flip", &flip );
m.insertItem( "&Quality", &quality );
m.insertItem( "&Output As", &output );
m.exec( QCursor::pos() );
}
void CameraMainWindow::resoMenuItemClicked( QAction* a )
{
captureX = a->text().left(3).toInt();
captureY = a->text().right(3).toInt();
odebug << "Capture Resolution now: " << captureX << ", " << captureY << oendl;
+ updateCaption();
}
void CameraMainWindow::qualityMenuItemClicked( QAction* a )
{
quality = a->text().left(3).toInt();
odebug << "Quality now: " << quality << oendl;
+ updateCaption();
}
void CameraMainWindow::zoomMenuItemClicked( QAction* a )
{
- zoom = QString( a->text()[2] ).toInt();
+ zoom = QString( a->text().at(2) ).toInt();
odebug << "Zoom now: " << zoom << oendl;
ZCameraIO::instance()->setZoom( zoom );
+ updateCaption();
+}
+
+
+void CameraMainWindow::flipMenuItemClicked( QAction* a )
+{
+ flip = QString( a->text().at(0) );
+ odebug << "Flip now: " << flip << oendl;
+ if ( flip == "A" )
+ ZCameraIO::instance()->setFlip( ZCameraIO::AUTOMATICFLIP );
+ else if ( flip == "0" )
+ ZCameraIO::instance()->setFlip( ZCameraIO::XNOFLIP | ZCameraIO::YNOFLIP );
+ else if ( flip == "X" )
+ ZCameraIO::instance()->setFlip( ZCameraIO::XFLIP );
+ else if ( flip == "Y" )
+ ZCameraIO::instance()->setFlip( ZCameraIO::YFLIP );
+ else if ( flip == "*" )
+ ZCameraIO::instance()->setFlip( ZCameraIO::XFLIP | ZCameraIO::YFLIP );
+
+ updateCaption();
}
void CameraMainWindow::outputMenuItemClicked( QAction* a )
{
captureFormat = a->text();
odebug << "Output format now: " << captureFormat << oendl;
+ updateCaption();
}
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;
name.sprintf( "/tmp/image-%d_%d_%d_q%d.%s", _pics++, captureX, captureY, quality, (const char*) captureFormat.lower() );
QImage i;
ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, &i );
QImage im = i.convertDepth( 32 );
- bool result = im.save( name, captureFormat, quality );
+ 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 );
+ if ( _capturefd == -1 )
+ {
+ owarn << "can't open capture file: " << strerror(errno) << oendl;
+ return;
+ }
+
+ _capturebuf = new unsigned char[captureX*captureY*2];
+ _capturing = true;
+ _videopics = 0;
+ updateCaption();
+ _time.start();
+ preview->setRefreshingRate( 1000 );
+ startTimer( 100 ); // too fast but that is ok
+}
+
+
+void CameraMainWindow::timerEvent( QTimerEvent* )
+{
+ if ( !_capturing )
+ {
+ owarn << "timer event in CameraMainWindow without capturing video ?" << oendl;
+ return;
+ }
+
+ 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 );
+
+ //postProcessVideo();
+
+ #ifndef QT_NO_DEBUG
+ preview->setRefreshingRate( 1500 );
+ #else
+ preview->setRefreshingRate( 200 );
+ #endif
+
+ //delete[] _capturebuf; //FIXME: close memory leak
+}
+
+void CameraMainWindow::postProcessVideo()
+{
+ preview->setRefreshingRate( 0 );
+
+ /*
+
+ QDialog* fr = new QDialog( this, "splash" ); //, 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();
+ 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();
+ }
+
+ */
+
+ int infd = ::open( CAPTUREFILE, O_RDONLY );
+ if ( infd == -1 )
+ {
+ owarn << "couldn't open capture file: " << strerror(errno) << oendl;
+ return;
+ }
+
+ int outfd = ::open( "/tmp/output.avi", O_WRONLY );
+ if ( outfd == -1 )
+ {
+ owarn << "couldn't open output file: " << strerror(errno) << oendl;
+ return;
+ }
+
+
+
+
+}
+
+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 <=" );
+}
+
+
diff --git a/noncore/multimedia/camera/mainwindow.h b/noncore/multimedia/camera/mainwindow.h
index 7a12452..ad8d1b1 100644
--- a/noncore/multimedia/camera/mainwindow.h
+++ b/noncore/multimedia/camera/mainwindow.h
@@ -17,16 +17,18 @@
#define MAINWINDOW_H
#include <qmainwindow.h>
#include <qdatetime.h>
#include <qimage.h>
#include <qpixmap.h>
+#include <qdatetime.h>
class QAction;
class QActionGroup;
class QIconSet;
+class QTimerEvent;
class QToolButton;
class QLabel;
class MainWindowBase;
class QCopChannel;
class PreviewWidget;
@@ -42,32 +44,49 @@ class CameraMainWindow: public QMainWindow
void changeZoom( int );
void systemMessage( const QCString&, const QByteArray& );
void showContextMenu();
void resoMenuItemClicked( QAction* );
void qualityMenuItemClicked( QAction* );
void zoomMenuItemClicked( QAction* );
+ void flipMenuItemClicked( QAction* );
void outputMenuItemClicked( QAction* );
void shutterClicked();
+ void updateCaption();
+
protected:
void init();
+ void startVideoCapture();
+ void stopVideoCapture();
+ void postProcessVideo();
+ void performCapture( const QString& );
+
+ virtual void timerEvent( QTimerEvent* );
private:
PreviewWidget* preview;
int _rotation;
QCopChannel* _sysChannel;
QActionGroup* resog;
QActionGroup* qualityg;
QActionGroup* zoomg;
+ QActionGroup* flipg;
QActionGroup* outputg;
+ QString flip;
int quality;
int zoom;
int captureX;
int captureY;
QString captureFormat;
+ bool _capturing;
int _pics;
+
+ QTime _time;
+ int _videopics;
+ int _capturefd;
+ unsigned char* _capturebuf;
};
#endif
diff --git a/noncore/multimedia/camera/previewwidget.cpp b/noncore/multimedia/camera/previewwidget.cpp
index f87dcc9..08330d0 100644
--- a/noncore/multimedia/camera/previewwidget.cpp
+++ b/noncore/multimedia/camera/previewwidget.cpp
@@ -69,6 +69,20 @@ void PreviewWidget::timerEvent( QTimerEvent* )
void PreviewWidget::mousePressEvent( QMouseEvent* )
{
emit contextMenuRequested();
}
+
+void PreviewWidget::setRefreshingRate( int ms )
+{
+ killTimers();
+ if ( ms )
+ startTimer( ms );
+}
+
+
+void PreviewWidget::refresh()
+{
+ QTimerEvent t( 10 ); // event id is meaningless in this case
+ timerEvent( &t );
+}
diff --git a/noncore/multimedia/camera/previewwidget.h b/noncore/multimedia/camera/previewwidget.h
index dada301..d37f80f 100644
--- a/noncore/multimedia/camera/previewwidget.h
+++ b/noncore/multimedia/camera/previewwidget.h
@@ -28,12 +28,15 @@ class PreviewWidget: public QLabel
Q_OBJECT
public:
PreviewWidget( QWidget * parent = 0, const char * name = 0, WFlags f = 0 );
virtual ~PreviewWidget();
+ void setRefreshingRate( int ms );
+ void refresh();
+
protected:
virtual void timerEvent( QTimerEvent* );
virtual void resizeEvent( QResizeEvent* );
virtual void mousePressEvent( QMouseEvent* );
signals:
diff --git a/noncore/multimedia/camera/zcameraio.cpp b/noncore/multimedia/camera/zcameraio.cpp
index 9af0c25..1c449e7 100644
--- a/noncore/multimedia/camera/zcameraio.cpp
+++ b/noncore/multimedia/camera/zcameraio.cpp
@@ -41,13 +41,15 @@ ZCameraIO* ZCameraIO::instance()
}
return ZCameraIO::_instance;
}
ZCameraIO::ZCameraIO()
- :_height( 0 ), _width( 0 ), _zoom( 0 ), _rot( 0 ), _readlen( 0 )
+ : _pressed( false ), _height( 0 ), _width( 0 ), _zoom( 0 ),
+ _flip( -1 ), _rot( 0 ), _readlen( 0 )
+
{
_driver = ::open( SHARPZDC, O_RDWR );
if ( _driver == -1 )
oerr << "Can't open camera driver: " << strerror(errno) << oendl;
else
init();
@@ -81,24 +83,30 @@ bool ZCameraIO::isOpen() const
return _driver != -1;
}
bool ZCameraIO::isShutterPressed()
{
- if ( _timer->elapsed() < 1000 ) //TODO: make this customizable?
+ if ( _status[0] == 'S' )
{
- clearShutterLatch();
- return false;
+ if ( !_pressed ) // wasn't pressed before, but is now!
+ {
+ _pressed = true;
+ _timer->start();
+ return true;
}
- if ( _status[0] == 'S' )
+
+ if ( _timer->elapsed() > 2000 ) // the press is pretty old now
{
- _timer->restart();
clearShutterLatch();
- return true;
+ _status[0] = 's';
+ _pressed = false;
+ }
}
- else return false;
+
+ return false;
}
bool ZCameraIO::isFinderReversed() const
{
return _status[1] == 'M';
@@ -146,15 +154,24 @@ void ZCameraIO::setReadMode( int mode )
char b[10];
sprintf( b, "M=%d", mode );
write( b, mode <= 9 ? 3 : 4 );
if ( mode & STATUS ) // STATUS bit is set
{
read( _status, 4 );
- if ( isShutterPressed() ) emit shutterClicked();
+ if ( isShutterPressed() )
+ {
+ emit shutterClicked();
}
}
+}
+
+
+void ZCameraIO::setFlip( int flip )
+{
+ _flip = flip;
+}
void ZCameraIO::clearShutterLatch()
{
write( "B", 1 );
}
@@ -195,21 +212,31 @@ bool ZCameraIO::snapshot( QImage* image )
{
setReadMode( STATUS );
odebug << "finder reversed = " << isFinderReversed() << oendl;
odebug << "rotation = " << _rot << oendl;
+ int readmode;
+ if ( _flip == -1 ) // AUTO
+ {
if ( _rot ) // Portrait
{
- setReadMode( IMAGE | isFinderReversed() ? XFLIP | YFLIP : 0 );
+ readmode = IMAGE | isFinderReversed() ? XFLIP | YFLIP : 0;
}
else // Landscape
{
- setReadMode( IMAGE | XFLIP | YFLIP ); //isFinderReversed() ? 0 : XFLIP );
+ readmode = IMAGE | XFLIP | YFLIP;
+ }
+ }
+ else // OVERRIDE
+ {
+ readmode = IMAGE | _flip;
}
+ setReadMode( readmode );
+
char buf[_readlen];
char* bp = buf;
unsigned char* p;
read( bp, _readlen );
@@ -231,24 +258,37 @@ bool ZCameraIO::snapshot( QImage* image )
return true;
}
bool ZCameraIO::snapshot( unsigned char* buf )
{
- setReadMode( IMAGE | XFLIP | YFLIP );
+ setReadMode( STATUS );
- read( (char*) buf, _readlen );
+ odebug << "finder reversed = " << isFinderReversed() << oendl;
+ odebug << "rotation = " << _rot << oendl;
- /* //TESTCODE
- int fd = open( "/tmp/cam", O_RDONLY );
- if ( ::read( fd, (char*) buf, 76800 ) != 76800 )
- owarn << "Couldn't read image from /dev/sharp_zdc" << oendl;
- // TESTCODE */
+ int readmode;
+ if ( _flip == -1 ) // AUTO
+ {
+ if ( _rot ) // Portrait
+ {
+ readmode = IMAGE | isFinderReversed() ? XFLIP | YFLIP : 0;
+ }
+ else // Landscape
+ {
+ readmode = IMAGE | XFLIP | YFLIP;
+ }
+ }
+ else // OVERRIDE
+ {
+ readmode = IMAGE | _flip;
+ }
+ setReadMode( readmode );
+ read( (char*) buf, _readlen );
- return true;
}
void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image )
{
int pw = _width;
@@ -259,6 +299,20 @@ void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image )
setCaptureFrame( w, h, zoom*256, false );
snapshot( image );
setCaptureFrame( pw, ph, _zoom, _rot );
}
+void ZCameraIO::captureFrame( int w, int h, int zoom, unsigned char* buf )
+{
+ //FIXME: this is too slow
+ int pw = _width;
+ int ph = _height;
+ if ( _rot )
+ setCaptureFrame( h, w, zoom*256, true );
+ else
+ setCaptureFrame( w, h, zoom*256, false );
+
+ snapshot( buf );
+ setCaptureFrame( pw, ph, _zoom, _rot );
+}
+
diff --git a/noncore/multimedia/camera/zcameraio.h b/noncore/multimedia/camera/zcameraio.h
index edce143..3352a5e 100644
--- a/noncore/multimedia/camera/zcameraio.h
+++ b/noncore/multimedia/camera/zcameraio.h
@@ -30,33 +30,36 @@ class ZCameraIO : public QObject
enum ReadMode
{
IMAGE = 0, STATUS = 1,
FASTER = 0, BETTER = 2,
XNOFLIP = 0, XFLIP = 4,
- YNOFLIP = 0, YFLIP = 8
+ YNOFLIP = 0, YFLIP = 8,
+ AUTOMATICFLIP = -1
};
// low level interface
bool setCaptureFrame( int w, int h, int zoom = 256, bool rot = true );
bool setZoom( int zoom = 0 );
void setReadMode( int = IMAGE | XFLIP | YFLIP );
+ void setFlip( int flip );
bool isShutterPressed(); // not const, because it calls clearShutterLatch
bool isAvailable() const;
bool isCapturing() const;
bool isFinderReversed() const;
- bool snapshot( unsigned char* );
- bool snapshot( QImage* );
+ bool snapshot( QImage* image );
+ bool snapshot( unsigned char* buf );
// high level interface
bool isOpen() const;
static ZCameraIO* instance();
void captureFrame( int w, int h, int zoom, QImage* image );
+ void captureFrame( int w, int h, int zoom, unsigned char* buf );
protected:
ZCameraIO();
void clearShutterLatch();
void init();
bool read( char*, int );
@@ -65,16 +68,18 @@ class ZCameraIO : public QObject
signals:
void shutterClicked();
private:
int _driver;
char _status[4];
+ bool _pressed;
static ZCameraIO* _instance;
int _height;
int _width;
int _zoom;
+ int _flip;
bool _rot;
int _readlen;
QTime* _timer;
};