From 453d08aa236307e91bcc4977e3a97a7381937077 Mon Sep 17 00:00:00 2001 From: tth Date: Fri, 16 Oct 2020 11:20:10 +0200 Subject: [PATCH] added universal exporter --- floatimg.h | 4 +++ funcs/Makefile | 5 +++- funcs/exporter.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ funcs/t.c | 32 +++++++++++++-------- 4 files changed, 103 insertions(+), 13 deletions(-) create mode 100644 funcs/exporter.c diff --git a/floatimg.h b/floatimg.h index 6d54a1f..15fb0cd 100644 --- a/floatimg.h +++ b/floatimg.h @@ -109,6 +109,10 @@ int fimg_colors_mixer_a(FloatImg *fimg, float fval); /* #coronamaison */ int fimg_rotate_90(FloatImg *src, FloatImg *dst, int notused); + +/* universal exporter XXX */ +int fimg_export_picture(FloatImg *pic, char *fname, int flags); + /* PNM files module */ int fimg_save_as_pnm(FloatImg *head, char *fname, int flags); int fimg_load_from_pnm(char *fname, FloatImg *head, int notused); diff --git a/funcs/Makefile b/funcs/Makefile index 971c09e..c7aa957 100644 --- a/funcs/Makefile +++ b/funcs/Makefile @@ -5,7 +5,7 @@ DEPS = ../floatimg.h Makefile OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \ fimg-libpnm.o rampes.o sfx0.o geometry.o rotate.o \ equalize.o fimg-fits.o saturation.o histogram.o \ - hsv.o classif.o contour2x2.o qsortrgb.o + hsv.o classif.o contour2x2.o qsortrgb.o exporter.o #--------------------------------------------------------------- @@ -67,6 +67,9 @@ classif.o: classif.c $(DEPS) qsortrgb.o: qsortrgb.c $(DEPS) gcc $(COPT) -c $< +exporter.o: exporter.c $(DEPS) + gcc $(COPT) -c $< + hsv.o: hsv.c $(DEPS) gcc $(COPT) -c $< diff --git a/funcs/exporter.c b/funcs/exporter.c new file mode 100644 index 0000000..ed6b698 --- /dev/null +++ b/funcs/exporter.c @@ -0,0 +1,75 @@ +/* + * exporter.c + */ + +#include +#include +#include + +#include "../floatimg.h" + +extern int verbosity; + +/* --------------------------------------------------------------------- */ +/* + * multi-magic 'save file' function. + */ +int fimg_export_picture(FloatImg *pic, char *fname, int flags) +{ +int filetype; +int foo; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p '%s' 0x%X )\n", __func__, + pic, fname, flags); +#endif + +filetype = format_from_extension(fname); +if (verbosity) { + fprintf(stderr, "file %s : type %d\n", fname, filetype); + } + +switch(filetype) { + + case FILE_TYPE_FIMG: + foo = fimg_dump_to_file(pic, fname, 0); + break; + + case FILE_TYPE_PNM: + foo = fimg_save_as_pnm(pic, fname, 0); + break; + + case FILE_TYPE_PNG: + foo = fimg_save_as_png(pic, fname, 0); + break; + + case FILE_TYPE_TGA: + fprintf(stderr, "%s: FILE_TYPE_TGA not implemented\n", + __func__); + foo = -666; + break; + + case FILE_TYPE_TIFF: + foo = fimg_write_as_tiff(pic, fname, 0); + break; + + case FILE_TYPE_FITS: + foo = fimg_save_R_as_fits(pic, fname, 0); + break; + + default: + foo = -1789; + break; + + } + +if (foo) { + fprintf(stderr, "%s: exporting '%s' -> %d\n", __func__, + fname, foo); + /* que faire maintenant ? */ + } + +return foo; +} +/* --------------------------------------------------------------------- */ + diff --git a/funcs/t.c b/funcs/t.c index ecdf4b5..08d0a4e 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -45,7 +45,7 @@ if (foo) { return foo; } -foo = fimg_dump_to_file(&dst, "out.fimg", 0); +foo = fimg_export_picture(&dst, "out.pnm", 0); if (foo) { fprintf(stderr, "%s : err %d saving result\n", __func__, foo); return foo; @@ -58,6 +58,9 @@ return 0; /* * nouveau 5 octobre 2020 pendant sonoptic */ + + + int essai_contour_2x2(char *infile) { FloatImg src, dst; @@ -78,13 +81,13 @@ else { fimg_clone(&src, &dst, 1); -foo = fimg_contour_2x2(&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_save_as_pnm(&dst, "out.pnm", 0); +foo = fimg_export_picture(&dst, "out2x2.pnm", 0); if (foo) { fprintf(stderr, "%s : err %d saving result\n", __func__, foo); return foo; @@ -124,7 +127,7 @@ if (foo) { return foo; } -foo = fimg_save_as_pnm(&dst, "out.pnm", 0); +foo = fimg_export_picture(&dst, "out.pnm", 0); if (foo) { fprintf(stderr, "%s : err %d saving result\n", __func__, foo); return foo; @@ -222,8 +225,8 @@ fimg_save_as_png(&src, "test.png", 0); foo = fimg_rotate_90(&src, &dst, 0); fprintf(stderr, "rotate 90 -> %d\n", foo); -foo = fimg_save_as_png(&dst, "rotated90.png", 0); -foo = fimg_save_as_pnm(&dst, "rotated90.pnm", 0); +foo = fimg_export_picture(&dst, "rotated90.png", 0); +foo = fimg_export_picture(&dst, "rotated90.pnm", 0); fimg_destroy(&src); @@ -479,7 +482,7 @@ re = fimg_test_pattern(&fimg, 9, 1.0); if (re) { fprintf(stderr, "fimg_test_pattern -> %d\n", re); } -fimg_save_as_pnm(&fimg, "mire.pnm", 0); +fimg_export_picture(&fimg, "mire.pnm", 0); return -1; } @@ -525,7 +528,6 @@ return 0; } /* --------------------------------------------------------------------- */ - int fimg_essai_histo(FloatImg *src, char *outpic, int k); /* histogram.c */ int fimg_essai_hsv(char *fname); /* hsv.c */ @@ -598,7 +600,10 @@ void help(int k) { Command *pcmd; -fprintf(stderr, "usage:\n\t./t command filename\n"); +fprintf(stderr, "usage:\n\t./t [options] command filename\n"); + +fprintf(stderr, "options:\n"); +fprintf(stderr, "\t-o outfile\n"); fprintf(stderr, "commands:\n"); pcmd = commands; @@ -614,16 +619,19 @@ exit(0); int main(int argc, char *argv[]) { int foo, opt; -char *filename, *command; +char *filename, *command, *outfile; fprintf(stderr, "++++++++ test des fonctions pid=%d\n", getpid()); -global_fvalue = 1.0; +global_fvalue = 1.0; +outfile = "out.pnm"; -while ((opt = getopt(argc, argv, "hk:v")) != -1) { + +while ((opt = getopt(argc, argv, "hk:p:v")) != -1) { switch(opt) { case 'h': help(0); break; case 'k': global_fvalue = atof(optarg); break; + case 'o': outfile = optarg; break; case 'v': verbosity++; break; } }