28 int Width,
int Height,
int NumChannels)
30 const int InPlace = (Dest == Src);
31 const int PadWidth = 2*Width;
32 const long ChannelJump = ((long)PadWidth) * ((long)Height);
33 const int SrcStride = (InPlace) ? PadWidth : Width;
36 for(k = 0; k < NumChannels; k++)
38 for(y = 0; y < Height; y++, Dest += PadWidth, Src += SrcStride)
41 memcpy(Dest, Src,
sizeof(num) * Width);
43 for(x = 0; x < Width; x++)
44 Dest[Width + x] = Dest[Width - 1 - x];
46 memcpy(Dest + ((
long)(2*(Height - y) - 1)) * PadWidth,
47 Dest,
sizeof(num) * PadWidth);
60 const numcomplex *KernelTrans,
const num *ztilde,
61 int Width,
int Height,
int NumChannels, num Alpha)
63 const int PadWidth = 2*Width;
64 const int PadHeight = 2*Height;
65 const int TransWidth = PadWidth/2 + 1;
66 const long TransNumPixels = ((long)TransWidth) * ((long)PadHeight);
74 FFT(execute)(TransformA);
77 for(k = 0; k < NumChannels; k++, ATrans += TransNumPixels)
78 for(i = 0; i < TransNumPixels; i++)
80 num Temp = Alpha*(KernelTrans[i][0] * ATrans[i][1]
81 - KernelTrans[i][1] * ATrans[i][0]);
82 ATrans[i][0] = Alpha*(KernelTrans[i][0] * ATrans[i][0]
83 + KernelTrans[i][1] * ATrans[i][1]);
100 num *DenomTrans = S->DenomTrans;
101 const num *Kernel = S->
Opt.Kernel;
102 const int KernelWidth = S->
Opt.KernelWidth;
103 const int KernelHeight = S->
Opt.KernelHeight;
106 const num Alpha = S->
Alpha;
107 const long PadNumPixels = ((
long)PadWidth) * ((
long)PadHeight);
108 const int TransWidth = PadWidth/2 + 1;
109 FFT(plan) Plan = NULL;
111 int PadSize[2], x0, y0, x, y, xi, yi;
113 for(i = 0; i < PadNumPixels; i++)
117 y0 = -KernelHeight/2;
121 for(y = y0, i = 0; y < y0 + KernelHeight; y++)
125 for(x = x0; x < x0 + KernelWidth; x++, i++)
128 B[xi + PadWidth*yi] += Kernel[i];
133 if(!(Plan = FFT(plan_dft_r2c_2d)(PadHeight, PadWidth, B,
134 KernelTrans, FFTW_ESTIMATE | FFTW_DESTROY_INPUT)))
138 FFT(destroy_plan)(Plan);
141 for(y = 0, i = 0; y < PadHeight; y++)
142 for(x = 0; x < TransWidth; x++, i++)
144 (num)(PadNumPixels*(Alpha*(KernelTrans[i][0]*KernelTrans[i][0]
145 + KernelTrans[i][1]*KernelTrans[i][1])
146 + 2*(2 - cos(x*
M_2PI/PadWidth) - cos(y*
M_2PI/PadHeight))));
149 PadSize[1] = PadWidth;
150 PadSize[0] = PadHeight;
152 if(!(S->TransformA = FFT(plan_many_dft_r2c)(2, PadSize, S->
NumChannels,
153 S->A, NULL, 1, PadNumPixels, ATrans, NULL, 1,
154 TransWidth*PadHeight, FFTW_ESTIMATE | FFTW_DESTROY_INPUT))
155 || !(S->InvTransformA = FFT(plan_many_dft_c2r)(2, PadSize,
156 S->
NumChannels, ATrans, NULL, 1, TransWidth*PadHeight, S->A,
157 NULL, 1, PadNumPixels, FFTW_ESTIMATE | FFTW_DESTROY_INPUT))
158 || !(S->TransformB = FFT(plan_many_dft_r2c)(2, PadSize,
159 S->
NumChannels, S->B, NULL, 1, PadNumPixels, BTrans, NULL, 1,
160 TransWidth*PadHeight, FFTW_ESTIMATE | FFTW_DESTROY_INPUT))
161 || !(S->InvTransformB = FFT(plan_many_dft_c2r)(2, PadSize,
162 S->
NumChannels, BTrans, NULL, 1, TransWidth*PadHeight, S->B,
163 NULL, 1, PadNumPixels, FFTW_ESTIMATE | FFTW_DESTROY_INPUT)))
185 const num *DenomTrans,
int Width,
int Height,
int NumChannels)
187 const long PadWidth = 2*Width;
188 const long PadHeight = 2*Height;
189 const long TransWidth = PadWidth/2 + 1;
190 const long TransNumPixels = TransWidth * PadHeight;
195 Divergence(B, PadWidth, PadHeight, dtilde, Width, Height, NumChannels);
199 FFT(execute)(TransformB);
202 for(k = 0; k < NumChannels; k++,
203 ATrans += TransNumPixels, BTrans += TransNumPixels)
204 for(i = 0; i < TransNumPixels; i++)
206 BTrans[i][0] = (ATrans[i][0] - BTrans[i][0]) / DenomTrans[i];
207 BTrans[i][1] = (ATrans[i][1] - BTrans[i][1]) / DenomTrans[i];
234 FFT(execute)(S->InvTransformB);
240 #if defined(TVREG_USEZ) || defined(DOXYGEN)
254 const int TransWidth = S->
PadWidth/2 + 1;
255 const long TransNumPixels = ((
long)TransWidth) * ((
long)S->
PadHeight);
260 AdjBlurFourier(ATrans, S->A, S->TransformA, KernelTrans, S->ztilde,
264 ATrans, S->
dtilde, S->DenomTrans,
269 ATrans += TransNumPixels, BTrans += TransNumPixels)
270 for(i = 0; i < TransNumPixels; i++)
272 ATrans[i][0] = KernelTrans[i][0] * BTrans[i][0]
273 - KernelTrans[i][1] * BTrans[i][1];
274 ATrans[i][1] = KernelTrans[i][0] * BTrans[i][1]
275 + KernelTrans[i][1] * BTrans[i][0];
279 FFT(execute)(S->InvTransformA);
281 FFT(execute)(S->InvTransformB);