Compare commits

...

3 Commits

Author SHA1 Message Date
tth
3849485c02 adding bare FITS file support 2020-07-24 10:38:13 +02:00
tth
4e90a400e7 added some file extensions 2020-07-23 19:08:17 +02:00
tth
288c5a57df fixed bug in DEBUG_LEVEL code 2020-07-22 18:18:20 +02:00
8 changed files with 119 additions and 17 deletions

1
.gitignore vendored
View File

@ -28,6 +28,7 @@ funcs/t
funcs/*.o funcs/*.o
funcs/*.png funcs/*.png
funcs/*.gif funcs/*.gif
funcs/*.fits
scripts/*.fimg scripts/*.fimg
scripts/*.pnm scripts/*.pnm

View File

@ -3,7 +3,7 @@
* ugly code from tTh * ugly code from tTh
*/ */
#define FIMG_VERSION 102 #define FIMG_VERSION 103
/* /*
* in memory descriptor * in memory descriptor
@ -39,6 +39,7 @@ typedef struct {
#define FILE_TYPE_PNG 3 #define FILE_TYPE_PNG 3
#define FILE_TYPE_TGA 4 #define FILE_TYPE_TGA 4
#define FILE_TYPE_TIFF 5 #define FILE_TYPE_TIFF 5
#define FILE_TYPE_FITS 6
/* lib/contrast.c */ /* lib/contrast.c */
#define CONTRAST_NONE 0 #define CONTRAST_NONE 0
@ -121,7 +122,6 @@ int fimg_cos_010(FloatImg *s, FloatImg *d, double maxval);
/* module funcs/geometry.c */ /* module funcs/geometry.c */
int fimg_equalize_compute(FloatImg *src, void *vptr); int fimg_equalize_compute(FloatImg *src, void *vptr);
int fimg_mk_gray_from(FloatImg *src, FloatImg*dst, int k); int fimg_mk_gray_from(FloatImg *src, FloatImg*dst, int k);
int fimg_desaturate(FloatImg *src, FloatImg *dst, int k); int fimg_desaturate(FloatImg *src, FloatImg *dst, int k);
@ -138,6 +138,9 @@ int fimg_dump_to_file(FloatImg *head, char *fname, int notused);
int fimg_load_from_dump(char *fname, FloatImg *where); int fimg_load_from_dump(char *fname, FloatImg *where);
int fimg_create_from_dump(char *fname, FloatImg *head); int fimg_create_from_dump(char *fname, FloatImg *head);
int fimg_save_R_as_fits(FloatImg *src, char *outname, int flags);
/* mathematics operations */ /* mathematics operations */
float fimg_get_maxvalue(FloatImg *head); float fimg_get_maxvalue(FloatImg *head);
int fimg_get_minmax_rgb(FloatImg *head, float mmvals[6]); int fimg_get_minmax_rgb(FloatImg *head, float mmvals[6]);

View File

@ -4,12 +4,13 @@ COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0
DEPS = ../floatimg.h Makefile 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 equalize.o fimg-fits.o
#--------------------------------------------------------------- #---------------------------------------------------------------
t: t.c $(DEPS) ../libfloatimg.a t: t.c $(DEPS) ../libfloatimg.a
gcc $(COPT) $< ../libfloatimg.a -lnetpbm -lpnglite -lz -lm -o $@ gcc $(COPT) $< ../libfloatimg.a -lnetpbm -lpnglite -lcfitsio \
-lz -lm -o $@
#--------------------------------------------------------------- #---------------------------------------------------------------
@ -22,6 +23,9 @@ fimg-png.o: fimg-png.c $(DEPS)
fimg-tiff.o: fimg-tiff.c $(DEPS) fimg-tiff.o: fimg-tiff.c $(DEPS)
gcc $(COPT) -c $< gcc $(COPT) -c $<
fimg-fits.o: fimg-fits.c $(DEPS)
gcc $(COPT) -c $<
fimg-libpnm.o: fimg-libpnm.c $(DEPS) fimg-libpnm.o: fimg-libpnm.c $(DEPS)
gcc $(COPT) -c $< gcc $(COPT) -c $<

View File

@ -17,7 +17,7 @@ float *M; /* alias of filter matrix */
double dval; double dval;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p)\n", __func__, s, d, filtr); fprintf(stderr, ">>> %s ( %p %p %p)\n", __func__, src, dst, filtr);
#endif #endif
/* aliasing some vars for cleaner code */ /* aliasing some vars for cleaner code */

69
funcs/fimg-fits.c Normal file
View File

