forked from tTh/FloatImg
small patches
This commit is contained in:
parent
5d139312e2
commit
cfe9f8cdae
51
floatimg.h
51
floatimg.h
@ -20,13 +20,41 @@
|
||||
* https://git.tetalab.org/tTh/FloatImg
|
||||
*/
|
||||
|
||||
#define FIMG_VERSION (224)
|
||||
#define FIMG_VERSION (226)
|
||||
#define RELEASE_NAME ("noname")
|
||||
#define PATCH_LEVEL ("aaaa")
|
||||
|
||||
|
||||
/* XXX add a test for stdint.h / uint32_t XXX */
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
/*
|
||||
* new 11 mars 2022, and a lot of iterations
|
||||
* around the concept of metadata for my work.
|
||||
*/
|
||||
/*
|
||||
* we MUST look at packing and endianess problems NOW
|
||||
* and we can think about a fixed size of this datablock
|
||||
*/
|
||||
#define MAGIC_MDATA 0xfe007007
|
||||
typedef struct {
|
||||
uint32_t magic;
|
||||
uint32_t padding;
|
||||
|
||||
struct timeval timestamp; // #include <stdlib.h>
|
||||
uint64_t cpid; // process id of the creator
|
||||
int32_t count;
|
||||
float fval;
|
||||
char idcam[32];
|
||||
int32_t origin; // enum ?
|
||||
uint32_t reserved[8];
|
||||
} FimgMetaData;
|
||||
|
||||
|
||||
/*
|
||||
* in memory descriptor of a floating image
|
||||
* ----------------------------------------
|
||||
*/
|
||||
#define MAGIC_FIMG 0x00F11F00
|
||||
typedef struct {
|
||||
@ -37,6 +65,7 @@ typedef struct {
|
||||
float fval;
|
||||
int count;
|
||||
float *R, *G, *B, *A;
|
||||
FimgMetaData mdatas; // added 20230912
|
||||
int reserved;
|
||||
} FloatImg;
|
||||
|
||||
@ -51,26 +80,6 @@ typedef struct {
|
||||
*/
|
||||
} FimgFileHead;
|
||||
|
||||
/*
|
||||
* new 11 mars 2022, and a lot of iterations
|
||||
* around the concept of metadata for my work.
|
||||
*/
|
||||
typedef struct {
|
||||
char magic[8]; // this is not an asciiz !
|
||||
struct timeval timestamp;
|
||||
uint64_t cpid; // process id of the creator
|
||||
int32_t count;
|
||||
float fval;
|
||||
char idcam[32];
|
||||
int32_t origin; // enum ?
|
||||
uint32_t reserved[8];
|
||||
|
||||
} FimgMetaData;
|
||||
/*
|
||||
* we MUST look at packing and endianess problems NOW
|
||||
* and we can think about a fised size of this datablock
|
||||
*/
|
||||
|
||||
|
||||
#define MAGIC_AREA51 0xA5EA0051
|
||||
typedef struct {
|
||||
|
@ -116,13 +116,15 @@ int fimg_cos_01(FloatImg *s, FloatImg *d, double maxval)
|
||||
int nbre, idx;
|
||||
double dval;
|
||||
|
||||
fprintf(stderr, ">>> %s ( %p %p %g )\n", __func__, s, d, maxval);
|
||||
|
||||
if (s->type != FIMG_TYPE_RGB) {
|
||||
fprintf(stderr, "%s: type %d invalide\n",
|
||||
__func__, s->type);
|
||||
return -4;
|
||||
}
|
||||
|
||||
if (NULL==d) { d = s; }
|
||||
if (NULL==d) { d = s; } /* In place */
|
||||
else {
|
||||
if (d->type != FIMG_TYPE_RGB) {
|
||||
fprintf(stderr, "%s: dst type %d invalide\n",
|
||||
|
@ -305,7 +305,8 @@ fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, fname, head);
|
||||
|
||||
/*
|
||||
* may be we can crash coredump here if the head
|
||||
* descriptor from caller is not blank ?
|
||||
* descriptor from caller is not blank ? Or just
|
||||
* display a warning ?
|
||||
*/
|
||||
|
||||
fp = fopen(fname, "r");
|
||||
@ -339,9 +340,12 @@ if (foo) {
|
||||
if ('a' == filehead.magic[4]) {
|
||||
if (verbosity > 1)
|
||||
{ fprintf(stderr, "%s: %s has metadata\n", __func__, fname); }
|
||||
/* old school processing...
|
||||
foo = fseek(fp, (long)sizeof(FimgMetaData), SEEK_CUR);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s : shit hit the fan\n", __func__);
|
||||
*/
|
||||
foo = fread(&head->mdatas, sizeof(FimgMetaData), 1, fp);
|
||||
if (1 != foo) {
|
||||
fprintf(stderr, "%s: shit hit the fan %d\n", __func__, foo);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
@ -14,22 +14,6 @@
|
||||
|
||||
extern int verbosity; /* must be declared around main() */
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
/*
|
||||
* specific function because magic field is NOT an asciiz !
|
||||
*/
|
||||
static void puts_magic_8(char *ptr, FILE *fp)
|
||||
{
|
||||
int foo;
|
||||
|
||||
fputs("magic = ", fp);
|
||||
fputc('[', fp);
|
||||
for (foo=0; foo<8; foo++) {
|
||||
fputc(ptr[foo], fp);
|
||||
}
|
||||
fputc(']', fp); fputc('\n', fp);
|
||||
fflush(fp);
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
int fimg_show_metadata(FimgMetaData *pmd, char *title, int notused)
|
||||
{
|
||||
@ -51,11 +35,11 @@ if (NULL != title) {
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "sizeof(metadata) = %ld\n", \
|
||||
sizeof(FimgMetaData));
|
||||
puts_magic_8(pmd->magic, stderr);
|
||||
fprintf(stderr, " Magic [%08x]\n", pmd->magic);
|
||||
}
|
||||
|
||||
/* SHOW TIMESTAMP HERE */
|
||||
fprintf(stderr, "seconds sc. epoch = %ld\n", pmd->timestamp.tv_sec);
|
||||
fprintf(stderr, "secs from epoch = %ld\n", pmd->timestamp.tv_sec);
|
||||
fprintf(stderr, "date & time = %s", ctime(&pmd->timestamp.tv_sec));
|
||||
doubletime = (double)pmd->timestamp.tv_sec + \
|
||||
(double)pmd->timestamp.tv_usec / 1e6;
|
||||
@ -75,13 +59,19 @@ fputc('\n', stderr);
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
/*
|
||||
* those values may be loaded from a config file ?
|
||||
*/
|
||||
int fimg_default_metadata(FimgMetaData *pmd, int bla)
|
||||
{
|
||||
int foo;
|
||||
struct timeval tvl;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pmd, bla);
|
||||
#endif
|
||||
|
||||
memset(pmd, 0, sizeof(FimgMetaData));
|
||||
memcpy(pmd->magic, "metadata", 8);
|
||||
|
||||
/* set timestamp here ? */
|
||||
/* CHALLENGE ACCEPTED */
|
||||
@ -99,6 +89,7 @@ else {
|
||||
memcpy(&(pmd->timestamp), &tvl, sizeof(struct timeval));
|
||||
}
|
||||
|
||||
pmd->magic = MAGIC_MDATA;
|
||||
pmd->cpid = getpid(); // we are the creator, no ?
|
||||
pmd->count = 1; // mmmm...
|
||||
pmd->fval = 255.0; // Ok
|
||||
@ -154,12 +145,13 @@ if (1 != foo) {
|
||||
|
||||
fclose(fp); /* got all needed datas */
|
||||
|
||||
if (memcmp(metadata.magic, "metadata", 8)) {
|
||||
fprintf(stderr, "'%s' invalid metadata\n", fname);
|
||||
puts_magic_8(metadata.magic, stderr);
|
||||
return -6;
|
||||
if (MAGIC_MDATA != metadata.magic) {
|
||||
fprintf(stderr, "%s: magic was %08X, wtf?\n", __func__,
|
||||
metadata.magic);
|
||||
return -4;
|
||||
}
|
||||
|
||||
|
||||
memcpy(pmd, &metadata, sizeof(FimgMetaData));
|
||||
|
||||
return 0;
|
||||
|
3
lib/t.c
3
lib/t.c
@ -23,8 +23,7 @@ int foo;
|
||||
fprintf(stderr, "-------- %s ( %s ) --------\n", __func__, fname);
|
||||
|
||||
foo = fimg_default_metadata(&Md, 0);
|
||||
|
||||
// foo = fimg_show_metadata(&Md, "default from t.c", 0);
|
||||
foo = fimg_show_metadata(&Md, "default from t.c", 0);
|
||||
|
||||
foo = fimg_get_metadata_from_file(fname, &Md);
|
||||
fprintf(stderr, "%s : get metadata -> %d\n", fname, foo);
|
||||
|
Loading…
Reference in New Issue
Block a user