From 3cf887e1039a53e29b90ec4c2dc2c7ded22e55ff Mon Sep 17 00:00:00 2001 From: tth Date: Mon, 7 Sep 2020 13:13:03 +0200 Subject: [PATCH] more cleanup --- funcs/histogram.c | 26 ++++++++++++++++---------- funcs/t.c | 9 ++++++--- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/funcs/histogram.c b/funcs/histogram.c index 322e3f0..f10118c 100644 --- a/funcs/histogram.c +++ b/funcs/histogram.c @@ -48,37 +48,43 @@ return -66; } /* --------------------------------------------------------------------- */ -#define NSLICES 1000 - -int fimg_essai_histo(FloatImg *src, char *outpic, int k) +int fimg_essai_histo(FloatImg *src, char *outpic, int nbslices) { -long histo[NSLICES]; +long *histo; int foo; FILE *pipe; -fprintf(stderr, ">>> %s ( %p '%s' %d )\n", __func__, src, outpic, k); +fprintf(stderr, ">>> %s ( %p '%s' %d )\n", __func__, src, outpic, nbslices); -memset(histo, 0, NSLICES*sizeof(long)); +if (NULL==(histo=calloc(nbslices, sizeof(long)))) { + fprintf(stderr, "OUT OF MEMORY\n"); + abort(); + } -foo = fimg_calcul_histo(src, histo, NSLICES); +foo = fimg_calcul_histo(src, histo, nbslices); // for (foo=0; foo>> %s ( '%s' %d )\n", __func__, fname, k); foo = fimg_create_from_dump(fname, &fimg); @@ -419,13 +420,15 @@ if (foo) { foo = fimg_essai_histo(&fimg, "out.png", k); if (foo) { - fprintf(stderr, "essai_histo -> %d\n", foo); + fprintf(stderr, "essai_histo -> error %d\n", foo); return foo; } +fimg_destroy(&fimg); + fprintf(stderr, "\\o/ end of %s\n", __func__); -return -1; +return 0; } /* --------------------------------------------------------------------- */ enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff, @@ -536,7 +539,7 @@ switch(opt) { foo = essai_ecriture_tiff(filename); break; case Histo: - foo = essai_histogramme(filename, 0); + foo = essai_histogramme(filename, 98765); break; default: fprintf(stderr, "%s : bad command\n", command);