author | mickeyl <mickeyl> | 2003-04-02 15:28:33 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-02 15:28:33 (UTC) |
commit | e9eeb493c75bfe6078f40952e85e859fb71fe970 (patch) (unidiff) | |
tree | 2a6eedcdfbc3aa166d3f9d3cf317cfb7d8de7a52 | |
parent | f0d3ff51dde49f994783827051464920529024af (diff) | |
download | opie-e9eeb493c75bfe6078f40952e85e859fb71fe970.zip opie-e9eeb493c75bfe6078f40952e85e859fb71fe970.tar.gz opie-e9eeb493c75bfe6078f40952e85e859fb71fe970.tar.bz2 |
implementation of camera API as described in the Sharp Camera API document nearly completed
-rw-r--r-- | noncore/multimedia/camera/mainwindow.cpp | 7 | ||||
-rw-r--r-- | noncore/multimedia/camera/zcameraio.cpp | 137 | ||||
-rw-r--r-- | noncore/multimedia/camera/zcameraio.h | 35 |
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 | |||
@@ -20,6 +20,8 @@ | |||
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 | ||
@@ -46,6 +48,10 @@ CameraMainWindow::~CameraMainWindow() | |||
46 | 48 | ||
47 | void CameraMainWindow::clickedSnapShot() | 49 | void 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 ) ) |
@@ -53,5 +59,6 @@ void CameraMainWindow::clickedSnapShot() | |||
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 | |||
@@ -21,6 +21,7 @@ | |||
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 | ||
@@ -28,20 +29,127 @@ | |||
28 | 29 | ||
29 | ZCameraIO* ZCameraIO::_instance = 0; | 30 | ZCameraIO* ZCameraIO::_instance = 0; |
30 | 31 | ||
32 | ZCameraIO* 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 | |||
31 | ZCameraIO::ZCameraIO() | 43 | ZCameraIO::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; | 54 | void 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 | ||
41 | ZCameraIO::~ZCameraIO() | 65 | ZCameraIO::~ZCameraIO() |
42 | { | 66 | { |
43 | if ( _driver != -1 ) | 67 | if ( _driver != -1 ) |
44 | close( _driver ); | 68 | ::close( _driver ); |
69 | } | ||
70 | |||
71 | |||
72 | inline bool ZCameraIO::isOpen() const | ||
73 | { | ||
74 | return _driver != -1; | ||
75 | } | ||
76 | |||
77 | |||
78 | inline bool ZCameraIO::isShutterPressed() | ||
79 | { | ||
80 | return _status[0] == 'S'; | ||
81 | clearShutterLatch(); | ||
82 | } | ||
83 | |||
84 | |||
85 | inline bool ZCameraIO::isFinderReversed() const | ||
86 | { | ||
87 | return _status[1] == 'M'; | ||
88 | } | ||
89 | |||
90 | |||
91 | inline bool ZCameraIO::isCapturing() const | ||
92 | { | ||
93 | return _status[2] == 'C'; | ||
94 | } | ||
95 | |||
96 | |||
97 | inline bool ZCameraIO::isAvailable() const | ||
98 | { | ||
99 | return _status[3] == 'A'; | ||
100 | } | ||
101 | |||
102 | |||
103 | bool 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 | |||
120 | void 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 | |||
130 | void ZCameraIO::clearShutterLatch() | ||
131 | { | ||
132 | char b = 'B'; | ||
133 | write( &b, 1 ); | ||
134 | } | ||
135 | |||
136 | |||
137 | bool 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 | |||
145 | bool 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 | ||
@@ -61,14 +169,13 @@ bool ZCameraIO::snapshot( QImage* image ) | |||
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 ) |
@@ -87,3 +194,13 @@ bool ZCameraIO::snapshot( QImage* image ) | |||
87 | 194 | ||
88 | return true; | 195 | return true; |
89 | } | 196 | } |
197 | |||
198 | bool 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 | |||
@@ -21,16 +21,45 @@ class QImage; | |||
21 | class ZCameraIO | 21 | class 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 |