From 2e2448b9c94af645db996ff10f768aaf21c9aa4c Mon Sep 17 00:00:00 2001 From: tth Date: Wed, 7 Apr 2021 20:55:38 +0200 Subject: [PATCH] new kluge : extracteur --- .gitignore | 1 + experiment/Makefile | 4 +- experiment/README.md | 5 +- experiment/extracteur.c | 104 +++++++++++++++++++++++++++++++++++++++ experiment/incrustator.h | 2 +- 5 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 experiment/extracteur.c diff --git a/.gitignore b/.gitignore index 7a5b7cb1..f7d1ee59 100644 --- a/.gitignore +++ b/.gitignore @@ -79,6 +79,7 @@ Fonderie/crapdef.h Fonderie/crapstr.h experiment/assemblage +experiment/extracteur experiment/*.fimg experiment/*.pnm experiment/*.o diff --git a/experiment/Makefile b/experiment/Makefile index bcaa8539..5a441f82 100644 --- a/experiment/Makefile +++ b/experiment/Makefile @@ -6,7 +6,7 @@ COPT = -Wall -fpic -g -DDEBUG_LEVEL=1 -lm DEPS = ../floatimg.h ../libfloatimg.a Makefile LIBS = -ltiff -lpnglite -lcfitsio -all: assemblage +all: assemblage extracteur incrustator.o: incrustator.c incrustator.h Makefile gcc -c $(COPT) $< @@ -14,3 +14,5 @@ incrustator.o: incrustator.c incrustator.h Makefile assemblage: assemblage.c Makefile incrustator.o gcc $(COPT) $< incrustator.o ../libfloatimg.a $(LIBS) -o $@ +extracteur: extracteur.c Makefile + gcc $(COPT) $< ../libfloatimg.a $(LIBS) -o $@ diff --git a/experiment/README.md b/experiment/README.md index 605e83e9..71d5d574 100644 --- a/experiment/README.md +++ b/experiment/README.md @@ -1,3 +1,6 @@ +# EXPÉRIMENTATION ÀLC -# ASSEMBLAGE +## ASSEMBLAGE + +## EXTRACTEUR diff --git a/experiment/extracteur.c b/experiment/extracteur.c new file mode 100644 index 00000000..f343859c --- /dev/null +++ b/experiment/extracteur.c @@ -0,0 +1,104 @@ +/* + * another ugly experiment + */ +#include +#include + +#include "../floatimg.h" + +#include "incrustator.h" + +int verbosity; + +/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */ +typedef struct { + int w, h; + int x, y; + int flags; + } Rectangle; + +/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */ +int print_rectangle(Rectangle *rect) +{ + +printf("rect @ %p : %dx%d at %d,%d\n", rect, rect->w, rect->h, + rect->x, rect->y); + +return 0; +} +/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */ +int essai_extraction(FloatImg *in, FloatImg *out, Rectangle *rect) +{ +int foo; +int xs, ys, xd, yd; +int count; +float rgb[3]; + +fimg_describe(in, "source"); +fimg_describe(out, "destination"); +print_rectangle(rect); + +count = 0; +for (yd=0; ydh; yd++) { + ys = yd + rect->y; + if ((ys<0) || (ys>=in->height)) continue; + for (xd=0; xdw; xd++) { + + xs = xd + rect->x; + fimg_get_rgb(in, xs, ys, rgb); + fimg_put_rgb(out, xd, yd, rgb); + count++; + + } + + } + +fprintf(stderr, "%s: %d pix moved\n", __func__, count); + +return 0; +} +/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */ + +int main(int argc, char *argv[]) +{ +int foo; +FloatImg src, dst; +Rectangle zone; +char *infile = "foo.fimg"; +char *outfile = "out.fimg"; + +verbosity = 1; + +if (3 != argc) { + fprintf(stderr, "usage\n\t %s infile.fimg outfile.???\n", + argv[0]); + exit(1); + } + +fimg_print_version(1); + +infile = argv[1]; outfile = argv[2]; + +foo = fimg_create_from_dump(infile, &src); +if (foo) { + fprintf(stderr, "%s: err %d loading image '%s'\n", __func__, + foo, infile); + exit(1); + } + +zone.w = src.width / 2; zone.h = src.height / 2; +zone.x = src.width / 4 ; zone.y = src.height / 4; + +foo = fimg_create(&dst, zone.w, zone.h, FIMG_TYPE_RGB); + +foo = essai_extraction(&src, &dst, &zone); +if (foo) { + fprintf(stderr, "EXTRACTOR EPIC FAIL %d\n", foo); + exit(1); + } + +foo = fimg_export_picture(&dst, outfile, 0); + +return 0; +} +/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */ diff --git a/experiment/incrustator.h b/experiment/incrustator.h index 1e75cd61..b1f60cb7 100644 --- a/experiment/incrustator.h +++ b/experiment/incrustator.h @@ -3,9 +3,9 @@ */ typedef struct { + unsigned long magic; int w, h; int x, y; - unsigned long magic; } FimgArea51; int incrustator_0(FloatImg *psrc, FloatImg *pdst,