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 /noncore/multimedia/camera/zcameraio.cpp | |
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. :(
Diffstat (limited to 'noncore/multimedia/camera/zcameraio.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/multimedia/camera/zcameraio.cpp | 58 |
1 files changed, 34 insertions, 24 deletions
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 | |||
@@ -21,15 +21,18 @@ | |||
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 | { |
@@ -40,13 +43,13 @@ ZCameraIO* 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 | ||
@@ -62,13 +65,16 @@ void ZCameraIO::init() | |||
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; |
@@ -104,25 +110,25 @@ 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 | ||
@@ -133,14 +139,26 @@ void ZCameraIO::clearShutterLatch() | |||
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 | { |
@@ -152,33 +170,18 @@ bool ZCameraIO::write( char* buf, int len ) | |||
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++ ) |
@@ -192,15 +195,22 @@ bool ZCameraIO::snapshot( QImage* image ) | |||
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 | ||