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

« back to all changes in this revision

Viewing changes to libvips/freqfilt/spectrum.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
/* make a displayable power spectrum for an image
 
2
 *
 
3
 * Author: Nicos Dessipris
 
4
 * Written on: 27/03/1991
 
5
 * Modified on : 
 
6
 * 16/6/93 J.Cupitt
 
7
 *      - im_ioflag() changed to im_iocheck()
 
8
 * 23/2/95 JC
 
9
 *      - rewritten for partials
 
10
 * 10/9/98 JC
 
11
 *      - frees memory more quickly
 
12
 * 2/4/02 JC
 
13
 *      - any number of bands
 
14
 * 7/2/10
 
15
 *      - gtkdoc
 
16
 *      - cleanups
 
17
 * 3/1/14
 
18
 *      - redone as a class
 
19
 */
 
20
 
 
21
/*
 
22
 
 
23
    This file is part of VIPS.
 
24
    
 
25
    VIPS is free software; you can redistribute it and/or modify
 
26
    it under the terms of the GNU Lesser General Public License as published by
 
27
    the Free Software Foundation; either version 2 of the License, or
 
28
    (at your option) any later version.
 
29
 
 
30
    This program is distributed in the hope that it will be useful,
 
31
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
32
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
33
    GNU Lesser General Public License for more details.
 
34
 
 
35
    You should have received a copy of the GNU Lesser General Public License
 
36
    along with this program; if not, write to the Free Software
 
37
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
38
    02110-1301  USA
 
39
 
 
40
 */
 
41
 
 
42
/*
 
43
 
 
44
    These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
 
45
 
 
46
 */
 
47
 
 
48
#ifdef HAVE_CONFIG_H
 
49
#include <config.h>
 
50
#endif /*HAVE_CONFIG_H*/
 
51
#include <vips/intl.h>
 
52
 
 
53
#include <stdio.h>
 
54
#include <stdlib.h>
 
55
 
 
56
#include <vips/vips.h>
 
57
#include "pfreqfilt.h"
 
58
 
 
59
typedef VipsFreqfilt VipsSpectrum;
 
60
typedef VipsFreqfiltClass VipsSpectrumClass;
 
61
 
 
62
G_DEFINE_TYPE( VipsSpectrum, vips_spectrum, VIPS_TYPE_FREQFILT );
 
63
 
 
64
static int
 
65
vips_spectrum_build( VipsObject *object )
 
66
{
 
67
        VipsFreqfilt *freqfilt = VIPS_FREQFILT( object );
 
68
        VipsImage **t = (VipsImage **) vips_object_local_array( object, 5 );
 
69
 
 
70
        VipsImage *in;
 
71
 
 
72
        if( VIPS_OBJECT_CLASS( vips_spectrum_parent_class )->
 
73
                build( object ) )
 
74
                return( -1 );
 
75
 
 
76
        in = freqfilt->in;
 
77
 
 
78
        if( in->BandFmt != VIPS_FORMAT_COMPLEX ) {
 
79
                if( vips_fwfft( in, &t[0], NULL ) )
 
80
                        return( -1 );
 
81
                in = t[0];
 
82
        }
 
83
 
 
84
        if( vips_abs( in, &t[1], NULL ) ||
 
85
                vips_scale( t[1], &t[2], "log", TRUE, NULL ) || 
 
86
                vips_wrap( t[2], &t[3], NULL ) )
 
87
                return( -1 );
 
88
 
 
89
        if( vips_image_write( t[3], freqfilt->out ) )
 
90
                return( -1 );
 
91
 
 
92
        return( 0 );
 
93
}
 
94
 
 
95
static void
 
96
vips_spectrum_class_init( VipsSpectrumClass *class )
 
97
{
 
98
        VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
 
99
 
 
100
        vobject_class->nickname = "spectrum";
 
101
        vobject_class->description = _( "make displayable power spectrum" );
 
102
        vobject_class->build = vips_spectrum_build;
 
103
 
 
104
}
 
105
 
 
106
static void
 
107
vips_spectrum_init( VipsSpectrum *spectrum )
 
108
{
 
109
}
 
110
 
 
111
/**
 
112
 * vips_spectrum:
 
113
 * @in: input image 
 
114
 * @out: output image
 
115
 * @...: %NULL-terminated list of optional named arguments
 
116
 *
 
117
 * Make a displayable (ie. 8-bit unsigned int) power spectrum.
 
118
 *
 
119
 * If @in is non-complex, it is transformed to Fourier space. Then the
 
120
 * absolute value is passed through vips_scale() in log mode, and vips_wrap().
 
121
 *
 
122
 * See also: vips_fwfft(), vips_scale(), vips_wrap().
 
123
 *
 
124
 * Returns: 0 on success, -1 on error.
 
125
 */
 
126
int
 
127
vips_spectrum( VipsImage *in, VipsImage **out, ... )
 
128
{
 
129
        va_list ap;
 
130
        int result;
 
131
 
 
132
        va_start( ap, out );
 
133
        result = vips_call_split( "spectrum", ap, in, out );
 
134
        va_end( ap );
 
135
 
 
136
        return( result );
 
137
}
 
138