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>
|
2021-05-20 18:31:28 +11:00
|
|
|
#include <stdint.h>
|
2019-09-13 04:48:12 +11:00
|
|
|
#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,
|
2021-04-10 04:04:59 +11:00
|
|
|
Displace, ReadPNG, Plasmas, Hilight, OpenEXR,
|
2021-10-05 09:35:56 +11:00
|
|
|
Geometrie, FileType, Mirror, KillRGB };
|
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 },
|
2021-02-04 05:33:38 +11:00
|
|
|
{ "plasma", Plasmas },
|
2021-03-21 05:47:42 +11:00
|
|
|
{ "hilight", Hilight },
|
2021-03-21 19:02:55 +11:00
|
|
|
{ "openexr", OpenEXR },
|
2021-04-10 04:04:59 +11:00
|
|
|
{ "geometrie", Geometrie, },
|
2021-04-23 20:15:56 +11:00
|
|
|
{ "filetype", FileType },
|
2021-04-26 20:43:42 +11:00
|
|
|
{ "mirror", Mirror },
|
2021-10-05 09:35:56 +11:00
|
|
|
{ "killrgb", KillRGB },
|
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;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
2021-03-17 21:13:29 +11:00
|
|
|
void list_tests(void)
|
|
|
|
{
|
|
|
|
Command *pcmd = commands;
|
|
|
|
while (pcmd->name) {
|
|
|
|
printf("%s\n", pcmd->name);
|
|
|
|
pcmd++;
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
2020-04-12 08:18:33 +11:00
|
|
|
void help(int k)
|
|
|
|
{
|
|
|
|
Command *pcmd;
|
|
|
|
|
2021-02-04 05:33:38 +11:00
|
|
|
fprintf(stderr, "usage:\n\t./t [options] command [filename]\n");
|
2020-10-16 20:20:10 +11:00
|
|
|
|
|
|
|
fprintf(stderr, "options:\n");
|
2021-03-17 21:13:29 +11:00
|
|
|
fprintf(stderr, "\t-k 1.414\tset float value\n");
|
|
|
|
fprintf(stderr, "\t-l\t\tlist tests\n");
|
|
|
|
fprintf(stderr, "\t-o \t\toutfile\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;
|
2021-02-04 05:33:38 +11:00
|
|
|
outfile = "out.pnm";
|
2020-10-27 02:45:36 +11:00
|
|
|
command = "none";
|
2021-02-04 05:33:38 +11:00
|
|
|
filename = "in.fimg";
|
2020-02-17 02:21:27 +11:00
|
|
|
|
2021-03-17 21:13:29 +11:00
|
|
|
while ((opt = getopt(argc, argv, "hk:lo:p:v")) != -1) {
|
|
|
|
// fprintf(stderr, "opt = %c\n", opt);
|
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;
|
2021-03-17 21:13:29 +11:00
|
|
|
case 'l': list_tests(); 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);
|
2020-02-26 10:14:47 +11:00
|
|
|
|
2021-02-04 05:33:38 +11:00
|
|
|
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;
|
2020-04-12 08:18:33 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
if (verbosity) {
|
2021-02-04 05:33:38 +11:00
|
|
|
fprintf(stderr, "++++++++ %s : running command '%s' on '%s'\n",
|
2020-10-07 01:30:42 +11:00
|
|
|
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:
|
2021-03-17 21:13:29 +11:00
|
|
|
foo = essai_ecriture_fits("out.fits");
|
2020-07-24 19:38:13 +11:00
|
|
|
break;
|
|
|
|
case Wpng:
|
2021-03-17 21:13:29 +11:00
|
|
|
foo = essai_ecriture_png("out.png");
|
2020-08-22 11:16:13 +11:00
|
|
|
break;
|
|
|
|
case Wtiff:
|
2021-03-17 21:13:29 +11:00
|
|
|
foo = essai_ecriture_tiff("out.tiff");
|
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:
|
2021-03-17 21:13:29 +11:00
|
|
|
// not ready for primtime
|
|
|
|
// foo = fimg_essai_hsv(filename);
|
|
|
|
foo = 0;
|
2020-09-09 07:55:17 +11:00
|
|
|
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:
|
2020-10-20 09:28:33 +11:00
|
|
|
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:
|
2020-10-20 09:28:33 +11:00
|
|
|
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:
|
2021-03-17 21:13:29 +11:00
|
|
|
// not ready for primetime
|
|
|
|
// foo = essai_lecture_png("in.png", outfile, 0);
|
|
|
|
foo = 0;
|
2020-11-10 00:27:28 +11:00
|
|
|
break;
|
2021-02-04 05:33:38 +11:00
|
|
|
case Plasmas:
|
2021-02-11 02:19:15 +11:00
|
|
|
foo = essai_plasma(filename, outfile, 1, global_fvalue);
|
2021-02-04 05:33:38 +11:00
|
|
|
fprintf(stderr, "we are all plasmafields\n");
|
|
|
|
break;
|
2021-03-17 21:13:29 +11:00
|
|
|
case Rotate:
|
|
|
|
fprintf(stderr, "rotate not implemented (%d)\n", rand());
|
|
|
|
foo = 0;
|
|
|
|
break;
|
2021-03-21 05:47:42 +11:00
|
|
|
case Hilight:
|
|
|
|
foo = essai_highlights(filename, outfile, 0, global_fvalue);
|
|
|
|
break;
|
2021-03-21 19:02:55 +11:00
|
|
|
case OpenEXR:
|
|
|
|
foo = essai_openexr(filename, outfile, 0x55);
|
|
|
|
break;
|
2021-04-10 04:04:59 +11:00
|
|
|
case Geometrie:
|
|
|
|
foo = essai_geometrie(filename, 0);
|
|
|
|
break;
|
2021-04-23 20:15:56 +11:00
|
|
|
case FileType:
|
|
|
|
foo = essai_detect_type();
|
|
|
|
break;
|
2021-04-26 20:43:42 +11:00
|
|
|
case Mirror:
|
|
|
|
foo = essai_miroir(filename, outfile, 0);
|
|
|
|
break;
|
2021-10-05 09:35:56 +11:00
|
|
|
case KillRGB:
|
|
|
|
foo = essai_killrgb(filename, outfile);
|
|
|
|
break;
|
2020-04-12 08:18:33 +11:00
|
|
|
default:
|
2021-03-17 21:13:29 +11:00
|
|
|
fprintf(stderr, "'%s' is a bad command\n", command);
|
2020-04-12 08:18:33 +11:00
|
|
|
exit(1);
|
2020-02-26 10:14:47 +11:00
|
|
|
|
2020-03-01 07:59:12 +11:00
|
|
|
}
|
|
|
|
|
2020-02-17 02:21:27 +11:00
|
|
|
if (foo) {
|
2021-03-17 21:13:29 +11:00
|
|
|
fprintf(stderr, "******* Essai --> %d\n", foo);
|
2020-02-17 02:21:27 +11:00
|
|
|
}
|
2019-10-31 01:49:53 +11:00
|
|
|
|
2021-03-17 21:13:29 +11:00
|
|
|
fprintf(stderr, "++++++++++++ end of '%s' pid %d\n", command, getpid());
|
2019-10-31 01:49:53 +11:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|