From bb2b3b72de03e2f82f39262f61540fc474f03b7a Mon Sep 17 00:00:00 2001 From: tTh Date: Wed, 1 May 2024 12:28:23 +0200 Subject: [PATCH] add -a option for absolute value of op result --- tools/Makefile | 2 +- tools/fimgops.c | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/Makefile b/tools/Makefile index 40a352ed..6473fa18 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -36,7 +36,7 @@ mkfimg: mkfimg.c $(DEPS) gcc $(COPT) $< ../libfloatimg.a -lm -o $@ fimgops: fimgops.c $(DEPS) - gcc $(COPT) $< ../libfloatimg.a -o $@ + gcc $(COPT) $< ../libfloatimg.a -lm -o $@ fimgfx: fimgfx.c $(DEPS) gcc $(COPT) $< ../libfloatimg.a \ diff --git a/tools/fimgops.c b/tools/fimgops.c index 5182ba2e..6be390d8 100644 --- a/tools/fimgops.c +++ b/tools/fimgops.c @@ -66,6 +66,7 @@ static void help(int lj) puts("usage:\n\tfimgops [options] A.fimg B.fimg operator D.fimg"); puts("options:"); +puts("\t-a\t\texport absolute value"); // puts("\t-g convert output to gray"); printf("\t-k N.N\t\tset float value (def=%.3f)\n", global_fvalue); puts("\t-v\t\tincrease verbosity"); @@ -107,13 +108,15 @@ return foo; int main(int argc, char *argv[]) { int foo, opt, action; +int absolute = 0; char *operator; FloatImg srcA, srcB, dest; global_fvalue = 0.5; -while ((opt = getopt(argc, argv, "hk:v")) != -1) { +while ((opt = getopt(argc, argv, "ahk:v")) != -1) { switch(opt) { + case 'a': absolute = 1; break; case 'g': break; case 'h': help(0); break; case 'k': global_fvalue = atof(optarg); break; @@ -182,6 +185,11 @@ if (foo) { operator, foo); } +if (absolute) { + if (verbosity) fprintf(stderr, "compute abs of %p\n", &dest); + fimg_absolute(&dest); + } + foo = fimg_dump_to_file(&dest, argv[optind+3], 0); if (foo) { fprintf(stderr, "dumping datas to file give us a %d\n", foo);