FloatImg/funcs/t.c

294 lines
6.8 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>
2021-05-20 09:31:28 +02:00
#include <stdint.h>
2019-09-12 19:48:12 +02:00
#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,
2021-04-09 19:04:59 +02:00
Displace, ReadPNG, Plasmas, Hilight, OpenEXR,
2021-10-10 23:38:10 +02:00
Geometrie, FileType, Mirror, KillRGB,
2021-11-26 23:10:29 +01:00
Pixelize,SplitLevel, DecompRgbz, DecompRgbg,
2022-11-01 09:35:40 +01:00
Rectangle, Dicom, Fakolor0, Fakolor3,
2024-04-01 17:49:14 +02:00
Fmorpho0, Fluffy, ThermoCol, TriPtyq };
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 },
2021-02-03 19:33:38 +01:00
{ "plasma", Plasmas },
2021-03-20 19:47:42 +01:00
{ "hilight", Hilight },
2021-03-21 09:02:55 +01:00
{ "openexr", OpenEXR },
2021-04-09 19:04:59 +02:00
{ "geometrie", Geometrie, },
2021-04-23 11:15:56 +02:00
{ "filetype", FileType },
2021-04-26 11:43:42 +02:00
{ "mirror", Mirror },
2021-10-05 00:35:56 +02:00
{ "killrgb", KillRGB },
2021-10-10 23:38:10 +02:00
{ "pixelize", Pixelize },
2021-10-15 23:21:02 +02:00
{ "spltlvl", SplitLevel },
{ "decomprgbz", DecompRgbz },
2021-11-26 23:10:29 +01:00
{ "decomprgbg", DecompRgbg },
2021-10-19 03:56:56 +02:00
{ "rectangle", Rectangle },
2021-11-27 00:01:37 +01:00
{ "dicom", Dicom },
2022-05-18 11:55:01 +02:00
{ "fakolor0", Fakolor0 },
{ "fakolor3", Fakolor3 },
2022-11-01 09:35:40 +01:00
{ "fmorpho0", Fmorpho0 },
{ "fluffy", Fluffy },
2024-03-20 18:44:06 +01:00
{ "thermocol", ThermoCol },
2024-04-01 17:49:14 +02:00
{ "triptyq", TriPtyq },
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;
}
/* --------------------------------------------------------------------- */
2021-03-17 11:13:29 +01:00
void list_tests(void)
{
Command *pcmd = commands;
while (pcmd->name) {
printf("%s\n", pcmd->name);
pcmd++;
}
exit(0);
}
/* --------------------------------------------------------------------- */
2020-04-11 23:18:33 +02:00
void help(int k)
{
Command *pcmd;
2021-02-03 19:33:38 +01:00
fprintf(stderr, "usage:\n\t./t [options] command [filename]\n");
2020-10-16 11:20:10 +02:00
fprintf(stderr, "options:\n");
2021-03-17 11:13:29 +01: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");
2022-11-01 09:35:40 +01:00
fprintf(stderr, "\t-v \t\tincrease verbosity\n");
2020-04-11 23:18:33 +02:00
2022-11-01 09:35:40 +01:00
if (verbosity) {
fprintf(stderr, "commands:\n");
pcmd = commands;
while (pcmd->name) {
fprintf(stderr, "\t%-15s %d\n", pcmd->name, pcmd->Cmd);
pcmd++;
}
2020-04-11 23:18:33 +02:00
}
2022-11-01 09:35:40 +01:00
2020-04-11 23:18:33 +02:00
fprintf(stderr, "\ncompiled on "__DATE__" at "__TIME__"\n");
2022-02-04 23:39:52 +01:00
if (k) fimg_print_version(k);
2020-04-11 23:18:33 +02:00
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;
2021-02-03 19:33:38 +01:00
outfile = "out.pnm";
2020-10-26 16:45:36 +01:00
command = "none";
2021-02-03 19:33:38 +01:00
filename = "in.fimg";
2020-02-16 16:21:27 +01:00
2021-03-17 11:13:29 +01:00
while ((opt = getopt(argc, argv, "hk:lo:p:v")) != -1) {
// fprintf(stderr, "opt = %c\n", opt);
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;
2021-03-17 11:13:29 +01:00
case 'l': list_tests(); 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);
2021-02-03 19:33:38 +01: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-11 23:18:33 +02:00
}
if (verbosity) {
2021-02-03 19:33:38 +01:00
fprintf(stderr, "++++++++ %s : running command '%s' on '%s'\n",
2020-10-06 16:30:42 +02:00
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:
2021-03-17 11:13:29 +01:00
foo = essai_ecriture_fits("out.fits");
2020-07-24 10:38:13 +02:00
break;
case Wpng:
2021-03-17 11:13:29 +01:00
foo = essai_ecriture_png("out.png");
2020-08-22 02:16:13 +02:00
break;
case Wtiff:
2021-03-17 11:13:29 +01:00
foo = essai_ecriture_tiff("out.tiff");
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:
2021-03-17 11:13:29 +01:00
// not ready for primtime
// foo = fimg_essai_hsv(filename);
foo = 0;
2020-09-08 22:55:17 +02:00
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:
2021-03-17 11:13:29 +01:00
// not ready for primetime
// foo = essai_lecture_png("in.png", outfile, 0);
foo = 0;
2020-11-09 14:27:28 +01:00
break;
2021-02-03 19:33:38 +01:00
case Plasmas:
2021-02-10 16:19:15 +01:00
foo = essai_plasma(filename, outfile, 1, global_fvalue);
2021-02-03 19:33:38 +01:00
fprintf(stderr, "we are all plasmafields\n");
break;
2021-03-17 11:13:29 +01:00
case Rotate:
fprintf(stderr, "rotate not implemented (%d)\n", rand());
foo = 0;
break;
2021-03-20 19:47:42 +01:00
case Hilight:
foo = essai_highlights(filename, outfile, 0, global_fvalue);
break;
2021-03-21 09:02:55 +01:00
case OpenEXR:
foo = essai_openexr(filename, outfile, 0x55);
break;
2021-04-09 19:04:59 +02:00
case Geometrie:
foo = essai_geometrie(filename, 0);
break;
2021-04-23 11:15:56 +02:00
case FileType:
foo = essai_detect_type();
break;
2021-04-26 11:43:42 +02:00
case Mirror:
foo = essai_miroir(filename, outfile, 0);
break;
2021-10-05 00:35:56 +02:00
case KillRGB:
foo = essai_killrgb(filename, outfile);
break;
2021-10-10 23:38:10 +02:00
case Pixelize:
foo = essai_pixelize(filename, outfile);
break;
2021-10-15 23:21:02 +02:00
case SplitLevel:
foo = essai_split_level(filename, outfile, 0);
break;
case DecompRgbz:
2021-10-25 20:49:10 +02:00
foo = essai_decomprgb_color(filename, outfile);
2021-10-15 23:21:02 +02:00
break;
2021-11-26 23:10:29 +01:00
case DecompRgbg:
foo = essai_decomprgb_gray(filename, outfile);
break;
2021-10-19 03:56:56 +02:00
case Rectangle:
essai_rectangle(outfile, 0);
break;
2021-11-27 00:01:37 +01:00
case Dicom:
foo = essai_dicom(filename, outfile, 0);
break;
2022-05-18 11:55:01 +02:00
case Fakolor0:
foo = essai_0_fausses_couleurs(outfile, 0);
break;
2022-11-01 09:35:40 +01:00
case Fmorpho0:
foo = essai_fmorpho_0(filename, "/tmp/fmorpho", 0);
break;
case Fluffy:
foo = essai_rndfluffy(filename, outfile, 0);
break;
2024-03-20 18:44:06 +01:00
case ThermoCol:
foo = essai_thermocol(filename, outfile);
fprintf(stderr, "retour thermocolor = %d\n", foo);
break;
2024-04-01 17:49:14 +02:00
case TriPtyq:
foo = essai_triptyq(filename, outfile);
fprintf(stderr, "retour triptyq = %d\n", foo);
break;
2024-03-20 18:44:06 +01:00
2020-04-11 23:18:33 +02:00
default:
2021-03-17 11:13:29 +01:00
fprintf(stderr, "'%s' is a bad command\n", command);
2020-04-11 23:18:33 +02:00
exit(1);
2020-02-29 21:59:12 +01:00
}
2020-02-16 16:21:27 +01:00
if (foo) {
2022-05-18 11:55:01 +02:00
fprintf(stderr, "******* essai --> %d\n\n", foo);
2020-02-16 16:21:27 +01:00
}
2019-10-30 15:49:53 +01:00
2021-03-17 11:13:29 +01:00
fprintf(stderr, "++++++++++++ end of '%s' pid %d\n", command, getpid());
2019-10-30 15:49:53 +01:00
return 0;
}
/* --------------------------------------------------------------------- */