summaryrefslogtreecommitdiff
Unidiff
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
@@ -13,35 +13,104 @@
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{
@@ -49,14 +118,15 @@ void usage()
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 {
@@ -64,10 +134,6 @@ int main( int argc, char** argv )
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;
@@ -83,7 +149,7 @@ int main( int argc, char** argv )
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 }
@@ -97,12 +163,12 @@ int main( int argc, char** argv )
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++;
@@ -116,31 +182,9 @@ int main( int argc, char** argv )
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
@@ -4,13 +4,13 @@ DESTDIR = $(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
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
@@ -139,6 +139,7 @@ bool ZCameraIO::setCaptureFrame( int width, int height, int zoom, bool 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
@@ -215,6 +216,8 @@ bool ZCameraIO::snapshot( QImage* image )
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 {
@@ -291,11 +294,12 @@ bool ZCameraIO::snapshot( unsigned char* buf )
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