Compare commits

...

7 Commits

Author SHA1 Message Date
tth
f0c704a818 cumul image can be converted to gray 2019-09-02 11:47:51 +02:00
tth
cc6dd330ed KRKRKR 2019-09-02 10:42:03 +02:00
tth
7157ce47a3 time to optimize for velocity 2019-09-02 10:07:56 +02:00
tth
d65b93fc66 size of capture is now an option 2019-09-02 04:31:27 +02:00
tth
7abdf7b43e enum_image_framesizes not working 2019-08-31 19:46:37 +02:00
tth
144498d68e enlever le truc qui compile pas facilement 2019-08-31 18:07:31 +02:00
tth
74496aa439 trop chaud pour ecrire la doc 2019-08-31 18:06:09 +02:00
8 changed files with 85 additions and 33 deletions

View File

@ -200,10 +200,9 @@ dans \texttt{floatimg.h}. Les codes d'erreur sont disparates
et non documenté. et non documenté.
\vspace{1em} \vspace{1em}
Bon, vous avez une image latente, et vous souhaitez dessiner dessus
Bon, vous avez une image latente, et (ou dedans ?) avec vos encres flottantes ?
vous souhaité dessiner dessus (ou dedans ?) avec vos encres Il y a une fonction pour ça.
flottantes ?
\subsection{funcs/}\index{funcs/}\label{funcs} \subsection{funcs/}\index{funcs/}\label{funcs}

27
essai.c
View File

@ -14,21 +14,11 @@
int verbosity; int verbosity;
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
void fait_un_dessin(char *fname) void fait_un_dessin(FloatImg *dessin)
{ {
FloatImg dessin;
double tb;
puts(""); fimg_draw_something(dessin);
fimg_timer_set(0);
fimg_create(&dessin, 3200, 2400, 3);
fimg_draw_something(&dessin);
fimg_dump_to_file(&dessin, "dessin.fimg", 0);
fimg_destroy(&dessin);
tb = fimg_timer_get(0);
fprintf(stderr, "%s = %f seconds\n", __func__, tb);
puts("");
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
void help(int k) void help(int k)
@ -60,10 +50,17 @@ if (verbosity) fimg_print_version(0);
fimg_create(&fimgA, W, H, 3); fimg_create(&fimgA, W, H, 3);
fimg_create(&fimgB, W, H, 3); fimg_create(&fimgB, W, H, 3);
fimg_timer_set(0);
fimg_drand48(&fimgB, 100.0); fimg_drand48(&fimgB, 100.0);
fimg_drand48(&fimgA, 100.0); fimg_timer_set(0);
fimg_add(&fimgA, &fimgB, &fimgA); #define NBP 500
for (foo=0; foo<NBP; foo++) {
if (verbosity) {
printf("%5d / %5d\n", foo, NBP);
}
fait_un_dessin(&fimgB);
fimg_add(&fimgA, &fimgB, &fimgA);
fimg_mul(&fimgA, &fimgB, &fimgA);
}
tb = fimg_timer_get(0); tb = fimg_timer_get(0);
fprintf(stderr, "%s = %f seconds\n", __func__, tb); fprintf(stderr, "%s = %f seconds\n", __func__, tb);
foo = fimg_save_as_pnm(&fimgA, "drand48.pnm", 0); foo = fimg_save_as_pnm(&fimgA, "drand48.pnm", 0);

View File

@ -9,4 +9,11 @@
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int essai_ecrire_tiff(FloatImg *src, char *fname)
{
/* bon, tout cela semble bien tortueux ! */
return 0;
}
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */

View File

@ -2,7 +2,7 @@
# building the base library # building the base library
# #
COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0 COPT = -Wall -fpic -g -no-pie -pg -DDEBUG_LEVEL=0
OBJS = fimg-core.o fimg-pnm.o fimg-file.o fimg-math.o \ OBJS = fimg-core.o fimg-pnm.o fimg-file.o fimg-math.o \
fimg-timers.o operators.o fimg-2gray.o fimg-timers.o operators.o fimg-2gray.o
DEPS = Makefile ../floatimg.h DEPS = Makefile ../floatimg.h

View File

@ -117,9 +117,16 @@ int nbre, idx;
fprintf(stderr, ">>> %s ( %p %g )\n", __func__, fi, kmul); fprintf(stderr, ">>> %s ( %p %g )\n", __func__, fi, kmul);
#endif #endif
nbre = fi->width * fi->height * fi->type; if (fi->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s : type %d invalide\n",
__func__, fi->type);
return;
}
nbre = fi->width * fi->height;
for (idx=0; idx<nbre; idx++) { for (idx=0; idx<nbre; idx++) {
fi->R[idx] = drand48() * kmul; fi->R[idx] = drand48() * kmul;
fi->G[idx] = drand48() * kmul;
fi->B[idx] = drand48() * kmul;
} }
} }

