FloatImg/funcs/t.c
2021-02-10 16:19:15 +01:00

191 lines
4.1 KiB
C

/*
* tests des fonctions diverses - main file
see also: tests.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pam.h>
#undef DEBUG_LEVEL
#define DEBUG_LEVEL 1
#include "../floatimg.h"
#include "tests.h"
int verbosity;
float global_fvalue;
/* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
Histo, Hsv, Classif, Ctr2x2, Qsortrgb,
Displace, ReadPNG, Plasmas };
typedef struct {
char *name;
int Cmd;
} Command;
Command commands[] = {
{ "equalize", Equalize },
{ "rotate", Rotate },
{ "sfx0", Sfx0 },
{ "f3x3", F3x3 },
{ "mire", MIRE },
{ "wfits", Wfits },
{ "wpng", Wpng },
{ "wtiff", Wtiff },
{ "histo", Histo },
{ "hsv", Hsv },
{ "classif", Classif },
{ "ctr2x2", Ctr2x2 },
{ "qsortrgb", Qsortrgb },
{ "displace", Displace },
{ "readpng", ReadPNG },
{ "plasma", Plasmas },
{ NULL, 0 }
} ;
/* --------------------------------------------------------------------- */
int lookup_cmd(char *cmdtxt)
{
Command *pcmd;
pcmd = commands;
while (pcmd->name) {
if (!strcmp(pcmd->name, cmdtxt)) return pcmd->Cmd;
pcmd++;
}
return -1;
}
/* --------------------------------------------------------------------- */
void help(int k)
{
Command *pcmd;
fprintf(stderr, "usage:\n\t./t [options] command [filename]\n");
fprintf(stderr, "options:\n");
fprintf(stderr, "\t-o outfile\n");
fprintf(stderr, "commands:\n");
pcmd = commands;
while (pcmd->name) {
fprintf(stderr, "\t%-15s %d\n", pcmd->name, pcmd->Cmd);
pcmd++;
}
fprintf(stderr, "\ncompiled on "__DATE__" at "__TIME__"\n");
exit(0);
}
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo, opt;
char *filename, *command, *outfile;
fprintf(stderr, "++++++++ test des fonctions pid=%d\n", getpid());
fprintf(stderr, "++++++++ compiled "__DATE__" at " __TIME__ "\n");
global_fvalue = 1.0;
outfile = "out.pnm";
command = "none";
filename = "in.fimg";
while ((opt = getopt(argc, argv, "hk:o:p:v")) != -1) {
switch(opt) {
case 'h': help(0); break;
case 'k': global_fvalue = atof(optarg); break;
case 'o': outfile = optarg; break;
case 'v': verbosity++; break;
}
}
// fprintf(stderr, "argc %d optind %d\n", argc, optind);
switch (argc-optind) {
case 1: /* only command */
command = argv[optind];
break;
case 2:
command = argv[optind];
filename = argv[optind+1];
break;
default:
fprintf(stderr, "%s: bad command line ?\n", argv[0]);
help(1);
break;
}
if (verbosity) {
fprintf(stderr, "++++++++ %s : running command '%s' on '%s'\n",
argv[0], command, filename);
fprintf(stderr, "global fvalue : %f\n", global_fvalue);
}
opt = lookup_cmd(command);
// fprintf(stderr, "lookup '%s' --> %d\n", command, opt);
switch(opt) {
case Equalize:
foo = essai_equalize(filename); break;
case Sfx0:
foo = essai_sfx0(filename); break;
case F3x3:
foo = essai_filtrage_3x3(filename); break;
case MIRE:
foo = essai_mire(filename, 0);
break;
case Wfits:
foo = essai_ecriture_fits(filename);
break;
case Wpng:
foo = essai_ecriture_png(filename);
break;
case Wtiff:
foo = essai_ecriture_tiff(filename);
break;
case Histo:
foo = essai_histogramme(filename, 98765);
break;
case Hsv:
foo = fimg_essai_hsv(filename);
break;
case Classif:
foo = essai_classif(filename, outfile, global_fvalue);
break;
case Ctr2x2:
foo = essai_contour_2x2(filename, outfile);
break;
case Qsortrgb:
foo = essai_qsort_rgb(filename, outfile);
break;
case Displace:
foo = essai_displacement(filename, outfile);
break;
case ReadPNG:
foo = essai_lecture_png(filename, outfile, 0);
break;
case Plasmas:
foo = essai_plasma(filename, outfile, 1, global_fvalue);
fprintf(stderr, "we are all plasmafields\n");
break;
default:
fprintf(stderr, "%s : bad command\n", command);
exit(1);
}
if (foo) {
fprintf(stderr, "Essai ====> %d\n", foo);
}
fprintf(stderr, "+++++ end of %s pid %d\n", command, getpid());
return 0;
}
/* --------------------------------------------------------------------- */