From 5564b24c54346a90947f697cb4b3cbb24ca0c462 Mon Sep 17 00:00:00 2001 From: tTh Date: Wed, 3 Apr 2019 12:09:04 +0200 Subject: [PATCH] enhancing the test proggy --- Makefile | 7 +++--- build.sh | 6 +++-- essai.c | 67 +++++++++++++++++++++++++++++++++++++------------------- 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index b2d1c4e3..0178d04a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ - -# Before running make, you must have -# a look to the 'build.sh' script ! +#################################################### +# Before running make, you must have # +# a look to the 'build.sh' script ! # +#################################################### COPT = -Wall -fpic -g -pg -DDEBUG_LEVEL=0 LDOPT = libfloatimg.a -pg -lm diff --git a/build.sh b/build.sh index 42b27016..bc7302df 100755 --- a/build.sh +++ b/build.sh @@ -1,23 +1,25 @@ #!/bin/bash cd lib -echo EEEEEEEEEE we are in $PWD +echo ============= we are in $PWD make error=$? if [ 0 -ne $error ]; then printf "in %s err %d in %s\n" $PWD $error $0 exit $error fi +echo cd .. cd funcs -echo EEEEEEEEEE we are in $PWD +echo ============= we are in $PWD make error=$? if [ 0 -ne $error ]; then printf "in %s err %d in %s\n" $PWD $error $0 exit $error fi +echo cd .. cd tools diff --git a/essai.c b/essai.c index 0c76fbb5..22cfe758 100644 --- a/essai.c +++ b/essai.c @@ -5,11 +5,14 @@ #include #include +#include #include #include #include "floatimg.h" +int verbosity; + /* --------------------------------------------------------------------- */ int add(FloatImg *a, FloatImg *b) { @@ -51,43 +54,63 @@ fprintf(stderr, "%s = %f seconds\n", __func__, tb); puts(""); } /* --------------------------------------------------------------------- */ +int parse_WxH(char *str, int *pw, int *ph) +{ +// char *ptr; +int foo, w, h; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( '%s' %p %p )\n", __func__, + str, pw, ph); +#endif + +foo = sscanf(str, "%dx%d", &w, &h); +if (2 != foo) { + fprintf(stderr, "%s : arg '%s' is invalid\n", __func__, str); + return foo; + } + +*pw = w; *ph = h; + +return 2; +} +/* --------------------------------------------------------------------- */ +void help(int k) +{ +puts("Options :"); +puts("\t-d WxH\timage size"); +exit(0); +} +/* --------------------------------------------------------------------- */ int main(int argc, char *argv[]) { FloatImg fimgA, fimgB; -int foo; +int foo, opt; +int W = 800, H = 600; double tb; -fimg_print_version(0); +while ((opt = getopt(argc, argv, "d:hv")) != -1) { + switch(opt) { + case 'd': parse_WxH(optarg, &W, &H); + break; + case 'h': help(0); break; + case 'v': verbosity++; break; + } + } -#define W 2000 -#define H 1700 - -fait_un_dessin("dessin.fimg"); +if (verbosity) fimg_print_version(0); fimg_create(&fimgA, W, H, 3); fimg_create(&fimgB, W, H, 3); -fimg_draw_something(&fimgA); - fimg_timer_set(0); fimg_drand48(&fimgB, 100.0); +fimg_drand48(&fimgA, 100.0); +add(&fimgA, &fimgB); tb = fimg_timer_get(0); fprintf(stderr, "%s = %f seconds\n", __func__, tb); - -foo = fimg_save_as_pnm(&fimgB, "drand48.pnm", 0); - -/* -fimg_printhead(&fimgA); fimg_printhead(&fimgB); -fimg_describe(&fimgA, "image A"); -*/ - -add(&fimgA, &fimgB); - -foo = fimg_save_as_pnm(&fimgA, "t.pnm", 0); -fprintf(stderr, "save as pnm -> %d\n", foo); -foo = fimg_dump_to_file(&fimgA, "t.fimg", 0); -fprintf(stderr, "save as fimg -> %d\n", foo); +foo = fimg_save_as_pnm(&fimgA, "drand48.pnm", 0); fimg_destroy(&fimgA); fimg_destroy(&fimgB);