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 | 162 | ||||
-rw-r--r-- | noncore/multimedia/camera/mainwindow.h | 9 | ||||
-rw-r--r-- | noncore/multimedia/camera/zcameraio.cpp | 11 |
6 files changed, 530 insertions, 35 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 | |||
@@ -6,3 +6,4 @@ CONFIG = qt warn_on debug | |||
6 | 6 | ||
7 | HEADERS = imageio.h \ | 7 | HEADERS = avi.h \ |
8 | imageio.h \ | ||
8 | zcameraio.h \ | 9 | zcameraio.h \ |
@@ -11,3 +12,4 @@ HEADERS = imageio.h \ | |||
11 | 12 | ||
12 | SOURCES = imageio.cpp \ | 13 | SOURCES = avi.c \ |
14 | imageio.cpp \ | ||
13 | zcameraio.cpp \ | 15 | zcameraio.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 | |||
@@ -19,2 +19,3 @@ | |||
19 | #include "imageio.h" | 19 | #include "imageio.h" |
20 | #include "avi.h" | ||
20 | 21 | ||
@@ -52,5 +53,9 @@ using namespace Opie; | |||
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 | { |
@@ -107,4 +112,4 @@ void CameraMainWindow::init() | |||
107 | zoom = 1; | 112 | zoom = 1; |
108 | captureX = 640; | 113 | captureX = 480; |
109 | captureY = 480; | 114 | captureY = 640; |
110 | captureFormat = "JPEG"; | 115 | captureFormat = "JPEG"; |
@@ -163,2 +168,4 @@ void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& dat | |||
163 | { | 168 | { |
169 | int _newrotation; | ||
170 | |||
164 | QDataStream stream( data, IO_ReadOnly ); | 171 | QDataStream stream( data, IO_ReadOnly ); |
@@ -167,6 +174,6 @@ void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& dat | |||
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 | { |
@@ -178,2 +185,13 @@ void CameraMainWindow::systemMessage( const QCString& msg, const QByteArray& dat | |||
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 | } |
@@ -225,2 +243,7 @@ void CameraMainWindow::showContextMenu() | |||
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() ); |
@@ -231,4 +254,16 @@ void CameraMainWindow::resoMenuItemClicked( QAction* a ) | |||
231 | { | 254 | { |
232 | captureX = a->text().left(3).toInt(); | 255 | switch ( _rotation ) |
233 | captureY = a->text().right(3).toInt(); | 256 | { |
257 | case 270: | ||
258 | captureY = a->text().left(3).toInt(); | ||
259 | captureX = a->text().right(3).toInt(); | ||
260 | break; | ||
261 | case 180: | ||
262 | captureX = a->text().left(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; |
@@ -327,3 +362,3 @@ void CameraMainWindow::startVideoCapture() | |||
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 ) |
@@ -337,2 +372,3 @@ void CameraMainWindow::startVideoCapture() | |||
337 | _videopics = 0; | 372 | _videopics = 0; |
373 | _framerate = 0; | ||
338 | updateCaption(); | 374 | updateCaption(); |
@@ -348,3 +384,3 @@ void CameraMainWindow::timerEvent( QTimerEvent* ) | |||
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; |
@@ -352,2 +388,4 @@ void CameraMainWindow::timerEvent( QTimerEvent* ) | |||
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 ); |
@@ -368,4 +406,5 @@ void CameraMainWindow::stopVideoCapture() | |||
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 | ||
@@ -380,3 +419,3 @@ void CameraMainWindow::stopVideoCapture() | |||
380 | 419 | ||
381 | void CameraMainWindow::postProcessVideo() | 420 | void CameraMainWindow::postProcessVideo( const QString& infile, const QString& outfile ) |
382 | { | 421 | { |
@@ -385,4 +424,16 @@ void CameraMainWindow::postProcessVideo() | |||
385 | /* | 424 | /* |
425 | unsigned char buf[153600]; | ||
386 | 426 | ||
387 | QDialog* fr = new QDialog( this, "splash" ); //, false, QWidget::WStyle_NoBorder | QWidget::WStyle_Customize ); | 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 | */ | ||
437 | |||
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..." ); |
@@ -396,14 +447,10 @@ void CameraMainWindow::postProcessVideo() | |||
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 ) |
@@ -414,3 +461,3 @@ void CameraMainWindow::postProcessVideo() | |||
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 ) |
@@ -421,4 +468,60 @@ void CameraMainWindow::postProcessVideo() | |||
421 | 468 | ||
469 | int framesize = captureX*captureY*2; | ||
470 | |||
471 | unsigned char* inbuffer = new unsigned char[ framesize ]; | ||
472 | QImage image; | ||
422 | 473 | ||
474 | avi_start( outfd, _videopics ); // write preambel | ||
423 | 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 | } | ||
520 | |||
521 | avi_end( outfd, captureX, captureY, _framerate ); | ||
522 | |||
523 | fr->hide(); | ||
524 | delete fr; | ||
525 | |||
526 | updateCaption(); | ||
424 | 527 | ||
@@ -426,2 +529,3 @@ void CameraMainWindow::postProcessVideo() | |||
426 | 529 | ||
530 | |||
427 | void CameraMainWindow::updateCaption() | 531 | void CameraMainWindow::updateCaption() |
@@ -435 +539,13 @@ void CameraMainWindow::updateCaption() | |||
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 | |||
@@ -59,3 +59,3 @@ class CameraMainWindow: public QMainWindow | |||
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& ); |
@@ -64,2 +64,7 @@ class CameraMainWindow: public QMainWindow | |||
64 | 64 | ||
65 | protected slots: | ||
66 | #ifndef QT_NO_DEBUG | ||
67 | void doSomething(); // solely for debugging purposes | ||
68 | #endif | ||
69 | |||
65 | private: | 70 | private: |
@@ -84,2 +89,3 @@ class CameraMainWindow: public QMainWindow | |||
84 | int _pics; | 89 | int _pics; |
90 | int _videos; | ||
85 | 91 | ||
@@ -88,2 +94,3 @@ class CameraMainWindow: public QMainWindow | |||
88 | int _capturefd; | 94 | int _capturefd; |
95 | int _framerate; | ||
89 | unsigned char* _capturebuf; | 96 | unsigned char* _capturebuf; |
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 | |||
@@ -295,6 +295,3 @@ void ZCameraIO::captureFrame( int w, int h, int zoom, QImage* image ) | |||
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 ); |
@@ -309,7 +306,3 @@ void ZCameraIO::captureFrame( int w, int h, int zoom, unsigned char* buf ) | |||
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 ); |