Browse Source

some tests added...

master
Tonton Th 3 years ago
parent
commit
0104a736ea
  1. 2
      lib/Makefile
  2. 5
      lib/fimg-core.c
  3. 4
      lib/fimg-file.c
  4. 3
      lib/fimg-math.c
  5. 88
      lib/t.c

2
lib/Makefile

@ -2,7 +2,7 @@ @@ -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 \

5
lib/fimg-core.c

@ -91,6 +91,11 @@ if ( ! fimg_type_is_valid(t) ) { @@ -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;

4
lib/fimg-file.c

@ -163,14 +163,14 @@ fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, fname, head); @@ -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__,

3
lib/fimg-math.c

@ -151,7 +151,7 @@ void fimg_mul_cste(FloatImg *fi, float value) @@ -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) { @@ -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);

88
lib/t.c

@ -41,6 +41,50 @@ if (foo) { @@ -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); @@ -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) { @@ -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) { @@ -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) { @@ -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; @@ -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, &copy, 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, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres power_2 valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "power2.fimg", 0);
fprintf(stderr, "apres power_2 valeur maxi = %f\n", maxi);
fimg_save_as_pnm(&copy, "power2.pnm", 0);
fimg_square_root(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy);
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);
maxi = (double)fimg_get_maxvalue(&copy);
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);
maxi = (double)fimg_get_maxvalue(&copy);
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 foo, opt;
@ -178,5 +231,14 @@ if (verbosity) fimg_print_version(0); @@ -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;
}

Loading…
Cancel
Save