LCOV - code coverage report
Current view: top level - alg - gdalresamplingkernels.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 19 20 95.0 %
Date: 2024-11-21 22:18:42 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  * $Id$
       3             :  *
       4             :  * Project:  GDAL Raster Interpolation
       5             :  * Purpose:  Interpolation algorithms with cache
       6             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 2001, Frank Warmerdam
      10             :  * Copyright (c) 2008-2012, Even Rouault <even dot rouault at spatialys.com>
      11             :  * Copyright (c) 2024, Javier Jimenez Shaw
      12             :  *
      13             :  * SPDX-License-Identifier: MIT
      14             :  ****************************************************************************/
      15             : 
      16             : #ifndef GDALRESAMPLINGKERNELS_H_INCLUDED
      17             : #define GDALRESAMPLINGKERNELS_H_INCLUDED
      18             : 
      19             : #include <cmath>
      20             : 
      21             : /*! @cond Doxygen_Suppress */
      22             : 
      23     4330210 : static inline double CubicKernel(double dfX)
      24             : {
      25             :     // http://en.wikipedia.org/wiki/Bicubic_interpolation#Bicubic_convolution_algorithm
      26             :     // W(x) formula with a = -0.5 (cubic hermite spline )
      27             :     // or
      28             :     // https://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf
      29             :     // k(x) (formula 8) with (B,C)=(0,0.5) the Catmull-Rom spline
      30     4330210 :     double dfAbsX = fabs(dfX);
      31     4330210 :     if (dfAbsX <= 1.0)
      32             :     {
      33      367328 :         double dfX2 = dfX * dfX;
      34      367328 :         return dfX2 * (1.5 * dfAbsX - 2.5) + 1;
      35             :     }
      36     3962880 :     else if (dfAbsX <= 2.0)
      37             :     {
      38     2495480 :         double dfX2 = dfX * dfX;
      39     2495480 :         return dfX2 * (-0.5 * dfAbsX + 2.5) - 4 * dfAbsX + 2;
      40             :     }
      41             :     else
      42     1467410 :         return 0.0;
      43             : }
      44             : 
      45         928 : static inline double CubicSplineKernel(double dfVal)
      46             : {
      47         928 :     if (dfVal > 2.0)
      48           0 :         return 0.0;
      49             : 
      50         928 :     const double xm1 = dfVal - 1.0;
      51         928 :     const double xp1 = dfVal + 1.0;
      52         928 :     const double xp2 = dfVal + 2.0;
      53             : 
      54         928 :     const double a = xp2 <= 0.0 ? 0.0 : xp2 * xp2 * xp2;
      55         928 :     const double b = xp1 <= 0.0 ? 0.0 : xp1 * xp1 * xp1;
      56         928 :     const double c = dfVal <= 0.0 ? 0.0 : dfVal * dfVal * dfVal;
      57         928 :     const double d = xm1 <= 0.0 ? 0.0 : xm1 * xm1 * xm1;
      58             : 
      59         928 :     return 0.16666666666666666667 * (a - (4.0 * b) + (6.0 * c) - (4.0 * d));
      60             : }
      61             : 
      62             : /*! @endcond */
      63             : 
      64             : #endif /* ndef GDALRESAMPLINGKERNELS_H_INCLUDED */

Generated by: LCOV version 1.14