summaryrefslogtreecommitdiff
path: root/noncore/multimedia/camera/cmd
authormickeyl <mickeyl>2003-05-11 22:40:20 (UTC)
committer mickeyl <mickeyl>2003-05-11 22:40:20 (UTC)
commitc0b6d29485dad8f39873def7cd890613f60a631b (patch) (unidiff)
tree5a8f0190ce739f3ba9af597537058818c643b434 /noncore/multimedia/camera/cmd
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 (limited to 'noncore/multimedia/camera/cmd') (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
3 files changed, 150 insertions, 61 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
@@ -15,2 +15,4 @@
15 15
16#include "capture.h"
17
16#include "zcameraio.h" 18#include "zcameraio.h"
@@ -19,27 +21,94 @@
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
@@ -51,4 +120,4 @@ void usage()
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" );
@@ -58,3 +127,4 @@ 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
@@ -66,6 +136,2 @@ int main( int argc, char** argv )
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
@@ -85,3 +151,3 @@ int main( int argc, char** argv )
85 { 151 {
86 name = argv[i]; 152 c->name = argv[i];
87 break; 153 break;
@@ -99,8 +165,8 @@ int main( int argc, char** argv )
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;
@@ -118,28 +184,6 @@ int main( int argc, char** argv )
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}
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
@@ -6,3 +6,3 @@ CONFIG = qt warn_on debug
6 6
7HEADERS = 7HEADERS = capture.h
8 8
@@ -12,3 +12,3 @@ INCLUDEPATH += $(OPIEDIR)/include ../lib
12DEPENDPATH += $(OPIEDIR)/include ../lib 12DEPENDPATH += $(OPIEDIR)/include ../lib
13LIBS += -lqpe -lopiecore2 -lopiecam 13LIBS += -lopiecore2 -lopiecam
14INTERFACES = 14INTERFACES =