/src/gdal/alg/gdalresamplingkernels.h
Line  | Count  | Source (jump to first uncovered line)  | 
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  |  | static inline double CubicKernel(double dfX)  | 
24  | 0  | { | 
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  | 0  |     double dfAbsX = fabs(dfX);  | 
31  | 0  |     if (dfAbsX <= 1.0)  | 
32  | 0  |     { | 
33  | 0  |         double dfX2 = dfX * dfX;  | 
34  | 0  |         return dfX2 * (1.5 * dfAbsX - 2.5) + 1;  | 
35  | 0  |     }  | 
36  | 0  |     else if (dfAbsX <= 2.0)  | 
37  | 0  |     { | 
38  | 0  |         double dfX2 = dfX * dfX;  | 
39  | 0  |         return dfX2 * (-0.5 * dfAbsX + 2.5) - 4 * dfAbsX + 2;  | 
40  | 0  |     }  | 
41  | 0  |     else  | 
42  | 0  |         return 0.0;  | 
43  | 0  | } Unexecuted instantiation: gdalwarpkernel.cpp:CubicKernel(double) Unexecuted instantiation: gdal_interpolateatpoint.cpp:CubicKernel(double) Unexecuted instantiation: gdal_rpc.cpp:CubicKernel(double)  | 
44  |  |  | 
45  |  | static inline double CubicSplineKernel(double dfVal)  | 
46  | 0  | { | 
47  | 0  |     if (dfVal > 2.0)  | 
48  | 0  |         return 0.0;  | 
49  |  |  | 
50  | 0  |     const double xm1 = dfVal - 1.0;  | 
51  | 0  |     const double xp1 = dfVal + 1.0;  | 
52  | 0  |     const double xp2 = dfVal + 2.0;  | 
53  |  | 
  | 
54  | 0  |     const double a = xp2 <= 0.0 ? 0.0 : xp2 * xp2 * xp2;  | 
55  | 0  |     const double b = xp1 <= 0.0 ? 0.0 : xp1 * xp1 * xp1;  | 
56  | 0  |     const double c = dfVal <= 0.0 ? 0.0 : dfVal * dfVal * dfVal;  | 
57  | 0  |     const double d = xm1 <= 0.0 ? 0.0 : xm1 * xm1 * xm1;  | 
58  |  | 
  | 
59  | 0  |     return 0.16666666666666666667 * (a - (4.0 * b) + (6.0 * c) - (4.0 * d));  | 
60  | 0  | } Unexecuted instantiation: gdalwarpkernel.cpp:CubicSplineKernel(double) Unexecuted instantiation: gdal_interpolateatpoint.cpp:CubicSplineKernel(double) Unexecuted instantiation: gdal_rpc.cpp:CubicSplineKernel(double)  | 
61  |  |  | 
62  |  | /*! @endcond */  | 
63  |  |  | 
64  |  | #endif /* ndef GDALRESAMPLINGKERNELS_H_INCLUDED */  |