adding bare FITS file support
This commit is contained in:
		
							parent
							
								
									4e90a400e7
								
							
						
					
					
						commit
						3849485c02
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -28,6 +28,7 @@ funcs/t | ||||
| funcs/*.o | ||||
| funcs/*.png | ||||
| funcs/*.gif | ||||
| funcs/*.fits | ||||
| 
 | ||||
| scripts/*.fimg | ||||
| scripts/*.pnm | ||||
|  | ||||
| @ -3,7 +3,7 @@ | ||||
|  *			ugly code from tTh | ||||
|  */ | ||||
| 
 | ||||
| #define		FIMG_VERSION	102 | ||||
| #define		FIMG_VERSION	103 | ||||
| 
 | ||||
| /*
 | ||||
|  *	in memory descriptor | ||||
| @ -39,6 +39,7 @@ typedef struct { | ||||
| #define FILE_TYPE_PNG			3 | ||||
| #define FILE_TYPE_TGA			4 | ||||
| #define FILE_TYPE_TIFF			5 | ||||
| #define FILE_TYPE_FITS			6 | ||||
| 
 | ||||
| /*	lib/contrast.c			*/ | ||||
| #define CONTRAST_NONE			0 | ||||
| @ -121,7 +122,6 @@ int fimg_cos_010(FloatImg *s, FloatImg *d, double maxval); | ||||
| /*	module funcs/geometry.c		*/ | ||||
| int fimg_equalize_compute(FloatImg *src, void *vptr); | ||||
| 
 | ||||
| 
 | ||||
| int fimg_mk_gray_from(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_create_from_dump(char *fname, FloatImg *head); | ||||
| 
 | ||||
| int fimg_save_R_as_fits(FloatImg *src, char *outname, int flags); | ||||
| 
 | ||||
| 
 | ||||
| /*	mathematics operations 				*/ | ||||
| float fimg_get_maxvalue(FloatImg *head); | ||||
| int   fimg_get_minmax_rgb(FloatImg *head, float mmvals[6]); | ||||
|  | ||||
| @ -4,12 +4,13 @@ COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0 | ||||
| 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 | ||||
| 	equalize.o fimg-fits.o | ||||
| 
 | ||||
| #---------------------------------------------------------------
 | ||||
| 
 | ||||
| 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) | ||||
| 	gcc $(COPT) -c $< | ||||
| 
 | ||||
| fimg-fits.o:		fimg-fits.c $(DEPS) | ||||
| 	gcc $(COPT) -c $< | ||||
| 
 | ||||
| fimg-libpnm.o:		fimg-libpnm.c $(DEPS) | ||||
| 	gcc $(COPT) -c $< | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										69
									
								
								funcs/fimg-fits.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								funcs/fimg-fits.c
									
									
									
									
									
										Normal 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; | ||||
| } | ||||
| /* --------------------------------------------------------------------- */ | ||||
| @ -46,7 +46,7 @@ for (x=0; x<fimg->width; x++) { | ||||
| 			fimg_plot_rgb(fimg, x, y, fr, fg, fb); | ||||
| 	} | ||||
| 
 | ||||
| k = fimg->height/4; | ||||
| k = fimg->height / 4; | ||||
| for (x=0; x<fimg->width; x++) { | ||||
| 	val =  ((double)x / (double)fimg->width) * dval; | ||||
| 	for (y=0; y<20; y++) { | ||||
|  | ||||
							
								
								
									
										45
									
								
								funcs/t.c
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								funcs/t.c
									
									
									
									
									
								
							| @ -6,12 +6,32 @@ | ||||
| #include <string.h> | ||||
| #include  <pam.h> | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| #include "../floatimg.h" | ||||
| 
 | ||||
| int		verbosity; | ||||
| 
 | ||||
| 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 | ||||
| @ -38,7 +58,6 @@ else	{ | ||||
| foo = fimg_equalize_compute(&src, NULL); | ||||
| fprintf(stderr, "equalize compute --> %d\n", foo); | ||||
| 
 | ||||
| 
 | ||||
| fimg_destroy(&src); | ||||
| 
 | ||||
| return -1; | ||||
| @ -315,7 +334,9 @@ int		re; | ||||
| fimg_create(&fimg, 1280, 960, FIMG_TYPE_RGB); | ||||
| 
 | ||||
| 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); | ||||
| 
 | ||||
| return -1; | ||||
| @ -346,15 +367,10 @@ int essai_ecrire_png(char *fname) | ||||
| FloatImg	fimg; | ||||
| int		foo; | ||||
| 
 | ||||
| fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB); | ||||
| fimg_create(&fimg, 800, 600, FIMG_TYPE_RGB); | ||||
| 
 | ||||
| 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); | ||||
| fprintf(stderr, "save as pnm -> %d\n", foo); | ||||
| @ -365,7 +381,7 @@ fprintf(stderr, "save as png -> %d\n", foo); | ||||
| return 0; | ||||
| } | ||||
| /* --------------------------------------------------------------------- */ | ||||
| enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE }; | ||||
| enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng }; | ||||
| typedef struct { | ||||
| 	char	*name; | ||||
| 	int	Cmd; | ||||
| @ -377,6 +393,8 @@ Command commands[] = { | ||||
| 	{ "sfx0",	Sfx0		}, | ||||
| 	{ "f3x3",	F3x3		}, | ||||
| 	{ "mire",	MIRE		}, | ||||
| 	{ "wfits",	Wfits		}, | ||||
| 	{ "wpng",	Wpng		}, | ||||
| 	{ NULL,		0		} | ||||
| 	} ; | ||||
| 
 | ||||
| @ -444,7 +462,7 @@ if (verbosity) { | ||||
| 	} | ||||
| 
 | ||||
| opt = lookup_cmd(command); | ||||
| fprintf(stderr, "lookup '%s' --> %d\n", command, opt); | ||||
| // fprintf(stderr, "lookup '%s' --> %d\n", command, opt);
 | ||||
| 
 | ||||
| switch(opt) { | ||||
| 	case Equalize: | ||||
| @ -458,7 +476,12 @@ switch(opt) { | ||||
| 	case MIRE: | ||||
| 		foo = essai_mire(filename, 0); | ||||
| 		break; | ||||
| 
 | ||||
| 	case Wfits: | ||||
| 		foo =  essai_ecriture_fits(filename); | ||||
| 		break; | ||||
| 	case Wpng: | ||||
| 		foo = essai_ecrire_png(filename); | ||||
| 		break; | ||||
| 	default: | ||||
| 		fprintf(stderr, "%s : bad command\n", command); | ||||
| 		exit(1); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user