making operators from garbage
parent
6258bd08ed
commit
016497c870
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* OPERATORS
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
extern int verbosity; /* must be declared around main() */
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
int fimg_add(FloatImg *a, FloatImg *b, FloatImg *d)
|
||||
{
|
||||
int idx, nbiter;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, a, b, d);
|
||||
#endif
|
||||
|
||||
if (3 != a->type || 3 != b->type || 3 != d->type) {
|
||||
fprintf(stderr, "%s : got a bad type fimg\n", __func__);
|
||||
return -8;
|
||||
}
|
||||
|
||||
nbiter = a->width * a->height;
|
||||
|
||||
for (idx=0; idx<nbiter; idx++) {
|
||||
d->R[idx] = a->R[idx] + b->R[idx];
|
||||
d->G[idx] = a->G[idx] + b->G[idx];
|
||||
d->B[idx] = a->B[idx] + b->B[idx];
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
/*
|
||||
* A - B -> D
|
||||
*/
|
||||
int fimg_sub(FloatImg *a, FloatImg *b, FloatImg *d)
|
||||
{
|
||||
int idx, nbiter;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, a, b, d);
|
||||
#endif
|
||||
|
||||
if (3 != a->type || 3 != b->type || 3 != d->type) {
|
||||
fprintf(stderr, "%s : got a bad type fimg\n", __func__);
|
||||
return -8;
|
||||
}
|
||||
|
||||
nbiter = a->width * a->height;
|
||||
|
||||
for (idx=0; idx<nbiter; idx++) {
|
||||
d->R[idx] = fabs(a->R[idx] - b->R[idx]);
|
||||
d->G[idx] = fabs(a->G[idx] - b->G[idx]);
|
||||
d->B[idx] = fabs(a->B[idx] - b->B[idx]);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
/* ---------------------------------------------------------------- */
|
||||
/*
|
||||
* A * B -> D
|
||||
*/
|
||||
int fimg_mul(FloatImg *a, FloatImg *b, FloatImg *d)
|
||||
{
|
||||
int idx, nbiter;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, a, b, d);
|
||||
#endif
|
||||
|
||||
if (3 != a->type || 3 != b->type || 3 != d->type) {
|
||||
fprintf(stderr, "%s : got a bad type fimg\n", __func__);
|
||||
return -8;
|
||||
}
|
||||
|
||||
nbiter = a->width * a->height;
|
||||
|
||||
for (idx=0; idx<nbiter; idx++) {
|
||||
d->R[idx] = a->R[idx] * b->R[idx];
|
||||
d->G[idx] = a->G[idx] * b->G[idx];
|
||||
d->B[idx] = a->B[idx] * b->B[idx];
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
Loading…
Reference in New Issue