author | mickeyl <mickeyl> | 2003-05-11 22:40:20 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-05-11 22:40:20 (UTC) |
commit | c0b6d29485dad8f39873def7cd890613f60a631b (patch) (unidiff) | |
tree | 5a8f0190ce739f3ba9af597537058818c643b434 /noncore/multimedia/camera/cmd/capture.cpp | |
parent | 10de2c93dffa16f6d2f1cf72fa20008757c5ef3a (diff) | |
download | opie-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 (limited to 'noncore/multimedia/camera/cmd/capture.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/multimedia/camera/cmd/capture.cpp | 162 |
1 files changed, 103 insertions, 59 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> | ||
26 | |||
27 | Capturer::Capturer() | ||
28 | :QFrame( 0 ), height( 320 ), width( 240 ), zoom( 1 ), quality( 90 ), | ||
29 | flip( "A" ), format( "JPEG" ), name( "Untitled" ) | ||
30 | { | ||
31 | } | ||
32 | |||
33 | |||
34 | Capturer::~Capturer() | ||
35 | { | ||
36 | } | ||
37 | |||
38 | |||
39 | void Capturer::checkSettings() | ||
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 | } | ||
23 | 79 | ||
24 | #include <assert.h> | 80 | if ( format != "JPEG" && format != "PNG" && format != "BMP" ) |
25 | #include <sys/types.h> | 81 | { |
26 | #include <sys/stat.h> | 82 | printf( "Warning: Corrected format to 'JPEG'\n" ); |
27 | #include <fcntl.h> | 83 | format = "JPEG"; |
28 | #include <string.h> | 84 | } |
29 | #include <errno.h> | 85 | } |
30 | #include <unistd.h> | ||
31 | #include <stdio.h> | ||
32 | 86 | ||
33 | #define CAPTUREFILE "/tmp/capture.dat" | ||
34 | #define OUTPUTFILE "/tmp/output.avi" | ||
35 | 87 | ||
36 | int captureX = 240; | 88 | void Capturer::capture() |
37 | int captureY = 320; | 89 | { |
38 | int quality = 75; | 90 | if ( flip == "A" ) |
39 | QString flip = "A"; | 91 | ZCameraIO::instance()->setFlip( ZCameraIO::AUTOMATICFLIP ); |
40 | int zoom = 1; | 92 | else if ( flip == "0" ) |
41 | QString format = "JPG"; | 93 | ZCameraIO::instance()->setFlip( ZCameraIO::XNOFLIP | ZCameraIO::YNOFLIP ); |
42 | QString name; | 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 | ||
44 | int performCapture(); | ||
45 | 114 | ||
46 | void usage() | 115 | void 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 | ||
57 | int main( int argc, char** argv ) | 126 | int 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 | |||
123 | int performCapture() | ||
124 | { | ||
125 | printf( "Capturing %dx%d Image [%s] q%d z%d --> %s\n", captureX, | ||
126 | captureY, | ||
127 | (const char*) format, | ||
128 | quality, | ||
129 | zoom, | ||
130 | (const char*) name ); | ||
131 | 185 | ||
132 | QImage i; | 186 | c->checkSettings(); |
133 | ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, &i ); | 187 | c->capture(); |
134 | QImage im = i.convertDepth( 32 ); | 188 | return 0; |
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 | ||