more cleanup

This commit is contained in:
2020-09-07 13:13:03 +02:00
parent 6228533479
commit 3cf887e103
2 changed files with 22 additions and 13 deletions

View File

@@ -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<NSLICES; foo++) {
// printf("%7d %ld\n", foo, histo[foo]);
// }
pipe = popen("gnuplot", "w");
if (NULL==pipe) {
fprintf(stderr, "%s: error running gnuplot\n", __func__);
return -17;
}
fprintf(pipe, "set term png size 1024,512\n");
fprintf(pipe, "set grid\n");
fprintf(pipe, "set output \"%s\"\n", outpic);
fprintf(pipe, "plot '/dev/stdin' with lines\n");
for (foo=0; foo<NSLICES; foo++) {
for (foo=0; foo<nbslices; foo++) {
fprintf(pipe, "%d %ld\n", foo, histo[foo]);
}
fclose(pipe);
pclose(pipe); // and not fclose (see man page)
free(histo);
return -1;
return 0;
}
/* --------------------------------------------------------------------- */