summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/camera/cmd/capture.cpp3
-rw-r--r--noncore/multimedia/camera/gui/mainwindow.cpp2
-rw-r--r--noncore/multimedia/camera/lib/avi.c1
3 files changed, 5 insertions, 1 deletions
diff --git a/noncore/multimedia/camera/cmd/capture.cpp b/noncore/multimedia/camera/cmd/capture.cpp
index 688622b..6b8c63c 100644
--- a/noncore/multimedia/camera/cmd/capture.cpp
+++ b/noncore/multimedia/camera/cmd/capture.cpp
@@ -94,99 +94,102 @@ void Capturer::capture()
94 else if ( flip == "0" ) 94 else if ( flip == "0" )
95 ZCameraIO::instance()->setFlip( ZCameraIO::XNOFLIP | ZCameraIO::YNOFLIP ); 95 ZCameraIO::instance()->setFlip( ZCameraIO::XNOFLIP | ZCameraIO::YNOFLIP );
96 else if ( flip == "X" ) 96 else if ( flip == "X" )
97 ZCameraIO::instance()->setFlip( ZCameraIO::XFLIP ); 97 ZCameraIO::instance()->setFlip( ZCameraIO::XFLIP );
98 else if ( flip == "Y" ) 98 else if ( flip == "Y" )
99 ZCameraIO::instance()->setFlip( ZCameraIO::YFLIP ); 99 ZCameraIO::instance()->setFlip( ZCameraIO::YFLIP );
100 else if ( flip == "*" ) 100 else if ( flip == "*" )
101 ZCameraIO::instance()->setFlip( ZCameraIO::XFLIP | ZCameraIO::YFLIP ); 101 ZCameraIO::instance()->setFlip( ZCameraIO::XFLIP | ZCameraIO::YFLIP );
102 102
103 ZCameraIO::instance()->captureFrame( width, height, zoom, &image ); 103 ZCameraIO::instance()->captureFrame( width, height, zoom, &image );
104 QImage im = image.convertDepth( 32 ); 104 QImage im = image.convertDepth( 32 );
105 bool result = im.save( name, format, quality ); 105 bool result = im.save( name, format, quality );
106 if ( !result ) 106 if ( !result )
107 { 107 {
108 printf( "QImageio-Problem while writing.\n" ); 108 printf( "QImageio-Problem while writing.\n" );
109 } 109 }
110 else 110 else
111 { 111 {
112 printf( "Ok.\n" ); 112 printf( "Ok.\n" );
113 } 113 }
114} 114}
115 115
116 116
117void usage() 117void usage()
118{ 118{
119 printf( "Usage: ./capture [options] filename\n\n" ); 119 printf( "Usage: ./capture [options] filename\n\n" );
120 printf( " -x xresolution (dividable by 16) [default=240]\n" ); 120 printf( " -x xresolution (dividable by 16) [default=240]\n" );
121 printf( " -y xresolution (dividable by 16) [default=320]\n" ); 121 printf( " -y xresolution (dividable by 16) [default=320]\n" );
122 printf( " -q quality (10-100) [default=75]\n" ); 122 printf( " -q quality (10-100) [default=75]\n" );
123 printf( " -f flip (A=auto, 0, X, Y, *=both) [default=Auto]\n" ); 123 printf( " -f flip (A=auto, 0, X, Y, *=both) [default=Auto]\n" );
124 printf( " -o output format (JPEG,BMP,PNG) [default=JPEG]\n" ); 124 printf( " -o output format (JPEG,BMP,PNG) [default=JPEG]\n" );
125 printf( " -z zoom (1-2) [default=1]\n" ); 125 printf( " -z zoom (1-2) [default=1]\n" );
126} 126}
127 127
128int main( int argc, char** argv ) 128int main( int argc, char** argv )
129{ 129{
130 OApplication* a = new OApplication( argc, argv, "Capture" ); 130 OApplication* a = new OApplication( argc, argv, "Capture" );
131 Capturer* c = new Capturer(); 131 Capturer* c = new Capturer();
132 132
133 if ( argc < 2 ) 133 if ( argc < 2 )
134 { 134 {
135 usage(); 135 usage();
136 return -1; 136 return -1;
137 } 137 }
138 138
139 #define I_HATE_WRITING_HARDCODED_PARSES 139 #define I_HATE_WRITING_HARDCODED_PARSES
140 140
141 int i = 1; 141 int i = 1;
142 while ( i < argc ) 142 while ( i < argc )
143 { 143 {
144 // check for filename 144 // check for filename
145 if ( argv[i][0] != '-' ) 145 if ( argv[i][0] != '-' )
146 { 146 {
147 if ( argc != i+1 ) 147 if ( argc != i+1 )
148 { 148 {
149 usage(); 149 usage();
150 return -1; 150 return -1;
151 } 151 }
152 else 152 else
153 { 153 {
154 c->name = argv[i]; 154 c->name = argv[i];
155 break; 155 break;
156 } 156 }
157 } 157 }
158 else 158 else
159 { 159 {
160 i++; 160 i++;
161 if ( argc == i ) 161 if ( argc == i )
162 { 162 {
163 usage(); 163 usage();
164 return -1; 164 return -1;
165 } 165 }
166 switch ( argv[i-1][1] ) 166 switch ( argv[i-1][1] )
167 { 167 {
168 case 'x': c->width = QString( argv[i] ).toInt(); break; 168 case 'x': c->width = QString( argv[i] ).toInt(); break;
169 case 'y': c->height = QString( argv[i] ).toInt(); break; 169 case 'y': c->height = QString( argv[i] ).toInt(); break;
170 case 'z': c->zoom = QString( argv[i] ).toInt(); break; 170 case 'z': c->zoom = QString( argv[i] ).toInt(); break;
171 case 'o': c->format = QString( argv[i] ); break; 171 case 'o': c->format = QString( argv[i] ); break;
172 case 'q': c->quality = QString( argv[i] ).toInt(); break; 172 case 'q': c->quality = QString( argv[i] ).toInt(); break;
173 case 'f': c->flip = QString( argv[i] )[0]; break; 173 case 'f': c->flip = QString( argv[i] )[0]; break;
174 default: usage(); return -1; 174 default: usage(); return -1;
175 } 175 }
176 i++; 176 i++;
177 } 177 }
178 178
179 #undef I_HATE_WRITING_HARDCODED_PARSES 179 #undef I_HATE_WRITING_HARDCODED_PARSES
180 } 180 }
181 181
182 if ( !ZCameraIO::instance()->isOpen() ) 182 if ( !ZCameraIO::instance()->isOpen() )
183 { 183 {
184 printf( "Error: Can't detect your camera. Exiting.\n" ); 184 printf( "Error: Can't detect your camera. Exiting.\n" );
185 return -1; 185 return -1;
186 } 186 }
187 187
188 c->checkSettings(); 188 c->checkSettings();
189 c->capture(); 189 c->capture();
190
191 delete c;
192 delete a;
190 return 0; 193 return 0;
191} 194}
192 195
diff --git a/noncore/multimedia/camera/gui/mainwindow.cpp b/noncore/multimedia/camera/gui/mainwindow.cpp
index 7f2a9bd..bde448d 100644
--- a/noncore/multimedia/camera/gui/mainwindow.cpp
+++ b/noncore/multimedia/camera/gui/mainwindow.cpp
@@ -453,193 +453,193 @@ void CameraMainWindow::shutterClicked()
453 { 453 {
454 !_capturing ? startVideoCapture() : stopVideoCapture(); 454 !_capturing ? startVideoCapture() : stopVideoCapture();
455 } 455 }
456} 456}
457 457
458 458
459void CameraMainWindow::performCapture( const QString& format ) 459void CameraMainWindow::performCapture( const QString& format )
460{ 460{
461 QString name; 461 QString name;
462 462
463 if ( outputTo == "Documents Folder" ) 463 if ( outputTo == "Documents Folder" )
464 { 464 {
465 name.sprintf( "%s/Documents/image/%s/", (const char*) QDir::homeDirPath(), (const char*) captureFormat.lower() ); 465 name.sprintf( "%s/Documents/image/%s/", (const char*) QDir::homeDirPath(), (const char*) captureFormat.lower() );
466 if ( !QDir( name ).exists() ) 466 if ( !QDir( name ).exists() )
467 { 467 {
468 odebug << "creating directory " << name << oendl; 468 odebug << "creating directory " << name << oendl;
469 QString msg = "mkdir -p " + name; 469 QString msg = "mkdir -p " + name;
470 system( msg.latin1() ); 470 system( msg.latin1() );
471 } 471 }
472 } 472 }
473 else 473 else
474 name = outputTo; 474 name = outputTo;
475 475
476 name.append( prefix ); 476 name.append( prefix );
477 if ( appendSettings ) 477 if ( appendSettings )
478 { 478 {
479 name.append( QString().sprintf( "_%d_%d_q%d", captureX, captureY, quality ) ); 479 name.append( QString().sprintf( "_%d_%d_q%d", captureX, captureY, quality ) );
480 } 480 }
481 name.append( QString().sprintf( "-%d.%s", _pics++, (const char*) captureFormat.lower() ) ); 481 name.append( QString().sprintf( "-%d.%s", _pics++, (const char*) captureFormat.lower() ) );
482 482
483 QImage i; 483 QImage i;
484 ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, &i ); 484 ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, &i );
485 QImage im = i.convertDepth( 32 ); 485 QImage im = i.convertDepth( 32 );
486 bool result = im.save( name, format, quality ); 486 bool result = im.save( name, format, quality );
487 if ( !result ) 487 if ( !result )
488 { 488 {
489 oerr << "imageio-Problem while writing." << oendl; 489 oerr << "imageio-Problem while writing." << oendl;
490 Global::statusMessage( "Error!" ); 490 Global::statusMessage( "Error!" );
491 } 491 }
492 else 492 else
493 { 493 {
494 odebug << captureFormat << "-image has been successfully captured" << oendl; 494 odebug << captureFormat << "-image has been successfully captured" << oendl;
495 Global::statusMessage( "Ok." ); 495 Global::statusMessage( "Ok." );
496 } 496 }
497} 497}
498 498
499 499
500void CameraMainWindow::startVideoCapture() 500void CameraMainWindow::startVideoCapture()
501{ 501{
502 ODevice::inst()->playTouchSound(); 502 ODevice::inst()->playTouchSound();
503 ODevice::inst()->setLedState( Led_Mail, Led_BlinkSlow ); 503 ODevice::inst()->setLedState( Led_Mail, Led_BlinkSlow );
504 504
505 _capturefd = ::open( CAPTUREFILE, O_WRONLY | O_CREAT | O_TRUNC ); 505 _capturefd = ::open( CAPTUREFILE, O_WRONLY | O_CREAT | O_TRUNC );
506 if ( _capturefd == -1 ) 506 if ( _capturefd == -1 )
507 { 507 {
508 owarn << "can't open capture file: " << strerror(errno) << oendl; 508 owarn << "can't open capture file: " << strerror(errno) << oendl;
509 return; 509 return;
510 } 510 }
511 511
512 _capturebuf = new unsigned char[captureX*captureY*2]; 512 _capturebuf = new unsigned char[captureX*captureY*2];
513 _capturing = true; 513 _capturing = true;
514 _videopics = 0; 514 _videopics = 0;
515 _framerate = 0; 515 _framerate = 0;
516 updateCaption(); 516 updateCaption();
517 _time.start(); 517 _time.start();
518 preview->setRefreshingRate( 1000 ); 518 preview->setRefreshingRate( 1000 );
519 startTimer( 100 ); // too fast but that is ok 519 startTimer( 100 ); // too fast but that is ok
520} 520}
521 521
522 522
523void CameraMainWindow::timerEvent( QTimerEvent* ) 523void CameraMainWindow::timerEvent( QTimerEvent* )
524{ 524{
525 if ( !_capturing ) 525 if ( !_capturing )
526 { 526 {
527 odebug << "timer event in CameraMainWindow without capturing video ?" << oendl; 527 odebug << "timer event in CameraMainWindow without capturing video ?" << oendl;
528 return; 528 return;
529 } 529 }
530 530
531 odebug << "timer event during video - now capturing frame #" << _videopics+1 << oendl; 531 odebug << "timer event during video - now capturing frame #" << _videopics+1 << oendl;
532 532
533 ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, _capturebuf ); 533 ZCameraIO::instance()->captureFrame( captureX, captureY, zoom, _capturebuf );
534 _videopics++; 534 _videopics++;
535 ::write( _capturefd, _capturebuf, captureX*captureY*2 ); 535 ::write( _capturefd, _capturebuf, captureX*captureY*2 );
536 setCaption( QString().sprintf( "Capturing %dx%d @ %.2f fps %d", 536 setCaption( QString().sprintf( "Capturing %dx%d @ %.2f fps %d",
537 captureX, captureY, 1000.0 / (_time.elapsed()/_videopics), _videopics ) ); 537 captureX, captureY, 1000.0 / (_time.elapsed()/_videopics), _videopics ) );
538} 538}
539 539
540 540
541void CameraMainWindow::stopVideoCapture() 541void CameraMainWindow::stopVideoCapture()
542{ 542{
543 killTimers(); 543 killTimers();
544 ODevice::inst()->playTouchSound(); 544 ODevice::inst()->playTouchSound();
545 ODevice::inst()->setLedState( Led_Mail, Led_Off ); 545 ODevice::inst()->setLedState( Led_Mail, Led_Off );
546 _capturing = false; 546 _capturing = false;
547 updateCaption(); 547 updateCaption();
548 ::close( _capturefd ); 548 ::close( _capturefd );
549 _framerate = 1000.0 / (_time.elapsed()/_videopics); 549 _framerate = static_cast<int>( 1000.0 / (_time.elapsed()/_videopics) );
550 550
551 QString name; 551 QString name;
552 if ( outputTo == "Documents Folder" ) 552 if ( outputTo == "Documents Folder" )
553 { 553 {
554 name.sprintf( "%s/Documents/video/%s/", (const char*) QDir::homeDirPath(), (const char*) captureFormat.lower() ); 554 name.sprintf( "%s/Documents/video/%s/", (const char*) QDir::homeDirPath(), (const char*) captureFormat.lower() );
555 if ( !QDir( name ).exists() ) 555 if ( !QDir( name ).exists() )
556 { 556 {
557 odebug << "creating directory " << name << oendl; 557 odebug << "creating directory " << name << oendl;
558 QString msg = "mkdir -p " + name; 558 QString msg = "mkdir -p " + name;
559 system( msg.latin1() ); 559 system( msg.latin1() );
560 } 560 }
561 } 561 }
562 else 562 else
563 name = outputTo; 563 name = outputTo;
564 564
565 name.append( "/" ); // sure is sure and safe is safe ;-) 565 name.append( "/" ); // sure is sure and safe is safe ;-)
566 name.append( prefix ); 566 name.append( prefix );
567 if ( appendSettings ) 567 if ( appendSettings )
568 name.append( QString().sprintf( "_%d_%d_q%d_%dfps", captureX, captureY, quality, _framerate ) ); 568 name.append( QString().sprintf( "_%d_%d_q%d_%dfps", captureX, captureY, quality, _framerate ) );
569 name.append( QString().sprintf( "-%d.%s", _videos++, (const char*) captureFormat.lower() ) ); 569 name.append( QString().sprintf( "-%d.%s", _videos++, (const char*) captureFormat.lower() ) );
570 postProcessVideo( CAPTUREFILE, name ); 570 postProcessVideo( CAPTUREFILE, name );
571 571
572 #ifndef QT_NO_DEBUG 572 #ifndef QT_NO_DEBUG
573 preview->setRefreshingRate( 1500 ); 573 preview->setRefreshingRate( 1500 );
574 #else 574 #else
575 preview->setRefreshingRate( 200 ); 575 preview->setRefreshingRate( 200 );
576 #endif 576 #endif
577 577
578 //delete[] _capturebuf; //FIXME: close memory leak 578 //delete[] _capturebuf; //FIXME: close memory leak
579} 579}
580 580
581void CameraMainWindow::postProcessVideo( const QString& infile, const QString& outfile ) 581void CameraMainWindow::postProcessVideo( const QString& infile, const QString& outfile )
582{ 582{
583 odebug << "post processing " << infile << " --> " << outfile << oendl; 583 odebug << "post processing " << infile << " --> " << outfile << oendl;
584 584
585 preview->setRefreshingRate( 0 ); 585 preview->setRefreshingRate( 0 );
586 586
587 /* 587 /*
588 unsigned char buf[153600]; 588 unsigned char buf[153600];
589 589
590 int fd = ::open( "/var/compile/opie/noncore/multimedia/camera/capture-320x240.dat", O_RDONLY ); 590 int fd = ::open( "/var/compile/opie/noncore/multimedia/camera/capture-320x240.dat", O_RDONLY );
591 ::read( fd, &buf, 153600 ); 591 ::read( fd, &buf, 153600 );
592 QImage i; 592 QImage i;
593 bufferToImage( 240, 320, (unsigned char*) &buf, &i ); 593 bufferToImage( 240, 320, (unsigned char*) &buf, &i );
594 QPixmap p; 594 QPixmap p;
595 p.convertFromImage( i ); 595 p.convertFromImage( i );
596 preview->setPixmap( p ); 596 preview->setPixmap( p );
597 imageToFile( &i, "/tmp/tmpfile", "JPEG", 100 ); 597 imageToFile( &i, "/tmp/tmpfile", "JPEG", 100 );
598 return; 598 return;
599 */ 599 */
600 600
601 QDialog* fr = new QDialog( this, "splash", false, QWidget::WStyle_StaysOnTop ); //, false, QWidget::WStyle_NoBorder | QWidget::WStyle_Customize ); 601 QDialog* fr = new QDialog( this, "splash", false, QWidget::WStyle_StaysOnTop ); //, false, QWidget::WStyle_NoBorder | QWidget::WStyle_Customize );
602 fr->setCaption( "Please wait..." ); 602 fr->setCaption( "Please wait..." );
603 QVBoxLayout* box = new QVBoxLayout( fr, 2, 2 ); 603 QVBoxLayout* box = new QVBoxLayout( fr, 2, 2 );
604 QProgressBar* bar = new QProgressBar( fr ); 604 QProgressBar* bar = new QProgressBar( fr );
605 bar->setCenterIndicator( true ); 605 bar->setCenterIndicator( true );
606 bar->setTotalSteps( _videopics-1 ); 606 bar->setTotalSteps( _videopics-1 );
607 QLabel* label = new QLabel( "Post processing frame bla/bla", fr ); 607 QLabel* label = new QLabel( "Post processing frame bla/bla", fr );
608 box->addWidget( bar ); 608 box->addWidget( bar );
609 box->addWidget( label ); 609 box->addWidget( label );
610 fr->show(); 610 fr->show();
611 label->show(); 611 label->show();
612 bar->show(); 612 bar->show();
613 fr->repaint(); 613 fr->repaint();
614 qApp->processEvents(); 614 qApp->processEvents();
615 615
616 // open files 616 // open files
617 617
618 int infd = ::open( (const char*) infile, O_RDONLY ); 618 int infd = ::open( (const char*) infile, O_RDONLY );
619 if ( infd == -1 ) 619 if ( infd == -1 )
620 { 620 {
621 owarn << "couldn't open capture file: " << strerror(errno) << oendl; 621 owarn << "couldn't open capture file: " << strerror(errno) << oendl;
622 return; 622 return;
623 } 623 }
624 624
625 int outfd = ::open( (const char*) outfile, O_CREAT | O_WRONLY | O_TRUNC, 0644 ); 625 int outfd = ::open( (const char*) outfile, O_CREAT | O_WRONLY | O_TRUNC, 0644 );
626 if ( outfd == -1 ) 626 if ( outfd == -1 )
627 { 627 {
628 owarn << "couldn't open output file: " << strerror(errno) << oendl; 628 owarn << "couldn't open output file: " << strerror(errno) << oendl;
629 return; 629 return;
630 } 630 }
631 631
632 int framesize = captureX*captureY*2; 632 int framesize = captureX*captureY*2;
633 633
634 unsigned char* inbuffer = new unsigned char[ framesize ]; 634 unsigned char* inbuffer = new unsigned char[ framesize ];
635 QImage image; 635 QImage image;
636 636
637 avi_start( outfd, _videopics ); // write preambel 637 avi_start( outfd, _videopics ); // write preambel
638 638
639 // post process 639 // post process
640 640
641 for ( int i = 0; i < _videopics; ++i ) 641 for ( int i = 0; i < _videopics; ++i )
642 { 642 {
643 odebug << "processing frame " << i << oendl; 643 odebug << "processing frame " << i << oendl;
644 644
645 // <gui> 645 // <gui>
diff --git a/noncore/multimedia/camera/lib/avi.c b/noncore/multimedia/camera/lib/avi.c
index 77aba33..d99c016 100644
--- a/noncore/multimedia/camera/lib/avi.c
+++ b/noncore/multimedia/camera/lib/avi.c
@@ -1,116 +1,117 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved.
3** Based on work from Andrew Tridgell and the jpegtoavi project 3** Based on work from Andrew Tridgell and the jpegtoavi project
4** 4**
5** This file is part of Opie Environment. 5** This file is part of Opie Environment.
6** 6**
7** This file may be distributed and/or modified under the terms of the 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 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 9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file. 10** packaging of this file.
11** 11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14** 14**
15**********************************************************************/ 15**********************************************************************/
16 16
17#include "avi.h" 17#include "avi.h"
18 18
19#include <string.h> 19#include <string.h>
20#include <stdio.h> 20#include <stdio.h>
21#include <stdlib.h>
21 22
22int nframes; 23int nframes;
23int totalsize; 24int totalsize;
24unsigned int* sizes; 25unsigned int* sizes;
25 26
26void fprint_quartet(int fd, unsigned int i) 27void fprint_quartet(int fd, unsigned int i)
27{ 28{
28 char data[4]; 29 char data[4];
29 30
30 data[0] = (char) i%0x100; 31 data[0] = (char) i%0x100;
31 i /= 0x100; 32 i /= 0x100;
32 data[1] = (char) i%0x100; 33 data[1] = (char) i%0x100;
33 i /= 0x100; 34 i /= 0x100;
34 data[2] = (char) i%0x100; 35 data[2] = (char) i%0x100;
35 i /= 0x100; 36 i /= 0x100;
36 data[3] = (char) i%0x100; 37 data[3] = (char) i%0x100;
37 38
38 write( fd, &data, 4 ); 39 write( fd, &data, 4 );
39} 40}
40 41
41// start writing an AVI file 42// start writing an AVI file
42 43
43void avi_start(int fd, int frames) 44void avi_start(int fd, int frames)
44{ 45{
45 int ofs = sizeof(struct riff_head)+ 46 int ofs = sizeof(struct riff_head)+
46 sizeof(struct list_head)+ 47 sizeof(struct list_head)+
47 sizeof(struct avi_head)+ 48 sizeof(struct avi_head)+
48 sizeof(struct list_head)+ 49 sizeof(struct list_head)+
49 sizeof(struct stream_head)+ 50 sizeof(struct stream_head)+
50 sizeof(struct frame_head)+ 51 sizeof(struct frame_head)+
51 sizeof(struct list_head)+ 52 sizeof(struct list_head)+
52 sizeof(struct dmlh_head)+ 53 sizeof(struct dmlh_head)+
53 sizeof(struct list_head); 54 sizeof(struct list_head);
54 55
55 printf( "avi_start: frames = %d\n", frames ); 56 printf( "avi_start: frames = %d\n", frames );
56 57
57 lseek(fd, ofs, SEEK_SET); 58 lseek(fd, ofs, SEEK_SET);
58 59
59 nframes = 0; 60 nframes = 0;
60 totalsize = 0; 61 totalsize = 0;
61 62
62 sizes = (unsigned int*) calloc( sizeof(unsigned int), frames ); // hold size of each frame 63 sizes = (unsigned int*) calloc( sizeof(unsigned int), frames ); // hold size of each frame
63} 64}
64 65
65// add a jpeg frame to an AVI file 66// add a jpeg frame to an AVI file
66void avi_add(int fd, u8 *buf, int size) 67void avi_add(int fd, u8 *buf, int size)
67{ 68{
68 struct db_head db = {"00db", 0}; 69 struct db_head db = {"00db", 0};
69 70
70 printf( "avi_add: nframes = %d, totalsize = %d, size = %d\n", nframes, totalsize, size ); 71 printf( "avi_add: nframes = %d, totalsize = %d, size = %d\n", nframes, totalsize, size );
71 72
72 // overwrite JFIF type with AVI1 73 // overwrite JFIF type with AVI1
73 buf[6]='A'; 74 buf[6]='A';
74 buf[7]='V'; 75 buf[7]='V';
75 buf[8]='I'; 76 buf[8]='I';
76 buf[9]='1'; 77 buf[9]='1';
77 78
78 while( size%4 ) size++; // align 0 modulo 4*/ 79 while( size%4 ) size++; // align 0 modulo 4*/
79 db.size = size; 80 db.size = size;
80 81
81 write( fd, &db, sizeof(db) ); 82 write( fd, &db, sizeof(db) );
82 write( fd, buf, size ); 83 write( fd, buf, size );
83 84
84 sizes[nframes] = size; 85 sizes[nframes] = size;
85 86
86 nframes++; 87 nframes++;
87 totalsize += size; // total frame size 88 totalsize += size; // total frame size
88} 89}
89 90
90// finish writing the AVI file - filling in the header 91// finish writing the AVI file - filling in the header
91void avi_end(int fd, int width, int height, int fps) 92void avi_end(int fd, int width, int height, int fps)
92{ 93{
93 struct idx1_head idx = {"idx1", 16*nframes }; 94 struct idx1_head idx = {"idx1", 16*nframes };
94 struct db_head db = {"00db", 0}; 95 struct db_head db = {"00db", 0};
95 struct riff_head rh = { "RIFF", 0, "AVI "}; 96 struct riff_head rh = { "RIFF", 0, "AVI "};
96 struct list_head lh1 = {"LIST", 0, "hdrl"}; 97 struct list_head lh1 = {"LIST", 0, "hdrl"};
97 struct avi_head ah; 98 struct avi_head ah;
98 struct list_head lh2 = {"LIST", 0, "strl"}; 99 struct list_head lh2 = {"LIST", 0, "strl"};
99 struct stream_head sh; 100 struct stream_head sh;
100 struct frame_head fh; 101 struct frame_head fh;
101 struct list_head lh3 = {"LIST", 0, "odml" }; 102 struct list_head lh3 = {"LIST", 0, "odml" };
102 struct dmlh_head dh = {"dmlh", 4, nframes }; 103 struct dmlh_head dh = {"dmlh", 4, nframes };
103 struct list_head lh4 = {"LIST", 0, "movi"}; 104 struct list_head lh4 = {"LIST", 0, "movi"};
104 int i; 105 int i;
105 unsigned int offset = 4; 106 unsigned int offset = 4;
106 107
107 printf( "avi_end: nframes = %d, fps = %d\n", nframes, fps ); 108 printf( "avi_end: nframes = %d, fps = %d\n", nframes, fps );
108 109
109 // write index 110 // write index
110 111
111 write(fd, &idx, sizeof(idx)); 112 write(fd, &idx, sizeof(idx));
112 113
113 for ( i = 0; i < nframes; i++ ) 114 for ( i = 0; i < nframes; i++ )
114 { 115 {
115 write(fd, &db, 4 ); // only need the 00db 116 write(fd, &db, 4 ); // only need the 00db
116 fprint_quartet( fd, 18 ); // ??? 117 fprint_quartet( fd, 18 ); // ???