Diffstat (limited to 'noncore/multimedia/camera/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/camera/mainwindow.cpp | 198 |
1 files changed, 190 insertions, 8 deletions
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 | |||
@@ -18,2 +18,3 @@ | |||
18 | #include "zcameraio.h" | 18 | #include "zcameraio.h" |
19 | #include "imageio.h" | ||
19 | 20 | ||
@@ -29,4 +30,6 @@ | |||
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> |
@@ -38,3 +41,2 @@ | |||
38 | using namespace Opie; | 41 | using namespace Opie; |
39 | |||
40 | #include <opie2/odebug.h> | 42 | #include <opie2/odebug.h> |
@@ -42,5 +44,13 @@ using namespace Opie; | |||
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 | ||
44 | CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) | 54 | CameraMainWindow::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 | { |
@@ -80,2 +90,5 @@ CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags | |||
80 | connect( ZCameraIO::instance(), SIGNAL( shutterClicked() ), this, SLOT( shutterClicked() ) ); | 90 | connect( ZCameraIO::instance(), SIGNAL( shutterClicked() ), this, SLOT( shutterClicked() ) ); |
91 | |||
92 | updateCaption(); | ||
93 | |||
81 | }; | 94 | }; |
@@ -91,2 +104,3 @@ void CameraMainWindow::init() | |||
91 | // TODO: Save this stuff in config | 104 | // TODO: Save this stuff in config |
105 | flip = 'A'; // auto | ||
92 | quality = 50; | 106 | quality = 50; |
@@ -123,2 +137,10 @@ void CameraMainWindow::init() | |||
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 ); |
@@ -128,2 +150,3 @@ void CameraMainWindow::init() | |||
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 | ||
@@ -132,3 +155,5 @@ void CameraMainWindow::init() | |||
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 | } |
@@ -171,2 +196,3 @@ void CameraMainWindow::changeZoom( int zoom ) | |||
171 | 196 | ||
197 | |||
172 | void CameraMainWindow::showContextMenu() | 198 | void CameraMainWindow::showContextMenu() |
@@ -181,2 +207,6 @@ void CameraMainWindow::showContextMenu() | |||
181 | 207 | ||
208 | QPopupMenu flip; | ||
209 | flip.setCheckable( true ); | ||
210 | flipg->addTo( &flip ); | ||
211 | |||
182 | QPopupMenu zoom; | 212 | QPopupMenu zoom; |
@@ -192,2 +222,3 @@ void CameraMainWindow::showContextMenu() | |||
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 ); |
@@ -203,2 +234,3 @@ void CameraMainWindow::resoMenuItemClicked( QAction* a ) | |||
203 | odebug << "Capture Resolution now: " << captureX << ", " << captureY << oendl; | 234 | odebug << "Capture Resolution now: " << captureX << ", " << captureY << oendl; |
235 | updateCaption(); | ||
204 | } | 236 | } |
@@ -210,2 +242,3 @@ void CameraMainWindow::qualityMenuItemClicked( QAction* a ) | |||
210 | odebug << "Quality now: " << quality << oendl; | 242 | odebug << "Quality now: " << quality << oendl; |
243 | updateCaption(); | ||
211 | } | 244 | } |
@@ -215,5 +248,25 @@ void 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 | |||
256 | void 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 | } |
@@ -225,2 +278,3 @@ void CameraMainWindow::outputMenuItemClicked( QAction* a ) | |||
225 | odebug << "Output format now: " << captureFormat << oendl; | 278 | odebug << "Output format now: " << captureFormat << oendl; |
279 | updateCaption(); | ||
226 | } | 280 | } |
@@ -230,7 +284,21 @@ void 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 | |||
302 | void CameraMainWindow::performCapture( const QString& format ) | ||
303 | { | ||
236 | QString name; | 304 | QString name; |
@@ -240,3 +308,3 @@ void CameraMainWindow::shutterClicked() | |||
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 ) |
@@ -253 +321,115 @@ void CameraMainWindow::shutterClicked() | |||
253 | 321 | ||
322 | |||
323 | void 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 | |||
345 | void 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 | |||
361 | void 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 | |||
381 | void 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 | |||
427 | void 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 | |||