forked from tTh/FloatImg
101 lines
1.9 KiB
C
101 lines
1.9 KiB
C
/*
|
|
* 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;
|
|
}
|
|
/* ------------------------------------------------------------------- */
|