Compare commits
5 Commits
ddfadf9a67
...
4dcc524fc4
Author | SHA1 | Date | |
---|---|---|---|
|
4dcc524fc4 | ||
|
263e254980 | ||
|
27e42a0ddd | ||
|
12c3218a93 | ||
|
8a663a95ee |
@ -2,9 +2,10 @@
|
|||||||
* floatimg.h
|
* floatimg.h
|
||||||
* ugly code from tTh
|
* ugly code from tTh
|
||||||
* http://la.buvette.org/photos/cumul
|
* http://la.buvette.org/photos/cumul
|
||||||
|
* https://git.tetalab.org/tTh/FloatImg
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define FIMG_VERSION (181)
|
#define FIMG_VERSION (182)
|
||||||
#define RELEASE_NAME ("noname")
|
#define RELEASE_NAME ("noname")
|
||||||
/*
|
/*
|
||||||
* in memory descriptor
|
* in memory descriptor
|
||||||
@ -35,7 +36,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
char magic[8]; // this is not an asciiz !
|
char magic[8]; // this is not an asciiz !
|
||||||
struct timeval timestamp;
|
struct timeval timestamp;
|
||||||
uint64_t pid; // process id of the creator
|
uint64_t cpid; // process id of the creator
|
||||||
int32_t count;
|
int32_t count;
|
||||||
float fval;
|
float fval;
|
||||||
char idcam[32];
|
char idcam[32];
|
||||||
|
@ -68,11 +68,16 @@ FILE *fp;
|
|||||||
int foo, nbre;
|
int foo, nbre;
|
||||||
FimgFileHead filehead;
|
FimgFileHead filehead;
|
||||||
|
|
||||||
#if 1 // DEBUG_LEVEL
|
#if DEBUG_LEVEL
|
||||||
fprintf(stderr, ">>> %s ( %p '%s' %p %d )\n", __func__, fimg,
|
fprintf(stderr, ">>> %s ( %p '%s' %p %d )\n", __func__, fimg,
|
||||||
fname, pmd, notused);
|
fname, pmd, notused);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (notused) {
|
||||||
|
fprintf(stderr, "%s: notused must be 0, was %d\n", \
|
||||||
|
__func__, notused);
|
||||||
|
}
|
||||||
|
|
||||||
if (FIMG_TYPE_RGB != fimg->type) {
|
if (FIMG_TYPE_RGB != fimg->type) {
|
||||||
fprintf(stderr, "%s : bad type %d\n", __func__, fimg->type);
|
fprintf(stderr, "%s : bad type %d\n", __func__, fimg->type);
|
||||||
return -8;
|
return -8;
|
||||||
@ -147,6 +152,11 @@ fprintf(stderr, ">>> %-25s ( %p '%s' %d )\n", __func__, fimg,
|
|||||||
fname, notused);
|
fname, notused);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (notused) {
|
||||||
|
fprintf(stderr, "%s: notused must be 0, was %d\n", \
|
||||||
|
__func__, notused);
|
||||||
|
}
|
||||||
|
|
||||||
if (FIMG_TYPE_RGB != fimg->type) {
|
if (FIMG_TYPE_RGB != fimg->type) {
|
||||||
fprintf(stderr, "%s : bad type %d\n", __func__, fimg->type);
|
fprintf(stderr, "%s : bad type %d\n", __func__, fimg->type);
|
||||||
return -8;
|
return -8;
|
||||||
|
@ -32,8 +32,10 @@ int fimg_show_metadata(FimgMetaData *pmd, char *title, int notused)
|
|||||||
int foo;
|
int foo;
|
||||||
double doubletime;
|
double doubletime;
|
||||||
|
|
||||||
|
#if DEBUG_LEVEL
|
||||||
fprintf(stderr, ">>> %s ( %p '%s' 0x%08x )\n", __func__,
|
fprintf(stderr, ">>> %s ( %p '%s' 0x%08x )\n", __func__,
|
||||||
pmd, title, notused);
|
pmd, title, notused);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (verbosity) {
|
if (verbosity) {
|
||||||
fprintf(stderr, "sizeof(metadata) = %ld\n", \
|
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 + \
|
doubletime = (double)pmd->timestamp.tv_sec + \
|
||||||
(double)pmd->timestamp.tv_usec / 1e6;
|
(double)pmd->timestamp.tv_usec / 1e6;
|
||||||
fprintf(stderr, "dtime of day = %e\n", doubletime);
|
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, "counter = %d\n", pmd->count);
|
||||||
fprintf(stderr, "float value = %.3f\n", pmd->fval);
|
fprintf(stderr, "float value = %.3f\n", pmd->fval);
|
||||||
fprintf(stderr, "id camera = '%s'\n", pmd->idcam);
|
fprintf(stderr, "id camera = '%s'\n", pmd->idcam);
|
||||||
@ -78,15 +80,18 @@ if (foo) {
|
|||||||
perror("omg");
|
perror("omg");
|
||||||
}
|
}
|
||||||
else {
|
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));
|
memcpy(&(pmd->timestamp), &tvl, sizeof(struct timeval));
|
||||||
}
|
}
|
||||||
|
|
||||||
pmd->pid = getpid();
|
pmd->cpid = getpid();
|
||||||
pmd->count = 0;
|
pmd->count = 0;
|
||||||
pmd->fval = 255.0;
|
pmd->fval = 255.0;
|
||||||
strcpy(pmd->idcam, "<unknow>");
|
strcpy(pmd->idcam, "<unknow>");
|
||||||
pmd->origin = 0x55555555;
|
pmd->origin = 0xdeadbeef;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -98,9 +103,9 @@ FimgFileHead filehead;
|
|||||||
FimgMetaData metadata;
|
FimgMetaData metadata;
|
||||||
int foo;
|
int foo;
|
||||||
|
|
||||||
// #if DEBUG_LEVEL
|
#if DEBUG_LEVEL
|
||||||
fprintf(stderr, ">>> %s ( '%s' %p )\n", __func__, fname, pmd);
|
fprintf(stderr, ">>> %s ( '%s' %p )\n", __func__, fname, pmd);
|
||||||
// #endif
|
#endif
|
||||||
|
|
||||||
if (NULL==(fp=fopen(fname, "r"))) {
|
if (NULL==(fp=fopen(fname, "r"))) {
|
||||||
perror(fname);
|
perror(fname);
|
||||||
@ -136,7 +141,8 @@ if (1 != foo) {
|
|||||||
fclose(fp); /* got all needed datas */
|
fclose(fp); /* got all needed datas */
|
||||||
|
|
||||||
if (memcmp(metadata.magic, "metadata", 8)) {
|
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;
|
return -6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
lib/t.c
3
lib/t.c
@ -28,6 +28,9 @@ foo = fimg_default_metadata(&Md);
|
|||||||
|
|
||||||
foo = fimg_get_metadata_from_file(fname, &Md);
|
foo = fimg_get_metadata_from_file(fname, &Md);
|
||||||
fprintf(stderr, "%s : get metadata -> %d\n", fname, foo);
|
fprintf(stderr, "%s : get metadata -> %d\n", fname, foo);
|
||||||
|
if (foo) {
|
||||||
|
return foo;
|
||||||
|
}
|
||||||
|
|
||||||
foo = fimg_show_metadata(&Md, fname, 0);
|
foo = fimg_show_metadata(&Md, fname, 0);
|
||||||
|
|
||||||
|
@ -13,29 +13,89 @@
|
|||||||
|
|
||||||
int verbosity;
|
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 get_print_metadata(char *fname, char *command)
|
||||||
{
|
{
|
||||||
int foo;
|
int foo, action;
|
||||||
FimgMetaData metadata;
|
FimgMetaData metadata;
|
||||||
|
|
||||||
// #if DEBUG_LEVEL
|
#if DEBUG_LEVEL
|
||||||
fprintf(stderr, ">>> %s ( '%s' %s )\n", __func__, fname, command);
|
fprintf(stderr, ">>> %s ( '%s' '%s' )\n", __func__, fname, command);
|
||||||
// #endif
|
#endif
|
||||||
|
|
||||||
foo = fimg_get_metadata_from_file(fname, &metadata);
|
foo = fimg_get_metadata_from_file(fname, &metadata);
|
||||||
if (foo) return foo;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
/* --------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------- */
|
||||||
void help(void)
|
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);
|
fimg_print_version(1);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
@ -60,7 +120,7 @@ if (2 != nbargs) {
|
|||||||
exit(1);
|
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);
|
if (foo) fprintf(stderr, "got a %d from job\n", foo);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -77,8 +77,9 @@ puts("Usage:\tmkfimg [options] quux.fimg width height");
|
|||||||
|
|
||||||
puts("\t-k N.N\tgive a float parameter");
|
puts("\t-k N.N\tgive a float parameter");
|
||||||
puts("\t-L\tlist howto make a pic");
|
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++) {
|
for (foo=cc=0; types[foo].code; foo++) {
|
||||||
cc += printf("%s ", types[foo].name);
|
cc += printf("%s ", types[foo].name);
|
||||||
if (cc>35) { cc=0; printf("\n\t\t | "); }
|
if (cc>35) { cc=0; printf("\n\t\t | "); }
|
||||||
@ -179,7 +180,7 @@ switch(type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wrmdata) {
|
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);
|
(void)fimg_default_metadata(&metadata);
|
||||||
sprintf(metadata.idcam, "mkfimg (libv %d)", FIMG_VERSION);
|
sprintf(metadata.idcam, "mkfimg (libv %d)", FIMG_VERSION);
|
||||||
foo = fimg_dumpmd_to_file(&fimg, fname, &metadata, 0);
|
foo = fimg_dumpmd_to_file(&fimg, fname, &metadata, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user