From cb599a253c248677e1fcdb0fea22764562e7d65d Mon Sep 17 00:00:00 2001 From: tTh Date: Sat, 29 Apr 2023 19:29:45 +0200 Subject: [PATCH] more experiments in progress --- Fonderie/sfx.c | 21 +++++++-- experiment/Makefile | 6 +++ experiment/README.md | 9 ++++ experiment/fimg2obj.c | 67 ++++++++++++++++++++++++++++ experiment/mnt.c | 100 ++++++++++++++++++++++++++++++++++++++++++ floatimg.h | 2 +- 6 files changed, 201 insertions(+), 4 deletions(-) create mode 100644 experiment/fimg2obj.c create mode 100644 experiment/mnt.c diff --git a/Fonderie/sfx.c b/Fonderie/sfx.c index 00b601a0..6cb0867a 100644 --- a/Fonderie/sfx.c +++ b/Fonderie/sfx.c @@ -129,16 +129,31 @@ float vals[3]; fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, notused); #endif -#define STP 16 /* stepd for x & y axex */ +/* XXX CRITICAL BUG XXX + * + * what to do if STP is not a modulo of + * the width (or size) of the picture ? + * why if img height is 600 and stp was 16 ? + + tth@redlady:~/Devel/FloatImg/Fonderie$ bc -l + 600/16 + 37.50000000000000000000 + + * + * And this mistake is all around the code /o\ + * + */ +#define STP 8 /* stepd for x & y axex */ coo[2] = coo[3] = STP; -for (y=0; yheight; y+=STP) { +for (y=0; y < pimg->height; y+=STP) { coo[1] = y; - for (x=0; xwidth; x+=STP) { + for (x=0; x < pimg->width; x+=STP) { coo[0] = x; foo = stat_zone(pimg, coo, vals); if (foo) abort(); /* next step : plot the datas */ + // XXX fprintf(stderr, "%s %6d %6d\n", __func__, x, y); pixel_trinitron(pimg, coo, vals); } } diff --git a/experiment/Makefile b/experiment/Makefile index ff6a6a6b..1f435ff0 100644 --- a/experiment/Makefile +++ b/experiment/Makefile @@ -23,6 +23,12 @@ muxplanes: muxplanes.c ${DEPS} movepixels: movepixels.c ${DEPS} gcc $(COPT) $< ../libfloatimg.a ${LIBS} -o $@ +mnt: mnt.c ${DEPS} + gcc $(COPT) $< ../libfloatimg.a ${LIBS} -o $@ + +fimg2obj: fimg2obj.c $(DEPS) + gcc $(COPT) $< ../libfloatimg.a ${LIBS} -o $@ + # --------------------------------------------------------- # CACHE ENGINE diff --git a/experiment/README.md b/experiment/README.md index 789c40da..089c4f95 100644 --- a/experiment/README.md +++ b/experiment/README.md @@ -9,4 +9,13 @@ Le contenu de ce répertoire doit donc être considéré comme **volatile**. Si vous y trouvez votre bonheur, il serait sage d'en faire une copie personnelle... +## MNT + +Modèles numériques de terrain. Rien ne marche. + +## fimg2obj + +Création d'un fichier .OBG (de Wavefront) à partir d'une image +flottante afin d'avoir des vues en 3d pertinentes, bien qu'assez +futiles. diff --git a/experiment/fimg2obj.c b/experiment/fimg2obj.c new file mode 100644 index 00000000..eeac4a09 --- /dev/null +++ b/experiment/fimg2obj.c @@ -0,0 +1,67 @@ + +/* + * another ugly experiment + */ +#include +#include +#include +#include + +#include "../floatimg.h" + +int verbosity; + +/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */ + +int convert_fimg_to_obj(char *fimgfname, char *objfname, int mode) +{ +FloatImg src; +int foo, x, y; +FILE *fp; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n", __func__, + fimgfname, objfname, mode); +#endif + +if (mode) { + fprintf(stderr, "in %s(), mode must be 0, was %d\n", __func__, mode); + } + +foo = fimg_create_from_dump(fimgfname, &src); +if (foo) { + fprintf(stderr, "err %d loading %f\n", foo, fimgfname); + return foo; + } + + + +return -1; +} +/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */ + +int main(int argc, char *argv[]) +{ +int foo, opt; +char *infile = "foo.fimg"; + +fprintf(stderr, "*** fimg2obj (%s %s)\n", __DATE__, __TIME__); + +verbosity = 0; + +#if 0 +for (foo=0; foo +#include +#include +#include + +#include "../floatimg.h" + +int verbosity; + +/* ------------------------------------------------------------------- */ +/* + * First try + */ +int brotche_mnt_style(FloatImg *src, FloatImg *dst) +{ +int x, y; +int offset; +float z1, z2, z3, z4; +float a, b, c; +float pente; + +fprintf(stderr, ">>> %s ( %p %p )\n", __func__, src, dst); + +#define W (src->width) +#define DX 1.0 +#define DY 1.0 + +for (y=0; y<(src->height-1); y++) { + for (x=0; x<(src->width-1); x++) { + offset = (y * src->width) + x; + z1 = src->R[offset]; + z2 = src->R[offset+1]; + z3 = src->R[offset+W]; + z4 = src->R[offset+W+1]; + + a = ( z1 + z2 + z3 + z4) / 4.0; + b = (-z1 + z2 - z3 + z4) / 2.0 / DX; + c = (-z1 - z2 + z3 + z4) / 2.0 / DY; + + pente = atanf(sqrt(b*b + c*c)); + + dst->R[offset] = 0; + if (pente < 0.0) dst->G[offset] = pente; + else dst->B[offset] = pente; + + + } + } + +return 0; +} +/* ------------------------------------------------------------------- */ +int main(int argc, char *argv[]) +{ +FloatImg src, dst; +char *infile, *outfile; +int foo; + +if (3 != argc) { + fprintf(stderr, "%s need 2 args : infile & outfile\n", argv[0]); + fimg_print_version(0); + exit(1); + } + +infile = argv[1]; outfile = argv[2]; + +fprintf(stderr,"--- working on %s\n", infile); + +foo = fimg_create_from_dump(infile, &src); +if (foo) { + fprintf(stderr, "err %d loading image '%s'\n", foo, infile); + exit(1); + } + +foo = fimg_clone(&src, &dst, 0); +if (foo) { + fprintf(stderr, "err %d cloning image\n", foo); + exit(1); + } + +foo = brotche_mnt_style(&src, &dst); +if (foo) { + fprintf(stderr, "something weird happen %d\n", foo); + exit(1); + } + +foo = fimg_export_picture(&dst, outfile, 0); +if (foo) { + fprintf(stderr, "err %d exporting to %s\n", foo, outfile); + exit(1); + } + +return 0; +} +/* ------------------------------------------------------------------- */ diff --git a/floatimg.h b/floatimg.h index d4a80130..72d63733 100644 --- a/floatimg.h +++ b/floatimg.h @@ -20,7 +20,7 @@ * https://git.tetalab.org/tTh/FloatImg */ -#define FIMG_VERSION (220) +#define FIMG_VERSION (221) #define RELEASE_NAME ("noname") /* XXX add a test for stdint.h / uint32_t XXX */