/usr/include/vigra/rfftw.hxx is in libvigraimpex-dev 1.10.0+git20160211.167be93+dfsg-5ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | /************************************************************************/
/* */
/* Copyright 1998-2002 by Ullrich Koethe */
/* */
/* This file is part of the VIGRA computer vision library. */
/* The VIGRA Website is */
/* http://hci.iwr.uni-heidelberg.de/vigra/ */
/* Please direct questions, bug reports, and contributions to */
/* ullrich.koethe@iwr.uni-heidelberg.de or */
/* vigra@informatik.uni-hamburg.de */
/* */
/* Permission is hereby granted, free of charge, to any person */
/* obtaining a copy of this software and associated documentation */
/* files (the "Software"), to deal in the Software without */
/* restriction, including without limitation the rights to use, */
/* copy, modify, merge, publish, distribute, sublicense, and/or */
/* sell copies of the Software, and to permit persons to whom the */
/* Software is furnished to do so, subject to the following */
/* conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the */
/* Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
/* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
/* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
/* OTHER DEALINGS IN THE SOFTWARE. */
/* */
/************************************************************************/
#ifndef VIGRA_RFFTW_HXX
#define VIGRA_RFFTW_HXX
#include "array_vector.hxx"
#include "fftw.hxx"
#include <rfftw.h>
namespace vigra {
namespace detail {
struct FFTWSinCosConfig
{
ArrayVector<fftw_real> twiddles;
ArrayVector<fftw_real> fftwInput;
ArrayVector<fftw_complex> fftwTmpResult;
fftw_real norm;
rfftwnd_plan fftwPlan;
};
template <class SrcIterator, class SrcAccessor,
class DestIterator, class DestAccessor,
class Config>
void
cosineTransformLineImpl(SrcIterator s, SrcIterator send, SrcAccessor src,
DestIterator d, DestAccessor dest,
Config & config)
{
int size = send - s;
int ns2 = size / 2;
int nm1 = size - 1;
int modn = size % 2;
if(size <= 0)
return;
fftw_real const * twiddles = config.twiddles.begin();
fftw_real * fftwInput = config.fftwInput.begin();
fftw_complex * fftwTmpResult = config.fftwTmpResult.begin();
fftw_real norm = config.norm;
rfftwnd_plan fftwPlan = config.fftwPlan;
switch(size)
{
case 1:
{
dest.set(src(s) / norm, d);
break;
}
case 2:
{
dest.set((src(s) + src(s, 1)) / norm, d);
dest.set((src(s) - src(s, 1)) / norm, d, 1);
break;
}
case 3:
{
fftw_real x1p3 = src(s) + src(s, 2);
fftw_real tx2 = 2.0 * src(s, 1);
dest.set((x1p3 + tx2) / norm, d, 0);
dest.set((src(s) - src(s, 2)) / norm, d, 1);
dest.set((x1p3 - tx2) / norm, d, 2);
break;
}
default:
{
fftw_real c1 = src(s) - src(s, nm1);
fftwInput[0] = src(s) + src(s, nm1);
for(int k=1; k<ns2; ++k)
{
int kc = nm1 - k;
fftw_real t1 = src(s, k) + src(s, kc);
fftw_real t2 = src(s, k) - src(s, kc);
c1 = c1 + twiddles[kc] * t2;
t2 = twiddles[k] * t2;
fftwInput[k] = t1 - t2;
fftwInput[kc] = t1 + t2;
}
if (modn != 0)
{
fftwInput[ns2] = 2.0*src(s, ns2);
}
rfftwnd_one_real_to_complex(fftwPlan, fftwInput, fftwTmpResult);
dest.set(fftwTmpResult[0].re / norm, d, 0);
for(int k=1; k<(size+1)/2; ++k)
{
dest.set(fftwTmpResult[k].re, d, 2*k-1);
dest.set(fftwTmpResult[k].im, d, 2*k);
}
fftw_real xim2 = dest(d, 1);
dest.set(c1 / norm, d, 1);
for(int k=3; k<size; k+=2)
{
fftw_real xi = dest(d, k);
dest.set(dest(d, k-2) - dest(d, k-1) / norm, d, k);
dest.set(xim2 / norm, d, k-1);
xim2 = xi;
}
if (modn != 0)
{
dest.set(xim2 / norm, d, size-1);
}
}
}
}
} // namespace detail
template <class SrcTraverser, class SrcAccessor,
class DestTraverser, class DestAccessor>
void cosineTransformX(SrcTraverser sul, SrcTraverser slr, SrcAccessor src,
DestTraverser dul, DestAccessor dest, fftw_real norm)
{
int w = slr.x - sul.x;
int h = slr.y - sul.y;
detail::FFTWSinCosConfig config;
// horizontal transformation
int ns2 = w / 2;
int nm1 = w - 1;
int modn = w % 2;
config.twiddles.resize(w+1);
config.fftwInput.resize(w+1);
config.fftwTmpResult.resize(w+1);
config.norm = norm;
config.fftwPlan = rfftw2d_create_plan(1, nm1, FFTW_REAL_TO_COMPLEX, FFTW_ESTIMATE );
fftw_real dt = M_PI / nm1;
for(int k=1; k<ns2; ++k)
{
fftw_real f = dt * k;
config.twiddles[k] = 2.0*VIGRA_CSTD::sin(f);
config.twiddles[nm1-k] = 2.0*VIGRA_CSTD::cos(f);
}
for(; sul.y != slr.y; ++sul.y, ++dul.y)
{
typename SrcTraverser::row_iterator s = sul.rowIterator();
typename SrcTraverser::row_iterator send = s + w;
typename DestTraverser::row_iterator d = dul.rowIterator();
cosineTransformLineImpl(s, send, src, d, dest, config);
}
rfftwnd_destroy_plan(config.fftwPlan);
}
template <class SrcTraverser, class SrcAccessor,
class DestTraverser, class DestAccessor>
void cosineTransformY(SrcTraverser sul, SrcTraverser slr, SrcAccessor src,
DestTraverser dul, DestAccessor dest, fftw_real norm)
{
int w = slr.x - sul.x;
int h = slr.y - sul.y;
detail::FFTWSinCosConfig config;
// horizontal transformation
int ns2 = h / 2;
int nm1 = h - 1;
int modn = h % 2;
config.twiddles.resize(h + 1);
config.fftwInput.resize(h + 1);
config.fftwTmpResult.resize(h + 1);
config.norm = norm;
config.fftwPlan = rfftw2d_create_plan(1, nm1, FFTW_REAL_TO_COMPLEX, FFTW_ESTIMATE );
fftw_real dt = M_PI / nm1;
for(int k=1; k<ns2; ++k)
{
fftw_real f = dt * k;
config.twiddles[k] = 2.0*VIGRA_CSTD::sin(f);
config.twiddles[nm1-k] = 2.0*VIGRA_CSTD::cos(f);
}
for(; sul.x != slr.x; ++sul.x, ++dul.x)
{
typename SrcTraverser::column_iterator s = sul.columnIterator();
typename SrcTraverser::column_iterator send = s + h;
typename DestTraverser::column_iterator d = dul.columnIterator();
cosineTransformLineImpl(s, send, src, d, dest, config);
}
rfftwnd_destroy_plan(config.fftwPlan);
}
template <class SrcTraverser, class SrcAccessor,
class DestTraverser, class DestAccessor>
inline void
realFourierTransformXEvenYEven(SrcTraverser sul, SrcTraverser slr, SrcAccessor src,
DestTraverser dul, DestAccessor dest, fftw_real norm)
{
BasicImage<fftw_real> tmp(slr - sul);
cosineTransformX(sul, slr, src, tmp.upperLeft(), tmp.accessor(), 1.0);
cosineTransformY(tmp.upperLeft(), tmp.lowerRight(), tmp.accessor(), dul, dest, norm);
}
template <class SrcTraverser, class SrcAccessor,
class DestTraverser, class DestAccessor>
inline void
realFourierTransformXEvenYEven(triple<SrcTraverser, SrcTraverser, SrcAccessor> src,
pair<DestTraverser, DestAccessor> dest, fftw_real norm)
{
realFourierTransformXEvenYEven(src.first, src.second, src.third, dest.first, dest.second, norm);
}
} // namespace vigra
#endif // VIGRA_RFFTW_HXX
|