forked from tTh/FloatImg
adding a file loading func - ugly code
This commit is contained in:
parent
452bc6cf29
commit
538023b586
|
@ -2,7 +2,7 @@
|
||||||
* floatimg.h
|
* floatimg.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define FIMG_VERSION 81
|
#define FIMG_VERSION 82
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* in memory descriptor
|
* in memory descriptor
|
||||||
|
@ -91,6 +91,7 @@ int fimg_mk_gray_from(FloatImg *src, FloatImg*dst, int k);
|
||||||
/* FIMG files module */
|
/* FIMG files module */
|
||||||
int fimg_fileinfos(char *fname, int *datas);
|
int fimg_fileinfos(char *fname, int *datas);
|
||||||
int fimg_dump_to_file(FloatImg *head, char *fname, int notused);
|
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_create_from_dump(char *fname, FloatImg *head);
|
||||||
|
|
||||||
/* mathematics operations */
|
/* mathematics operations */
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "../floatimg.h"
|
#include "../floatimg.h"
|
||||||
|
|
||||||
extern int verbosity; /* must be declared around main() */
|
extern int verbosity; /* must be declared around main() */
|
||||||
|
@ -99,6 +99,47 @@ if (nbre != foo) {
|
||||||
|
|
||||||
fclose(fp);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
/* ---------------------------------------------------------------- */
|
/* ---------------------------------------------------------------- */
|
||||||
|
|
Loading…
Reference in New Issue