summaryrefslogtreecommitdiff
path: root/noncore
authormickeyl <mickeyl>2003-04-19 00:40:00 (UTC)
committer mickeyl <mickeyl>2003-04-19 00:40:00 (UTC)
commit724bb4ef15cd02a360e49de9c67847a19d5ca832 (patch) (unidiff)
tree0fc5f2aab63c005aa2cfd36f7517547c0aa62e1d /noncore
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 (limited to 'noncore') (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
@@ -1,17 +1,19 @@
1MOC_DIR = ./moc 1MOC_DIR = ./moc
2OBJECTS_DIR = ./obj 2OBJECTS_DIR = ./obj
3DESTDIR = $(OPIEDIR)/bin 3DESTDIR = $(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
15 17
16INCLUDEPATH += $(OPIEDIR)/include 18INCLUDEPATH += $(OPIEDIR)/include
17DEPENDPATH += $(OPIEDIR)/include 19DEPENDPATH += $(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 @@
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
@@ -13,39 +13,49 @@
13** 13**
14**********************************************************************/ 14**********************************************************************/
15 15
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>
22#include <qvbox.h> 23#include <qvbox.h>
23#include <qcombobox.h> 24#include <qcombobox.h>
24#include <qcursor.h> 25#include <qcursor.h>
25#include <qdatastream.h> 26#include <qdatastream.h>
26#include <qfile.h> 27#include <qfile.h>
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>
35#include <qpe/qcopenvelope_qws.h> 38#include <qpe/qcopenvelope_qws.h>
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() )
49 { 59 {
50 QVBox* v = new QVBox( this ); 60 QVBox* v = new QVBox( this );
51 v->setMargin( 10 ); 61 v->setMargin( 10 );
@@ -75,23 +85,27 @@ CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags
75 connect( _sysChannel, SIGNAL( received( const QCString&, const QByteArray& ) ), 85 connect( _sysChannel, SIGNAL( received( const QCString&, const QByteArray& ) ),
76 this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); 86 this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) );
77 87
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
84CameraMainWindow::~CameraMainWindow() 97CameraMainWindow::~CameraMainWindow()
85{ 98{
86} 99}
87 100
88 101
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;
95 captureY = 480; 109 captureY = 480;
96 captureFormat = "JPEG"; 110 captureFormat = "JPEG";
97 111
@@ -118,22 +132,33 @@ void CameraMainWindow::init()
118 132
119 zoomg = new QActionGroup( 0, "zoom", true ); 133 zoomg = new QActionGroup( 0, "zoom", true );
120 zoomg->setToggleAction( true ); 134 zoomg->setToggleAction( true );
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
137void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data ) 162void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data )
138{ 163{
139 QDataStream stream( data, IO_ReadOnly ); 164 QDataStream stream( data, IO_ReadOnly );
@@ -166,88 +191,245 @@ void CameraMainWindow::changeZoom( int zoom )
166 default: assert( 0 ); break; 191 default: assert( 0 ); break;
167 } 192 }
168 193
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;
175 reso.setCheckable( true ); 201 reso.setCheckable( true );
176 resog->addTo( &reso ); 202 resog->addTo( &reso );
177 203
178 QPopupMenu quality; 204 QPopupMenu quality;
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 );
185 215
186 QPopupMenu output; 216 QPopupMenu output;
187 output.setCheckable( true ); 217 output.setCheckable( true );
188 outputg->addTo( &output ); 218 outputg->addTo( &output );
189 219
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() );
196} 227}
197 228
198 229
199void CameraMainWindow::resoMenuItemClicked( QAction* a ) 230void CameraMainWindow::resoMenuItemClicked( QAction* a )
200{ 231{
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
207void CameraMainWindow::qualityMenuItemClicked( QAction* a ) 239void 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
222void CameraMainWindow::outputMenuItemClicked( QAction* a ) 275void 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;
245 Global::statusMessage( "Error!" ); 313 Global::statusMessage( "Error!" );
246 } 314 }
247 else 315 else
248 { 316 {
249 odebug << captureFormat << "-image has been successfully captured" << oendl; 317 odebug << captureFormat << "-image has been successfully captured" << oendl;
250 Global::statusMessage( "Ok." ); 318 Global::statusMessage( "Ok." );
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
@@ -17,16 +17,18 @@
17#define MAINWINDOW_H 17#define MAINWINDOW_H
18 18
19#include <qmainwindow.h> 19#include <qmainwindow.h>
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;
30class QCopChannel; 32class QCopChannel;
31class PreviewWidget; 33class PreviewWidget;
32 34
@@ -42,32 +44,49 @@ class CameraMainWindow: public QMainWindow
42 void changeZoom( int ); 44 void changeZoom( int );
43 void systemMessage( const QCString&, const QByteArray& ); 45 void systemMessage( const QCString&, const QByteArray& );
44 void showContextMenu(); 46 void showContextMenu();
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;
56 int _rotation; 67 int _rotation;
57 QCopChannel* _sysChannel; 68 QCopChannel* _sysChannel;
58 69
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
@@ -69,6 +69,20 @@ void PreviewWidget::timerEvent( QTimerEvent* )
69 69
70void PreviewWidget::mousePressEvent( QMouseEvent* ) 70void PreviewWidget::mousePressEvent( QMouseEvent* )
71{ 71{
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
@@ -28,12 +28,15 @@ class PreviewWidget: public QLabel
28 Q_OBJECT 28 Q_OBJECT
29 29
30 public: 30 public:
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* );
37 virtual void mousePressEvent( QMouseEvent* ); 40 virtual void mousePressEvent( QMouseEvent* );
38 41
39 signals: 42 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()
41 } 41 }
42 return ZCameraIO::_instance; 42 return ZCameraIO::_instance;
43} 43}
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 )
51 oerr << "Can't open camera driver: " << strerror(errno) << oendl; 53 oerr << "Can't open camera driver: " << strerror(errno) << oendl;
52 else 54 else
53 init(); 55 init();
@@ -81,24 +83,30 @@ bool ZCameraIO::isOpen() const
81 return _driver != -1; 83 return _driver != -1;
82} 84}
83 85
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
102bool ZCameraIO::isFinderReversed() const 110bool ZCameraIO::isFinderReversed() const
103{ 111{
104 return _status[1] == 'M'; 112 return _status[1] == 'M';
@@ -146,17 +154,26 @@ void ZCameraIO::setReadMode( int mode )
146 char b[10]; 154 char b[10];
147 sprintf( b, "M=%d", mode ); 155 sprintf( b, "M=%d", mode );
148 write( b, mode <= 9 ? 3 : 4 ); 156 write( b, mode <= 9 ? 3 : 4 );
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 );
160} 177}
161 178
162 179
@@ -195,21 +212,31 @@ bool ZCameraIO::snapshot( QImage* image )
195{ 212{
196 setReadMode( STATUS ); 213 setReadMode( STATUS );
197 214
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;
213 240
214 read( bp, _readlen ); 241 read( bp, _readlen );
215 242
@@ -231,24 +258,37 @@ bool ZCameraIO::snapshot( QImage* image )
231 return true; 258 return true;
232} 259}
233 260
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
252void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image ) 292void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image )
253{ 293{
254 int pw = _width; 294 int pw = _width;
@@ -259,6 +299,20 @@ void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image )
259 setCaptureFrame( w, h, zoom*256, false ); 299 setCaptureFrame( w, h, zoom*256, false );
260 snapshot( image ); 300 snapshot( image );
261 setCaptureFrame( pw, ph, _zoom, _rot ); 301 setCaptureFrame( pw, ph, _zoom, _rot );
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
@@ -30,33 +30,36 @@ class ZCameraIO : public QObject
30 30
31 enum ReadMode 31 enum ReadMode
32 { 32 {
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
40 41
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();
60 void clearShutterLatch(); 63 void clearShutterLatch();
61 void init(); 64 void init();
62 bool read( char*, int ); 65 bool read( char*, int );
@@ -65,16 +68,18 @@ class ZCameraIO : public QObject
65 signals: 68 signals:
66 void shutterClicked(); 69 void shutterClicked();
67 70
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
78 QTime* _timer; 83 QTime* _timer;
79}; 84};
80 85