~ubuntu-branches/ubuntu/trusty/vips/trusty-proposed

« back to all changes in this revision

Viewing changes to libvips/create/mask_ideal.c

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2014-03-29 12:29:29 UTC
  • mfrom: (1.1.21) (30.1.16 sid)
  • Revision ID: package-import@ubuntu.com-20140329122929-fvxnaann32ex0gzk
Tags: 7.38.5-2
Enable dh-autoreconf. (Closes: #742872)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <vips/intl.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
{
 
59
        VipsMaskIdeal *ideal = (VipsMaskIdeal *) mask;
 
60
        double fc = ideal->frequency_cutoff;
 
61
 
 
62
        double dist2 = dx * dx + dy * dy;
 
63
        double fc2 = fc * fc;
 
64
 
 
65
        return( dist2 <= fc2 ? 1.0 : 0.0 ); 
 
66
}
 
67
 
 
68
static void
 
69
vips_mask_ideal_class_init( VipsMaskIdealClass *class )
 
70
{
 
71
        GObjectClass *gobject_class = G_OBJECT_CLASS( class );
 
72
        VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
 
73
        VipsMaskClass *mask_class = VIPS_MASK_CLASS( class );
 
74
 
 
75
        gobject_class->set_property = vips_object_set_property;
 
76
        gobject_class->get_property = vips_object_get_property;
 
77
 
 
78
        vobject_class->nickname = "mask_ideal";
 
79
        vobject_class->description = _( "make an ideal filter" );
 
80
 
 
81
        mask_class->point = vips_mask_ideal_point;
 
82
 
 
83
        VIPS_ARG_DOUBLE( class, "frequency_cutoff", 6, 
 
84
                _( "Frequency cutoff" ), 
 
85
                _( "Frequency cutoff" ),
 
86
                VIPS_ARGUMENT_REQUIRED_INPUT,
 
87
                G_STRUCT_OFFSET( VipsMaskIdeal, frequency_cutoff ),
 
88
                0.0, 1000000.0, 0.5 );
 
89
 
 
90
}
 
91
 
 
92
static void
 
93
vips_mask_ideal_init( VipsMaskIdeal *ideal )
 
94
{
 
95
        ideal->frequency_cutoff = 0.5;
 
96
}
 
97
 
 
98
/**
 
99
 * vips_mask_ideal:
 
100
 * @out: output image
 
101
 * @width: image size
 
102
 * @height: image size
 
103
 * @frequency_cutoff: 
 
104
 * @...: %NULL-terminated list of optional named arguments
 
105
 *
 
106
 * Optional arguments:
 
107
 *
 
108
 * @nodc: don't set the DC pixel
 
109
 * @reject: invert the filter sense
 
110
 * @optical: coordinates in optical space
 
111
 * @uchar: output a uchar image
 
112
 *
 
113
 * Make an ideal high- or low-pass filter, that is, one with a sharp cutoff
 
114
 * positioned at @frequency_cutoff, where @frequency_cutoff is in
 
115
 * the range 0 - 1.
 
116
 *
 
117
 * This operation creates a one-band float image of the specified size. 
 
118
 * The image has
 
119
 * values in the range [0, 1] and is typically used for multiplying against 
 
120
 * frequency domain images to filter them.
 
121
 * Masks are created with the DC component at (0, 0). The DC pixel always
 
122
 * has the value 1.0.
 
123
 *
 
124
 * Set @nodc to not set the DC pixel. 
 
125
 *
 
126
 * Set @optical to position the DC component in the centre of the image. This
 
127
 * makes the mask suitable for multiplying against optical Fourier transforms. 
 
128
 * See vips_wrap(). 
 
129
 *
 
130
 * Set @reject to invert the sense of
 
131
 * the filter. For example, low-pass becomes low-reject. 
 
132
 *
 
133
 * Set @uchar to output an 8-bit unsigned char image rather than a
 
134
 * float image. In this case, pixels are in the range [0 - 255].
 
135
 *
 
136
 * See also: vips_mask_ideal(), vips_mask_ideal_ring(), 
 
137
 * vips_mask_ideal_band(), vips_mask_butterworth(), 
 
138
 * vips_mask_butterworth_ring(), vips_mask_butterworth_band(), 
 
139
 * vips_mask_gaussian(), vips_mask_gaussian_ring(), 
 
140
 * vips_mask_gaussian_band(). 
 
141
 *
 
142
 * Returns: 0 on success, -1 on error
 
143
 */
 
144
int
 
145
vips_mask_ideal( VipsImage **out, int width, int height, 
 
146
        double frequency_cutoff, ... )
 
147
{
 
148
        va_list ap;
 
149
        int result;
 
150
 
 
151
        va_start( ap, frequency_cutoff );
 
152
        result = vips_call_split( "mask_ideal", ap, out, width, height, 
 
153
                frequency_cutoff );
 
154
        va_end( ap );
 
155
 
 
156
        return( result );
 
157
}