summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-06 14:38:18 (UTC)
committer mickeyl <mickeyl>2003-04-06 14:38:18 (UTC)
commit0b985ce87d6ce6d4110a50d5be48831d34794cd2 (patch) (unidiff)
treeda19d8dc2cd2b37d15220783940652e8e91f3843
parent91d65a97c956963a24f418fadd7cd69f6a52f5d5 (diff)
downloadopie-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. :(
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/camera/.cvsignore4
-rw-r--r--noncore/multimedia/camera/camera.pro4
-rw-r--r--noncore/multimedia/camera/mainwindow.cpp40
-rw-r--r--noncore/multimedia/camera/mainwindow.h12
-rw-r--r--noncore/multimedia/camera/mainwindowbase.ui246
-rw-r--r--noncore/multimedia/camera/previewwidget.cpp45
-rw-r--r--noncore/multimedia/camera/previewwidget.h39
-rw-r--r--noncore/multimedia/camera/zcameraio.cpp58
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 @@
1config.in 1config.in
2mainwindowbase.h
3mainwindowbase.cpp
4Makefile
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
@@ -5,16 +5,18 @@ TEMPLATE = app
5CONFIG = qt warn_on debug 5CONFIG = qt warn_on debug
6 6
7HEADERS = zcameraio.h \ 7HEADERS = zcameraio.h \
8 previewwidget.h \
8 mainwindow.h 9 mainwindow.h
9 10
10SOURCES = zcameraio.cpp \ 11SOURCES = zcameraio.cpp \
12 previewwidget.cpp \
11 mainwindow.cpp \ 13 mainwindow.cpp \
12 main.cpp 14 main.cpp
13 15
14INCLUDEPATH += $(OPIEDIR)/include 16INCLUDEPATH += $(OPIEDIR)/include
15DEPENDPATH += $(OPIEDIR)/include 17DEPENDPATH += $(OPIEDIR)/include
16LIBS += -lqpe -lopiecore2 18LIBS += -lqpe -lopiecore2
17INTERFACES = 19INTERFACES = mainwindowbase.ui
18TARGET = opiecam 20TARGET = opiecam
19 21
20include ( $(OPIEDIR)/include.pro ) 22include ( $(OPIEDIR)/include.pro )
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
@@ -14,30 +14,28 @@
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
28CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) 30CameraMainWindow::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
@@ -46,19 +44,17 @@ CameraMainWindow::~CameraMainWindow()
46} 44}
47 45
48 46
49void CameraMainWindow::clickedSnapShot() 47void 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
@@ -17,10 +17,14 @@
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
21class QIconSet; 24class QIconSet;
22class QToolButton; 25class QToolButton;
23class QLabel; 26class QLabel;
27class MainWindowBase;
24 28
25class CameraMainWindow: public QMainWindow 29class CameraMainWindow: public QMainWindow
26{ 30{
@@ -30,13 +34,13 @@ class CameraMainWindow: public QMainWindow
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
19PreviewWidget::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
29PreviewWidget::~PreviewWidget()
30{
31}
32
33
34void 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
23class 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
@@ -24,9 +24,12 @@
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
30ZCameraIO* ZCameraIO::_instance = 0; 33ZCameraIO* ZCameraIO::_instance = 0;
31 34
32ZCameraIO* ZCameraIO::instance() 35ZCameraIO* ZCameraIO::instance()
@@ -43,7 +46,7 @@ ZCameraIO* ZCameraIO::instance()
43ZCameraIO::ZCameraIO() 46ZCameraIO::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
@@ -65,7 +68,10 @@ void ZCameraIO::init()
65ZCameraIO::~ZCameraIO() 68ZCameraIO::~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
@@ -107,7 +113,7 @@ bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot )
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
@@ -119,7 +125,7 @@ bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot )
119 125
120void ZCameraIO::setReadMode( int mode ) 126void 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
@@ -136,8 +142,20 @@ void ZCameraIO::clearShutterLatch()
136 142
137bool ZCameraIO::read( char* b, int len ) 143bool 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
@@ -155,27 +173,12 @@ bool ZCameraIO::write( char* buf, int len )
155 173
156bool ZCameraIO::snapshot( QImage* image ) 174bool 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 )
@@ -195,11 +198,18 @@ bool ZCameraIO::snapshot( QImage* image )
195 return true; 198 return true;
196} 199}
197 200
198bool ZCameraIO::snapshot( uchar* buf ) 201bool 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}