Пример #1
0
int main(int argc, char **argv) {
    int n = 2;
    double f[4] = { 0.0, 1.0, 2.0, 3.0 };
    double x[2] = { atof(argv[1]), atof(argv[2]) };
    double result;
    
    result = lerp(n, x, f);
    printf("Result is: %f\n", result);

    result = lerp2(x[0], x[1], f);
    printf("Result is: %f\n", result);

    return 0;
}
Пример #2
0
Файл: img.c Проект: rlk/scmtiff
static int img_linear(img *p, const double *v, float *c)
{
    double s = v[0] - 0.5;
    double t = v[1] - 0.5;

    const int ia = (int) floor(s);
    const int ib = (int)  ceil(s);
    const int ja = (int) floor(t);
    const int jb = (int)  ceil(t);

    float aa[4], ab[4];
    float ba[4], bb[4];

    int daa = img_pixel(p, ia, ja, aa);
    int dab = img_pixel(p, ia, jb, ab);
    int dba = img_pixel(p, ib, ja, ba);
    int dbb = img_pixel(p, ib, jb, bb);

    if (daa && dab && dba && dbb)
    {
        const float u = (float) (s - floor(s));
        const float v = (float) (t - floor(t));

        switch (p->c)
        {
            case 4: c[3] = lerp2(aa[3], ab[3], ba[3], bb[3], u, v);
            case 3: c[2] = lerp2(aa[2], ab[2], ba[2], bb[2], u, v);
            case 2: c[1] = lerp2(aa[1], ab[1], ba[1], bb[1], u, v);
            case 1: c[0] = lerp2(aa[0], ab[0], ba[0], bb[0], u, v);
        }
    }
    else if (daa)
    {
        switch (p->c)
        {
            case 4: c[3] = aa[3];
            case 3: c[2] = aa[2];
            case 2: c[1] = aa[1];
            case 1: c[0] = aa[0];
        }
    }
    else if (dab)
    {
        switch (p->c)
        {
            case 4: c[3] = ab[3];
            case 3: c[2] = ab[2];
            case 2: c[1] = ab[1];
            case 1: c[0] = ab[0];
        }
    }
    else if (dba)
    {
        switch (p->c)
        {
            case 4: c[3] = ba[3];
            case 3: c[2] = ba[2];
            case 2: c[1] = ba[1];
            case 1: c[0] = ba[0];
        }
    }
    else if (dbb)
    {
        switch (p->c)
        {
            case 4: c[3] = bb[3];
            case 3: c[2] = bb[2];
            case 2: c[1] = bb[1];
            case 1: c[0] = bb[0];
        }
    }
    return (daa || dab || dba || dbb) ? 1 : 0;
}