Compare commits

..

5 Commits

Author SHA1 Message Date
tth
4dcc524fc4 more fun with metadata 2022-04-17 04:25:31 +02:00
tth
263e254980 bla 2022-04-17 04:20:35 +02:00
tth
27e42a0ddd a little clean 2022-04-17 04:19:06 +02:00
tth
12c3218a93 renaming a member of the metadata struct 2022-04-17 04:03:38 +02:00
tth
8a663a95ee one more step : display metadata 2022-04-17 04:00:12 +02:00
6 changed files with 101 additions and 20 deletions

View File

@ -2,9 +2,10 @@
* floatimg.h
* ugly code from tTh
* http://la.buvette.org/photos/cumul
* https://git.tetalab.org/tTh/FloatImg
*/
#define FIMG_VERSION (181)
#define FIMG_VERSION (182)
#define RELEASE_NAME ("noname")
/*
* in memory descriptor
@ -35,7 +36,7 @@ typedef struct {
typedef struct {
char magic[8]; // this is not an asciiz !
struct timeval timestamp;
uint64_t pid; // process id of the creator
uint64_t cpid; // process id of the creator
int32_t count;
float fval;
char idcam[32];

View File

@ -68,11 +68,16 @@ FILE *fp;
int foo, nbre;
FimgFileHead filehead;
#if 1 // DEBUG_LEVEL
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p '%s' %p %d )\n", __func__, fimg,
fname, pmd, notused);
#endif
if (notused) {
fprintf(stderr, "%s: notused must be 0, was %d\n", \
__func__, notused);
}
if (FIMG_TYPE_RGB != fimg->type) {
fprintf(stderr, "%s : bad type %d\n", __func__, fimg->type);
return -8;
@ -147,6 +152,11 @@ fprintf(stderr, ">>> %-25s ( %p '%s' %d )\n", __func__, fimg,
fname, notused);
#endif
if (notused) {
fprintf(stderr, "%s: notused must be 0, was %d\n", \
__func__, notused);
}
if (FIMG_TYPE_RGB != fimg->type) {
fprintf(stderr, "%s : bad type %d\n", __func__, fimg->type);
return -8;

View File

@ -32,8 +32,10 @@ int fimg_show_metadata(FimgMetaData *pmd, char *title, int notused)
int foo;
double doubletime;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p '%s' 0x%08x )\n", __func__,
pmd, title, notused);
#endif
if (verbosity) {
fprintf(stderr, "sizeof(metadata) = %ld\n", \
@ -46,7 +48,7 @@ fprintf(stderr, "seconds sc. epoch = %ld\n", pmd->timestamp.tv_sec);
doubletime = (double)pmd->timestamp.tv_sec + \
(double)pmd->timestamp.tv_usec / 1e6;
fprintf(stderr, "dtime of day = %e\n", doubletime);
fprintf(stderr, "creator pid = %ld\n", pmd->pid);
fprintf(stderr, "creator pid = %ld\n", pmd->cpid);
fprintf(stderr, "counter = %d\n", pmd->count);
fprintf(stderr, "float value = %.3f\n", pmd->fval);
fprintf(stderr, "id camera = '%s'\n", pmd->idcam);
@ -78,15 +80,18 @@ if (foo) {
perror("omg");
}
else {
fprintf(stderr, "Time of day %12ld %12ld\n", tvl.tv_sec, tvl.tv_usec);
if (verbosity) {
fprintf(stderr, "Time of day %12ld %12ld\n", \
tvl.tv_sec, tvl.tv_usec);
}
memcpy(&(pmd->timestamp), &tvl, sizeof(struct timeval));
}
pmd->pid = getpid();
pmd->cpid = getpid();
pmd->count = 0;
pmd->fval = 255.0;
strcpy(pmd->idcam, "<unknow>");
pmd->origin = 0x55555555;
pmd->origin = 0xdeadbeef;
return 0;
}
@ -98,9 +103,9 @@ FimgFileHead filehead;
FimgMetaData metadata;
int foo;
// #if DEBUG_LEVEL
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %p )\n", __func__, fname, pmd);
// #endif
#endif
if (NULL==(fp=fopen(fname, "r"))) {
perror(fname);
@ -136,7 +141,8 @@ if (1 != foo) {
fclose(fp); /* got all needed datas */
if (memcmp(metadata.magic, "metadata", 8)) {
fprintf(stderr, "'%s' invalid metadata.\n", fname);
fprintf(stderr, "'%s' invalid metadata\n", fname);
puts_magic_8(metadata.magic, stderr);
return -6;
}

