writing TIFF, first setp
This commit is contained in:
parent
abb7c92026
commit
5a34cda32e
1
.gitignore
vendored
1
.gitignore
vendored
@ -29,6 +29,7 @@ funcs/*.o
|
||||
funcs/*.png
|
||||
funcs/*.gif
|
||||
funcs/*.fits
|
||||
funcs/*.tiff
|
||||
|
||||
scripts/*.fimg
|
||||
scripts/*.pnm
|
||||
|
@ -148,6 +148,8 @@ 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_write_as_tiff(FloatImg *src, char *fname, int flags);
|
||||
|
||||
|
||||
/* mathematics operations */
|
||||
float fimg_get_maxvalue(FloatImg *head);
|
||||
|
@ -9,7 +9,8 @@ OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \
|
||||
#---------------------------------------------------------------
|
||||
|
||||
t: t.c $(DEPS) ../libfloatimg.a
|
||||
gcc $(COPT) $< ../libfloatimg.a -lnetpbm -lpnglite -lcfitsio \
|
||||
gcc $(COPT) $< ../libfloatimg.a -lnetpbm -lpnglite -lcfitsio \
|
||||
-ltiff \
|
||||
-lz -lm -o $@
|
||||
|
||||
#---------------------------------------------------------------
|
||||
|
@ -4,18 +4,87 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <tiffio.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int essai_ecrire_tiff(FloatImg *src, char *fname)
|
||||
int fimg_write_as_tiff(FloatImg *src, char *fname, int flags)
|
||||
{
|
||||
TIFF *tiff;
|
||||
unsigned short *linebuff, *ptr;
|
||||
int x, y, idx, foo;
|
||||
char ligne[100];
|
||||
double maximum, fk;
|
||||
|
||||
/* bon, tout cela semble bien tortueux ! */
|
||||
|
||||
fprintf(stderr, "%s %s to be implemented\n", __FILE__, __func__);
|
||||
if (FIMG_TYPE_RGB != src->type) {
|
||||
fprintf(stderr, "%s: src bad type %d\n", __func__, src->type);
|
||||
return -2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
linebuff = calloc(src->width, 3*sizeof(unsigned short));
|
||||
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);
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
38
funcs/t.c
38
funcs/t.c
@ -14,6 +14,26 @@ int verbosity;
|
||||
|
||||
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) */
|
||||
int essai_ecriture_fits(char *outname)
|
||||
@ -25,7 +45,6 @@ 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);
|
||||
@ -362,7 +381,7 @@ fprintf(stderr, "%s: save as pnm -> %d\n", __func__, foo);
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int essai_ecrire_png(char *fname)
|
||||
int essai_ecriture_png(char *fname)
|
||||
{
|
||||
FloatImg fimg;
|
||||
int foo;
|
||||
@ -371,9 +390,10 @@ fimg_create(&fimg, 800, 600, FIMG_TYPE_RGB);
|
||||
|
||||
fimg_draw_something(&fimg);
|
||||
|
||||
|
||||
foo = fimg_save_as_pnm(&fimg, "quux.pnm", 0);
|
||||
fprintf(stderr, "save as pnm -> %d\n", foo);
|
||||
if (verbosity) {
|
||||
foo = fimg_save_as_pnm(&fimg, "quux.pnm", 0);
|
||||
fprintf(stderr, "%s: save as pnm -> %d\n", __func__, foo);
|
||||
}
|
||||
|
||||
foo = fimg_save_as_png(&fimg, fname, 0);
|
||||
fprintf(stderr, "save as png -> %d\n", foo);
|
||||
@ -381,7 +401,7 @@ fprintf(stderr, "save as png -> %d\n", foo);
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng };
|
||||
enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff };
|
||||
typedef struct {
|
||||
char *name;
|
||||
int Cmd;
|
||||
@ -395,6 +415,7 @@ Command commands[] = {
|
||||
{ "mire", MIRE },
|
||||
{ "wfits", Wfits },
|
||||
{ "wpng", Wpng },
|
||||
{ "wtiff", Wtiff },
|
||||
{ NULL, 0 }
|
||||
} ;
|
||||
|
||||
@ -480,7 +501,10 @@ switch(opt) {
|
||||
foo = essai_ecriture_fits(filename);
|
||||
break;
|
||||
case Wpng:
|
||||
foo = essai_ecrire_png(filename);
|
||||
foo = essai_ecriture_png(filename);
|
||||
break;
|
||||
case Wtiff:
|
||||
foo = essai_ecriture_tiff(filename);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s : bad command\n", command);
|
||||
|
Loading…
Reference in New Issue
Block a user