diff --git a/floatimg.h b/floatimg.h index de7692b7..92a2a1cd 100644 --- a/floatimg.h +++ b/floatimg.h @@ -2,7 +2,7 @@ * floatimg.h */ -#define FIMG_VERSION 81 +#define FIMG_VERSION 82 /* * in memory descriptor @@ -91,6 +91,7 @@ int fimg_mk_gray_from(FloatImg *src, FloatImg*dst, int k); /* FIMG files module */ int fimg_fileinfos(char *fname, int *datas); 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); /* mathematics operations */ diff --git a/lib/fimg-file.c b/lib/fimg-file.c index 6289ad02..7523ca29 100644 --- a/lib/fimg-file.c +++ b/lib/fimg-file.c @@ -8,7 +8,7 @@ #include #include #include - +#include #include "../floatimg.h" extern int verbosity; /* must be declared around main() */ @@ -99,6 +99,47 @@ if (nbre != foo) { fclose(fp); +return 0; +} +/* ---------------------------------------------------------------- */ +int fimg_load_from_dump(char *fname, FloatImg *where) +{ +FILE *fp; +int foo, nbre; +FimgFileHead filehead; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, fname, head); +#endif + +if (NULL==(fp = fopen(fname, "r"))) { + perror(fname); exit(1); + } +foo = fread(&filehead, sizeof(FimgFileHead), 1, fp); +if (1 != foo) { + fprintf(stderr, "%s : short read\n", fname); + fclose(fp); + return -1; + } + +/* check compatibility */ +if ( (filehead.w != where->width) || + (filehead.h != where->height) || + (filehead.t != where->type) ) { + + fprintf(stderr, "file '%s' incompatible\n", fname); + exit(3); + } + +nbre = filehead.w*filehead.h*filehead.t; /* ugly quirk */ +foo = fread(where->R, sizeof(float), nbre, fp); +if (nbre != foo) { + fprintf(stderr, "err read '%s' : %d\n", fname, errno); + exit(3); + } + +fclose(fp); + return 0; } /* ---------------------------------------------------------------- */