author | mickeyl <mickeyl> | 2003-04-20 17:36:20 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-20 17:36:20 (UTC) |
commit | 606f5d9cd2ecba4df175bc722621e4e4df3bc516 (patch) (unidiff) | |
tree | f9da7a8bdbac0e576014fc1ca7fa5f6a2066b67a | |
parent | c02c43c91251e8d71048b27855fc1900e430272d (diff) | |
download | opie-606f5d9cd2ecba4df175bc722621e4e4df3bc516.zip opie-606f5d9cd2ecba4df175bc722621e4e4df3bc516.tar.gz opie-606f5d9cd2ecba4df175bc722621e4e4df3bc516.tar.bz2 |
too much work for that damn video feature... some progress, but it's still not right
-rw-r--r-- | noncore/multimedia/camera/avi.c | 235 | ||||
-rw-r--r-- | noncore/multimedia/camera/avi.h | 142 | ||||
-rw-r--r-- | noncore/multimedia/camera/camera.pro | 6 | ||||
-rw-r--r-- | noncore/multimedia/camera/mainwindow.cpp | 158 | ||||
-rw-r--r-- | noncore/multimedia/camera/mainwindow.h | 9 | ||||
-rw-r--r-- | noncore/multimedia/camera/zcameraio.cpp | 11 |
6 files changed, 528 insertions, 33 deletions
diff --git a/noncore/multimedia/camera/avi.c b/noncore/multimedia/camera/avi.c new file mode 100644 index 0000000..0c757c9 --- a/dev/null +++ b/noncore/multimedia/camera/avi.c | |||
@@ -0,0 +1,235 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. | ||
3 | ** Based on work from Andrew Tridgell and the jpegtoavi project | ||
4 | ** | ||
5 | ** This file is part of Opie Environment. | ||
6 | ** | ||
7 | ** This file may be distributed and/or modified under the terms of the | ||
8 | ** GNU General Public License version 2 as published by the Free Software | ||
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
10 | ** packaging of this file. | ||
11 | ** | ||
12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
14 | ** | ||
15 | **********************************************************************/ | ||
16 | |||
17 | #include "avi.h" | ||
18 | |||
19 | #include <string.h> | ||
20 | #include <stdio.h> | ||
21 | |||
22 | int nframes; | ||
23 | int totalsize; | ||
24 | unsigned int* sizes; | ||
25 | |||
26 | void fprint_quartet(int fd, unsigned int i) | ||
27 | { | ||
28 | char data[4]; | ||
29 | |||
30 | data[0] = (char) i%0x100; | ||
31 | i /= 0x100; | ||
32 | data[1] = (char) i%0x100; | ||
33 | i /= 0x100; | ||
34 | data[2] = (char) i%0x100; | ||
35 | i /= 0x100; | ||
36 | data[3] = (char) i%0x100; | ||
37 | |||
38 | write( fd, &data, 4 ); | ||
39 | } | ||
40 | |||
41 | // start writing an AVI file | ||
42 | |||
43 | void avi_start(int fd, int frames) | ||
44 | { | ||
45 | int ofs = sizeof(struct riff_head)+ | ||
46 | sizeof(struct list_head)+ | ||
47 | sizeof(struct avi_head)+ | ||
48 | sizeof(struct list_head)+ | ||
49 | sizeof(struct stream_head)+ | ||
50 | sizeof(struct frame_head)+ | ||
51 | sizeof(struct list_head)+ | ||
52 | sizeof(struct dmlh_head)+ | ||
53 | sizeof(struct list_head); | ||
54 | |||
55 | printf( "avi_start: frames = %d\n", frames ); | ||
56 | |||
57 | lseek(fd, ofs, SEEK_SET); | ||
58 | |||
59 | nframes = 0; | ||
60 | totalsize = 0; | ||
61 | |||
62 | sizes = (unsigned int*) calloc( sizeof(unsigned int), frames ); // hold size of each frame | ||
63 | } | ||
64 | |||
65 | // add a jpeg frame to an AVI file | ||
66 | void avi_add(int fd, u8 *buf, int size) | ||
67 | { | ||
68 | struct db_head db = {"00db", 0}; | ||
69 | |||
70 | printf( "avi_add: nframes = %d, totalsize = %d, size = %d\n", nframes, totalsize, size ); | ||
71 | |||
72 | // overwrite JFIF type with AVI1 | ||
73 | buf[6]='A'; | ||
74 | buf[7]='V'; | ||
75 | buf[8]='I'; | ||
76 | buf[9]='1'; | ||
77 | |||
78 | while( size%4 ) size++; // align 0 modulo 4*/ | ||
79 | db.size = size; | ||
80 | |||
81 | write( fd, &db, sizeof(db) ); | ||
82 | write( fd, buf, size ); | ||
83 | |||
84 | sizes[nframes] = size; | ||
85 | |||
86 | nframes++; | ||
87 | totalsize += size; // total frame size | ||
88 | } | ||
89 | |||
90 | // finish writing the AVI file - filling in the header | ||
91 | void avi_end(int fd, int width, int height, int fps) | ||
92 | { | ||
93 | struct idx1_head idx = {"idx1", 16*nframes }; | ||
94 | struct db_head db = {"00db", 0}; | ||
95 | struct riff_head rh = { "RIFF", 0, "AVI "}; | ||
96 | struct list_head lh1 = {"LIST", 0, "hdrl"}; | ||
97 | struct avi_head ah; | ||
98 | struct list_head lh2 = {"LIST", 0, "strl"}; | ||
99 | struct stream_head sh; | ||
100 | struct frame_head fh; | ||
101 | struct list_head lh3 = {"LIST", 0, "odml" }; | ||
102 | struct dmlh_head dh = {"dmlh", 4, nframes }; | ||
103 | struct list_head lh4 = {"LIST", 0, "movi"}; | ||
104 | int i; | ||
105 | unsigned int offset = 4; | ||
106 | |||
107 | printf( "avi_end: nframes = %d, fps = %d\n", nframes, fps ); | ||
108 | |||
109 | // write index | ||
110 | |||
111 | write(fd, &idx, sizeof(idx)); | ||
112 | |||
113 | for ( i = 0; i < nframes; i++ ) | ||
114 | { | ||
115 | write(fd, &db, 4 ); // only need the 00db | ||
116 | fprint_quartet( fd, 18 ); // ??? | ||
117 | fprint_quartet( fd, offset ); | ||
118 | fprint_quartet( fd, sizes[i] ); | ||
119 | offset += sizes[i]; | ||
120 | } | ||
121 | |||
122 | free( sizes ); | ||
123 | |||
124 | bzero( &ah, sizeof(ah) ); | ||
125 | strcpy(ah.avih, "avih"); | ||
126 | ah.time = 1000000 / fps; | ||
127 | ah.maxbytespersec = 1000000.0*(totalsize/nframes)/ah.time; | ||
128 | ah.numstreams = 1; | ||
129 | ah.flags = AVIF_HASINDEX; | ||
130 | ah.width = width; | ||
131 | ah.height = height; | ||
132 | |||
133 | bzero(&sh, sizeof(sh)); | ||
134 | strcpy(sh.strh, "strh"); | ||
135 | strcpy(sh.vids, "vids"); | ||
136 | strcpy(sh.codec, "MJPG"); | ||
137 | sh.scale = ah.time; | ||
138 | sh.rate = 1000000; | ||
139 | sh.length = nframes; | ||
140 | |||
141 | bzero(&fh, sizeof(fh)); | ||
142 | strcpy(fh.strf, "strf"); | ||
143 | fh.width = width; | ||
144 | fh.height = height; | ||
145 | fh.planes = 1; | ||
146 | fh.bitcount = 24; | ||
147 | strcpy(fh.codec,"MJPG"); | ||
148 | fh.unpackedsize = 3*width*height; | ||
149 | |||
150 | rh.size = sizeof(lh1)+sizeof(ah)+sizeof(lh2)+sizeof(sh)+ | ||
151 | sizeof(fh)+sizeof(lh3)+sizeof(dh)+sizeof(lh4)+ | ||
152 | nframes*sizeof(struct db_head)+ | ||
153 | totalsize + sizeof(struct idx1_head)+ (16*nframes) +4; // FIXME:16 bytes per nframe // the '4' - what for??? | ||
154 | |||
155 | lh1.size = 4+sizeof(ah)+sizeof(lh2)+sizeof(sh)+sizeof(fh)+sizeof(lh3)+sizeof(dh); | ||
156 | ah.size = sizeof(ah)-8; | ||
157 | lh2.size = 4+sizeof(sh)+sizeof(fh)+sizeof(lh3)+sizeof(dh); //4+sizeof(sh)+sizeof(fh); | ||
158 | sh.size = sizeof(sh)-8; | ||
159 | fh.size = sizeof(fh)-8; | ||
160 | fh.size2 = fh.size; | ||
161 | lh3.size = 4+sizeof(dh); | ||
162 | lh4.size = 4+ nframes*sizeof(struct db_head)+ totalsize; | ||
163 | |||
164 | lseek(fd, 0, SEEK_SET); | ||
165 | |||
166 | write(fd, &rh, sizeof(rh)); | ||
167 | write(fd, &lh1, sizeof(lh1)); | ||
168 | write(fd, &ah, sizeof(ah)); | ||
169 | write(fd, &lh2, sizeof(lh2)); | ||
170 | write(fd, &sh, sizeof(sh)); | ||
171 | write(fd, &fh, sizeof(fh)); | ||
172 | write(fd, &lh3, sizeof(lh3)); | ||
173 | write(fd, &dh, sizeof(dh)); | ||
174 | write(fd, &lh4, sizeof(lh4)); | ||
175 | } | ||
176 | |||
177 | |||
178 | /* NOTE: This is not a general purpose routine - it is meant to only | ||
179 | cope with AVIs saved using the other functions in this file | ||
180 | void avi_explode(char *fname) | ||
181 | { | ||
182 | struct riff_head rh; | ||
183 | struct list_head lh1; | ||
184 | struct avi_head ah; | ||
185 | struct list_head lh2; | ||
186 | struct stream_head sh; | ||
187 | struct frame_head fh; | ||
188 | struct list_head lh3; | ||
189 | int hsize, qsize; | ||
190 | u16 *htables = jpeg_huffman_tables(&hsize); | ||
191 | u16 *qtables = jpeg_quantisation_tables(&qsize, image_quality); | ||
192 | int fd, i; | ||
193 | |||
194 | fd = open(fname,O_RDONLY); | ||
195 | if (fd == -1) { | ||
196 | perror(fname); | ||
197 | return; | ||
198 | } | ||
199 | |||
200 | read(fd, &rh, sizeof(rh)); | ||
201 | read(fd, &lh1, sizeof(lh1)); | ||
202 | read(fd, &ah, sizeof(ah)); | ||
203 | read(fd, &lh2, sizeof(lh2)); | ||
204 | read(fd, &sh, sizeof(sh)); | ||
205 | read(fd, &fh, sizeof(fh)); | ||
206 | read(fd, &lh3, sizeof(lh3)); | ||
207 | |||
208 | for (i=0; ; i++) { | ||
209 | u8 buf[500*1024]; | ||
210 | struct db_head db; | ||
211 | char fname[100]; | ||
212 | int fd2; | ||
213 | |||
214 | if (read(fd, &db, sizeof(db)) != sizeof(db) || | ||
215 | read(fd, buf, db.size) != db.size) break; | ||
216 | |||
217 | snprintf(fname, sizeof(fname)-1,"frame.%d", i); | ||
218 | |||
219 | fd2 = open(fname,O_WRONLY|O_CREAT, 0644); | ||
220 | if (fd2 == -1) { | ||
221 | perror(fname); | ||
222 | continue; | ||
223 | } | ||
224 | write(fd2, buf, 2); | ||
225 | write(fd2, qtables, qsize); | ||
226 | write(fd2, htables, hsize); | ||
227 | write(fd2, buf+2, db.size-2); | ||
228 | close(fd2); | ||
229 | } | ||
230 | close(fd); | ||
231 | printf("exploded %d frames\n", i); | ||
232 | } | ||
233 | |||
234 | */ | ||
235 | |||
diff --git a/noncore/multimedia/camera/avi.h b/noncore/multimedia/camera/avi.h new file mode 100644 index 0000000..fbdc14a --- a/dev/null +++ b/noncore/multimedia/camera/avi.h | |||
@@ -0,0 +1,142 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. | ||
3 | ** Based on work from Andrew Tridgell and the jpegtoavi project | ||
4 | ** | ||
5 | ** This file is part of Opie Environment. | ||
6 | ** | ||
7 | ** This file may be distributed and/or modified under the terms of the | ||
8 | ** GNU General Public License version 2 as published by the Free Software | ||
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
10 | ** packaging of this file. | ||
11 | ** | ||
12 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
13 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
14 | ** | ||
15 | **********************************************************************/ | ||
16 | |||
17 | #ifndef AVI_H | ||
18 | #define AVI_H | ||
19 | |||
20 | #include <unistd.h> | ||
21 | #include <stdio.h> | ||
22 | #include <sys/types.h> | ||
23 | |||
24 | #ifdef __cplusplus | ||
25 | extern "C" { | ||
26 | #endif | ||
27 | |||
28 | typedef unsigned char u8; | ||
29 | typedef unsigned short u16; | ||
30 | typedef unsigned u32; | ||
31 | |||
32 | // header flags | ||
33 | |||
34 | const u32 AVIF_HASINDEX=0x00000010; /* index at end of file */ | ||
35 | const u32 AVIF_MUSTUSEINDEX=0x00000020; | ||
36 | const u32 AVIF_ISINTERLEAVED=0x00000100; | ||
37 | const u32 AVIF_TRUSTCKTYPE=0x00000800; | ||
38 | const u32 AVIF_WASCAPTUREFILE=0x00010000; | ||
39 | const u32 AVIF_COPYRIGHTED=0x00020000; | ||
40 | |||
41 | // function prototypes | ||
42 | |||
43 | void avi_start(int fd, int frame); | ||
44 | void avi_add(int fd, u8 *buf, int size); | ||
45 | void avi_end(int fd, int width, int height, int fps); | ||
46 | void fprint_quartet(int fd, unsigned int i); | ||
47 | |||
48 | // the following structures are ordered as they appear in a typical AVI | ||
49 | |||
50 | struct riff_head { | ||
51 | char riff[4]; // chunk type = "RIFF" | ||
52 | u32 size; // chunk size | ||
53 | char avistr[4]; // avi magic = "AVI " | ||
54 | }; | ||
55 | |||
56 | // the avih chunk contains a number of list chunks | ||
57 | |||
58 | struct avi_head { | ||
59 | char avih[4]; // chunk type = "avih" | ||
60 | u32 size; // chunk size | ||
61 | u32 time; // microsec per frame == 1e6 / fps | ||
62 | u32 maxbytespersec; // = 1e6*(total size/frames)/per_usec) | ||
63 | u32 pad; // pad = 0 | ||
64 | u32 flags; // e.g. AVIF_HASINDEX | ||
65 | u32 nframes; // total number of frames | ||
66 | u32 initialframes; // = 0 | ||
67 | u32 numstreams; // = 1 for now (later = 2 because of audio) | ||
68 | u32 suggested_bufsize; // = 0 (no suggestion) | ||
69 | u32 width; // width | ||
70 | u32 height; // height | ||
71 | u32 reserved[4]; // reserved for future use = 0 | ||
72 | }; | ||
73 | |||
74 | |||
75 | // the LIST chunk contains a number (==#numstreams) of stream chunks | ||
76 | |||
77 | struct list_head { | ||
78 | char list[4]; // chunk type = "LIST" | ||
79 | u32 size; | ||
80 | char type[4]; | ||
81 | }; | ||
82 | |||
83 | |||
84 | struct dmlh_head { | ||
85 | char dmlh[4]; // chunk type dmlh | ||
86 | u32 size; // 4 | ||
87 | u32 nframes; // number of frames | ||
88 | }; | ||
89 | |||
90 | |||
91 | struct stream_head { | ||
92 | char strh[4]; // chunk type = "strh" | ||
93 | u32 size; // chunk size | ||
94 | char vids[4]; // stream type = "vids" | ||
95 | char codec[4]; // codec name (for us, = "MJPG") | ||
96 | u32 flags; // contains AVIT_F* flags | ||
97 | u16 priority; // = 0 | ||
98 | u16 language; // = 0 | ||
99 | u32 initialframes; // = 0 | ||
100 | u32 scale; // = usec per frame | ||
101 | u32 rate; // 1e6 | ||
102 | u32 start; // = 0 | ||
103 | u32 length; // number of frames | ||
104 | u32 suggested_bufsize; // = 0 | ||
105 | u32 quality; // = 0 ? | ||
106 | u32 samplesize; // = 0 ? | ||
107 | }; | ||
108 | |||
109 | |||
110 | struct db_head { | ||
111 | char db[4]; // "00db" | ||
112 | u32 size; | ||
113 | }; | ||
114 | |||
115 | // a frame chunk contains one JPEG image | ||
116 | |||
117 | struct frame_head { | ||
118 | char strf[4]; // chunk type = "strf" | ||
119 | u32 size; // sizeof chunk (big endian) ? | ||
120 | u32 size2; // sizeof chunk (little endian) ? | ||
121 | u32 width; | ||
122 | u32 height; | ||
123 | u16 planes; // 1 bitplane | ||
124 | u16 bitcount; // 24 bpl | ||
125 | char codec[4]; // MJPG (for us) | ||
126 | u32 unpackedsize; // = 3*w*h | ||
127 | u32 r1; // reserved | ||
128 | u32 r2; // reserved | ||
129 | u32 clr_used; // reserved | ||
130 | u32 clr_important; // reserved | ||
131 | }; | ||
132 | |||
133 | struct idx1_head { | ||
134 | char idx1[4]; // chunk type = "idx1" | ||
135 | u32 size; // chunk size | ||
136 | }; | ||
137 | |||
138 | #ifdef __cplusplus | ||
139 | } | ||
140 | #endif | ||
141 | |||
142 | #endif | ||
diff --git a/noncore/multimedia/camera/camera.pro b/noncore/multimedia/camera/camera.pro index 8aedcea..c0e6ca8 100644 --- a/noncore/multimedia/camera/camera.pro +++ b/noncore/multimedia/camera/camera.pro | |||
@@ -4,12 +4,14 @@ DESTDIR = $(OPIEDIR)/bin | |||
4 | TEMPLATE = app | 4 | TEMPLATE = app |
5 | CONFIG = qt warn_on debug | 5 | CONFIG = qt warn_on debug |
6 | 6 | ||
7 | HEADERS = imageio.h \ | 7 | HEADERS = avi.h \ |
8 | imageio.h \ | ||
8 | zcameraio.h \ | 9 | zcameraio.h \ |
9 | previewwidget.h \ | 10 | previewwidget.h \ |
10 | mainwindow.h | 11 | mainwindow.h |
11 | 12 | ||
12 | SOURCES = imageio.cpp \ | 13 | SOURCES = avi.c \ |
14 | imageio.cpp \ | ||
13 | zcameraio.cpp \ | 15 | zcameraio.cpp \ |
14 | previewwidget.cpp \ | 16 | previewwidget.cpp \ |
15 | mainwindow.cpp \ | 17 | mainwindow.cpp \ |
diff --git a/noncore/multimedia/camera/mainwindow.cpp b/noncore/multimedia/camera/mainwindow.cpp index 6141fd1..e27a50e 100644 --- a/noncore/multimedia/camera/mainwindow.cpp +++ b/noncore/multimedia/camera/mainwindow.cpp | |||
@@ -17,6 +17,7 @@ | |||
17 | #include "previewwidget.h" | 17 | #include "previewwidget.h" |
18 | #include "zcameraio.h" | 18 | #include "zcameraio.h" |
19 | #include "imageio.h" | 19 | #include "imageio.h" |
20 | #include "avi.h" | ||
20 | 21 | ||
21 | #include <qapplication.h> | 22 | #include <qapplication.h> |
22 | #include <qaction.h> | 23 | #include <qaction.h> |
@@ -50,9 +51,13 @@ using namespace Opie; | |||
50 | #include <unistd.h> | 51 | #include <unistd.h> |
51 | 52 | ||
52 | #define CAPTUREFILE "/tmp/capture.dat" | 53 | #define CAPTUREFILE "/tmp/capture.dat" |
54 | #define OUTPUTFILE "/tmp/output.avi" | ||
53 | 55 | ||
54 | CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) | 56 | CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags f ) |
55 | :QMainWindow( parent, name, f ), _capturing( false ), _pics( 0 ) | 57 | :QMainWindow( parent, name, f ), |
58 | _rotation( 270 ), // FIXME: get this from current settings (ODevice?) | ||
59 | _capturing( false ), | ||
60 | _pics( 0 ), _videos( 0 ) | ||
56 | { | 61 | { |
57 | #ifdef QT_NO_DEBUG | 62 | #ifdef QT_NO_DEBUG |
58 | if ( !ZCameraIO::instance()->isOpen() ) | 63 | if ( !ZCameraIO::instance()->isOpen() ) |
@@ -105,8 +110,8 @@ void CameraMainWindow::init() | |||
105 | flip = 'A'; // auto | 110 | flip = 'A'; // auto |
106 | quality = 50; | 111 | quality = 50; |
107 | zoom = 1; | 112 | zoom = 1; |
108 | captureX = 640; | 113 | captureX = 480; |
109 | captureY = 480; | 114 | captureY = 640; |
110 | captureFormat = "JPEG"; | 115 | captureFormat = "JPEG"; |
111 | 116 | ||
112 | resog = new QActionGroup( 0, "reso", true ); | 117 | resog = new QActionGroup( 0, "reso", true ); |
@@ -161,14 +166,16 @@ void CameraMainWindow::init() | |||
161 | 166 | ||
162 | void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data ) | 167 | void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& data ) |
163 | { | 168 | { |
169 | int _newrotation; | ||
170 | |||
164 | QDataStream stream( data, IO_ReadOnly ); | 171 | QDataStream stream( data, IO_ReadOnly ); |
165 | odebug << "received system message: " << msg << oendl; | 172 | odebug << "received system message: " << msg << oendl; |
166 | if ( msg == "setCurrentRotation(int)" ) | 173 | if ( msg == "setCurrentRotation(int)" ) |
167 | { | 174 | { |
168 | stream >> _rotation; | 175 | stream >> _newrotation; |
169 | odebug << "received setCurrentRotation(" << _rotation << ")" << oendl; | 176 | odebug << "received setCurrentRotation(" << _newrotation << ")" << oendl; |
170 | 177 | ||
171 | switch ( _rotation ) | 178 | switch ( _newrotation ) |
172 | { | 179 | { |
173 | case 270: preview->resize( QSize( 240, 288 ) ); break; | 180 | case 270: preview->resize( QSize( 240, 288 ) ); break; |
174 | case 180: preview->resize( QSize( 320, 208 ) ); break; | 181 | case 180: preview->resize( QSize( 320, 208 ) ); break; |
@@ -176,6 +183,17 @@ void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& dat | |||
176 | "This rotation is not supported.\n" | 183 | "This rotation is not supported.\n" |
177 | "Supported are 180° and 270°" ); | 184 | "Supported are 180° and 270°" ); |
178 | } | 185 | } |
186 | |||
187 | if ( _newrotation != _rotation ) | ||
188 | { | ||
189 | int tmp = captureX; | ||
190 | captureX = captureY; | ||
191 | captureY = tmp; | ||
192 | _rotation = _newrotation; | ||
193 | } | ||
194 | |||
195 | updateCaption(); | ||
196 | |||
179 | } | 197 | } |
180 | } | 198 | } |
181 | 199 | ||
@@ -223,14 +241,31 @@ void CameraMainWindow::showContextMenu() | |||
223 | m.insertItem( "&Flip", &flip ); | 241 | m.insertItem( "&Flip", &flip ); |
224 | m.insertItem( "&Quality", &quality ); | 242 | m.insertItem( "&Quality", &quality ); |
225 | m.insertItem( "&Output As", &output ); | 243 | m.insertItem( "&Output As", &output ); |
244 | |||
245 | #ifndef QT_NO_DEBUG | ||
246 | m.insertItem( "&Debug!", this, SLOT( doSomething() ) ); | ||
247 | #endif | ||
248 | |||
226 | m.exec( QCursor::pos() ); | 249 | m.exec( QCursor::pos() ); |
227 | } | 250 | } |
228 | 251 | ||
229 | 252 | ||
230 | void CameraMainWindow::resoMenuItemClicked( QAction* a ) | 253 | void CameraMainWindow::resoMenuItemClicked( QAction* a ) |
231 | { | 254 | { |
255 | switch ( _rotation ) | ||
256 | { | ||
257 | case 270: | ||
258 | captureY = a->text().left(3).toInt(); | ||
259 | captureX = a->text().right(3).toInt(); | ||
260 | break; | ||
261 | case 180: | ||
232 | captureX = a->text().left(3).toInt(); | 262 | captureX = a->text().left(3).toInt(); |
233 | captureY = a->text().right(3).toInt(); | 263 | captureY = a->text().right(3).toInt(); |
264 | break; | ||
265 | default: QMessageBox::warning( this, "opie-camera", | ||
266 | "This rotation is not supported.\n" | ||
267 | "Supported are 180° and 270°" ); | ||
268 | } | ||
234 | odebug << "Capture Resolution now: " << captureX << ", " << captureY << oendl; | 269 | odebug << "Capture Resolution now: " << captureX << ", " << captureY << oendl; |
235 | updateCaption(); | 270 | updateCaption(); |
236 | } | 271 | } |
@@ -325,7 +360,7 @@ void CameraMainWindow::startVideoCapture() | |||
325 | //ODevice::inst()->touchSound(); | 360 | //ODevice::inst()->touchSound(); |
326 | ODevice::inst()->setLedState( Led_Mail, Led_BlinkSlow ); | 361 | ODevice::inst()->setLedState( Led_Mail, Led_BlinkSlow ); |
327 | 362 | ||
328 | _capturefd = ::open( CAPTUREFILE, O_WRONLY | O_CREAT ); | 363 | _capturefd = ::open( CAPTUREFILE, O_WRONLY | O_CREAT | O_TRUNC ); |
329 | if ( _capturefd == -1 ) | 364 | if ( _capturefd == -1 ) |
330 | { | 365 | { |
331 | owarn << "can't open capture file: " << strerror(errno) << oendl; | 366 | owarn << "can't open capture file: " << strerror(errno) << oendl; |
@@ -335,6 +370,7 @@ void CameraMainWindow::startVideoCapture() | |||
335 | _capturebuf = new unsigned char[captureX*captureY*2]; | 370 | _capturebuf = new unsigned char[captureX*captureY*2]; |
336 | _capturing = true; | 371 | _capturing = true; |
337 | _videopics = 0; | 372 | _videopics = 0; |
373 | _framerate = 0; | ||
338 | updateCaption(); | 374 | updateCaption(); |
339 | _time.start(); | 375 | _time.start(); |
340 | preview->setRefreshingRate( 1000 ); | 376 | preview->setRefreshingRate( 1000 ); |
@@ -346,10 +382,12 @@ void CameraMainWindow::timerEvent( QTimerEvent* ) | |||
346 | { | 382 | { |
347 | if ( !_capturing ) | 383 | if ( !_capturing ) |
348 | { | 384 | { |
349 | owarn << "timer event in CameraMainWindow without capturing video ?" << oendl; | 385 | odebug << "timer event in CameraMainWindow without capturing video ?" << oendl; |
350 | return; | 386 | return; |
351 | } | 387 | } |
352 | 388 | ||
389 | odebug << "timer event during video - now capturing frame #" << _videopics+1 << oendl; | ||
390 | |||
353 | ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, _capturebuf ); | 391 | ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, _capturebuf ); |
354 | _videopics++; | 392 | _videopics++; |
355 | ::write( _capturefd, _capturebuf, captureX*captureY*2 ); | 393 | ::write( _capturefd, _capturebuf, captureX*captureY*2 ); |
@@ -366,8 +404,9 @@ void CameraMainWindow::stopVideoCapture() | |||
366 | _capturing = false; | 404 | _capturing = false; |
367 | updateCaption(); | 405 | updateCaption(); |
368 | ::close( _capturefd ); | 406 | ::close( _capturefd ); |
407 | _framerate = 1000.0 / (_time.elapsed()/_videopics); | ||
369 | 408 | ||
370 | //postProcessVideo(); | 409 | postProcessVideo( CAPTUREFILE, QString().sprintf( "/tmp/video-%d_%d_%d_q%d-%dfps.avi", _videos++, captureX, captureY, quality, _framerate ) ); |
371 | 410 | ||
372 | #ifndef QT_NO_DEBUG | 411 | #ifndef QT_NO_DEBUG |
373 | preview->setRefreshingRate( 1500 ); | 412 | preview->setRefreshingRate( 1500 ); |
@@ -378,13 +417,25 @@ void CameraMainWindow::stopVideoCapture() | |||
378 | //delete[] _capturebuf; //FIXME: close memory leak | 417 | //delete[] _capturebuf; //FIXME: close memory leak |
379 | } | 418 | } |
380 | 419 | ||
381 | void CameraMainWindow::postProcessVideo() | 420 | void CameraMainWindow::postProcessVideo( const QString& infile, const QString& outfile ) |
382 | { | 421 | { |
383 | preview->setRefreshingRate( 0 ); | 422 | preview->setRefreshingRate( 0 ); |
384 | 423 | ||
385 | /* | 424 | /* |
425 | unsigned char buf[153600]; | ||
426 | |||
427 | int fd = ::open( "/var/compile/opie/noncore/multimedia/camera/capture-320x240.dat", O_RDONLY ); | ||
428 | ::read( fd, &buf, 153600 ); | ||
429 | QImage i; | ||
430 | bufferToImage( 240, 320, (unsigned char*) &buf, &i ); | ||
431 | QPixmap p; | ||
432 | p.convertFromImage( i ); | ||
433 | preview->setPixmap( p ); | ||
434 | imageToFile( &i, "/tmp/tmpfile", "JPEG", 100 ); | ||
435 | return; | ||
436 | */ | ||
386 | 437 | ||
387 | QDialog* fr = new QDialog( this, "splash" ); //, false, QWidget::WStyle_NoBorder | QWidget::WStyle_Customize ); | 438 | QDialog* fr = new QDialog( this, "splash", false, QWidget::WStyle_StaysOnTop ); //, false, QWidget::WStyle_NoBorder | QWidget::WStyle_Customize ); |
388 | fr->setCaption( "Please wait..." ); | 439 | fr->setCaption( "Please wait..." ); |
389 | QVBoxLayout* box = new QVBoxLayout( fr, 2, 2 ); | 440 | QVBoxLayout* box = new QVBoxLayout( fr, 2, 2 ); |
390 | QProgressBar* bar = new QProgressBar( fr ); | 441 | QProgressBar* bar = new QProgressBar( fr ); |
@@ -394,36 +445,89 @@ void CameraMainWindow::postProcessVideo() | |||
394 | box->addWidget( bar ); | 445 | box->addWidget( bar ); |
395 | box->addWidget( label ); | 446 | box->addWidget( label ); |
396 | fr->show(); | 447 | fr->show(); |
448 | label->show(); | ||
449 | bar->show(); | ||
450 | fr->repaint(); | ||
397 | qApp->processEvents(); | 451 | qApp->processEvents(); |
398 | 452 | ||
399 | for ( int i = 0; i < _videopics; ++i ) | 453 | // open files |
400 | { | ||
401 | label->setText( QString().sprintf( "Post processing frame %d / %d", i+1, _videopics ) ); | ||
402 | bar->setProgress( i ); | ||
403 | qApp->processEvents(); | ||
404 | } | ||
405 | |||
406 | */ | ||
407 | 454 | ||
408 | int infd = ::open( CAPTUREFILE, O_RDONLY ); | 455 | int infd = ::open( (const char*) infile, O_RDONLY ); |
409 | if ( infd == -1 ) | 456 | if ( infd == -1 ) |
410 | { | 457 | { |
411 | owarn << "couldn't open capture file: " << strerror(errno) << oendl; | 458 | owarn << "couldn't open capture file: " << strerror(errno) << oendl; |
412 | return; | 459 | return; |
413 | } | 460 | } |
414 | 461 | ||
415 | int outfd = ::open( "/tmp/output.avi", O_WRONLY ); | 462 | int outfd = ::open( (const char*) outfile, O_CREAT | O_WRONLY | O_TRUNC, 0644 ); |
416 | if ( outfd == -1 ) | 463 | if ( outfd == -1 ) |
417 | { | 464 | { |
418 | owarn << "couldn't open output file: " << strerror(errno) << oendl; | 465 | owarn << "couldn't open output file: " << strerror(errno) << oendl; |
419 | return; | 466 | return; |
420 | } | 467 | } |
421 | 468 | ||
469 | int framesize = captureX*captureY*2; | ||
470 | |||
471 | unsigned char* inbuffer = new unsigned char[ framesize ]; | ||
472 | QImage image; | ||
473 | |||
474 | avi_start( outfd, _videopics ); // write preambel | ||
475 | |||
476 | // post process | ||
477 | |||
478 | for ( int i = 0; i < _videopics; ++i ) | ||
479 | { | ||
480 | odebug << "processing frame " << i << oendl; | ||
481 | |||
482 | // <gui> | ||
483 | label->setText( QString().sprintf( "Post processing frame %d / %d", i+1, _videopics ) ); | ||
484 | bar->setProgress( i ); | ||
485 | bar->repaint(); | ||
486 | qApp->processEvents(); | ||
487 | // </gui> | ||
488 | |||
489 | int read = ::read( infd, inbuffer, framesize ); | ||
490 | odebug << "read " << read << " bytes" << oendl; | ||
491 | bufferToImage( captureX, captureY, inbuffer, &image ); | ||
492 | |||
493 | QPixmap p; | ||
494 | p.convertFromImage( image ); | ||
495 | preview->setPixmap( p ); | ||
496 | preview->repaint(); | ||
497 | qApp->processEvents(); | ||
498 | |||
499 | QString tmpfilename( "/tmp/tempfile" ); | ||
500 | //tmpfilename.sprintf( "/tmp/test/%d.jpg", i ); | ||
501 | |||
502 | imageToFile( &image, tmpfilename, "JPEG", quality ); | ||
503 | |||
504 | QFile framefile( tmpfilename ); | ||
505 | if ( !framefile.open( IO_ReadOnly ) ) | ||
506 | { | ||
507 | oerr << "can't process file: %s" << strerror(errno) << oendl; | ||
508 | return; // TODO: clean up temp ressources | ||
509 | } | ||
510 | |||
511 | int filesize = framefile.size(); | ||
512 | odebug << "filesize for frame " << i << " = " << filesize << oendl; | ||
513 | |||
514 | unsigned char* tempbuffer = new unsigned char[ filesize ]; | ||
515 | framefile.readBlock( (char*) tempbuffer, filesize ); | ||
516 | avi_add( outfd, tempbuffer, filesize ); | ||
517 | delete tempbuffer; | ||
518 | framefile.close(); | ||
519 | } | ||
422 | 520 | ||
521 | avi_end( outfd, captureX, captureY, _framerate ); | ||
423 | 522 | ||
523 | fr->hide(); | ||
524 | delete fr; | ||
525 | |||
526 | updateCaption(); | ||
424 | 527 | ||
425 | } | 528 | } |
426 | 529 | ||
530 | |||
427 | void CameraMainWindow::updateCaption() | 531 | void CameraMainWindow::updateCaption() |
428 | { | 532 | { |
429 | if ( !_capturing ) | 533 | if ( !_capturing ) |
@@ -433,3 +537,15 @@ void CameraMainWindow::updateCaption() | |||
433 | } | 537 | } |
434 | 538 | ||
435 | 539 | ||
540 | #ifndef QT_NO_DEBUG | ||
541 | void CameraMainWindow::doSomething() | ||
542 | { | ||
543 | captureX = 240; | ||
544 | captureY = 320; | ||
545 | _videopics = 176; | ||
546 | _framerate = 5; | ||
547 | postProcessVideo( "/var/compile/opie/noncore/multimedia/camera/capture-320x240.dat", | ||
548 | "/tmp/output.avi" ); | ||
549 | } | ||
550 | #endif | ||
551 | |||
diff --git a/noncore/multimedia/camera/mainwindow.h b/noncore/multimedia/camera/mainwindow.h index ad8d1b1..ac83488 100644 --- a/noncore/multimedia/camera/mainwindow.h +++ b/noncore/multimedia/camera/mainwindow.h | |||
@@ -57,11 +57,16 @@ class CameraMainWindow: public QMainWindow | |||
57 | void init(); | 57 | void init(); |
58 | void startVideoCapture(); | 58 | void startVideoCapture(); |
59 | void stopVideoCapture(); | 59 | void stopVideoCapture(); |
60 | void postProcessVideo(); | 60 | void postProcessVideo( const QString&, const QString& ); |
61 | void performCapture( const QString& ); | 61 | void performCapture( const QString& ); |
62 | 62 | ||
63 | virtual void timerEvent( QTimerEvent* ); | 63 | virtual void timerEvent( QTimerEvent* ); |
64 | 64 | ||
65 | protected slots: | ||
66 | #ifndef QT_NO_DEBUG | ||
67 | void doSomething(); // solely for debugging purposes | ||
68 | #endif | ||
69 | |||
65 | private: | 70 | private: |
66 | PreviewWidget* preview; | 71 | PreviewWidget* preview; |
67 | int _rotation; | 72 | int _rotation; |
@@ -82,10 +87,12 @@ class CameraMainWindow: public QMainWindow | |||
82 | 87 | ||
83 | bool _capturing; | 88 | bool _capturing; |
84 | int _pics; | 89 | int _pics; |
90 | int _videos; | ||
85 | 91 | ||
86 | QTime _time; | 92 | QTime _time; |
87 | int _videopics; | 93 | int _videopics; |
88 | int _capturefd; | 94 | int _capturefd; |
95 | int _framerate; | ||
89 | unsigned char* _capturebuf; | 96 | unsigned char* _capturebuf; |
90 | }; | 97 | }; |
91 | 98 | ||
diff --git a/noncore/multimedia/camera/zcameraio.cpp b/noncore/multimedia/camera/zcameraio.cpp index 1c449e7..c940b45 100644 --- a/noncore/multimedia/camera/zcameraio.cpp +++ b/noncore/multimedia/camera/zcameraio.cpp | |||
@@ -293,10 +293,7 @@ void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image ) | |||
293 | { | 293 | { |
294 | int pw = _width; | 294 | int pw = _width; |
295 | int ph = _height; | 295 | int ph = _height; |
296 | if ( _rot ) | 296 | setCaptureFrame( w, h, zoom*256, _rot ); |
297 | setCaptureFrame( h, w, zoom*256, true ); | ||
298 | else | ||
299 | setCaptureFrame( w, h, zoom*256, false ); | ||
300 | snapshot( image ); | 297 | snapshot( image ); |
301 | setCaptureFrame( pw, ph, _zoom, _rot ); | 298 | setCaptureFrame( pw, ph, _zoom, _rot ); |
302 | } | 299 | } |
@@ -307,11 +304,7 @@ void ZCameraIO::captureFrame( int w, int h, int zoom, unsigned char* buf ) | |||
307 | //FIXME: this is too slow | 304 | //FIXME: this is too slow |
308 | int pw = _width; | 305 | int pw = _width; |
309 | int ph = _height; | 306 | int ph = _height; |
310 | if ( _rot ) | 307 | setCaptureFrame( w, h, zoom*256, _rot ); |
311 | setCaptureFrame( h, w, zoom*256, true ); | ||
312 | else | ||
313 | setCaptureFrame( w, h, zoom*256, false ); | ||
314 | |||
315 | snapshot( buf ); | 308 | snapshot( buf ); |
316 | setCaptureFrame( pw, ph, _zoom, _rot ); | 309 | setCaptureFrame( pw, ph, _zoom, _rot ); |
317 | } | 310 | } |