summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore 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.cpp198
-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.cpp100
-rw-r--r--noncore/multimedia/camera/zcameraio.h11
9 files changed, 396 insertions, 36 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
@@ -4,11 +4,13 @@ DESTDIR = $(OPIEDIR)/bin
4TEMPLATE = app 4TEMPLATE = app
5CONFIG = qt warn_on debug 5CONFIG = qt warn_on debug
6 6
7HEADERS = zcameraio.h \ 7HEADERS = imageio.h \
8 zcameraio.h \
8 previewwidget.h \ 9 previewwidget.h \
9 mainwindow.h 10 mainwindow.h
10 11
11SOURCES = zcameraio.cpp \ 12SOURCES = imageio.cpp \
13 zcameraio.cpp \
12 previewwidget.cpp \ 14 previewwidget.cpp \
13 mainwindow.cpp \ 15 mainwindow.cpp \
14 main.cpp 16 main.cpp
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 @@
1/**********************************************************************
2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
3**
4** This file is part of Opie Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14**********************************************************************/
15
16#include "imageio.h"
17
18#include <opie2/odebug.h>
19#include <qimage.h>
20
21
22void bufferToImage( int _width, int _height, unsigned char* bp, QImage* image )
23{
24 unsigned char* p;
25
26 image->create( _width, _height, 16 );
27 for ( int i = 0; i < _height; ++i )
28 {
29 p = image->scanLine( i );
30 for ( int j = 0; j < _width; j++ )
31 {
32 *p = *bp;
33 p++;
34 bp++;
35 *p = *bp;
36 p++;
37 bp++;
38 }
39 }
40}
41
42
43void imageToFile( QImage* i, const QString& name, const QString& format, int quality )
44{
45 QImage im = i->convertDepth( 32 );
46 bool result = im.save( name, format, quality );
47 if ( !result )
48 {
49 oerr << "imageio-Problem while writing." << oendl;
50 }
51 else
52 {
53 odebug << format << "-image has been successfully captured" << oendl;
54 }
55} \ 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 @@
1/**********************************************************************
2** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved.
3**
4** This file is part of Opie Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14**********************************************************************/
15
16#ifndef IMAGEIO_H
17#define IMAGEIO_H
18
19#include <qstring.h>
20
21class QImage;
22
23void bufferToImage( int _width, int height, unsigned char* bp, QImage* image );
24void imageToFile( QImage* i, const QString& name, const QString& format, int quality );
25
26#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
@@ -16,6 +16,7 @@
16#include "mainwindow.h" 16#include "mainwindow.h"
17#include "previewwidget.h" 17#include "previewwidget.h"
18#include "zcameraio.h" 18#include "zcameraio.h"
19#include "imageio.h"
19 20
20#include <qapplication.h> 21#include <qapplication.h>
21#include <qaction.h> 22#include <qaction.h>
@@ -27,8 +28,10 @@
27#include <qimage.h> 28#include <qimage.h>
28#include <qlabel.h> 29#include <qlabel.h>
29#include <qpopupmenu.h> 30#include <qpopupmenu.h>
31#include <qprogressbar.h>
30#include <qpushbutton.h> 32#include <qpushbutton.h>
31#include <qmessagebox.h> 33#include <qmessagebox.h>
34#include <qlayout.h>
32#include <qdirectpainter_qws.h> 35#include <qdirectpainter_qws.h>
33#include <qpe/global.h> 36#include <qpe/global.h>
34#include <qpe/resource.h> 37#include <qpe/resource.h>
@@ -36,13 +39,20 @@
36#include <opie/ofiledialog.h> 39#include <opie/ofiledialog.h>
37#include <opie/odevice.h> 40#include <opie/odevice.h>
38using namespace Opie; 41using namespace Opie;
39
40#include <opie2/odebug.h> 42#include <opie2/odebug.h>
41 43
42#include <assert.h> 44#include <assert.h>
45#include <sys/types.h>
46#include <sys/stat.h>
47#include <fcntl.h>
48#include <string.h>
49#include <errno.h>
50#include <unistd.h>
51
52#define CAPTUREFILE "/tmp/capture.dat"
43 53
44CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) 54CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f )
45 :QMainWindow( parent, name, f ), _pics( 0 ) 55 :QMainWindow( parent, name, f ), _capturing( false ), _pics( 0 )
46{ 56{
47 #ifdef QT_NO_DEBUG 57 #ifdef QT_NO_DEBUG
48 if ( !ZCameraIO::instance()->isOpen() ) 58 if ( !ZCameraIO::instance()->isOpen() )
@@ -78,6 +88,9 @@ CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags
78 connect( preview, SIGNAL( contextMenuRequested() ), this, SLOT( showContextMenu() ) ); 88 connect( preview, SIGNAL( contextMenuRequested() ), this, SLOT( showContextMenu() ) );
79 89
80 connect( ZCameraIO::instance(), SIGNAL( shutterClicked() ), this, SLOT( shutterClicked() ) ); 90 connect( ZCameraIO::instance(), SIGNAL( shutterClicked() ), this, SLOT( shutterClicked() ) );
91
92 updateCaption();
93
81}; 94};
82 95
83 96
@@ -89,6 +102,7 @@ CameraMainWindow::~CameraMainWindow()
89void CameraMainWindow::init() 102void CameraMainWindow::init()
90{ 103{
91 // TODO: Save this stuff in config 104 // TODO: Save this stuff in config
105 flip = 'A'; // auto
92 quality = 50; 106 quality = 50;
93 zoom = 1; 107 zoom = 1;
94 captureX = 640; 108 captureX = 640;
@@ -121,16 +135,27 @@ void CameraMainWindow::init()
121 ( new QAction( "x 1", 0, 0, zoomg, 0, true ) )->setOn( true ); 135 ( new QAction( "x 1", 0, 0, zoomg, 0, true ) )->setOn( true );
122 new QAction( "x 2", 0, 0, zoomg, 0, true ); 136 new QAction( "x 2", 0, 0, zoomg, 0, true );
123 137
138 flipg = new QActionGroup( 0, "flip", true );
139 flipg->setToggleAction( true );
140 ( new QAction( "Auto (recommended)", 0, 0, flipg, 0, true ) )->setOn( true );
141 new QAction( "0 (always off)", 0, 0, flipg, 0, true );
142 new QAction( "X (always horizontal)", 0, 0, flipg, 0, true );
143 new QAction( "Y (always vertical)", 0, 0, flipg, 0, true );
144 new QAction( "* (always both)", 0, 0, flipg, 0, true );
145
124 outputg = new QActionGroup( 0, "output", true ); 146 outputg = new QActionGroup( 0, "output", true );
125 outputg->setToggleAction( true ); 147 outputg->setToggleAction( true );
126 ( new QAction( "JPEG", 0, 0, outputg, 0, true ) )->setOn( true ); 148 ( new QAction( "JPEG", 0, 0, outputg, 0, true ) )->setOn( true );
127 new QAction( "PNG", 0, 0, outputg, 0, true ); 149 new QAction( "PNG", 0, 0, outputg, 0, true );
128 new QAction( "BMP", 0, 0, outputg, 0, true ); 150 new QAction( "BMP", 0, 0, outputg, 0, true );
151 new QAction( "AVI", 0, 0, outputg, 0, true );
129 152
130 connect( resog, SIGNAL( selected(QAction*) ), this, SLOT( resoMenuItemClicked(QAction*) ) ); 153 connect( resog, SIGNAL( selected(QAction*) ), this, SLOT( resoMenuItemClicked(QAction*) ) );
131 connect( qualityg, SIGNAL( selected(QAction*) ), this, SLOT( qualityMenuItemClicked(QAction*) ) ); 154 connect( qualityg, SIGNAL( selected(QAction*) ), this, SLOT( qualityMenuItemClicked(QAction*) ) );
132 connect( zoomg, SIGNAL( selected(QAction*) ), this, SLOT( zoomMenuItemClicked(QAction*) ) ); 155 connect( zoomg, SIGNAL( selected(QAction*) ), this, SLOT( zoomMenuItemClicked(QAction*) ) );
156 connect( flipg, SIGNAL( selected(QAction*) ), this, SLOT( flipMenuItemClicked(QAction*) ) );
133 connect( outputg, SIGNAL( selected(QAction*) ), this, SLOT( outputMenuItemClicked(QAction*) ) ); 157 connect( outputg, SIGNAL( selected(QAction*) ), this, SLOT( outputMenuItemClicked(QAction*) ) );
158
134} 159}
135 160
136 161
@@ -169,6 +194,7 @@ void CameraMainWindow::changeZoom( int zoom )
169 ZCameraIO::instance()->setCaptureFrame( 240, 160, z ); 194 ZCameraIO::instance()->setCaptureFrame( 240, 160, z );
170} 195}
171 196
197
172void CameraMainWindow::showContextMenu() 198void CameraMainWindow::showContextMenu()
173{ 199{
174 QPopupMenu reso; 200 QPopupMenu reso;
@@ -179,6 +205,10 @@ void CameraMainWindow::showContextMenu()
179 quality.setCheckable( true ); 205 quality.setCheckable( true );
180 qualityg->addTo( &quality ); 206 qualityg->addTo( &quality );
181 207
208 QPopupMenu flip;
209 flip.setCheckable( true );
210 flipg->addTo( &flip );
211
182 QPopupMenu zoom; 212 QPopupMenu zoom;
183 zoom.setCheckable( true ); 213 zoom.setCheckable( true );
184 zoomg->addTo( &zoom ); 214 zoomg->addTo( &zoom );
@@ -190,6 +220,7 @@ void CameraMainWindow::showContextMenu()
190 QPopupMenu m( this ); 220 QPopupMenu m( this );
191 m.insertItem( "&Resolution", &reso ); 221 m.insertItem( "&Resolution", &reso );
192 m.insertItem( "&Zoom", &zoom ); 222 m.insertItem( "&Zoom", &zoom );
223 m.insertItem( "&Flip", &flip );
193 m.insertItem( "&Quality", &quality ); 224 m.insertItem( "&Quality", &quality );
194 m.insertItem( "&Output As", &output ); 225 m.insertItem( "&Output As", &output );
195 m.exec( QCursor::pos() ); 226 m.exec( QCursor::pos() );
@@ -201,6 +232,7 @@ void CameraMainWindow::resoMenuItemClicked( QAction* a )
201 captureX = a->text().left(3).toInt(); 232 captureX = a->text().left(3).toInt();
202 captureY = a->text().right(3).toInt(); 233 captureY = a->text().right(3).toInt();
203 odebug << "Capture Resolution now: " << captureX << ", " << captureY << oendl; 234 odebug << "Capture Resolution now: " << captureX << ", " << captureY << oendl;
235 updateCaption();
204} 236}
205 237
206 238
@@ -208,14 +240,35 @@ void CameraMainWindow::qualityMenuItemClicked( QAction* a )
208{ 240{
209 quality = a->text().left(3).toInt(); 241 quality = a->text().left(3).toInt();
210 odebug << "Quality now: " << quality << oendl; 242 odebug << "Quality now: " << quality << oendl;
243 updateCaption();
211} 244}
212 245
213 246
214void CameraMainWindow::zoomMenuItemClicked( QAction* a ) 247void CameraMainWindow::zoomMenuItemClicked( QAction* a )
215{ 248{
216 zoom = QString( a->text()[2] ).toInt(); 249 zoom = QString( a->text().at(2) ).toInt();
217 odebug << "Zoom now: " << zoom << oendl; 250 odebug << "Zoom now: " << zoom << oendl;
218 ZCameraIO::instance()->setZoom( zoom ); 251 ZCameraIO::instance()->setZoom( zoom );
252 updateCaption();
253}
254
255
256void CameraMainWindow::flipMenuItemClicked( QAction* a )
257{
258 flip = QString( a->text().at(0) );
259 odebug << "Flip now: " << flip << oendl;
260 if ( flip == "A" )
261 ZCameraIO::instance()->setFlip( ZCameraIO::AUTOMATICFLIP );
262 else if ( flip == "0" )
263 ZCameraIO::instance()->setFlip( ZCameraIO::XNOFLIP | ZCameraIO::YNOFLIP );
264 else if ( flip == "X" )
265 ZCameraIO::instance()->setFlip( ZCameraIO::XFLIP );
266 else if ( flip == "Y" )
267 ZCameraIO::instance()->setFlip( ZCameraIO::YFLIP );
268 else if ( flip == "*" )
269 ZCameraIO::instance()->setFlip( ZCameraIO::XFLIP | ZCameraIO::YFLIP );
270
271 updateCaption();
219} 272}
220 273
221 274
@@ -223,22 +276,37 @@ void CameraMainWindow::outputMenuItemClicked( QAction* a )
223{ 276{
224 captureFormat = a->text(); 277 captureFormat = a->text();
225 odebug << "Output format now: " << captureFormat << oendl; 278 odebug << "Output format now: " << captureFormat << oendl;
279 updateCaption();
226} 280}
227 281
228 282
229void CameraMainWindow::shutterClicked() 283void CameraMainWindow::shutterClicked()
230{ 284{
231 Global::statusMessage( "CAPTURING..." ); 285 if ( captureFormat != "AVI" ) // capture one photo per shutterClick
232 qApp->processEvents(); 286 {
287 Global::statusMessage( "CAPTURING..." );
288 qApp->processEvents();
233 289
234 odebug << "Shutter has been pressed" << oendl; 290 odebug << "Shutter has been pressed" << oendl;
235 ODevice::inst()->touchSound(); 291 ODevice::inst()->touchSound();
292
293 performCapture( captureFormat );
294 }
295 else // capture video! start with one shutter click and stop with the next
296 {
297 !_capturing ? startVideoCapture() : stopVideoCapture();
298 }
299}
300
301
302void CameraMainWindow::performCapture( const QString& format )
303{
236 QString name; 304 QString name;
237 name.sprintf( "/tmp/image-%d_%d_%d_q%d.%s", _pics++, captureX, captureY, quality, (const char*) captureFormat.lower() ); 305 name.sprintf( "/tmp/image-%d_%d_%d_q%d.%s", _pics++, captureX, captureY, quality, (const char*) captureFormat.lower() );
238 QImage i; 306 QImage i;
239 ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, &i ); 307 ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, &i );
240 QImage im = i.convertDepth( 32 ); 308 QImage im = i.convertDepth( 32 );
241 bool result = im.save( name, captureFormat, quality ); 309 bool result = im.save( name, format, quality );
242 if ( !result ) 310 if ( !result )
243 { 311 {
244 oerr << "imageio-Problem while writing." << oendl; 312 oerr << "imageio-Problem while writing." << oendl;
@@ -251,3 +319,117 @@ void CameraMainWindow::shutterClicked()
251 } 319 }
252} 320}
253 321
322
323void CameraMainWindow::startVideoCapture()
324{
325 //ODevice::inst()->touchSound();
326 ODevice::inst()->setLedState( Led_Mail, Led_BlinkSlow );
327
328 _capturefd = ::open( CAPTUREFILE, O_WRONLY | O_CREAT );
329 if ( _capturefd == -1 )
330 {
331 owarn << "can't open capture file: " << strerror(errno) << oendl;
332 return;
333 }
334
335 _capturebuf = new unsigned char[captureX*captureY*2];
336 _capturing = true;
337 _videopics = 0;
338 updateCaption();
339 _time.start();
340 preview->setRefreshingRate( 1000 );
341 startTimer( 100 ); // too fast but that is ok
342}
343
344
345void CameraMainWindow::timerEvent( QTimerEvent* )
346{
347 if ( !_capturing )
348 {
349 owarn << "timer event in CameraMainWindow without capturing video ?" << oendl;
350 return;
351 }
352
353 ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, _capturebuf );
354 _videopics++;
355 ::write( _capturefd, _capturebuf, captureX*captureY*2 );
356 setCaption( QString().sprintf( "Capturing %dx%d @ %.2f fps %d",
357 captureX, captureY, 1000.0 / (_time.elapsed()/_videopics), _videopics ) );
358}
359
360
361void CameraMainWindow::stopVideoCapture()
362{
363 killTimers();
364 //ODevice::inst()->touchSound();
365 ODevice::inst()->setLedState( Led_Mail, Led_Off );
366 _capturing = false;
367 updateCaption();
368 ::close( _capturefd );
369
370 //postProcessVideo();
371
372 #ifndef QT_NO_DEBUG
373 preview->setRefreshingRate( 1500 );
374 #else
375 preview->setRefreshingRate( 200 );
376 #endif
377
378 //delete[] _capturebuf; //FIXME: close memory leak
379}
380
381void CameraMainWindow::postProcessVideo()
382{
383 preview->setRefreshingRate( 0 );
384
385 /*
386
387 QDialog* fr = new QDialog( this, "splash" ); //, false, QWidget::WStyle_NoBorder | QWidget::WStyle_Customize );
388 fr->setCaption( "Please wait..." );
389 QVBoxLayout* box = new QVBoxLayout( fr, 2, 2 );
390 QProgressBar* bar = new QProgressBar( fr );
391 bar->setCenterIndicator( true );
392 bar->setTotalSteps( _videopics-1 );
393 QLabel* label = new QLabel( "Post processing frame bla/bla", fr );
394 box->addWidget( bar );
395 box->addWidget( label );
396 fr->show();
397 qApp->processEvents();
398
399 for ( int i = 0; i < _videopics; ++i )
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
408 int infd = ::open( CAPTUREFILE, O_RDONLY );
409 if ( infd == -1 )
410 {
411 owarn << "couldn't open capture file: " << strerror(errno) << oendl;
412 return;
413 }
414
415 int outfd = ::open( "/tmp/output.avi", O_WRONLY );
416 if ( outfd == -1 )
417 {
418 owarn << "couldn't open output file: " << strerror(errno) << oendl;
419 return;
420 }
421
422
423
424
425}
426
427void CameraMainWindow::updateCaption()
428{
429 if ( !_capturing )
430 setCaption( QString().sprintf( "Opie-Camera: %dx%d %s q%d z%d (%s)", captureX, captureY, (const char*) captureFormat.lower(), quality, zoom, (const char*) flip ) );
431 else
432 setCaption( "Opie-Camera: => CAPTURING <=" );
433}
434
435
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
@@ -20,10 +20,12 @@
20#include <qdatetime.h> 20#include <qdatetime.h>
21#include <qimage.h> 21#include <qimage.h>
22#include <qpixmap.h> 22#include <qpixmap.h>
23#include <qdatetime.h>
23 24
24class QAction; 25class QAction;
25class QActionGroup; 26class QActionGroup;
26class QIconSet; 27class QIconSet;
28class QTimerEvent;
27class QToolButton; 29class QToolButton;
28class QLabel; 30class QLabel;
29class MainWindowBase; 31class MainWindowBase;
@@ -45,11 +47,20 @@ class CameraMainWindow: public QMainWindow
45 void resoMenuItemClicked( QAction* ); 47 void resoMenuItemClicked( QAction* );
46 void qualityMenuItemClicked( QAction* ); 48 void qualityMenuItemClicked( QAction* );
47 void zoomMenuItemClicked( QAction* ); 49 void zoomMenuItemClicked( QAction* );
50 void flipMenuItemClicked( QAction* );
48 void outputMenuItemClicked( QAction* ); 51 void outputMenuItemClicked( QAction* );
49 void shutterClicked(); 52 void shutterClicked();
50 53
54 void updateCaption();
55
51 protected: 56 protected:
52 void init(); 57 void init();
58 void startVideoCapture();
59 void stopVideoCapture();
60 void postProcessVideo();
61 void performCapture( const QString& );
62
63 virtual void timerEvent( QTimerEvent* );
53 64
54 private: 65 private:
55 PreviewWidget* preview; 66 PreviewWidget* preview;
@@ -59,15 +70,23 @@ class CameraMainWindow: public QMainWindow
59 QActionGroup* resog; 70 QActionGroup* resog;
60 QActionGroup* qualityg; 71 QActionGroup* qualityg;
61 QActionGroup* zoomg; 72 QActionGroup* zoomg;
73 QActionGroup* flipg;
62 QActionGroup* outputg; 74 QActionGroup* outputg;
63 75
76 QString flip;
64 int quality; 77 int quality;
65 int zoom; 78 int zoom;
66 int captureX; 79 int captureX;
67 int captureY; 80 int captureY;
68 QString captureFormat; 81 QString captureFormat;
69 82
83 bool _capturing;
70 int _pics; 84 int _pics;
85
86 QTime _time;
87 int _videopics;
88 int _capturefd;
89 unsigned char* _capturebuf;
71}; 90};
72 91
73#endif 92#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
@@ -72,3 +72,17 @@ void PreviewWidget::mousePressEvent( QMouseEvent* )
72 emit contextMenuRequested(); 72 emit contextMenuRequested();
73} 73}
74 74
75
76void PreviewWidget::setRefreshingRate( int ms )
77{
78 killTimers();
79 if ( ms )
80 startTimer( ms );
81}
82
83
84void PreviewWidget::refresh()
85{
86 QTimerEvent t( 10 ); // event id is meaningless in this case
87 timerEvent( &t );
88}
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
@@ -31,6 +31,9 @@ class PreviewWidget: public QLabel
31 PreviewWidget( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ); 31 PreviewWidget( QWidget * parent = 0, const char * name = 0, WFlags f = 0 );
32 virtual ~PreviewWidget(); 32 virtual ~PreviewWidget();
33 33
34 void setRefreshingRate( int ms );
35 void refresh();
36
34 protected: 37 protected:
35 virtual void timerEvent( QTimerEvent* ); 38 virtual void timerEvent( QTimerEvent* );
36 virtual void resizeEvent( QResizeEvent* ); 39 virtual void resizeEvent( QResizeEvent* );
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
@@ -44,7 +44,9 @@ ZCameraIO* ZCameraIO::instance()
44 44
45 45
46ZCameraIO::ZCameraIO() 46ZCameraIO::ZCameraIO()
47 :_height( 0 ), _width( 0 ), _zoom( 0 ), _rot( 0 ), _readlen( 0 ) 47 : _pressed( false ), _height( 0 ), _width( 0 ), _zoom( 0 ),
48 _flip( -1 ), _rot( 0 ), _readlen( 0 )
49
48{ 50{
49 _driver = ::open( SHARPZDC, O_RDWR ); 51 _driver = ::open( SHARPZDC, O_RDWR );
50 if ( _driver == -1 ) 52 if ( _driver == -1 )
@@ -84,18 +86,24 @@ bool ZCameraIO::isOpen() const
84 86
85bool ZCameraIO::isShutterPressed() 87bool ZCameraIO::isShutterPressed()
86{ 88{
87 if ( _timer->elapsed() < 1000 ) //TODO: make this customizable?
88 {
89 clearShutterLatch();
90 return false;
91 }
92 if ( _status[0] == 'S' ) 89 if ( _status[0] == 'S' )
93 { 90 {
94 _timer->restart(); 91 if ( !_pressed ) // wasn't pressed before, but is now!
95 clearShutterLatch(); 92 {
96 return true; 93 _pressed = true;
94 _timer->start();
95 return true;
96 }
97
98 if ( _timer->elapsed() > 2000 ) // the press is pretty old now
99 {
100 clearShutterLatch();
101 _status[0] = 's';
102 _pressed = false;
103 }
97 } 104 }
98 else return false; 105
106 return false;
99} 107}
100 108
101 109
@@ -149,11 +157,20 @@ void ZCameraIO::setReadMode( int mode )
149 if ( mode & STATUS ) // STATUS bit is set 157 if ( mode & STATUS ) // STATUS bit is set
150 { 158 {
151 read( _status, 4 ); 159 read( _status, 4 );
152 if ( isShutterPressed() ) emit shutterClicked(); 160 if ( isShutterPressed() )
161 {
162 emit shutterClicked();
163 }
153 } 164 }
154} 165}
155 166
156 167
168void ZCameraIO::setFlip( int flip )
169{
170 _flip = flip;
171}
172
173
157void ZCameraIO::clearShutterLatch() 174void ZCameraIO::clearShutterLatch()
158{ 175{
159 write( "B", 1 ); 176 write( "B", 1 );
@@ -198,15 +215,25 @@ bool ZCameraIO::snapshot( QImage* image )
198 odebug << "finder reversed = " << isFinderReversed() << oendl; 215 odebug << "finder reversed = " << isFinderReversed() << oendl;
199 odebug << "rotation = " << _rot << oendl; 216 odebug << "rotation = " << _rot << oendl;
200 217
201 if ( _rot ) // Portrait 218 int readmode;
219 if ( _flip == -1 ) // AUTO
202 { 220 {
203 setReadMode( IMAGE | isFinderReversed() ? XFLIP | YFLIP : 0 ); 221 if ( _rot ) // Portrait
222 {
223 readmode = IMAGE | isFinderReversed() ? XFLIP | YFLIP : 0;
224 }
225 else // Landscape
226 {
227 readmode = IMAGE | XFLIP | YFLIP;
228 }
204 } 229 }
205 else // Landscape 230 else // OVERRIDE
206 { 231 {
207 setReadMode( IMAGE | XFLIP | YFLIP ); //isFinderReversed() ? 0 : XFLIP ); 232 readmode = IMAGE | _flip;
208 } 233 }
209 234
235 setReadMode( readmode );
236
210 char buf[_readlen]; 237 char buf[_readlen];
211 char* bp = buf; 238 char* bp = buf;
212 unsigned char* p; 239 unsigned char* p;
@@ -234,18 +261,31 @@ bool ZCameraIO::snapshot( QImage* image )
234 261
235bool ZCameraIO::snapshot( unsigned char* buf ) 262bool ZCameraIO::snapshot( unsigned char* buf )
236{ 263{
237 setReadMode( IMAGE | XFLIP | YFLIP ); 264 setReadMode( STATUS );
238 265
239 read( (char*) buf, _readlen ); 266 odebug << "finder reversed = " << isFinderReversed() << oendl;
267 odebug << "rotation = " << _rot << oendl;
240 268
241 /* //TESTCODE 269 int readmode;
242 int fd = open( "/tmp/cam", O_RDONLY ); 270 if ( _flip == -1 ) // AUTO
243 if ( ::read( fd, (char*) buf, 76800 ) != 76800 ) 271 {
244 owarn << "Couldn't read image from /dev/sharp_zdc" << oendl; 272 if ( _rot ) // Portrait
245 // TESTCODE */ 273 {
274 readmode = IMAGE | isFinderReversed() ? XFLIP | YFLIP : 0;
275 }
276 else // Landscape
277 {
278 readmode = IMAGE | XFLIP | YFLIP;
279 }
280 }
281 else // OVERRIDE
282 {
283 readmode = IMAGE | _flip;
284 }
246 285
286 setReadMode( readmode );
287 read( (char*) buf, _readlen );
247 288
248 return true;
249} 289}
250 290
251 291
@@ -262,3 +302,17 @@ void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image )
262} 302}
263 303
264 304
305void ZCameraIO::captureFrame( int w, int h, int zoom, unsigned char* buf )
306{
307 //FIXME: this is too slow
308 int pw = _width;
309 int ph = _height;
310 if ( _rot )
311 setCaptureFrame( h, w, zoom*256, true );
312 else
313 setCaptureFrame( w, h, zoom*256, false );
314
315 snapshot( buf );
316 setCaptureFrame( pw, ph, _zoom, _rot );
317}
318
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
@@ -33,7 +33,8 @@ class ZCameraIO : public QObject
33 IMAGE = 0, STATUS = 1, 33 IMAGE = 0, STATUS = 1,
34 FASTER = 0, BETTER = 2, 34 FASTER = 0, BETTER = 2,
35 XNOFLIP = 0, XFLIP = 4, 35 XNOFLIP = 0, XFLIP = 4,
36 YNOFLIP = 0, YFLIP = 8 36 YNOFLIP = 0, YFLIP = 8,
37 AUTOMATICFLIP = -1
37 }; 38 };
38 39
39 // low level interface 40 // low level interface
@@ -41,19 +42,21 @@ class ZCameraIO : public QObject
41 bool setCaptureFrame( int w, int h, int zoom = 256, bool rot = true ); 42 bool setCaptureFrame( int w, int h, int zoom = 256, bool rot = true );
42 bool setZoom( int zoom = 0 ); 43 bool setZoom( int zoom = 0 );
43 void setReadMode( int = IMAGE | XFLIP | YFLIP ); 44 void setReadMode( int = IMAGE | XFLIP | YFLIP );
45 void setFlip( int flip );
44 46
45 bool isShutterPressed(); // not const, because it calls clearShutterLatch 47 bool isShutterPressed(); // not const, because it calls clearShutterLatch
46 bool isAvailable() const; 48 bool isAvailable() const;
47 bool isCapturing() const; 49 bool isCapturing() const;
48 bool isFinderReversed() const; 50 bool isFinderReversed() const;
49 51
50 bool snapshot( unsigned char* ); 52 bool snapshot( QImage* image );
51 bool snapshot( QImage* ); 53 bool snapshot( unsigned char* buf );
52 54
53 // high level interface 55 // high level interface
54 bool isOpen() const; 56 bool isOpen() const;
55 static ZCameraIO* instance(); 57 static ZCameraIO* instance();
56 void captureFrame( int w, int h, int zoom, QImage* image ); 58 void captureFrame( int w, int h, int zoom, QImage* image );
59 void captureFrame( int w, int h, int zoom, unsigned char* buf );
57 60
58 protected: 61 protected:
59 ZCameraIO(); 62 ZCameraIO();
@@ -68,10 +71,12 @@ class ZCameraIO : public QObject
68 private: 71 private:
69 int _driver; 72 int _driver;
70 char _status[4]; 73 char _status[4];
74 bool _pressed;
71 static ZCameraIO* _instance; 75 static ZCameraIO* _instance;
72 int _height; 76 int _height;
73 int _width; 77 int _width;
74 int _zoom; 78 int _zoom;
79 int _flip;
75 bool _rot; 80 bool _rot;
76 int _readlen; 81 int _readlen;
77 82