From 149bd0b06c375ff62fdc087c7914bef997fc2e17 Mon Sep 17 00:00:00 2001 From: le vieux Date: Sun, 28 Feb 2021 00:45:09 +0100 Subject: [PATCH] going for a real ride ? --- tools/fimg2text.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/tools/fimg2text.c b/tools/fimg2text.c index f38dac39..2efc19d9 100644 --- a/tools/fimg2text.c +++ b/tools/fimg2text.c @@ -16,7 +16,8 @@ int verbosity; int export_as_machinable(FloatImg *src, char *fname, int steps, int flags) { FILE *fp; -int x, y, idx; +int x, y; +float rgb[3]; #if DEBUG_LEVEL fprintf(stderr, ">>> %25s ( %p '%s' %d )\n", __func__, @@ -25,22 +26,19 @@ fprintf(stderr, ">>> %25s ( %p '%s' %d )\n", __func__, fp = NULL; /* molly guard */ if (strcmp("-", fname)) { /* real file */ - fprintf(stderr, "real file\n"); + fprintf(stderr, "real file '%s'\n", fname); } - else { +else { fprintf(stderr, "kitchen sink\n"); } -idx = 0; fp = stdout; /* XXX */ for (y=0; yheight; y+=steps) { for (x=0; xwidth; x+=steps) { + fimg_get_rgb(src, x, y, rgb); fprintf(fp, "%d %d ", x, y); - fprintf(fp, " %f %f %f\n", - src->R[idx], src->G[idx], src->B[idx]); - idx++; - + fprintf(fp, "%f %f %f\n", rgb[0], rgb[1], rgb[2]); } } @@ -57,13 +55,19 @@ fprintf(stderr, ">>> %s ( %p %g )\n", __func__, pimg, vmax); #endif foo = fimg_get_minmax_rgb(pimg, mmv); -// fimg_print_minmax(mmv, "norm it ?"); +if (foo) { + fprintf(stderr, "%s: ABEND\n", __func__); + abort(); + } maxi = mmv[1]; if (mmv[3] > maxi) maxi = mmv[3]; if (mmv[5] > maxi) maxi = mmv[5]; -// fprintf(stderr, "maximum = %f\n", maxi); coef = vmax / maxi; -// fprintf(stderr, "coef = %f\n", coef); +if (verbosity) { + fprintf(stderr, "mins %f %f %f\n", mmv[0], mmv[2], mmv[4]); + fprintf(stderr, "maxs %f %f %f\n", mmv[1], mmv[3], mmv[5]); + fprintf(stderr, "coef = %f\n", coef); + } sz = pimg->width * pimg->height; @@ -108,9 +112,10 @@ if (foo) { if (verbosity) { fimg_describe(&fimg, srcname); + fprintf(stderr, "normalize to %f\n", norm); } if (norm > 0.0) { - fprintf(stderr, "normalize %p\n", &fimg); + // fprintf(stderr, "normalize %p\n", &fimg); foo = normalize(&fimg, norm); } @@ -139,7 +144,7 @@ int foo, opt; int steps = 16; float norm_val = 222.0; /* < 0 : don't normalize */ -while ((opt = getopt(argc, argv, "hs:v")) != -1) { +while ((opt = getopt(argc, argv, "hn:s:v")) != -1) { switch(opt) { case 'v': verbosity++; break; case 'h': help(1); exit(1); @@ -154,8 +159,9 @@ if (1 != argc-optind) { } foo = convertir_fimg_en_machinable(argv[optind], "-", steps, norm_val); -if (foo) +if (foo) { fprintf(stderr, "%s : got a %d from convertor\n", argv[0], foo); + } return 0; }