1) renommer quelques fonctions dans lib/operators.c

2) ajouter une fonction d'additin d'images (maybe ?) plus rapide
3) reparation d'un bug dans tools/fimgops.c
This commit is contained in:
Tonton Th 2020-01-15 11:38:40 +01:00
parent 2d75f70215
commit d624a45fc4
4 changed files with 41 additions and 13 deletions

View File

@ -62,7 +62,7 @@ for (foo=0; foo<NBP; foo++) {
printf("%5d / %5d\n", foo, NBP); printf("%5d / %5d\n", foo, NBP);
} }
fait_un_dessin(&fimgB); fait_un_dessin(&fimgB);
fimg_add(&fimgA, &fimgB, &fimgA); fimg_add_3(&fimgA, &fimgB, &fimgA);
// fimg_mul(&fimgA, &fimgB, &fimgA); // fimg_mul(&fimgA, &fimgB, &fimgA);
} }
tb = fimg_timer_get(0); tb = fimg_timer_get(0);

View File

@ -2,7 +2,7 @@
* floatimg.h * floatimg.h
*/ */
#define FIMG_VERSION 86 #define FIMG_VERSION 87
/* /*
* in memory descriptor * in memory descriptor
@ -69,9 +69,10 @@ int fimg_images_compatible(FloatImg *a, FloatImg *b);
int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef); int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef);
/* 'operats' module */ /* 'operats' module */
int fimg_add(FloatImg *a, FloatImg *b, FloatImg *d); int fimg_add_3(FloatImg *a, FloatImg *b, FloatImg *d);
int fimg_sub(FloatImg *a, FloatImg *b, FloatImg *d); int fimg_add_2(FloatImg *a, FloatImg *b); /* B+=A */
int fimg_mul(FloatImg *a, FloatImg *b, FloatImg *d); int fimg_sub_3(FloatImg *a, FloatImg *b, FloatImg *d);
int fimg_mul_3(FloatImg *a, FloatImg *b, FloatImg *d);
int fimg_minimum(FloatImg *a, FloatImg *b, FloatImg *d); int fimg_minimum(FloatImg *a, FloatImg *b, FloatImg *d);
int fimg_maximum(FloatImg *a, FloatImg *b, FloatImg *d); int fimg_maximum(FloatImg *a, FloatImg *b, FloatImg *d);

View File

@ -16,10 +16,10 @@ extern int verbosity; /* must be declared around main() */
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
/* /*
* A + B -> D * A + B -> D
* why is this func so slow ? * why is this func so slow ?
*/ */
int fimg_add(FloatImg *a, FloatImg *b, FloatImg *d) int fimg_add_3(FloatImg *a, FloatImg *b, FloatImg *d)
{ {
int idx, nbpixels; int idx, nbpixels;
@ -40,13 +40,40 @@ for (idx=0; idx<nbpixels; idx++) {
d->B[idx] = a->B[idx] + b->B[idx]; d->B[idx] = a->B[idx] + b->B[idx];
} }
return 0;
}
/* ---------------------------------------------------------------- */
/*
* B += A may be faster than fimg_add_3 ?
*/
int fimg_add_2(FloatImg *a, FloatImg *b)
{
int idx, nbpixels;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p )\n", __func__, a, b);
#endif
if (3 != a->type || 3 != b->type) {
fprintf(stderr, "%s : got a bad type fimg\n", __func__);
return -8;
}
nbpixels = a->width * a->height;
for (idx=0; idx<nbpixels; idx++) {
b->R[idx] += a->R[idx];
b->G[idx] += a->G[idx];
b->B[idx] += a->B[idx];
}
return 0; return 0;
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
/* /*
* A - B -> D * A - B -> D
*/ */
int fimg_sub(FloatImg *a, FloatImg *b, FloatImg *d) int fimg_sub_3(FloatImg *a, FloatImg *b, FloatImg *d)
{ {
int idx, nbpixels; int idx, nbpixels;
@ -76,7 +103,7 @@ return 0;
/* /*
* A * B -> D * A * B -> D
*/ */
int fimg_mul(FloatImg *a, FloatImg *b, FloatImg *d) int fimg_mul_3(FloatImg *a, FloatImg *b, FloatImg *d)
{ {
int idx, nbpixels; int idx, nbpixels;

View File

@ -80,16 +80,16 @@ int foo;
switch (action) { switch (action) {
case OP_ADD: case OP_ADD:
foo = fimg_add(A, B, D); break; foo = fimg_add_3(A, B, D); break;
case OP_SUB: case OP_SUB:
foo = fimg_sub(A, B, D); break; foo = fimg_sub_3(A, B, D); break;
case OP_MIX: case OP_MIX:
if (verbosity) fprintf(stderr, "fvalue is %f\n", if (verbosity) fprintf(stderr, "fvalue is %f\n",
global_fvalue); global_fvalue);
foo = fimg_interpolate(A, B, D, global_fvalue); foo = fimg_interpolate(A, B, D, global_fvalue);
break; break;
case OP_MUL: case OP_MUL:
foo = fimg_add(A, B, D); break; foo = fimg_mul_3(A, B, D); break;
case OP_MINI: case OP_MINI:
foo = fimg_maximum(A, B, D); break; foo = fimg_maximum(A, B, D); break;
case OP_MAXI: case OP_MAXI: