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 | |||
@@ -22,2 +22,4 @@ | |||
22 | 22 | ||
23 | #include <qdirectpainter_qws.h> | ||
24 | |||
23 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
@@ -48,2 +50,6 @@ void CameraMainWindow::clickedSnapShot() | |||
48 | { | 50 | { |
51 | QDirectPainter fb( l ); | ||
52 | ZCameraIO::instance()->snapshot( fb.frameBuffer() ); | ||
53 | |||
54 | /* | ||
49 | QImage i; | 55 | QImage i; |
@@ -55,2 +61,3 @@ void CameraMainWindow::clickedSnapShot() | |||
55 | } | 61 | } |
62 | */ | ||
56 | } | 63 | } |
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 | |||
@@ -23,2 +23,3 @@ | |||
23 | #include <unistd.h> | 23 | #include <unistd.h> |
24 | #include <stdio.h> | ||
24 | 25 | ||
@@ -30,10 +31,33 @@ 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 | ||
@@ -43,3 +67,87 @@ ZCameraIO::~ZCameraIO() | |||
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 | } |
@@ -63,10 +171,9 @@ bool ZCameraIO::snapshot( QImage* image ) | |||
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 | ||
@@ -89 +196,11 @@ bool ZCameraIO::snapshot( QImage* image ) | |||
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 | |||
@@ -23,8 +23,31 @@ class ZCameraIO | |||
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 | ||
@@ -32,3 +55,9 @@ class ZCameraIO | |||
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 | }; |