IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 5, 2011, 10:37:54 AM (15 years ago)
Author:
eugene
Message:

compile-time option for separable (but unthreaded) bilinear interpolation (which is faster?); correct psImageMaskCircle for 0.5 pixel offset

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/imageops/psImageInterpolate.c

    r28667 r31446  
    3131#include "psImageConvolve.h"
    3232
     33# define IS_BILIN_SEPARABLE 0
     34
    3335#include "psImageInterpolate.h"
    3436
     
    4850};
    4951
     52# if (IS_BILIN_SEPARABLE)
    5053/// Generate a linear interpolation kernel
    5154static inline void interpolationKernelBilinear(psF32 *kernel, // Kernel vector to populate
     
    5659    kernel[1] = frac;
    5760}
     61# else
     62/// Generate a linear interpolation kernel
     63static inline void interpolationKernelBilinear(
     64    psF32 kernel[kernelSizes[PS_INTERPOLATE_BILINEAR]][kernelSizes[PS_INTERPOLATE_BILINEAR]], // Kernel
     65    float xFrac, float yFrac // Fraction of pixel
     66    )
     67{
     68    // (xF*yF, (1-xF)(1-yF) = 1 - xF - yF + xFyF
     69
     70    kernel[0][0] = 1.0 - xFrac - yFrac + xFrac*yFrac;
     71    kernel[1][0] = yFrac - xFrac*yFrac;
     72    kernel[0][1] = xFrac - xFrac*yFrac;
     73    kernel[1][1] = xFrac*yFrac;
     74}
     75# endif
    5876
    5977#if 0
     
    173191        // Nothing to pre-compute
    174192        break;
     193# if (IS_BILIN_SEPARABLE)
    175194      case PS_INTERPOLATE_BILINEAR:
    176195        interpolationKernelBilinear(kernel, frac);
    177196        break;
     197# endif
    178198      case PS_INTERPOLATE_GAUSS:
    179199        interpolationKernelGauss(kernel, kernelSizes[mode], 0.5, frac);
     
    184204        interpolationKernelLanczos(kernel, kernelSizes[mode], frac);
    185205        break;
     206# if (!IS_BILIN_SEPARABLE)
     207      case PS_INTERPOLATE_BILINEAR:
     208# endif
    186209      case PS_INTERPOLATE_BIQUADRATIC:  // 2D kernel
    187210      default:
     
    234257
    235258    switch (mode) {
     259# if (IS_BILIN_SEPARABLE)
    236260      case PS_INTERPOLATE_BILINEAR:
     261# endif
    237262      case PS_INTERPOLATE_GAUSS:
    238263      case PS_INTERPOLATE_LANCZOS2:
     
    258283        }
    259284        break;
     285# if (!IS_BILIN_SEPARABLE)
     286      case PS_INTERPOLATE_BILINEAR:
     287# endif
    260288      case PS_INTERPOLATE_BIQUADRATIC:
    261289        // 2D kernel, would cost too much memory to pre-calculate
     
    360388    int xCentral = floor((X) - 0.5), yCentral = floor((Y) - 0.5); /* Central pixel */ \
    361389    float xFrac = (X) - xCentral - 0.5, yFrac = (Y) - yCentral - 0.5; /* Fraction of pixel */ \
     390    bool xExact = fabsf(xFrac) < FLT_EPSILON, yExact = fabsf(yFrac) < FLT_EPSILON; /* Are shifts exact? */ \
     391
     392// Set up the kernel parameters; defines some useful values
     393// EAM : I'm unsure of the right answer here
     394#define INTERPOLATE_SETUP_EAM(X, Y)                              \
     395    int xCentral = floor((X)), yCentral = floor((Y)); /* Central pixel */ \
     396    float xFrac = (X) - xCentral, yFrac = (Y) - yCentral; /* Fraction of pixel */ \
    362397    bool xExact = fabsf(xFrac) < FLT_EPSILON, yExact = fabsf(yFrac) < FLT_EPSILON; /* Are shifts exact? */ \
    363398
     
    722757}
    723758
    724 // Interpolation engine for (separable) interpolation kernels
     759// Interpolation engine for (non-separable) interpolation kernels
    725760static psImageInterpolateStatus interpolateKernel(double *imageValue, double *varianceValue,
    726761                                                  psImageMaskType *maskValue, float x, float y,
     
    747782    // Get the appropriate kernels
    748783    psF32 kernel[size][size];
     784
     785# if (IS_BILIN_SEPARABLE)
    749786    psAssert(mode == PS_INTERPOLATE_BIQUADRATIC, "Mode is %x", mode);
    750787    interpolationKernelBiquadratic(kernel, xFrac, yFrac);
     788# else
     789    psAssert((mode == PS_INTERPOLATE_BIQUADRATIC) || (mode == PS_INTERPOLATE_BILINEAR), "Mode is %x", mode);
     790    if (mode == PS_INTERPOLATE_BIQUADRATIC) {
     791        interpolationKernelBiquadratic(kernel, xFrac, yFrac);
     792    } else {
     793        interpolationKernelBilinear(kernel, xFrac, yFrac);
     794    }
     795# endif
     796
     797# if (0)
     798    for (int i = 0; i < size; i++) {
     799        for (int j = 0; j < size; j++) {
     800            fprintf (stderr, "%f ", kernel[i][j]);
     801        }
     802        fprintf (stderr, "\n");
     803    }
     804# endif
    751805
    752806    float sumKernel = 0.0;              // Sum of the kernel
     
    908962        return interpolateKernel(imageValue, varianceValue, maskValue, x, y, interp);
    909963      case PS_INTERPOLATE_BILINEAR:
     964# if (!IS_BILIN_SEPARABLE)
     965        return interpolateKernel(imageValue, varianceValue, maskValue, x, y, interp);
     966# endif
    910967      case PS_INTERPOLATE_GAUSS:
    911968      case PS_INTERPOLATE_LANCZOS2:
Note: See TracChangeset for help on using the changeset viewer.