FloatImg4PythonBinding/lib/interpolate.c

70 lines
1.5 KiB
C
Raw Normal View History

2019-09-10 10:31:48 +11:00
/*
* interpolate.c
*/
2019-09-10 01:02:44 +11:00
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include "../floatimg.h"
int verbosity;
/* ---------------------------------------------------------------- */
2019-09-10 02:24:31 +11:00
static int gray_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef)
{
2019-09-10 10:31:48 +11:00
int picsize, idx;
picsize = d->width * d->height;
for (idx=0; idx<picsize; idx++) {
d->R[idx] = (coef * s1->R[idx]) + ((1.0-coef) * s2->R[idx]);
}
return 0;
2019-09-10 02:24:31 +11:00
}
/* ---------------------------------------------------------------- */
2019-09-10 10:31:48 +11:00
static int rgb_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef)
2019-09-10 01:02:44 +11:00
{
int picsize, idx;
2019-09-10 10:31:48 +11:00
picsize = d->width * d->height * 3; /* rude hack ? */
2019-09-10 01:02:44 +11:00
for (idx=0; idx<picsize; idx++) {
d->R[idx] = (coef * s1->R[idx]) + ((1.0-coef) * s2->R[idx]);
2019-09-10 10:31:48 +11:00
}
return 0;
}
/* ---------------------------------------------------------------- */
int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef)
{
int foo;
foo = fimg_images_compatible(s1, s2);
if (foo) {
fprintf(stderr, "compat -> %d\n", foo);
return foo;
}
foo = fimg_images_compatible(s1, d);
if (foo) {
fprintf(stderr, "compat -> %d\n", foo);
return foo;
}
2019-09-10 01:02:44 +11:00
2019-09-10 10:31:48 +11:00
switch (s1->type) {
case FIMG_TYPE_GRAY:
gray_interpolate(s1, s2, d, coef); break;
case FIMG_TYPE_RGB:
rgb_interpolate(s1, s2, d, coef); break;
default:
fprintf(stderr, "%s, %d is a bad type\n", __func__, s1->type);
return -18;
2019-09-10 01:02:44 +11:00
}
2019-09-10 02:24:31 +11:00
return 0;
2019-09-10 01:02:44 +11:00
}
/* ---------------------------------------------------------------- */