author | mickeyl <mickeyl> | 2003-04-06 14:38:18 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-06 14:38:18 (UTC) |
commit | 0b985ce87d6ce6d4110a50d5be48831d34794cd2 (patch) (unidiff) | |
tree | da19d8dc2cd2b37d15220783940652e8e91f3843 | |
parent | 91d65a97c956963a24f418fadd7cd69f6a52f5d5 (diff) | |
download | opie-0b985ce87d6ce6d4110a50d5be48831d34794cd2.zip opie-0b985ce87d6ce6d4110a50d5be48831d34794cd2.tar.gz opie-0b985ce87d6ce6d4110a50d5be48831d34794cd2.tar.bz2 |
- add realtime preview widget with zoom control
The camera driver is damn slow. For a 240x160x16 image, it takes ~100ms. That gives approx. 10fps which is too slow for doing video. :(
-rw-r--r-- | noncore/multimedia/camera/.cvsignore | 4 | ||||
-rw-r--r-- | noncore/multimedia/camera/camera.pro | 4 | ||||
-rw-r--r-- | noncore/multimedia/camera/mainwindow.cpp | 40 | ||||
-rw-r--r-- | noncore/multimedia/camera/mainwindow.h | 12 | ||||
-rw-r--r-- | noncore/multimedia/camera/mainwindowbase.ui | 246 | ||||
-rw-r--r-- | noncore/multimedia/camera/previewwidget.cpp | 45 | ||||
-rw-r--r-- | noncore/multimedia/camera/previewwidget.h | 39 | ||||
-rw-r--r-- | noncore/multimedia/camera/zcameraio.cpp | 58 |
8 files changed, 397 insertions, 51 deletions
diff --git a/noncore/multimedia/camera/.cvsignore b/noncore/multimedia/camera/.cvsignore index 6d678c6..d89e3af 100644 --- a/noncore/multimedia/camera/.cvsignore +++ b/noncore/multimedia/camera/.cvsignore | |||
@@ -1 +1,5 @@ | |||
1 | config.in | 1 | config.in |
2 | mainwindowbase.h | ||
3 | mainwindowbase.cpp | ||
4 | Makefile | ||
5 | |||
diff --git a/noncore/multimedia/camera/camera.pro b/noncore/multimedia/camera/camera.pro index e937807..2d1faa3 100644 --- a/noncore/multimedia/camera/camera.pro +++ b/noncore/multimedia/camera/camera.pro | |||
@@ -1,21 +1,23 @@ | |||
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 = zcameraio.h \ |
8 | previewwidget.h \ | ||
8 | mainwindow.h | 9 | mainwindow.h |
9 | 10 | ||
10 | SOURCES = zcameraio.cpp \ | 11 | SOURCES = zcameraio.cpp \ |
12 | previewwidget.cpp \ | ||
11 | mainwindow.cpp \ | 13 | mainwindow.cpp \ |
12 | main.cpp | 14 | main.cpp |
13 | 15 | ||
14 | INCLUDEPATH += $(OPIEDIR)/include | 16 | INCLUDEPATH += $(OPIEDIR)/include |
15 | DEPENDPATH += $(OPIEDIR)/include | 17 | DEPENDPATH += $(OPIEDIR)/include |
16 | LIBS += -lqpe -lopiecore2 | 18 | LIBS += -lqpe -lopiecore2 |
17 | INTERFACES = | 19 | INTERFACES = mainwindowbase.ui |
18 | TARGET = opiecam | 20 | TARGET = opiecam |
19 | 21 | ||
20 | include ( $(OPIEDIR)/include.pro ) | 22 | include ( $(OPIEDIR)/include.pro ) |
21 | 23 | ||
diff --git a/noncore/multimedia/camera/mainwindow.cpp b/noncore/multimedia/camera/mainwindow.cpp index 4218232..8578bce 100644 --- a/noncore/multimedia/camera/mainwindow.cpp +++ b/noncore/multimedia/camera/mainwindow.cpp | |||
@@ -1,64 +1,60 @@ | |||
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 "mainwindowbase.h" | ||
17 | #include "zcameraio.h" | 18 | #include "zcameraio.h" |
18 | 19 | ||
19 | #include <qvbox.h> | 20 | #include <qvbox.h> |
21 | #include <qcombobox.h> | ||
20 | #include <qpushbutton.h> | 22 | #include <qpushbutton.h> |
21 | #include <qlabel.h> | 23 | #include <qlabel.h> |
22 | |||
23 | #include <qdirectpainter_qws.h> | 24 | #include <qdirectpainter_qws.h> |
24 | |||
25 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
26 | #include <opie/ofiledialog.h> | 26 | #include <opie/ofiledialog.h> |
27 | 27 | ||
28 | #include <assert.h> | ||
29 | |||
28 | CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) | 30 | CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) |
29 | :QMainWindow( parent, name, f ) | 31 | :QMainWindow( parent, name, f ) |
30 | { | 32 | { |
31 | QVBox* v = new QVBox( this ); | 33 | mw = new MainWindowBase( this, "main widget" ); |
32 | l = new QLabel( v ); | 34 | ZCameraIO::instance()->setCaptureFrame( 240, 160, 256 ); |
33 | l->setFixedSize( QSize( 240, 160 ) ); | 35 | setCentralWidget( mw ); |
34 | QPushButton* p = new QPushButton( "Snapshot", v ); | 36 | mw->show(); |
35 | connect( p, SIGNAL( clicked() ), this, SLOT( clickedSnapShot() ) ); | ||
36 | v->show(); | ||
37 | l->show(); | ||
38 | p->show(); | ||
39 | setCentralWidget( v ); | ||
40 | 37 | ||
38 | connect( mw->zoom, SIGNAL( activated( int ) ), this, SLOT( changeZoom(int) ) ); | ||
41 | }; | 39 | }; |
42 | 40 | ||
43 | 41 | ||
44 | CameraMainWindow::~CameraMainWindow() | 42 | CameraMainWindow::~CameraMainWindow() |
45 | { | 43 | { |
46 | } | 44 | } |
47 | 45 | ||
48 | 46 | ||
49 | void CameraMainWindow::clickedSnapShot() | 47 | void CameraMainWindow::changeZoom( int zoom ) |
50 | { | 48 | { |
51 | QDirectPainter fb( l ); | 49 | int z; |
52 | ZCameraIO::instance()->snapshot( fb.frameBuffer() ); | 50 | switch ( zoom ) |
53 | |||
54 | /* | ||
55 | QImage i; | ||
56 | QPixmap p; | ||
57 | if ( ZCameraIO::instance()->snapshot( &i ) ) | ||
58 | { | 51 | { |
59 | p.convertFromImage( i ); | 52 | case 0: z = 128; break; |
60 | l->setPixmap( p ); | 53 | case 1: z = 256; break; |
54 | case 2: z = 512; break; | ||
55 | default: assert( 0 ); break; | ||
61 | } | 56 | } |
62 | */ | 57 | |
58 | ZCameraIO::instance()->setCaptureFrame( 240, 160, z ); | ||
63 | } | 59 | } |
64 | 60 | ||
diff --git a/noncore/multimedia/camera/mainwindow.h b/noncore/multimedia/camera/mainwindow.h index 521107b..7ccdcf8 100644 --- a/noncore/multimedia/camera/mainwindow.h +++ b/noncore/multimedia/camera/mainwindow.h | |||
@@ -1,42 +1,46 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. | 2 | ** Copyright (C) 2003 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 | #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> | ||
21 | #include <qimage.h> | ||
22 | #include <qpixmap.h> | ||
20 | 23 | ||
21 | class QIconSet; | 24 | class QIconSet; |
22 | class QToolButton; | 25 | class QToolButton; |
23 | class QLabel; | 26 | class QLabel; |
27 | class MainWindowBase; | ||
24 | 28 | ||
25 | class CameraMainWindow: public QMainWindow | 29 | class CameraMainWindow: public QMainWindow |
26 | { | 30 | { |
27 | Q_OBJECT | 31 | Q_OBJECT |
28 | 32 | ||
29 | public: | 33 | public: |
30 | CameraMainWindow( QWidget * parent = 0, const char * name = "mainwindow", WFlags f = 0 ); | 34 | CameraMainWindow( QWidget * parent = 0, const char * name = "mainwindow", WFlags f = 0 ); |
31 | virtual ~CameraMainWindow(); | 35 | virtual ~CameraMainWindow(); |
32 | 36 | ||
33 | protected: | ||
34 | |||
35 | public slots: | 37 | public slots: |
36 | void clickedSnapShot(); | 38 | void changeZoom( int ); |
39 | |||
40 | protected: | ||
37 | 41 | ||
38 | private: | 42 | private: |
39 | QLabel* l; | 43 | MainWindowBase* mw; |
40 | }; | 44 | }; |
41 | 45 | ||
42 | #endif | 46 | #endif |
diff --git a/noncore/multimedia/camera/mainwindowbase.ui b/noncore/multimedia/camera/mainwindowbase.ui new file mode 100644 index 0000000..8da884a --- a/dev/null +++ b/noncore/multimedia/camera/mainwindowbase.ui | |||
@@ -0,0 +1,246 @@ | |||
1 | <!DOCTYPE UI><UI> | ||
2 | <class>MainWindowBase</class> | ||
3 | <widget> | ||
4 | <class>QWidget</class> | ||
5 | <property stdset="1"> | ||
6 | <name>name</name> | ||
7 | <cstring>MainWindowBase</cstring> | ||
8 | </property> | ||
9 | <property stdset="1"> | ||
10 | <name>geometry</name> | ||
11 | <rect> | ||
12 | <x>0</x> | ||
13 | <y>0</y> | ||
14 | <width>242</width> | ||
15 | <height>329</height> | ||
16 | </rect> | ||
17 | </property> | ||
18 | <property stdset="1"> | ||
19 | <name>caption</name> | ||
20 | <string>Form1</string> | ||
21 | </property> | ||
22 | <property> | ||
23 | <name>layoutMargin</name> | ||
24 | </property> | ||
25 | <property> | ||
26 | <name>layoutSpacing</name> | ||
27 | </property> | ||
28 | <grid> | ||
29 | <property stdset="1"> | ||
30 | <name>margin</name> | ||
31 | <number>0</number> | ||
32 | </property> | ||
33 | <property stdset="1"> | ||
34 | <name>spacing</name> | ||
35 | <number>2</number> | ||
36 | </property> | ||
37 | <widget row="1" column="0" > | ||
38 | <class>QLayoutWidget</class> | ||
39 | <property stdset="1"> | ||
40 | <name>name</name> | ||
41 | <cstring>Layout1</cstring> | ||
42 | </property> | ||
43 | <hbox> | ||
44 | <property stdset="1"> | ||
45 | <name>margin</name> | ||
46 | <number>0</number> | ||
47 | </property> | ||
48 | <property stdset="1"> | ||
49 | <name>spacing</name> | ||
50 | <number>6</number> | ||
51 | </property> | ||
52 | <widget> | ||
53 | <class>QLabel</class> | ||
54 | <property stdset="1"> | ||
55 | <name>name</name> | ||
56 | <cstring>TextLabel1</cstring> | ||
57 | </property> | ||
58 | <property stdset="1"> | ||
59 | <name>text</name> | ||
60 | <string>Reso:</string> | ||
61 | </property> | ||
62 | </widget> | ||
63 | <widget> | ||
64 | <class>QComboBox</class> | ||
65 | <item> | ||
66 | <property> | ||
67 | <name>text</name> | ||
68 | <string>240x160</string> | ||
69 | </property> | ||
70 | </item> | ||
71 | <item> | ||
72 | <property> | ||
73 | <name>text</name> | ||
74 | <string>480x320</string> | ||
75 | </property> | ||
76 | </item> | ||
77 | <property stdset="1"> | ||
78 | <name>name</name> | ||
79 | <cstring>resolution</cstring> | ||
80 | </property> | ||
81 | </widget> | ||
82 | <widget> | ||
83 | <class>QLabel</class> | ||
84 | <property stdset="1"> | ||
85 | <name>name</name> | ||
86 | <cstring>TextLabel2</cstring> | ||
87 | </property> | ||
88 | <property stdset="1"> | ||
89 | <name>text</name> | ||
90 | <string>Zoom:</string> | ||
91 | </property> | ||
92 | </widget> | ||
93 | <widget> | ||
94 | <class>QComboBox</class> | ||
95 | <item> | ||
96 | <property> | ||
97 | <name>text</name> | ||
98 | <string>Half</string> | ||
99 | </property> | ||
100 | </item> | ||
101 | <item> | ||
102 | <property> | ||
103 | <name>text</name> | ||
104 | <string>Full</string> | ||
105 | </property> | ||
106 | </item> | ||
107 | <item> | ||
108 | <property> | ||
109 | <name>text</name> | ||
110 | <string>Double</string> | ||
111 | </property> | ||
112 | </item> | ||
113 | <property stdset="1"> | ||
114 | <name>name</name> | ||
115 | <cstring>zoom</cstring> | ||
116 | </property> | ||
117 | </widget> | ||
118 | </hbox> | ||
119 | </widget> | ||
120 | <widget row="2" column="0" > | ||
121 | <class>QLayoutWidget</class> | ||
122 | <property stdset="1"> | ||
123 | <name>name</name> | ||
124 | <cstring>Layout2</cstring> | ||
125 | </property> | ||
126 | <hbox> | ||
127 | <property stdset="1"> | ||
128 | <name>margin</name> | ||
129 | <number>0</number> | ||
130 | </property> | ||
131 | <property stdset="1"> | ||
132 | <name>spacing</name> | ||
133 | <number>6</number> | ||
134 | </property> | ||
135 | <spacer> | ||
136 | <property> | ||
137 | <name>name</name> | ||
138 | <cstring>Spacer1</cstring> | ||
139 | </property> | ||
140 | <property stdset="1"> | ||
141 | <name>orientation</name> | ||
142 | <enum>Horizontal</enum> | ||
143 | </property> | ||
144 | <property stdset="1"> | ||
145 | <name>sizeType</name> | ||
146 | <enum>Expanding</enum> | ||
147 | </property> | ||
148 | <property> | ||
149 | <name>sizeHint</name> | ||
150 | <size> | ||
151 | <width>20</width> | ||
152 | <height>20</height> | ||
153 | </size> | ||
154 | </property> | ||
155 | </spacer> | ||
156 | <widget> | ||
157 | <class>QPushButton</class> | ||
158 | <property stdset="1"> | ||
159 | <name>name</name> | ||
160 | <cstring>PushButton1</cstring> | ||
161 | </property> | ||
162 | <property stdset="1"> | ||
163 | <name>text</name> | ||
164 | <string>Take Photo</string> | ||
165 | </property> | ||
166 | <property stdset="1"> | ||
167 | <name>default</name> | ||
168 | <bool>true</bool> | ||
169 | </property> | ||
170 | </widget> | ||
171 | <spacer> | ||
172 | <property> | ||
173 | <name>name</name> | ||
174 | <cstring>Spacer2</cstring> | ||
175 | </property> | ||
176 | <property stdset="1"> | ||
177 | <name>orientation</name> | ||
178 | <enum>Horizontal</enum> | ||
179 | </property> | ||
180 | <property stdset="1"> | ||
181 | <name>sizeType</name> | ||
182 | <enum>Expanding</enum> | ||
183 | </property> | ||
184 | <property> | ||
185 | <name>sizeHint</name> | ||
186 | <size> | ||
187 | <width>20</width> | ||
188 | <height>20</height> | ||
189 | </size> | ||
190 | </property> | ||
191 | </spacer> | ||
192 | </hbox> | ||
193 | </widget> | ||
194 | <spacer row="3" column="0" > | ||
195 | <property> | ||
196 | <name>name</name> | ||
197 | <cstring>Spacer3</cstring> | ||
198 | </property> | ||
199 | <property stdset="1"> | ||
200 | <name>orientation</name> | ||
201 | <enum>Vertical</enum> | ||
202 | </property> | ||
203 | <property stdset="1"> | ||
204 | <name>sizeType</name> | ||
205 | <enum>Expanding</enum> | ||
206 | </property> | ||
207 | <property> | ||
208 | <name>sizeHint</name> | ||
209 | <size> | ||
210 | <width>20</width> | ||
211 | <height>20</height> | ||
212 | </size> | ||
213 | </property> | ||
214 | </spacer> | ||
215 | <widget row="0" column="0" > | ||
216 | <class>PreviewWidget</class> | ||
217 | <property stdset="1"> | ||
218 | <name>name</name> | ||
219 | <cstring>preview</cstring> | ||
220 | </property> | ||
221 | </widget> | ||
222 | </grid> | ||
223 | </widget> | ||
224 | <customwidgets> | ||
225 | <customwidget> | ||
226 | <class>PreviewWidget</class> | ||
227 | <header location="local">previewwidget.h</header> | ||
228 | <sizehint> | ||
229 | <width>240</width> | ||
230 | <height>160</height> | ||
231 | </sizehint> | ||
232 | <container>0</container> | ||
233 | <sizepolicy> | ||
234 | <hordata>0</hordata> | ||
235 | <verdata>0</verdata> | ||
236 | </sizepolicy> | ||
237 | <pixmap>image0</pixmap> | ||
238 | </customwidget> | ||
239 | </customwidgets> | ||
240 | <images> | ||
241 | <image> | ||
242 | <name>image0</name> | ||
243 | <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1ddec44f503c0ae2a154410f53d0ed20e2bf6bdb656dd6861dd23d9a66591b0587fd1654235ebded6f0edcd53e419d87ae7b1f4f9b8f906d0bfe012317426a70b07bdc2f3ec77f8ed6b89559061a0343d06a124cc105596482585094bc0ae599b04646c9018926491b2205e140c485cace25755c175d0a967b622ff900b8cc9c7d29af594ea722d589167f813aa852ba07d94b9dce296e883fe7bb163f23896753</data> | ||
244 | </image> | ||
245 | </images> | ||
246 | </UI> | ||
diff --git a/noncore/multimedia/camera/previewwidget.cpp b/noncore/multimedia/camera/previewwidget.cpp new file mode 100644 index 0000000..bb84c00 --- a/dev/null +++ b/noncore/multimedia/camera/previewwidget.cpp | |||
@@ -0,0 +1,45 @@ | |||
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 "previewwidget.h" | ||
17 | #include "zcameraio.h" | ||
18 | |||
19 | PreviewWidget::PreviewWidget( QWidget * parent, const char * name, WFlags f ) | ||
20 | :QLabel( parent, name, f ) | ||
21 | { | ||
22 | setFixedSize( QSize( 240, 160 ) ); | ||
23 | setBackgroundMode( NoBackground ); | ||
24 | |||
25 | startTimer( 150 ); | ||
26 | }; | ||
27 | |||
28 | |||
29 | PreviewWidget::~PreviewWidget() | ||
30 | { | ||
31 | } | ||
32 | |||
33 | |||
34 | void PreviewWidget::timerEvent( QTimerEvent* ) | ||
35 | { | ||
36 | //QDirectPainter fb( this ); | ||
37 | //ZCameraIO::instance()->snapshot( fb.frameBuffer() ); | ||
38 | |||
39 | if ( ZCameraIO::instance()->snapshot( &i ) ) | ||
40 | { | ||
41 | p.convertFromImage( i ); | ||
42 | setPixmap( p ); | ||
43 | } | ||
44 | } | ||
45 | |||
diff --git a/noncore/multimedia/camera/previewwidget.h b/noncore/multimedia/camera/previewwidget.h new file mode 100644 index 0000000..c031d95 --- a/dev/null +++ b/noncore/multimedia/camera/previewwidget.h | |||
@@ -0,0 +1,39 @@ | |||
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 PREVIEWWIDGET_H | ||
17 | #define PREVIEWWIDGET_H | ||
18 | |||
19 | #include <qlabel.h> | ||
20 | #include <qimage.h> | ||
21 | #include <qpixmap.h> | ||
22 | |||
23 | class PreviewWidget: public QLabel | ||
24 | { | ||
25 | Q_OBJECT | ||
26 | |||
27 | public: | ||
28 | PreviewWidget( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ); | ||
29 | virtual ~PreviewWidget(); | ||
30 | |||
31 | protected: | ||
32 | virtual void timerEvent( QTimerEvent* ); | ||
33 | |||
34 | private: | ||
35 | QPixmap p; | ||
36 | QImage i; | ||
37 | }; | ||
38 | |||
39 | #endif | ||
diff --git a/noncore/multimedia/camera/zcameraio.cpp b/noncore/multimedia/camera/zcameraio.cpp index 7343dca..56b2e13 100644 --- a/noncore/multimedia/camera/zcameraio.cpp +++ b/noncore/multimedia/camera/zcameraio.cpp | |||
@@ -1,206 +1,216 @@ | |||
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 "zcameraio.h" | 16 | #include "zcameraio.h" |
17 | 17 | ||
18 | #include <sys/types.h> | 18 | #include <sys/types.h> |
19 | #include <sys/stat.h> | 19 | #include <sys/stat.h> |
20 | #include <errno.h> | 20 | #include <errno.h> |
21 | #include <string.h> | 21 | #include <string.h> |
22 | #include <fcntl.h> | 22 | #include <fcntl.h> |
23 | #include <unistd.h> | 23 | #include <unistd.h> |
24 | #include <stdio.h> | 24 | #include <stdio.h> |
25 | 25 | ||
26 | #include <qimage.h> | 26 | #include <qimage.h> |
27 | #include <qdatetime.h> | ||
27 | 28 | ||
28 | #include <opie2/odebug.h> | 29 | #include <opie2/odebug.h> |
29 | 30 | ||
31 | #define SHARPZDC "/dev/sharp_zdc" | ||
32 | |||
30 | ZCameraIO* ZCameraIO::_instance = 0; | 33 | ZCameraIO* ZCameraIO::_instance = 0; |
31 | 34 | ||
32 | ZCameraIO* ZCameraIO::instance() | 35 | ZCameraIO* ZCameraIO::instance() |
33 | { | 36 | { |
34 | if ( !ZCameraIO::_instance ) | 37 | if ( !ZCameraIO::_instance ) |
35 | { | 38 | { |
36 | odebug << "Creating ZCameraIO::_instance" << oendl; | 39 | odebug << "Creating ZCameraIO::_instance" << oendl; |
37 | ZCameraIO::_instance = new ZCameraIO(); | 40 | ZCameraIO::_instance = new ZCameraIO(); |
38 | } | 41 | } |
39 | return ZCameraIO::_instance; | 42 | return ZCameraIO::_instance; |
40 | } | 43 | } |
41 | 44 | ||
42 | 45 | ||
43 | ZCameraIO::ZCameraIO() | 46 | ZCameraIO::ZCameraIO() |
44 | :_height( 0 ), _width( 0 ), _zoom( 0 ), _rot( 0 ), _readlen( 0 ) | 47 | :_height( 0 ), _width( 0 ), _zoom( 0 ), _rot( 0 ), _readlen( 0 ) |
45 | { | 48 | { |
46 | _driver = ::open( "/dev/sharp_zdc", O_RDWR ); | 49 | _driver = ::open( SHARPZDC, O_RDWR ); |
47 | if ( _driver == -1 ) | 50 | if ( _driver == -1 ) |
48 | oerr << "Can't open camera driver: " << strerror(errno) << oendl; | 51 | oerr << "Can't open camera driver: " << strerror(errno) << oendl; |
49 | else | 52 | else |
50 | init(); | 53 | init(); |
51 | } | 54 | } |
52 | 55 | ||
53 | 56 | ||
54 | void ZCameraIO::init() | 57 | void ZCameraIO::init() |
55 | { | 58 | { |
56 | if ( ZCameraIO::_instance ) | 59 | if ( ZCameraIO::_instance ) |
57 | ofatal << "Don't create more than one ZCameraIO instances." << oendl; | 60 | ofatal << "Don't create more than one ZCameraIO instances." << oendl; |
58 | else | 61 | else |
59 | { | 62 | { |
60 | setReadMode( STATUS ); | 63 | setReadMode( STATUS ); |
61 | } | 64 | } |
62 | } | 65 | } |
63 | 66 | ||
64 | 67 | ||
65 | ZCameraIO::~ZCameraIO() | 68 | ZCameraIO::~ZCameraIO() |
66 | { | 69 | { |
67 | if ( _driver != -1 ) | 70 | if ( _driver != -1 ) |
71 | { | ||
72 | setReadMode( 0 ); | ||
68 | ::close( _driver ); | 73 | ::close( _driver ); |
74 | } | ||
69 | } | 75 | } |
70 | 76 | ||
71 | 77 | ||
72 | inline bool ZCameraIO::isOpen() const | 78 | inline bool ZCameraIO::isOpen() const |
73 | { | 79 | { |
74 | return _driver != -1; | 80 | return _driver != -1; |
75 | } | 81 | } |
76 | 82 | ||
77 | 83 | ||
78 | inline bool ZCameraIO::isShutterPressed() | 84 | inline bool ZCameraIO::isShutterPressed() |
79 | { | 85 | { |
80 | return _status[0] == 'S'; | 86 | return _status[0] == 'S'; |
81 | clearShutterLatch(); | 87 | clearShutterLatch(); |
82 | } | 88 | } |
83 | 89 | ||
84 | 90 | ||
85 | inline bool ZCameraIO::isFinderReversed() const | 91 | inline bool ZCameraIO::isFinderReversed() const |
86 | { | 92 | { |
87 | return _status[1] == 'M'; | 93 | return _status[1] == 'M'; |
88 | } | 94 | } |
89 | 95 | ||
90 | 96 | ||
91 | inline bool ZCameraIO::isCapturing() const | 97 | inline bool ZCameraIO::isCapturing() const |
92 | { | 98 | { |
93 | return _status[2] == 'C'; | 99 | return _status[2] == 'C'; |
94 | } | 100 | } |
95 | 101 | ||
96 | 102 | ||
97 | inline bool ZCameraIO::isAvailable() const | 103 | inline bool ZCameraIO::isAvailable() const |
98 | { | 104 | { |
99 | return _status[3] == 'A'; | 105 | return _status[3] == 'A'; |
100 | } | 106 | } |
101 | 107 | ||
102 | 108 | ||
103 | bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot ) | 109 | bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot ) |
104 | { | 110 | { |
105 | char b[100]; | 111 | char b[100]; |
106 | sprintf( b, "%c=%d,%d,%d,%d", rot ? 'R':'S', width, height, zoom, width*2 ); | 112 | sprintf( b, "%c=%d,%d,%d,%d", rot ? 'R':'S', width, height, zoom, width*2 ); |
107 | if ( write( b ) ) | 113 | if ( write( b ) ) |
108 | { | 114 | { |
109 | _width = width; | 115 | _width = width; |
110 | _height = _height; | 116 | _height = height; |
111 | _zoom = zoom; | 117 | _zoom = zoom; |
112 | _rot = rot; | 118 | _rot = rot; |
113 | _readlen = 2 * _width * _height; // camera is fixed @ 16 bits per pixel | 119 | _readlen = 2 * _width * _height; // camera is fixed @ 16 bits per pixel |
114 | return true; | 120 | return true; |
115 | } | 121 | } |
116 | return false; | 122 | return false; |
117 | } | 123 | } |
118 | 124 | ||
119 | 125 | ||
120 | void ZCameraIO::setReadMode( int mode ) | 126 | void ZCameraIO::setReadMode( int mode ) |
121 | { | 127 | { |
122 | char b[4]; | 128 | char b[10]; |
123 | sprintf( b, "M=%d", mode ); | 129 | sprintf( b, "M=%d", mode ); |
124 | write( b, mode <= 9 ? 3 : 4 ); | 130 | write( b, mode <= 9 ? 3 : 4 ); |
125 | if ( mode & 1 ) // STATUS bit is set | 131 | if ( mode & 1 ) // STATUS bit is set |
126 | read( _status, 4 ); | 132 | read( _status, 4 ); |
127 | } | 133 | } |
128 | 134 | ||
129 | 135 | ||
130 | void ZCameraIO::clearShutterLatch() | 136 | void ZCameraIO::clearShutterLatch() |
131 | { | 137 | { |
132 | char b = 'B'; | 138 | char b = 'B'; |
133 | write( &b, 1 ); | 139 | write( &b, 1 ); |
134 | } | 140 | } |
135 | 141 | ||
136 | 142 | ||
137 | bool ZCameraIO::read( char* b, int len ) | 143 | bool ZCameraIO::read( char* b, int len ) |
138 | { | 144 | { |
145 | #ifndef NO_TIMING | ||
146 | QTime t; | ||
147 | t.start(); | ||
148 | #endif | ||
139 | int rlen = ::read( _driver, b, len ); | 149 | int rlen = ::read( _driver, b, len ); |
140 | odebug << "read " << rlen << " from driver." << oendl; | 150 | #ifndef NO_TIMING |
151 | int time = t.elapsed(); | ||
152 | #else | ||
153 | int time = -1; | ||
154 | #endif | ||
155 | if ( rlen ) | ||
156 | odebug << "read " << rlen << " ('" << b[0] << b[1] << b[2] << b[3] << "') [" << time << " ms] from driver." << oendl; | ||
157 | else | ||
158 | odebug << "read nothing from driver." << oendl; | ||
141 | return rlen == len; | 159 | return rlen == len; |
142 | } | 160 | } |
143 | 161 | ||
144 | 162 | ||
145 | bool ZCameraIO::write( char* buf, int len ) | 163 | bool ZCameraIO::write( char* buf, int len ) |
146 | { | 164 | { |
147 | if ( !len ) | 165 | if ( !len ) |
148 | len = strlen( buf ); | 166 | len = strlen( buf ); |
149 | 167 | ||
150 | odebug << "writing '" << buf << "' to driver." << oendl; | 168 | odebug << "writing '" << buf << "' to driver." << oendl; |
151 | 169 | ||
152 | return ::write( _driver, buf, len ) == len; | 170 | return ::write( _driver, buf, len ) == len; |
153 | } | 171 | } |
154 | 172 | ||
155 | 173 | ||
156 | bool ZCameraIO::snapshot( QImage* image ) | 174 | bool ZCameraIO::snapshot( QImage* image ) |
157 | { | 175 | { |
158 | /* | 176 | setReadMode( IMAGE | XFLIP | YFLIP ); |
159 | |||
160 | char buf[76800]; | 177 | char buf[76800]; |
161 | 178 | char* bp = buf; | |
162 | write( _driver, "M=13", 4 ); | ||
163 | write( _driver, "R=240,160,256,480", 17 ); | ||
164 | write( _driver, "M=12", 4 ); | ||
165 | |||
166 | int result = read( _driver, &buf, sizeof buf ); | ||
167 | |||
168 | return result == sizeof buf; | ||
169 | |||
170 | */ | ||
171 | |||
172 | unsigned char buf[76800]; | ||
173 | unsigned char* bp = buf; | ||
174 | unsigned char* p; | 179 | unsigned char* p; |
175 | 180 | ||
176 | int fd = open( "/tmp/cam", O_RDONLY ); | 181 | read( bp, _readlen ); |
177 | if ( ::read( fd, buf, sizeof buf ) != sizeof buf ) | ||
178 | owarn << "Couldn't read image from /dev/sharp_zdc" << oendl; | ||
179 | 182 | ||
180 | image->create( 240, 160, 16 ); | 183 | image->create( 240, 160, 16 ); |
181 | for ( int i = 0; i < 160; ++i ) | 184 | for ( int i = 0; i < 160; ++i ) |
182 | { | 185 | { |
183 | p = image->scanLine( i ); | 186 | p = image->scanLine( i ); |
184 | for ( int j = 0; j < 240; j++ ) | 187 | for ( int j = 0; j < 240; j++ ) |
185 | { | 188 | { |
186 | *p = *bp; | 189 | *p = *bp; |
187 | p++; | 190 | p++; |
188 | bp++; | 191 | bp++; |
189 | *p = *bp; | 192 | *p = *bp; |
190 | p++; | 193 | p++; |
191 | bp++; | 194 | bp++; |
192 | } | 195 | } |
193 | } | 196 | } |
194 | 197 | ||
195 | return true; | 198 | return true; |
196 | } | 199 | } |
197 | 200 | ||
198 | bool ZCameraIO::snapshot( uchar* buf ) | 201 | bool ZCameraIO::snapshot( unsigned char* buf ) |
199 | { | 202 | { |
203 | setReadMode( IMAGE | XFLIP | YFLIP ); | ||
204 | |||
205 | read( (char*) buf, _readlen ); | ||
206 | |||
207 | /* //TESTCODE | ||
200 | int fd = open( "/tmp/cam", O_RDONLY ); | 208 | int fd = open( "/tmp/cam", O_RDONLY ); |
201 | if ( ::read( fd, buf, 76800 ) != 76800 ) | 209 | if ( ::read( fd, (char*) buf, 76800 ) != 76800 ) |
202 | owarn << "Couldn't read image from /dev/sharp_zdc" << oendl; | 210 | owarn << "Couldn't read image from /dev/sharp_zdc" << oendl; |
211 | // TESTCODE */ | ||
212 | |||
203 | 213 | ||
204 | return true; | 214 | return true; |
205 | } | 215 | } |
206 | 216 | ||