From 445ecf3600316c1d69deb34f9a58cfa98a595803 Mon Sep 17 00:00:00 2001 From: tth Date: Sun, 31 Jan 2021 15:36:03 +0100 Subject: [PATCH] splitting test proggy --- funcs/Makefile | 6 +- funcs/t.c | 608 +---------------------------------------------- funcs/tests.c | 621 +++++++++++++++++++++++++++++++++++++++++++++++++ funcs/tests.h | 26 +++ 4 files changed, 656 insertions(+), 605 deletions(-) create mode 100644 funcs/tests.c create mode 100644 funcs/tests.h diff --git a/funcs/Makefile b/funcs/Makefile index 6c6455d7..8e8c90eb 100644 --- a/funcs/Makefile +++ b/funcs/Makefile @@ -11,8 +11,12 @@ OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \ #--------------------------------------------------------------- -t: t.c $(DEPS) ../libfloatimg.a +tests.o: tests.c tests.h $(DEPS) + gcc $(COPT) -c $< + +t: t.c $(DEPS) ../libfloatimg.a tests.o gcc $(COPT) $< \ + tests.o \ -I/usr/include/netpbm/ \ -I/usr/include/cfitsio/ \ ../libfloatimg.a -lnetpbm -lpnglite -lcfitsio \ diff --git a/funcs/t.c b/funcs/t.c index d76487e6..35279357 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -1,5 +1,6 @@ /* - * tests des fonctions diverses + * tests des fonctions diverses - main file + see also: tests.c */ #include @@ -11,613 +12,12 @@ #define DEBUG_LEVEL 1 #include "../floatimg.h" +#include "tests.h" int verbosity; - float global_fvalue; /* --------------------------------------------------------------------- */ -/* nouveau 24 octobre 2020, pendant le masque-flamme coronavidique */ - -int essai_displacement(char *infile, char *outfile) -{ -int foo; -FloatImg src, dst; - -fprintf(stderr, "%s : loading %s\n", __func__, infile); -foo = fimg_create_from_dump(infile, &src); -if (foo) { - fprintf(stderr, "%s: error loading '%s'\n", __func__, infile); - return foo; - } - -fimg_clone(&src, &dst, 1); - -foo = fimg_displacement_0(&src, &dst, 0); -if (foo) { - fprintf(stderr, "%s: err %d in disp map 0\n", __func__, foo); - return foo; - } - -foo = fimg_export_picture(&dst, outfile, 0); -if (foo) { - fprintf(stderr, "%s : err %d saving result\n", __func__, foo); - return foo; - } - -return 0; -} -/* --------------------------------------------------------------------- */ -/* - * nouveau 7 octobre 2020 pendant sonoptic - * - * inspiration: Olivier Baudu - */ - -int essai_qsort_rgb(char *infile, char *outfile) -{ -FloatImg src, dst; -int foo; - -if (NULL != infile) { - fprintf(stderr, "%s : loading %s\n", __func__, infile); - foo = fimg_create_from_dump(infile, &src); - if (foo) { - fprintf(stderr, "%s: error loading '%s'\n", __func__, infile); - return foo; - } - } -else { - fprintf(stderr, "%s : NOT INPUT FILE, FUBAR\n", __func__); - abort(); - } - -fimg_clone(&src, &dst, 1); - -foo = fimg_qsort_rgb_b(&src, &dst, 0); -if (foo) { - fprintf(stderr, "%s: err %d in qsort_rgb\n", __func__, foo); - return foo; - } - -foo = fimg_export_picture(&dst, outfile, 0); -if (foo) { - fprintf(stderr, "%s : err %d saving result\n", __func__, foo); - return foo; - } - -fimg_destroy(&src); fimg_destroy(&dst); - -return 0; -} - -/* --------------------------------------------------------------------- */ -/* - * nouveau 5 octobre 2020 pendant sonoptic - */ - -int essai_contour_2x2(char *infile, char *outfile) -{ -FloatImg src, dst; -int foo; - -if (NULL != infile) { - fprintf(stderr, "%s : loading %s\n", __func__, infile); - foo = fimg_create_from_dump(infile, &src); - if (foo) { - fprintf(stderr, "%s: error loading '%s'\n", __func__, infile); - return foo; - } - } -else { - fprintf(stderr, "%s : NOT INPUT FILE, FUBAR\n", __func__); - abort(); - } - -fimg_clone(&src, &dst, 1); - -foo = fimg_contour_2x2(&src, &dst, 0); -if (foo) { - fprintf(stderr, "%s: err %d in contour_2x2\n", __func__, foo); - return foo; - } - -foo = fimg_export_picture(&dst, outfile, 0); -if (foo) { - fprintf(stderr, "%s : err %d saving result\n", __func__, foo); - return foo; - } - -fimg_destroy(&src); fimg_destroy(&dst); - -return 0; -} -/* --------------------------------------------------------------------- */ -/* - * nouveau 5 octobre 2020 pendant sonoptic - */ -int essai_classif(char *infile, char *outfile) -{ -FloatImg src, dst; -int foo; - -if (NULL != infile) { - fprintf(stderr, "%s : loading %s\n", __func__, infile); - foo = fimg_create_from_dump(infile, &src); - if (foo) { - fprintf(stderr, "%s: error loading '%s'\n", __func__, infile); - return foo; - } - } -else { - fprintf(stderr, "%s : NOT INPUT FILE, FUBAR\n", __func__); - abort(); - } - -fimg_clone(&src, &dst, 1); - -fprintf(stderr, "%s : fvalue is %f\n", __func__, global_fvalue); - -foo = fimg_classif_trial(&src, &dst, global_fvalue, 0); -if (foo) { - fprintf(stderr, "%s: err %d in classif_trial\n", __func__, foo); - return foo; - } - -foo = fimg_export_picture(&dst, outfile, 0); -if (foo) { - fprintf(stderr, "%s : err %d saving result\n", __func__, foo); - return foo; - } - -fimg_destroy(&src); fimg_destroy(&dst); - -return 0; -} -/* --------------------------------------------------------------------- */ -/* nouveau 19 aout 2020, le matin avant la canicule */ - -int essai_ecriture_tiff(char *outname) -{ -int foo; -FloatImg picz; - -fimg_create(&picz, 800, 600, FIMG_TYPE_RGB); -fimg_test_pattern(&picz, 0, 22222); - -foo = fimg_write_as_tiff(&picz, outname, 0); -if (foo) { - fprintf(stderr, "%s got a %d\n", __func__, foo); - return foo; - } - -return -7; -} -/* --------------------------------------------------------------------- */ -/* essai de fichiers FITS (astronomie) */ -int essai_ecriture_fits(char *outname) -{ -FloatImg src; -int foo; - -fprintf(stderr, "%s is creating the picz\n", __func__); -fimg_create(&src, 512, 512, FIMG_TYPE_RGB); -fimg_test_pattern(&src, 0, 255.0); - -foo = fimg_save_R_as_fits(&src, outname, 0); - -fprintf(stderr, "saving '%s' to fits --> %d\n", outname, foo); - -return -1; -} -/* --------------------------------------------------------------------- */ -/* - * egalisation dynamique approximative - * #coronamaison Thu 09 Apr 2020 03:37:10 PM CEST - */ -int essai_equalize(char *infile) -{ -FloatImg src; -int foo; - -if (NULL != infile) { - fprintf(stderr, "%s: loading %s\n", __func__, infile); - foo = fimg_create_from_dump(infile, &src); - if (foo) { - fprintf(stderr, "%s: err load '%s'\n", __func__, infile); - return foo; - } - } -else { - fprintf(stderr, "%s : NOT INPUT FILE, FUBAR\n", __func__); - abort(); - } - -foo = fimg_equalize_compute(&src, NULL, 666.666); -fprintf(stderr, "equalize compute --> %d\n", foo); - -fimg_destroy(&src); - -return -1; -} -/* --------------------------------------------------------------------- */ -int essai_rotate(char *infile) -{ -FloatImg src, dst; -int foo; - -if (NULL != infile) { - fprintf(stderr, "%s: loading %s\n", __func__, infile); - foo = fimg_create_from_dump(infile, &src); - if (foo) { - fprintf(stderr, "%s: err load '%s'\n", __func__, infile); - return foo; - } - } -else { - fprintf(stderr, "%s : NOT INPUT FILE, FUBAR\n", __func__); - abort(); - } - -fimg_save_as_png(&src, "test.png", 0); - -foo = fimg_rotate_90(&src, &dst, 0); -fprintf(stderr, "rotate 90 -> %d\n", foo); - -foo = fimg_export_picture(&dst, "rotated90.png", 0); -foo = fimg_export_picture(&dst, "rotated90.pnm", 0); - -fimg_destroy(&src); - -return -1; -} -/* --------------------------------------------------------------------- */ -int essai_filtrage_3x3(char *infile) -{ -FloatImg src, dst; -int foo; /// , idx; -// char buffer[100]; - -FimgFilter3x3 filter_a = { - - { 1.0, 1.0, 1.0, - 1.0, -3.0, 1.0, - 1.0, 1.0, 1.0 }, - 8.0, 0.0 - - }; - -FimgFilter3x3 filter_b = { - - { -2.0, -1.0, 0.0, - -1.0, 3.0, 1.0, - 0.0, 1.0, 2.0 }, - 8.0, 0.0 - - }; - -if (NULL != infile) { - fprintf(stderr, "%s: loading %s\n", __func__, infile); - foo = fimg_create_from_dump(infile, &src); - if (foo) { - fprintf(stderr, "%s: err load '%s'\n", __func__, infile); - return foo; - } - } -else { - fprintf(stderr, "%s is creating the picz\n", __func__); - fimg_create(&src, 640, 480, FIMG_TYPE_RGB); - fimg_test_pattern(&src, 0, 255.0); - } - -// fimg_save_as_png(&src, "test.png", 0); - -foo = fimg_clone(&src, &dst, 0); -if (foo) { - fprintf(stderr, "%s: err clone %p\n", __func__, &src); - return -44; - } - -fimg_filter_3x3(&src, &dst, &filter_a); - -foo = fimg_clamp_negativ(&dst); - -if (foo) { - fprintf(stderr, "clamped %d negative pixels\n", foo); - } -// foo = fimg_save_as_png(&dst, "f3x3a.png", 0); -// foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0); - -fimg_filter_3x3(&src, &dst, &filter_b); -foo = fimg_clamp_negativ(&dst); -if (foo) { - fprintf(stderr, "clamped %d negative pixels\n", foo); - } -// foo = fimg_save_as_png(&dst, "f3x3b.png", 0); -// foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0); - -fimg_destroy(&src); fimg_destroy(&dst); - -return 0; -} -/* --------------------------------------------------------------------- */ -int essai_filtrage_2x2(char *infile) -{ -FloatImg fimg; -int foo, idx; -char buffer[100]; - -if (NULL != infile) { - fprintf(stderr, "%s: loading %s\n", __func__, infile); - foo = fimg_create_from_dump(infile, &fimg); - if (foo) { - fprintf(stderr, "%s: err load '%s'\n", __func__, infile); - return foo; - } - } -else { - fprintf(stderr, "%s is creating the picz\n", __func__); - fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB); - fimg_draw_something(&fimg); - } - -foo = fimg_save_as_pnm(&fimg, "source.pnm", 0); - -/* - * running multiple filters so you can - * watch the up-left shift :) - */ -for (idx=0; idx<5; idx++) { - foo = fimg_lissage_2x2(&fimg); - sprintf(buffer, "filter%03d.png", idx); - foo = fimg_save_as_png(&fimg, buffer, 0); - if (verbosity) { - fprintf(stderr, "%s %d\n", buffer, foo); - } - } - -fimg_destroy(&fimg); - -return 0; -} -/* --------------------------------------------------------------------- */ -int essai_geometrie(char *infile) -{ -FloatImg fimg, result; -int foo; - -if (NULL != infile) { - fprintf(stderr, "loading %s\n", infile); - foo = fimg_create_from_dump(infile, &fimg); - if (foo) { - fprintf(stderr, "%s: err load '%s'\n", __func__, infile); - return foo; - } - } -else { - fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB); - fimg_draw_something(&fimg); - } - -foo = fimg_save_as_pnm(&fimg, "source.pnm", 0); - -memset(&result, 0, sizeof(FloatImg)); - -foo = fimg_halfsize_0(&fimg, &result, 0); -fprintf(stderr, "retour halfsize -> %d\n", foo); -if (foo) { - return -2; - } - -if (verbosity) fimg_describe(&result, "result after halfsize"); - -foo = fimg_save_as_pnm(&result, "something.pnm", 0); - -return 0; -} -/* --------------------------------------------------------------------- */ -int essai_sfx0(char *infile) -{ -FloatImg fimg; -int foo; - -if (NULL != infile) { - fprintf(stderr, "loading %s\n", infile); - foo = fimg_create_from_dump(infile, &fimg); - if (foo) { - fprintf(stderr, "%s: err load '%s'\n", __func__, infile); - return foo; - } - } -else { - fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB); - fimg_draw_something(&fimg); - } - -foo = fimg_save_as_pnm(&fimg, "something.pnm", 0); -if (foo) { - fprintf(stderr, "%s: err save %d\n", __func__, foo); - return -6; - } -foo = fimg_killcolors_a(&fimg, 0.0); -foo = fimg_save_as_pnm(&fimg, "colorskilled-a.pnm", 0); -if (foo) { - fprintf(stderr, "%s: err save %d\n", __func__, foo); - return -6; - } - -foo = fimg_killcolors_b(&fimg, 0.0); -foo = fimg_save_as_pnm(&fimg, "colorskilled-b.pnm", 0); -if (foo) { - fprintf(stderr, "%s: err save %d\n", __func__, foo); - return -6; - } - - -return 0; -} -/* --------------------------------------------------------------------- */ -int essai_parse_double(void) -{ -int foo; -double dval; -char *str; - -str = "12.34"; dval = 0.0; -foo = parse_double(str, &dval); -printf("%-10s -> %3d %g\n", str, foo, dval); - -str = "12e4"; dval = 0.0; -foo = parse_double(str, &dval); -printf("%-10s -> %3d %g\n", str, foo, dval); - -str = "5s"; dval = 0.0; -foo = parse_double(str, &dval); -printf("%-10s -> %3d %g\n", str, foo, dval); - -str = "PORN"; dval = 0.0; -foo = parse_double(str, &dval); -printf("%-10s -> %3d %g\n", str, foo, dval); - -return 0; -} -/* --------------------------------------------------------------------- */ -int essai_detect_type(void) -{ -int foo; -char *fname; - -foo = format_from_extension(fname="foo.fimg"); -printf("%-10s %d\n\n", fname, foo); - -foo = format_from_extension(fname="foo.pnm"); -printf("%-10s %d\n\n", fname, foo); - -foo = format_from_extension(fname="foo.png"); -printf("%-10s %d\n\n", fname, foo); - -foo = format_from_extension(fname="foo.tiff"); -printf("%-10s %d\n\n", fname, foo); - -foo = format_from_extension(fname="foo.fits"); -printf("%-10s %d\n\n", fname, foo); - -foo = format_from_extension(fname="foo.xyzzy"); -printf("%-10s %d\n\n", fname, foo); - -return 0; -} -/* --------------------------------------------------------------------- */ -int essai_mire(char *outname, int notused) -{ -FloatImg fimg; -int re; - -fimg_create(&fimg, 1280, 960, FIMG_TYPE_RGB); - -re = fimg_test_pattern(&fimg, 9, 1.0); -if (re) { - fprintf(stderr, "fimg_test_pattern -> %d\n", re); - } -fimg_export_picture(&fimg, "mire.pnm", 0); - -return -1; -} -/* --------------------------------------------------------------------- */ -int essai_rampes(void) -{ -FloatImg fimg; -int foo; - -fimg_create(&fimg, 640, 480, FIMG_TYPE_RGB); - -foo = fimg_hdeg_a(&fimg, (double)3.141592654); -fprintf(stderr, "make h deg -> %d\n", foo); -foo = fimg_save_as_pnm(&fimg, "hdeg.pnm", 0); -fprintf(stderr, "%s: save as pnm -> %d\n", __func__, foo); - -foo = fimg_vdeg_a(&fimg, (double)3.141592654); -fprintf(stderr, "make h deg -> %d\n", foo); -foo = fimg_save_as_pnm(&fimg, "vdeg.pnm", 0); -fprintf(stderr, "%s: save as pnm -> %d\n", __func__, foo); - -return 0; -} -/* --------------------------------------------------------------------- */ -int essai_lecture_png(char *fname, char *outfile, int notused) -{ -FloatImg fimg; -int foo; - -fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused); - -memset(&fimg, 0, sizeof(FloatImg)); -foo = fimg_create_from_png(fname, &fimg); -if (foo) { - fprintf(stderr, "%s: createfrom -> %d\n", __func__, foo); - return foo; - } -fimg_describe(&fimg, "created from png"); - -foo = fimg_export_picture(&fimg, outfile, 0); -if (foo) { - fprintf(stderr, "%s : err %d saving result to %s\n", __func__, - foo, outfile); - return foo; - } -return 0; -} -/* --------------------------------------------------------------------- */ -int essai_ecriture_png(char *fname) -{ -FloatImg fimg; -int foo; - -fimg_create(&fimg, 800, 600, FIMG_TYPE_RGB); - -fimg_draw_something(&fimg); - -if (verbosity) { - foo = fimg_save_as_pnm(&fimg, "quux.pnm", 0); - fprintf(stderr, "%s: save as pnm -> %d\n", __func__, foo); - } - -foo = fimg_save_as_png(&fimg, fname, 0); -fprintf(stderr, "save as png -> %d\n", foo); - -return 0; -} -/* --------------------------------------------------------------------- */ - -int fimg_essai_histo(FloatImg *src, char *outpic, int k); /* histogram.c */ -int fimg_essai_hsv(char *fname); /* hsv.c */ - - -int essai_histogramme(char *fname, int k) -{ -FloatImg fimg; -int foo; - -fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, k); - -foo = fimg_create_from_dump(fname, &fimg); -if (foo) { - fprintf(stderr, "%s: err load '%s'\n", __func__, fname); - return foo; - } - -foo = fimg_essai_histo(&fimg, "out.png", k); -if (foo) { - fprintf(stderr, "essai_histo -> error %d\n", foo); - return foo; - } - -fimg_destroy(&fimg); - -fprintf(stderr, "\\o/ end of %s\n", __func__); - -return 0; -} /* --------------------------------------------------------------------- */ enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff, Histo, Hsv, Classif, Ctr2x2, Qsortrgb, @@ -749,7 +149,7 @@ switch(opt) { foo = fimg_essai_hsv(filename); break; case Classif: - foo = essai_classif(filename, outfile); + foo = essai_classif(filename, outfile, global_fvalue); break; case Ctr2x2: foo = essai_contour_2x2(filename, outfile); diff --git a/funcs/tests.c b/funcs/tests.c new file mode 100644 index 00000000..28ed2304 --- /dev/null +++ b/funcs/tests.c @@ -0,0 +1,621 @@ +/* + * tests des fonctions diverses - subroutines + see also: t.c + */ + +#include +#include +#include +#include + +#undef DEBUG_LEVEL +#define DEBUG_LEVEL 1 + +#include "../floatimg.h" +#include "tests.h" + +extern int verbosity; + +/* --------------------------------------------------------------------- */ +/* nouveau 24 octobre 2020, pendant le masque-flamme coronavidique */ + +int essai_displacement(char *infile, char *outfile) +{ +int foo; +FloatImg src, dst; + +fprintf(stderr, "%s : loading %s\n", __func__, infile); +foo = fimg_create_from_dump(infile, &src); +if (foo) { + fprintf(stderr, "%s: error loading '%s'\n", __func__, infile); + return foo; + } + +fimg_clone(&src, &dst, 1); + +foo = fimg_displacement_0(&src, &dst, 0); +if (foo) { + fprintf(stderr, "%s: err %d in disp map 0\n", __func__, foo); + return foo; + } + +foo = fimg_export_picture(&dst, outfile, 0); +if (foo) { + fprintf(stderr, "%s : err %d saving result\n", __func__, foo); + return foo; + } + +return 0; +} +/* --------------------------------------------------------------------- */ +/* + * nouveau 7 octobre 2020 pendant sonoptic + * + * inspiration: Olivier Baudu + */ + +int essai_qsort_rgb(char *infile, char *outfile) +{ +FloatImg src, dst; +int foo; + +if (NULL != infile) { + fprintf(stderr, "%s : loading %s\n", __func__, infile); + foo = fimg_create_from_dump(infile, &src); + if (foo) { + fprintf(stderr, "%s: error loading '%s'\n", __func__, infile); + return foo; + } + } +else { + fprintf(stderr, "%s : NOT INPUT FILE, FUBAR\n", __func__); + abort(); + } + +fimg_clone(&src, &dst, 1); + +foo = fimg_qsort_rgb_b(&src, &dst, 0); +if (foo) { + fprintf(stderr, "%s: err %d in qsort_rgb\n", __func__, foo); + return foo; + } + +foo = fimg_export_picture(&dst, outfile, 0); +if (foo) { + fprintf(stderr, "%s : err %d saving result\n", __func__, foo); + return foo; + } + +fimg_destroy(&src); fimg_destroy(&dst); + +return 0; +} + +/* --------------------------------------------------------------------- */ +/* + * nouveau 5 octobre 2020 pendant sonoptic + */ + +int essai_contour_2x2(char *infile, char *outfile) +{ +FloatImg src, dst; +int foo; + +if (NULL != infile) { + fprintf(stderr, "%s : loading %s\n", __func__, infile); + foo = fimg_create_from_dump(infile, &src); + if (foo) { + fprintf(stderr, "%s: error loading '%s'\n", __func__, infile); + return foo; + } + } +else { + fprintf(stderr, "%s : NOT INPUT FILE, FUBAR\n", __func__); + abort(); + } + +fimg_clone(&src, &dst, 1); + +foo = fimg_contour_2x2(&src, &dst, 0); +if (foo) { + fprintf(stderr, "%s: err %d in contour_2x2\n", __func__, foo); + return foo; + } + +foo = fimg_export_picture(&dst, outfile, 0); +if (foo) { + fprintf(stderr, "%s : err %d saving result\n", __func__, foo); + return foo; + } + +fimg_destroy(&src); fimg_destroy(&dst); + +return 0; +} +/* --------------------------------------------------------------------- */ +/* + * nouveau 5 octobre 2020 pendant sonoptic + */ +int essai_classif(char *infile, char *outfile, float fvalue) +{ +FloatImg src, dst; +int foo; + +if (NULL != infile) { + fprintf(stderr, "%s : loading %s\n", __func__, infile); + foo = fimg_create_from_dump(infile, &src); + if (foo) { + fprintf(stderr, "%s: error loading '%s'\n", __func__, infile); + return foo; + } + } +else { + fprintf(stderr, "%s : NOT INPUT FILE, FUBAR\n", __func__); + abort(); + } + +fimg_clone(&src, &dst, 1); + +fprintf(stderr, "%s : fvalue is %f\n", __func__, fvalue); + +foo = fimg_classif_trial(&src, &dst, fvalue, 0); +if (foo) { + fprintf(stderr, "%s: err %d in classif_trial\n", __func__, foo); + return foo; + } + +foo = fimg_export_picture(&dst, outfile, 0); +if (foo) { + fprintf(stderr, "%s : err %d saving result\n", __func__, foo); + return foo; + } + +fimg_destroy(&src); fimg_destroy(&dst); + +return 0; +} +/* --------------------------------------------------------------------- */ +/* nouveau 19 aout 2020, le matin avant la canicule */ + +int essai_ecriture_tiff(char *outname) +{ +int foo; +FloatImg picz; + +fimg_create(&picz, 800, 600, FIMG_TYPE_RGB); +fimg_test_pattern(&picz, 0, 22222); + +foo = fimg_write_as_tiff(&picz, outname, 0); +if (foo) { + fprintf(stderr, "%s got a %d\n", __func__, foo); + return foo; + } + +return -7; +} +/* --------------------------------------------------------------------- */ +/* essai de fichiers FITS (astronomie) */ +int essai_ecriture_fits(char *outname) +{ +FloatImg src; +int foo; + +fprintf(stderr, "%s is creating the picz\n", __func__); +fimg_create(&src, 512, 512, FIMG_TYPE_RGB); +fimg_test_pattern(&src, 0, 255.0); + +foo = fimg_save_R_as_fits(&src, outname, 0); + +fprintf(stderr, "saving '%s' to fits --> %d\n", outname, foo); + +return -1; +} +/* --------------------------------------------------------------------- */ +/* + * egalisation dynamique approximative + * #coronamaison Thu 09 Apr 2020 03:37:10 PM CEST + */ +int essai_equalize(char *infile) +{ +FloatImg src; +int foo; + +if (NULL != infile) { + fprintf(stderr, "%s: loading %s\n", __func__, infile); + foo = fimg_create_from_dump(infile, &src); + if (foo) { + fprintf(stderr, "%s: err load '%s'\n", __func__, infile); + return foo; + } + } +else { + fprintf(stderr, "%s : NOT INPUT FILE, FUBAR\n", __func__); + abort(); + } + +foo = fimg_equalize_compute(&src, NULL, 666.666); +fprintf(stderr, "equalize compute --> %d\n", foo); + +fimg_destroy(&src); + +return -1; +} +/* --------------------------------------------------------------------- */ +int essai_rotate(char *infile) +{ +FloatImg src, dst; +int foo; + +if (NULL != infile) { + fprintf(stderr, "%s: loading %s\n", __func__, infile); + foo = fimg_create_from_dump(infile, &src); + if (foo) { + fprintf(stderr, "%s: err load '%s'\n", __func__, infile); + return foo; + } + } +else { + fprintf(stderr, "%s : NOT INPUT FILE, FUBAR\n", __func__); + abort(); + } + +fimg_save_as_png(&src, "test.png", 0); + +foo = fimg_rotate_90(&src, &dst, 0); +fprintf(stderr, "rotate 90 -> %d\n", foo); + +foo = fimg_export_picture(&dst, "rotated90.png", 0); +foo = fimg_export_picture(&dst, "rotated90.pnm", 0); + +fimg_destroy(&src); + +return -1; +} +/* --------------------------------------------------------------------- */ +int essai_filtrage_3x3(char *infile) +{ +FloatImg src, dst; +int foo; /// , idx; +// char buffer[100]; + +FimgFilter3x3 filter_a = { + + { 1.0, 1.0, 1.0, + 1.0, -3.0, 1.0, + 1.0, 1.0, 1.0 }, + 8.0, 0.0 + + }; + +FimgFilter3x3 filter_b = { + + { -2.0, -1.0, 0.0, + -1.0, 3.0, 1.0, + 0.0, 1.0, 2.0 }, + 8.0, 0.0 + + }; + +if (NULL != infile) { + fprintf(stderr, "%s: loading %s\n", __func__, infile); + foo = fimg_create_from_dump(infile, &src); + if (foo) { + fprintf(stderr, "%s: err load '%s'\n", __func__, infile); + return foo; + } + } +else { + fprintf(stderr, "%s is creating the picz\n", __func__); + fimg_create(&src, 640, 480, FIMG_TYPE_RGB); + fimg_test_pattern(&src, 0, 255.0); + } + +// fimg_save_as_png(&src, "test.png", 0); + +foo = fimg_clone(&src, &dst, 0); +if (foo) { + fprintf(stderr, "%s: err clone %p\n", __func__, &src); + return -44; + } + +fimg_filter_3x3(&src, &dst, &filter_a); + +foo = fimg_clamp_negativ(&dst); + +if (foo) { + fprintf(stderr, "clamped %d negative pixels\n", foo); + } +// foo = fimg_save_as_png(&dst, "f3x3a.png", 0); +// foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0); + +fimg_filter_3x3(&src, &dst, &filter_b); +foo = fimg_clamp_negativ(&dst); +if (foo) { + fprintf(stderr, "clamped %d negative pixels\n", foo); + } +// foo = fimg_save_as_png(&dst, "f3x3b.png", 0); +// foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0); + +fimg_destroy(&src); fimg_destroy(&dst); + +return 0; +} +/* --------------------------------------------------------------------- */ +int essai_filtrage_2x2(char *infile) +{ +FloatImg fimg; +int foo, idx; +char buffer[100]; + +if (NULL != infile) { + fprintf(stderr, "%s: loading %s\n", __func__, infile); + foo = fimg_create_from_dump(infile, &fimg); + if (foo) { + fprintf(stderr, "%s: err load '%s'\n", __func__, infile); + return foo; + } + } +else { + fprintf(stderr, "%s is creating the picz\n", __func__); + fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB); + fimg_draw_something(&fimg); + } + +foo = fimg_save_as_pnm(&fimg, "source.pnm", 0); + +/* + * running multiple filters so you can + * watch the up-left shift :) + */ +for (idx=0; idx<5; idx++) { + foo = fimg_lissage_2x2(&fimg); + sprintf(buffer, "filter%03d.png", idx); + foo = fimg_save_as_png(&fimg, buffer, 0); + if (verbosity) { + fprintf(stderr, "%s %d\n", buffer, foo); + } + } + +fimg_destroy(&fimg); + +return 0; +} +/* --------------------------------------------------------------------- */ +int essai_geometrie(char *infile) +{ +FloatImg fimg, result; +int foo; + +if (NULL != infile) { + fprintf(stderr, "loading %s\n", infile); + foo = fimg_create_from_dump(infile, &fimg); + if (foo) { + fprintf(stderr, "%s: err load '%s'\n", __func__, infile); + return foo; + } + } +else { + fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB); + fimg_draw_something(&fimg); + } + +foo = fimg_save_as_pnm(&fimg, "source.pnm", 0); + +memset(&result, 0, sizeof(FloatImg)); + +foo = fimg_halfsize_0(&fimg, &result, 0); +fprintf(stderr, "retour halfsize -> %d\n", foo); +if (foo) { + return -2; + } + +if (verbosity) fimg_describe(&result, "result after halfsize"); + +foo = fimg_save_as_pnm(&result, "something.pnm", 0); + +return 0; +} +/* --------------------------------------------------------------------- */ +int essai_sfx0(char *infile) +{ +FloatImg fimg; +int foo; + +if (NULL != infile) { + fprintf(stderr, "loading %s\n", infile); + foo = fimg_create_from_dump(infile, &fimg); + if (foo) { + fprintf(stderr, "%s: err load '%s'\n", __func__, infile); + return foo; + } + } +else { + fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB); + fimg_draw_something(&fimg); + } + +foo = fimg_save_as_pnm(&fimg, "something.pnm", 0); +if (foo) { + fprintf(stderr, "%s: err save %d\n", __func__, foo); + return -6; + } +foo = fimg_killcolors_a(&fimg, 0.0); +foo = fimg_save_as_pnm(&fimg, "colorskilled-a.pnm", 0); +if (foo) { + fprintf(stderr, "%s: err save %d\n", __func__, foo); + return -6; + } + +foo = fimg_killcolors_b(&fimg, 0.0); +foo = fimg_save_as_pnm(&fimg, "colorskilled-b.pnm", 0); +if (foo) { + fprintf(stderr, "%s: err save %d\n", __func__, foo); + return -6; + } + + +return 0; +} +/* --------------------------------------------------------------------- */ +int essai_parse_double(void) +{ +int foo; +double dval; +char *str; + +str = "12.34"; dval = 0.0; +foo = parse_double(str, &dval); +printf("%-10s -> %3d %g\n", str, foo, dval); + +str = "12e4"; dval = 0.0; +foo = parse_double(str, &dval); +printf("%-10s -> %3d %g\n", str, foo, dval); + +str = "5s"; dval = 0.0; +foo = parse_double(str, &dval); +printf("%-10s -> %3d %g\n", str, foo, dval); + +str = "PORN"; dval = 0.0; +foo = parse_double(str, &dval); +printf("%-10s -> %3d %g\n", str, foo, dval); + +return 0; +} +/* --------------------------------------------------------------------- */ +int essai_detect_type(void) +{ +int foo; +char *fname; + +foo = format_from_extension(fname="foo.fimg"); +printf("%-10s %d\n\n", fname, foo); + +foo = format_from_extension(fname="foo.pnm"); +printf("%-10s %d\n\n", fname, foo); + +foo = format_from_extension(fname="foo.png"); +printf("%-10s %d\n\n", fname, foo); + +foo = format_from_extension(fname="foo.tiff"); +printf("%-10s %d\n\n", fname, foo); + +foo = format_from_extension(fname="foo.fits"); +printf("%-10s %d\n\n", fname, foo); + +foo = format_from_extension(fname="foo.xyzzy"); +printf("%-10s %d\n\n", fname, foo); + +return 0; +} +/* --------------------------------------------------------------------- */ +int essai_mire(char *outname, int notused) +{ +FloatImg fimg; +int re; + +fimg_create(&fimg, 1280, 960, FIMG_TYPE_RGB); + +re = fimg_test_pattern(&fimg, 9, 1.0); +if (re) { + fprintf(stderr, "fimg_test_pattern -> %d\n", re); + } +fimg_export_picture(&fimg, "mire.pnm", 0); + +return -1; +} +/* --------------------------------------------------------------------- */ +int essai_rampes(void) +{ +FloatImg fimg; +int foo; + +fimg_create(&fimg, 640, 480, FIMG_TYPE_RGB); + +foo = fimg_hdeg_a(&fimg, (double)3.141592654); +fprintf(stderr, "make h deg -> %d\n", foo); +foo = fimg_save_as_pnm(&fimg, "hdeg.pnm", 0); +fprintf(stderr, "%s: save as pnm -> %d\n", __func__, foo); + +foo = fimg_vdeg_a(&fimg, (double)3.141592654); +fprintf(stderr, "make h deg -> %d\n", foo); +foo = fimg_save_as_pnm(&fimg, "vdeg.pnm", 0); +fprintf(stderr, "%s: save as pnm -> %d\n", __func__, foo); + +return 0; +} +/* --------------------------------------------------------------------- */ +int essai_lecture_png(char *fname, char *outfile, int notused) +{ +FloatImg fimg; +int foo; + +fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, notused); + +memset(&fimg, 0, sizeof(FloatImg)); +foo = fimg_create_from_png(fname, &fimg); +if (foo) { + fprintf(stderr, "%s: createfrom -> %d\n", __func__, foo); + return foo; + } +fimg_describe(&fimg, "created from png"); + +foo = fimg_export_picture(&fimg, outfile, 0); +if (foo) { + fprintf(stderr, "%s : err %d saving result to %s\n", __func__, + foo, outfile); + return foo; + } +return 0; +} +/* --------------------------------------------------------------------- */ +int essai_ecriture_png(char *fname) +{ +FloatImg fimg; +int foo; + +fimg_create(&fimg, 800, 600, FIMG_TYPE_RGB); + +fimg_draw_something(&fimg); + +if (verbosity) { + foo = fimg_save_as_pnm(&fimg, "quux.pnm", 0); + fprintf(stderr, "%s: save as pnm -> %d\n", __func__, foo); + } + +foo = fimg_save_as_png(&fimg, fname, 0); +fprintf(stderr, "save as png -> %d\n", foo); + +return 0; +} +/* --------------------------------------------------------------------- */ + +int fimg_essai_hsv(char *fname); /* hsv.c */ + + +int essai_histogramme(char *fname, int k) +{ +FloatImg fimg; +int foo; + +fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, fname, k); + +foo = fimg_create_from_dump(fname, &fimg); +if (foo) { + fprintf(stderr, "%s: err load '%s'\n", __func__, fname); + return foo; + } + +foo = fimg_essai_histo(&fimg, "out.png", k); +if (foo) { + fprintf(stderr, "essai_histo -> error %d\n", foo); + return foo; + } + +fimg_destroy(&fimg); + +fprintf(stderr, "\\o/ end of %s\n", __func__); + +return 0; +} +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ diff --git a/funcs/tests.h b/funcs/tests.h new file mode 100644 index 00000000..f7881010 --- /dev/null +++ b/funcs/tests.h @@ -0,0 +1,26 @@ +/* + * tests des fonctions diverses - prototypes + see also: t.c & tests.c + */ + +int essai_displacement(char *infile, char *outfile); +int essai_qsort_rgb(char *infile, char *outfile); +int essai_equalize(char *infile); +int essai_ecriture_fits(char *outname); +int essai_rotate(char *infile); +int essai_filtrage_2x2(char *infile); +int essai_filtrage_3x3(char *infile); +int essai_sfx0(char *infile); +int essai_mire(char *infile, int wtf); +int essai_ecriture_png(char *infile); +int essai_ecriture_tiff(char *infile); +int fimg_essai_hsv(char *infile); +int essai_classif(char *infile, char *outfile, float fvalue); +int essai_contour_2x2(char *filename, char *outfile); + +int fimg_essai_histo(FloatImg *src, char *outpic, int k); /* histogram.c */ +int essai_histogramme(char *fname, int k); + +int essai_lecture_png(char *fname, char *outfile, int notused); + +