RetroArch
filters.h
Go to the documentation of this file.
1 /* Copyright (C) 2010-2018 The RetroArch team
2  *
3  * ---------------------------------------------------------------------------------------
4  * The following license statement only applies to this file (filters.h).
5  * ---------------------------------------------------------------------------------------
6  *
7  * Permission is hereby granted, free of charge,
8  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef _LIBRETRO_SDK_FILTERS_H
24 #define _LIBRETRO_SDK_FILTERS_H
25 
26 /* for MSVC; should be benign under any circumstances */
27 #define _USE_MATH_DEFINES
28 
29 #include <stdlib.h>
30 #include <math.h>
31 #include <retro_inline.h>
32 #include <retro_math.h>
33 
34 static INLINE double sinc(double val)
35 {
36  if (fabs(val) < 0.00001)
37  return 1.0;
38  return sin(val) / val;
39 }
40 
41 /* Paeth prediction filter. */
42 static INLINE int paeth(int a, int b, int c)
43 {
44  int p = a + b - c;
45  int pa = abs(p - a);
46  int pb = abs(p - b);
47  int pc = abs(p - c);
48 
49  if (pa <= pb && pa <= pc)
50  return a;
51  else if (pb <= pc)
52  return b;
53  return c;
54 }
55 
56 /* Modified Bessel function of first order.
57  * Check Wiki for mathematical definition ... */
58 static INLINE double besseli0(double x)
59 {
60  unsigned i;
61  double sum = 0.0;
62  double factorial = 1.0;
63  double factorial_mult = 0.0;
64  double x_pow = 1.0;
65  double two_div_pow = 1.0;
66  double x_sqr = x * x;
67 
68  /* Approximate. This is an infinite sum.
69  * Luckily, it converges rather fast. */
70  for (i = 0; i < 18; i++)
71  {
72  sum += x_pow * two_div_pow / (factorial * factorial);
73 
74  factorial_mult += 1.0;
75  x_pow *= x_sqr;
76  two_div_pow *= 0.25;
77  factorial *= factorial_mult;
78  }
79 
80  return sum;
81 }
82 
83 static INLINE double kaiser_window_function(double index, double beta)
84 {
85  return besseli0(beta * sqrtf(1 - index * index));
86 }
87 
88 static INLINE double lanzcos_window_function(double index)
89 {
90  return sinc(M_PI * index);
91 }
92 
93 #endif
GLuint GLfloat * val
Definition: glext.h:7847
#define INLINE
Definition: retro_inline.h:35
static INLINE double lanzcos_window_function(double index)
Definition: filters.h:88
#define M_PI
Definition: compat.h:190
const GLubyte * c
Definition: glext.h:9812
GLboolean GLboolean GLboolean b
Definition: glext.h:6844
#define fabs(x)
Definition: math.h:27
static INLINE double sinc(double val)
Definition: filters.h:34
static INLINE int paeth(int a, int b, int c)
Definition: filters.h:42
GLint GLint GLint GLint GLint x
Definition: glext.h:6295
GLfloat GLfloat p
Definition: glext.h:9809
GLuint index
Definition: glext.h:6671
#define sin(x)
Definition: math.h:23
static INLINE double besseli0(double x)
Definition: filters.h:58
static INLINE double kaiser_window_function(double index, double beta)
Definition: filters.h:83
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6844