View File

@ -28,6 +28,9 @@ foo = fimg_default_metadata(&Md);
foo = fimg_get_metadata_from_file(fname, &Md);
fprintf(stderr, "%s : get metadata -> %d\n", fname, foo);
if (foo) {
return foo;
}
foo = fimg_show_metadata(&Md, fname, 0);

View File

@ -13,29 +13,89 @@
int verbosity;
/* --------------------------------------------------------------------- */
enum comId { C_timestamp, C_count, C_fval, C_cpid, C_origin,
C_idcam, C_all };
typedef struct {
char *name;
int id;
} Cmd;
Cmd Cmd_list[] = {
{ "timestamp", C_timestamp },
{ "cpid", C_cpid },
{ "count", C_count },
{ "fval", C_fval },
{ "origin", C_origin },
{ "idcam", C_idcam },
{ "all", C_all },
{ NULL, 0, }
};
/* --------------------------------------------------------------------- */
int lookup_cmd(char *txt)
{
Cmd *cmd;
int n;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, txt);
#endif
for (n=0, cmd=Cmd_list; cmd->name; cmd++, n++) {
#if DEBUG_LEVEL > 1
fprintf(stderr, " try %-12s %3d\n", cmd->name, n);
#endif
if (!strcmp(cmd->name, txt)) {
// fprintf(stderr, "found '%s' at %d\n", txt, n);
return cmd->id;
}
}
return -1; /* NOT FOUND */
}
/* --------------------------------------------------------------------- */
int get_print_metadata(char *fname, char *command)
{
int foo;
int foo, action;
FimgMetaData metadata;
// #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %s )\n", __func__, fname, command);
// #endif
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' '%s' )\n", __func__, fname, command);
#endif
foo = fimg_get_metadata_from_file(fname, &metadata);
if (foo) return foo;
/* switch on command here, please */
/* switch on command here */
action = lookup_cmd(command);
// fprintf(stderr, " command '%s' -> %d\n", command, action);
fimg_show_metadata(&metadata, fname, 0);
switch(action) {
case C_timestamp:
printf("ts %ld\n", metadata.timestamp.tv_sec); break;
case C_count:
printf("count %d\n", metadata.count); break;
case C_fval:
printf("fval %f\n", metadata.fval); break;
case C_cpid:
printf("cpid %ld\n", metadata.cpid); break;
case C_origin:
printf("origin 0x%x\n", metadata.origin); break;
case C_idcam:
printf("camid \"%s\"\n", metadata.idcam); break;
case C_all:
fimg_show_metadata(&metadata, fname, 0); break;
default:
fprintf(stderr, "WTF?\n"); exit(1);
}
return 0;
}
/* --------------------------------------------------------------------- */
void help(void)
{
fprintf(stderr, "*** fimgmetadata (%s, %s)\n", __DATE__, __TIME__);
fprintf(stderr, "*** Fimg Metadata Reader (%s, %s)\n", __DATE__, __TIME__);
fimg_print_version(1);
exit(0);
}
@ -60,7 +120,7 @@ if (2 != nbargs) {
exit(1);
}
foo = get_print_metadata(argv[optind], argv[optind+1]);
foo = get_print_metadata(argv[optind+1], argv[optind]);
if (foo) fprintf(stderr, "got a %d from job\n", foo);
return 0;

View File

@ -77,8 +77,9 @@ puts("Usage:\tmkfimg [options] quux.fimg width height");
puts("\t-k N.N\tgive a float parameter");
puts("\t-L\tlist howto make a pic");
fputs("\t-t bla\thowto make the pic :\n\t\t | ", stdout);
puts("\t-m\tadd faked metadata");
fputs("\t-t bla\thowto make the pic :\n\t\t | ", stdout);
for (foo=cc=0; types[foo].code; foo++) {
cc += printf("%s ", types[foo].name);
if (cc>35) { cc=0; printf("\n\t\t | "); }
@ -179,7 +180,7 @@ switch(type) {
}
if (wrmdata) {
fprintf(stderr, "%s: warning, metadata is bogus\n", argv[0]);
// fprintf(stderr, "%s: warning, metadata is bogus\n", argv[0]);
(void)fimg_default_metadata(&metadata);
sprintf(metadata.idcam, "mkfimg (libv %d)", FIMG_VERSION);
foo = fimg_dumpmd_to_file(&fimg, fname, &metadata, 0);