Coverage Report

Created: 2025-01-28 06:33

/src/libvips/libvips/create/mask_ideal.c
Line
Count
Source (jump to first uncovered line)
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
G_DEFINE_TYPE(VipsMaskIdeal, vips_mask_ideal, VIPS_TYPE_MASK);
55
56
static double
57
vips_mask_ideal_point(VipsMask *mask, double dx, double dy)
58
0
{
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
 * Optional arguments:
106
 *
107
 * * @nodc: don't set the DC pixel
108
 * * @reject: invert the filter sense
109
 * * @optical: coordinates in optical space
110
 * * @uchar: output a uchar image
111
 *
112
 * Make an ideal high- or low-pass filter, that is, one with a sharp cutoff
113
 * positioned at @frequency_cutoff, where @frequency_cutoff is in
114
 * the range 0 - 1.
115
 *
116
 * This operation creates a one-band float image of the specified size.
117
 * The image has
118
 * values in the range [0, 1] and is typically used for multiplying against
119
 * frequency domain images to filter them.
120
 * Masks are created with the DC component at (0, 0). The DC pixel always
121
 * has the value 1.0.
122
 *
123
 * Set @nodc to not set the DC pixel.
124
 *
125
 * Set @optical to position the DC component in the centre of the image. This
126
 * makes the mask suitable for multiplying against optical Fourier transforms.
127
 * See vips_wrap().
128
 *
129
 * Set @reject to invert the sense of
130
 * the filter. For example, low-pass becomes low-reject.
131
 *
132
 * Set @uchar to output an 8-bit unsigned char image rather than a
133
 * float image. In this case, pixels are in the range [0 - 255].
134
 *
135
 * See also: vips_mask_ideal(), vips_mask_ideal_ring(),
136
 * vips_mask_ideal_band(), vips_mask_butterworth(),
137
 * vips_mask_butterworth_ring(), vips_mask_butterworth_band(),
138
 * vips_mask_gaussian(), vips_mask_gaussian_ring(),
139
 * vips_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
}