From 2f3a8870c4a7dd090b10abed5588096993c3d57d Mon Sep 17 00:00:00 2001 From: tth Date: Mon, 9 Sep 2019 16:02:44 +0200 Subject: [PATCH] starting interpolate funcs --- floatimg.h | 3 +++ lib/Makefile | 9 ++++++-- lib/interpolate.c | 44 ++++++++++++++++++++++++++++++++++++++ lib/t.c | 54 +++++++++++++++++++++++++++++++++++------------ 4 files changed, 95 insertions(+), 15 deletions(-) create mode 100644 lib/interpolate.c diff --git a/floatimg.h b/floatimg.h index 790448e4..9f0effc7 100644 --- a/floatimg.h +++ b/floatimg.h @@ -46,6 +46,9 @@ int fimg_plot_rgb (FloatImg *head, int x, int y, float r, float g, float b); int fimg_clear(FloatImg *fimg); int fimg_add_rgb(FloatImg *head, int x, int y, float r, float g, float b); + +int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef); + /* 'operats' module */ int fimg_add(FloatImg *a, FloatImg *b, FloatImg *d); int fimg_sub(FloatImg *a, FloatImg *b, FloatImg *d); diff --git a/lib/Makefile b/lib/Makefile index 308e1554..7d58bbd8 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -4,7 +4,9 @@ COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0 OBJS = fimg-core.o fimg-pnm.o fimg-file.o fimg-math.o \ - fimg-timers.o operators.o fimg-2gray.o + fimg-timers.o operators.o fimg-2gray.o \ + interpolate.o + DEPS = Makefile ../floatimg.h # modify it 'as you like' @@ -13,7 +15,7 @@ AR=ar all: $(OBJS) ../libfloatimg.a t: t.c ../libfloatimg.a $(DEPS) - gcc $(COPT) $< ../libfloatimg.a -lm -o $@ + gcc $(COPT) $< ../libfloatimg.a -lpnglite -lm -o $@ # -------------------------------------------- @@ -29,6 +31,9 @@ fimg-2gray.o: fimg-2gray.c $(DEPS) operators.o: operators.c $(DEPS) gcc $(COPT) -c $< +interpolate.o: interpolate.c $(DEPS) + gcc $(COPT) -c $< + fimg-pnm.o: fimg-pnm.c $(DEPS) gcc $(COPT) -c $< diff --git a/lib/interpolate.c b/lib/interpolate.c new file mode 100644 index 00000000..ac813abb --- /dev/null +++ b/lib/interpolate.c @@ -0,0 +1,44 @@ + +#include +#include +#include +#include +#include + +#include "../floatimg.h" + +int verbosity; + +/* ---------------------------------------------------------------- */ +int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef) +{ +int picsize, idx; + +if (FIMG_TYPE_RGB != s1->type) { + fprintf(stderr, "%s : bad src 1 type %d on %p\n", __func__, + s1->type, s1); + return -8; + } + +if (FIMG_TYPE_RGB != s2->type) { + fprintf(stderr, "%s : bad src 2 type %d on %p\n", __func__, + s2->type, s2); + return -8; + } +if (FIMG_TYPE_RGB != d->type) { + fprintf(stderr, "%s : bad dst type %d on %p\n", __func__, + d->type, d); + return -9; + } + +picsize = d->width * d->height * 2; + +for (idx=0; idxR[idx] = (coef * s1->R[idx]) + ((1.0-coef) * s2->R[idx]); + + } + +return -1; +} +/* ---------------------------------------------------------------- */ diff --git a/lib/t.c b/lib/t.c index b4e53942..dd1076b6 100644 --- a/lib/t.c +++ b/lib/t.c @@ -1,3 +1,8 @@ +/* + * programme de test pour + * les fonctions de base. + */ + #include #include #include @@ -62,25 +67,48 @@ fimg_destroy(&gray); return 0; } /* ---------------------------------------------------------------- */ -#define W 2048 -#define H 2048 -int main(int argc, char *argv[]) -{ -int foo; -FloatImg dessin, noise, result; - -verbosity = 1; - -fimg_print_version(1); - +/**** foo = fimg_create(&dessin, W, H, 3); petit_dessin(&dessin); foo = fimg_create(&noise, W, H, 3); fimg_drand48(&noise, 0.1); +****/ +/* ---------------------------------------------------------------- */ +#define W 320 +#define H 240 +int main(int argc, char *argv[]) +{ +int foo, idx; +float coef; +FloatImg dessin, noise, result; +char outname[100]; + +verbosity = 1; + +fimg_print_version(1); + +foo = fimg_create_from_png("/home/tth/TMP/floatimg/s2.png", &dessin); +foo = fimg_create_from_png("/home/tth/TMP/floatimg/s1.png", &noise); + foo = fimg_create(&result, W, H, 3); -foo = fimg_mul(&dessin, &noise, &result); -essai_2gray(&result, "gray.pnm"); + +#define NBRE 42 + +for (idx=0; idx