52 const int Width = S->
Width;
53 const int Height = S->
Height;
55 const num Thresh = 1/S->
Opt.Gamma1;
56 const num ThreshSquared = Thresh * Thresh;
57 const long ChannelStride = ((long)Width) * ((long)Height);
58 const long NumEl = NumChannels * ChannelStride;
64 for(y = 0; y < Height - 1; y++, d++, dtilde++, u++)
67 for(x = 0; x < Width - 1; x++, d++, dtilde++, u++)
69 for(i = 0, Magnitude = 0; i < NumEl; i += ChannelStride)
71 d[i].
x += (u[i + 1] - u[i]) - dtilde[i].x;
72 d[i].y += (u[i + Width] - u[i]) - dtilde[i].y;
73 Magnitude += d[i].x*d[i].x + d[i].y*d[i].y;
76 if(Magnitude > ThreshSquared)
78 Magnitude = 1 - Thresh/(num)sqrt(Magnitude);
80 for(i = 0; i < NumEl; i += ChannelStride)
82 dnew.
x = Magnitude*d[i].x;
83 dnew.
y = Magnitude*d[i].y;
84 dtilde[i].x = 2*dnew.
x - d[i].x;
85 dtilde[i].y = 2*dnew.
y - d[i].y;
90 for(i = 0; i < NumEl; i += ChannelStride)
92 dtilde[i].
x = -d[i].x;
93 dtilde[i].y = -d[i].y;
100 for(i = 0, Magnitude = 0; i < NumEl; i += ChannelStride)
102 d[i].y += (u[i + Width] - u[i]) - dtilde[i].y;
103 Magnitude += d[i].y*d[i].y;
104 d[i].x = dtilde[i].x = 0;
107 if(Magnitude > ThreshSquared)
109 Magnitude = 1 - Thresh/(num)sqrt(Magnitude);
111 for(i = 0; i < NumEl; i += ChannelStride)
113 dnew.
y = Magnitude*d[i].y;
114 dtilde[i].y = 2*dnew.
y - d[i].y;
119 for(i = 0; i < NumEl; i += ChannelStride)
121 dtilde[i].y = -d[i].y;
127 for(x = 0; x < Width - 1; x++, d++, dtilde++, u++)
129 for(i = 0, Magnitude = 0; i < NumEl; i += ChannelStride)
131 d[i].x += (u[i + 1] - u[i]) - dtilde[i].x;
132 Magnitude += d[i].x*d[i].x;
133 d[i].y = dtilde[i].y = 0;
136 if(Magnitude > ThreshSquared)
138 Magnitude = 1 - Thresh/(num)sqrt(Magnitude);
140 for(i = 0; i < NumEl; i += ChannelStride)
142 dnew.
x = Magnitude*d[i].x;
143 dtilde[i].x = 2*dnew.
x - d[i].x;
148 for(i = 0; i < NumEl; i += ChannelStride)
150 dtilde[i].x = -d[i].x;
156 for(i = 0; i < NumEl; i += ChannelStride)
157 d[i].x = d[i].y = dtilde[i].x = dtilde[i].y = 0;