diff options
-rw-r--r-- | capture.c | 30 |
1 files changed, 24 insertions, 6 deletions
@@ -46,6 +46,8 @@ static unsigned int n_buffers = 0; FILE * output_file = NULL; static unsigned int width = 640; static unsigned int height = 480; +static int remember = 0; /* boolean flag for recording */ +static int bytesperline = 0; static void errno_exit (const char * s) @@ -88,11 +90,11 @@ process_image (const void * p) { fputc ('.', stdout); fflush (stdout); - if (output_file) { + if (remember && output_file) { /* Write a portable graymap (PGM) binary file. If num_frames > 1, all the files will be concatenated. */ - fprintf(output_file, "P5\n%d %d %d\n", width, height, 255); - fwrite(p, 1, width*height, output_file); + fprintf(output_file, "P5\n%d %d %d\n", bytesperline, height, 255); + fwrite(p, 1, bytesperline*height, output_file); } } @@ -542,14 +544,19 @@ init_device (void) /* Note VIDIOC_S_FMT may change width and height. */ + fprintf(stderr, "Image has total size %d with %d bytes per line\n", fmt.fmt.pix.sizeimage, fmt.fmt.pix.bytesperline); + + /* Remember the number of bytes per line for use in the PGM writer */ + bytesperline = fmt.fmt.pix.bytesperline; + /* Buggy driver paranoia. */ - min = fmt.fmt.pix.width * 2; + min = fmt.fmt.pix.width; if (fmt.fmt.pix.bytesperline < min) fmt.fmt.pix.bytesperline = min; min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height; if (fmt.fmt.pix.sizeimage < min) fmt.fmt.pix.sizeimage = min; - + switch (io) { case IO_METHOD_READ: init_read (fmt.fmt.pix.sizeimage); @@ -613,13 +620,14 @@ usage (FILE * fp, "-r | --read Use read() calls\n" "-u | --userp Use application allocated buffers\n" "-n | --numframes Number of frames to acquire (default=1)\n" + "-w | --warmup Number of warmup frames to require before acquisition.\n" "-f | --framerate Frame rate at which to acquire (default: unspecified)\n" "-o | --outfile File in which to dump frames as cat'd PGM\n" "", argv[0]); } -static const char short_options [] = "d:hmrun:f:o:"; +static const char short_options [] = "d:hmrun:w:f:o:"; static const struct option long_options [] = { @@ -629,6 +637,7 @@ long_options [] = { { "read", no_argument, NULL, 'r' }, { "userp", no_argument, NULL, 'u' }, { "numframes", required_argument, NULL, 'n' }, + { "warmup", required_argument, NULL, 'w' }, { "framerate", required_argument, NULL, 'f' }, { "outfile", required_argument, NULL, 'o' }, { 0, 0, 0, 0 } @@ -640,6 +649,7 @@ main (int argc, { dev_name = "/dev/video"; unsigned int numframes = 1; + unsigned int warmup = 0; unsigned int framerate = 0; for (;;) { @@ -681,6 +691,10 @@ main (int argc, numframes = atoi(optarg); break; + case 'w': + warmup = atoi(optarg); + break; + case 'f': framerate = atoi(optarg); break; @@ -708,6 +722,10 @@ main (int argc, if (framerate > 0) set_framerate(1, framerate); + remember = 0; + mainloop (warmup); + + remember = 1; mainloop (numframes); stop_capturing (); |