try to get mdata from .fimg file

This commit is contained in:
tth 2022-04-08 03:10:43 +02:00
parent f52e24b30c
commit 4b64330884
2 changed files with 56 additions and 1 deletions

View File

@ -4,7 +4,7 @@
* http://la.buvette.org/photos/cumul
*/
#define FIMG_VERSION 176
#define FIMG_VERSION 177
/*
* in memory descriptor

View File

@ -38,6 +38,61 @@ pmd->count = 0;
pmd->fval = 255.0;
strcpy(pmd->idcam, "<unknow>");
pmd->origin = 999;
return -1;
}
/* ---------------------------------------------------------------- */
int fimg_get_metadata_from_file(char *fname, FimgMetaData *pmd)
{
FILE *fp;
FimgFileHead filehead;
FimgMetaData metadata;
int foo;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %s %p )\n", __func__, fname, pmd);
#endif
if (NULL==(fp=fopen(fname, "r"))) {
return -1;
}
foo = fread(&filehead, sizeof(FimgFileHead), 1, fp);
if (sizeof(FimgFileHead) != foo) {
fprintf(stderr, "short read on %s (head)\n", fname);
fclose(fp);
return -2;
}
if (memcmp(filehead.magic, "FIMG", 4)) {
fprintf(stderr, "'%s' is not a fimg file.\n", fname);
fclose(fp);
return -3;
}
if ('a' != filehead.magic[4]) {
fprintf(stderr, "'%s' have no metadata.\n", fname);
fclose(fp);
return -4;
}
foo = fread(&metadata, sizeof(FimgMetaData), 1, fp);
if (sizeof(FimgMetaData) != foo) {
fprintf(stderr, "short read on %s (metadata)\n", fname);
fclose(fp);
return -5;
}
fclose(fp); /* got all needed datas */
if (memcmp(metadata.magic, "metadata", 8)) {
fprintf(stderr, "'%s' invalid metadata.\n", fname);
fclose(fp);
return -6;
}
memcpy(pmd, &metadata, sizeof(FimgMetaData));
return 0;
}
/* ---------------------------------------------------------------- */