From 615321eca8c46529cc77f44243e004cded2503b7 Mon Sep 17 00:00:00 2001 From: tth Date: Sat, 14 May 2022 20:49:59 +0200 Subject: [PATCH] a big commit of garbage --- Fonderie/crapulator.c | 19 ++++++++++++++++++ Fonderie/crapulors.liste | 1 + Fonderie/sfx.c | 32 ++++++++++++++++++++++++++++++ Fonderie/sfx.h | 2 ++ Fonderie/t.c | 10 +++++----- floatimg.h | 8 +++++--- lib/fimg-file.c | 43 ++++++++++++++++++++++++++++++++++++---- lib/metadata.c | 22 ++++++++++++-------- tools/README.md | 4 +++- tools/essai.sh | 14 +++++++++++-- tools/fimgmetadata.c | 2 +- tools/fimgstats.c | 4 +++- tools/mkfimg.c | 2 +- v4l2/essai.sh | 21 ++++++++++++++++---- v4l2/grabvidseq.c | 24 +++++++++++++++++----- 15 files changed, 173 insertions(+), 35 deletions(-) diff --git a/Fonderie/crapulator.c b/Fonderie/crapulator.c index f54d9dbb..e78e9f18 100644 --- a/Fonderie/crapulator.c +++ b/Fonderie/crapulator.c @@ -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); diff --git a/Fonderie/crapulors.liste b/Fonderie/crapulors.liste index 21b6ab98..43568e98 100644 --- a/Fonderie/crapulors.liste +++ b/Fonderie/crapulors.liste @@ -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 diff --git a/Fonderie/sfx.c b/Fonderie/sfx.c index 16112b09..87957fad 100644 --- a/Fonderie/sfx.c +++ b/Fonderie/sfx.c @@ -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; yheight; y++) { + + for (x=0; xwidth; 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 ! diff --git a/Fonderie/sfx.h b/Fonderie/sfx.h index 1463f871..51d13f26 100644 --- a/Fonderie/sfx.h +++ b/Fonderie/sfx.h @@ -3,6 +3,8 @@ * --------------------------------------------------- */ +int graylevel2popcolors(FloatImg *src, FloatImg *dst, int k); + int incrustation_vignette(FloatImg *src, FloatImg *dst, int k); diff --git a/Fonderie/t.c b/Fonderie/t.c index 07d5b39a..275ca893 100644 --- a/Fonderie/t.c +++ b/Fonderie/t.c @@ -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); diff --git a/floatimg.h b/floatimg.h index 443a66fa..aa869638 100644 --- a/floatimg.h +++ b/floatimg.h @@ -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); diff --git a/lib/fimg-file.c b/lib/fimg-file.c index a1612804..11d88c2d 100644 --- a/lib/fimg-file.c +++ b/lib/fimg-file.c @@ -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); diff --git a/lib/metadata.c b/lib/metadata.c index 31c34e1c..9629b026 100644 --- a/lib/metadata.c +++ b/lib/metadata.c @@ -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, ""); -pmd->origin = 0xdeadbeef; +pmd->cpid = getpid(); // we are the creator, no ? +pmd->count = 1; // mmmm... +pmd->fval = 255.0; // Ok +strcpy(pmd->idcam, ""); +pmd->origin = 0xdeadbeef; // classic joke, sorry +pmd->reserved[0] = bla; +pmd->reserved[7] = 0x55445544; // magic number is a crime return 0; } diff --git a/tools/README.md b/tools/README.md index a32cca7b..a2482a9c 100644 --- a/tools/README.md +++ b/tools/README.md @@ -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*. + diff --git a/tools/essai.sh b/tools/essai.sh index 109f1c7f..9d6e54b5 100755 --- a/tools/essai.sh +++ b/tools/essai.sh @@ -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 # ----------------------------------------------------- diff --git a/tools/fimgmetadata.c b/tools/fimgmetadata.c index 7737993e..29efcb04 100644 --- a/tools/fimgmetadata.c +++ b/tools/fimgmetadata.c @@ -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: diff --git a/tools/fimgstats.c b/tools/fimgstats.c index 62277168..0978bba4 100644 --- a/tools/fimgstats.c +++ b/tools/fimgstats.c @@ -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[]) diff --git a/tools/mkfimg.c b/tools/mkfimg.c index b480bd32..c5c28b25 100644 --- a/tools/mkfimg.c +++ b/tools/mkfimg.c @@ -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 diff --git a/v4l2/essai.sh b/v4l2/essai.sh index 9a824b5a..cd7ef7c3 100755 --- a/v4l2/essai.sh +++ b/v4l2/essai.sh @@ -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 # ----------------------------------------------------- diff --git a/v4l2/grabvidseq.c b/v4l2/grabvidseq.c index 36a35177..b5d44763 100644 --- a/v4l2/grabvidseq.c +++ b/v4l2/grabvidseq.c @@ -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);