View File

@ -26,8 +26,8 @@ fimg2pnm: fimg2pnm.c $(DEPS)
fimg2png: fimg2png.c $(DEPS) fimg2png: fimg2png.c $(DEPS)
gcc $(COPT) $< ../libfloatimg.a -o $@ gcc $(COPT) $< ../libfloatimg.a -o $@
addtga2fimg: addtga2fimg.c $(DEPS) # addtga2fimg: addtga2fimg.c $(DEPS)
gcc $(COPT) $< ../libfloatimg.a -limageSO -lm -o $@ # gcc $(COPT) $< ../libfloatimg.a -limageSO -lm -o $@
addpnm2fimg: addpnm2fimg.c $(DEPS) addpnm2fimg: addpnm2fimg.c $(DEPS)
gcc $(COPT) $< ../libfloatimg.a -lm -o $@ gcc $(COPT) $< ../libfloatimg.a -lm -o $@

View File

@ -36,9 +36,6 @@
#define SAVE_AS_PNM 0 #define SAVE_AS_PNM 0
#define SAVE_AS_FIMG 0 #define SAVE_AS_FIMG 0
#define WIDTH 1920
#define HEIGHT 1080
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
#define CLEAR(x) memset(&(x), 0, sizeof(x)) #define CLEAR(x) memset(&(x), 0, sizeof(x))
@ -74,10 +71,12 @@ if (verbosity) {
} }
puts("options :"); puts("options :");
puts("\t-d /dev/?\tselect video device"); puts("\t-d /dev/?\tselect video device");
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 NNN\t\tperiod in seconds");
puts("\t-s WxH\t\tsize of capture");
puts("\t-v\t\tincrease verbosity"); puts("\t-v\t\tincrease verbosity");
exit(0); exit(0);
} }
@ -102,7 +101,10 @@ int foo, bar;
double period = 10.0; /* delai entre les captures */ double period = 10.0; /* delai entre les captures */
int nbre_capt = 1; /* nombre de captures */ int nbre_capt = 1; /* nombre de captures */
int opt; int opt;
int width = 640;
int height = 480;
double t_final; double t_final;
int to_gray = 0;
char *dest_dir = "."; /* no trailing slash */ char *dest_dir = "."; /* no trailing slash */
char *outfile = "out.pnm"; char *outfile = "out.pnm";
@ -110,14 +112,16 @@ char *outfile = "out.pnm";
FloatImg grab, cumul; FloatImg grab, cumul;
#endif #endif
while ((opt = getopt(argc, argv, "d:hn:o:O:p:v")) != -1) { while ((opt = getopt(argc, argv, "d:ghn:o:O:p:s:v")) != -1) {
switch(opt) { switch(opt) {
case 'd': dev_name = optarg; break; case 'd': dev_name = optarg; break;
case 'g': to_gray = 1; break;
case 'h': help(0); break; case 'h': help(0); break;
case 'n': nbre_capt = atoi(optarg); break; case 'n': nbre_capt = atoi(optarg); break;
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 'v': verbosity++; break; case 'v': verbosity++; break;
} }
} }
@ -125,6 +129,7 @@ while ((opt = getopt(argc, argv, "d:hn:o:O:p:v")) != -1) {
if (verbosity) { if (verbosity) {
fprintf(stderr, "running %s pid=%d\n", argv[0], getpid()); fprintf(stderr, "running %s pid=%d\n", argv[0], getpid());
fprintf(stderr, "period is %.3f microseconds\n", period); fprintf(stderr, "period is %.3f microseconds\n", period);
fprintf(stderr, "framesize is %dx%d\n", width, height);
} }
fd = v4l2_open(dev_name, O_RDWR | O_NONBLOCK, 0); fd = v4l2_open(dev_name, O_RDWR | O_NONBLOCK, 0);
@ -135,16 +140,17 @@ if (fd < 0) {
CLEAR(fmt); CLEAR(fmt);
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = WIDTH; fmt.fmt.pix.width = width;
fmt.fmt.pix.height = HEIGHT; fmt.fmt.pix.height = height;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24; fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24;
fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
xioctl(fd, VIDIOC_S_FMT, &fmt); xioctl(fd, VIDIOC_S_FMT, &fmt);
if (fmt.fmt.pix.pixelformat != V4L2_PIX_FMT_RGB24) { if (fmt.fmt.pix.pixelformat != V4L2_PIX_FMT_RGB24) {
/* are others formats usable ? */
printf("Libv4l didn't accept RGB24 format. Can't proceed.\n"); printf("Libv4l didn't accept RGB24 format. Can't proceed.\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if ((fmt.fmt.pix.width != WIDTH) || (fmt.fmt.pix.height != HEIGHT)) { if ((fmt.fmt.pix.width != width) || (fmt.fmt.pix.height != height)) {
printf("Warning: driver is sending image at %dx%d\n", printf("Warning: driver is sending image at %dx%d\n",
fmt.fmt.pix.width, fmt.fmt.pix.height); fmt.fmt.pix.width, fmt.fmt.pix.height);
} }
@ -195,11 +201,10 @@ foo = fimg_create(&cumul,
FIMG_TYPE_RGB); FIMG_TYPE_RGB);
fimg_clear(&cumul); fimg_clear(&cumul);
cumul.fval = 255.0; cumul.fval = 255.0;
cumul.count = 0;
#endif #endif
type = V4L2_BUF_TYPE_VIDEO_CAPTURE; type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
xioctl(fd, VIDIOC_STREAMON, &type); xioctl(fd, VIDIOC_STREAMON, &type);
@ -280,6 +285,10 @@ 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, "\t%.2f fps\n", (double)nbre_capt / t_final);
#if SAVE_AS_CUMUL #if SAVE_AS_CUMUL
if (to_gray) {
if (verbosity) fputs("converting to gray\n", stderr);
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

View File

@ -19,6 +19,38 @@
int verbosity; int verbosity;
/* --------------------------------------------------------------------- */
/*
* this code was written from a strace output :)
*/
int enum_image_framesizes(int fd, char *txt, int k)
{
int foo, idx;
struct v4l2_frmsizeenum fmtsz;
printf("-- image framesizes enumeration (%s)\n", txt);
for (idx=0; ; idx++) {
memset(&fmtsz, 0, sizeof(fmtsz));
fmtsz.index = idx;
foo = ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &fmtsz);
if (foo) {
if (EINVAL==errno) {
break;
}
else {
perror(__func__);
break;
}
}
printf("%4d %4d %4d\n", idx, fmtsz.pixel_format, fmtsz.type);
}
return 0;
}
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int enum_image_formats(int fd, char *txt, int k) int enum_image_formats(int fd, char *txt, int k)
{ {
@ -61,7 +93,7 @@ int index, foo;
struct v4l2_input input; struct v4l2_input input;
char ligne[50]; char ligne[50];
printf("-- inputs enumeration '%s'\n", txt); printf("-- inputs enumeration (%s)\n", txt);
index = 0; index = 0;
for(;;) { for(;;) {
@ -219,6 +251,7 @@ foo = enum_controls(vfd, "is that working ?", 0);
foo = enum_extended_controls(vfd, "looking for extended", 0); foo = enum_extended_controls(vfd, "looking for extended", 0);
enum_image_framesizes(vfd, "code pas fini", 0);
close(vfd); close(vfd);