Compare commits

..

No commits in common. "4dcc524fc4484791c6682328564d0ad1173a0fa4" and "ddfadf9a674212d8fb1d02a76347aece402b8172" have entirely different histories.

6 changed files with 20 additions and 101 deletions

View File

@ -2,10 +2,9 @@
* 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 (182) #define FIMG_VERSION (181)
#define RELEASE_NAME ("noname") #define RELEASE_NAME ("noname")
/* /*
* in memory descriptor * in memory descriptor
@ -36,7 +35,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 cpid; // process id of the creator uint64_t pid; // process id of the creator
int32_t count; int32_t count;
float fval; float fval;
char idcam[32]; char idcam[32];

View File

@ -68,16 +68,11 @@ FILE *fp;
int foo, nbre; int foo, nbre;
FimgFileHead filehead; FimgFileHead filehead;
#if DEBUG_LEVEL #if 1 // 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;
@ -152,11 +147,6 @@ 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;

View File

@ -32,10 +32,8 @@ 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", \
@ -48,7 +46,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->cpid); fprintf(stderr, "creator pid = %ld\n", pmd->pid);
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);
@ -80,18 +78,15 @@ if (foo) {
perror("omg"); perror("omg");
} }
else { else {
if (verbosity) { fprintf(stderr, "Time of day %12ld %12ld\n", tvl.tv_sec, tvl.tv_usec);
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->cpid = getpid(); pmd->pid = 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 = 0xdeadbeef; pmd->origin = 0x55555555;
return 0; return 0;
} }
@ -103,9 +98,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);
@ -141,8 +136,7 @@ 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;
} }

View File

@ -28,9 +28,6 @@ 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);

View File

@ -13,89 +13,29 @@
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, action; int foo;
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 */ /* switch on command here, please */
action = lookup_cmd(command);
// fprintf(stderr, " command '%s' -> %d\n", command, action);
switch(action) { fimg_show_metadata(&metadata, fname, 0);
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, "*** Fimg Metadata Reader (%s, %s)\n", __DATE__, __TIME__); fprintf(stderr, "*** fimgmetadata (%s, %s)\n", __DATE__, __TIME__);
fimg_print_version(1); fimg_print_version(1);
exit(0); exit(0);
} }
@ -120,7 +60,7 @@ if (2 != nbargs) {
exit(1); exit(1);
} }
foo = get_print_metadata(argv[optind+1], argv[optind]); foo = get_print_metadata(argv[optind], argv[optind+1]);
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;

View File

@ -77,9 +77,8 @@ 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");
puts("\t-m\tadd faked metadata");
fputs("\t-t bla\thowto make the pic :\n\t\t | ", stdout); 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 | "); }
@ -180,7 +179,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);