tdf#151341 Use lzfse compression instead of bzip2
[LibreOffice.git] / vcl / inc / ResampleKernel.hxx
blobca54213f544989f29921619d9d3a571f0808e546
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_RESAMPLEKERNEL_HXX
21 #define INCLUDED_VCL_RESAMPLEKERNEL_HXX
23 #include <boost/math/special_functions/sinc.hpp>
25 namespace vcl {
27 // Resample kernels
29 class Kernel
31 public:
32 Kernel() {}
33 virtual ~Kernel() {}
35 virtual double GetWidth() const = 0;
36 virtual double Calculate( double x ) const = 0;
39 class Lanczos3Kernel final : public Kernel
41 public:
42 Lanczos3Kernel() : Kernel () {}
44 virtual double GetWidth() const override { return 3.0; }
45 virtual double Calculate (double x) const override
47 return (-3.0 <= x && x < 3.0) ? SincFilter(x) * SincFilter( x / 3.0 ) : 0.0;
50 static double SincFilter(double x)
52 if (x == 0.0)
54 return 1.0;
56 x = x * M_PI;
57 return boost::math::sinc_pi(x, SincPolicy());
60 private:
61 typedef boost::math::policies::policy<
62 boost::math::policies::promote_double<false> > SincPolicy;
65 class BicubicKernel final : public Kernel
67 public:
68 BicubicKernel() : Kernel () {}
70 private:
71 virtual double GetWidth() const override { return 2.0; }
72 virtual double Calculate (double x) const override
74 if (x < 0.0)
76 x = -x;
79 if (x <= 1.0)
81 return (1.5 * x - 2.5) * x * x + 1.0;
83 else if (x < 2.0)
85 return ((-0.5 * x + 2.5) * x - 4) * x + 2;
87 return 0.0;
91 class BilinearKernel final : public Kernel
93 public:
94 BilinearKernel() : Kernel () {}
96 private:
97 virtual double GetWidth() const override { return 1.0; }
98 virtual double Calculate (double x) const override
100 if (x < 0.0)
102 x = -x;
104 if (x < 1.0)
106 return 1.0-x;
108 return 0.0;
112 } // namespace vcl
114 #endif // INCLUDED_VCL_RESAMPLEKERNEL_HXX
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */