summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-02 15:28:33 (UTC)
committer mickeyl <mickeyl>2003-04-02 15:28:33 (UTC)
commite9eeb493c75bfe6078f40952e85e859fb71fe970 (patch) (unidiff)
tree2a6eedcdfbc3aa166d3f9d3cf317cfb7d8de7a52
parentf0d3ff51dde49f994783827051464920529024af (diff)
downloadopie-e9eeb493c75bfe6078f40952e85e859fb71fe970.zip
opie-e9eeb493c75bfe6078f40952e85e859fb71fe970.tar.gz
opie-e9eeb493c75bfe6078f40952e85e859fb71fe970.tar.bz2
implementation of camera API as described in the Sharp Camera API document nearly completed
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/camera/mainwindow.cpp7
-rw-r--r--noncore/multimedia/camera/zcameraio.cpp137
-rw-r--r--noncore/multimedia/camera/zcameraio.h35
3 files changed, 166 insertions, 13 deletions
diff --git a/noncore/multimedia/camera/mainwindow.cpp b/noncore/multimedia/camera/mainwindow.cpp
index 2cca9f9..4218232 100644
--- a/noncore/multimedia/camera/mainwindow.cpp
+++ b/noncore/multimedia/camera/mainwindow.cpp
@@ -7,51 +7,58 @@
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 "zcameraio.h" 17#include "zcameraio.h"
18 18
19#include <qvbox.h> 19#include <qvbox.h>
20#include <qpushbutton.h> 20#include <qpushbutton.h>
21#include <qlabel.h> 21#include <qlabel.h>
22 22
23#include <qdirectpainter_qws.h>
24
23#include <qpe/resource.h> 25#include <qpe/resource.h>
24#include <opie/ofiledialog.h> 26#include <opie/ofiledialog.h>
25 27
26CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) 28CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f )
27 :QMainWindow( parent, name, f ) 29 :QMainWindow( parent, name, f )
28{ 30{
29 QVBox* v = new QVBox( this ); 31 QVBox* v = new QVBox( this );
30 l = new QLabel( v ); 32 l = new QLabel( v );
31 l->setFixedSize( QSize( 240, 160 ) ); 33 l->setFixedSize( QSize( 240, 160 ) );
32 QPushButton* p = new QPushButton( "Snapshot", v ); 34 QPushButton* p = new QPushButton( "Snapshot", v );
33 connect( p, SIGNAL( clicked() ), this, SLOT( clickedSnapShot() ) ); 35 connect( p, SIGNAL( clicked() ), this, SLOT( clickedSnapShot() ) );
34 v->show(); 36 v->show();
35 l->show(); 37 l->show();
36 p->show(); 38 p->show();
37 setCentralWidget( v ); 39 setCentralWidget( v );
38 40
39}; 41};
40 42
41 43
42CameraMainWindow::~CameraMainWindow() 44CameraMainWindow::~CameraMainWindow()
43{ 45{
44} 46}
45 47
46 48
47void CameraMainWindow::clickedSnapShot() 49void CameraMainWindow::clickedSnapShot()
48{ 50{
51 QDirectPainter fb( l );
52 ZCameraIO::instance()->snapshot( fb.frameBuffer() );
53
54 /*
49 QImage i; 55 QImage i;
50 QPixmap p; 56 QPixmap p;
51 if ( ZCameraIO::instance()->snapshot( &i ) ) 57 if ( ZCameraIO::instance()->snapshot( &i ) )
52 { 58 {
53 p.convertFromImage( i ); 59 p.convertFromImage( i );
54 l->setPixmap( p ); 60 l->setPixmap( p );
55 } 61 }
62 */
56} 63}
57 64
diff --git a/noncore/multimedia/camera/zcameraio.cpp b/noncore/multimedia/camera/zcameraio.cpp
index e74136f..7343dca 100644
--- a/noncore/multimedia/camera/zcameraio.cpp
+++ b/noncore/multimedia/camera/zcameraio.cpp
@@ -8,82 +8,199 @@
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 25
25#include <qimage.h> 26#include <qimage.h>
26 27
27#include <opie2/odebug.h> 28#include <opie2/odebug.h>
28 29
29ZCameraIO* ZCameraIO::_instance = 0; 30ZCameraIO* ZCameraIO::_instance = 0;
30 31
32ZCameraIO* ZCameraIO::instance()
33{
34 if ( !ZCameraIO::_instance )
35 {
36 odebug << "Creating ZCameraIO::_instance" << oendl;
37 ZCameraIO::_instance = new ZCameraIO();
38 }
39 return ZCameraIO::_instance;
40}
41
42
31ZCameraIO::ZCameraIO() 43ZCameraIO::ZCameraIO()
44 :_height( 0 ), _width( 0 ), _zoom( 0 ), _rot( 0 ), _readlen( 0 )
32{ 45{
33 _driver = open( "/dev/sharp_zdc", O_RDWR ); 46 _driver = ::open( "/dev/sharp_zdc", O_RDWR );
34 if ( _driver == -1 ) 47 if ( _driver == -1 )
35 oerr << "Can't open camera driver: " << strerror(errno) << oendl; 48 oerr << "Can't open camera driver: " << strerror(errno) << oendl;
49 else
50 init();
51}
52
36 53
37 ZCameraIO::_instance = this; 54void ZCameraIO::init()
38}; 55{
56 if ( ZCameraIO::_instance )
57 ofatal << "Don't create more than one ZCameraIO instances." << oendl;
58 else
59 {
60 setReadMode( STATUS );
61 }
62}
39 63
40 64
41ZCameraIO::~ZCameraIO() 65ZCameraIO::~ZCameraIO()
42{ 66{
43 if ( _driver != -1 ) 67 if ( _driver != -1 )
44 close( _driver ); 68 ::close( _driver );
69}
70
71
72inline bool ZCameraIO::isOpen() const
73{
74 return _driver != -1;
75}
76
77
78inline bool ZCameraIO::isShutterPressed()
79{
80 return _status[0] == 'S';
81 clearShutterLatch();
82}
83
84
85inline bool ZCameraIO::isFinderReversed() const
86{
87 return _status[1] == 'M';
88}
89
90
91inline bool ZCameraIO::isCapturing() const
92{
93 return _status[2] == 'C';
94}
95
96
97inline bool ZCameraIO::isAvailable() const
98{
99 return _status[3] == 'A';
100}
101
102
103bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot )
104{
105 char b[100];
106 sprintf( b, "%c=%d,%d,%d,%d", rot ? 'R':'S', width, height, zoom, width*2 );
107 if ( write( b ) )
108 {
109 _width = width;
110 _height = _height;
111 _zoom = zoom;
112 _rot = rot;
113 _readlen = 2 * _width * _height; // camera is fixed @ 16 bits per pixel
114 return true;
115 }
116 return false;
117}
118
119
120void ZCameraIO::setReadMode( int mode )
121{
122 char b[4];
123 sprintf( b, "M=%d", mode );
124 write( b, mode <= 9 ? 3 : 4 );
125 if ( mode & 1 ) // STATUS bit is set
126 read( _status, 4 );
127}
128
129
130void ZCameraIO::clearShutterLatch()
131{
132 char b = 'B';
133 write( &b, 1 );
134}
135
136
137bool ZCameraIO::read( char* b, int len )
138{
139 int rlen = ::read( _driver, b, len );
140 odebug << "read " << rlen << " from driver." << oendl;
141 return rlen == len;
142}
143
144
145bool ZCameraIO::write( char* buf, int len )
146{
147 if ( !len )
148 len = strlen( buf );
149
150 odebug << "writing '" << buf << "' to driver." << oendl;
151
152 return ::write( _driver, buf, len ) == len;
45} 153}
46 154
47 155
48bool ZCameraIO::snapshot( QImage* image ) 156bool ZCameraIO::snapshot( QImage* image )
49{ 157{
50 /* 158 /*
51 159
52 char buf[76800]; 160 char buf[76800];
53 161
54 write( _driver, "M=13", 4 ); 162 write( _driver, "M=13", 4 );
55 write( _driver, "R=240,160,256,480", 17 ); 163 write( _driver, "R=240,160,256,480", 17 );
56 write( _driver, "M=12", 4 ); 164 write( _driver, "M=12", 4 );
57 165
58 int result = read( _driver, &buf, sizeof buf ); 166 int result = read( _driver, &buf, sizeof buf );
59 167
60 return result == sizeof buf; 168 return result == sizeof buf;
61 169
62 */ 170 */
63 171
64 uchar buf[76800]; 172 unsigned char buf[76800];
65 uchar* bp = buf; 173 unsigned char* bp = buf;
66 uchar* p; 174 unsigned char* p;
67
68 175
69 int fd = open( "/tmp/cam", O_RDONLY ); 176 int fd = open( "/tmp/cam", O_RDONLY );
70 if ( read( fd, buf, sizeof buf ) != sizeof buf ) 177 if ( ::read( fd, buf, sizeof buf ) != sizeof buf )
71 qDebug( "WARNING: couldn't read image!" ); 178 owarn << "Couldn't read image from /dev/sharp_zdc" << oendl;
72 179
73 image->create( 240, 160, 16 ); 180 image->create( 240, 160, 16 );
74 for ( int i = 0; i < 160; ++i ) 181 for ( int i = 0; i < 160; ++i )
75 { 182 {
76 p = image->scanLine( i ); 183 p = image->scanLine( i );
77 for ( int j = 0; j < 240; j++ ) 184 for ( int j = 0; j < 240; j++ )
78 { 185 {
79 *p = *bp; 186 *p = *bp;
80 p++; 187 p++;
81 bp++; 188 bp++;
82 *p = *bp; 189 *p = *bp;
83 p++; 190 p++;
84 bp++; 191 bp++;
85 } 192 }
86 } 193 }
87 194
88 return true; 195 return true;
89} 196}
197
198bool ZCameraIO::snapshot( uchar* buf )
199{
200 int fd = open( "/tmp/cam", O_RDONLY );
201 if ( ::read( fd, buf, 76800 ) != 76800 )
202 owarn << "Couldn't read image from /dev/sharp_zdc" << oendl;
203
204 return true;
205}
206
diff --git a/noncore/multimedia/camera/zcameraio.h b/noncore/multimedia/camera/zcameraio.h
index 1690aa6..bc4926b 100644
--- a/noncore/multimedia/camera/zcameraio.h
+++ b/noncore/multimedia/camera/zcameraio.h
@@ -8,29 +8,58 @@
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 ZCAMERAIO_H 16#ifndef ZCAMERAIO_H
17#define ZCAMERAIO_H 17#define ZCAMERAIO_H
18 18
19class QImage; 19class QImage;
20 20
21class ZCameraIO 21class ZCameraIO
22{ 22{
23 public: 23 public:
24 ZCameraIO();
25 virtual ~ZCameraIO(); 24 virtual ~ZCameraIO();
26 25
27 bool isOpen() const { return _driver != -1; }; 26 enum ReadMode
27 {
28 IMAGE = 0, STATUS = 1,
29 FASTER = 0, BETTER = 2,
30 XNOFLIP = 0, XFLIP = 4,
31 YNOFLIP = 0, YFLIP = 8
32 };
33
34 bool setCaptureFrame( int w, int h, int zoom = 256, bool rot = true );
35 void setReadMode( int = IMAGE | XFLIP | YFLIP );
36
37 bool isShutterPressed(); // not const, because it calls clearShutterLatch
38 bool isAvailable() const;
39 bool isCapturing() const;
40 bool isFinderReversed() const;
41
42 bool isOpen() const;
28 bool snapshot( QImage* ); 43 bool snapshot( QImage* );
29 static ZCameraIO* instance() { return _instance; }; 44 bool snapshot( unsigned char* );
45 static ZCameraIO* instance();
46
47 protected:
48 ZCameraIO();
49 void clearShutterLatch();
50 void init();
51 bool read( char*, int );
52 bool write( char*, int = 0 );
30 53
31 private: 54 private:
32 int _driver; 55 int _driver;
56 char _status[4];
33 static ZCameraIO* _instance; 57 static ZCameraIO* _instance;
58 int _height;
59 int _width;
60 int _zoom;
61 bool _rot;
62 int _readlen;
34}; 63};
35 64
36#endif 65#endif