diff --git a/floatimg.h b/floatimg.h index 6d54a1f6..15fb0cd3 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 971c09e3..c7aa9576 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 00000000..ed6b698a --- /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 ecdf4b51..08d0a4e1 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; } }