Diffstat (limited to 'noncore/multimedia/camera/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/camera/mainwindow.cpp | 162 |
1 files changed, 139 insertions, 23 deletions
diff --git a/noncore/multimedia/camera/mainwindow.cpp b/noncore/multimedia/camera/mainwindow.cpp index 6141fd1..e27a50e 100644 --- a/noncore/multimedia/camera/mainwindow.cpp +++ b/noncore/multimedia/camera/mainwindow.cpp | |||
@@ -1,79 +1,84 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. | 2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Opie Environment. | 4 | ** This file is part of Opie Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 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 | 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 | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
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 | #include "imageio.h" |
20 | #include "avi.h" | ||
20 | 21 | ||
21 | #include <qapplication.h> | 22 | #include <qapplication.h> |
22 | #include <qaction.h> | 23 | #include <qaction.h> |
23 | #include <qvbox.h> | 24 | #include <qvbox.h> |
24 | #include <qcombobox.h> | 25 | #include <qcombobox.h> |
25 | #include <qcursor.h> | 26 | #include <qcursor.h> |
26 | #include <qdatastream.h> | 27 | #include <qdatastream.h> |
27 | #include <qfile.h> | 28 | #include <qfile.h> |
28 | #include <qimage.h> | 29 | #include <qimage.h> |
29 | #include <qlabel.h> | 30 | #include <qlabel.h> |
30 | #include <qpopupmenu.h> | 31 | #include <qpopupmenu.h> |
31 | #include <qprogressbar.h> | 32 | #include <qprogressbar.h> |
32 | #include <qpushbutton.h> | 33 | #include <qpushbutton.h> |
33 | #include <qmessagebox.h> | 34 | #include <qmessagebox.h> |
34 | #include <qlayout.h> | 35 | #include <qlayout.h> |
35 | #include <qdirectpainter_qws.h> | 36 | #include <qdirectpainter_qws.h> |
36 | #include <qpe/global.h> | 37 | #include <qpe/global.h> |
37 | #include <qpe/resource.h> | 38 | #include <qpe/resource.h> |
38 | #include <qpe/qcopenvelope_qws.h> | 39 | #include <qpe/qcopenvelope_qws.h> |
39 | #include <opie/ofiledialog.h> | 40 | #include <opie/ofiledialog.h> |
40 | #include <opie/odevice.h> | 41 | #include <opie/odevice.h> |
41 | using namespace Opie; | 42 | using namespace Opie; |
42 | #include <opie2/odebug.h> | 43 | #include <opie2/odebug.h> |
43 | 44 | ||
44 | #include <assert.h> | 45 | #include <assert.h> |
45 | #include <sys/types.h> | 46 | #include <sys/types.h> |
46 | #include <sys/stat.h> | 47 | #include <sys/stat.h> |
47 | #include <fcntl.h> | 48 | #include <fcntl.h> |
48 | #include <string.h> | 49 | #include <string.h> |
49 | #include <errno.h> | 50 | #include <errno.h> |
50 | #include <unistd.h> | 51 | #include <unistd.h> |
51 | 52 | ||
52 | #define CAPTUREFILE "/tmp/capture.dat" | 53 | #define CAPTUREFILE "/tmp/capture.dat" |
54 | #define OUTPUTFILE "/tmp/output.avi" | ||
53 | 55 | ||
54 | CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) | 56 | CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) |
55 | :QMainWindow( parent, name, f ), _capturing( false ), _pics( 0 ) | 57 | :QMainWindow( parent, name, f ), |
58 | _rotation( 270 ), // FIXME: get this from current settings (ODevice?) | ||
59 | _capturing( false ), | ||
60 | _pics( 0 ), _videos( 0 ) | ||
56 | { | 61 | { |
57 | #ifdef QT_NO_DEBUG | 62 | #ifdef QT_NO_DEBUG |
58 | if ( !ZCameraIO::instance()->isOpen() ) | 63 | if ( !ZCameraIO::instance()->isOpen() ) |
59 | { | 64 | { |
60 | QVBox* v = new QVBox( this ); | 65 | QVBox* v = new QVBox( this ); |
61 | v->setMargin( 10 ); | 66 | v->setMargin( 10 ); |
62 | QLabel* l1 = new QLabel( v ); | 67 | QLabel* l1 = new QLabel( v ); |
63 | l1->setPixmap( Resource::loadPixmap( "camera/error" ) ); | 68 | l1->setPixmap( Resource::loadPixmap( "camera/error" ) ); |
64 | QLabel* l2 = new QLabel( v ); | 69 | QLabel* l2 = new QLabel( v ); |
65 | l2->setText( "<b>Sorry. could not detect your camera :-(</b><p>" | 70 | l2->setText( "<b>Sorry. could not detect your camera :-(</b><p>" |
66 | "* Is the sharpzdc_cs module loaded ?<br>" | 71 | "* Is the sharpzdc_cs module loaded ?<br>" |
67 | "* Is /dev/sharpzdc read/writable ?<p>" ); | 72 | "* Is /dev/sharpzdc read/writable ?<p>" ); |
68 | connect( new QPushButton( "Exit", v ), SIGNAL( clicked() ), this, SLOT( close() ) ); | 73 | connect( new QPushButton( "Exit", v ), SIGNAL( clicked() ), this, SLOT( close() ) ); |
69 | setCentralWidget( v ); | 74 | setCentralWidget( v ); |
70 | return; | 75 | return; |
71 | } | 76 | } |
72 | #endif | 77 | #endif |
73 | 78 | ||
74 | init(); | 79 | init(); |
75 | 80 | ||
76 | _rotation = 270; //TODO: grab these from the actual settings | 81 | _rotation = 270; //TODO: grab these from the actual settings |
77 | 82 | ||
78 | preview = new PreviewWidget( this, "camera preview widget" ); | 83 | preview = new PreviewWidget( this, "camera preview widget" ); |
79 | //setCentralWidget( preview ); <--- don't do this! | 84 | //setCentralWidget( preview ); <--- don't do this! |
@@ -84,50 +89,50 @@ CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags | |||
84 | _sysChannel = new QCopChannel( "QPE/System", this ); | 89 | _sysChannel = new QCopChannel( "QPE/System", this ); |
85 | connect( _sysChannel, SIGNAL( received( const QCString&, const QByteArray& ) ), | 90 | connect( _sysChannel, SIGNAL( received( const QCString&, const QByteArray& ) ), |
86 | this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); | 91 | this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); |
87 | 92 | ||
88 | connect( preview, SIGNAL( contextMenuRequested() ), this, SLOT( showContextMenu() ) ); | 93 | connect( preview, SIGNAL( contextMenuRequested() ), this, SLOT( showContextMenu() ) ); |
89 | 94 | ||
90 | connect( ZCameraIO::instance(), SIGNAL( shutterClicked() ), this, SLOT( shutterClicked() ) ); | 95 | connect( ZCameraIO::instance(), SIGNAL( shutterClicked() ), this, SLOT( shutterClicked() ) ); |
91 | 96 | ||
92 | updateCaption(); | 97 | updateCaption(); |
93 | 98 | ||
94 | }; | 99 | }; |
95 | 100 | ||
96 | 101 | ||
97 | CameraMainWindow::~CameraMainWindow() | 102 | CameraMainWindow::~CameraMainWindow() |
98 | { | 103 | { |
99 | } | 104 | } |
100 | 105 | ||
101 | 106 | ||
102 | void CameraMainWindow::init() | 107 | void CameraMainWindow::init() |
103 | { | 108 | { |
104 | // TODO: Save this stuff in config | 109 | // TODO: Save this stuff in config |
105 | flip = 'A'; // auto | 110 | flip = 'A'; // auto |
106 | quality = 50; | 111 | quality = 50; |
107 | zoom = 1; | 112 | zoom = 1; |
108 | captureX = 640; | 113 | captureX = 480; |
109 | captureY = 480; | 114 | captureY = 640; |
110 | captureFormat = "JPEG"; | 115 | captureFormat = "JPEG"; |
111 | 116 | ||
112 | resog = new QActionGroup( 0, "reso", true ); | 117 | resog = new QActionGroup( 0, "reso", true ); |
113 | resog->setToggleAction( true ); | 118 | resog->setToggleAction( true ); |
114 | new QAction( " 64 x 48", 0, 0, resog, 0, true ); | 119 | new QAction( " 64 x 48", 0, 0, resog, 0, true ); |
115 | new QAction( "128 x 96", 0, 0, resog, 0, true ); | 120 | new QAction( "128 x 96", 0, 0, resog, 0, true ); |
116 | new QAction( "192 x 144", 0, 0, resog, 0, true ); | 121 | new QAction( "192 x 144", 0, 0, resog, 0, true ); |
117 | new QAction( "256 x 192", 0, 0, resog, 0, true ); | 122 | new QAction( "256 x 192", 0, 0, resog, 0, true ); |
118 | new QAction( "320 x 240", 0, 0, resog, 0, true ); | 123 | new QAction( "320 x 240", 0, 0, resog, 0, true ); |
119 | new QAction( "384 x 288", 0, 0, resog, 0, true ); | 124 | new QAction( "384 x 288", 0, 0, resog, 0, true ); |
120 | new QAction( "448 x 336", 0, 0, resog, 0, true ); | 125 | new QAction( "448 x 336", 0, 0, resog, 0, true ); |
121 | new QAction( "512 x 384", 0, 0, resog, 0, true ); | 126 | new QAction( "512 x 384", 0, 0, resog, 0, true ); |
122 | new QAction( "576 x 432", 0, 0, resog, 0, true ); | 127 | new QAction( "576 x 432", 0, 0, resog, 0, true ); |
123 | ( new QAction( "640 x 480", 0, 0, resog, 0, true ) )->setOn( true ); | 128 | ( new QAction( "640 x 480", 0, 0, resog, 0, true ) )->setOn( true ); |
124 | 129 | ||
125 | qualityg = new QActionGroup( 0, "quality", true ); | 130 | qualityg = new QActionGroup( 0, "quality", true ); |
126 | qualityg->setToggleAction( true ); | 131 | qualityg->setToggleAction( true ); |
127 | new QAction( " 0 (minimal)", 0, 0, qualityg, 0, true ); | 132 | new QAction( " 0 (minimal)", 0, 0, qualityg, 0, true ); |
128 | new QAction( " 25 (low)", 0, 0, qualityg, 0, true ); | 133 | new QAction( " 25 (low)", 0, 0, qualityg, 0, true ); |
129 | ( new QAction( " 50 (good)", 0, 0, qualityg, 0, true ) )->setOn( true ); | 134 | ( new QAction( " 50 (good)", 0, 0, qualityg, 0, true ) )->setOn( true ); |
130 | new QAction( " 75 (better)", 0, 0, qualityg, 0, true ); | 135 | new QAction( " 75 (better)", 0, 0, qualityg, 0, true ); |
131 | new QAction( "100 (best)", 0, 0, qualityg, 0, true ); | 136 | new QAction( "100 (best)", 0, 0, qualityg, 0, true ); |
132 | 137 | ||
133 | zoomg = new QActionGroup( 0, "zoom", true ); | 138 | zoomg = new QActionGroup( 0, "zoom", true ); |
@@ -140,118 +145,148 @@ void CameraMainWindow::init() | |||
140 | ( new QAction( "Auto (recommended)", 0, 0, flipg, 0, true ) )->setOn( true ); | 145 | ( new QAction( "Auto (recommended)", 0, 0, flipg, 0, true ) )->setOn( true ); |
141 | new QAction( "0 (always off)", 0, 0, flipg, 0, true ); | 146 | new QAction( "0 (always off)", 0, 0, flipg, 0, true ); |
142 | new QAction( "X (always horizontal)", 0, 0, flipg, 0, true ); | 147 | new QAction( "X (always horizontal)", 0, 0, flipg, 0, true ); |
143 | new QAction( "Y (always vertical)", 0, 0, flipg, 0, true ); | 148 | new QAction( "Y (always vertical)", 0, 0, flipg, 0, true ); |
144 | new QAction( "* (always both)", 0, 0, flipg, 0, true ); | 149 | new QAction( "* (always both)", 0, 0, flipg, 0, true ); |
145 | 150 | ||
146 | outputg = new QActionGroup( 0, "output", true ); | 151 | outputg = new QActionGroup( 0, "output", true ); |
147 | outputg->setToggleAction( true ); | 152 | outputg->setToggleAction( true ); |
148 | ( new QAction( "JPEG", 0, 0, outputg, 0, true ) )->setOn( true ); | 153 | ( new QAction( "JPEG", 0, 0, outputg, 0, true ) )->setOn( true ); |
149 | new QAction( "PNG", 0, 0, outputg, 0, true ); | 154 | new QAction( "PNG", 0, 0, outputg, 0, true ); |
150 | new QAction( "BMP", 0, 0, outputg, 0, true ); | 155 | new QAction( "BMP", 0, 0, outputg, 0, true ); |
151 | new QAction( "AVI", 0, 0, outputg, 0, true ); | 156 | new QAction( "AVI", 0, 0, outputg, 0, true ); |
152 | 157 | ||
153 | connect( resog, SIGNAL( selected(QAction*) ), this, SLOT( resoMenuItemClicked(QAction*) ) ); | 158 | connect( resog, SIGNAL( selected(QAction*) ), this, SLOT( resoMenuItemClicked(QAction*) ) ); |
154 | connect( qualityg, SIGNAL( selected(QAction*) ), this, SLOT( qualityMenuItemClicked(QAction*) ) ); | 159 | connect( qualityg, SIGNAL( selected(QAction*) ), this, SLOT( qualityMenuItemClicked(QAction*) ) ); |
155 | connect( zoomg, SIGNAL( selected(QAction*) ), this, SLOT( zoomMenuItemClicked(QAction*) ) ); | 160 | connect( zoomg, SIGNAL( selected(QAction*) ), this, SLOT( zoomMenuItemClicked(QAction*) ) ); |
156 | connect( flipg, SIGNAL( selected(QAction*) ), this, SLOT( flipMenuItemClicked(QAction*) ) ); | 161 | connect( flipg, SIGNAL( selected(QAction*) ), this, SLOT( flipMenuItemClicked(QAction*) ) ); |
157 | connect( outputg, SIGNAL( selected(QAction*) ), this, SLOT( outputMenuItemClicked(QAction*) ) ); | 162 | connect( outputg, SIGNAL( selected(QAction*) ), this, SLOT( outputMenuItemClicked(QAction*) ) ); |
158 | 163 | ||
159 | } | 164 | } |
160 | 165 | ||
161 | 166 | ||
162 | void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data ) | 167 | void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data ) |
163 | { | 168 | { |
169 | int _newrotation; | ||
170 | |||
164 | QDataStream stream( data, IO_ReadOnly ); | 171 | QDataStream stream( data, IO_ReadOnly ); |
165 | odebug << "received system message: " << msg << oendl; | 172 | odebug << "received system message: " << msg << oendl; |
166 | if ( msg == "setCurrentRotation(int)" ) | 173 | if ( msg == "setCurrentRotation(int)" ) |
167 | { | 174 | { |
168 | stream >> _rotation; | 175 | stream >> _newrotation; |
169 | odebug << "received setCurrentRotation(" << _rotation << ")" << oendl; | 176 | odebug << "received setCurrentRotation(" << _newrotation << ")" << oendl; |
170 | 177 | ||
171 | switch ( _rotation ) | 178 | switch ( _newrotation ) |
172 | { | 179 | { |
173 | case 270: preview->resize( QSize( 240, 288 ) ); break; | 180 | case 270: preview->resize( QSize( 240, 288 ) ); break; |
174 | case 180: preview->resize( QSize( 320, 208 ) ); break; | 181 | case 180: preview->resize( QSize( 320, 208 ) ); break; |
175 | default: QMessageBox::warning( this, "opie-camera", | 182 | default: QMessageBox::warning( this, "opie-camera", |
176 | "This rotation is not supported.\n" | 183 | "This rotation is not supported.\n" |
177 | "Supported are 180° and 270°" ); | 184 | "Supported are 180° and 270°" ); |
178 | } | 185 | } |
186 | |||
187 | if ( _newrotation != _rotation ) | ||
188 | { | ||
189 | int tmp = captureX; | ||
190 | captureX = captureY; | ||
191 | captureY = tmp; | ||
192 | _rotation = _newrotation; | ||
193 | } | ||
194 | |||
195 | updateCaption(); | ||
196 | |||
179 | } | 197 | } |
180 | } | 198 | } |
181 | 199 | ||
182 | 200 | ||
183 | void CameraMainWindow::changeZoom( int zoom ) | 201 | void CameraMainWindow::changeZoom( int zoom ) |
184 | { | 202 | { |
185 | int z; | 203 | int z; |
186 | switch ( zoom ) | 204 | switch ( zoom ) |
187 | { | 205 | { |
188 | case 0: z = 128; break; | 206 | case 0: z = 128; break; |
189 | case 1: z = 256; break; | 207 | case 1: z = 256; break; |
190 | case 2: z = 512; break; | 208 | case 2: z = 512; break; |
191 | default: assert( 0 ); break; | 209 | default: assert( 0 ); break; |
192 | } | 210 | } |
193 | 211 | ||
194 | ZCameraIO::instance()->setCaptureFrame( 240, 160, z ); | 212 | ZCameraIO::instance()->setCaptureFrame( 240, 160, z ); |
195 | } | 213 | } |
196 | 214 | ||
197 | 215 | ||
198 | void CameraMainWindow::showContextMenu() | 216 | void CameraMainWindow::showContextMenu() |
199 | { | 217 | { |
200 | QPopupMenu reso; | 218 | QPopupMenu reso; |
201 | reso.setCheckable( true ); | 219 | reso.setCheckable( true ); |
202 | resog->addTo( &reso ); | 220 | resog->addTo( &reso ); |
203 | 221 | ||
204 | QPopupMenu quality; | 222 | QPopupMenu quality; |
205 | quality.setCheckable( true ); | 223 | quality.setCheckable( true ); |
206 | qualityg->addTo( &quality ); | 224 | qualityg->addTo( &quality ); |
207 | 225 | ||
208 | QPopupMenu flip; | 226 | QPopupMenu flip; |
209 | flip.setCheckable( true ); | 227 | flip.setCheckable( true ); |
210 | flipg->addTo( &flip ); | 228 | flipg->addTo( &flip ); |
211 | 229 | ||
212 | QPopupMenu zoom; | 230 | QPopupMenu zoom; |
213 | zoom.setCheckable( true ); | 231 | zoom.setCheckable( true ); |
214 | zoomg->addTo( &zoom ); | 232 | zoomg->addTo( &zoom ); |
215 | 233 | ||
216 | QPopupMenu output; | 234 | QPopupMenu output; |
217 | output.setCheckable( true ); | 235 | output.setCheckable( true ); |
218 | outputg->addTo( &output ); | 236 | outputg->addTo( &output ); |
219 | 237 | ||
220 | QPopupMenu m( this ); | 238 | QPopupMenu m( this ); |
221 | m.insertItem( "&Resolution", &reso ); | 239 | m.insertItem( "&Resolution", &reso ); |
222 | m.insertItem( "&Zoom", &zoom ); | 240 | m.insertItem( "&Zoom", &zoom ); |
223 | m.insertItem( "&Flip", &flip ); | 241 | m.insertItem( "&Flip", &flip ); |
224 | m.insertItem( "&Quality", &quality ); | 242 | m.insertItem( "&Quality", &quality ); |
225 | m.insertItem( "&Output As", &output ); | 243 | m.insertItem( "&Output As", &output ); |
244 | |||
245 | #ifndef QT_NO_DEBUG | ||
246 | m.insertItem( "&Debug!", this, SLOT( doSomething() ) ); | ||
247 | #endif | ||
248 | |||
226 | m.exec( QCursor::pos() ); | 249 | m.exec( QCursor::pos() ); |
227 | } | 250 | } |
228 | 251 | ||
229 | 252 | ||
230 | void CameraMainWindow::resoMenuItemClicked( QAction* a ) | 253 | void CameraMainWindow::resoMenuItemClicked( QAction* a ) |
231 | { | 254 | { |
232 | captureX = a->text().left(3).toInt(); | 255 | switch ( _rotation ) |
233 | captureY = a->text().right(3).toInt(); | 256 | { |
257 | case 270: | ||
258 | captureY = a->text().left(3).toInt(); | ||
259 | captureX = a->text().right(3).toInt(); | ||
260 | break; | ||
261 | case 180: | ||
262 | captureX = a->text().left(3).toInt(); | ||
263 | captureY = a->text().right(3).toInt(); | ||
264 | break; | ||
265 | default: QMessageBox::warning( this, "opie-camera", | ||
266 | "This rotation is not supported.\n" | ||
267 | "Supported are 180° and 270°" ); | ||
268 | } | ||
234 | odebug << "Capture Resolution now: " << captureX << ", " << captureY << oendl; | 269 | odebug << "Capture Resolution now: " << captureX << ", " << captureY << oendl; |
235 | updateCaption(); | 270 | updateCaption(); |
236 | } | 271 | } |
237 | 272 | ||
238 | 273 | ||
239 | void CameraMainWindow::qualityMenuItemClicked( QAction* a ) | 274 | void CameraMainWindow::qualityMenuItemClicked( QAction* a ) |
240 | { | 275 | { |
241 | quality = a->text().left(3).toInt(); | 276 | quality = a->text().left(3).toInt(); |
242 | odebug << "Quality now: " << quality << oendl; | 277 | odebug << "Quality now: " << quality << oendl; |
243 | updateCaption(); | 278 | updateCaption(); |
244 | } | 279 | } |
245 | 280 | ||
246 | 281 | ||
247 | void CameraMainWindow::zoomMenuItemClicked( QAction* a ) | 282 | void CameraMainWindow::zoomMenuItemClicked( QAction* a ) |
248 | { | 283 | { |
249 | zoom = QString( a->text().at(2) ).toInt(); | 284 | zoom = QString( a->text().at(2) ).toInt(); |
250 | odebug << "Zoom now: " << zoom << oendl; | 285 | odebug << "Zoom now: " << zoom << oendl; |
251 | ZCameraIO::instance()->setZoom( zoom ); | 286 | ZCameraIO::instance()->setZoom( zoom ); |
252 | updateCaption(); | 287 | updateCaption(); |
253 | } | 288 | } |
254 | 289 | ||
255 | 290 | ||
256 | void CameraMainWindow::flipMenuItemClicked( QAction* a ) | 291 | void CameraMainWindow::flipMenuItemClicked( QAction* a ) |
257 | { | 292 | { |
@@ -304,132 +339,213 @@ void CameraMainWindow::performCapture( const QString& format ) | |||
304 | QString name; | 339 | QString name; |
305 | name.sprintf( "/tmp/image-%d_%d_%d_q%d.%s", _pics++, captureX, captureY, quality, (const char*) captureFormat.lower() ); | 340 | name.sprintf( "/tmp/image-%d_%d_%d_q%d.%s", _pics++, captureX, captureY, quality, (const char*) captureFormat.lower() ); |
306 | QImage i; | 341 | QImage i; |
307 | ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, &i ); | 342 | ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, &i ); |
308 | QImage im = i.convertDepth( 32 ); | 343 | QImage im = i.convertDepth( 32 ); |
309 | bool result = im.save( name, format, quality ); | 344 | bool result = im.save( name, format, quality ); |
310 | if ( !result ) | 345 | if ( !result ) |
311 | { | 346 | { |
312 | oerr << "imageio-Problem while writing." << oendl; | 347 | oerr << "imageio-Problem while writing." << oendl; |
313 | Global::statusMessage( "Error!" ); | 348 | Global::statusMessage( "Error!" ); |
314 | } | 349 | } |
315 | else | 350 | else |
316 | { | 351 | { |
317 | odebug << captureFormat << "-image has been successfully captured" << oendl; | 352 | odebug << captureFormat << "-image has been successfully captured" << oendl; |
318 | Global::statusMessage( "Ok." ); | 353 | Global::statusMessage( "Ok." ); |
319 | } | 354 | } |
320 | } | 355 | } |
321 | 356 | ||
322 | 357 | ||
323 | void CameraMainWindow::startVideoCapture() | 358 | void CameraMainWindow::startVideoCapture() |
324 | { | 359 | { |
325 | //ODevice::inst()->touchSound(); | 360 | //ODevice::inst()->touchSound(); |
326 | ODevice::inst()->setLedState( Led_Mail, Led_BlinkSlow ); | 361 | ODevice::inst()->setLedState( Led_Mail, Led_BlinkSlow ); |
327 | 362 | ||
328 | _capturefd = ::open( CAPTUREFILE, O_WRONLY | O_CREAT ); | 363 | _capturefd = ::open( CAPTUREFILE, O_WRONLY | O_CREAT | O_TRUNC ); |
329 | if ( _capturefd == -1 ) | 364 | if ( _capturefd == -1 ) |
330 | { | 365 | { |
331 | owarn << "can't open capture file: " << strerror(errno) << oendl; | 366 | owarn << "can't open capture file: " << strerror(errno) << oendl; |
332 | return; | 367 | return; |
333 | } | 368 | } |
334 | 369 | ||
335 | _capturebuf = new unsigned char[captureX*captureY*2]; | 370 | _capturebuf = new unsigned char[captureX*captureY*2]; |
336 | _capturing = true; | 371 | _capturing = true; |
337 | _videopics = 0; | 372 | _videopics = 0; |
373 | _framerate = 0; | ||
338 | updateCaption(); | 374 | updateCaption(); |
339 | _time.start(); | 375 | _time.start(); |
340 | preview->setRefreshingRate( 1000 ); | 376 | preview->setRefreshingRate( 1000 ); |
341 | startTimer( 100 ); // too fast but that is ok | 377 | startTimer( 100 ); // too fast but that is ok |
342 | } | 378 | } |
343 | 379 | ||
344 | 380 | ||
345 | void CameraMainWindow::timerEvent( QTimerEvent* ) | 381 | void CameraMainWindow::timerEvent( QTimerEvent* ) |
346 | { | 382 | { |
347 | if ( !_capturing ) | 383 | if ( !_capturing ) |
348 | { | 384 | { |
349 | owarn << "timer event in CameraMainWindow without capturing video ?" << oendl; | 385 | odebug << "timer event in CameraMainWindow without capturing video ?" << oendl; |
350 | return; | 386 | return; |
351 | } | 387 | } |
352 | 388 | ||
389 | odebug << "timer event during video - now capturing frame #" << _videopics+1 << oendl; | ||
390 | |||
353 | ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, _capturebuf ); | 391 | ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, _capturebuf ); |
354 | _videopics++; | 392 | _videopics++; |
355 | ::write( _capturefd, _capturebuf, captureX*captureY*2 ); | 393 | ::write( _capturefd, _capturebuf, captureX*captureY*2 ); |
356 | setCaption( QString().sprintf( "Capturing %dx%d @ %.2f fps %d", | 394 | setCaption( QString().sprintf( "Capturing %dx%d @ %.2f fps %d", |
357 | captureX, captureY, 1000.0 / (_time.elapsed()/_videopics), _videopics ) ); | 395 | captureX, captureY, 1000.0 / (_time.elapsed()/_videopics), _videopics ) ); |
358 | } | 396 | } |
359 | 397 | ||
360 | 398 | ||
361 | void CameraMainWindow::stopVideoCapture() | 399 | void CameraMainWindow::stopVideoCapture() |
362 | { | 400 | { |
363 | killTimers(); | 401 | killTimers(); |
364 | //ODevice::inst()->touchSound(); | 402 | //ODevice::inst()->touchSound(); |
365 | ODevice::inst()->setLedState( Led_Mail, Led_Off ); | 403 | ODevice::inst()->setLedState( Led_Mail, Led_Off ); |
366 | _capturing = false; | 404 | _capturing = false; |
367 | updateCaption(); | 405 | updateCaption(); |
368 | ::close( _capturefd ); | 406 | ::close( _capturefd ); |
407 | _framerate = 1000.0 / (_time.elapsed()/_videopics); | ||
369 | 408 | ||
370 | //postProcessVideo(); | 409 | postProcessVideo( CAPTUREFILE, QString().sprintf( "/tmp/video-%d_%d_%d_q%d-%dfps.avi", _videos++, captureX, captureY, quality, _framerate ) ); |
371 | 410 | ||
372 | #ifndef QT_NO_DEBUG | 411 | #ifndef QT_NO_DEBUG |
373 | preview->setRefreshingRate( 1500 ); | 412 | preview->setRefreshingRate( 1500 ); |
374 | #else | 413 | #else |
375 | preview->setRefreshingRate( 200 ); | 414 | preview->setRefreshingRate( 200 ); |
376 | #endif | 415 | #endif |
377 | 416 | ||
378 | //delete[] _capturebuf; //FIXME: close memory leak | 417 | //delete[] _capturebuf; //FIXME: close memory leak |
379 | } | 418 | } |
380 | 419 | ||
381 | void CameraMainWindow::postProcessVideo() | 420 | void CameraMainWindow::postProcessVideo( const QString& infile, const QString& outfile ) |
382 | { | 421 | { |
383 | preview->setRefreshingRate( 0 ); | 422 | preview->setRefreshingRate( 0 ); |
384 | 423 | ||
385 | /* | 424 | /* |
425 | unsigned char buf[153600]; | ||
386 | 426 | ||
387 | QDialog* fr = new QDialog( this, "splash" ); //, false, QWidget::WStyle_NoBorder | QWidget::WStyle_Customize ); | 427 | int fd = ::open( "/var/compile/opie/noncore/multimedia/camera/capture-320x240.dat", O_RDONLY ); |
428 | ::read( fd, &buf, 153600 ); | ||
429 | QImage i; | ||
430 | bufferToImage( 240, 320, (unsigned char*) &buf, &i ); | ||
431 | QPixmap p; | ||
432 | p.convertFromImage( i ); | ||
433 | preview->setPixmap( p ); | ||
434 | imageToFile( &i, "/tmp/tmpfile", "JPEG", 100 ); | ||
435 | return; | ||
436 | */ | ||
437 | |||
438 | QDialog* fr = new QDialog( this, "splash", false, QWidget::WStyle_StaysOnTop ); //, false, QWidget::WStyle_NoBorder | QWidget::WStyle_Customize ); | ||
388 | fr->setCaption( "Please wait..." ); | 439 | fr->setCaption( "Please wait..." ); |
389 | QVBoxLayout* box = new QVBoxLayout( fr, 2, 2 ); | 440 | QVBoxLayout* box = new QVBoxLayout( fr, 2, 2 ); |
390 | QProgressBar* bar = new QProgressBar( fr ); | 441 | QProgressBar* bar = new QProgressBar( fr ); |
391 | bar->setCenterIndicator( true ); | 442 | bar->setCenterIndicator( true ); |
392 | bar->setTotalSteps( _videopics-1 ); | 443 | bar->setTotalSteps( _videopics-1 ); |
393 | QLabel* label = new QLabel( "Post processing frame bla/bla", fr ); | 444 | QLabel* label = new QLabel( "Post processing frame bla/bla", fr ); |
394 | box->addWidget( bar ); | 445 | box->addWidget( bar ); |
395 | box->addWidget( label ); | 446 | box->addWidget( label ); |
396 | fr->show(); | 447 | fr->show(); |
448 | label->show(); | ||
449 | bar->show(); | ||
450 | fr->repaint(); | ||
397 | qApp->processEvents(); | 451 | qApp->processEvents(); |
398 | 452 | ||
399 | for ( int i = 0; i < _videopics; ++i ) | 453 | // open files |
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 | 454 | ||
408 | int infd = ::open( CAPTUREFILE, O_RDONLY ); | 455 | int infd = ::open( (const char*) infile, O_RDONLY ); |
409 | if ( infd == -1 ) | 456 | if ( infd == -1 ) |
410 | { | 457 | { |
411 | owarn << "couldn't open capture file: " << strerror(errno) << oendl; | 458 | owarn << "couldn't open capture file: " << strerror(errno) << oendl; |
412 | return; | 459 | return; |
413 | } | 460 | } |
414 | 461 | ||
415 | int outfd = ::open( "/tmp/output.avi", O_WRONLY ); | 462 | int outfd = ::open( (const char*) outfile, O_CREAT | O_WRONLY | O_TRUNC, 0644 ); |
416 | if ( outfd == -1 ) | 463 | if ( outfd == -1 ) |
417 | { | 464 | { |
418 | owarn << "couldn't open output file: " << strerror(errno) << oendl; | 465 | owarn << "couldn't open output file: " << strerror(errno) << oendl; |
419 | return; | 466 | return; |
420 | } | 467 | } |
421 | 468 | ||
469 | int framesize = captureX*captureY*2; | ||
470 | |||
471 | unsigned char* inbuffer = new unsigned char[ framesize ]; | ||
472 | QImage image; | ||
422 | 473 | ||
474 | avi_start( outfd, _videopics ); // write preambel | ||
423 | 475 | ||
476 | // post process | ||
477 | |||
478 | for ( int i = 0; i < _videopics; ++i ) | ||
479 | { | ||
480 | odebug << "processing frame " << i << oendl; | ||
481 | |||
482 | // <gui> | ||
483 | label->setText( QString().sprintf( "Post processing frame %d / %d", i+1, _videopics ) ); | ||
484 | bar->setProgress( i ); | ||
485 | bar->repaint(); | ||
486 | qApp->processEvents(); | ||
487 | // </gui> | ||
488 | |||
489 | int read = ::read( infd, inbuffer, framesize ); | ||
490 | odebug << "read " << read << " bytes" << oendl; | ||
491 | bufferToImage( captureX, captureY, inbuffer, &image ); | ||
492 | |||
493 | QPixmap p; | ||
494 | p.convertFromImage( image ); | ||
495 | preview->setPixmap( p ); | ||
496 | preview->repaint(); | ||
497 | qApp->processEvents(); | ||
498 | |||
499 | QString tmpfilename( "/tmp/tempfile" ); | ||
500 | //tmpfilename.sprintf( "/tmp/test/%d.jpg", i ); | ||
501 | |||
502 | imageToFile( &image, tmpfilename, "JPEG", quality ); | ||
503 | |||
504 | QFile framefile( tmpfilename ); | ||
505 | if ( !framefile.open( IO_ReadOnly ) ) | ||
506 | { | ||
507 | oerr << "can't process file: %s" << strerror(errno) << oendl; | ||
508 | return; // TODO: clean up temp ressources | ||
509 | } | ||
510 | |||
511 | int filesize = framefile.size(); | ||
512 | odebug << "filesize for frame " << i << " = " << filesize << oendl; | ||
513 | |||
514 | unsigned char* tempbuffer = new unsigned char[ filesize ]; | ||
515 | framefile.readBlock( (char*) tempbuffer, filesize ); | ||
516 | avi_add( outfd, tempbuffer, filesize ); | ||
517 | delete tempbuffer; | ||
518 | framefile.close(); | ||
519 | } | ||
520 | |||
521 | avi_end( outfd, captureX, captureY, _framerate ); | ||
522 | |||
523 | fr->hide(); | ||
524 | delete fr; | ||
525 | |||
526 | updateCaption(); | ||
424 | 527 | ||
425 | } | 528 | } |
426 | 529 | ||
530 | |||
427 | void CameraMainWindow::updateCaption() | 531 | void CameraMainWindow::updateCaption() |
428 | { | 532 | { |
429 | if ( !_capturing ) | 533 | 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 ) ); | 534 | 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 | 535 | else |
432 | setCaption( "Opie-Camera: => CAPTURING <=" ); | 536 | setCaption( "Opie-Camera: => CAPTURING <=" ); |
433 | } | 537 | } |
434 | 538 | ||
435 | 539 | ||
540 | #ifndef QT_NO_DEBUG | ||
541 | void CameraMainWindow::doSomething() | ||
542 | { | ||
543 | captureX = 240; | ||
544 | captureY = 320; | ||
545 | _videopics = 176; | ||
546 | _framerate = 5; | ||
547 | postProcessVideo( "/var/compile/opie/noncore/multimedia/camera/capture-320x240.dat", | ||
548 | "/tmp/output.avi" ); | ||
549 | } | ||
550 | #endif | ||
551 | |||