Compare commits

..

No commits in common. "e3cd73e7db572e1e81dc7d72901cbe096f480da7" and "abb7c92026145c7f143f4c4115a8dde2f0225f5a" have entirely different histories.

5 changed files with 11 additions and 108 deletions

1
.gitignore vendored
View File

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

View File

@ -148,8 +148,6 @@ 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_G_as_fits(FloatImg *src, char *outname, int flags);
int fimg_save_B_as_fits(FloatImg *src, char *outname, int flags); int fimg_save_B_as_fits(FloatImg *src, char *outname, int flags);
int fimg_write_as_tiff(FloatImg *src, char *fname, int flags);
/* mathematics operations */ /* mathematics operations */
float fimg_get_maxvalue(FloatImg *head); float fimg_get_maxvalue(FloatImg *head);

View File

@ -9,8 +9,7 @@ OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \
#--------------------------------------------------------------- #---------------------------------------------------------------
t: t.c $(DEPS) ../libfloatimg.a t: t.c $(DEPS) ../libfloatimg.a
gcc $(COPT) $< ../libfloatimg.a -lnetpbm -lpnglite -lcfitsio \ gcc $(COPT) $< ../libfloatimg.a -lnetpbm -lpnglite -lcfitsio \
-ltiff \
-lz -lm -o $@ -lz -lm -o $@
#--------------------------------------------------------------- #---------------------------------------------------------------

View File

@ -4,87 +4,18 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <tiffio.h>
#include "../floatimg.h" #include "../floatimg.h"
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
extern int verbosity;
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int fimg_write_as_tiff(FloatImg *src, char *fname, int flags) int essai_ecrire_tiff(FloatImg *src, char *fname)
{ {
TIFF *tiff;
unsigned short *linebuff, *ptr;
int x, y, idx, foo;
char ligne[100];
double maximum, fk;
/* bon, tout cela semble bien tortueux ! */ /* bon, tout cela semble bien tortueux ! */
if (FIMG_TYPE_RGB != src->type) { fprintf(stderr, "%s %s to be implemented\n", __FILE__, __func__);
fprintf(stderr, "%s: src bad type %d\n", __func__, src->type);
return -2;
}
linebuff = calloc(src->width, 3*sizeof(unsigned short)); return 0;
if (NULL==linebuff) {
fprintf(stderr, "%s: fatal memory error\n", __func__);
return -7;
}
maximum = (double)fimg_get_maxvalue(src);
fk = maximum / 65535.0;
if (verbosity) {
fprintf(stderr, "%s : maxv %f fk %f\n", __func__, maximum, fk);
}
tiff = TIFFOpen(fname, "w");
printf("tiff at %p\n", tiff);
TIFFSetField(tiff, TIFFTAG_IMAGEWIDTH, src->width);
TIFFSetField(tiff, TIFFTAG_IMAGELENGTH, src->height);
TIFFSetField(tiff, TIFFTAG_SAMPLESPERPIXEL, 3); // RGB
TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 16); // 0->65535
TIFFSetField(tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
sprintf(ligne, "lib FloatImg %d by tTh", FIMG_VERSION);
TIFFSetField(tiff, TIFFTAG_SOFTWARE, ligne);
foo = src->width * 3;
foo = TIFFDefaultStripSize(tiff, foo);
fprintf(stderr, "default strip size %d\n", foo);
TIFFSetField(tiff, TIFFTAG_ROWSPERSTRIP, foo);
for (y=0; y<src->height; y++) {
ptr = linebuff;
idx = y * src->width;
for (x=0; x<src->width; x++) {
*ptr++ = (unsigned short) (src->R[idx] / fk);
*ptr++ = (unsigned short) (src->G[idx] / fk);
*ptr++ = (unsigned short) (src->B[idx] / fk);
idx++;
}
TIFFWriteScanline(tiff, linebuff, y, 0);
idx += src->width;
}
TIFFClose(tiff);
free(linebuff);
return -1;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */

View File

@ -14,26 +14,6 @@ int verbosity;
float global_fvalue; float global_fvalue;
/* --------------------------------------------------------------------- */
/* nouveau 19 aout 2020, le matin avant la canicule */
int essai_ecriture_tiff(char *outname)
{
int foo;
FloatImg picz;
fimg_create(&picz, 800, 600, FIMG_TYPE_RGB);
fimg_test_pattern(&picz, 0, 22222);
foo = fimg_write_as_tiff(&picz, outname, 0);
if (foo) {
fprintf(stderr, "%s got a %d\n", __func__, foo);
return foo;
}
return -7;
}
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* essai de fichiers FITS (astronomie) */ /* essai de fichiers FITS (astronomie) */
int essai_ecriture_fits(char *outname) int essai_ecriture_fits(char *outname)
@ -45,6 +25,7 @@ fprintf(stderr, "%s is creating the picz\n", __func__);
fimg_create(&src, 512, 512, FIMG_TYPE_RGB); fimg_create(&src, 512, 512, FIMG_TYPE_RGB);
fimg_test_pattern(&src, 0, 255.0); 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); foo = fimg_save_R_as_fits(&src, outname, 0);
fprintf(stderr, "saving '%s' to fits --> %d\n", outname, foo); fprintf(stderr, "saving '%s' to fits --> %d\n", outname, foo);
@ -381,7 +362,7 @@ fprintf(stderr, "%s: save as pnm -> %d\n", __func__, foo);
return 0; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
int essai_ecriture_png(char *fname) int essai_ecrire_png(char *fname)
{ {
FloatImg fimg; FloatImg fimg;
int foo; int foo;
@ -390,10 +371,9 @@ fimg_create(&fimg, 800, 600, FIMG_TYPE_RGB);
fimg_draw_something(&fimg); fimg_draw_something(&fimg);
if (verbosity) {
foo = fimg_save_as_pnm(&fimg, "quux.pnm", 0); foo = fimg_save_as_pnm(&fimg, "quux.pnm", 0);
fprintf(stderr, "%s: save as pnm -> %d\n", __func__, foo); fprintf(stderr, "save as pnm -> %d\n", foo);
}
foo = fimg_save_as_png(&fimg, fname, 0); foo = fimg_save_as_png(&fimg, fname, 0);
fprintf(stderr, "save as png -> %d\n", foo); fprintf(stderr, "save as png -> %d\n", foo);
@ -401,7 +381,7 @@ fprintf(stderr, "save as png -> %d\n", foo);
return 0; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff }; enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng };
typedef struct { typedef struct {
char *name; char *name;
int Cmd; int Cmd;
@ -415,7 +395,6 @@ Command commands[] = {
{ "mire", MIRE }, { "mire", MIRE },
{ "wfits", Wfits }, { "wfits", Wfits },
{ "wpng", Wpng }, { "wpng", Wpng },
{ "wtiff", Wtiff },
{ NULL, 0 } { NULL, 0 }
} ; } ;
@ -501,10 +480,7 @@ switch(opt) {
foo = essai_ecriture_fits(filename); foo = essai_ecriture_fits(filename);
break; break;
case Wpng: case Wpng:
foo = essai_ecriture_png(filename); foo = essai_ecrire_png(filename);
break;
case Wtiff:
foo = essai_ecriture_tiff(filename);
break; break;
default: default:
fprintf(stderr, "%s : bad command\n", command); fprintf(stderr, "%s : bad command\n", command);