Compare commits
3 Commits
5d139312e2
...
1f1398f9f2
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1f1398f9f2 | ||
![]() |
2699476135 | ||
![]() |
cfe9f8cdae |
53
floatimg.h
53
floatimg.h
@ -20,13 +20,41 @@
|
||||
* https://git.tetalab.org/tTh/FloatImg
|
||||
*/
|
||||
|
||||
#define FIMG_VERSION (224)
|
||||
#define FIMG_VERSION (227)
|
||||
#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 {
|
||||
@ -299,6 +308,8 @@ void fimg_drand48(FloatImg *fi, float kmul);
|
||||
long fimg_count_negativ(FloatImg *fi);
|
||||
long fimg_clamp_negativ(FloatImg *fi);
|
||||
|
||||
int fimg_max_of_max(FloatImg *img, float maxes[3]);
|
||||
|
||||
/* various funcs modules */
|
||||
int fimg_load_from_png(char *filename, FloatImg *fimg);
|
||||
int fimg_create_from_png(char *filename, FloatImg *fimg);
|
||||
|
@ -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",
|
||||
|
@ -47,8 +47,8 @@ if (memcmp(filehead.magic, "FIMG", 4)) {
|
||||
}
|
||||
|
||||
/* XXX preparer la gestion des metadata */
|
||||
if ('a' == filehead.magic[4]) {
|
||||
fprintf(stderr,"\n\t****** %s have metadata\n\n", fname);
|
||||
if ('a' == filehead.magic[4] && verbosity) {
|
||||
fprintf(stderr,"\t****** %s have metadata\n", fname);
|
||||
}
|
||||
|
||||
datas[0] = filehead.w;
|
||||
@ -260,7 +260,8 @@ if ( (filehead.w != where->width) ||
|
||||
|
||||
/* XXX preparer la gestion des metadata */
|
||||
if ('a' == filehead.magic[4]) {
|
||||
if (verbosity > 1) fprintf(stderr,"****** %s have metadata\n", fname);
|
||||
if (verbosity > 1) fprintf(stderr,"%s say %s have metadata\n",
|
||||
__func__, fname);
|
||||
foo = fseek(fp, (long)sizeof(FimgMetaData), SEEK_CUR);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: seek error\n", __func__);
|
||||
@ -305,7 +306,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");
|
||||
@ -338,10 +340,13 @@ if (foo) {
|
||||
*/
|
||||
if ('a' == filehead.magic[4]) {
|
||||
if (verbosity > 1)
|
||||
{ fprintf(stderr, "%s: %s has metadata\n", __func__, fname); }
|
||||
{ fprintf(stderr, "in %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();
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,37 @@ for (idx=0; idx<surface; idx++) {
|
||||
else if (fval > mmvals[5]) mmvals[5] = fval;
|
||||
}
|
||||
|
||||
return -0;
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* new: Fri Oct 6 19:51:28 UTC 2023
|
||||
*
|
||||
* can compute the maxima of a lot of pictures...
|
||||
*/
|
||||
|
||||
fimg_max_of_max(FloatImg *img, float maxes[3])
|
||||
{
|
||||
float localmax[3];
|
||||
int idx, surface;
|
||||
float fval;
|
||||
|
||||
localmax[0] = localmax[1] = localmax[2] = -1e9;
|
||||
|
||||
surface = img->width * img->height;
|
||||
for (idx=0; idx<surface; idx++) {
|
||||
fval = img->R[idx];
|
||||
if (fval > localmax[0]) localmax[0] = fval;
|
||||
fval = img->G[idx];
|
||||
if (fval > localmax[1]) localmax[1] = fval;
|
||||
fval = img->B[idx];
|
||||
if (fval > localmax[2]) localmax[2] = fval;
|
||||
}
|
||||
|
||||
if (localmax[0] > maxes[0]) maxes[0] = localmax[0];
|
||||
if (localmax[1] > maxes[1]) maxes[1] = localmax[1];
|
||||
if (localmax[2] > maxes[2]) maxes[2] = localmax[2];
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
int fimg_meanvalues(FloatImg *head, float means[4])
|
||||
|
@ -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);
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
@ -41,11 +42,12 @@ puts("");
|
||||
puts("$ cumulfimgs a.fimg b.fimg c-fimg ...");
|
||||
puts("cumulator options :");
|
||||
puts("\t-g\tconvert to gray level");
|
||||
puts("\t-m\tcompute the max of the maxes");
|
||||
puts("\t-o\tname of output file");
|
||||
puts("\t-s\trescale end image");
|
||||
puts("\t-v\tincrease verbosity");
|
||||
puts("");
|
||||
if (verbosity) { puts("Xperiment"); fimg_print_version(v); }
|
||||
fimg_print_version(v);
|
||||
exit(0);
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
@ -59,17 +61,19 @@ int to_gray = 0;
|
||||
int experiment = 0;
|
||||
int rescale = 0;
|
||||
int src_loaded = 0;
|
||||
int minmax = 0;
|
||||
|
||||
char *output_file = "out.fimg";
|
||||
FloatImg accu, temp;
|
||||
float vals[6];
|
||||
float vals[3];
|
||||
|
||||
g_width = g_height = 0;
|
||||
|
||||
while ((opt = getopt(argc, argv, "gho:svx")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "ghmo:svx")) != -1) {
|
||||
switch(opt) {
|
||||
case 'g': to_gray = 1; break;
|
||||
case 'h': help(1); break;
|
||||
case 'm': minmax++; break;
|
||||
case 'o': output_file = optarg; break;
|
||||
case 's': rescale = 1; break;
|
||||
case 'v': verbosity++; break;
|
||||
@ -83,9 +87,12 @@ if (verbosity) fprintf(stderr, "------ cumulfimgs ------\n");
|
||||
fprintf(stderr, "argc = %d, optind = %d\n", argc, optind);
|
||||
#endif
|
||||
|
||||
memset(vals, 0, 3*sizeof(float));
|
||||
|
||||
for (idx=optind; idx<argc; idx++) {
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "%5d %s\n", idx, argv[idx]);
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "---------------- %s\n", argv[idx]);
|
||||
fflush(stderr);
|
||||
#endif
|
||||
foo = testfile(argv[idx]);
|
||||
if (foo) {
|
||||
@ -93,8 +100,15 @@ for (idx=optind; idx<argc; idx++) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* load the picture, create a clone of the first
|
||||
*/
|
||||
if ( ! src_loaded ) {
|
||||
foo = fimg_create_from_dump(argv[idx], &accu);
|
||||
if (foo) {
|
||||
fprintf(stderr, "create from dump -> %d\n", foo);
|
||||
exit(1);
|
||||
}
|
||||
fimg_clone(&accu, &temp, 0);
|
||||
src_loaded = 1;
|
||||
}
|
||||
@ -104,8 +118,20 @@ for (idx=optind; idx<argc; idx++) {
|
||||
fprintf(stderr, "load from dump -> %d\n", foo);
|
||||
exit(1);
|
||||
}
|
||||
fimg_add_2(&temp, &accu);
|
||||
}
|
||||
|
||||
if (minmax) {
|
||||
/*
|
||||
* print the maximum values and compute the
|
||||
* maximum of all the maximums
|
||||
*/
|
||||
foo = fimg_max_of_max(&temp, vals);
|
||||
// fprintf(stderr, "%5d max of max %9.3f %9.3f %9.3f\n",
|
||||
// idx, vals[0], vals[1], vals[2]);
|
||||
}
|
||||
|
||||
fimg_add_2(&temp, &accu);
|
||||
|
||||
compte++;
|
||||
}
|
||||
|
||||
@ -120,6 +146,9 @@ if (experiment) {
|
||||
}
|
||||
/* XXX */
|
||||
|
||||
fprintf(stderr, "max of max %9.3f %9.3f %9.3f\n",
|
||||
vals[0], vals[1], vals[2]);
|
||||
|
||||
|
||||
if (to_gray) {
|
||||
foo = fimg_desaturate(&accu, &accu, 0);
|
||||
@ -156,6 +185,8 @@ if (verbosity) {
|
||||
vals[4], vals[5], vals[5]-vals[4]);
|
||||
}
|
||||
|
||||
fimg_destroy(&accu); fimg_destroy(&temp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
Loading…
Reference in New Issue
Block a user