summaryrefslogtreecommitdiff
path: root/noncore/multimedia/camera/lib
authormickeyl <mickeyl>2003-05-07 10:21:19 (UTC)
committer mickeyl <mickeyl>2003-05-07 10:21:19 (UTC)
commitb632caef8d73edb7b5cab0c1b58df723ed654410 (patch) (side-by-side diff)
tree91f25d0cf8922c2620f90bd716f7a73f29fa0cdd /noncore/multimedia/camera/lib
parent6fc02cae4bd1fe3478e6e34575f481236ce5ede8 (diff)
downloadopie-b632caef8d73edb7b5cab0c1b58df723ed654410.zip
opie-b632caef8d73edb7b5cab0c1b58df723ed654410.tar.gz
opie-b632caef8d73edb7b5cab0c1b58df723ed654410.tar.bz2
restructure tree for inclusion of a command line application enabling the use as a webcam
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 @@
+moc
+obj
+config.in
+Makefile
+
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 @@
+/**********************************************************************
+** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved.
+** Based on work from Andrew Tridgell and the jpegtoavi project
+**
+** This file is part of Opie Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+**********************************************************************/
+
+#include "avi.h"
+
+#include <string.h>
+#include <stdio.h>
+
+int nframes;
+int totalsize;
+unsigned int* sizes;
+
+void fprint_quartet(int fd, unsigned int i)
+{
+ char data[4];
+
+ data[0] = (char) i%0x100;
+ i /= 0x100;
+ data[1] = (char) i%0x100;
+ i /= 0x100;
+ data[2] = (char) i%0x100;
+ i /= 0x100;
+ data[3] = (char) i%0x100;
+
+ write( fd, &data, 4 );
+}
+
+// start writing an AVI file
+
+void avi_start(int fd, int frames)
+{
+ int ofs = sizeof(struct riff_head)+
+ sizeof(struct list_head)+
+ sizeof(struct avi_head)+
+ sizeof(struct list_head)+
+ sizeof(struct stream_head)+
+ sizeof(struct frame_head)+
+ sizeof(struct list_head)+
+ sizeof(struct dmlh_head)+
+ sizeof(struct list_head);
+
+ printf( "avi_start: frames = %d\n", frames );
+
+ lseek(fd, ofs, SEEK_SET);
+
+ nframes = 0;
+ totalsize = 0;
+
+ sizes = (unsigned int*) calloc( sizeof(unsigned int), frames ); // hold size of each frame
+}
+
+// add a jpeg frame to an AVI file
+void avi_add(int fd, u8 *buf, int size)
+{
+ struct db_head db = {"00db", 0};
+
+ printf( "avi_add: nframes = %d, totalsize = %d, size = %d\n", nframes, totalsize, size );
+
+ // overwrite JFIF type with AVI1
+ buf[6]='A';
+ buf[7]='V';
+ buf[8]='I';
+ buf[9]='1';
+
+ while( size%4 ) size++; // align 0 modulo 4*/
+ db.size = size;
+
+ write( fd, &db, sizeof(db) );
+ write( fd, buf, size );
+
+ sizes[nframes] = size;
+
+ nframes++;
+ totalsize += size; // total frame size
+}
+
+// finish writing the AVI file - filling in the header
+void avi_end(int fd, int width, int height, int fps)
+{
+ struct idx1_head idx = {"idx1", 16*nframes };
+ struct db_head db = {"00db", 0};
+ struct riff_head rh = { "RIFF", 0, "AVI "};
+ struct list_head lh1 = {"LIST", 0, "hdrl"};
+ struct avi_head ah;
+ struct list_head lh2 = {"LIST", 0, "strl"};
+ struct stream_head sh;
+ struct frame_head fh;
+ struct list_head lh3 = {"LIST", 0, "odml" };
+ struct dmlh_head dh = {"dmlh", 4, nframes };
+ struct list_head lh4 = {"LIST", 0, "movi"};
+ int i;
+ unsigned int offset = 4;
+
+ printf( "avi_end: nframes = %d, fps = %d\n", nframes, fps );
+
+ // write index
+
+ write(fd, &idx, sizeof(idx));
+
+ for ( i = 0; i < nframes; i++ )
+ {
+ write(fd, &db, 4 ); // only need the 00db
+ fprint_quartet( fd, 18 ); // ???
+ fprint_quartet( fd, offset );
+ fprint_quartet( fd, sizes[i] );
+ offset += sizes[i] + 8; //+8 (for the additional header)
+ }
+
+ free( sizes );
+
+ bzero( &ah, sizeof(ah) );
+ strcpy(ah.avih, "avih");
+ ah.time = 1000000 / fps;
+ ah.maxbytespersec = 1000000.0*(totalsize/nframes)/ah.time;
+ ah.nframes = nframes;
+ ah.numstreams = 1;
+ ah.flags = AVIF_HASINDEX;
+ ah.width = width;
+ ah.height = height;
+
+ bzero(&sh, sizeof(sh));
+ strcpy(sh.strh, "strh");
+ strcpy(sh.vids, "vids");
+ strcpy(sh.codec, "MJPG");
+ sh.scale = ah.time;
+ sh.rate = 1000000;
+ sh.length = nframes;
+
+ bzero(&fh, sizeof(fh));
+ strcpy(fh.strf, "strf");
+ fh.width = width;
+ fh.height = height;
+ fh.planes = 1;
+ fh.bitcount = 24;
+ strcpy(fh.codec,"MJPG");
+ fh.unpackedsize = 3*width*height;
+
+ rh.size = sizeof(lh1)+sizeof(ah)+sizeof(lh2)+sizeof(sh)+
+ sizeof(fh)+sizeof(lh3)+sizeof(dh)+sizeof(lh4)+
+ nframes*sizeof(struct db_head)+
+ totalsize + sizeof(struct idx1_head)+ (16*nframes) +4; // FIXME:16 bytes per nframe // the '4' - what for???
+
+ lh1.size = 4+sizeof(ah)+sizeof(lh2)+sizeof(sh)+sizeof(fh)+sizeof(lh3)+sizeof(dh);
+ ah.size = sizeof(ah)-8;
+ lh2.size = 4+sizeof(sh)+sizeof(fh)+sizeof(lh3)+sizeof(dh); //4+sizeof(sh)+sizeof(fh);
+ sh.size = sizeof(sh)-8;
+ fh.size = sizeof(fh)-8;
+ fh.size2 = fh.size;
+ lh3.size = 4+sizeof(dh);
+ lh4.size = 4+ nframes*sizeof(struct db_head)+ totalsize;
+
+ lseek(fd, 0, SEEK_SET);
+
+ write(fd, &rh, sizeof(rh));
+ write(fd, &lh1, sizeof(lh1));
+ write(fd, &ah, sizeof(ah));
+ write(fd, &lh2, sizeof(lh2));
+ write(fd, &sh, sizeof(sh));
+ write(fd, &fh, sizeof(fh));
+ write(fd, &lh3, sizeof(lh3));
+ write(fd, &dh, sizeof(dh));
+ write(fd, &lh4, sizeof(lh4));
+}
+
+
+/* NOTE: This is not a general purpose routine - it is meant to only
+ cope with AVIs saved using the other functions in this file
+void avi_explode(char *fname)
+{
+ struct riff_head rh;
+ struct list_head lh1;
+ struct avi_head ah;
+ struct list_head lh2;
+ struct stream_head sh;
+ struct frame_head fh;
+ struct list_head lh3;
+ int hsize, qsize;
+ u16 *htables = jpeg_huffman_tables(&hsize);
+ u16 *qtables = jpeg_quantisation_tables(&qsize, image_quality);
+ int fd, i;
+
+ fd = open(fname,O_RDONLY);
+ if (fd == -1) {
+ perror(fname);
+ return;
+ }
+
+ read(fd, &rh, sizeof(rh));
+ read(fd, &lh1, sizeof(lh1));
+ read(fd, &ah, sizeof(ah));
+ read(fd, &lh2, sizeof(lh2));
+ read(fd, &sh, sizeof(sh));
+ read(fd, &fh, sizeof(fh));
+ read(fd, &lh3, sizeof(lh3));
+
+ for (i=0; ; i++) {
+ u8 buf[500*1024];
+ struct db_head db;
+ char fname[100];
+ int fd2;
+
+ if (read(fd, &db, sizeof(db)) != sizeof(db) ||
+ read(fd, buf, db.size) != db.size) break;
+
+ snprintf(fname, sizeof(fname)-1,"frame.%d", i);
+
+ fd2 = open(fname,O_WRONLY|O_CREAT, 0644);
+ if (fd2 == -1) {
+ perror(fname);
+ continue;
+ }
+ write(fd2, buf, 2);
+ write(fd2, qtables, qsize);
+ write(fd2, htables, hsize);
+ write(fd2, buf+2, db.size-2);
+ close(fd2);
+ }
+ close(fd);
+ printf("exploded %d frames\n", i);
+}
+
+*/
+
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 @@
+/**********************************************************************
+** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved.
+** Based on work from Andrew Tridgell and the jpegtoavi project
+**
+** This file is part of Opie Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+**********************************************************************/
+
+#ifndef AVI_H
+#define AVI_H
+
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef unsigned char u8;
+typedef unsigned short u16;
+typedef unsigned u32;
+
+// header flags
+
+const u32 AVIF_HASINDEX=0x00000010; /* index at end of file */
+const u32 AVIF_MUSTUSEINDEX=0x00000020;
+const u32 AVIF_ISINTERLEAVED=0x00000100;
+const u32 AVIF_TRUSTCKTYPE=0x00000800;
+const u32 AVIF_WASCAPTUREFILE=0x00010000;
+const u32 AVIF_COPYRIGHTED=0x00020000;
+
+// function prototypes
+
+void avi_start(int fd, int frame);
+void avi_add(int fd, u8 *buf, int size);
+void avi_end(int fd, int width, int height, int fps);
+void fprint_quartet(int fd, unsigned int i);
+
+// the following structures are ordered as they appear in a typical AVI
+
+struct riff_head {
+ char riff[4]; // chunk type = "RIFF"
+ u32 size; // chunk size
+ char avistr[4]; // avi magic = "AVI "
+};
+
+// the avih chunk contains a number of list chunks
+
+struct avi_head {
+ char avih[4]; // chunk type = "avih"
+ u32 size; // chunk size
+ u32 time; // microsec per frame == 1e6 / fps
+ u32 maxbytespersec; // = 1e6*(total size/frames)/per_usec)
+ u32 pad; // pad = 0
+ u32 flags; // e.g. AVIF_HASINDEX
+ u32 nframes; // total number of frames
+ u32 initialframes; // = 0
+ u32 numstreams; // = 1 for now (later = 2 because of audio)
+ u32 suggested_bufsize; // = 0 (no suggestion)
+ u32 width; // width
+ u32 height; // height
+ u32 reserved[4]; // reserved for future use = 0
+};
+
+
+// the LIST chunk contains a number (==#numstreams) of stream chunks
+
+struct list_head {
+ char list[4]; // chunk type = "LIST"
+ u32 size;
+ char type[4];
+};
+
+
+struct dmlh_head {
+ char dmlh[4]; // chunk type dmlh
+ u32 size; // 4
+ u32 nframes; // number of frames
+};
+
+
+struct stream_head {
+ char strh[4]; // chunk type = "strh"
+ u32 size; // chunk size
+ char vids[4]; // stream type = "vids"
+ char codec[4]; // codec name (for us, = "MJPG")
+ u32 flags; // contains AVIT_F* flags
+ u16 priority; // = 0
+ u16 language; // = 0
+ u32 initialframes; // = 0
+ u32 scale; // = usec per frame
+ u32 rate; // 1e6
+ u32 start; // = 0
+ u32 length; // number of frames
+ u32 suggested_bufsize; // = 0
+ u32 quality; // = 0 ?
+ u32 samplesize; // = 0 ?
+};
+
+
+struct db_head {
+ char db[4]; // "00db"
+ u32 size;
+};
+
+// a frame chunk contains one JPEG image
+
+struct frame_head {
+ char strf[4]; // chunk type = "strf"
+ u32 size; // sizeof chunk (big endian) ?
+ u32 size2; // sizeof chunk (little endian) ?
+ u32 width;
+ u32 height;
+ u16 planes; // 1 bitplane
+ u16 bitcount; // 24 bpl
+ char codec[4]; // MJPG (for us)
+ u32 unpackedsize; // = 3*w*h
+ u32 r1; // reserved
+ u32 r2; // reserved
+ u32 clr_used; // reserved
+ u32 clr_important; // reserved
+};
+
+struct idx1_head {
+ char idx1[4]; // chunk type = "idx1"
+ u32 size; // chunk size
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#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 @@
+/**********************************************************************
+** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
+**
+** This file is part of Opie Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+**********************************************************************/
+
+#include "imageio.h"
+
+#include <opie2/odebug.h>
+#include <qimage.h>
+
+
+void bufferToImage( int _width, int _height, unsigned char* bp, QImage* image )
+{
+ unsigned char* p;
+
+ image->create( _width, _height, 16 );
+ for ( int i = 0; i < _height; ++i )
+ {
+ p = image->scanLine( i );
+ for ( int j = 0; j < _width; j++ )
+ {
+ *p = *bp;
+ p++;
+ bp++;
+ *p = *bp;
+ p++;
+ bp++;
+ }
+ }
+}
+
+
+void imageToFile( QImage* i, const QString& name, const QString& format, int quality )
+{
+ QImage im = i->convertDepth( 32 );
+ bool result = im.save( name, format, quality );
+ if ( !result )
+ {
+ oerr << "imageio-Problem while writing to " << name << oendl;
+ }
+ else
+ {
+ odebug << format << "-image has been successfully captured" << oendl;
+ }
+}
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 @@
+/**********************************************************************
+** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved.
+**
+** This file is part of Opie Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+**********************************************************************/
+
+#ifndef IMAGEIO_H
+#define IMAGEIO_H
+
+#include <qstring.h>
+
+class QImage;
+
+void bufferToImage( int _width, int height, unsigned char* bp, QImage* image );
+void imageToFile( QImage* i, const QString& name, const QString& format, int quality );
+
+#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 @@
+/**********************************************************************
+** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
+**
+** This file is part of Opie Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+**********************************************************************/
+
+#include "zcameraio.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#include <qimage.h>
+#include <qdatetime.h>
+
+#include <opie2/odebug.h>
+
+#define SHARPZDC "/dev/sharp_zdc"
+
+ZCameraIO* ZCameraIO::_instance = 0;
+
+ZCameraIO* ZCameraIO::instance()
+{
+ if ( !ZCameraIO::_instance )
+ {
+ odebug << "Creating ZCameraIO::_instance" << oendl;
+ ZCameraIO::_instance = new ZCameraIO();
+ }
+ return ZCameraIO::_instance;
+}
+
+
+ZCameraIO::ZCameraIO()
+ : _pressed( false ), _height( 0 ), _width( 0 ), _zoom( 0 ),
+ _flip( -1 ), _rot( 0 ), _readlen( 0 )
+
+{
+ _driver = ::open( SHARPZDC, O_RDWR );
+ if ( _driver == -1 )
+ oerr << "Can't open camera driver: " << strerror(errno) << oendl;
+ else
+ init();
+}
+
+
+void ZCameraIO::init()
+{
+ if ( ZCameraIO::_instance )
+ ofatal << "Don't create more than one ZCameraIO instances." << oendl;
+ else
+ {
+ _timer = new QTime();
+ setReadMode( STATUS );
+ }
+}
+
+
+ZCameraIO::~ZCameraIO()
+{
+ if ( _driver != -1 )
+ {
+ setReadMode( 0 );
+ ::close( _driver );
+ }
+}
+
+
+bool ZCameraIO::isOpen() const
+{
+ return _driver != -1;
+}
+
+
+bool ZCameraIO::isShutterPressed()
+{
+ if ( _status[0] == 'S' )
+ {
+ if ( !_pressed ) // wasn't pressed before, but is now!
+ {
+ _pressed = true;
+ _timer->start();
+ return true;
+ }
+
+ if ( _timer->elapsed() > 2000 ) // the press is pretty old now
+ {
+ clearShutterLatch();
+ _status[0] = 's';
+ _pressed = false;
+ }
+ }
+
+ return false;
+}
+
+
+bool ZCameraIO::isFinderReversed() const
+{
+ return _status[1] == 'M';
+}
+
+
+bool ZCameraIO::isCapturing() const
+{
+ return _status[2] == 'C';
+}
+
+
+bool ZCameraIO::isAvailable() const
+{
+ return _status[3] == 'A';
+}
+
+
+bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot )
+{
+ odebug << "setCaptureFrame( " << width << ", " << height << ", " << zoom << ", " << rot << " )" << oendl;
+ char b[100];
+ sprintf( b, "%c=%d,%d,%d,%d", rot ? 'R':'S', width, height, zoom, width*2 );
+ if ( write( b ) )
+ {
+ _width = width;
+ _height = height;
+ _zoom = zoom;
+ _rot = rot;
+ _readlen = 2 * _width * _height; // camera is fixed @ 16 bits per pixel
+ return true;
+ }
+ return false;
+}
+
+
+bool ZCameraIO::setZoom( int zoom )
+{
+ return setCaptureFrame( _width, _height, zoom*256, _rot );
+}
+
+
+void ZCameraIO::setReadMode( int mode )
+{
+ char b[10];
+ sprintf( b, "M=%d", mode );
+ write( b, mode <= 9 ? 3 : 4 );
+ if ( mode & STATUS ) // STATUS bit is set
+ {
+ read( _status, 4 );
+ if ( isShutterPressed() )
+ {
+ emit shutterClicked();
+ }
+ }
+}
+
+
+void ZCameraIO::setFlip( int flip )
+{
+ _flip = flip;
+}
+
+
+void ZCameraIO::clearShutterLatch()
+{
+ write( "B", 1 );
+}
+
+
+bool ZCameraIO::read( char* b, int len )
+{
+ #ifndef NO_TIMING
+ QTime t;
+ t.start();
+ #endif
+ int rlen = ::read( _driver, b, len );
+ #ifndef NO_TIMING
+ int time = t.elapsed();
+ #else
+ int time = -1;
+ #endif
+ if ( rlen )
+ odebug << "read " << rlen << " ('" << b[0] << b[1] << b[2] << b[3] << "') [" << time << " ms] from driver." << oendl;
+ else
+ odebug << "read nothing from driver." << oendl;
+ return rlen == len;
+}
+
+
+bool ZCameraIO::write( char* buf, int len )
+{
+ if ( !len )
+ len = strlen( buf );
+
+ odebug << "writing '" << buf << "' to driver." << oendl;
+
+ return ::write( _driver, buf, len ) == len;
+}
+
+
+bool ZCameraIO::snapshot( QImage* image )
+{
+ setReadMode( STATUS );
+
+ odebug << "finder reversed = " << isFinderReversed() << oendl;
+ odebug << "rotation = " << _rot << oendl;
+
+ int readmode;
+ if ( _flip == -1 ) // AUTO
+ {
+ if ( _rot ) // Portrait
+ {
+ readmode = IMAGE | isFinderReversed() ? XFLIP | YFLIP : 0;
+ }
+ else // Landscape
+ {
+ readmode = IMAGE | XFLIP | YFLIP;
+ }
+ }
+ else // OVERRIDE
+ {
+ readmode = IMAGE | _flip;
+ }
+
+ setReadMode( readmode );
+
+ char buf[_readlen];
+ char* bp = buf;
+ unsigned char* p;
+
+ read( bp, _readlen );
+
+ image->create( _width, _height, 16 );
+ for ( int i = 0; i < _height; ++i )
+ {
+ p = image->scanLine( i );
+ for ( int j = 0; j < _width; j++ )
+ {
+ *p = *bp;
+ p++;
+ bp++;
+ *p = *bp;
+ p++;
+ bp++;
+ }
+ }
+
+ return true;
+}
+
+
+bool ZCameraIO::snapshot( unsigned char* buf )
+{
+ setReadMode( STATUS );
+
+ odebug << "finder reversed = " << isFinderReversed() << oendl;
+ odebug << "rotation = " << _rot << oendl;
+
+ int readmode;
+ if ( _flip == -1 ) // AUTO
+ {
+ if ( _rot ) // Portrait
+ {
+ readmode = IMAGE | isFinderReversed() ? XFLIP | YFLIP : 0;
+ }
+ else // Landscape
+ {
+ readmode = IMAGE | XFLIP | YFLIP;
+ }
+ }
+ else // OVERRIDE
+ {
+ readmode = IMAGE | _flip;
+ }
+
+ setReadMode( readmode );
+ read( (char*) buf, _readlen );
+
+}
+
+
+void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image )
+{
+ int pw = _width;
+ int ph = _height;
+ setCaptureFrame( w, h, zoom*256, _rot );
+ snapshot( image );
+ setCaptureFrame( pw, ph, _zoom, _rot );
+}
+
+
+void ZCameraIO::captureFrame( int w, int h, int zoom, unsigned char* buf )
+{
+ //FIXME: this is too slow
+ int pw = _width;
+ int ph = _height;
+ setCaptureFrame( w, h, zoom*256, _rot );
+ snapshot( buf );
+ setCaptureFrame( pw, ph, _zoom, _rot );
+}
+
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 @@
+/**********************************************************************
+** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved.
+**
+** This file is part of Opie Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+**********************************************************************/
+
+#ifndef ZCAMERAIO_H
+#define ZCAMERAIO_H
+
+#include <qobject.h>
+
+class QImage;
+class QTime;
+
+class ZCameraIO : public QObject
+{
+ Q_OBJECT
+
+ public:
+ virtual ~ZCameraIO();
+
+ enum ReadMode
+ {
+ IMAGE = 0, STATUS = 1,
+ FASTER = 0, BETTER = 2,
+ XNOFLIP = 0, XFLIP = 4,
+ YNOFLIP = 0, YFLIP = 8,
+ AUTOMATICFLIP = -1
+ };
+
+ // low level interface
+
+ bool setCaptureFrame( int w, int h, int zoom = 256, bool rot = true );
+ bool setZoom( int zoom = 0 );
+ void setReadMode( int = IMAGE | XFLIP | YFLIP );
+ void setFlip( int flip );
+
+ bool isShutterPressed(); // not const, because it calls clearShutterLatch
+ bool isAvailable() const;
+ bool isCapturing() const;
+ bool isFinderReversed() const;
+
+ bool snapshot( QImage* image );
+ bool snapshot( unsigned char* buf );
+
+ // high level interface
+ bool isOpen() const;
+ static ZCameraIO* instance();
+ void captureFrame( int w, int h, int zoom, QImage* image );
+ void captureFrame( int w, int h, int zoom, unsigned char* buf );
+
+ protected:
+ ZCameraIO();
+ void clearShutterLatch();
+ void init();
+ bool read( char*, int );
+ bool write( char*, int = 0 );
+
+ signals:
+ void shutterClicked();
+
+ private:
+ int _driver;
+ char _status[4];
+ bool _pressed;
+ static ZCameraIO* _instance;
+ int _height;
+ int _width;
+ int _zoom;
+ int _flip;
+ bool _rot;
+ int _readlen;
+
+ QTime* _timer;
+};
+
+#endif