FloatImg4PythonBinding/funcs/t.c

180 lines
3.9 KiB
C
Raw Normal View History

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