From 711e54fe4375cbde23e831d5cae087392f30b34a Mon Sep 17 00:00:00 2001 From: tth Date: Thu, 3 Sep 2020 02:00:32 +0200 Subject: [PATCH] histocomputing boilerplate [done] --- funcs/histogram.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++ funcs/t.c | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 funcs/histogram.c diff --git a/funcs/histogram.c b/funcs/histogram.c new file mode 100644 index 00000000..158e3920 --- /dev/null +++ b/funcs/histogram.c @@ -0,0 +1,76 @@ +/* + * FLOATIMG + * calculer un histogramme et l'afficher + */ + +#include +#include +#include + +#include "../floatimg.h" + +extern int verbosity; + +/* --------------------------------------------------------------------- */ +int fimg_calcul_histo(FloatImg *src, long *ghist, int sz) +{ +float maxval; +int x, y, idx; +float rgb[3], moy; + +fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, src, ghist, sz); + +maxval = fimg_get_maxvalue(src); + +fprintf(stderr, "maximum is %f\n", maxval); + +for (y=0; yheight; y++) { + for(x=0; xwidth; x++) { + fimg_get_rgb(src, x, y, rgb); + moy = (rgb[0]+rgb[1]+rgb[2]) / 3.0; + + /* ok, here the had math part ... */ + idx = (int)( (moy*sz) / maxval); + + /* sanity check */ + if (idx<0 || idx>=sz) { + fprintf(stderr, "idx = %d, error\n", idx); + abort(); + } + + ghist[idx]++; + } + } + +return -66; +} +/* --------------------------------------------------------------------- */ + +#define NSLICES 999 + +int fimg_essai_histo(FloatImg *src, char *outpic, int k) +{ +long histo[NSLICES]; +int foo; +FILE *pipe; + +fprintf(stderr, ">>> %s ( %p '%s' %d )\n", __func__, src, outpic, k); + +memset(histo, 0, NSLICES*sizeof(long)); + +foo = fimg_calcul_histo(src, histo, NSLICES); + +for (foo=0; foo