From 0104a736ea52f03e644e476897c8d72b697038e1 Mon Sep 17 00:00:00 2001 From: Tonton Th Date: Fri, 10 Jan 2020 12:01:12 +0100 Subject: [PATCH] some tests added... --- lib/Makefile | 2 +- lib/fimg-core.c | 5 +++ lib/fimg-file.c | 4 +-- lib/fimg-math.c | 3 +- lib/t.c | 88 +++++++++++++++++++++++++++++++++++++++++-------- 5 files changed, 85 insertions(+), 17 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 6280e92b..92bc1a55 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -2,7 +2,7 @@ # building the base library # -COPT = -Wall -fpic -g -pg -no-pie -DDEBUG_LEVEL=0 +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 \ diff --git a/lib/fimg-core.c b/lib/fimg-core.c index 41b55660..121b67cb 100644 --- a/lib/fimg-core.c +++ b/lib/fimg-core.c @@ -91,6 +91,11 @@ if ( ! fimg_type_is_valid(t) ) { return -2; } +/* + * what to do if we've got a descriptor for an image + * already allocated ? +*/ + memset(fimg, 0, sizeof(FloatImg)); surface = w * h; diff --git a/lib/fimg-file.c b/lib/fimg-file.c index 3646a41f..8b4668e5 100644 --- a/lib/fimg-file.c +++ b/lib/fimg-file.c @@ -163,14 +163,14 @@ fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, fname, head); fp = fopen(fname, "r"); if (NULL==fp) { perror(fname); - exit(1); + return -15; } foo = fread(&filehead, sizeof(FimgFileHead), 1, fp); if (1 != foo) { fprintf(stderr, "%s : short read\n", fname); fclose(fp); - return -1; + return -16; } #if DEBUG_LEVEL fprintf(stderr, "%s : got [ %d %d %d ] from '%s'\n", __func__, diff --git a/lib/fimg-math.c b/lib/fimg-math.c index 4cab2443..9fef44b0 100644 --- a/lib/fimg-math.c +++ b/lib/fimg-math.c @@ -151,7 +151,7 @@ void fimg_mul_cste(FloatImg *fi, float value) { int nbre, idx; -if (fi->type != FIMG_TYPE_RGB) { +if ( (fi->type != FIMG_TYPE_RGB) && (fi->type != FIMG_TYPE_GRAY) ) { fprintf(stderr, "%s : type %d invalide\n", __func__, fi->type); return; @@ -183,6 +183,7 @@ if (fi->count < 1) { /* * mmmm, is this real ? + * how to accuratly check the value of 'I.fval' ? */ coef = 1.0 / ((double)fi->count * (double)fi->fval); diff --git a/lib/t.c b/lib/t.c index 79987bea..8197a872 100644 --- a/lib/t.c +++ b/lib/t.c @@ -41,6 +41,50 @@ if (foo) { val = fimg_get_maxvalue(&A); fprintf(stderr, "AFTER max pixel %f\n", val); +fimg_destroy(&A); + +return 0; +} +/* ---------------------------------------------------------------- */ +#define WI 1024 +#define HI 768 +#define KDEG 3.141592654 /* secret magic number */ + +int essai_interpolate(int k) +{ +FloatImg A, B, C; +int foo; + +foo = fimg_create(&A, WI, HI, FIMG_TYPE_RGB); +if (foo) { + fprintf(stderr, "%s err create A %d\n", __func__, foo); + return foo; + } +fimg_hdeg_a(&A, KDEG); + +foo = fimg_create(&B, WI, HI, FIMG_TYPE_RGB); +if (foo) { + fprintf(stderr, "%s err create B %d\n", __func__, foo); + return foo; + } +fimg_vdeg_a(&B, KDEG); + +foo = fimg_create(&C, WI, HI, FIMG_TYPE_RGB); +if (foo) { + fprintf(stderr, "%s err create C %d\n", __func__, foo); + return foo; + } + +foo = fimg_interpolate(&A, &B, &C, 0.5); +if (foo) { + fprintf(stderr, "%s err interpolate %d\n", __func__, foo); + return foo; + } + +foo = fimg_save_as_pnm(&C, "interpolate.pnm", 0); + +fimg_destroy(&A); fimg_destroy(&B); fimg_destroy(&C); + return 0; } /* ---------------------------------------------------------------- */ @@ -74,13 +118,14 @@ fimg_destroy(&gray); return 0; } /* ---------------------------------------------------------------- */ +#define TAILLE 1024 int essai_clone_et_copy(int unused) { FloatImg A, B, C; int foo; -foo = fimg_create(&A, 512, 512, FIMG_TYPE_RGB); +foo = fimg_create(&A, TAILLE, TAILLE, FIMG_TYPE_RGB); if (foo) { fprintf(stderr, "%s err create A %d\n", __func__, foo); return foo; @@ -90,8 +135,8 @@ if (foo) { fprintf(stderr, "%s err drawing A %d\n", __func__, foo); return foo; } -foo = fimg_save_as_pnm(&A, "A.pnm", 0); +foo = fimg_save_as_pnm(&A, "A.pnm", 0); if (foo) { fprintf(stderr, "%s : err %d on save_as_pnm\n", __func__, foo); exit(1); @@ -103,7 +148,7 @@ if (foo) { return foo; } -foo = fimg_create(&C, 512, 512, FIMG_TYPE_RGB); +foo = fimg_create(&C, TAILLE, TAILLE, FIMG_TYPE_RGB); if (foo) { fprintf(stderr, "%s err create A %d\n", __func__, foo); return foo; @@ -115,9 +160,13 @@ if (foo) { } foo = fimg_save_as_pnm(&C, "C.pnm", 0); +fimg_destroy(&A); fimg_destroy(&B); fimg_destroy(&C); return 0; } + +#undef TAILLE + /* ---------------------------------------------------------------- */ int essai_contraste(char *fname) @@ -127,38 +176,42 @@ FloatImg dessin, copy; double maxi; foo = fimg_create_from_dump(fname, &dessin); +if (foo) { + fprintf(stderr, "in %s, error %d loading '%s'\n", + __func__, foo, fname); + return foo; + } + foo = fimg_clone(&dessin, ©, 0); maxi = (double)fimg_get_maxvalue(&dessin); -fprintf(stderr, "image source valeur maxi = %f\n", maxi); +fprintf(stderr, "image source valeur maxi = %f\n", maxi); fimg_power_2(&dessin, ©, maxi); maxi = (double)fimg_get_maxvalue(©); -fprintf(stderr, "apres power_2 valeur maxi = %f\n", maxi); -fimg_dump_to_file(©, "power2.fimg", 0); +fprintf(stderr, "apres power_2 valeur maxi = %f\n", maxi); +fimg_save_as_pnm(©, "power2.pnm", 0); fimg_square_root(&dessin, ©, maxi); maxi = (double)fimg_get_maxvalue(©); fprintf(stderr, "apres square_root valeur maxi = %f\n", maxi); -fimg_dump_to_file(©, "squareroot.fimg", 0); +fimg_save_as_pnm(©, "squareroot.pnm", 0); fimg_cos_01(&dessin, ©, maxi); maxi = (double)fimg_get_maxvalue(©); fprintf(stderr, "apres cos 01 valeur maxi = %f\n", maxi); -fimg_dump_to_file(©, "cos_01.fimg", 0); +fimg_save_as_pnm(©, "cos_01.pnm", 0); fimg_cos_010(&dessin, ©, maxi); maxi = (double)fimg_get_maxvalue(©); fprintf(stderr, "apres cos 010 valeur maxi = %f\n", maxi); -fimg_dump_to_file(©, "cos_010.fimg", 0); +fimg_save_as_pnm(©, "cos_010.pnm", 0); -fimg_destroy(&dessin); +fimg_destroy(&dessin); fimg_destroy(©); -return -1; +return 0; } /* ---------------------------------------------------------------- */ -#define W 320 -#define H 240 int main(int argc, char *argv[]) { int foo, opt; @@ -178,5 +231,14 @@ if (verbosity) fimg_print_version(0); foo = essai_normalize(); fprintf(stderr, "retour essai normalize -> %d\n", foo); +foo = essai_contraste("quux.fimg"); +fprintf(stderr, "retour essai contraste -> %d\n", foo); + +foo = essai_clone_et_copy(0); +fprintf(stderr, "retour essai clone'n'copy -> %d\n", foo); + +foo = essai_interpolate(0); +fprintf(stderr, "retour essai interpolate -> %d\n", foo); + return 0; }