LibreOffice Module vcl (master) 1
ResampleKernel.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifndef INCLUDED_VCL_RESAMPLEKERNEL_HXX
21#define INCLUDED_VCL_RESAMPLEKERNEL_HXX
22
23#include <boost/math/special_functions/sinc.hpp>
24
25namespace vcl {
26
27// Resample kernels
28
29class Kernel
30{
31public:
32 Kernel() {}
33 virtual ~Kernel() {}
34
35 virtual double GetWidth() const = 0;
36 virtual double Calculate( double x ) const = 0;
37};
38
39class Lanczos3Kernel final : public Kernel
40{
41public:
43
44 virtual double GetWidth() const override { return 3.0; }
45 virtual double Calculate (double x) const override
46 {
47 return (-3.0 <= x && x < 3.0) ? SincFilter(x) * SincFilter( x / 3.0 ) : 0.0;
48 }
49
50 static double SincFilter(double x)
51 {
52 if (x == 0.0)
53 {
54 return 1.0;
55 }
56 x = x * M_PI;
57 return boost::math::sinc_pi(x, SincPolicy());
58 }
59
60private:
61 typedef boost::math::policies::policy<
62 boost::math::policies::promote_double<false> > SincPolicy;
63};
64
65class BicubicKernel final : public Kernel
66{
67public:
69
70private:
71 virtual double GetWidth() const override { return 2.0; }
72 virtual double Calculate (double x) const override
73 {
74 if (x < 0.0)
75 {
76 x = -x;
77 }
78
79 if (x <= 1.0)
80 {
81 return (1.5 * x - 2.5) * x * x + 1.0;
82 }
83 else if (x < 2.0)
84 {
85 return ((-0.5 * x + 2.5) * x - 4) * x + 2;
86 }
87 return 0.0;
88 }
89};
90
91class BilinearKernel final : public Kernel
92{
93public:
95
96private:
97 virtual double GetWidth() const override { return 1.0; }
98 virtual double Calculate (double x) const override
99 {
100 if (x < 0.0)
101 {
102 x = -x;
103 }
104 if (x < 1.0)
105 {
106 return 1.0-x;
107 }
108 return 0.0;
109 }
110};
111
112} // namespace vcl
113
114#endif // INCLUDED_VCL_RESAMPLEKERNEL_HXX
115
116/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual double GetWidth() const override
virtual double Calculate(double x) const override
virtual double GetWidth() const override
virtual double Calculate(double x) const override
virtual double GetWidth() const =0
virtual double Calculate(double x) const =0
virtual ~Kernel()
static double SincFilter(double x)
virtual double GetWidth() const override
virtual double Calculate(double x) const override
boost::math::policies::policy< boost::math::policies::promote_double< false > > SincPolicy
float x