author | mickeyl <mickeyl> | 2003-04-19 00:40:00 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-19 00:40:00 (UTC) |
commit | 724bb4ef15cd02a360e49de9c67847a19d5ca832 (patch) (unidiff) | |
tree | 0fc5f2aab63c005aa2cfd36f7517547c0aa62e1d | |
parent | 6e7112a3610c4e562f991ba6d6f33ca2fe0c605d (diff) | |
download | opie-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
-rw-r--r-- | noncore/multimedia/camera/camera.pro | 6 | ||||
-rw-r--r-- | noncore/multimedia/camera/imageio.cpp | 55 | ||||
-rw-r--r-- | noncore/multimedia/camera/imageio.h | 26 | ||||
-rw-r--r-- | noncore/multimedia/camera/mainwindow.cpp | 198 | ||||
-rw-r--r-- | noncore/multimedia/camera/mainwindow.h | 19 | ||||
-rw-r--r-- | noncore/multimedia/camera/previewwidget.cpp | 14 | ||||
-rw-r--r-- | noncore/multimedia/camera/previewwidget.h | 3 | ||||
-rw-r--r-- | noncore/multimedia/camera/zcameraio.cpp | 100 | ||||
-rw-r--r-- | noncore/multimedia/camera/zcameraio.h | 11 |
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,23 +1,25 @@ | |||
1 | MOC_DIR = ./moc | 1 | MOC_DIR = ./moc |
2 | OBJECTS_DIR = ./obj | 2 | OBJECTS_DIR = ./obj |
3 | DESTDIR = $(OPIEDIR)/bin | 3 | DESTDIR = $(OPIEDIR)/bin |
4 | TEMPLATE = app | 4 | TEMPLATE = app |
5 | CONFIG = qt warn_on debug | 5 | CONFIG = qt warn_on debug |
6 | 6 | ||
7 | HEADERS = zcameraio.h \ | 7 | HEADERS = imageio.h \ |
8 | zcameraio.h \ | ||
8 | previewwidget.h \ | 9 | previewwidget.h \ |
9 | mainwindow.h | 10 | mainwindow.h |
10 | 11 | ||
11 | SOURCES = zcameraio.cpp \ | 12 | SOURCES = 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 | ||
16 | INCLUDEPATH += $(OPIEDIR)/include | 18 | INCLUDEPATH += $(OPIEDIR)/include |
17 | DEPENDPATH += $(OPIEDIR)/include | 19 | DEPENDPATH += $(OPIEDIR)/include |
18 | LIBS += -lqpe -lopie -lopiecore2 | 20 | LIBS += -lqpe -lopie -lopiecore2 |
19 | INTERFACES = | 21 | INTERFACES = |
20 | TARGET = opiecam | 22 | TARGET = opiecam |
21 | 23 | ||
22 | include ( $(OPIEDIR)/include.pro ) | 24 | include ( $(OPIEDIR)/include.pro ) |
23 | 25 | ||
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 | |||
22 | void 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 | |||
43 | void 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 | |||
21 | class QImage; | ||
22 | |||
23 | void bufferToImage( int _width, int height, unsigned char* bp, QImage* image ); | ||
24 | void 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 | |||
@@ -7,51 +7,61 @@ | |||
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 | 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> |
38 | using namespace Opie; | 41 | using 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 | ||
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 | { |
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 ); |
52 | QLabel* l1 = new QLabel( v ); | 62 | QLabel* l1 = new QLabel( v ); |
53 | l1->setPixmap( Resource::loadPixmap( "camera/error" ) ); | 63 | l1->setPixmap( Resource::loadPixmap( "camera/error" ) ); |
54 | QLabel* l2 = new QLabel( v ); | 64 | QLabel* l2 = new QLabel( v ); |
55 | l2->setText( "<b>Sorry. could not detect your camera :-(</b><p>" | 65 | l2->setText( "<b>Sorry. could not detect your camera :-(</b><p>" |
56 | "* Is the sharpzdc_cs module loaded ?<br>" | 66 | "* Is the sharpzdc_cs module loaded ?<br>" |
57 | "* Is /dev/sharpzdc read/writable ?<p>" ); | 67 | "* Is /dev/sharpzdc read/writable ?<p>" ); |
@@ -69,35 +79,39 @@ CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags | |||
69 | //setCentralWidget( preview ); <--- don't do this! | 79 | //setCentralWidget( preview ); <--- don't do this! |
70 | preview->resize( QSize( 240, 288 ) ); | 80 | preview->resize( QSize( 240, 288 ) ); |
71 | preview->show(); | 81 | preview->show(); |
72 | 82 | ||
73 | // construct a System Channel to receive setRotation messages | 83 | // construct a System Channel to receive setRotation messages |
74 | _sysChannel = new QCopChannel( "QPE/System", this ); | 84 | _sysChannel = new QCopChannel( "QPE/System", this ); |
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 | ||
84 | CameraMainWindow::~CameraMainWindow() | 97 | CameraMainWindow::~CameraMainWindow() |
85 | { | 98 | { |
86 | } | 99 | } |
87 | 100 | ||
88 | 101 | ||
89 | void CameraMainWindow::init() | 102 | void 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 | ||
98 | resog = new QActionGroup( 0, "reso", true ); | 112 | resog = new QActionGroup( 0, "reso", true ); |
99 | resog->setToggleAction( true ); | 113 | resog->setToggleAction( true ); |
100 | new QAction( " 64 x 48", 0, 0, resog, 0, true ); | 114 | new QAction( " 64 x 48", 0, 0, resog, 0, true ); |
101 | new QAction( "128 x 96", 0, 0, resog, 0, true ); | 115 | new QAction( "128 x 96", 0, 0, resog, 0, true ); |
102 | new QAction( "192 x 144", 0, 0, resog, 0, true ); | 116 | new QAction( "192 x 144", 0, 0, resog, 0, true ); |
103 | new QAction( "256 x 192", 0, 0, resog, 0, true ); | 117 | new QAction( "256 x 192", 0, 0, resog, 0, true ); |
@@ -112,34 +126,45 @@ void CameraMainWindow::init() | |||
112 | qualityg->setToggleAction( true ); | 126 | qualityg->setToggleAction( true ); |
113 | new QAction( " 0 (minimal)", 0, 0, qualityg, 0, true ); | 127 | new QAction( " 0 (minimal)", 0, 0, qualityg, 0, true ); |
114 | new QAction( " 25 (low)", 0, 0, qualityg, 0, true ); | 128 | new QAction( " 25 (low)", 0, 0, qualityg, 0, true ); |
115 | ( new QAction( " 50 (good)", 0, 0, qualityg, 0, true ) )->setOn( true ); | 129 | ( new QAction( " 50 (good)", 0, 0, qualityg, 0, true ) )->setOn( true ); |
116 | new QAction( " 75 (better)", 0, 0, qualityg, 0, true ); | 130 | new QAction( " 75 (better)", 0, 0, qualityg, 0, true ); |
117 | new QAction( "100 (best)", 0, 0, qualityg, 0, true ); | 131 | new QAction( "100 (best)", 0, 0, qualityg, 0, true ); |
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 | ||
137 | void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data ) | 162 | void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data ) |
138 | { | 163 | { |
139 | QDataStream stream( data, IO_ReadOnly ); | 164 | QDataStream stream( data, IO_ReadOnly ); |
140 | odebug << "received system message: " << msg << oendl; | 165 | odebug << "received system message: " << msg << oendl; |
141 | if ( msg == "setCurrentRotation(int)" ) | 166 | if ( msg == "setCurrentRotation(int)" ) |
142 | { | 167 | { |
143 | stream >> _rotation; | 168 | stream >> _rotation; |
144 | odebug << "received setCurrentRotation(" << _rotation << ")" << oendl; | 169 | odebug << "received setCurrentRotation(" << _rotation << ")" << oendl; |
145 | 170 | ||
@@ -160,94 +185,251 @@ void CameraMainWindow::changeZoom( int zoom ) | |||
160 | int z; | 185 | int z; |
161 | switch ( zoom ) | 186 | switch ( zoom ) |
162 | { | 187 | { |
163 | case 0: z = 128; break; | 188 | case 0: z = 128; break; |
164 | case 1: z = 256; break; | 189 | case 1: z = 256; break; |
165 | case 2: z = 512; break; | 190 | case 2: z = 512; break; |
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 | |||
172 | void CameraMainWindow::showContextMenu() | 198 | void 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 | ||
199 | void CameraMainWindow::resoMenuItemClicked( QAction* a ) | 230 | void 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 | ||
207 | void CameraMainWindow::qualityMenuItemClicked( QAction* a ) | 239 | 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 | ||
214 | void CameraMainWindow::zoomMenuItemClicked( QAction* a ) | 247 | 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 | } |
220 | 273 | ||
221 | 274 | ||
222 | void CameraMainWindow::outputMenuItemClicked( QAction* a ) | 275 | 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 | ||
229 | void CameraMainWindow::shutterClicked() | 283 | 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; |
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 | |||
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 | |||
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 | |||
@@ -11,63 +11,82 @@ | |||
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 | #ifndef MAINWINDOW_H | 16 | #ifndef MAINWINDOW_H |
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 | ||
24 | class QAction; | 25 | class QAction; |
25 | class QActionGroup; | 26 | class QActionGroup; |
26 | class QIconSet; | 27 | class QIconSet; |
28 | class QTimerEvent; | ||
27 | class QToolButton; | 29 | class QToolButton; |
28 | class QLabel; | 30 | class QLabel; |
29 | class MainWindowBase; | 31 | class MainWindowBase; |
30 | class QCopChannel; | 32 | class QCopChannel; |
31 | class PreviewWidget; | 33 | class PreviewWidget; |
32 | 34 | ||
33 | class CameraMainWindow: public QMainWindow | 35 | class CameraMainWindow: public QMainWindow |
34 | { | 36 | { |
35 | Q_OBJECT | 37 | Q_OBJECT |
36 | 38 | ||
37 | public: | 39 | public: |
38 | CameraMainWindow( QWidget * parent = 0, const char * name = "mainwindow", WFlags f = 0 ); | 40 | CameraMainWindow( QWidget * parent = 0, const char * name = "mainwindow", WFlags f = 0 ); |
39 | virtual ~CameraMainWindow(); | 41 | virtual ~CameraMainWindow(); |
40 | 42 | ||
41 | public slots: | 43 | public slots: |
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 | |||
@@ -63,12 +63,26 @@ void PreviewWidget::timerEvent( QTimerEvent* ) | |||
63 | { | 63 | { |
64 | p.convertFromImage( i ); | 64 | p.convertFromImage( i ); |
65 | setPixmap( p ); | 65 | setPixmap( p ); |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | 69 | ||
70 | void PreviewWidget::mousePressEvent( QMouseEvent* ) | 70 | void PreviewWidget::mousePressEvent( QMouseEvent* ) |
71 | { | 71 | { |
72 | emit contextMenuRequested(); | 72 | emit contextMenuRequested(); |
73 | } | 73 | } |
74 | 74 | ||
75 | |||
76 | void PreviewWidget::setRefreshingRate( int ms ) | ||
77 | { | ||
78 | killTimers(); | ||
79 | if ( ms ) | ||
80 | startTimer( ms ); | ||
81 | } | ||
82 | |||
83 | |||
84 | void 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 | |||
@@ -22,24 +22,27 @@ | |||
22 | 22 | ||
23 | class QTimerEvent; | 23 | class QTimerEvent; |
24 | class QResizeEvent; | 24 | class QResizeEvent; |
25 | 25 | ||
26 | class PreviewWidget: public QLabel | 26 | class PreviewWidget: public QLabel |
27 | { | 27 | { |
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: |
40 | void contextMenuRequested(); | 43 | void contextMenuRequested(); |
41 | 44 | ||
42 | private: | 45 | private: |
43 | QPixmap p; | 46 | QPixmap p; |
44 | QImage i; | 47 | QImage i; |
45 | }; | 48 | }; |
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 | |||
@@ -35,25 +35,27 @@ ZCameraIO* ZCameraIO::_instance = 0; | |||
35 | ZCameraIO* ZCameraIO::instance() | 35 | ZCameraIO* ZCameraIO::instance() |
36 | { | 36 | { |
37 | if ( !ZCameraIO::_instance ) | 37 | if ( !ZCameraIO::_instance ) |
38 | { | 38 | { |
39 | odebug << "Creating ZCameraIO::_instance" << oendl; | 39 | odebug << "Creating ZCameraIO::_instance" << oendl; |
40 | ZCameraIO::_instance = new ZCameraIO(); | 40 | ZCameraIO::_instance = new ZCameraIO(); |
41 | } | 41 | } |
42 | return ZCameraIO::_instance; | 42 | return ZCameraIO::_instance; |
43 | } | 43 | } |
44 | 44 | ||
45 | 45 | ||
46 | ZCameraIO::ZCameraIO() | 46 | ZCameraIO::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(); |
54 | } | 56 | } |
55 | 57 | ||
56 | 58 | ||
57 | void ZCameraIO::init() | 59 | void ZCameraIO::init() |
58 | { | 60 | { |
59 | if ( ZCameraIO::_instance ) | 61 | if ( ZCameraIO::_instance ) |
@@ -75,36 +77,42 @@ ZCameraIO::~ZCameraIO() | |||
75 | } | 77 | } |
76 | } | 78 | } |
77 | 79 | ||
78 | 80 | ||
79 | bool ZCameraIO::isOpen() const | 81 | bool ZCameraIO::isOpen() const |
80 | { | 82 | { |
81 | return _driver != -1; | 83 | return _driver != -1; |
82 | } | 84 | } |
83 | 85 | ||
84 | 86 | ||
85 | bool ZCameraIO::isShutterPressed() | 87 | bool 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 | ||
102 | bool ZCameraIO::isFinderReversed() const | 110 | bool ZCameraIO::isFinderReversed() const |
103 | { | 111 | { |
104 | return _status[1] == 'M'; | 112 | return _status[1] == 'M'; |
105 | } | 113 | } |
106 | 114 | ||
107 | 115 | ||
108 | bool ZCameraIO::isCapturing() const | 116 | bool ZCameraIO::isCapturing() const |
109 | { | 117 | { |
110 | return _status[2] == 'C'; | 118 | return _status[2] == 'C'; |
@@ -140,29 +148,38 @@ bool ZCameraIO::setZoom( int zoom ) | |||
140 | return setCaptureFrame( _width, _height, zoom*256, _rot ); | 148 | return setCaptureFrame( _width, _height, zoom*256, _rot ); |
141 | } | 149 | } |
142 | 150 | ||
143 | 151 | ||
144 | void ZCameraIO::setReadMode( int mode ) | 152 | void ZCameraIO::setReadMode( int mode ) |
145 | { | 153 | { |
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 | ||
168 | void ZCameraIO::setFlip( int flip ) | ||
169 | { | ||
170 | _flip = flip; | ||
171 | } | ||
172 | |||
173 | |||
157 | void ZCameraIO::clearShutterLatch() | 174 | void ZCameraIO::clearShutterLatch() |
158 | { | 175 | { |
159 | write( "B", 1 ); | 176 | write( "B", 1 ); |
160 | } | 177 | } |
161 | 178 | ||
162 | 179 | ||
163 | bool ZCameraIO::read( char* b, int len ) | 180 | bool ZCameraIO::read( char* b, int len ) |
164 | { | 181 | { |
165 | #ifndef NO_TIMING | 182 | #ifndef NO_TIMING |
166 | QTime t; | 183 | QTime t; |
167 | t.start(); | 184 | t.start(); |
168 | #endif | 185 | #endif |
@@ -189,33 +206,43 @@ bool ZCameraIO::write( char* buf, int len ) | |||
189 | 206 | ||
190 | return ::write( _driver, buf, len ) == len; | 207 | return ::write( _driver, buf, len ) == len; |
191 | } | 208 | } |
192 | 209 | ||
193 | 210 | ||
194 | bool ZCameraIO::snapshot( QImage* image ) | 211 | 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 | ||
216 | image->create( _width, _height, 16 ); | 243 | image->create( _width, _height, 16 ); |
217 | for ( int i = 0; i < _height; ++i ) | 244 | for ( int i = 0; i < _height; ++i ) |
218 | { | 245 | { |
219 | p = image->scanLine( i ); | 246 | p = image->scanLine( i ); |
220 | for ( int j = 0; j < _width; j++ ) | 247 | for ( int j = 0; j < _width; j++ ) |
221 | { | 248 | { |
@@ -225,40 +252,67 @@ bool ZCameraIO::snapshot( QImage* image ) | |||
225 | *p = *bp; | 252 | *p = *bp; |
226 | p++; | 253 | p++; |
227 | bp++; | 254 | bp++; |
228 | } | 255 | } |
229 | } | 256 | } |
230 | 257 | ||
231 | return true; | 258 | return true; |
232 | } | 259 | } |
233 | 260 | ||
234 | 261 | ||
235 | bool ZCameraIO::snapshot( unsigned char* buf ) | 262 | bool 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 | ||
252 | void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image ) | 292 | void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image ) |
253 | { | 293 | { |
254 | int pw = _width; | 294 | int pw = _width; |
255 | int ph = _height; | 295 | int ph = _height; |
256 | if ( _rot ) | 296 | if ( _rot ) |
257 | setCaptureFrame( h, w, zoom*256, true ); | 297 | setCaptureFrame( h, w, zoom*256, true ); |
258 | else | 298 | else |
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 | ||
305 | void 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 | |||
@@ -24,58 +24,63 @@ class QTime; | |||
24 | class ZCameraIO : public QObject | 24 | class ZCameraIO : public QObject |
25 | { | 25 | { |
26 | Q_OBJECT | 26 | Q_OBJECT |
27 | 27 | ||
28 | public: | 28 | public: |
29 | virtual ~ZCameraIO(); | 29 | virtual ~ZCameraIO(); |
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 ); |
63 | bool write( char*, int = 0 ); | 66 | bool write( char*, int = 0 ); |
64 | 67 | ||
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 | ||
81 | #endif | 86 | #endif |