is extracteur ready for the prime time ?

This commit is contained in:
tth 2021-04-10 23:04:18 +02:00
parent 7718ca0f62
commit 9cf60526d7
2 changed files with 66 additions and 14 deletions

View File

@ -1,9 +1,19 @@
#!/bin/bash #!/bin/bash
make assemblage make extracteur
grabvidseq -vv -n 4 -p 3.3333 -o foo.fimg IMGS="foo.fimg"
./assemblage -v for idx in $(seq 0 69)
do
outf=$(printf "%s/X%04d.png" "/tmp" $idx)
echo $outf
x=$(( idx * 4 ))
y=$(( idx + 80 ))
./extracteur $IMGS 320,200,${x},${y} $outf
done
convert -delay 10 /tmp/X????.png foo.gif
display out.pnm

View File

@ -3,6 +3,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include "../floatimg.h" #include "../floatimg.h"
@ -27,6 +28,21 @@ printf("rect @ %p : %dx%d at %d,%d\n", rect, rect->w, rect->h,
return 0; return 0;
} }
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */ /* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */
int parse_rectangle(char *str, Rectangle *r, int notused)
{
int x, y, w, h, foo;
if (verbosity)
fprintf(stderr, "parsing %s\n", str);
foo = sscanf(str, "%d,%d,%d,%d", &w, &h, &x, &y);
if (4 == foo) {
r->x = x, r->y = y, r->w = w, r->h = h;
return 4;
}
return -1;
}
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */
int essai_extraction(FloatImg *in, FloatImg *out, Rectangle *rect) int essai_extraction(FloatImg *in, FloatImg *out, Rectangle *rect)
{ {
int foo; int foo;
@ -45,14 +61,12 @@ for (yd=0; yd<rect->h; yd++) {
ys = yd + rect->y; ys = yd + rect->y;
if ((ys<0) || (ys>=in->height)) continue; if ((ys<0) || (ys>=in->height)) continue;
for (xd=0; xd<rect->w; xd++) { for (xd=0; xd<rect->w; xd++) {
xs = xd + rect->x; xs = xd + rect->x;
if ((xs<0) || (xs>=in->width)) continue;
fimg_get_rgb(in, xs, ys, rgb); fimg_get_rgb(in, xs, ys, rgb);
fimg_put_rgb(out, xd, yd, rgb); fimg_put_rgb(out, xd, yd, rgb);
count++; count++;
} }
} }
// fprintf(stderr, "%s: %d pix moved\n", __func__, count); // fprintf(stderr, "%s: %d pix moved\n", __func__, count);
@ -60,10 +74,16 @@ for (yd=0; yd<rect->h; yd++) {
return 0; return 0;
} }
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */ /* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */
void help(int k)
{
puts("Usage:\n\textracteur in.fimg w,h,x,y out.???");
exit(0);
}
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int foo; int foo, opt;
FloatImg src, dst; FloatImg src, dst;
Rectangle zone; Rectangle zone;
char *infile = "foo.fimg"; char *infile = "foo.fimg";
@ -71,15 +91,25 @@ char *outfile = "out.fimg";
verbosity = 0; verbosity = 0;
if (3 != argc) { while ((opt = getopt(argc, argv, "hv")) != -1) {
fprintf(stderr, "usage\n\t %s infile.fimg outfile.???\n", switch(opt) {
argv[0]); case 'h': help(0); break;
case 'v': verbosity++; break;
default: break;
}
}
if (3 != argc-optind) {
fprintf(stderr, "---- %s errcli %d ----\n", argv[0], argc-optind);
help(1);
exit(1); exit(1);
} }
fprintf(stderr, "***%s %s %s\n", argv[0], __DATE__, __TIME__);
fimg_print_version(1); fimg_print_version(1);
infile = argv[1]; outfile = argv[2]; infile = argv[optind]; outfile = argv[optind+2];
fprintf(stderr, " %s -> %s\n", infile, outfile);
foo = fimg_create_from_dump(infile, &src); foo = fimg_create_from_dump(infile, &src);
if (foo) { if (foo) {
@ -88,8 +118,16 @@ if (foo) {
exit(1); exit(1);
} }
zone.w = src.width / 2; zone.h = src.height / 2; if (4 != parse_rectangle( argv[optind+1], &zone, 0) ) {
zone.x = src.width / 4 ; zone.y = src.height / 4; fprintf(stderr, "%s: error in parsing of '%s'\n",
argv[0], argv[optind+1]);
exit(1);
}
// zone.w = src.width / 2; zone.h = src.height / 2;
// zone.x = src.width / 4 ; zone.y = src.height / 4;
print_rectangle(&zone);
foo = fimg_create(&dst, zone.w, zone.h, FIMG_TYPE_RGB); foo = fimg_create(&dst, zone.w, zone.h, FIMG_TYPE_RGB);
@ -100,6 +138,10 @@ if (foo) {
} }
foo = fimg_export_picture(&dst, outfile, 0); foo = fimg_export_picture(&dst, outfile, 0);
if (foo) {
fprintf(stderr, "export '%s' -> err %d\n", outfile, foo);
exit(1);
}
return 0; return 0;
} }