summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-05-11 22:40:20 (UTC)
committer mickeyl <mickeyl>2003-05-11 22:40:20 (UTC)
commitc0b6d29485dad8f39873def7cd890613f60a631b (patch) (unidiff)
tree5a8f0190ce739f3ba9af597537058818c643b434
parent10de2c93dffa16f6d2f1cf72fa20008757c5ef3a (diff)
downloadopie-c0b6d29485dad8f39873def7cd890613f60a631b.zip
opie-c0b6d29485dad8f39873def7cd890613f60a631b.tar.gz
opie-c0b6d29485dad8f39873def7cd890613f60a631b.tar.bz2
command line capturer now seems to work
you can now write yourself a nice webcam application :)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/camera/cmd/capture.cpp162
-rw-r--r--noncore/multimedia/camera/cmd/capture.h45
-rw-r--r--noncore/multimedia/camera/cmd/cmd.pro4
-rw-r--r--noncore/multimedia/camera/lib/zcameraio.cpp8
4 files changed, 156 insertions, 63 deletions
diff --git a/noncore/multimedia/camera/cmd/capture.cpp b/noncore/multimedia/camera/cmd/capture.cpp
index 7960bbb..64c223c 100644
--- a/noncore/multimedia/camera/cmd/capture.cpp
+++ b/noncore/multimedia/camera/cmd/capture.cpp
@@ -1,146 +1,190 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
4** This file is part of Opie Environment. 4** This file is part of Opie Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 "capture.h"
17
16#include "zcameraio.h" 18#include "zcameraio.h"
17#include "imageio.h" 19#include "imageio.h"
18#include "avi.h" 20#include "avi.h"
19 21
20#include <qfile.h>
21#include <qimage.h>
22#include <opie2/oapplication.h> 22#include <opie2/oapplication.h>
23#include <opie2/odebug.h>
24
25#include <qimage.h>
23 26
24#include <assert.h> 27Capturer::Capturer()
25#include <sys/types.h> 28 :QFrame( 0 ), height( 320 ), width( 240 ), zoom( 1 ), quality( 90 ),
26#include <sys/stat.h> 29 flip( "A" ), format( "JPEG" ), name( "Untitled" )
27#include <fcntl.h> 30{
28#include <string.h> 31}
29#include <errno.h>
30#include <unistd.h>
31#include <stdio.h>
32 32
33#define CAPTUREFILE "/tmp/capture.dat"
34#define OUTPUTFILE "/tmp/output.avi"
35 33
36int captureX = 240; 34Capturer::~Capturer()
37int captureY = 320; 35{
38int quality = 75; 36}
39QString flip = "A"; 37
40int zoom = 1; 38
41QString format = "JPG"; 39void Capturer::checkSettings()
42QString name; 40{
41 if ( width > height )
42 {
43 if ( 0 != width % 16 || width < 16 || width > 640 )
44 {
45 printf( "Warning: Corrected X resolution to 320 px\n" );
46 width = 320;
47 }
48 if ( 0 != height % 16 || height < 16 || height > 480 )
49 {
50 printf( "Warning: Corrected Y resolution to 240 px\n" );
51 height = 240;
52 }
53 }
54 else
55 {
56 if ( 0 != width % 16 || width < 16 || width > 480 )
57 {
58 printf( "Warning: Corrected X resolution to 240 px\n" );
59 width = 240;
60 }
61 if ( 0 != height % 16 || height < 16 || height > 640 )
62 {
63 printf( "Warning: Corrected Y resolution to 320 px\n" );
64 height = 320;
65 }
66 }
67
68 if ( quality > 100 || quality < 10 )
69 {
70 printf( "Warning: Corrected quality to 75%%\n" );
71 quality = 75;
72 }
73
74 if ( zoom > 2 || zoom < 1 )
75 {
76 printf( "Warning: Corrected zoom to x1\n" );
77 zoom = 1;
78 }
79
80 if ( format != "JPEG" && format != "PNG" && format != "BMP" )
81 {
82 printf( "Warning: Corrected format to 'JPEG'\n" );
83 format = "JPEG";
84 }
85}
86
87
88void Capturer::capture()
89{
90 if ( flip == "A" )
91 ZCameraIO::instance()->setFlip( ZCameraIO::AUTOMATICFLIP );
92 else if ( flip == "0" )
93 ZCameraIO::instance()->setFlip( ZCameraIO::XNOFLIP | ZCameraIO::YNOFLIP );
94 else if ( flip == "X" )
95 ZCameraIO::instance()->setFlip( ZCameraIO::XFLIP );
96 else if ( flip == "Y" )
97 ZCameraIO::instance()->setFlip( ZCameraIO::YFLIP );
98 else if ( flip == "*" )
99 ZCameraIO::instance()->setFlip( ZCameraIO::XFLIP | ZCameraIO::YFLIP );
100
101 ZCameraIO::instance()->captureFrame( width, height, zoom, &image );
102 QImage im = image.convertDepth( 32 );
103 bool result = im.save( name, format, quality );
104 if ( !result )
105 {
106 printf( "QImageio-Problem while writing.\n" );
107 }
108 else
109 {
110 printf( "Ok.\n" );
111 }
112}
43 113
44int performCapture();
45 114
46void usage() 115void usage()
47{ 116{
48 printf( "Usage: ./capture [options] filename\n\n" ); 117 printf( "Usage: ./capture [options] filename\n\n" );
49 printf( " -x xresolution (dividable by 16) [default=240]\n" ); 118 printf( " -x xresolution (dividable by 16) [default=240]\n" );
50 printf( " -y xresolution (dividable by 16) [default=320]\n" ); 119 printf( " -y xresolution (dividable by 16) [default=320]\n" );
51 printf( " -q quality (10-100) [default=75]\n" ); 120 printf( " -q quality (10-100) [default=75]\n" );
52 printf( " -f flip (A=auto, X, Y, *=both) [default=Auto]\n" ); 121 printf( " -f flip (A=auto, 0, X, Y, *=both) [default=Auto]\n" );
53 printf( " -o output format (JPG,BMP,PNG) [default=JPG]\n" ); 122 printf( " -o output format (JPEG,BMP,PNG) [default=JPEG]\n" );
54 printf( " -z zoom (1-2) [default=1]\n" ); 123 printf( " -z zoom (1-2) [default=1]\n" );
55} 124}
56 125
57int main( int argc, char** argv ) 126int main( int argc, char** argv )
58{ 127{
59 OApplication* a = new OApplication( argc, argv, "opie-camera" ); 128 OApplication* a = new OApplication( argc, argv, "Capture" );
129 Capturer* c = new Capturer();
60 130
61 if ( argc < 2 ) 131 if ( argc < 2 )
62 { 132 {
63 usage(); 133 usage();
64 return -1; 134 return -1;
65 } 135 }
66 136
67 int captureX = 240;
68 int captureY = 320;
69 QString flip = "A";
70
71 #define I_HATE_WRITING_HARDCODED_PARSES 137 #define I_HATE_WRITING_HARDCODED_PARSES
72 138
73 int i = 1; 139 int i = 1;
74 while ( i < argc ) 140 while ( i < argc )
75 { 141 {
76 // check for filename 142 // check for filename
77 if ( argv[i][0] != '-' ) 143 if ( argv[i][0] != '-' )
78 { 144 {
79 if ( argc != i+1 ) 145 if ( argc != i+1 )
80 { 146 {
81 usage(); 147 usage();
82 return -1; 148 return -1;
83 } 149 }
84 else 150 else
85 { 151 {
86 name = argv[i]; 152 c->name = argv[i];
87 break; 153 break;
88 } 154 }
89 } 155 }
90 else 156 else
91 { 157 {
92 i++; 158 i++;
93 if ( argc == i ) 159 if ( argc == i )
94 { 160 {
95 usage(); 161 usage();
96 return -1; 162 return -1;
97 } 163 }
98 switch ( argv[i-1][1] ) 164 switch ( argv[i-1][1] )
99 { 165 {
100 case 'x': captureX = QString( argv[i] ).toInt(); break; 166 case 'x': c->width = QString( argv[i] ).toInt(); break;
101 case 'y': captureY = QString( argv[i] ).toInt(); break; 167 case 'y': c->height = QString( argv[i] ).toInt(); break;
102 case 'z': zoom = QString( argv[i] ).toInt(); break; 168 case 'z': c->zoom = QString( argv[i] ).toInt(); break;
103 case 'o': format = QString( argv[i] ); break; 169 case 'o': c->format = QString( argv[i] ); break;
104 case 'q': quality = QString( argv[i] ).toInt(); break; 170 case 'q': c->quality = QString( argv[i] ).toInt(); break;
105 case 'f': flip = QString( argv[i] )[0]; break; 171 case 'f': c->flip = QString( argv[i] )[0]; break;
106 default: usage(); return -1; 172 default: usage(); return -1;
107 } 173 }
108 i++; 174 i++;
109 } 175 }
110 176
111 #undef I_HATE_WRITING_HARDCODED_PARSES 177 #undef I_HATE_WRITING_HARDCODED_PARSES
112 } 178 }
113 179
114 if ( !ZCameraIO::instance()->isOpen() ) 180 if ( !ZCameraIO::instance()->isOpen() )
115 { 181 {
116 printf( "Error: Can't detect your camera. Exiting.\n" ); 182 printf( "Error: Can't detect your camera. Exiting.\n" );
117 return -1; 183 return -1;
118 } 184 }
119 return performCapture();
120}
121
122 185
123int performCapture() 186 c->checkSettings();
124{ 187 c->capture();
125 printf( "Capturing %dx%d Image [%s] q%d z%d --> %s\n", captureX, 188 return 0;
126 captureY,
127 (const char*) format,
128 quality,
129 zoom,
130 (const char*) name );
131
132 QImage i;
133 ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, &i );
134 QImage im = i.convertDepth( 32 );
135 bool result = im.save( name, format, quality );
136 if ( !result )
137 {
138 printf( "QImageio-Problem while writing.\n" );
139 return -1;
140 }
141 else
142 {
143 printf( "Ok.\n" );
144 }
145} 189}
146 190
diff --git a/noncore/multimedia/camera/cmd/capture.h b/noncore/multimedia/camera/cmd/capture.h
new file mode 100644
index 0000000..f23aca0
--- a/dev/null
+++ b/noncore/multimedia/camera/cmd/capture.h
@@ -0,0 +1,45 @@
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#include "zcameraio.h"
17#include "imageio.h"
18#include "avi.h"
19
20#include <qfile.h>
21#include <qframe.h>
22#include <qimage.h>
23
24class Capturer: public QFrame
25{
26 Q_OBJECT
27
28 public:
29 Capturer();
30 virtual ~Capturer();
31
32 int height;
33 int width;
34 int zoom;
35 int quality;
36 QString flip;
37 QString format;
38 QString name;
39 QImage image;
40
41 public slots:
42 void capture();
43 void checkSettings();
44};
45
diff --git a/noncore/multimedia/camera/cmd/cmd.pro b/noncore/multimedia/camera/cmd/cmd.pro
index 3b1aaa6..a5791f4 100644
--- a/noncore/multimedia/camera/cmd/cmd.pro
+++ b/noncore/multimedia/camera/cmd/cmd.pro
@@ -1,18 +1,18 @@
1MOC_DIR = ./moc 1MOC_DIR = ./moc
2OBJECTS_DIR = ./obj 2OBJECTS_DIR = ./obj
3DESTDIR = $(OPIEDIR)/bin 3DESTDIR = $(OPIEDIR)/bin
4TEMPLATE = app 4TEMPLATE = app
5CONFIG = qt warn_on debug 5CONFIG = qt warn_on debug
6 6
7HEADERS = 7HEADERS = capture.h
8 8
9SOURCES = capture.cpp 9SOURCES = capture.cpp
10 10
11INCLUDEPATH += $(OPIEDIR)/include ../lib 11INCLUDEPATH += $(OPIEDIR)/include ../lib
12DEPENDPATH += $(OPIEDIR)/include ../lib 12DEPENDPATH += $(OPIEDIR)/include ../lib
13LIBS += -lqpe -lopiecore2 -lopiecam 13LIBS += -lopiecore2 -lopiecam
14INTERFACES = 14INTERFACES =
15TARGET = capture 15TARGET = capture
16 16
17include ( $(OPIEDIR)/include.pro ) 17include ( $(OPIEDIR)/include.pro )
18 18
diff --git a/noncore/multimedia/camera/lib/zcameraio.cpp b/noncore/multimedia/camera/lib/zcameraio.cpp
index c940b45..d59cbbb 100644
--- a/noncore/multimedia/camera/lib/zcameraio.cpp
+++ b/noncore/multimedia/camera/lib/zcameraio.cpp
@@ -1,311 +1,315 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
4** This file is part of Opie Environment. 4** This file is part of Opie Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 "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#include <stdio.h>
25 25
26#include <qimage.h> 26#include <qimage.h>
27#include <qdatetime.h> 27#include <qdatetime.h>
28 28
29#include <opie2/odebug.h> 29#include <opie2/odebug.h>
30 30
31#define SHARPZDC "/dev/sharp_zdc" 31#define SHARPZDC "/dev/sharp_zdc"
32 32
33ZCameraIO* ZCameraIO::_instance = 0; 33ZCameraIO* ZCameraIO::_instance = 0;
34 34
35ZCameraIO* ZCameraIO::instance() 35ZCameraIO* ZCameraIO::instance()
36{ 36{
37 if ( !ZCameraIO::_instance ) 37 if ( !ZCameraIO::_instance )
38 { 38 {
39 odebug << "Creating ZCameraIO::_instance" << oendl; 39 odebug << "Creating ZCameraIO::_instance" << oendl;
40 ZCameraIO::_instance = new ZCameraIO(); 40 ZCameraIO::_instance = new ZCameraIO();
41 } 41 }
42 return ZCameraIO::_instance; 42 return ZCameraIO::_instance;
43} 43}
44 44
45 45
46ZCameraIO::ZCameraIO() 46ZCameraIO::ZCameraIO()
47 : _pressed( false ), _height( 0 ), _width( 0 ), _zoom( 0 ), 47 : _pressed( false ), _height( 0 ), _width( 0 ), _zoom( 0 ),
48 _flip( -1 ), _rot( 0 ), _readlen( 0 ) 48 _flip( -1 ), _rot( 0 ), _readlen( 0 )
49 49
50{ 50{
51 _driver = ::open( SHARPZDC, O_RDWR ); 51 _driver = ::open( SHARPZDC, O_RDWR );
52 if ( _driver == -1 ) 52 if ( _driver == -1 )
53 oerr << "Can't open camera driver: " << strerror(errno) << oendl; 53 oerr << "Can't open camera driver: " << strerror(errno) << oendl;
54 else 54 else
55 init(); 55 init();
56} 56}
57 57
58 58
59void ZCameraIO::init() 59void ZCameraIO::init()
60{ 60{
61 if ( ZCameraIO::_instance ) 61 if ( ZCameraIO::_instance )
62 ofatal << "Don't create more than one ZCameraIO instances." << oendl; 62 ofatal << "Don't create more than one ZCameraIO instances." << oendl;
63 else 63 else
64 { 64 {
65 _timer = new QTime(); 65 _timer = new QTime();
66 setReadMode( STATUS ); 66 setReadMode( STATUS );
67 } 67 }
68} 68}
69 69
70 70
71ZCameraIO::~ZCameraIO() 71ZCameraIO::~ZCameraIO()
72{ 72{
73 if ( _driver != -1 ) 73 if ( _driver != -1 )
74 { 74 {
75 setReadMode( 0 ); 75 setReadMode( 0 );
76 ::close( _driver ); 76 ::close( _driver );
77 } 77 }
78} 78}
79 79
80 80
81bool ZCameraIO::isOpen() const 81bool ZCameraIO::isOpen() const
82{ 82{
83 return _driver != -1; 83 return _driver != -1;
84} 84}
85 85
86 86
87bool ZCameraIO::isShutterPressed() 87bool ZCameraIO::isShutterPressed()
88{ 88{
89 if ( _status[0] == 'S' ) 89 if ( _status[0] == 'S' )
90 { 90 {
91 if ( !_pressed ) // wasn't pressed before, but is now! 91 if ( !_pressed ) // wasn't pressed before, but is now!
92 { 92 {
93 _pressed = true; 93 _pressed = true;
94 _timer->start(); 94 _timer->start();
95 return true; 95 return true;
96 } 96 }
97 97
98 if ( _timer->elapsed() > 2000 ) // the press is pretty old now 98 if ( _timer->elapsed() > 2000 ) // the press is pretty old now
99 { 99 {
100 clearShutterLatch(); 100 clearShutterLatch();
101 _status[0] = 's'; 101 _status[0] = 's';
102 _pressed = false; 102 _pressed = false;
103 } 103 }
104 } 104 }
105 105
106 return false; 106 return false;
107} 107}
108 108
109 109
110bool ZCameraIO::isFinderReversed() const 110bool ZCameraIO::isFinderReversed() const
111{ 111{
112 return _status[1] == 'M'; 112 return _status[1] == 'M';
113} 113}
114 114
115 115
116bool ZCameraIO::isCapturing() const 116bool ZCameraIO::isCapturing() const
117{ 117{
118 return _status[2] == 'C'; 118 return _status[2] == 'C';
119} 119}
120 120
121 121
122bool ZCameraIO::isAvailable() const 122bool ZCameraIO::isAvailable() const
123{ 123{
124 return _status[3] == 'A'; 124 return _status[3] == 'A';
125} 125}
126 126
127 127
128bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot ) 128bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool rot )
129{ 129{
130 odebug << "setCaptureFrame( " << width << ", " << height << ", " << zoom << ", " << rot << " )" << oendl; 130 odebug << "setCaptureFrame( " << width << ", " << height << ", " << zoom << ", " << rot << " )" << oendl;
131 char b[100]; 131 char b[100];
132 sprintf( b, "%c=%d,%d,%d,%d", rot ? 'R':'S', width, height, zoom, width*2 ); 132 sprintf( b, "%c=%d,%d,%d,%d", rot ? 'R':'S', width, height, zoom, width*2 );
133 if ( write( b ) ) 133 if ( write( b ) )
134 { 134 {
135 _width = width; 135 _width = width;
136 _height = height; 136 _height = height;
137 _zoom = zoom; 137 _zoom = zoom;
138 _rot = rot; 138 _rot = rot;
139 _readlen = 2 * _width * _height; // camera is fixed @ 16 bits per pixel 139 _readlen = 2 * _width * _height; // camera is fixed @ 16 bits per pixel
140 return true; 140 return true;
141 } 141 }
142 owarn << "couldn't write to driver" << oendl;
142 return false; 143 return false;
143} 144}
144 145
145 146
146bool ZCameraIO::setZoom( int zoom ) 147bool ZCameraIO::setZoom( int zoom )
147{ 148{
148 return setCaptureFrame( _width, _height, zoom*256, _rot ); 149 return setCaptureFrame( _width, _height, zoom*256, _rot );
149} 150}
150 151
151 152
152void ZCameraIO::setReadMode( int mode ) 153void ZCameraIO::setReadMode( int mode )
153{ 154{
154 char b[10]; 155 char b[10];
155 sprintf( b, "M=%d", mode ); 156 sprintf( b, "M=%d", mode );
156 write( b, mode <= 9 ? 3 : 4 ); 157 write( b, mode <= 9 ? 3 : 4 );
157 if ( mode & STATUS ) // STATUS bit is set 158 if ( mode & STATUS ) // STATUS bit is set
158 { 159 {
159 read( _status, 4 ); 160 read( _status, 4 );
160 if ( isShutterPressed() ) 161 if ( isShutterPressed() )
161 { 162 {
162 emit shutterClicked(); 163 emit shutterClicked();
163 } 164 }
164 } 165 }
165} 166}
166 167
167 168
168void ZCameraIO::setFlip( int flip ) 169void ZCameraIO::setFlip( int flip )
169{ 170{
170 _flip = flip; 171 _flip = flip;
171} 172}
172 173
173 174
174void ZCameraIO::clearShutterLatch() 175void ZCameraIO::clearShutterLatch()
175{ 176{
176 write( "B", 1 ); 177 write( "B", 1 );
177} 178}
178 179
179 180
180bool ZCameraIO::read( char* b, int len ) 181bool ZCameraIO::read( char* b, int len )
181{ 182{
182 #ifndef NO_TIMING 183 #ifndef NO_TIMING
183 QTime t; 184 QTime t;
184 t.start(); 185 t.start();
185 #endif 186 #endif
186 int rlen = ::read( _driver, b, len ); 187 int rlen = ::read( _driver, b, len );
187 #ifndef NO_TIMING 188 #ifndef NO_TIMING
188 int time = t.elapsed(); 189 int time = t.elapsed();
189 #else 190 #else
190 int time = -1; 191 int time = -1;
191 #endif 192 #endif
192 if ( rlen ) 193 if ( rlen )
193 odebug << "read " << rlen << " ('" << b[0] << b[1] << b[2] << b[3] << "') [" << time << " ms] from driver." << oendl; 194 odebug << "read " << rlen << " ('" << b[0] << b[1] << b[2] << b[3] << "') [" << time << " ms] from driver." << oendl;
194 else 195 else
195 odebug << "read nothing from driver." << oendl; 196 odebug << "read nothing from driver." << oendl;
196 return rlen == len; 197 return rlen == len;
197} 198}
198 199
199 200
200bool ZCameraIO::write( char* buf, int len ) 201bool ZCameraIO::write( char* buf, int len )
201{ 202{
202 if ( !len ) 203 if ( !len )
203 len = strlen( buf ); 204 len = strlen( buf );
204 205
205 odebug << "writing '" << buf << "' to driver." << oendl; 206 odebug << "writing '" << buf << "' to driver." << oendl;
206 207
207 return ::write( _driver, buf, len ) == len; 208 return ::write( _driver, buf, len ) == len;
208} 209}
209 210
210 211
211bool ZCameraIO::snapshot( QImage* image ) 212bool ZCameraIO::snapshot( QImage* image )
212{ 213{
213 setReadMode( STATUS ); 214 setReadMode( STATUS );
214 215
215 odebug << "finder reversed = " << isFinderReversed() << oendl; 216 odebug << "finder reversed = " << isFinderReversed() << oendl;
216 odebug << "rotation = " << _rot << oendl; 217 odebug << "rotation = " << _rot << oendl;
217 218
219 odebug << "w=" << _width << " h= " << _height << " readlen= " << _readlen << oendl;
220
218 int readmode; 221 int readmode;
219 if ( _flip == -1 ) // AUTO 222 if ( _flip == -1 ) // AUTO
220 { 223 {
221 if ( _rot ) // Portrait 224 if ( _rot ) // Portrait
222 { 225 {
223 readmode = IMAGE | isFinderReversed() ? XFLIP | YFLIP : 0; 226 readmode = IMAGE | isFinderReversed() ? XFLIP | YFLIP : 0;
224 } 227 }
225 else // Landscape 228 else // Landscape
226 { 229 {
227 readmode = IMAGE | XFLIP | YFLIP; 230 readmode = IMAGE | XFLIP | YFLIP;
228 } 231 }
229 } 232 }
230 else // OVERRIDE 233 else // OVERRIDE
231 { 234 {
232 readmode = IMAGE | _flip; 235 readmode = IMAGE | _flip;
233 } 236 }
234 237
235 setReadMode( readmode ); 238 setReadMode( readmode );
236 239
237 char buf[_readlen]; 240 char buf[_readlen];
238 char* bp = buf; 241 char* bp = buf;
239 unsigned char* p; 242 unsigned char* p;
240 243
241 read( bp, _readlen ); 244 read( bp, _readlen );
242 245
243 image->create( _width, _height, 16 ); 246 image->create( _width, _height, 16 );
244 for ( int i = 0; i < _height; ++i ) 247 for ( int i = 0; i < _height; ++i )
245 { 248 {
246 p = image->scanLine( i ); 249 p = image->scanLine( i );
247 for ( int j = 0; j < _width; j++ ) 250 for ( int j = 0; j < _width; j++ )
248 { 251 {
249 *p = *bp; 252 *p = *bp;
250 p++; 253 p++;
251 bp++; 254 bp++;
252 *p = *bp; 255 *p = *bp;
253 p++; 256 p++;
254 bp++; 257 bp++;
255 } 258 }
256 } 259 }
257 260
258 return true; 261 return true;
259} 262}
260 263
261 264
262bool ZCameraIO::snapshot( unsigned char* buf ) 265bool ZCameraIO::snapshot( unsigned char* buf )
263{ 266{
264 setReadMode( STATUS ); 267 setReadMode( STATUS );
265 268
266 odebug << "finder reversed = " << isFinderReversed() << oendl; 269 odebug << "finder reversed = " << isFinderReversed() << oendl;
267 odebug << "rotation = " << _rot << oendl; 270 odebug << "rotation = " << _rot << oendl;
268 271
269 int readmode; 272 int readmode;
270 if ( _flip == -1 ) // AUTO 273 if ( _flip == -1 ) // AUTO
271 { 274 {
272 if ( _rot ) // Portrait 275 if ( _rot ) // Portrait
273 { 276 {
274 readmode = IMAGE | isFinderReversed() ? XFLIP | YFLIP : 0; 277 readmode = IMAGE | isFinderReversed() ? XFLIP | YFLIP : 0;
275 } 278 }
276 else // Landscape 279 else // Landscape
277 { 280 {
278 readmode = IMAGE | XFLIP | YFLIP; 281 readmode = IMAGE | XFLIP | YFLIP;
279 } 282 }
280 } 283 }
281 else // OVERRIDE 284 else // OVERRIDE
282 { 285 {
283 readmode = IMAGE | _flip; 286 readmode = IMAGE | _flip;
284 } 287 }
285 288
286 setReadMode( readmode ); 289 setReadMode( readmode );
287 read( (char*) buf, _readlen ); 290 read( (char*) buf, _readlen );
288 291
289} 292}
290 293
291 294
292void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image ) 295void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image )
293{ 296{
297 int prot = _rot;
294 int pw = _width; 298 int pw = _width;
295 int ph = _height; 299 int ph = _height;
296 setCaptureFrame( w, h, zoom*256, _rot ); 300 setCaptureFrame( w, h, zoom*256, w<h );
297 snapshot( image ); 301 snapshot( image );
298 setCaptureFrame( pw, ph, _zoom, _rot ); 302 setCaptureFrame( pw, ph, _zoom, prot );
299} 303}
300 304
301 305
302void ZCameraIO::captureFrame( int w, int h, int zoom, unsigned char* buf ) 306void ZCameraIO::captureFrame( int w, int h, int zoom, unsigned char* buf )
303{ 307{
304 //FIXME: this is too slow 308 //FIXME: this is too slow
305 int pw = _width; 309 int pw = _width;
306 int ph = _height; 310 int ph = _height;
307 setCaptureFrame( w, h, zoom*256, _rot ); 311 setCaptureFrame( w, h, zoom*256, _rot );
308 snapshot( buf ); 312 snapshot( buf );
309 setCaptureFrame( pw, ph, _zoom, _rot ); 313 setCaptureFrame( pw, ph, _zoom, _rot );
310} 314}
311 315