premiere version de l'upscaling qui fonctionne

This commit is contained in:
tth 2019-09-03 15:37:49 +02:00
parent d3c1a1f0a2
commit b67d023f0c
4 changed files with 45 additions and 26 deletions

View File

@ -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 DEPS = ../floatimg.h ../libfloatimg.a Makefile
all: grabvidseq t all: grabvidseq t

View File

@ -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_add_rgb2fimg(unsigned char *src, int w, int h, FloatImg *d);
int x_rgb2fimg(unsigned char *src, int w, int h, FloatImg *d); int x_rgb2fimg(unsigned char *src, int w, int h, FloatImg *d);

View File

@ -75,8 +75,9 @@ puts("\t-g\t\tconvert to gray");
puts("\t-n NNN\t\thow many frames ?"); puts("\t-n NNN\t\thow many frames ?");
puts("\t-O ./\t\tset Output dir"); puts("\t-O ./\t\tset Output dir");
puts("\t-o bla\t\tset output filename"); 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-s WxH\t\tsize of capture");
puts("\t-u\t\ttry upscaling...");
puts("\t-v\t\tincrease verbosity"); puts("\t-v\t\tincrease verbosity");
exit(0); exit(0);
} }
@ -105,14 +106,15 @@ int width = 640;
int height = 480; int height = 480;
double t_final; double t_final;
int to_gray = 0; int to_gray = 0;
int upscaling = 0;
char *dest_dir = "."; /* no trailing slash */ char *dest_dir = "."; /* no trailing slash */
char *outfile = "out.pnm"; char *outfile = "out.pnm";
#if SAVE_AS_CUMUL #if SAVE_AS_CUMUL
FloatImg grab, cumul; FloatImg cumul;
#endif #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) { switch(opt) {
case 'd': dev_name = optarg; break; case 'd': dev_name = optarg; break;
case 'g': to_gray = 1; 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': dest_dir = optarg; break;
case 'o': outfile = optarg; break; case 'o': outfile = optarg; break;
case 'p': period = 1e6*atof(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; case 'v': verbosity++; break;
} }
} }
@ -193,12 +197,17 @@ for (i = 0; i < n_buffers; ++i) {
} }
#if SAVE_AS_CUMUL #if SAVE_AS_CUMUL
foo = fimg_create(&grab, if (upscaling) {
fmt.fmt.pix.width, fmt.fmt.pix.height, foo = fimg_create(&cumul,
fmt.fmt.pix.width*2, fmt.fmt.pix.height*2,
FIMG_TYPE_RGB); FIMG_TYPE_RGB);
}
else {
foo = fimg_create(&cumul, foo = fimg_create(&cumul,
fmt.fmt.pix.width, fmt.fmt.pix.height, fmt.fmt.pix.width, fmt.fmt.pix.height,
FIMG_TYPE_RGB); FIMG_TYPE_RGB);
}
fimg_clear(&cumul); fimg_clear(&cumul);
cumul.fval = 255.0; cumul.fval = 255.0;
cumul.count = 0; cumul.count = 0;
@ -256,13 +265,14 @@ for (i = 0; i < nbre_capt; i++) {
#endif #endif
#if SAVE_AS_CUMUL #if SAVE_AS_CUMUL
/** this is the slow version if (upscaling) {
x_rgb2fimg(buffers[buf.index].start, x_upscaler_0(buffers[buf.index].start,
fmt.fmt.pix.width, fmt.fmt.pix.height, &grab); fmt.fmt.pix.width, fmt.fmt.pix.height, &cumul);
fimg_add(&grab, &cumul, &cumul); }
**/ else {
x_add_rgb2fimg(buffers[buf.index].start, x_add_rgb2fimg(buffers[buf.index].start,
fmt.fmt.pix.width, fmt.fmt.pix.height, &cumul); fmt.fmt.pix.width, fmt.fmt.pix.height, &cumul);
}
#endif #endif
#if SAVE_AS_FIMG #if SAVE_AS_FIMG
@ -281,18 +291,19 @@ for (i = 0; i < nbre_capt; i++) {
} }
t_final = fimg_timer_get(0); t_final = fimg_timer_get(0);
fprintf(stderr, "pid %d : elapsed time %g s\n", getpid(), t_final); fprintf(stderr, "pid %d : elapsed %g s -> %.2f fps\n", getpid(),
fprintf(stderr, "\t%.2f fps\n", (double)nbre_capt / t_final); t_final, (double)nbre_capt / t_final);
#if SAVE_AS_CUMUL #if SAVE_AS_CUMUL
if (to_gray) { if (to_gray) {
if (verbosity) fputs("converting to gray\n", stderr); if (verbosity) fputs("converting to gray\n", stderr);
foo = fimg_to_gray(&cumul); foo = fimg_to_gray(&cumul);
} }
// save cumul to file // save cumul to file
foo = fimg_save_as_pnm(&cumul, outfile, 0); foo = fimg_save_as_pnm(&cumul, outfile, 0);
// free buffers // free buffers
fimg_destroy(&grab);
fimg_destroy(&cumul); fimg_destroy(&cumul);
#endif #endif

View File

@ -5,15 +5,17 @@
#include "funcs.h" #include "funcs.h"
extern int verbosity;
/* /*
* Be careful, these functions are not yet fireproof, * Be careful, these functions are not yet fireproof,
* and calling conventions are fluctuating. * 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 *rp, *gp, *bp;
float r, g, b; float r, g, b;
static unsigned short modz; static unsigned short modz;
@ -26,12 +28,16 @@ if ( d->width != w*2 || d->height != h*2 ) {
return -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<h; y++) { for (y=0; y<h; y++) {
yy = (y*2) + ! (modz & 1); yy = (y*2) + oy;
for (x=0; x<w; x++) { for (x=0; x<w; x++) {
xx = (x*2) + ! (modz & 2); xx = (x*2) + ox;
r = (float)*src++; r = (float)*src++;
g = (float)*src++; g = (float)*src++;
b = (float)*src++; b = (float)*src++;