some tests added...

This commit is contained in:
Tonton Th 2020-01-10 12:01:12 +01:00
parent e51888b206
commit 0104a736ea
5 changed files with 85 additions and 17 deletions

View File

@ -2,7 +2,7 @@
# building the base library # 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 \ 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 \

View File

@ -91,6 +91,11 @@ if ( ! fimg_type_is_valid(t) ) {
return -2; return -2;
} }
/*
* what to do if we've got a descriptor for an image
* already allocated ?
*/
memset(fimg, 0, sizeof(FloatImg)); memset(fimg, 0, sizeof(FloatImg));
surface = w * h; surface = w * h;

View File

@ -163,14 +163,14 @@ fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, fname, head);
fp = fopen(fname, "r"); fp = fopen(fname, "r");
if (NULL==fp) { if (NULL==fp) {
perror(fname); perror(fname);
exit(1); return -15;
} }
foo = fread(&filehead, sizeof(FimgFileHead), 1, fp); foo = fread(&filehead, sizeof(FimgFileHead), 1, fp);
if (1 != foo) { if (1 != foo) {
fprintf(stderr, "%s : short read\n", fname); fprintf(stderr, "%s : short read\n", fname);
fclose(fp); fclose(fp);
return -1; return -16;
} }
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, "%s : got [ %d %d %d ] from '%s'\n", __func__, fprintf(stderr, "%s : got [ %d %d %d ] from '%s'\n", __func__,

View File

@ -151,7 +151,7 @@ void fimg_mul_cste(FloatImg *fi, float value)
{ {
int nbre, idx; 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", fprintf(stderr, "%s : type %d invalide\n",
__func__, fi->type); __func__, fi->type);
return; return;
@ -183,6 +183,7 @@ if (fi->count < 1) {
/* /*
* mmmm, is this real ? * mmmm, is this real ?
* how to accuratly check the value of 'I.fval' ?
*/ */
coef = 1.0 / ((double)fi->count * (double)fi->fval); coef = 1.0 / ((double)fi->count * (double)fi->fval);

84
lib/t.c
View File

@ -41,6 +41,50 @@ if (foo) {
val = fimg_get_maxvalue(&A); val = fimg_get_maxvalue(&A);
fprintf(stderr, "AFTER max pixel %f\n", val); 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; return 0;
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
@ -74,13 +118,14 @@ fimg_destroy(&gray);
return 0; return 0;
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
#define TAILLE 1024
int essai_clone_et_copy(int unused) int essai_clone_et_copy(int unused)
{ {
FloatImg A, B, C; FloatImg A, B, C;
int foo; int foo;
foo = fimg_create(&A, 512, 512, FIMG_TYPE_RGB); foo = fimg_create(&A, TAILLE, TAILLE, FIMG_TYPE_RGB);
if (foo) { if (foo) {
fprintf(stderr, "%s err create A %d\n", __func__, foo); fprintf(stderr, "%s err create A %d\n", __func__, foo);
return foo; return foo;
@ -90,8 +135,8 @@ if (foo) {
fprintf(stderr, "%s err drawing A %d\n", __func__, foo); fprintf(stderr, "%s err drawing A %d\n", __func__, foo);
return foo; return foo;
} }
foo = fimg_save_as_pnm(&A, "A.pnm", 0);
foo = fimg_save_as_pnm(&A, "A.pnm", 0);
if (foo) { if (foo) {
fprintf(stderr, "%s : err %d on save_as_pnm\n", __func__, foo); fprintf(stderr, "%s : err %d on save_as_pnm\n", __func__, foo);
exit(1); exit(1);
@ -103,7 +148,7 @@ if (foo) {
return foo; return foo;
} }
foo = fimg_create(&C, 512, 512, FIMG_TYPE_RGB); foo = fimg_create(&C, TAILLE, TAILLE, FIMG_TYPE_RGB);
if (foo) { if (foo) {
fprintf(stderr, "%s err create A %d\n", __func__, foo); fprintf(stderr, "%s err create A %d\n", __func__, foo);
return foo; return foo;
@ -115,9 +160,13 @@ if (foo) {
} }
foo = fimg_save_as_pnm(&C, "C.pnm", 0); foo = fimg_save_as_pnm(&C, "C.pnm", 0);
fimg_destroy(&A); fimg_destroy(&B); fimg_destroy(&C);
return 0; return 0;
} }
#undef TAILLE
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
int essai_contraste(char *fname) int essai_contraste(char *fname)
@ -127,6 +176,12 @@ FloatImg dessin, copy;
double maxi; double maxi;
foo = fimg_create_from_dump(fname, &dessin); 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, &copy, 0); foo = fimg_clone(&dessin, &copy, 0);
maxi = (double)fimg_get_maxvalue(&dessin); maxi = (double)fimg_get_maxvalue(&dessin);
@ -135,30 +190,28 @@ fprintf(stderr, "image source valeur maxi = %f\n", maxi);
fimg_power_2(&dessin, &copy, maxi); fimg_power_2(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy); maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres power_2 valeur maxi = %f\n", maxi); fprintf(stderr, "apres power_2 valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "power2.fimg", 0); fimg_save_as_pnm(&copy, "power2.pnm", 0);
fimg_square_root(&dessin, &copy, maxi); fimg_square_root(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy); maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres square_root valeur maxi = %f\n", maxi); fprintf(stderr, "apres square_root valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "squareroot.fimg", 0); fimg_save_as_pnm(&copy, "squareroot.pnm", 0);
fimg_cos_01(&dessin, &copy, maxi); fimg_cos_01(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy); maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres cos 01 valeur maxi = %f\n", maxi); fprintf(stderr, "apres cos 01 valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "cos_01.fimg", 0); fimg_save_as_pnm(&copy, "cos_01.pnm", 0);
fimg_cos_010(&dessin, &copy, maxi); fimg_cos_010(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy); maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres cos 010 valeur maxi = %f\n", maxi); fprintf(stderr, "apres cos 010 valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "cos_010.fimg", 0); fimg_save_as_pnm(&copy, "cos_010.pnm", 0);
fimg_destroy(&dessin); fimg_destroy(&dessin); fimg_destroy(&copy);
return -1; return 0;
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
#define W 320
#define H 240
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int foo, opt; int foo, opt;
@ -178,5 +231,14 @@ if (verbosity) fimg_print_version(0);
foo = essai_normalize(); foo = essai_normalize();
fprintf(stderr, "retour essai normalize -> %d\n", foo); 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; return 0;
} }