a big commit of garbage

This commit is contained in:
tth 2022-05-14 20:49:59 +02:00
parent 4dcc524fc4
commit 615321eca8
15 changed files with 173 additions and 35 deletions

View File

@ -212,6 +212,20 @@ ret = fimg_decomp_rgbz_color(img, &tmp, k);
fimg_copy_data(&tmp, img);
fimg_destroy(&tmp);
return ret;
}
/* -------------------------------------------------------------- */
/* nouveau 14 mai 2022 */
static int run_gr2popcol(FloatImg *img, int k)
{
FloatImg tmp;
int ret;
memset(&tmp, 0, sizeof(FloatImg));
fimg_clone(img, &tmp, 0);
ret = graylevel2popcolors(img, &tmp, k);
fimg_copy_data(&tmp, img);
fimg_destroy(&tmp);
return ret;
}
/* -------------------------------------------------------------- */
@ -424,6 +438,11 @@ switch (idFx) {
retval = fimg_highlight_color(image, image, 'R', 1.717);
break;
case CR_gr2popcol:
// fprintf(stderr, "******* TO BE DONE ********\n");
retval = run_gr2popcol(image, -1);
break;
default :
fprintf(stderr, "%s : effect #%d invalid\n",
__func__, idFx);

View File

@ -41,5 +41,6 @@
49 splitlevel 1 1
50 decrgbzc 1 99
51 decrgbzg 1 99
60 gr2popcol 1 99
99 message 1 1.0
-1 end 1 1.0

View File

@ -21,6 +21,38 @@
*/
extern int verbosity;
/* -------------------------------------------------------------- */
/* nouveau 14 mai 2022 rue Ernest Renan */
int graylevel2popcolors(FloatImg *src, FloatImg *dst, int k)
{
int x, y;
float rgb[3];
float theoric_maxval;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, src, dst, k);
#endif
theoric_maxval = src->fval * src->count;
fprintf(stderr, "theoric maxval = %f\n", theoric_maxval);
fimg_clear(dst);
// fimg_export_picture(src, "src.png", 0);
for (y=0; y<src->height; y++) {
for (x=0; x<src->width; x++)
{
fimg_get_rgb(src, x, y, rgb);
rgb[1] = fabs(rgb[0] - rgb[2]);
fimg_put_rgb(dst, x, y, rgb);
}
}
// fimg_export_picture(dst, "dst.png", 0);
return 0;
}
/* -------------------------------------------------------------- */
/*
* please, add some parameters !

View File

@ -3,6 +3,8 @@
* ---------------------------------------------------
*/
int graylevel2popcolors(FloatImg *src, FloatImg *dst, int k);
int incrustation_vignette(FloatImg *src, FloatImg *dst, int k);

View File

@ -166,19 +166,19 @@ int experiment(void)
int foo;
FloatImg image, dest;
fprintf(stderr, "EXPERIMENT\n");
fprintf(stderr, "--------- EXPERIMENT ------------\n");
foo = fimg_create_from_dump("01137.fimg", &image);
foo = fimg_create_from_dump("mire.fimg", &image);
if (foo) {
fprintf(stderr, "%s: err %d on create_from_dump\n",
__func__, foo);
return -1;
}
foo = fimg_clone(&image, &dest, 1);
foo = fimg_copy_data(&image, &dest);
foo = fimg_clone(&image, &dest, 0);
incrustation_vignette(&image, &dest, 0);
foo = graylevel2popcolors(&image, &dest, 0);
fprintf(stderr, "POP COLOR- -> %d\n", foo);
fimg_export_picture(&dest, "foo.png", 0);

View File