@ -0,0 +1,69 @@
/*
* FLOATIMG
* import/export to/from FITS files
*/
#include <stdio.h>
#include <stdlib.h>
#include <fitsio.h>
#include "../floatimg.h"
extern int verbosity;
/* --------------------------------------------------------------------- */
int fimg_save_R_as_fits(FloatImg *src, char *outname, int flags)
{
fitsfile *fptr; /* pointer to the FITS file */
int status, idx, sz;
int bitpix = FLOAT_IMG;
long naxis = 2;
long naxes[2];
float **array;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p '%s' %d )\n", __func__, src, outname, flags);
#endif
status = 0;
remove(outname); /* Delete old file if it already exists */
if (fits_create_file(&fptr, outname, &status)) {
fits_report_error(stderr, status);
return -9;
}
naxes[0] = src->width; naxes[1] = src->height;
array = calloc(src->height, sizeof(float *));
if (verbosity) fimg_describe(src, "to be saved as fits");
/* initialize pointers to the start of each row of the image */
for( idx=0; idx<naxes[1]; idx++ ) {
/**** MAGIC CODE MUST COME HERE ****/
array[idx] = src->R + (idx*naxes[0]);
// fprintf(stderr, " %6d %p\n", idx, array[idx]);
}
if ( fits_create_img(fptr, bitpix, naxis, naxes, &status) ) {
fits_report_error(stderr, status);
return -10;
}
sz = naxes[0]*naxes[1];
if ( fits_write_img(fptr, TFLOAT, 1, sz, array[0], &status) ) {
fits_report_error(stderr, status);
return -10;
}
if ( fits_close_file(fptr, &status) ) {
fits_report_error(stderr, status);
return -9;
}
return 0;
}
/* --------------------------------------------------------------------- */

View File

@ -6,12 +6,32 @@
#include <string.h> #include <string.h>
#include <pam.h> #include <pam.h>
#include "../floatimg.h" #include "../floatimg.h"
int verbosity; int verbosity;
float global_fvalue; float global_fvalue;
/* --------------------------------------------------------------------- */
/* 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_as_pnm(&src, "foo.pnm", 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 * egalisation dynamique approximative
@ -38,7 +58,6 @@ else {
foo = fimg_equalize_compute(&src, NULL); foo = fimg_equalize_compute(&src, NULL);
fprintf(stderr, "equalize compute --> %d\n", foo); fprintf(stderr, "equalize compute --> %d\n", foo);
fimg_destroy(&src); fimg_destroy(&src);
return -1; return -1;
@ -315,7 +334,9 @@ int re;
fimg_create(&fimg, 1280, 960, FIMG_TYPE_RGB); fimg_create(&fimg, 1280, 960, FIMG_TYPE_RGB);
re = fimg_test_pattern(&fimg, 9, 1.0); 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_save_as_pnm(&fimg, "mire.pnm", 0);
return -1; return -1;
@ -346,15 +367,10 @@ int essai_ecrire_png(char *fname)
FloatImg fimg; FloatImg fimg;
int foo; int foo;
fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB); fimg_create(&fimg, 800, 600, FIMG_TYPE_RGB);
fimg_draw_something(&fimg); fimg_draw_something(&fimg);
/* XXX
for (foo=0; foo<512; foo++) {
fimg_plot_rgb(&fimg, foo, foo, 17000.0, 8000.0, 11111.1);
}
*/
foo = fimg_save_as_pnm(&fimg, "quux.pnm", 0); foo = fimg_save_as_pnm(&fimg, "quux.pnm", 0);
fprintf(stderr, "save as pnm -> %d\n", foo); fprintf(stderr, "save as pnm -> %d\n", foo);
@ -365,7 +381,7 @@ fprintf(stderr, "save as png -> %d\n", foo);
return 0; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE }; enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng };
typedef struct { typedef struct {
char *name; char *name;
int Cmd; int Cmd;
@ -377,6 +393,8 @@ Command commands[] = {
{ "sfx0", Sfx0 }, { "sfx0", Sfx0 },
{ "f3x3", F3x3 }, { "f3x3", F3x3 },
{ "mire", MIRE }, { "mire", MIRE },
{ "wfits", Wfits },
{ "wpng", Wpng },
{ NULL, 0 } { NULL, 0 }
} ; } ;
@ -444,7 +462,7 @@ if (verbosity) {
} }
opt = lookup_cmd(command); opt = lookup_cmd(command);
fprintf(stderr, "lookup '%s' --> %d\n", command, opt); // fprintf(stderr, "lookup '%s' --> %d\n", command, opt);
switch(opt) { switch(opt) {
case Equalize: case Equalize:
@ -458,7 +476,12 @@ switch(opt) {
case MIRE: case MIRE:
foo = essai_mire(filename, 0); foo = essai_mire(filename, 0);
break; break;
case Wfits:
foo = essai_ecriture_fits(filename);
break;
case Wpng:
foo = essai_ecrire_png(filename);
break;
default: default:
fprintf(stderr, "%s : bad command\n", command); fprintf(stderr, "%s : bad command\n", command);
exit(1); exit(1);

View File

@ -58,8 +58,10 @@ fprintf(stderr, "[%s] --> [%s]\n", fname, cptr);
if (!strcasecmp(cptr, ".pnm")) return FILE_TYPE_PNM; if (!strcasecmp(cptr, ".pnm")) return FILE_TYPE_PNM;
if (!strcasecmp(cptr, ".fimg")) return FILE_TYPE_FIMG; if (!strcasecmp(cptr, ".fimg")) return FILE_TYPE_FIMG;
if (!strcasecmp(cptr, ".tga")) return FILE_TYPE_TGA;
if (!strcasecmp(cptr, ".png")) return FILE_TYPE_PNG; if (!strcasecmp(cptr, ".png")) return FILE_TYPE_PNG;
if (!strcasecmp(cptr, ".tiff")) return FILE_TYPE_TIFF; if (!strcasecmp(cptr, ".tiff")) return FILE_TYPE_TIFF;
if (!strcasecmp(cptr, ".fits")) return FILE_TYPE_FITS;
return -1; return -1;
} }