Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/inc/ResampleKernel.hxx
Line
Count
Source
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
#pragma once
21
22
#include <boost/math/special_functions/sinc.hpp>
23
24
namespace vcl {
25
26
// Resample kernels
27
28
class Kernel
29
{
30
public:
31
0
             Kernel() {}
32
0
    virtual ~Kernel() {}
33
34
    virtual double  GetWidth() const = 0;
35
    virtual double  Calculate( double x ) const = 0;
36
};
37
38
class Lanczos3Kernel final : public Kernel
39
{
40
public:
41
0
    Lanczos3Kernel() : Kernel () {}
42
43
0
    virtual double  GetWidth() const override { return 3.0; }
44
    virtual double  Calculate (double x) const override
45
0
    {
46
0
        return (-3.0 <= x && x < 3.0) ? SincFilter(x) * SincFilter( x / 3.0 ) : 0.0;
47
0
    }
48
49
    static double SincFilter(double x)
50
0
    {
51
0
        if (x == 0.0)
52
0
        {
53
0
            return 1.0;
54
0
        }
55
0
        x = x * M_PI;
56
0
        return boost::math::sinc_pi(x, SincPolicy());
57
0
    }
58
59
private:
60
    typedef boost::math::policies::policy<
61
        boost::math::policies::promote_double<false> > SincPolicy;
62
};
63
64
class BicubicKernel final : public Kernel
65
{
66
public:
67
0
    BicubicKernel() : Kernel () {}
68
69
private:
70
0
    virtual double  GetWidth() const override { return 2.0; }
71
    virtual double  Calculate (double x) const override
72
0
    {
73
0
        if (x < 0.0)
74
0
        {
75
0
            x = -x;
76
0
        }
77
78
0
        if (x <= 1.0)
79
0
        {
80
0
            return (1.5 * x - 2.5) * x * x + 1.0;
81
0
        }
82
0
        else if (x < 2.0)
83
0
        {
84
0
            return ((-0.5 * x + 2.5) * x - 4) * x + 2;
85
0
        }
86
0
        return 0.0;
87
0
    }
88
};
89
90
class BilinearKernel final : public Kernel
91
{
92
public:
93
0
    BilinearKernel() : Kernel () {}
94
95
private:
96
0
    virtual double  GetWidth() const override { return 1.0; }
97
    virtual double  Calculate (double x) const override
98
0
    {
99
0
        if (x < 0.0)
100
0
        {
101
0
            x = -x;
102
0
        }
103
0
        if (x < 1.0)
104
0
        {
105
0
            return 1.0-x;
106
0
        }
107
0
        return 0.0;
108
0
    }
109
};
110
111
} // namespace vcl
112
113
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */