From beedc2e190347fc88a6ad5a0dd8ea567795a4ef6 Mon Sep 17 00:00:00 2001 From: tth Date: Fri, 25 Sep 2020 11:43:25 +0200 Subject: [PATCH] better cumulator --- floatimg.h | 2 +- lib/fimg-2gray.c | 2 +- tools/cumulfimgs.c | 28 ++++++++++++++++++++++++---- tools/essai.sh | 2 +- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/floatimg.h b/floatimg.h index c59af44e..3704e165 100644 --- a/floatimg.h +++ b/floatimg.h @@ -3,7 +3,7 @@ * ugly code from tTh */ -#define FIMG_VERSION 106 +#define FIMG_VERSION 107 /* * in memory descriptor diff --git a/lib/fimg-2gray.c b/lib/fimg-2gray.c index 02f66d6d..4884b9e6 100644 --- a/lib/fimg-2gray.c +++ b/lib/fimg-2gray.c @@ -70,7 +70,7 @@ for (foo=0; fooR[foo] + src->G[foo] + src->B[foo]) / 3.0; } -return -99; +return 0; } /* --------------------------------------------------------------------- */ diff --git a/tools/cumulfimgs.c b/tools/cumulfimgs.c index c89cd84f..2baa54b9 100644 --- a/tools/cumulfimgs.c +++ b/tools/cumulfimgs.c @@ -19,12 +19,12 @@ int foo, numbers[3]; foo = fimg_fileinfos(path, numbers); if (foo) { #if DEBUG_LEVEL - fprintf(stderr, "%s -> err %d\n", path, foo); + fprintf(stderr, "fileinfo of '%s' -> err %d\n", path, foo); #endif return foo; } -fprintf(stderr, "%s \t%d x %d\n",path, numbers[0], numbers[1]); +if (verbosity) fprintf(stderr, "%-20s %d x %d\n",path, numbers[0], numbers[1]); if (FIMG_TYPE_RGB != numbers[2]) { fprintf(stderr, "file %s, %d : bad type\n", path, numbers[2]); @@ -39,6 +39,7 @@ void help(int v) puts("cumulator options :"); puts("\t-v\tincrease verbosity"); puts("\t-o\tname of output file"); +puts("\t-g\tconvert to gray level"); if (verbosity) { puts(""); fimg_print_version(1); } exit(0); @@ -48,14 +49,17 @@ int main(int argc, char *argv[]) { int foo, idx; int opt; + +int to_gray = 0; char *output_file = "out.fimg"; FloatImg accu, temp; int src_loaded = 0; g_width = g_height = 0; -while ((opt = getopt(argc, argv, "ho:v")) != -1) { +while ((opt = getopt(argc, argv, "gho:v")) != -1) { switch(opt) { + case 'g': to_gray = 1; break; case 'h': help(0); break; case 'o': output_file = optarg; break; case 'v': verbosity++; break; @@ -73,10 +77,14 @@ fprintf(stderr, "argc = %d, optind = %d\n", argc, optind); for (idx=optind; idx %d\n", argv[idx],foo); + if (foo) { + fprintf(stderr, "testfile %s -> %d\n", argv[idx],foo); + } if ( ! src_loaded ) { foo = fimg_create_from_dump(argv[idx], &accu); @@ -85,12 +93,24 @@ for (idx=optind; idx %d\n", foo); + exit(1); + } fimg_add_2(&temp, &accu); } } +if (to_gray) { + + foo = fimg_desaturate(&accu, &accu, 0); + if (foo) { + fprintf(stderr, "desaturate: error %d\n", foo); + } + } + foo = fimg_dump_to_file(&accu, output_file, 0); return 0; diff --git a/tools/essai.sh b/tools/essai.sh index acd7d69f..d0c69d12 100755 --- a/tools/essai.sh +++ b/tools/essai.sh @@ -37,7 +37,7 @@ D=" 800 600 " ./mkfimg -v -t vdeg vdeg.fimg $D ./mkfimg -v -t drand48 rand.fimg $D -./cumulfimgs -vv -o foo.fimg hdeg.fimg rand.fimg vdeg.fimg +./cumulfimgs -v -g -o foo.fimg hdeg.fimg rand.fimg vdeg.fimg } # -----------------------------------------------------