Compare commits

..

3 Commits

Author SHA1 Message Date
tth
29480bfdfd oups again... 2020-10-20 00:09:20 +02:00
tth
0b703e0633 hmmm, no warning for that ? 2020-10-16 11:48:54 +02:00
tth
453d08aa23 added universal exporter 2020-10-16 11:20:10 +02:00
6 changed files with 105 additions and 16 deletions

View File

@ -109,6 +109,10 @@ int fimg_colors_mixer_a(FloatImg *fimg, float fval);
/* #coronamaison */ /* #coronamaison */
int fimg_rotate_90(FloatImg *src, FloatImg *dst, int notused); 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 */ /* PNM files module */
int fimg_save_as_pnm(FloatImg *head, char *fname, int flags); int fimg_save_as_pnm(FloatImg *head, char *fname, int flags);
int fimg_load_from_pnm(char *fname, FloatImg *head, int notused); int fimg_load_from_pnm(char *fname, FloatImg *head, int notused);

View File

@ -5,7 +5,7 @@ DEPS = ../floatimg.h Makefile
OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \ 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 \ fimg-libpnm.o rampes.o sfx0.o geometry.o rotate.o \
equalize.o fimg-fits.o saturation.o histogram.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) qsortrgb.o: qsortrgb.c $(DEPS)
gcc $(COPT) -c $< gcc $(COPT) -c $<
exporter.o: exporter.c $(DEPS)
gcc $(COPT) -c $<
hsv.o: hsv.c $(DEPS) hsv.o: hsv.c $(DEPS)
gcc $(COPT) -c $< gcc $(COPT) -c $<

View File

@ -9,7 +9,7 @@
#include "../floatimg.h" #include "../floatimg.h"
int verbosity; extern int verbosity;
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* nouveau 2 octobre 2020, juste avant sonoptic de la pluie craignos */ /* nouveau 2 octobre 2020, juste avant sonoptic de la pluie craignos */

View File

@ -9,7 +9,7 @@
#include "../floatimg.h" #include "../floatimg.h"
int verbosity; extern int verbosity;
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* nouveau 4 octobre 2020, juste avant sonoptic de la pluie craignos */ /* nouveau 4 octobre 2020, juste avant sonoptic de la pluie craignos */
@ -41,7 +41,6 @@ if (fimg_images_not_compatible(psrc, pdst)) {
return -8; return -8;
} }
if (reverse) { if (reverse) {
v1 = 0.0; v2 = 1.0; v1 = 0.0; v2 = 1.0;
} }

75
funcs/exporter.c Normal file
View File

@ -0,0 +1,75 @@
/*
* exporter.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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;
}
/* --------------------------------------------------------------------- */

View File

@ -45,7 +45,7 @@ if (foo) {
return foo; return foo;
} }
foo = fimg_dump_to_file(&dst, "out.fimg", 0); foo = fimg_export_picture(&dst, "out.pnm", 0);
if (foo) { if (foo) {
fprintf(stderr, "%s : err %d saving result\n", __func__, foo); fprintf(stderr, "%s : err %d saving result\n", __func__, foo);
return foo; return foo;
@ -58,6 +58,9 @@ return 0;
/* /*
* nouveau 5 octobre 2020 pendant sonoptic * nouveau 5 octobre 2020 pendant sonoptic
*/ */
int essai_contour_2x2(char *infile) int essai_contour_2x2(char *infile)
{ {
FloatImg src, dst; FloatImg src, dst;
@ -78,13 +81,13 @@ else {
fimg_clone(&src, &dst, 1); fimg_clone(&src, &dst, 1);
foo = fimg_contour_2x2(&src, &dst, 1); foo = fimg_contour_2x2(&src, &dst, 0);
if (foo) { if (foo) {
fprintf(stderr, "%s: err %d in contour_2x2\n", __func__, foo); fprintf(stderr, "%s: err %d in contour_2x2\n", __func__, foo);
return foo; return foo;
} }
foo = fimg_save_as_pnm(&dst, "out.pnm", 0); foo = fimg_export_picture(&dst, "out2x2.pnm", 0);
if (foo) { if (foo) {
fprintf(stderr, "%s : err %d saving result\n", __func__, foo); fprintf(stderr, "%s : err %d saving result\n", __func__, foo);
return foo; return foo;
@ -124,7 +127,7 @@ if (foo) {
return foo; return foo;
} }
foo = fimg_save_as_pnm(&dst, "out.pnm", 0); foo = fimg_export_picture(&dst, "out.pnm", 0);
if (foo) { if (foo) {
fprintf(stderr, "%s : err %d saving result\n", __func__, foo); fprintf(stderr, "%s : err %d saving result\n", __func__, foo);
return foo; return foo;
@ -222,8 +225,8 @@ fimg_save_as_png(&src, "test.png", 0);
foo = fimg_rotate_90(&src, &dst, 0); foo = fimg_rotate_90(&src, &dst, 0);
fprintf(stderr, "rotate 90 -> %d\n", foo); fprintf(stderr, "rotate 90 -> %d\n", foo);
foo = fimg_save_as_png(&dst, "rotated90.png", 0); foo = fimg_export_picture(&dst, "rotated90.png", 0);
foo = fimg_save_as_pnm(&dst, "rotated90.pnm", 0); foo = fimg_export_picture(&dst, "rotated90.pnm", 0);
fimg_destroy(&src); fimg_destroy(&src);
@ -479,7 +482,7 @@ re = fimg_test_pattern(&fimg, 9, 1.0);
if (re) { if (re) {
fprintf(stderr, "fimg_test_pattern -> %d\n", 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; return -1;
} }
@ -525,7 +528,6 @@ return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int fimg_essai_histo(FloatImg *src, char *outpic, int k); /* histogram.c */ int fimg_essai_histo(FloatImg *src, char *outpic, int k); /* histogram.c */
int fimg_essai_hsv(char *fname); /* hsv.c */ int fimg_essai_hsv(char *fname); /* hsv.c */
@ -598,7 +600,10 @@ void help(int k)
{ {
Command *pcmd; 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"); fprintf(stderr, "commands:\n");
pcmd = commands; pcmd = commands;
@ -614,16 +619,19 @@ exit(0);
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int foo, opt; int foo, opt;
char *filename, *command; char *filename, *command, *outfile;
fprintf(stderr, "++++++++ test des fonctions pid=%d\n", getpid()); 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) { switch(opt) {
case 'h': help(0); break; case 'h': help(0); break;
case 'k': global_fvalue = atof(optarg); break; case 'k': global_fvalue = atof(optarg); break;
case 'o': outfile = optarg; break;
case 'v': verbosity++; break; case 'v': verbosity++; break;
} }
} }