From 6e410e5f50c2fe4f3bd1ab9199263f709f8853f2 Mon Sep 17 00:00:00 2001 From: tth Date: Sun, 28 Mar 2021 18:52:03 +0200 Subject: [PATCH] experiment on incrustation --- .gitignore | 5 +++ experiment/Makefile | 17 +++++++++- experiment/README.md | 4 ++- experiment/assemblage.c | 69 ++++++++++++++++++++++++++++++++++++++++ experiment/incrustator.c | 52 ++++++++++++++++++++++++++++++ experiment/incrustator.h | 7 ++++ 6 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 experiment/assemblage.c create mode 100644 experiment/incrustator.c create mode 100644 experiment/incrustator.h diff --git a/.gitignore b/.gitignore index 282e61ae..fc83d170 100644 --- a/.gitignore +++ b/.gitignore @@ -76,3 +76,8 @@ Fonderie/singlepass Fonderie/crapdef.h Fonderie/crapstr.h +experiment/assemblage +experiment/*.fimg +experiment/*.pnm +experiment/*.o + diff --git a/experiment/Makefile b/experiment/Makefile index f902b8e7..68b0e82d 100644 --- a/experiment/Makefile +++ b/experiment/Makefile @@ -1 +1,16 @@ -# plasma experiment + +#  experiments + + +COPT = -Wall -fpic -g -DDEBUG_LEVEL=0 -lm +DEPS = ../floatimg.h ../libfloatimg.a Makefile +LIBS = -ltiff -lpnglite -lcfitsio + +all: assemblage + +incrustator.o: incrustator.c incrustator.h Makefile + gcc -c $(COPT) $< + +assemblage: assemblage.c Makefile incrustator.o + gcc $(COPT) $< incrustator.o ../libfloatimg.a $(LIBS) -o $@ + diff --git a/experiment/README.md b/experiment/README.md index dde30033..605e83e9 100644 --- a/experiment/README.md +++ b/experiment/README.md @@ -1 +1,3 @@ -# PLASMA EXPERIMENT \ No newline at end of file + +# ASSEMBLAGE + diff --git a/experiment/assemblage.c b/experiment/assemblage.c new file mode 100644 index 00000000..8133361d --- /dev/null +++ b/experiment/assemblage.c @@ -0,0 +1,69 @@ +/* + * assemblage experimental + */ + +#include +#include + +#include "../floatimg.h" + +#include "incrustator.h" + +int verbosity; + +/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */ +int premier_essai(int largeur, int hauteur, char *outname) +{ +FloatImg grande, incrust; +int foo; + +foo = fimg_create(&grande, largeur, hauteur, FIMG_TYPE_RGB); +if (foo) { + fprintf(stderr, "%s: Kkrkr %d pour create grande\n", __func__, foo); + return -1; + } +fimg_vdeg_a(&grande, 13.37); + +foo = fimg_create(&incrust, 640, 480, FIMG_TYPE_RGB); +if (foo) { + fprintf(stderr, "%s: Kkrkr %d pour create incrust\n", __func__, foo); + return -1; + } +fimg_drand48(&incrust, 13.37); + +foo = incrustator_0(&incrust, &grande, 100, 100, 0); +if (foo) { + fprintf(stderr, "%s: Kkrkr %d sur incrustator_0\n", __func__, foo); + return -1; + } + +foo = fimg_export_picture(&grande, outname, 0); +if (foo) { + fprintf(stderr, "%s: error %d export '%s'\n", __func__, + foo, outname); + return -1; + } + +return 0; +} +/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */ +int main(int argc, char *argv[]) +{ +int foo; + +verbosity = 1; + +fimg_print_version(1); + +foo = premier_essai(1280, 1024, "out.pnm"); +if (foo) { + fprintf(stderr, "EPIC FAIL %s\n", argv[0]); + exit(1); + } + +return 0; +} +/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */ + + + diff --git a/experiment/incrustator.c b/experiment/incrustator.c new file mode 100644 index 00000000..94c37c74 --- /dev/null +++ b/experiment/incrustator.c @@ -0,0 +1,52 @@ +/* + * incrustator experimental + */ + +#include +#include + +#include "../floatimg.h" + +#include "incrustator.h" + +extern int verbosity; + +/* ---------------------------------------------------------------- */ +int incrustator_0(FloatImg *psrc, FloatImg *pdst, + int xpos, int ypos, int flags) +{ +int y, srcpos, dstpos, szl; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %s ( %p %p %d %d 0x%04X\n", __func__, psrc, pdst, + xpos, ypos, flags); +#endif + +if (verbosity > 1) { + fimg_describe(psrc, "source"); + fimg_describe(pdst, "destination"); + } + +/* check boudaries */ +if ( (xpos < 0) || (xpos > pdst->width - psrc->width) || + (ypos < 0) || (ypos > pdst->height - psrc->height) ) { + fprintf(stderr, "%s: boudary error\n", __func__); + return -2; + } + +/* move all the data by looping over lines */ +srcpos = 0; +szl = psrc->width * sizeof(float); +for (y=0; yheight; y++) { + dstpos = ((y +ypos) * pdst->width) + xpos; + // fprintf(stderr, " %7d %7d %7d\n", y, srcpos, dstpos); + + memcpy(pdst->R + dstpos, psrc->R + srcpos, szl); + memcpy(pdst->G + dstpos, psrc->G + srcpos, szl); + memcpy(pdst->B + dstpos, psrc->B + srcpos, szl); + srcpos += psrc->height; + } + +return 0; +} +/* ---------------------------------------------------------------- */ diff --git a/experiment/incrustator.h b/experiment/incrustator.h new file mode 100644 index 00000000..9cd2b888 --- /dev/null +++ b/experiment/incrustator.h @@ -0,0 +1,7 @@ +/* + * incrustator experimental + */ + + +int incrustator_0(FloatImg *psrc, FloatImg *pdst, + int xpos, int ypos, int flags);