diff --git a/v4l2/Makefile b/v4l2/Makefile index fe6c561..ace84c9 100644 --- a/v4l2/Makefile +++ b/v4l2/Makefile @@ -1,6 +1,6 @@ -COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=1 +COPT = -Wall -fpic -g -pg -no-pie -DDEBUG_LEVEL=1 DEPS = ../floatimg.h ../libfloatimg.a Makefile all: grabvidseq t diff --git a/v4l2/funcs.h b/v4l2/funcs.h index 86c1154..a4c28c8 100644 --- a/v4l2/funcs.h +++ b/v4l2/funcs.h @@ -8,6 +8,8 @@ int init_device(int notused); /* --------------------------------------------------------------------- */ +int x_upscaler_0(unsigned char *src, int w, int h, FloatImg *d); + int x_add_rgb2fimg(unsigned char *src, int w, int h, FloatImg *d); int x_rgb2fimg(unsigned char *src, int w, int h, FloatImg *d); diff --git a/v4l2/grabvidseq.c b/v4l2/grabvidseq.c index a15fc5e..0e895b6 100644 --- a/v4l2/grabvidseq.c +++ b/v4l2/grabvidseq.c @@ -75,8 +75,9 @@ puts("\t-g\t\tconvert to gray"); puts("\t-n NNN\t\thow many frames ?"); puts("\t-O ./\t\tset Output dir"); puts("\t-o bla\t\tset output filename"); -puts("\t-p NNN\t\tperiod in seconds"); +puts("\t-p NN.N\t\tperiod in seconds"); puts("\t-s WxH\t\tsize of capture"); +puts("\t-u\t\ttry upscaling..."); puts("\t-v\t\tincrease verbosity"); exit(0); } @@ -105,14 +106,15 @@ int width = 640; int height = 480; double t_final; int to_gray = 0; +int upscaling = 0; char *dest_dir = "."; /* no trailing slash */ char *outfile = "out.pnm"; #if SAVE_AS_CUMUL -FloatImg grab, cumul; +FloatImg cumul; #endif -while ((opt = getopt(argc, argv, "d:ghn:o:O:p:s:v")) != -1) { +while ((opt = getopt(argc, argv, "d:ghn:o:O:p:s:uv")) != -1) { switch(opt) { case 'd': dev_name = optarg; break; case 'g': to_gray = 1; break; @@ -121,7 +123,9 @@ while ((opt = getopt(argc, argv, "d:ghn:o:O:p:s:v")) != -1) { case 'O': dest_dir = optarg; break; case 'o': outfile = optarg; break; case 'p': period = 1e6*atof(optarg); break; - case 's': parse_WxH(optarg, &width, &height); break; + case 's': parse_WxH(optarg, &width, &height); + break; + case 'u': upscaling = 1; break; case 'v': verbosity++; break; } } @@ -193,12 +197,17 @@ for (i = 0; i < n_buffers; ++i) { } #if SAVE_AS_CUMUL -foo = fimg_create(&grab, - fmt.fmt.pix.width, fmt.fmt.pix.height, - FIMG_TYPE_RGB); -foo = fimg_create(&cumul, - fmt.fmt.pix.width, fmt.fmt.pix.height, - FIMG_TYPE_RGB); +if (upscaling) { + foo = fimg_create(&cumul, + fmt.fmt.pix.width*2, fmt.fmt.pix.height*2, + FIMG_TYPE_RGB); + } +else { + foo = fimg_create(&cumul, + fmt.fmt.pix.width, fmt.fmt.pix.height, + FIMG_TYPE_RGB); + } + fimg_clear(&cumul); cumul.fval = 255.0; cumul.count = 0; @@ -256,13 +265,14 @@ for (i = 0; i < nbre_capt; i++) { #endif #if SAVE_AS_CUMUL - /** this is the slow version - x_rgb2fimg(buffers[buf.index].start, - fmt.fmt.pix.width, fmt.fmt.pix.height, &grab); - fimg_add(&grab, &cumul, &cumul); - **/ - x_add_rgb2fimg(buffers[buf.index].start, - fmt.fmt.pix.width, fmt.fmt.pix.height, &cumul); + if (upscaling) { + x_upscaler_0(buffers[buf.index].start, + fmt.fmt.pix.width, fmt.fmt.pix.height, &cumul); + } + else { + x_add_rgb2fimg(buffers[buf.index].start, + fmt.fmt.pix.width, fmt.fmt.pix.height, &cumul); + } #endif #if SAVE_AS_FIMG @@ -281,18 +291,19 @@ for (i = 0; i < nbre_capt; i++) { } t_final = fimg_timer_get(0); -fprintf(stderr, "pid %d : elapsed time %g s\n", getpid(), t_final); -fprintf(stderr, "\t%.2f fps\n", (double)nbre_capt / t_final); +fprintf(stderr, "pid %d : elapsed %g s -> %.2f fps\n", getpid(), + t_final, (double)nbre_capt / t_final); #if SAVE_AS_CUMUL if (to_gray) { if (verbosity) fputs("converting to gray\n", stderr); foo = fimg_to_gray(&cumul); } + // save cumul to file foo = fimg_save_as_pnm(&cumul, outfile, 0); + // free buffers -fimg_destroy(&grab); fimg_destroy(&cumul); #endif diff --git a/v4l2/rgb2fimg.c b/v4l2/rgb2fimg.c index 07e7bf2..7cd6ba8 100644 --- a/v4l2/rgb2fimg.c +++ b/v4l2/rgb2fimg.c @@ -5,15 +5,17 @@ #include "funcs.h" +extern int verbosity; + /* * Be careful, these functions are not yet fireproof, * and calling conventions are fluctuating. */ /* --------------------------------------------------------------------- */ -int x_upscaler(unsigned char *src, int w, int h, FloatImg *d) +int x_upscaler_0(unsigned char *src, int w, int h, FloatImg *d) { -int x, y, xx, yy; +int x, y, xx, yy, ox, oy; // float *rp, *gp, *bp; float r, g, b; static unsigned short modz; @@ -26,12 +28,16 @@ if ( d->width != w*2 || d->height != h*2 ) { return -2; } -// rp = d->R, gp = d->G, bp = d->B; +ox = ! (modz & 2); +oy = ! (modz & 1); + +if (verbosity>2) fprintf(stderr, "%s %5d %d %d\n", __func__, + modz, ox, oy); for (y=0; y