2019-09-10 01:31:48 +02:00
|
|
|
/*
|
|
|
|
* interpolate.c
|
|
|
|
*/
|
2019-09-09 16:02:44 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2021-05-20 09:31:28 +02:00
|
|
|
#include <stdint.h>
|
2019-09-09 16:02:44 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "../floatimg.h"
|
|
|
|
|
2020-01-22 18:15:29 +01:00
|
|
|
extern int verbosity;
|
2019-09-09 16:02:44 +02:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- */
|
2019-09-09 17:24:31 +02:00
|
|
|
static int gray_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef)
|
|
|
|
{
|
2019-09-10 01:31:48 +02: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-09 17:24:31 +02:00
|
|
|
}
|
|
|
|
/* ---------------------------------------------------------------- */
|
2019-09-10 01:31:48 +02:00
|
|
|
static int rgb_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef)
|
2019-09-09 16:02:44 +02:00
|
|
|
{
|
|
|
|
int picsize, idx;
|
|
|
|
|
2021-03-17 18:32:51 +01:00
|
|
|
picsize = d->width * d->height;
|
2019-09-09 16:02:44 +02:00
|
|
|
for (idx=0; idx<picsize; idx++) {
|
|
|
|
d->R[idx] = (coef * s1->R[idx]) + ((1.0-coef) * s2->R[idx]);
|
2021-03-17 18:32:51 +01:00
|
|
|
d->G[idx] = (coef * s1->G[idx]) + ((1.0-coef) * s2->G[idx]);
|
|
|
|
d->B[idx] = (coef * s1->B[idx]) + ((1.0-coef) * s2->B[idx]);
|
2019-09-10 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef)
|
|
|
|
{
|
|
|
|
int foo;
|
|
|
|
|
2020-02-17 07:40:06 +01:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( %p %p %p %f )\n", __func__,
|
|
|
|
s1, s2, d, coef);
|
|
|
|
#endif
|
|
|
|
|
2023-07-04 17:25:12 +02:00
|
|
|
/* sanity check here ? or may be ask the
|
|
|
|
caller to do it himself ?
|
|
|
|
*/
|
|
|
|
if ( (coef < 0.0) || (coef >= 1.0) ){
|
|
|
|
fprintf(stderr, "%s: coef %f out of range\n", __func__, coef);
|
|
|
|
return -8;
|
|
|
|
}
|
|
|
|
|
2020-04-06 20:09:11 +02:00
|
|
|
foo = fimg_images_not_compatible(s1, s2);
|
2019-09-10 01:31:48 +02:00
|
|
|
if (foo) {
|
2020-02-17 07:40:06 +01:00
|
|
|
fprintf(stderr, "compat s1 s2 -> %d\n", foo);
|
2019-09-10 01:31:48 +02:00
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
2020-04-06 20:09:11 +02:00
|
|
|
foo = fimg_images_not_compatible(s1, d);
|
2019-09-10 01:31:48 +02:00
|
|
|
if (foo) {
|
2020-02-17 07:40:06 +01:00
|
|
|
fprintf(stderr, "compat s1 d -> %d\n", foo);
|
2019-09-10 01:31:48 +02:00
|
|
|
return foo;
|
|
|
|
}
|
2019-09-09 16:02:44 +02:00
|
|
|
|
2019-09-10 01:31:48 +02:00
|
|
|
switch (s1->type) {
|
|
|
|
case FIMG_TYPE_GRAY:
|
2020-02-17 07:40:06 +01:00
|
|
|
gray_interpolate (s1, s2, d, coef); break;
|
2019-09-10 01:31:48 +02:00
|
|
|
case FIMG_TYPE_RGB:
|
2020-02-17 07:40:06 +01:00
|
|
|
rgb_interpolate (s1, s2, d, coef); break;
|
2023-07-05 16:48:55 +02:00
|
|
|
case FIMG_TYPE_RGBA:
|
|
|
|
fprintf(stderr, "WTF?\n");
|
|
|
|
return -18;
|
2019-09-10 01:31:48 +02:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "%s, %d is a bad type\n", __func__, s1->type);
|
|
|
|
return -18;
|
2019-09-09 16:02:44 +02:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:24:31 +02:00
|
|
|
return 0;
|
2019-09-09 16:02:44 +02:00
|
|
|
}
|
|
|
|
/* ---------------------------------------------------------------- */
|