more cleanup

This commit is contained in:
tth 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 nbslices)
int fimg_essai_histo(FloatImg *src, char *outpic, int k)
{ {
long histo[NSLICES]; long *histo;
int foo; int foo;
FILE *pipe; 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++) { // for (foo=0; foo<NSLICES; foo++) {
// printf("%7d %ld\n", foo, histo[foo]); // printf("%7d %ld\n", foo, histo[foo]);
// } // }
pipe = popen("gnuplot", "w"); 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 term png size 1024,512\n");
fprintf(pipe, "set grid\n"); fprintf(pipe, "set grid\n");
fprintf(pipe, "set output \"%s\"\n", outpic); fprintf(pipe, "set output \"%s\"\n", outpic);
fprintf(pipe, "plot '/dev/stdin' with lines\n"); 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]); fprintf(pipe, "%d %ld\n", foo, histo[foo]);
} }
fclose(pipe); pclose(pipe); // and not fclose (see man page)
free(histo);
return -1; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */

View File

@ -409,6 +409,7 @@ int essai_histogramme(char *fname, int k)
{ {
FloatImg fimg; FloatImg fimg;
int foo; int foo;
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, k); fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, k);
foo = fimg_create_from_dump(fname, &fimg); foo = fimg_create_from_dump(fname, &fimg);
@ -419,13 +420,15 @@ if (foo) {
foo = fimg_essai_histo(&fimg, "out.png", k); foo = fimg_essai_histo(&fimg, "out.png", k);
if (foo) { if (foo) {
fprintf(stderr, "essai_histo -> %d\n", foo); fprintf(stderr, "essai_histo -> error %d\n", foo);
return foo; return foo;
} }
fimg_destroy(&fimg);
fprintf(stderr, "\\o/ end of %s\n", __func__); fprintf(stderr, "\\o/ end of %s\n", __func__);
return -1; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff, enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
@ -536,7 +539,7 @@ switch(opt) {
foo = essai_ecriture_tiff(filename); foo = essai_ecriture_tiff(filename);
break; break;
case Histo: case Histo:
foo = essai_histogramme(filename, 0); foo = essai_histogramme(filename, 98765);
break; break;
default: default:
fprintf(stderr, "%s : bad command\n", command); fprintf(stderr, "%s : bad command\n", command);