more experiments in progress

This commit is contained in:
tTh 2023-04-29 19:29:45 +02:00
parent ff916c434c
commit cb599a253c
6 changed files with 201 additions and 4 deletions

View File

@ -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; y<pimg->height; y+=STP) {
for (y=0; y < pimg->height; y+=STP) {
coo[1] = y;
for (x=0; x<pimg->width; 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);
}
}

View File

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

View File

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

67
experiment/fimg2obj.c Normal file
View File

@ -0,0 +1,67 @@
/*
* another ugly experiment
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#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<argc; foo++) {
fprintf(stderr, "%9d %s\n", foo, argv[foo]);
}
#endif
foo = convert_fimg_to_obj(infile, "foo.obj", 0);
if (foo) {
fprintf(stderr, "convertor give us %d\n", foo);
exit(1);
}
return 0;
}
/* ---------------------------------------------- ~~~~~~~~~~~~~~~~ */

100
experiment/mnt.c Normal file
View File

@ -0,0 +1,100 @@
/*
* Modeles Numeriques de Terrain
*
*/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#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;
}
/* ------------------------------------------------------------------- */

View File

@ -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 */