private void RenderOutputBackwards(Surface dst, Rectangle[] rects, RectInt32 bounds) { var center = new PointInt32(bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2); double maxValue = 0; object _lock = new object(); if (this.IsCancelRequested) { return; } Parallel.For(0, rects.Length, (i, loopStateI) => { if (this.IsCancelRequested) { loopStateI.Stop(); return; } Rectangle rect = rects[i]; Parallel.For(rect.Top, rect.Bottom, (y, loopStateY) => { if (this.IsCancelRequested) { loopStateY.Stop(); return; } double mVal = 0; for (int x = rect.Left; x < rect.Right; x++) { Complex val = this._fftPlanBackwards.GetOutput(x - bounds.Left, y - bounds.Top); mVal = Math.Max(mVal, val.Magnitude); } lock (_lock) { maxValue = Math.Max(maxValue, mVal); } }); }); double factor = 1.0 / maxValue; Func <double, ColorBgra> getColor = this._valueSource.GetGetColorFunc(); if (this.IsCancelRequested) { return; } Parallel.For(0, rects.Length, (i, loopStateI) => { if (this.IsCancelRequested) { loopStateI.Stop(); return; } Rectangle rect = rects[i]; Parallel.For(rect.Top, rect.Bottom, (y, loopStateY) => { if (this.IsCancelRequested) { loopStateY.Stop(); return; } for (int x = rect.Left; x < rect.Right; x++) { Complex val = this._fftPlanBackwards.GetOutput(x - bounds.Left, y - bounds.Top); ColorBgra color = getColor(val.Magnitude * factor); dst[x, y] = ColorBgra.FromColor(color); } }); }); }
private void RenderOutputForwards(Surface dst, Rectangle[] rects, RectInt32 bounds) { var center = new PointInt32(bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2); double maxValue = 0; object _lock = new object(); if (this.IsCancelRequested) { return; } Parallel.For(0, rects.Length, (i, loopStateI) => { if (this.IsCancelRequested) { loopStateI.Stop(); return; } Rectangle rect = rects[i]; Parallel.For(rect.Top, rect.Bottom, (y, loopStateY) => { if (this.IsCancelRequested) { loopStateY.Stop(); return; } double mVal = 0; for (int x = rect.Left; x < rect.Right; x++) { Complex val = this._fftPlanForwards.GetOutput(x - bounds.Left, y - bounds.Top); mVal = Math.Max(mVal, val.Magnitude); } lock (_lock) { maxValue = Math.Max(maxValue, mVal); } }); }); double factor = GetFactor(maxValue); if (this.IsCancelRequested) { return; } Parallel.For(0, rects.Length, (i, loopStateI) => { if (this.IsCancelRequested) { loopStateI.Stop(); return; } Rectangle rect = rects[i]; Parallel.For(rect.Top, rect.Bottom, (y, loopStateY) => { if (this.IsCancelRequested) { loopStateY.Stop(); return; } for (int x = rect.Left; x < rect.Right; x++) { int fftx = x - center.X; if (fftx < 0) { fftx += bounds.Width; } int ffty = y - center.Y; if (ffty < 0) { ffty += bounds.Height; } Complex val = this._fftPlanForwards.GetOutput(fftx, ffty); dst[x, y] = ComplexToColor(val, factor); } }); }); }