From b3de3b96f7fc7628fdb8b0ee945c2a5f99ff052a Mon Sep 17 00:00:00 2001 From: tth Date: Sun, 25 Apr 2021 12:51:01 +0200 Subject: [PATCH] move extractor to func/ --- experiment/extracteur.c | 23 ++--------------------- floatimg.h | 12 ++++++++++-- funcs/geometry.c | 33 +++++++++++++++++++++++++++++++++ funcs/utils.c | 20 ++++++++++++++++++++ 4 files changed, 65 insertions(+), 23 deletions(-) diff --git a/experiment/extracteur.c b/experiment/extracteur.c index 1cdee6db..50331233 100644 --- a/experiment/extracteur.c +++ b/experiment/extracteur.c @@ -12,11 +12,6 @@ int verbosity; /* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */ -typedef struct { - int w, h; - int x, y; - int flags; - } Rectangle; /* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */ int print_rectangle(Rectangle *rect) @@ -28,20 +23,6 @@ printf("rect @ %p : %dx%d at %d,%d\n", rect, rect->w, rect->h, 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) { @@ -111,7 +92,7 @@ if (verbosity) { } infile = argv[optind]; outfile = argv[optind+2]; -fprintf(stderr, " %s -> %s\n", infile, outfile); +fprintf(stderr, "%s %s -> %s\n", argv[0], infile, outfile); foo = fimg_create_from_dump(infile, &src); if (foo) { @@ -133,7 +114,7 @@ if (verbosity) print_rectangle(&zone); foo = fimg_create(&dst, zone.w, zone.h, FIMG_TYPE_RGB); -foo = essai_extraction(&src, &dst, &zone); +foo = fimg_extractor(&src, &dst, &zone); if (foo) { fprintf(stderr, "EXTRACTOR EPIC FAIL %d\n", foo); exit(1); diff --git a/floatimg.h b/floatimg.h index 624ddc4d..7b0fe79c 100644 --- a/floatimg.h +++ b/floatimg.h @@ -4,13 +4,13 @@ * http://la.buvette.org/photos/cumul */ -#define FIMG_VERSION 134 +#define FIMG_VERSION 135 /* * in memory descriptor */ typedef struct { - int magic; + unsigned long magic; int width; int height; int type; @@ -28,6 +28,12 @@ typedef struct { int w, h, t; } FimgFileHead; +typedef struct { + unsigned long magic; + int w, h; + int x, y; + int flags; + } Rectangle; #define FIMG_TYPE_GRAY 1 #define FIMG_TYPE_RGB 3 @@ -160,6 +166,7 @@ int fimg_desaturate(FloatImg *src, FloatImg *dst, int notused); /* module funcs/geometry.c */ int fimg_halfsize_0(FloatImg *src, FloatImg *dst, int notused); int fimg_halfsize_1(FloatImg *src, FloatImg *dst, int notused); +int fimg_extractor(FloatImg *in, FloatImg *out, Rectangle *rect); int fimg_displacement_0(FloatImg *psrc, FloatImg *pdst, int flags); @@ -209,6 +216,7 @@ int fimg_multirandom(FloatImg *fimg, long nbpass); void fimg_print_minmax(float minmax[6], char *titre); int parse_WxH(char *str, int *pw, int *ph); int parse_double(char *str, double *dptr); +int parse_rectangle(char *str, Rectangle *r, int notused); int format_from_extension(char *fname); char * extension_from_format(int fmt); diff --git a/funcs/geometry.c b/funcs/geometry.c index b6fcd156..d10ff28a 100644 --- a/funcs/geometry.c +++ b/funcs/geometry.c @@ -8,6 +8,8 @@ #include "../floatimg.h" +extern int verbosity; + /* --------------------------------------------------------------------- */ /* * really crude function, need more work... @@ -102,4 +104,35 @@ for (y=0; yh; yd++) { + ys = yd + rect->y; + if ((ys<0) || (ys>=in->height)) continue; + for (xd=0; xdw; xd++) { + xs = xd + rect->x; + if ((xs<0) || (xs>=in->width)) continue; + 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; +} +/* --------------------------------------------------------------------- */ diff --git a/funcs/utils.c b/funcs/utils.c index 33a72ac0..93572d81 100644 --- a/funcs/utils.c +++ b/funcs/utils.c @@ -70,6 +70,26 @@ if (!strcasecmp(name, "exr")) return FILE_TYPE_EXR; return -1; } + +/* --------------------------------------------------------------------- */ +/* + * /!\ return 4 on success + */ +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 format_from_extension(char *fname) {