FloatImg4PythonBinding/funcs/t.c

180 lines
3.9 KiB
C
Raw Normal View History

2019-09-13 04:48:12 +11:00
/*
2021-02-01 01:36:03 +11:00
* tests des fonctions diverses - main file
see also: tests.c
2019-09-13 04:48:12 +11:00
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pam.h>
2020-11-10 00:27:28 +11:00
#undef DEBUG_LEVEL
#define DEBUG_LEVEL 1
2020-07-24 19:38:13 +11:00
2019-09-13 04:48:12 +11:00
#include "../floatimg.h"
2021-02-01 01:36:03 +11:00
#include "tests.h"
2019-09-13 04:48:12 +11:00
2020-01-23 08:14:06 +11:00
int verbosity;
2020-02-17 02:21:27 +11:00
float global_fvalue;
2020-10-27 02:45:36 +11:00
/* --------------------------------------------------------------------- */
2020-09-03 10:37:53 +11:00
/* --------------------------------------------------------------------- */
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
2020-10-27 02:45:36 +11:00
Histo, Hsv, Classif, Ctr2x2, Qsortrgb,
2020-11-10 00:27:28 +11:00
Displace, ReadPNG };
2020-04-12 08:18:33 +11:00
typedef struct {
char *name;
int Cmd;
} Command;
Command commands[] = {
{ "equalize", Equalize },
{ "rotate", Rotate },
{ "sfx0", Sfx0 },
{ "f3x3", F3x3 },
2020-07-03 01:55:45 +11:00
{ "mire", MIRE },
2020-07-24 19:38:13 +11:00
{ "wfits", Wfits },
{ "wpng", Wpng },
2020-08-22 11:16:13 +11:00
{ "wtiff", Wtiff },
2020-09-03 10:37:53 +11:00
{ "histo", Histo },
2020-09-09 07:55:17 +11:00
{ "hsv", Hsv },
2020-10-04 22:05:28 +11:00
{ "classif", Classif },
2020-10-07 20:32:23 +11:00
{ "ctr2x2", Ctr2x2 },
2020-10-08 20:24:29 +11:00
{ "qsortrgb", Qsortrgb },
2020-10-27 02:45:36 +11:00
{ "displace", Displace },
2020-11-10 00:27:28 +11:00
{ "readpng", ReadPNG },
2020-04-12 08:18:33 +11:00
{ 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;
2020-10-16 20:20:10 +11:00
fprintf(stderr, "usage:\n\t./t [options] command filename\n");
fprintf(stderr, "options:\n");
fprintf(stderr, "\t-o outfile\n");
2020-04-12 08:18:33 +11:00
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);
}
/* --------------------------------------------------------------------- */
2019-10-31 01:49:53 +11:00
int main(int argc, char *argv[])
{
2020-02-17 02:21:27 +11:00
int foo, opt;
2020-10-16 20:20:10 +11:00
char *filename, *command, *outfile;
2019-10-31 01:49:53 +11:00
2020-09-03 11:00:32 +11:00
fprintf(stderr, "++++++++ test des fonctions pid=%d\n", getpid());
2020-10-27 02:45:36 +11:00
fprintf(stderr, "++++++++ compiled "__DATE__" at " __TIME__ "\n");
2019-12-14 04:18:07 +11:00
2020-10-16 20:20:10 +11:00
global_fvalue = 1.0;
outfile = "out.pnm";
2020-10-27 02:45:36 +11:00
command = "none";
2020-02-17 02:21:27 +11:00
while ((opt = getopt(argc, argv, "hk:o:p:v")) != -1) {
2020-02-17 02:21:27 +11:00
switch(opt) {
2020-04-12 08:18:33 +11:00
case 'h': help(0); break;
2020-02-17 02:21:27 +11:00
case 'k': global_fvalue = atof(optarg); break;
2020-10-16 20:20:10 +11:00
case 'o': outfile = optarg; break;
2020-02-17 02:21:27 +11:00
case 'v': verbosity++; break;
}
}
2020-04-12 08:18:33 +11:00
// fprintf(stderr, "argc %d optind %d\n", argc, optind);
filename = NULL;
2020-04-12 08:18:33 +11:00
if (2 != argc-optind) {
fprintf(stderr, "%s: bad command line\n", argv[0]);
help(1);
}
command = argv[optind];
filename = argv[optind+1];
if (verbosity) {
2020-10-07 01:30:42 +11:00
fprintf(stderr, "%s : running command '%s' on '%s'\n",
argv[0], command, filename);
2020-10-06 21:48:17 +11:00
fprintf(stderr, "global fvalue : %f\n", global_fvalue);
2020-04-12 08:18:33 +11:00
}
opt = lookup_cmd(command);
2020-07-24 19:38:13 +11:00
// fprintf(stderr, "lookup '%s' --> %d\n", command, opt);
2020-04-12 08:18:33 +11:00
switch(opt) {
case Equalize:
foo = essai_equalize(filename); break;
case Sfx0:
foo = essai_sfx0(filename); break;
case F3x3:
foo = essai_filtrage_3x3(filename); break;
2020-07-03 01:55:45 +11:00
case MIRE:
foo = essai_mire(filename, 0);
break;
2020-07-24 19:38:13 +11:00
case Wfits:
foo = essai_ecriture_fits(filename);
break;
case Wpng:
2020-08-22 11:16:13 +11:00
foo = essai_ecriture_png(filename);
break;
case Wtiff:
foo = essai_ecriture_tiff(filename);
2020-07-24 19:38:13 +11:00
break;
2020-09-03 10:37:53 +11:00
case Histo:
2020-09-07 22:13:03 +11:00
foo = essai_histogramme(filename, 98765);
2020-09-03 10:37:53 +11:00
break;
2020-09-09 07:55:17 +11:00
case Hsv:
foo = fimg_essai_hsv(filename);
break;
2020-10-04 22:05:28 +11:00
case Classif:
2021-02-01 01:36:03 +11:00
foo = essai_classif(filename, outfile, global_fvalue);
2020-10-04 22:05:28 +11:00
break;
2020-10-07 20:32:23 +11:00
case Ctr2x2:
foo = essai_contour_2x2(filename, outfile);
2020-10-07 20:32:23 +11:00
break;
2020-10-08 20:24:29 +11:00
case Qsortrgb:
foo = essai_qsort_rgb(filename, outfile);
2020-10-08 20:24:29 +11:00
break;
2020-10-27 02:45:36 +11:00
case Displace:
foo = essai_displacement(filename, outfile);
break;
2020-11-10 00:27:28 +11:00
case ReadPNG:
foo = essai_lecture_png(filename, outfile, 0);
break;
2020-04-12 08:18:33 +11:00
default:
fprintf(stderr, "%s : bad command\n", command);
exit(1);
2020-03-01 07:59:12 +11:00
}
2020-02-17 02:21:27 +11:00
if (foo) {
fprintf(stderr, "Essai ====> %d\n", foo);
2020-02-17 02:21:27 +11:00
}
2019-10-31 01:49:53 +11:00
2020-10-13 00:55:06 +11:00
fprintf(stderr, "+++++ end of %s pid %d\n", command, getpid());
2019-10-31 01:49:53 +11:00
return 0;
}
/* --------------------------------------------------------------------- */