diff --git a/essai.c b/essai.c index 08f4a3f..4f9b673 100644 --- a/essai.c +++ b/essai.c @@ -62,7 +62,7 @@ for (foo=0; foo D + * A + B -> D * 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; @@ -40,13 +40,40 @@ for (idx=0; idxB[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; idxR[idx] += a->R[idx]; + b->G[idx] += a->G[idx]; + b->B[idx] += a->B[idx]; + } + return 0; } /* ---------------------------------------------------------------- */ /* * 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; @@ -57,7 +84,7 @@ fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, a, b, d); if (3 != a->type || 3 != b->type || 3 != d->type) { fprintf(stderr, "%s : got a bad type fimg\n", __func__); return -8; - } + } nbpixels = a->width * a->height; @@ -76,7 +103,7 @@ return 0; /* * 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; diff --git a/tools/fimgops.c b/tools/fimgops.c index a9359bb..e7420fc 100644 --- a/tools/fimgops.c +++ b/tools/fimgops.c @@ -80,16 +80,16 @@ int foo; switch (action) { case OP_ADD: - foo = fimg_add(A, B, D); break; + foo = fimg_add_3(A, B, D); break; case OP_SUB: - foo = fimg_sub(A, B, D); break; + foo = fimg_sub_3(A, B, D); break; case OP_MIX: if (verbosity) fprintf(stderr, "fvalue is %f\n", global_fvalue); foo = fimg_interpolate(A, B, D, global_fvalue); break; case OP_MUL: - foo = fimg_add(A, B, D); break; + foo = fimg_mul_3(A, B, D); break; case OP_MINI: foo = fimg_maximum(A, B, D); break; case OP_MAXI: