forked from tTh/FloatImg
99 lines
2.3 KiB
C
99 lines
2.3 KiB
C
/*
|
|
* metadata.c
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <unistd.h>
|
|
#include "string.h"
|
|
|
|
#include "../floatimg.h"
|
|
|
|
extern int verbosity; /* must be declared around main() */
|
|
|
|
/* ---------------------------------------------------------------- */
|
|
int fimg_show_metadata(FimgMetaData *pmd, char *title, int notused)
|
|
{
|
|
|
|
fprintf(stderr, ">>> %s ( %p '%s' 0x%08x )\n", __func__,
|
|
pmd, title, notused);
|
|
|
|
fprintf(stderr, "sizeof metadata = %ld\n", sizeof(FimgMetaData));
|
|
fprintf(stderr, "magic = '%8s'\n", pmd->magic);
|
|
/* TIMESTAMP HERE */
|
|
fprintf(stderr, "counter = %d\n", pmd->count);
|
|
fprintf(stderr, "float value = %.3f\n", pmd->fval);
|
|
fprintf(stderr, "id camera = '%s'\n", pmd->idcam);
|
|
fprintf(stderr, "origin = %d\n", pmd->origin);
|
|
|
|
return -1;
|
|
}
|
|
/* ---------------------------------------------------------------- */
|
|
int fimg_default_metadata(FimgMetaData *pmd)
|
|
{
|
|
|
|
memcpy(pmd->magic, "metadata", 8);
|
|
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;
|
|
}
|
|
/* ---------------------------------------------------------------- */
|