From 635b72263587d981ca82824971e8fa5ecc4a38e6 Mon Sep 17 00:00:00 2001 From: tth Date: Sun, 21 Mar 2021 09:02:55 +0100 Subject: [PATCH] trying to do EXR io --- Fonderie/single.c | 2 +- floatimg.h | 4 +++- funcs/Makefile | 5 ++++- funcs/exporter.c | 3 +++ funcs/fimg-openexr.c | 30 ++++++++++++++++++++++++++++++ funcs/t.c | 6 +++++- funcs/tests.c | 25 +++++++++++++++++++++++++ funcs/tests.h | 1 + funcs/utils.c | 1 + lib/Makefile | 2 +- 10 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 funcs/fimg-openexr.c diff --git a/Fonderie/single.c b/Fonderie/single.c index 9ebe539b..a7caacd7 100644 --- a/Fonderie/single.c +++ b/Fonderie/single.c @@ -99,7 +99,7 @@ fprintf(stderr, " chainfilter %d\n", chainfilter); fprintf(stderr, " destination %s\n", destination); if (k) { - + /* XXX */ } return -1; diff --git a/floatimg.h b/floatimg.h index 70e34dab..d5d5d42a 100644 --- a/floatimg.h +++ b/floatimg.h @@ -4,7 +4,7 @@ * http://la.buvette.org/photos/cumul */ -#define FIMG_VERSION 125 +#define FIMG_VERSION 126 /* * in memory descriptor @@ -42,6 +42,7 @@ typedef struct { #define FILE_TYPE_TIFF 5 #define FILE_TYPE_FITS 6 #define FILE_TYPE_BMP 7 +#define FILE_TYPE_EXR 8 /* lib/contrast.c */ #define CONTRAST_NONE 0 @@ -175,6 +176,7 @@ 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); +int fimg_save_as_exr(FloatImg *src, char *outname, int flags); /* mathematics operations */ diff --git a/funcs/Makefile b/funcs/Makefile index bd572514..b5daa78f 100644 --- a/funcs/Makefile +++ b/funcs/Makefile @@ -5,7 +5,7 @@ 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 sfx1.o sfx2.o \ - geometry.o rotate.o \ + geometry.o rotate.o fimg-openexr.o \ equalize.o fimg-fits.o saturation.o histogram.o \ hsv.o classif.o contour2x2.o qsortrgb.o exporter.o \ displacement.o dithering.o plasmas.o @@ -42,6 +42,9 @@ fimg-bmp.o: fimg-bmp.c $(DEPS) fimg-tiff.o: fimg-tiff.c $(DEPS) gcc $(COPT) -c $< +fimg-openexr.o: fimg-openexr.c $(DEPS) + gcc $(COPT) -c $< + fimg-fits.o: fimg-fits.c $(DEPS) gcc $(COPT) -I/usr/include/cfitsio/ -c $< diff --git a/funcs/exporter.c b/funcs/exporter.c index 7eada001..d71ff7f4 100644 --- a/funcs/exporter.c +++ b/funcs/exporter.c @@ -53,6 +53,9 @@ switch(filetype) { case FILE_TYPE_BMP: fprintf(stderr, "%s: file type BMP not implemented\n", __func__); foo = -666; + case FILE_TYPE_EXR: + fprintf(stderr, "%s: file type EXR experimental\n", __func__); + foo = fimg_save_as_exr(pic, fname, 0); default: foo = -1789; break; diff --git a/funcs/fimg-openexr.c b/funcs/fimg-openexr.c new file mode 100644 index 00000000..8ea5e44e --- /dev/null +++ b/funcs/fimg-openexr.c @@ -0,0 +1,30 @@ +/* + * Lecture/ecriture des images EXR + * ------------------------------- + */ + +#include +#include +#include + +#include "../floatimg.h" + +extern int verbosity; + +/* --------------------------------------------------------------------- */ +int fimg_save_as_exr(FloatImg *src, char *outname, int flags) +{ +// #if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p '%s' 0x%X )\n", __func__, src, outname, flags); +// #endif + +if (FIMG_TYPE_RGB != src->type) { + fprintf(stderr, "%s: src bad type %d\n", __func__, src->type); + return -2; + } + + + +return -2; +} +/* --------------------------------------------------------------------- */ diff --git a/funcs/t.c b/funcs/t.c index 671cc418..64443a7d 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -21,7 +21,7 @@ float global_fvalue; /* --------------------------------------------------------------------- */ enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff, Histo, Hsv, Classif, Ctr2x2, Qsortrgb, - Displace, ReadPNG, Plasmas, Hilight }; + Displace, ReadPNG, Plasmas, Hilight, OpenEXR }; typedef struct { char *name; int Cmd; @@ -45,6 +45,7 @@ Command commands[] = { { "readpng", ReadPNG }, { "plasma", Plasmas }, { "hilight", Hilight }, + { "openexr", OpenEXR }, { NULL, 0 } } ; @@ -198,6 +199,9 @@ switch(opt) { case Hilight: foo = essai_highlights(filename, outfile, 0, global_fvalue); break; + case OpenEXR: + foo = essai_openexr(filename, outfile, 0x55); + break; default: fprintf(stderr, "'%s' is a bad command\n", command); exit(1); diff --git a/funcs/tests.c b/funcs/tests.c index b79c08a4..96a6250b 100644 --- a/funcs/tests.c +++ b/funcs/tests.c @@ -16,6 +16,31 @@ extern int verbosity; +/* --------------------------------------------------------------------- */ +/* nouveau 21 mars 2021 - rue d'Aragon */ +int essai_openexr(char *inf, char *outf, int flags) +{ +FloatImg src; +int foo; + +fprintf(stderr, ">>> %s ( '%s' '%s' 0x%X )\n", __func__, + inf, outf, flags); + +foo = fimg_create_from_dump(inf, &src); +if (0 != foo) { + fprintf(stderr, "%s: err %d loading image '%s'\n", __func__, + foo, inf); + return foo; + } +// fprintf(stderr, "image loaded at %p\n", &src); +fimg_describe(&src, "for save EXR test"); + +foo = fimg_save_as_exr(&src, outf, flags); + +fimg_destroy(&src); + +return -2; +} /* --------------------------------------------------------------------- */ /* nouveau 20 mars 2021 - rue d'Aragon */ int essai_highlights(char *inf, char *outf, int ikoef, float fkoef) diff --git a/funcs/tests.h b/funcs/tests.h index 419aec1c..2fb1f09e 100644 --- a/funcs/tests.h +++ b/funcs/tests.h @@ -26,4 +26,5 @@ int essai_histogramme(char *fname, int k); int essai_lecture_png(char *fname, char *outfile, int notused); int essai_highlights(char *inf, char *outf, int ikoef, float fkoef); +int essai_openexr(char *inf, char *outf, int flags); diff --git a/funcs/utils.c b/funcs/utils.c index 67fafa98..61249109 100644 --- a/funcs/utils.c +++ b/funcs/utils.c @@ -73,6 +73,7 @@ if (!strcasecmp(cptr, ".png" )) return FILE_TYPE_PNG; if (!strcasecmp(cptr, ".tiff")) return FILE_TYPE_TIFF; if (!strcasecmp(cptr, ".tif" )) return FILE_TYPE_TIFF; if (!strcasecmp(cptr, ".fits")) return FILE_TYPE_FITS; +if (!strcasecmp(cptr, ".exr")) return FILE_TYPE_EXR; return -1; } diff --git a/lib/Makefile b/lib/Makefile index 25170ce7..0f3dfeac 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -2,7 +2,7 @@ # building the base library # -COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=1 +COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0 OBJS = fimg-core.o fimg-pnm.o fimg-file.o fimg-math.o \ fimg-timers.o operators.o fimg-2gray.o \