deprecate old im_*fft*() funcs
just wrappers over the new classes
This commit is contained in:
parent
46489ea84c
commit
fe92ef64d4
|
@ -4370,3 +4370,56 @@ im_video_v4l1( IMAGE *im, const char *device,
|
|||
return( -1 );
|
||||
}
|
||||
|
||||
int
|
||||
im_fwfft( IMAGE *in, IMAGE *out )
|
||||
{
|
||||
VipsImage *x;
|
||||
|
||||
if( vips_fwfft( in, &x, NULL ) )
|
||||
return( -1 );
|
||||
|
||||
if( im_copy( x, out ) ) {
|
||||
g_object_unref( x );
|
||||
return( -1 );
|
||||
}
|
||||
g_object_unref( x );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_invfft( IMAGE *in, IMAGE *out )
|
||||
{
|
||||
VipsImage *x;
|
||||
|
||||
if( vips_invfft( in, &x, NULL ) )
|
||||
return( -1 );
|
||||
|
||||
if( im_copy( x, out ) ) {
|
||||
g_object_unref( x );
|
||||
return( -1 );
|
||||
}
|
||||
g_object_unref( x );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_invfftr( IMAGE *in, IMAGE *out )
|
||||
{
|
||||
VipsImage *x;
|
||||
|
||||
if( vips_invfft( in, &x,
|
||||
"real", TRUE,
|
||||
NULL ) )
|
||||
return( -1 );
|
||||
|
||||
if( im_copy( x, out ) ) {
|
||||
g_object_unref( x );
|
||||
return( -1 );
|
||||
}
|
||||
g_object_unref( x );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
|
|
|
@ -10,9 +10,6 @@ libfreq_filt_la_SOURCES = \
|
|||
im_disp_ps.c \
|
||||
im_fractsurf.c \
|
||||
im_freq_mask.c \
|
||||
im_freqflt.c \
|
||||
im_fwfft.c \
|
||||
im_invfft.c \
|
||||
im_invfftr.c
|
||||
im_freqflt.c
|
||||
|
||||
AM_CPPFLAGS = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@
|
||||
|
|
|
@ -1,384 +0,0 @@
|
|||
/* im_fwfft
|
||||
*
|
||||
* Copyright: 1990, N. Dessipris.
|
||||
*
|
||||
* Author: Nicos Dessipris
|
||||
* Written on: 12/04/1990
|
||||
* Modified on : 09/05/1990 to cope with float input
|
||||
* Modified on : 08/03/1991 history removed
|
||||
* Modified on : 03/04/1991 to cope with any input
|
||||
*
|
||||
* 28/6/95 JC
|
||||
* - rewritten to use im_clip2f() rather than own code
|
||||
* - memory leaks fixed
|
||||
* 10/9/98 JC
|
||||
* - frees memory more quickly
|
||||
* 2/4/02 JC
|
||||
* - fftw code added
|
||||
* 13/7/02 JC
|
||||
* - output Type set to IM_TYPE_FOURIER to help nip
|
||||
* 27/2/03 JC
|
||||
* - exploits real_to_complex() path in libfftw for real input (thanks
|
||||
* Matt) for a 2x speed-up
|
||||
* 17/11/03 JC
|
||||
* - fix a segv for wider than high images in the real_to_complex() path
|
||||
* (thanks Andrey)
|
||||
* - fixes to real_to_complex() path to give the correct result for
|
||||
* non-square images, including odd widths and heights
|
||||
* 3/11/04
|
||||
* - added fftw3 support
|
||||
* 7/2/10
|
||||
* - cleanups
|
||||
* - gtkdoc
|
||||
* 25/3/10
|
||||
* - have a "t" image linked to out to keep the image alive for longer
|
||||
* 27/1/12
|
||||
* - better setting of interpretation
|
||||
* - remove own fft fallback code
|
||||
* - remove fftw2 path
|
||||
* - reduce memuse
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
This file is part of VIPS.
|
||||
|
||||
VIPS is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
||||
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
#include <vips/intl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef HAVE_FFTW
|
||||
#include <fftw3.h>
|
||||
#endif /*HAVE_FFTW*/
|
||||
|
||||
#include <vips/vips.h>
|
||||
#include <vips/internal.h>
|
||||
|
||||
#ifdef HAVE_FFTW
|
||||
|
||||
/* Real to complex forward transform.
|
||||
*/
|
||||
static int
|
||||
rfwfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
|
||||
{
|
||||
const guint64 size = VIPS_IMAGE_N_PELS( in );
|
||||
const int half_width = in->Xsize / 2 + 1;
|
||||
|
||||
IMAGE *real;
|
||||
double *half_complex;
|
||||
double *planner_scratch;
|
||||
|
||||
fftw_plan plan;
|
||||
double *buf, *q, *p;
|
||||
int x, y;
|
||||
|
||||
if( vips_check_mono( "im_fwfft", in ) ||
|
||||
vips_check_uncoded( "im_fwfft", in ) )
|
||||
return( -1 );
|
||||
|
||||
/* Convert input to a real double membuffer.
|
||||
*/
|
||||
if( !(real = im_open_local( dummy, "fwfft1:1", "t" )) ||
|
||||
im_clip2fmt( in, real, IM_BANDFMT_DOUBLE ) )
|
||||
return( -1 );
|
||||
|
||||
/* Make the plan for the transform. Yes, they really do use nx for
|
||||
* height and ny for width. Use a separate scratch buffer for the
|
||||
* planner, we can't overwrite real->data
|
||||
*/
|
||||
if( !(planner_scratch = IM_ARRAY( dummy,
|
||||
VIPS_IMAGE_N_PELS( in ), double )) )
|
||||
return( -1 );
|
||||
if( !(half_complex = IM_ARRAY( dummy,
|
||||
in->Ysize * half_width * 2, double )) )
|
||||
return( -1 );
|
||||
if( !(plan = fftw_plan_dft_r2c_2d( in->Ysize, in->Xsize,
|
||||
planner_scratch, (fftw_complex *) half_complex,
|
||||
0 )) ) {
|
||||
im_error( "im_fwfft",
|
||||
"%s", _( "unable to create transform plan" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if( im_incheck( real ) )
|
||||
return( -1 );
|
||||
fftw_execute_dft_r2c( plan,
|
||||
(double *) real->data, (fftw_complex *) half_complex );
|
||||
|
||||
fftw_destroy_plan( plan );
|
||||
|
||||
/* WIO to out.
|
||||
*/
|
||||
if( im_outcheck( out ) ||
|
||||
im_cp_desc( out, in ) )
|
||||
return( -1 );
|
||||
out->BandFmt = IM_BANDFMT_DPCOMPLEX;
|
||||
out->Type = IM_TYPE_FOURIER;
|
||||
if( im_setupout( out ) )
|
||||
return( -1 );
|
||||
if( !(buf = (double *) IM_ARRAY( dummy,
|
||||
IM_IMAGE_SIZEOF_LINE( out ), VipsPel )) )
|
||||
return( -1 );
|
||||
|
||||
/* Copy to out and normalise. The right half is the up/down and
|
||||
* left/right flip of the left, but conjugated. Do the first
|
||||
* row separately, then mirror around the centre row.
|
||||
*/
|
||||
p = half_complex;
|
||||
q = buf;
|
||||
|
||||
for( x = 0; x < half_width; x++ ) {
|
||||
q[0] = p[0] / size;
|
||||
q[1] = p[1] / size;
|
||||
p += 2;
|
||||
q += 2;
|
||||
}
|
||||
|
||||
p = half_complex + ((in->Xsize + 1) / 2 - 1) * 2;
|
||||
|
||||
for( x = half_width; x < out->Xsize; x++ ) {
|
||||
q[0] = p[0] / size;
|
||||
q[1] = -1.0 * p[1] / size;
|
||||
p -= 2;
|
||||
q += 2;
|
||||
}
|
||||
|
||||
if( im_writeline( 0, out, (VipsPel *) buf ) )
|
||||
return( -1 );
|
||||
|
||||
for( y = 1; y < out->Ysize; y++ ) {
|
||||
p = half_complex + y * half_width * 2;
|
||||
q = buf;
|
||||
|
||||
for( x = 0; x < half_width; x++ ) {
|
||||
q[0] = p[0] / size;
|
||||
q[1] = p[1] / size;
|
||||
p += 2;
|
||||
q += 2;
|
||||
}
|
||||
|
||||
/* Good grief.
|
||||
*/
|
||||
p = half_complex + 2 *
|
||||
((out->Ysize - y + 1) * half_width - 2 +
|
||||
(in->Xsize & 1));
|
||||
|
||||
for( x = half_width; x < out->Xsize; x++ ) {
|
||||
q[0] = p[0] / size;
|
||||
q[1] = -1.0 * p[1] / size;
|
||||
p -= 2;
|
||||
q += 2;
|
||||
}
|
||||
|
||||
if( im_writeline( y, out, (VipsPel *) buf ) )
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/* Complex to complex forward transform.
|
||||
*/
|
||||
static int
|
||||
cfwfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
|
||||
{
|
||||
IMAGE *cmplx;
|
||||
fftw_plan plan;
|
||||
double *planner_scratch;
|
||||
double *buf, *q, *p;
|
||||
int x, y;
|
||||
|
||||
if( vips_check_mono( "im_fwfft", in ) ||
|
||||
vips_check_uncoded( "im_fwfft", in ) )
|
||||
return( -1 );
|
||||
|
||||
/* Double-complex input.
|
||||
*/
|
||||
if( !(cmplx = im_open_local( dummy, "fwfft1:1", "t" )) ||
|
||||
im_clip2fmt( in, cmplx, IM_BANDFMT_DPCOMPLEX ) )
|
||||
return( -1 );
|
||||
|
||||
/* We have to have a separate buffer for the planner to work on.
|
||||
*/
|
||||
if( !(planner_scratch = IM_ARRAY( dummy,
|
||||
VIPS_IMAGE_N_PELS( in ) * 2, double )) )
|
||||
return( -1 );
|
||||
|
||||
/* Make the plan for the transform.
|
||||
*/
|
||||
if( !(plan = fftw_plan_dft_2d( in->Ysize, in->Xsize,
|
||||
(fftw_complex *) planner_scratch,
|
||||
(fftw_complex *) planner_scratch,
|
||||
FFTW_FORWARD,
|
||||
0 )) ) {
|
||||
im_error( "im_fwfft",
|
||||
"%s", _( "unable to create transform plan" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if( im_incheck( cmplx ) )
|
||||
return( -1 );
|
||||
fftw_execute_dft( plan,
|
||||
(fftw_complex *) cmplx->data, (fftw_complex *) cmplx->data );
|
||||
|
||||
fftw_destroy_plan( plan );
|
||||
|
||||
/* WIO to out.
|
||||
*/
|
||||
if( im_outcheck( out ) ||
|
||||
im_cp_desc( out, in ) )
|
||||
return( -1 );
|
||||
out->BandFmt = IM_BANDFMT_DPCOMPLEX;
|
||||
out->Type = IM_TYPE_FOURIER;
|
||||
if( im_setupout( out ) )
|
||||
return( -1 );
|
||||
if( !(buf = (double *) IM_ARRAY( dummy,
|
||||
IM_IMAGE_SIZEOF_LINE( out ), VipsPel )) )
|
||||
return( -1 );
|
||||
|
||||
/* Copy to out, normalise.
|
||||
*/
|
||||
for( p = (double *) cmplx->data, y = 0; y < out->Ysize; y++ ) {
|
||||
guint64 size = VIPS_IMAGE_N_PELS( out );
|
||||
|
||||
q = buf;
|
||||
|
||||
for( x = 0; x < out->Xsize; x++ ) {
|
||||
q[0] = p[0] / size;
|
||||
q[1] = p[1] / size;
|
||||
p += 2;
|
||||
q += 2;
|
||||
}
|
||||
|
||||
if( im_writeline( y, out, (VipsPel *) buf ) )
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static int
|
||||
fwfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
|
||||
{
|
||||
if( vips_bandfmt_iscomplex( in->BandFmt ) )
|
||||
return( cfwfft1( dummy, in, out ) );
|
||||
else
|
||||
return( rfwfft1( dummy, in, out ) );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static int
|
||||
fwfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
|
||||
{
|
||||
im_error( "im_fwfft",
|
||||
"%s", _( "vips configured without FFT support" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
typedef int (*im__fftproc_fn)( VipsImage *, VipsImage *, VipsImage * );
|
||||
|
||||
/* Transform an n-band image with a 1-band processing function.
|
||||
*
|
||||
* Memory strategy: we need memory buffers for the input and the output of
|
||||
* fftw. In some modes fftw generates only half the output and we construct
|
||||
* the rest.
|
||||
*
|
||||
* input pipeline ->
|
||||
* bandsplit ->
|
||||
* full memory image, freed when im_*fft*() exits ->
|
||||
* fftw ->
|
||||
* half memory image, freed when im_*fft*() exits ->
|
||||
* full memory image, freed when @out is freed ->
|
||||
* partial bandjoin ->
|
||||
* output pipeline
|
||||
*
|
||||
* im__fftproc() needs to just call im__fftproc_fn directly for 1 band images,
|
||||
* so we can't cache the output in this fn.
|
||||
*/
|
||||
int
|
||||
im__fftproc( IMAGE *dummy, IMAGE *in, IMAGE *out, im__fftproc_fn fn )
|
||||
{
|
||||
IMAGE **bands;
|
||||
IMAGE **fft;
|
||||
int b;
|
||||
|
||||
if( in->Bands == 1 )
|
||||
return( fn( dummy, in, out ) );
|
||||
|
||||
if( !(bands = IM_ARRAY( dummy, in->Bands, IMAGE * )) ||
|
||||
im_open_local_array( dummy, bands, in->Bands, "bands", "p" ) )
|
||||
return( -1 );
|
||||
|
||||
if( !(fft = IM_ARRAY( out, in->Bands, IMAGE * )) ||
|
||||
im_open_local_array( out, fft, in->Bands, "fft", "p" ) )
|
||||
return( -1 );
|
||||
|
||||
for( b = 0; b < in->Bands; b++ )
|
||||
if( im_extract_band( in, bands[b], b ) ||
|
||||
fn( dummy, bands[b], fft[b] ) )
|
||||
return( -1 );
|
||||
|
||||
if( im_gbandjoin( fft, out, in->Bands ) )
|
||||
return( -1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* im_fwfft:
|
||||
* @in: input image
|
||||
* @out: output image
|
||||
*
|
||||
* Transform an image to Fourier space.
|
||||
*
|
||||
* VIPS uses the fftw Fourier Transform library. If this library was not
|
||||
* available when VIPS was configured, these functions will fail.
|
||||
*
|
||||
* See also: im_invfft(), im_disp_ps().
|
||||
*
|
||||
* Returns: 0 on success, -1 on error.
|
||||
*/
|
||||
int
|
||||
im_fwfft( IMAGE *in, IMAGE *out )
|
||||
{
|
||||
IMAGE *dummy;
|
||||
|
||||
if( !(dummy = im_open( "im_fwfft:1", "p" )) )
|
||||
return( -1 );
|
||||
if( im__fftproc( dummy, in, out, fwfft1 ) ) {
|
||||
im_close( dummy );
|
||||
return( -1 );
|
||||
}
|
||||
im_close( dummy );
|
||||
|
||||
return( 0 );
|
||||
}
|
|
@ -1,168 +0,0 @@
|
|||
/* im_invfft
|
||||
*
|
||||
* Copyright: 1990, N. Dessipris.
|
||||
*
|
||||
* Author: Nicos Dessipris
|
||||
* Written on: 12/04/1990
|
||||
* Modified on :
|
||||
* 28/6/95 JC
|
||||
* - rewritten, based on new im_fwfft() code
|
||||
* 10/9/98 JC
|
||||
* - frees memory more quickly
|
||||
* 2/4/02 JC
|
||||
* - fftw code added
|
||||
* 13/7/02 JC
|
||||
* - Type reset
|
||||
* 27/2/03 JC
|
||||
* - tiny speed-up ... save 1 copy on write
|
||||
* 22/1/04 JC
|
||||
* - oops, fix for segv on wider than high fftw transforms
|
||||
* 3/11/04
|
||||
* - added fftw3 support
|
||||
* 7/2/10
|
||||
* - gtkdoc
|
||||
* 27/1/12
|
||||
* - better setting of interpretation
|
||||
* - remove own fft fallback code
|
||||
* - remove fftw2 path
|
||||
* - reduce memuse
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
This file is part of VIPS.
|
||||
|
||||
VIPS is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
||||
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
#include <vips/intl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef HAVE_FFTW
|
||||
#include <fftw3.h>
|
||||
#endif /*HAVE_FFTW*/
|
||||
|
||||
#include <vips/vips.h>
|
||||
#include <vips/internal.h>
|
||||
|
||||
#ifdef HAVE_FFTW
|
||||
|
||||
/* Complex to complex inverse transform.
|
||||
*/
|
||||
static int
|
||||
invfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
|
||||
{
|
||||
fftw_plan plan;
|
||||
IMAGE *cmplx;
|
||||
double *planner_scratch;
|
||||
|
||||
if( vips_check_mono( "im_invfft", in ) ||
|
||||
vips_check_uncoded( "im_invfft", in ) )
|
||||
return( -1 );
|
||||
|
||||
/* Double-complex input.
|
||||
*/
|
||||
if( !(cmplx = im_open_local( dummy, "invfft:1", "t" )) ||
|
||||
im_clip2fmt( in, cmplx, IM_BANDFMT_DPCOMPLEX ) )
|
||||
return( -1 );
|
||||
|
||||
/* Make the plan for the transform. Yes, they really do use nx for
|
||||
* height and ny for width.
|
||||
*/
|
||||
if( !(planner_scratch = IM_ARRAY( dummy,
|
||||
VIPS_IMAGE_N_PELS( in ) * 2, double )) )
|
||||
return( -1 );
|
||||
if( !(plan = fftw_plan_dft_2d( in->Ysize, in->Xsize,
|
||||
(fftw_complex *) planner_scratch,
|
||||
(fftw_complex *) planner_scratch,
|
||||
FFTW_BACKWARD,
|
||||
0 )) ) {
|
||||
im_error( "im_invfft",
|
||||
"%s", _( "unable to create transform plan" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if( im_incheck( cmplx ) )
|
||||
return( -1 );
|
||||
fftw_execute_dft( plan,
|
||||
(fftw_complex *) cmplx->data, (fftw_complex *) cmplx->data );
|
||||
|
||||
fftw_destroy_plan( plan );
|
||||
|
||||
cmplx->Type = IM_TYPE_B_W;
|
||||
|
||||
if( im_copy( cmplx, out ) )
|
||||
return( -1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static int
|
||||
invfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
|
||||
{
|
||||
im_error( "im_invfft",
|
||||
"%s", _( "vips configured without FFT support" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* im_invfft:
|
||||
* @in: input image
|
||||
* @out: output image
|
||||
*
|
||||
* Transform an image from Fourier space to real space. The result is complex.
|
||||
* If you are OK with a real result, use im_invfftr() instead, it's quicker.
|
||||
*
|
||||
* VIPS uses the fftw3 or fftw2 Fourier transform libraries if possible. If
|
||||
* they were not available when VIPS was built, it falls back to it's own
|
||||
* FFT functions which are slow and only work for square images whose sides
|
||||
* are a power of two.
|
||||
*
|
||||
* See also: im_invfftr(), im_fwfft(), im_disp_ps().
|
||||
*
|
||||
* Returns: 0 on success, -1 on error.
|
||||
*/
|
||||
int
|
||||
im_invfft( IMAGE *in, IMAGE *out )
|
||||
{
|
||||
IMAGE *dummy = im_open( "im_invfft:1", "p" );
|
||||
|
||||
if( !dummy )
|
||||
return( -1 );
|
||||
if( im__fftproc( dummy, in, out, invfft1 ) ) {
|
||||
im_close( dummy );
|
||||
return( -1 );
|
||||
}
|
||||
im_close( dummy );
|
||||
|
||||
return( 0 );
|
||||
}
|
|
@ -1,183 +0,0 @@
|
|||
/* im_invfftr
|
||||
*
|
||||
* Modified on :
|
||||
* 27/2/03 JC
|
||||
* - from im_invfft.c
|
||||
* 22/1/04 JC
|
||||
* - oops, fix for segv on wider than high fftw transforms
|
||||
* 3/11/04
|
||||
* - added fftw3 support
|
||||
* 7/2/10
|
||||
* - gtkdoc
|
||||
* 27/1/12
|
||||
* - better setting of interpretation
|
||||
* - remove own fft fallback code
|
||||
* - remove fftw2 path
|
||||
* - reduce memuse
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
This file is part of VIPS.
|
||||
|
||||
VIPS is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
||||
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
#include <vips/intl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef HAVE_FFTW
|
||||
#include <fftw3.h>
|
||||
#endif /*HAVE_FFTW*/
|
||||
|
||||
#include <vips/vips.h>
|
||||
#include <vips/internal.h>
|
||||
|
||||
#ifdef HAVE_FFTW
|
||||
|
||||
/* Complex to real inverse transform.
|
||||
*/
|
||||
static int
|
||||
invfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
|
||||
{
|
||||
const int half_width = in->Xsize / 2 + 1;
|
||||
|
||||
IMAGE *cmplx;
|
||||
double *half_complex;
|
||||
IMAGE *real;
|
||||
double *planner_scratch;
|
||||
fftw_plan plan;
|
||||
int x, y;
|
||||
double *q, *p;
|
||||
|
||||
/* Double-complex input.
|
||||
*/
|
||||
if( !(cmplx = im_open_local( dummy, "invfft:1", "t" )) ||
|
||||
im_clip2fmt( in, cmplx, IM_BANDFMT_DPCOMPLEX ) )
|
||||
return( -1 );
|
||||
|
||||
/* Build half-complex image.
|
||||
*/
|
||||
if( !(half_complex = IM_ARRAY( dummy,
|
||||
in->Ysize * half_width * 2, double )) )
|
||||
return( -1 );
|
||||
if( im_incheck( cmplx ) )
|
||||
return( -1 );
|
||||
q = half_complex;
|
||||
for( y = 0; y < cmplx->Ysize; y++ ) {
|
||||
p = ((double *) cmplx->data) + (guint64) y * in->Xsize * 2;
|
||||
|
||||
for( x = 0; x < half_width; x++ ) {
|
||||
q[0] = p[0];
|
||||
q[1] = p[1];
|
||||
p += 2;
|
||||
q += 2;
|
||||
}
|
||||
}
|
||||
|
||||
/* Make mem buffer real image for output.
|
||||
*/
|
||||
if( !(real = im_open_local( out, "invfft1-2", "t" )) )
|
||||
return( -1 );
|
||||
if( im_cp_desc( real, in ) )
|
||||
return( -1 );
|
||||
real->BandFmt = IM_BANDFMT_DOUBLE;
|
||||
real->Type = IM_TYPE_B_W;
|
||||
if( im_setupout( real ) ||
|
||||
im_outcheck( real ) )
|
||||
return( -1 );
|
||||
|
||||
/* Make the plan for the transform. Yes, they really do use nx for
|
||||
* height and ny for width.
|
||||
*/
|
||||
if( !(planner_scratch = IM_ARRAY( dummy,
|
||||
in->Ysize * half_width * 2, double )) )
|
||||
return( -1 );
|
||||
if( !(plan = fftw_plan_dft_c2r_2d( in->Ysize, in->Xsize,
|
||||
(fftw_complex *) planner_scratch, (double *) real->data,
|
||||
0 )) ) {
|
||||
im_error( "im_invfft",
|
||||
"%s", _( "unable to create transform plan" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
fftw_execute_dft_c2r( plan,
|
||||
(fftw_complex *) half_complex, (double *) real->data );
|
||||
|
||||
fftw_destroy_plan( plan );
|
||||
|
||||
if( im_copy( real, out ) )
|
||||
return( -1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static int
|
||||
invfft1( IMAGE *dummy, IMAGE *in, IMAGE *out )
|
||||
{
|
||||
im_error( "im_invfftr",
|
||||
"%s", _( "vips configured without FFT support" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* im_invfftr:
|
||||
* @in: input image
|
||||
* @out: output image
|
||||
*
|
||||
* Transform an image from Fourier space to real space, giving a real result.
|
||||
* This is faster than im_invfft(), which gives a complex result.
|
||||
*
|
||||
* VIPS uses the fftw3 or fftw2 Fourier transform libraries if possible. If
|
||||
* they were not available when VIPS was built, it falls back to it's own
|
||||
* FFT functions which are slow and only work for square images whose sides
|
||||
* are a power of two.
|
||||
*
|
||||
* See also: im_invfft(), im_fwfft(), im_disp_ps().
|
||||
*
|
||||
* Returns: 0 on success, -1 on error.
|
||||
*/
|
||||
int
|
||||
im_invfftr( IMAGE *in, IMAGE *out )
|
||||
{
|
||||
IMAGE *dummy = im_open( "im_invfft:1", "p" );
|
||||
|
||||
if( !dummy )
|
||||
return( -1 );
|
||||
if( im__fftproc( dummy, in, out, invfft1 ) ) {
|
||||
im_close( dummy );
|
||||
return( -1 );
|
||||
}
|
||||
im_close( dummy );
|
||||
|
||||
return( 0 );
|
||||
}
|
|
@ -43,10 +43,6 @@ int vips_fwfft( VipsImage *in, VipsImage **out, ... )
|
|||
int vips_invfft( VipsImage *in, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
|
||||
int im_fwfft( VipsImage *in, VipsImage *out );
|
||||
int im_invfft( VipsImage *in, VipsImage *out );
|
||||
int im_invfftr( VipsImage *in, VipsImage *out );
|
||||
|
||||
int im_freqflt( VipsImage *in, VipsImage *mask, VipsImage *out );
|
||||
int im_disp_ps( VipsImage *in, VipsImage *out );
|
||||
int im_phasecor_fft( VipsImage *in1, VipsImage *in2, VipsImage *out );
|
||||
|
|
|
@ -966,6 +966,10 @@ int im_flt_image_freq( VipsImage *in, VipsImage *out, ImMaskType flag, ... );
|
|||
int im_create_fmask( VipsImage *out,
|
||||
int xsize, int ysize, ImMaskType flag, ... );
|
||||
|
||||
int im_fwfft( VipsImage *in, VipsImage *out );
|
||||
int im_invfft( VipsImage *in, VipsImage *out );
|
||||
int im_invfftr( VipsImage *in, VipsImage *out );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus*/
|
||||
|
|
Loading…
Reference in New Issue