From b79f6851f5e787c7a5ae079887f87208977cbeb3 Mon Sep 17 00:00:00 2001 From: tTh Date: Sat, 21 Jan 2023 09:06:36 +0100 Subject: [PATCH] add an extractor --- funcs/geometry.c | 10 +++- install.sh | 1 + tools/Makefile | 5 +- tools/README.md | 4 ++ tools/fimgextract.c | 118 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 tools/fimgextract.c diff --git a/funcs/geometry.c b/funcs/geometry.c index b5c71726..7921aca6 100644 --- a/funcs/geometry.c +++ b/funcs/geometry.c @@ -116,12 +116,20 @@ int xs, ys, xd, yd; int count; float rgb[3]; +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, in, out, rect); +#endif + if (verbosity > 1) { fimg_describe(in, "extractor: source"); fimg_describe(out, "extractor: destination"); // print_rectangle(rect); } +/* + * some sanity controls, please ! XXX + */ + count = 0; for (yd=0; ydh; yd++) { ys = yd + rect->y; @@ -135,7 +143,7 @@ for (yd=0; ydh; yd++) { } } -// fprintf(stderr, "%s: %d pix moved\n", __func__, count); +if (verbosity > 1) fprintf(stderr, "%s: %d pix moved\n", __func__, count); return 0; } diff --git a/install.sh b/install.sh index 5dfcd192..ebf9ecbc 100755 --- a/install.sh +++ b/install.sh @@ -9,6 +9,7 @@ cp tools/mkfimg tools/fimg2pnm tools/fimgops \ tools/cumulfimgs tools/fimg2text \ tools/fimghalfsize \ tools/fimgmetadata \ + tools/fimgextract \ /usr/local/bin cp v4l2/grabvidseq v4l2/video-infos \ diff --git a/tools/Makefile b/tools/Makefile index 271484c5..4b88bd19 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -14,11 +14,14 @@ all: fimg2pnm mkfimg png2fimg fimgstats fimg2png \ fimg2tiff fimg2text fimg2fits \ addpnm2fimg cumulfimgs fimgops fimgfx \ fimgmetadata \ - fimghalfsize + fimghalfsize fimgextract fimgmetadata: fimgmetadata.c $(DEPS) gcc $(COPT) $< ../libfloatimg.a -lm -o $@ +fimgextract: fimgextract.c $(DEPS) + gcc $(COPT) $< ../libfloatimg.a -lm -o $@ + fimgstats: fimgstats.c $(DEPS) gcc $(COPT) $< ../libfloatimg.a -lm -o $@ diff --git a/tools/README.md b/tools/README.md index a2482a9c..0e2c8f41 100644 --- a/tools/README.md +++ b/tools/README.md @@ -47,3 +47,7 @@ afin de les rendre machinables. Voir aussi *fimgmetadata*. Nouveau avril 2022. Need more doc... Voir aussi *fimg2text*. +## fimgextract + +nouveau novembre 2022. + diff --git a/tools/fimgextract.c b/tools/fimgextract.c new file mode 100644 index 00000000..4bba01f4 --- /dev/null +++ b/tools/fimgextract.c @@ -0,0 +1,118 @@ +/* + * This thing is just a mess ! + * *************************** + */ +#include +#include +#include +#include + +#include "../floatimg.h" + +int verbosity; // nasty global var. + +/* --------------------------------------------------------------------- */ +/* nouveau ~ 2 octobre 2022 */ +int extractor(char *srcname, char *dstname, FimgArea51 *rect) +{ +FloatImg src, dst; +int foo; + +fprintf(stderr, ">>> %s ( %s %s %p )\n", __func__, srcname, dstname, rect); + +if (verbosity) { + print_rectangle((char *)__func__, rect); + } + +foo = fimg_create_from_dump(srcname, &src); +if (foo) { + fprintf(stderr, "%s: load %s from dump --> %d\n", __func__, + srcname, foo); + return foo; + } + +foo = fimg_create(&dst, rect->w, rect->h, 3); +if (foo) { + fprintf(stderr, "%s: fimg create dst --> %d\n", __func__, foo); + return foo; + } + +/* REAL operation was here ! */ +foo = fimg_extractor(&src, &dst, rect); +if (foo) { + fprintf(stderr, "%s: fimg extractor --> %d\n", __func__, foo); +#ifdef MUST_ABORT + abort(); // kill me hardly ! +#endif + return foo; + } + +// debug code XXX (void)fimg_save_as_pnm(&dst, "f.pnm", 0); + +foo = fimg_dump_to_file(&dst, dstname, 0); +if (foo) { + fprintf(stderr, "%s: dumping datas to '%s' give us a %d\n", + __func__, dstname, foo); + return foo; + } + +return 0; +} +/* --------------------------------------------------------------------- */ +void help(void) +{ + +printf("-- Fimg Extractor -- lib v%d -- %s %s\n", FIMG_VERSION, + __DATE__, __TIME__); + +puts("usage:\n\tfimgextract [options] source.fimg width,height,xpos,ypos"); +puts("options:"); +puts("\t-o out.fimg\tname the output file"); +puts("\t-v\t\tmake be a blabla box"); +puts("\t-x\t\tenable crashy feature"); +exit(0); +} +/* --------------------------------------------------------------------- */ + +int main(int argc, char *argv[]) +{ +int foo, idx; +int opt; +int experiment = 0; +FimgArea51 area; +char *output_file = "out.fimg"; + +while ((opt = getopt(argc, argv, "ho:vx")) != -1) { + switch(opt) { + case 'h': help(); break; + case 'o': output_file = optarg; break; + case 'v': verbosity++; break; + case 'x': experiment++; break; + } + } + +fprintf(stderr, "argc = %d optind = %d\n", argc, optind); +for (idx=optind; idx %d\n", argv[0], foo); + exit(1); + } + +foo = extractor(argv[argc-2], output_file, &area); +if (foo) { + fprintf(stderr, "%s: extractor --> %d\n", __func__, foo); + exit(1); + } + +return 0; +} +/* --------------------------------------------------------------------- */