summaryrefslogtreecommitdiff
path: root/noncore/multimedia/camera/lib
Unidiff
Diffstat (limited to 'noncore/multimedia/camera/lib') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/camera/lib/.cvsignore5
-rw-r--r--noncore/multimedia/camera/lib/avi.c236
-rw-r--r--noncore/multimedia/camera/lib/avi.h142
-rw-r--r--noncore/multimedia/camera/lib/imageio.cpp55
-rw-r--r--noncore/multimedia/camera/lib/imageio.h26
-rw-r--r--noncore/multimedia/camera/lib/zcameraio.cpp311
-rw-r--r--noncore/multimedia/camera/lib/zcameraio.h86
7 files changed, 861 insertions, 0 deletions
diff --git a/noncore/multimedia/camera/lib/.cvsignore b/noncore/multimedia/camera/lib/.cvsignore
new file mode 100644
index 0000000..737c5b2
--- a/dev/null
+++ b/noncore/multimedia/camera/lib/.cvsignore
@@ -0,0 +1,5 @@
1moc
2obj
3config.in
4Makefile
5
diff --git a/noncore/multimedia/camera/lib/avi.c b/noncore/multimedia/camera/lib/avi.c
new file mode 100644
index 0000000..77aba33
--- a/dev/null
+++ b/noncore/multimedia/camera/lib/avi.c
@@ -0,0 +1,236 @@
1/**********************************************************************
2** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved.
3** Based on work from Andrew Tridgell and the jpegtoavi project
4**
5** This file is part of Opie Environment.
6**
7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file.
11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14**
15**********************************************************************/
16
17#include "avi.h"
18
19#include <string.h>
20#include <stdio.h>
21
22int nframes;
23int totalsize;
24unsigned int* sizes;
25
26void fprint_quartet(int fd, unsigned int i)
27{
28 char data[4];
29
30 data[0] = (char) i%0x100;
31 i /= 0x100;
32 data[1] = (char) i%0x100;
33 i /= 0x100;
34 data[2] = (char) i%0x100;
35 i /= 0x100;
36 data[3] = (char) i%0x100;
37
38 write( fd, &data, 4 );
39}
40
41// start writing an AVI file
42
43void avi_start(int fd, int frames)
44{
45 int ofs = sizeof(struct riff_head)+
46 sizeof(struct list_head)+
47 sizeof(struct avi_head)+
48 sizeof(struct list_head)+
49 sizeof(struct stream_head)+
50 sizeof(struct frame_head)+
51 sizeof(struct list_head)+
52 sizeof(struct dmlh_head)+
53 sizeof(struct list_head);
54
55 printf( "avi_start: frames = %d\n", frames );
56
57 lseek(fd, ofs, SEEK_SET);
58
59 nframes = 0;
60 totalsize = 0;
61
62 sizes = (unsigned int*) calloc( sizeof(unsigned int), frames ); // hold size of each frame
63}
64
65// add a jpeg frame to an AVI file
66void avi_add(int fd, u8 *buf, int size)
67{
68 struct db_head db = {"00db", 0};
69
70 printf( "avi_add: nframes = %d, totalsize = %d, size = %d\n", nframes, totalsize, size );
71
72 // overwrite JFIF type with AVI1
73 buf[6]='A';
74 buf[7]='V';
75 buf[8]='I';
76 buf[9]='1';
77
78 while( size%4 ) size++; // align 0 modulo 4*/
79 db.size = size;
80
81 write( fd, &db, sizeof(db) );
82 write( fd, buf, size );
83
84 sizes[nframes] = size;
85
86 nframes++;
87 totalsize += size; // total frame size
88}
89
90// finish writing the AVI file - filling in the header
91void avi_end(int fd, int width, int height, int fps)
92{
93 struct idx1_head idx = {"idx1", 16*nframes };
94 struct db_head db = {"00db", 0};
95 struct riff_head rh = { "RIFF", 0, "AVI "};
96 struct list_head lh1 = {"LIST", 0, "hdrl"};
97 struct avi_head ah;
98 struct list_head lh2 = {"LIST", 0, "strl"};
99 struct stream_head sh;
100 struct frame_head fh;
101 struct list_head lh3 = {"LIST", 0, "odml" };
102 struct dmlh_head dh = {"dmlh", 4, nframes };
103 struct list_head lh4 = {"LIST", 0, "movi"};
104 int i;
105 unsigned int offset = 4;
106
107 printf( "avi_end: nframes = %d, fps = %d\n", nframes, fps );
108
109 // write index
110
111 write(fd, &idx, sizeof(idx));
112
113 for ( i = 0; i < nframes; i++ )
114 {
115 write(fd, &db, 4 ); // only need the 00db
116 fprint_quartet( fd, 18 ); // ???
117 fprint_quartet( fd, offset );
118 fprint_quartet( fd, sizes[i] );
119 offset += sizes[i] + 8; //+8 (for the additional header)
120 }
121
122 free( sizes );
123
124 bzero( &ah, sizeof(ah) );
125 strcpy(ah.avih, "avih");
126 ah.time = 1000000 / fps;
127 ah.maxbytespersec = 1000000.0*(totalsize/nframes)/ah.time;
128 ah.nframes = nframes;
129 ah.numstreams = 1;
130 ah.flags = AVIF_HASINDEX;
131 ah.width = width;
132 ah.height = height;
133
134 bzero(&sh, sizeof(sh));
135 strcpy(sh.strh, "strh");
136 strcpy(sh.vids, "vids");
137 strcpy(sh.codec, "MJPG");
138 sh.scale = ah.time;
139 sh.rate = 1000000;
140 sh.length = nframes;
141
142 bzero(&fh, sizeof(fh));
143 strcpy(fh.strf, "strf");
144 fh.width = width;
145 fh.height = height;
146 fh.planes = 1;
147 fh.bitcount = 24;
148 strcpy(fh.codec,"MJPG");
149 fh.unpackedsize = 3*width*height;
150
151 rh.size = sizeof(lh1)+sizeof(ah)+sizeof(lh2)+sizeof(sh)+
152 sizeof(fh)+sizeof(lh3)+sizeof(dh)+sizeof(lh4)+
153 nframes*sizeof(struct db_head)+
154 totalsize + sizeof(struct idx1_head)+ (16*nframes) +4; // FIXME:16 bytes per nframe // the '4' - what for???
155
156 lh1.size = 4+sizeof(ah)+sizeof(lh2)+sizeof(sh)+sizeof(fh)+sizeof(lh3)+sizeof(dh);
157 ah.size = sizeof(ah)-8;
158 lh2.size = 4+sizeof(sh)+sizeof(fh)+sizeof(lh3)+sizeof(dh); //4+sizeof(sh)+sizeof(fh);
159 sh.size = sizeof(sh)-8;
160 fh.size = sizeof(fh)-8;
161 fh.size2 = fh.size;
162 lh3.size = 4+sizeof(dh);
163 lh4.size = 4+ nframes*sizeof(struct db_head)+ totalsize;
164
165 lseek(fd, 0, SEEK_SET);
166
167 write(fd, &rh, sizeof(rh));
168 write(fd, &lh1, sizeof(lh1));
169 write(fd, &ah, sizeof(ah));
170 write(fd, &lh2, sizeof(lh2));
171 write(fd, &sh, sizeof(sh));
172 write(fd, &fh, sizeof(fh));
173 write(fd, &lh3, sizeof(lh3));
174 write(fd, &dh, sizeof(dh));
175 write(fd, &lh4, sizeof(lh4));
176}
177
178
179/* NOTE: This is not a general purpose routine - it is meant to only
180 cope with AVIs saved using the other functions in this file
181void avi_explode(char *fname)
182{
183 struct riff_head rh;
184 struct list_head lh1;
185 struct avi_head ah;
186 struct list_head lh2;
187 struct stream_head sh;
188 struct frame_head fh;
189 struct list_head lh3;
190 int hsize, qsize;
191 u16 *htables = jpeg_huffman_tables(&hsize);
192 u16 *qtables = jpeg_quantisation_tables(&qsize, image_quality);
193 int fd, i;
194
195 fd = open(fname,O_RDONLY);
196 if (fd == -1) {
197 perror(fname);
198 return;
199 }
200
201 read(fd, &rh, sizeof(rh));
202 read(fd, &lh1, sizeof(lh1));
203 read(fd, &ah, sizeof(ah));
204 read(fd, &lh2, sizeof(lh2));
205 read(fd, &sh, sizeof(sh));
206 read(fd, &fh, sizeof(fh));
207 read(fd, &lh3, sizeof(lh3));
208
209 for (i=0; ; i++) {
210 u8 buf[500*1024];
211 struct db_head db;
212 char fname[100];
213 int fd2;
214
215 if (read(fd, &db, sizeof(db)) != sizeof(db) ||
216 read(fd, buf, db.size) != db.size) break;
217
218 snprintf(fname, sizeof(fname)-1,"frame.%d", i);
219
220 fd2 = open(fname,O_WRONLY|O_CREAT, 0644);
221 if (fd2 == -1) {
222 perror(fname);
223 continue;
224 }
225 write(fd2, buf, 2);
226 write(fd2, qtables, qsize);
227 write(fd2, htables, hsize);
228 write(fd2, buf+2, db.size-2);
229 close(fd2);
230 }
231 close(fd);
232 printf("exploded %d frames\n", i);
233}
234
235*/
236
diff --git a/noncore/multimedia/camera/lib/avi.h b/noncore/multimedia/camera/lib/avi.h
new file mode 100644
index 0000000..fbdc14a
--- a/dev/null
+++ b/noncore/multimedia/camera/lib/avi.h
@@ -0,0 +1,142 @@
1/**********************************************************************
2** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved.
3** Based on work from Andrew Tridgell and the jpegtoavi project
4**
5** This file is part of Opie Environment.
6**
7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file.
11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14**
15**********************************************************************/
16
17#ifndef AVI_H
18#define AVI_H
19
20#include <unistd.h>
21#include <stdio.h>
22#include <sys/types.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28typedef unsigned char u8;
29typedef unsigned short u16;
30typedef unsigned u32;
31
32// header flags
33
34const u32 AVIF_HASINDEX=0x00000010; /* index at end of file */
35const u32 AVIF_MUSTUSEINDEX=0x00000020;
36const u32 AVIF_ISINTERLEAVED=0x00000100;
37const u32 AVIF_TRUSTCKTYPE=0x00000800;
38const u32 AVIF_WASCAPTUREFILE=0x00010000;
39const u32 AVIF_COPYRIGHTED=0x00020000;
40
41// function prototypes
42
43void avi_start(int fd, int frame);
44void avi_add(int fd, u8 *buf, int size);
45void avi_end(int fd, int width, int height, int fps);
46void fprint_quartet(int fd, unsigned int i);
47
48// the following structures are ordered as they appear in a typical AVI
49
50struct riff_head {
51 char riff[4]; // chunk type = "RIFF"
52 u32 size; // chunk size
53 char avistr[4]; // avi magic = "AVI "
54};
55
56// the avih chunk contains a number of list chunks
57
58struct avi_head {
59 char avih[4]; // chunk type = "avih"
60 u32 size; // chunk size
61 u32 time; // microsec per frame == 1e6 / fps
62 u32 maxbytespersec; // = 1e6*(total size/frames)/per_usec)
63 u32 pad; // pad = 0
64 u32 flags; // e.g. AVIF_HASINDEX
65 u32 nframes; // total number of frames
66 u32 initialframes; // = 0
67 u32 numstreams; // = 1 for now (later = 2 because of audio)
68 u32 suggested_bufsize; // = 0 (no suggestion)
69 u32 width; // width
70 u32 height; // height
71 u32 reserved[4]; // reserved for future use = 0
72};
73
74
75// the LIST chunk contains a number (==#numstreams) of stream chunks
76
77struct list_head {
78 char list[4]; // chunk type = "LIST"
79 u32 size;
80 char type[4];
81};
82
83
84struct dmlh_head {
85 char dmlh[4]; // chunk type dmlh
86 u32 size; // 4
87 u32 nframes; // number of frames
88};
89
90
91struct stream_head {
92 char strh[4]; // chunk type = "strh"
93 u32 size; // chunk size
94 char vids[4]; // stream type = "vids"
95 char codec[4]; // codec name (for us, = "MJPG")
96 u32 flags; // contains AVIT_F* flags
97 u16 priority; // = 0
98 u16 language; // = 0
99 u32 initialframes; // = 0
100 u32 scale; // = usec per frame
101 u32 rate; // 1e6
102 u32 start; // = 0
103 u32 length; // number of frames
104 u32 suggested_bufsize; // = 0
105 u32 quality; // = 0 ?
106 u32 samplesize; // = 0 ?
107};
108
109
110struct db_head {
111 char db[4]; // "00db"
112 u32 size;
113};
114
115// a frame chunk contains one JPEG image
116
117struct frame_head {
118 char strf[4]; // chunk type = "strf"
119 u32 size; // sizeof chunk (big endian) ?
120 u32 size2; // sizeof chunk (little endian) ?
121 u32 width;
122 u32 height;
123 u16 planes; // 1 bitplane
124 u16 bitcount; // 24 bpl
125 char codec[4]; // MJPG (for us)
126 u32 unpackedsize; // = 3*w*h
127 u32 r1; // reserved
128 u32 r2; // reserved
129 u32 clr_used; // reserved
130 u32 clr_important; // reserved
131};
132
133struct idx1_head {
134 char idx1[4]; // chunk type = "idx1"
135 u32 size; // chunk size
136};
137
138#ifdef __cplusplus
139}
140#endif
141
142#endif
diff --git a/noncore/multimedia/camera/lib/imageio.cpp b/noncore/multimedia/camera/lib/imageio.cpp
new file mode 100644
index 0000000..ed0d39f
--- a/dev/null
+++ b/noncore/multimedia/camera/lib/imageio.cpp
@@ -0,0 +1,55 @@
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 "imageio.h"
17
18#include <opie2/odebug.h>
19#include <qimage.h>
20
21
22void bufferToImage( int _width, int _height, unsigned char* bp, QImage* image )
23{
24 unsigned char* p;
25
26 image->create( _width, _height, 16 );
27 for ( int i = 0; i < _height; ++i )
28 {
29 p = image->scanLine( i );
30 for ( int j = 0; j < _width; j++ )
31 {
32 *p = *bp;
33 p++;
34 bp++;
35 *p = *bp;
36 p++;
37 bp++;
38 }
39 }
40}
41
42
43void imageToFile( QImage* i, const QString& name, const QString& format, int quality )
44{
45 QImage im = i->convertDepth( 32 );
46 bool result = im.save( name, format, quality );
47 if ( !result )
48 {
49 oerr << "imageio-Problem while writing to " << name << oendl;
50 }
51 else
52 {
53 odebug << format << "-image has been successfully captured" << oendl;
54 }
55}
diff --git a/noncore/multimedia/camera/lib/imageio.h b/noncore/multimedia/camera/lib/imageio.h
new file mode 100644
index 0000000..8dba2ed
--- a/dev/null
+++ b/noncore/multimedia/camera/lib/imageio.h
@@ -0,0 +1,26 @@
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 IMAGEIO_H
17#define IMAGEIO_H
18
19#include <qstring.h>
20
21class QImage;
22
23void bufferToImage( int _width, int height, unsigned char* bp, QImage* image );
24void imageToFile( QImage* i, const QString& name, const QString& format, int quality );
25
26#endif
diff --git a/noncore/multimedia/camera/lib/zcameraio.cpp b/noncore/multimedia/camera/lib/zcameraio.cpp
new file mode 100644
index 0000000..c940b45
--- a/dev/null
+++ b/noncore/multimedia/camera/lib/zcameraio.cpp
@@ -0,0 +1,311 @@
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 "zcameraio.h"
17
18#include <sys/types.h>
19#include <sys/stat.h>
20#include <errno.h>
21#include <string.h>
22#include <fcntl.h>
23#include <unistd.h>
24#include <stdio.h>
25
26#include <qimage.h>
27#include <qdatetime.h>
28
29#include <opie2/odebug.h>
30
31#define SHARPZDC "/dev/sharp_zdc"
32
33ZCameraIO* ZCameraIO::_instance = 0;
34
35ZCameraIO* ZCameraIO::instance()
36{
37 if ( !ZCameraIO::_instance )
38 {
39 odebug << "Creating ZCameraIO::_instance" << oendl;
40 ZCameraIO::_instance = new ZCameraIO();
41 }
42 return ZCameraIO::_instance;
43}
44
45
46ZCameraIO::ZCameraIO()
47 : _pressed( false ), _height( 0 ), _width( 0 ), _zoom( 0 ),
48 _flip( -1 ), _rot( 0 ), _readlen( 0 )
49
50{
51 _driver = ::open( SHARPZDC, O_RDWR );
52 if ( _driver == -1 )
53 oerr << "Can't open camera driver: " << strerror(errno) << oendl;
54 else
55 init();
56}
57
58
59void ZCameraIO::init()
60{
61 if ( ZCameraIO::_instance )
62 ofatal << "Don't create more than one ZCameraIO instances." << oendl;
63 else
64 {
65 _timer = new QTime();
66 setReadMode( STATUS );
67 }
68}
69
70
71ZCameraIO::~ZCameraIO()
72{
73 if ( _driver != -1 )
74 {
75 setReadMode( 0 );
76 ::close( _driver );
77 }
78}
79
80
81bool ZCameraIO::isOpen() const
82{
83 return _driver != -1;
84}
85
86
87bool ZCameraIO::isShutterPressed()
88{
89 if ( _status[0] == 'S' )
90 {
91 if ( !_pressed ) // wasn't pressed before, but is now!
92 {
93 _pressed = true;
94 _timer->start();
95 return true;
96 }
97
98 if ( _timer->elapsed() > 2000 ) // the press is pretty old now
99 {
100 clearShutterLatch();
101 _status[0] = 's';
102 _pressed = false;
103 }
104 }
105
106 return false;
107}
108
109
110bool ZCameraIO::isFinderReversed() const
111{
112 return _status[1] == 'M';
113}
114
115
116bool ZCameraIO::isCapturing() const
117{
118 return _status[2] == 'C';
119}
120
121
122bool ZCameraIO::isAvailable() const
123{
124 return _status[3] == 'A';
125}
126
127
128bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot )
129{
130 odebug << "setCaptureFrame( " << width << ", " << height << ", " << zoom << ", " << rot << " )" << oendl;
131 char b[100];
132 sprintf( b, "%c=%d,%d,%d,%d", rot ? 'R':'S', width, height, zoom, width*2 );
133 if ( write( b ) )
134 {
135 _width = width;
136 _height = height;
137 _zoom = zoom;
138 _rot = rot;
139 _readlen = 2 * _width * _height; // camera is fixed @ 16 bits per pixel
140 return true;
141 }
142 return false;
143}
144
145
146bool ZCameraIO::setZoom( int zoom )
147{
148 return setCaptureFrame( _width, _height, zoom*256, _rot );
149}
150
151
152void ZCameraIO::setReadMode( int mode )
153{
154 char b[10];
155 sprintf( b, "M=%d", mode );
156 write( b, mode <= 9 ? 3 : 4 );
157 if ( mode & STATUS ) // STATUS bit is set
158 {
159 read( _status, 4 );
160 if ( isShutterPressed() )
161 {
162 emit shutterClicked();
163 }
164 }
165}
166
167
168void ZCameraIO::setFlip( int flip )
169{
170 _flip = flip;
171}
172
173
174void ZCameraIO::clearShutterLatch()
175{
176 write( "B", 1 );
177}
178
179
180bool ZCameraIO::read( char* b, int len )
181{
182 #ifndef NO_TIMING
183 QTime t;
184 t.start();
185 #endif
186 int rlen = ::read( _driver, b, len );
187 #ifndef NO_TIMING
188 int time = t.elapsed();
189 #else
190 int time = -1;
191 #endif
192 if ( rlen )
193 odebug << "read " << rlen << " ('" << b[0] << b[1] << b[2] << b[3] << "') [" << time << " ms] from driver." << oendl;
194 else
195 odebug << "read nothing from driver." << oendl;
196 return rlen == len;
197}
198
199
200bool ZCameraIO::write( char* buf, int len )
201{
202 if ( !len )
203 len = strlen( buf );
204
205 odebug << "writing '" << buf << "' to driver." << oendl;
206
207 return ::write( _driver, buf, len ) == len;
208}
209
210
211bool ZCameraIO::snapshot( QImage* image )
212{
213 setReadMode( STATUS );
214
215 odebug << "finder reversed = " << isFinderReversed() << oendl;
216 odebug << "rotation = " << _rot << oendl;
217
218 int readmode;
219 if ( _flip == -1 ) // AUTO
220 {
221 if ( _rot ) // Portrait
222 {
223 readmode = IMAGE | isFinderReversed() ? XFLIP | YFLIP : 0;
224 }
225 else // Landscape
226 {
227 readmode = IMAGE | XFLIP | YFLIP;
228 }
229 }
230 else // OVERRIDE
231 {
232 readmode = IMAGE | _flip;
233 }
234
235 setReadMode( readmode );
236
237 char buf[_readlen];
238 char* bp = buf;
239 unsigned char* p;
240
241 read( bp, _readlen );
242
243 image->create( _width, _height, 16 );
244 for ( int i = 0; i < _height; ++i )
245 {
246 p = image->scanLine( i );
247 for ( int j = 0; j < _width; j++ )
248 {
249 *p = *bp;
250 p++;
251 bp++;
252 *p = *bp;
253 p++;
254 bp++;
255 }
256 }
257
258 return true;
259}
260
261
262bool ZCameraIO::snapshot( unsigned char* buf )
263{
264 setReadMode( STATUS );
265
266 odebug << "finder reversed = " << isFinderReversed() << oendl;
267 odebug << "rotation = " << _rot << oendl;
268
269 int readmode;
270 if ( _flip == -1 ) // AUTO
271 {
272 if ( _rot ) // Portrait
273 {
274 readmode = IMAGE | isFinderReversed() ? XFLIP | YFLIP : 0;
275 }
276 else // Landscape
277 {
278 readmode = IMAGE | XFLIP | YFLIP;
279 }
280 }
281 else // OVERRIDE
282 {
283 readmode = IMAGE | _flip;
284 }
285
286 setReadMode( readmode );
287 read( (char*) buf, _readlen );
288
289}
290
291
292void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image )
293{
294 int pw = _width;
295 int ph = _height;
296 setCaptureFrame( w, h, zoom*256, _rot );
297 snapshot( image );
298 setCaptureFrame( pw, ph, _zoom, _rot );
299}
300
301
302void ZCameraIO::captureFrame( int w, int h, int zoom, unsigned char* buf )
303{
304 //FIXME: this is too slow
305 int pw = _width;
306 int ph = _height;
307 setCaptureFrame( w, h, zoom*256, _rot );
308 snapshot( buf );
309 setCaptureFrame( pw, ph, _zoom, _rot );
310}
311
diff --git a/noncore/multimedia/camera/lib/zcameraio.h b/noncore/multimedia/camera/lib/zcameraio.h
new file mode 100644
index 0000000..3352a5e
--- a/dev/null
+++ b/noncore/multimedia/camera/lib/zcameraio.h
@@ -0,0 +1,86 @@
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 ZCAMERAIO_H
17#define ZCAMERAIO_H
18
19#include <qobject.h>
20
21class QImage;
22class QTime;
23
24class ZCameraIO : public QObject
25{
26 Q_OBJECT
27
28 public:
29 virtual ~ZCameraIO();
30
31 enum ReadMode
32 {
33 IMAGE = 0, STATUS = 1,
34 FASTER = 0, BETTER = 2,
35 XNOFLIP = 0, XFLIP = 4,
36 YNOFLIP = 0, YFLIP = 8,
37 AUTOMATICFLIP = -1
38 };
39
40 // low level interface
41
42 bool setCaptureFrame( int w, int h, int zoom = 256, bool rot = true );
43 bool setZoom( int zoom = 0 );
44 void setReadMode( int = IMAGE | XFLIP | YFLIP );
45 void setFlip( int flip );
46
47 bool isShutterPressed(); // not const, because it calls clearShutterLatch
48 bool isAvailable() const;
49 bool isCapturing() const;
50 bool isFinderReversed() const;
51
52 bool snapshot( QImage* image );
53 bool snapshot( unsigned char* buf );
54
55 // high level interface
56 bool isOpen() const;
57 static ZCameraIO* instance();
58 void captureFrame( int w, int h, int zoom, QImage* image );
59 void captureFrame( int w, int h, int zoom, unsigned char* buf );
60
61 protected:
62 ZCameraIO();
63 void clearShutterLatch();
64 void init();
65 bool read( char*, int );
66 bool write( char*, int = 0 );
67
68 signals:
69 void shutterClicked();
70
71 private:
72 int _driver;
73 char _status[4];
74 bool _pressed;
75 static ZCameraIO* _instance;
76 int _height;
77 int _width;
78 int _zoom;
79 int _flip;
80 bool _rot;
81 int _readlen;
82
83 QTime* _timer;
84};
85
86#endif