@ -5,7 +5,7 @@
* https://git.tetalab.org/tTh/FloatImg
*/
#define FIMG_VERSION (182)
#define FIMG_VERSION (185)
#define RELEASE_NAME ("noname")
/*
* in memory descriptor
@ -45,7 +45,9 @@ typedef struct {
} FimgMetaData;
/*
* we MUST look at packing and endianess problems NOW */
* we MUST look at packing and endianess problems NOW
* and we can thing about a fised size of this datablock
*/
#define MAGIC_AREA51 0xA5EA0051
@ -233,7 +235,7 @@ int fimg_create_from_dump(char *fname, FloatImg *head);
/* FIMG metadata module */
int fimg_show_metadata(FimgMetaData *pmd, char *title, int notused);
int fimg_default_metadata(FimgMetaData *pmd);
int fimg_default_metadata(FimgMetaData *pmd, int bla);
int fimg_get_metadata_from_file(char *fname, FimgMetaData *pmd);
int fimg_save_R_as_fits(FloatImg *src, char *outname, int flags);

View File

@ -48,7 +48,7 @@ if (memcmp(filehead.magic, "FIMG", 4)) {
/* XXX preparer la gestion des metadata */
if ('a' == filehead.magic[4]) {
fprintf(stderr,"****** %s have metadata\n", fname);
fprintf(stderr,"\n\t****** %s have metadata\n\n", fname);
}
datas[0] = filehead.w;
@ -67,6 +67,7 @@ int fimg_dumpmd_to_file(FloatImg *fimg, char *fname, \
FILE *fp;
int foo, nbre;
FimgFileHead filehead;
FimgMetaData fakemd;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p '%s' %p %d )\n", __func__, fimg,
@ -83,6 +84,20 @@ if (FIMG_TYPE_RGB != fimg->type) {
return -8;
}
/* OK, we have to make a fake metadata chunk, if the caller
* don't have one. Ugly, and nice */
if (NULL == pmd) {
fprintf(stderr, ">>> %s making faked metadata\n", __func__);
foo = fimg_default_metadata(&fakemd, 3);
fprintf(stderr, "fakemd is at %p\n", &fakemd);
pmd = &fakemd;
}
else {
/* OK, get some funky metadatas */
fprintf(stderr, "OK %s get funky metadatas\n", __func__);
fprintf(stderr, "acquisition values %f %d\n", pmd->fval, pmd->count);
}
fp = fopen(fname, "w");
if (NULL==fp) {
perror(fname);
@ -96,7 +111,7 @@ filehead.t = fimg->type;
/* XXX metadata */
if (NULL != pmd) {
fprintf(stderr, "ok, %s give an 'a' flag\n", __func__);
filehead.magic[4] = 'a';
}
@ -108,8 +123,9 @@ if (1 != foo) {
return -2;
}
/* XXX metadata */
/* we have metadata, put them on tape */
if (NULL != pmd) {
fprintf(stderr, ">>> %s write metadata %p\n", __func__, pmd);
foo = fwrite(pmd, sizeof(FimgMetaData), 1, fp);
if (1 != foo) {
perror(fname);
@ -236,6 +252,12 @@ if ( (filehead.w != where->width) ||
/* XXX preparer la gestion des metadata */
if ('a' == filehead.magic[4]) {
fprintf(stderr,"****** %s have metadata\n", fname);
foo = fseek(fp, (long)sizeof(FimgMetaData), SEEK_CUR);
if (foo) {
fprintf(stderr, "%s: seek error\n", __func__);
perror(fname);
exit(1);
}
}
nbre = filehead.w * filehead.h; /* number of pixels per frame */
@ -274,7 +296,7 @@ fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, fname, head);
/*
* may be we can crash coredump here if the head
* descriptor is not blank ?
* descriptor from calleris not blank ?
*/
fp = fopen(fname, "r");
@ -301,6 +323,19 @@ if (foo) {
return foo;
}
/* bugfix Sat 14 May 2022 07:02:53 PM CEST */
/*
* Oh boy, we have to skeep the metadata chunck
*/
if ('a' == filehead.magic[4]) {
fprintf(stderr, "OMG %s metadata !!!\n", __func__);
foo = fseek(fp, (long)sizeof(FimgMetaData), SEEK_CUR);
if (foo) {
fprintf(stderr, "%s : shit hit the fan\n", __func__);
abort();
}
}
size = filehead.w * filehead.h;
nbread = 0;
nbread += fread(head->R, sizeof(float), size, fp);

View File

@ -37,6 +37,10 @@ fprintf(stderr, ">>> %s ( %p '%s' 0x%08x )\n", __func__,
pmd, title, notused);
#endif
if (NULL != title) {
fprintf(stderr, "==== metadate for %s\n", title);
}
if (verbosity) {
fprintf(stderr, "sizeof(metadata) = %ld\n", \
sizeof(FimgMetaData));
@ -49,8 +53,8 @@ doubletime = (double)pmd->timestamp.tv_sec + \
(double)pmd->timestamp.tv_usec / 1e6;
fprintf(stderr, "dtime of day = %e\n", doubletime);
fprintf(stderr, "creator pid = %ld\n", pmd->cpid);
fprintf(stderr, "counter = %d\n", pmd->count);
fprintf(stderr, "float value = %.3f\n", pmd->fval);
fprintf(stderr, "counter = %d\n", pmd->count);
fprintf(stderr, "id camera = '%s'\n", pmd->idcam);
fprintf(stderr, "origin = 0x%x\n", pmd->origin);
@ -63,7 +67,7 @@ fputc('\n', stderr);
return 0;
}
/* ---------------------------------------------------------------- */
int fimg_default_metadata(FimgMetaData *pmd)
int fimg_default_metadata(FimgMetaData *pmd, int bla)
{
int foo;
struct timeval tvl;
@ -81,17 +85,19 @@ if (foo) {
}
else {
if (verbosity) {
fprintf(stderr, "Time of day %12ld %12ld\n", \
fprintf(stderr, " set TimeOfDay to %12ld , %8ld\n", \
tvl.tv_sec, tvl.tv_usec);
}
memcpy(&(pmd->timestamp), &tvl, sizeof(struct timeval));
}
pmd->cpid = getpid();
pmd->count = 0;
pmd->fval = 255.0;
strcpy(pmd->idcam, "<unknow>");
pmd->origin = 0xdeadbeef;
pmd->cpid = getpid(); // we are the creator, no ?
pmd->count = 1; // mmmm...
pmd->fval = 255.0; // Ok
strcpy(pmd->idcam, "<noname>");
pmd->origin = 0xdeadbeef; // classic joke, sorry
pmd->reserved[0] = bla;
pmd->reserved[7] = 0x55445544; // magic number is a crime
return 0;
}

View File

@ -40,8 +40,10 @@ ne sont gérés que de façon très rudimentaire.
## fimg2text
Nouveau de l'année 2020+1 : exfiltrer toutes des données d'une image flottante
afin de les rendre machinables.
afin de les rendre machinables. Voir aussi *fimgmetadata*.
## fimgmetadata
Nouveau avril 2022. Need more doc...
Voir aussi *fimg2text*.

View File

@ -6,8 +6,18 @@
# -----------------------------------------------------
TMPF="../funcs/in.fimg"
TMPF="bar.fimg"
# -----------------------------------------------------
function essai_metadata
{
echo " ____ essai metadata ________"
./mkfimg -v -m -t hdeg $TMPF 800 600
echo ; echo
./fimgstats $TMPF
echo ; echo
./fimgmetadata all $TMPF
}
# -----------------------------------------------------
function essai_rot90
{
@ -53,6 +63,6 @@ function essai_hilight
}
# -----------------------------------------------------
essai_hilight
essai_metadata
# -----------------------------------------------------

View File

@ -73,7 +73,7 @@ action = lookup_cmd(command);
switch(action) {
case C_timestamp:
printf("ts %ld\n", metadata.timestamp.tv_sec); break;
printf("timestamp %ld\n", metadata.timestamp.tv_sec); break;
case C_count:
printf("count %d\n", metadata.count); break;
case C_fval:

View File

@ -10,7 +10,6 @@
#include "../floatimg.h"
int verbosity; /* global */
int make_csv;
/* --------------------------------------------------------------------- */
@ -108,6 +107,9 @@ fputs( "usage : fimgstats [options] file.fimg\n"
"\t-c\tmake a machinable csv\n"
"\t-v\tincrease verbosity\n"
, stderr);
if (k) {
fimg_print_version(k);
}
}
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])

View File

@ -181,7 +181,7 @@ switch(type) {
if (wrmdata) {
// fprintf(stderr, "%s: warning, metadata is bogus\n", argv[0]);
(void)fimg_default_metadata(&metadata);
(void)fimg_default_metadata(&metadata, 9);
sprintf(metadata.idcam, "mkfimg (libv %d)", FIMG_VERSION);
foo = fimg_dumpmd_to_file(&fimg, fname, &metadata, 0);
#if DEBUG_LEVEL

View File

@ -2,11 +2,24 @@
# -----------------------------------------------------
TMPF="tmp.fimg"
FIMG="bar.fimg"
CAM="/dev/video0"
# -----------------------------------------------------
./grabvidseq -d $CAM -n 10000 -vv -p 0 -r 90
clear
# -----------------------------------------------------
SEQ=" -n 60 -p 0 "
./grabvidseq -vv -m -d $CAM $SEQ -o $FIMG
echo ; echo ================= STATS ======================
../tools/fimgstats -v $FIMG
exit
echo
echo ================ METADATA ====================
../tools/fimgmetadata -v timestamp $FIMG
echo
../tools/fimgmetadata -v all $FIMG
# -----------------------------------------------------

View File

@ -80,6 +80,7 @@ if (verbosity) {
puts("options :");
puts("\t-d /dev/?\tselect video device");
puts("\t-g\t\tconvert to gray");
puts("\t-m\t\ttry to add metadata");
puts("\t-n NNN\t\thow many frames ?");
puts("\t-O ./\t\tset Output dir");
puts("\t-o bla.xxx\tset output filename");
@ -90,7 +91,7 @@ puts("\t-c mode\t\tcontrast enhancement");
puts("\t-u\t\ttry upscaling...");
puts("\t-v\t\tincrease verbosity");
puts("\t-Z\t\tenable systrace");
if (verbosity) {
if (verbosity > 1) {
puts("\n\t\tXXX list all the contrast modes, please\n");
}
exit(0);
@ -125,13 +126,15 @@ int upscaling = 0;
int contrast = CONTRAST_NONE;
int rotfactor = 0; /* only 0 or 90 here */
char *dest_dir = "."; /* no trailing slash */
char *outfile = "out.pnm";
char *outfile = "out.fimg";
int add_metadata = 0;
FimgMetaData metadata;
#if SAVE_AS_CUMUL
FloatImg cumul, tmpfimg, *to_save;
#endif
while ((opt = getopt(argc, argv, "c:d:ghn:o:O:p:r:s:uvZ")) != -1) {
while ((opt = getopt(argc, argv, "c:d:ghmn:o:O:p:r:s:uvZ")) != -1) {
switch(opt) {
case 'c': contrast = fimg_id_contraste(optarg);
if (contrast < 0) {
@ -142,6 +145,7 @@ while ((opt = getopt(argc, argv, "c:d:ghn:o:O:p:r:s:uvZ")) != -1) {
case 'd': dev_name = optarg; break;
case 'g': to_gray = 1; break;
case 'h': help(0); break;
case 'm': add_metadata++; break;
case 'n': nbre_capt = atoi(optarg); break;
case 'O': dest_dir = optarg; break;
case 'o': outfile = optarg; break;
@ -386,11 +390,21 @@ if (90 == rotfactor) {
to_save = &tmpfimg;
}
foo = format_from_extension(outfile);
switch (foo) {
case FILE_TYPE_FIMG:
foo = fimg_dump_to_file(to_save, outfile, 0);
fimg_default_metadata(&metadata, 51);
/* copy some values to mdstruct */
metadata.fval = to_save->fval;
metadata.count = to_save->count;
if (add_metadata) {
fprintf(stderr, ">>> save %s with md\n", outfile);
foo = fimg_dumpmd_to_file(to_save, outfile, \
&metadata, 0);
}
else {
foo = fimg_dump_to_file(to_save, outfile, 0);
}
break;
case FILE_TYPE_PNM:
foo = fimg_save_as_pnm(to_save, outfile, 1);