Coverage Report

Created: 2026-12-01 07:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvips/libvips/create/mask_ideal.c
Line
Count
Source
1
/* creates an ideal filter.
2
 *
3
 * 02/01/14
4
 *  - from ideal.c
5
 */
6
7
/*
8
9
  This file is part of VIPS.
10
11
  VIPS is free software; you can redistribute it and/or modify
12
  it under the terms of the GNU Lesser General Public License as published by
13
  the Free Software Foundation; either version 2 of the License, or
14
  (at your option) any later version.
15
16
  This program is distributed in the hope that it will be useful,
17
  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
  GNU Lesser General Public License for more details.
20
21
  You should have received a copy of the GNU Lesser General Public License
22
  along with this program; if not, write to the Free Software
23
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24
  02110-1301  USA
25
26
 */
27
28
/*
29
30
  These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
31
32
 */
33
34
/*
35
#define VIPS_DEBUG
36
 */
37
38
#ifdef HAVE_CONFIG_H
39
#include <config.h>
40
#endif /*HAVE_CONFIG_H*/
41
#include <glib/gi18n-lib.h>
42
43
#include <stdio.h>
44
#include <string.h>
45
#include <stdlib.h>
46
#include <math.h>
47
48
#include <vips/vips.h>
49
50
#include "pcreate.h"
51
#include "point.h"
52
#include "pmask.h"
53
54
4
G_DEFINE_TYPE(VipsMaskIdeal, vips_mask_ideal, VIPS_TYPE_MASK);
55
4
56
4
static double
57
4
vips_mask_ideal_point(VipsMask *mask, double dx, double dy)
58
4
{
59
0
  VipsMaskIdeal *ideal = (VipsMaskIdeal *) mask;
60
0
  double fc = ideal->frequency_cutoff;
61
62
0
  double dist2 = dx * dx + dy * dy;
63
0
  double fc2 = fc * fc;
64
65
0
  return dist2 <= fc2 ? 0.0 : 1.0;
66
0
}
67
68
static void
69
vips_mask_ideal_class_init(VipsMaskIdealClass *class)
70
1
{
71
1
  GObjectClass *gobject_class = G_OBJECT_CLASS(class);
72
1
  VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS(class);
73
1
  VipsMaskClass *mask_class = VIPS_MASK_CLASS(class);
74
75
1
  gobject_class->set_property = vips_object_set_property;
76
1
  gobject_class->get_property = vips_object_get_property;
77
78
1
  vobject_class->nickname = "mask_ideal";
79
1
  vobject_class->description = _("make an ideal filter");
80
81
1
  mask_class->point = vips_mask_ideal_point;
82
83
1
  VIPS_ARG_DOUBLE(class, "frequency_cutoff", 6,
84
1
    _("Frequency cutoff"),
85
1
    _("Frequency cutoff"),
86
1
    VIPS_ARGUMENT_REQUIRED_INPUT,
87
1
    G_STRUCT_OFFSET(VipsMaskIdeal, frequency_cutoff),
88
1
    0.0, 1000000.0, 0.5);
89
1
}
90
91
static void
92
vips_mask_ideal_init(VipsMaskIdeal *ideal)
93
0
{
94
0
  ideal->frequency_cutoff = 0.5;
95
0
}
96
97
/**
98
 * vips_mask_ideal:
99
 * @out: (out): output image
100
 * @width: image size
101
 * @height: image size
102
 * @frequency_cutoff: threshold at which filter ends
103
 * @...: `NULL`-terminated list of optional named arguments
104
 *
105
 * Make an ideal high- or low-pass filter, that is, one with a sharp cutoff
106
 * positioned at @frequency_cutoff, where @frequency_cutoff is in
107
 * the range 0 - 1.
108
 *
109
 * This operation creates a one-band float image of the specified size.
110
 * The image has
111
 * values in the range [0, 1] and is typically used for multiplying against
112
 * frequency domain images to filter them.
113
 * Masks are created with the DC component at (0, 0). The DC pixel always
114
 * has the value 1.0.
115
 *
116
 * Set @nodc to not set the DC pixel.
117
 *
118
 * Set @optical to position the DC component in the centre of the image. This
119
 * makes the mask suitable for multiplying against optical Fourier transforms.
120
 * See [method@Image.wrap].
121
 *
122
 * Set @reject to invert the sense of
123
 * the filter. For example, low-pass becomes low-reject.
124
 *
125
 * Set @uchar to output an 8-bit unsigned char image rather than a
126
 * float image. In this case, pixels are in the range [0 - 255].
127
 *
128
 * ::: tip "Optional arguments"
129
 *     * @nodc: `gboolean`, don't set the DC pixel
130
 *     * @reject: `gboolean`, invert the filter sense
131
 *     * @optical: `gboolean`, coordinates in optical space
132
 *     * @uchar: `gboolean`, output a uchar image
133
 *
134
 * ::: seealso
135
 *     [ctor@Image.mask_ideal], [ctor@Image.mask_ideal_ring],
136
 *     [ctor@Image.mask_ideal_band], [ctor@Image.mask_butterworth],
137
 *     [ctor@Image.mask_butterworth_ring], [ctor@Image.mask_butterworth_band],
138
 *     [ctor@Image.mask_gaussian], [ctor@Image.mask_gaussian_ring],
139
 *     [ctor@Image.mask_gaussian_band].
140
 *
141
 * Returns: 0 on success, -1 on error
142
 */
143
int
144
vips_mask_ideal(VipsImage **out, int width, int height,
145
  double frequency_cutoff, ...)
146
0
{
147
0
  va_list ap;
148
0
  int result;
149
150
0
  va_start(ap, frequency_cutoff);
151
0
  result = vips_call_split("mask_ideal", ap, out, width, height,
152
0
    frequency_cutoff);
153
0
  va_end(ap);
154
155
0
  return result;
156
0
}