From 327cadd03ad51b6d948d30cbcbb27e3c756141da Mon Sep 17 00:00:00 2001 From: tth Date: Sat, 3 Apr 2021 10:46:00 +0200 Subject: [PATCH] add a crude FITS exporter --- .gitignore | 1 + floatimg.h | 3 ++- tools/Makefile | 5 +++- tools/fimg2fits.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 tools/fimg2fits.c diff --git a/.gitignore b/.gitignore index fc83d170..a7aefbda 100644 --- a/.gitignore +++ b/.gitignore @@ -52,6 +52,7 @@ v4l2/nc-camcontrol tools/fimg2png tools/fimg2pnm tools/fimg2tiff +tools/fimg2fits tools/fimg2text tools/fimgstats tools/mkfimg diff --git a/floatimg.h b/floatimg.h index c52658bc..cdcc8e9d 100644 --- a/floatimg.h +++ b/floatimg.h @@ -4,7 +4,7 @@ * http://la.buvette.org/photos/cumul */ -#define FIMG_VERSION 130 +#define FIMG_VERSION 131 /* * in memory descriptor @@ -174,6 +174,7 @@ int fimg_create_from_dump(char *fname, FloatImg *head); int fimg_save_R_as_fits(FloatImg *src, char *outname, int flags); int fimg_save_G_as_fits(FloatImg *src, char *outname, int flags); int fimg_save_B_as_fits(FloatImg *src, char *outname, int flags); +int fimg_save_plane_as_fits(FloatImg *src, char *oname, char plane, int flags); int fimg_write_as_tiff(FloatImg *src, char *fname, int flags); int fimg_save_as_exr(FloatImg *src, char *outname, int flags); diff --git a/tools/Makefile b/tools/Makefile index 6ed5ef93..b0870678 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -9,7 +9,7 @@ DEPS = ../floatimg.h ../libfloatimg.a Makefile # ---------- all: fimg2pnm mkfimg png2fimg fimgstats fimg2png \ - fimg2tiff fimg2text \ + fimg2tiff fimg2text fimg2fits \ addpnm2fimg cumulfimgs fimgops fimgfx fimgstats: fimgstats.c $(DEPS) @@ -30,6 +30,9 @@ fimgfx: fimgfx.c $(DEPS) fimg2pnm: fimg2pnm.c $(DEPS) gcc $(COPT) $< ../libfloatimg.a -o $@ +fimg2fits: fimg2fits.c $(DEPS) + gcc $(COPT) $< ../libfloatimg.a -lcfitsio -o $@ + fimg2png: fimg2png.c $(DEPS) gcc $(COPT) $< ../libfloatimg.a -lpnglite -lz -o $@ diff --git a/tools/fimg2fits.c b/tools/fimg2fits.c new file mode 100644 index 00000000..41221ede --- /dev/null +++ b/tools/fimg2fits.c @@ -0,0 +1,66 @@ +/* + * exporting a floatimg to a FITS file + */ + +#include +#include +#include + +#include "../floatimg.h" + +int verbosity; + +/* ----------------------------------------------------------------- */ +int export_fimg_plane_as_fits(char *infile, char *outfile, char plane) +{ +FloatImg fimg; +int foo; + +foo = fimg_create_from_dump(infile, &fimg); +if (foo) { + fprintf(stderr, "%s: create fimg from '%s' -> %d\n", __func__, + infile, foo); + return -1; + } + +foo = fimg_save_plane_as_fits(&fimg, outfile, plane, 0); +if (foo) { + fprintf(stderr, "%s: err %d on fits export\n", __func__, foo); + return foo; + } + +fimg_destroy(&fimg); + +return -1; +} +/* ----------------------------------------------------------------- */ +static void help(int k) +{ +puts("export to FITS format"); +puts("\t-p select colorplane : R, G, B"); +} +/* ----------------------------------------------------------------- */ + +int main(int argc, char *argv[]) +{ +int foo, opt; +int plane = '?'; + +while ((opt = getopt(argc, argv, "p:hv")) != -1) { + switch(opt) { + case 'p': plane = optarg[0]; break; + case 'v': verbosity++; break; + case 'h': help(1); exit(1); + } + } + +if (2 != argc-optind) { + fprintf(stderr, "error: %s need two filenames\n", argv[0]); + exit(1); + } + +export_fimg_plane_as_fits(argv[optind], argv[optind+1], plane); + +return 0; +} +/* ----------------------------------------------------------------- */