From 090a7719713ebe542d8ed0838b4dc367eec4e0c2 Mon Sep 17 00:00:00 2001 From: tth Date: Wed, 11 Sep 2019 18:58:39 +0200 Subject: [PATCH] more operators :) --- doc/the_floatimg_hack.tex | 13 ++++++++++++- tools/fimgops.c | 23 +++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/doc/the_floatimg_hack.tex b/doc/the_floatimg_hack.tex index 74f35ae..21b3694 100644 --- a/doc/the_floatimg_hack.tex +++ b/doc/the_floatimg_hack.tex @@ -295,10 +295,21 @@ usage : fimgstats [options] file.fimg Operations diverses sur ou entre des images. \begin{verbatim} -Usage: +usage: fimgops [options] A.fimg B.fimg operator D.fimg +operators: + add 1 + sub 2 + mix 3 + mul 4 +options: + -g convert output to gray + -k N.N set float value + -v increase verbosity \end{verbatim} +Pour l'operateur \texttt{mix}, le paramĂȘtre flottant doit +ĂȘtre fourni en utilisant l'option \texttt{-k}. \subsection{fimg2png, fimg2pnm, fimg2tiff} \index{fimg2png}\label{fimg2png} diff --git a/tools/fimgops.c b/tools/fimgops.c index e3e17b5..75211b7 100644 --- a/tools/fimgops.c +++ b/tools/fimgops.c @@ -7,9 +7,14 @@ int verbosity; +/* --------------------------------------------------------------------- */ + +float global_fvalue; + /* --------------------------------------------------------------------- */ #define OP_ADD 1 #define OP_SUB 2 +#define OP_MIX 3 #define OP_MUL 4 typedef struct { int code; @@ -19,6 +24,7 @@ typedef struct { Opcode opcodes[] = { { OP_ADD, "add" }, { OP_SUB, "sub" }, + { OP_MIX, "mix" }, { OP_MUL, "mul" }, { 0, NULL } }; @@ -27,7 +33,7 @@ static void pr_opcodes(void) Opcode *optr; puts("operators:"); for (optr = opcodes; optr->code; optr++) { - printf("\t%-20s %d\n", optr->op, optr->code); + printf("\t%-15s %d\n", optr->op, optr->code); } } static int look_opcode(char *txt) @@ -52,6 +58,10 @@ static void help(int lj) puts("usage:\n\tfimgops [options] A.fimg B.fimg operator D.fimg"); pr_opcodes(); +puts("options:"); +puts("\t-g convert output to gray"); +puts("\t-k N.N set float value"); +puts("\t-v increase verbosity"); if (verbosity) fimg_print_version(1); exit(0); } @@ -66,6 +76,11 @@ switch (action) { foo = fimg_add(A, B, D); break; case OP_SUB: foo = fimg_sub(A, B, D); break; + case OP_MIX: + if (verbosity) fprintf(stderr, "fvalue is %f\n", + global_fvalue); + foo = fimg_interpolate(A, B, D, global_fvalue); + break; case OP_MUL: foo = fimg_add(A, B, D); break; default: @@ -79,7 +94,6 @@ return foo; int main(int argc, char *argv[]) { int foo, opt, action; -float fvalue; char *operator; FloatImg srcA, srcB, dest; @@ -87,7 +101,7 @@ FloatImg srcA, srcB, dest; while ((opt = getopt(argc, argv, "hk:v")) != -1) { switch(opt) { case 'h': help(0); break; - case 'k': fvalue = atof(optarg); break; + case 'k': global_fvalue = atof(optarg); break; case 'v': verbosity++; break; } } @@ -141,7 +155,8 @@ foo = fimg_create(&dest, srcA.width, srcA.height, srcA.type); foo = exec_operator(&srcA, &srcB, action, &dest); if (foo) { - fprintf(stderr, "operator exec give us a %d\n", foo); + fprintf(stderr, "operator '%s' exec give us a %d\n", + operator, foo); } foo = fimg_dump_to_file(&dest, argv[optind+3], 0);