experiment on incrustation

This commit is contained in:
tth 2021-03-28 18:52:03 +02:00
parent 5d121dee87
commit 6e410e5f50
6 changed files with 152 additions and 2 deletions

5
.gitignore vendored
View File

@ -76,3 +76,8 @@ Fonderie/singlepass
Fonderie/crapdef.h Fonderie/crapdef.h
Fonderie/crapstr.h Fonderie/crapstr.h
experiment/assemblage
experiment/*.fimg
experiment/*.pnm
experiment/*.o

View File

@ -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 $@

View File

@ -1 +1,3 @@
# PLASMA EXPERIMENT
# ASSEMBLAGE

69
experiment/assemblage.c Normal file
View File

@ -0,0 +1,69 @@
/*
* assemblage experimental
*/
#include <stdio.h>
#include <stdlib.h>
#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;
}
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */

52
experiment/incrustator.c Normal file
View File

@ -0,0 +1,52 @@
/*
* incrustator experimental
*/
#include <stdio.h>
#include <string.h>
#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; y<psrc->height; 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;
}
/* ---------------------------------------------------------------- */

7
experiment/incrustator.h Normal file
View File

@ -0,0 +1,7 @@
/*
* incrustator experimental
*/
int incrustator_0(FloatImg *psrc, FloatImg *pdst,
int xpos, int ypos, int flags);