small patches

This commit is contained in:
tTh 2023-10-06 21:34:11 +02:00
parent 5d139312e2
commit cfe9f8cdae
5 changed files with 56 additions and 50 deletions

View File

@ -20,13 +20,41 @@
* https://git.tetalab.org/tTh/FloatImg * https://git.tetalab.org/tTh/FloatImg
*/ */
#define FIMG_VERSION (224) #define FIMG_VERSION (226)
#define RELEASE_NAME ("noname") #define RELEASE_NAME ("noname")
#define PATCH_LEVEL ("aaaa")
/* XXX add a test for stdint.h / uint32_t XXX */ /* XXX add a test for stdint.h / uint32_t XXX */
#include <stdint.h> #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 * in memory descriptor of a floating image
* ----------------------------------------
*/ */
#define MAGIC_FIMG 0x00F11F00 #define MAGIC_FIMG 0x00F11F00
typedef struct { typedef struct {
@ -37,6 +65,7 @@ typedef struct {
float fval; float fval;
int count; int count;
float *R, *G, *B, *A; float *R, *G, *B, *A;
FimgMetaData mdatas; // added 20230912
int reserved; int reserved;
} FloatImg; } FloatImg;
@ -51,26 +80,6 @@ typedef struct {
*/ */
} FimgFileHead; } 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 #define MAGIC_AREA51 0xA5EA0051
typedef struct { typedef struct {

View File

@ -116,13 +116,15 @@ int fimg_cos_01(FloatImg *s, FloatImg *d, double maxval)
int nbre, idx; int nbre, idx;
double dval; double dval;
fprintf(stderr, ">>> %s ( %p %p %g )\n", __func__, s, d, maxval);
if (s->type != FIMG_TYPE_RGB) { if (s->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s: type %d invalide\n", fprintf(stderr, "%s: type %d invalide\n",
__func__, s->type); __func__, s->type);
return -4; return -4;
} }
if (NULL==d) { d = s; } if (NULL==d) { d = s; } /* In place */
else { else {
if (d->type != FIMG_TYPE_RGB) { if (d->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s: dst type %d invalide\n", fprintf(stderr, "%s: dst type %d invalide\n",

View File

@ -305,7 +305,8 @@ fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, fname, head);
/* /*
* may be we can crash coredump here if the 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"); fp = fopen(fname, "r");
@ -339,9 +340,12 @@ if (foo) {
if ('a' == filehead.magic[4]) { if ('a' == filehead.magic[4]) {
if (verbosity > 1) if (verbosity > 1)
{ fprintf(stderr, "%s: %s has metadata\n", __func__, fname); } { fprintf(stderr, "%s: %s has metadata\n", __func__, fname); }
/* old school processing...
foo = fseek(fp, (long)sizeof(FimgMetaData), SEEK_CUR); 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(); abort();
} }
} }

View File

@ -14,22 +14,6 @@
extern int verbosity; /* must be declared around main() */ 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) int fimg_show_metadata(FimgMetaData *pmd, char *title, int notused)
{ {
@ -51,11 +35,11 @@ if (NULL != title) {
if (verbosity) { if (verbosity) {
fprintf(stderr, "sizeof(metadata) = %ld\n", \ fprintf(stderr, "sizeof(metadata) = %ld\n", \
sizeof(FimgMetaData)); sizeof(FimgMetaData));
puts_magic_8(pmd->magic, stderr); fprintf(stderr, " Magic [%08x]\n", pmd->magic);
} }
/* SHOW TIMESTAMP HERE */ /* 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)); fprintf(stderr, "date & time = %s", ctime(&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;
@ -75,13 +59,19 @@ fputc('\n', stderr);
return 0; return 0;
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
/*
* those values may be loaded from a config file ?
*/
int fimg_default_metadata(FimgMetaData *pmd, int bla) int fimg_default_metadata(FimgMetaData *pmd, int bla)
{ {
int foo; int foo;
struct timeval tvl; struct timeval tvl;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pmd, bla);
#endif
memset(pmd, 0, sizeof(FimgMetaData)); memset(pmd, 0, sizeof(FimgMetaData));
memcpy(pmd->magic, "metadata", 8);
/* set timestamp here ? */ /* set timestamp here ? */
/* CHALLENGE ACCEPTED */ /* CHALLENGE ACCEPTED */
@ -99,6 +89,7 @@ else {
memcpy(&(pmd->timestamp), &tvl, sizeof(struct timeval)); memcpy(&(pmd->timestamp), &tvl, sizeof(struct timeval));
} }
pmd->magic = MAGIC_MDATA;
pmd->cpid = getpid(); // we are the creator, no ? pmd->cpid = getpid(); // we are the creator, no ?
pmd->count = 1; // mmmm... pmd->count = 1; // mmmm...
pmd->fval = 255.0; // Ok pmd->fval = 255.0; // Ok
@ -154,12 +145,13 @@ if (1 != foo) {
fclose(fp); /* got all needed datas */ fclose(fp); /* got all needed datas */
if (memcmp(metadata.magic, "metadata", 8)) { if (MAGIC_MDATA != metadata.magic) {
fprintf(stderr, "'%s' invalid metadata\n", fname); fprintf(stderr, "%s: magic was %08X, wtf?\n", __func__,
puts_magic_8(metadata.magic, stderr); metadata.magic);
return -6; return -4;
} }
memcpy(pmd, &metadata, sizeof(FimgMetaData)); memcpy(pmd, &metadata, sizeof(FimgMetaData));
return 0; return 0;

View File

@ -23,8 +23,7 @@ int foo;
fprintf(stderr, "-------- %s ( %s ) --------\n", __func__, fname); fprintf(stderr, "-------- %s ( %s ) --------\n", __func__, fname);
foo = fimg_default_metadata(&Md, 0); 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); 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);