public override void ProcessPixels(RectangleI region) { ComplexGrid gridDirect = new ComplexGrid(ImageBounds, ProjectionBounds, fDir); ComplexGrid gridInverse = new ComplexGrid(ImageBounds, ProjectionBounds, fInv); Parallel.For(region.TopLeft.Y, region.BottomRight.Y, y => { Parallel.For(region.TopLeft.X, region.BottomRight.X, x => { var pDir = (PointI)lerpPoint(new PointD(x, y), gridDirect[x, y], Alpha); var pInv = (PointI)lerpPoint(new PointD(x, y), gridInverse[x, y], Alpha); SKColor color; if (IsPointInRange(pDir, ImageBounds)) { color = SourceImage.GetPixel(pDir.X, pDir.Y); } else if (IsPointInRange(pInv, ImageBounds)) { color = SourceImage.GetPixel(pInv.X, pInv.Y); } else { color = SKColor.Empty; } DestImage.SetPixel(x, y, color); }); }); }
public override void PostProcess() { SKBitmap rendered = Device.Present(); for (int y = 0; y < DestImage.Height; y++) { for (int x = 0; x < DestImage.Width; x++) { SKColor pixel = rendered.GetPixel(x, DestImage.Height - (y + 1)); DestImage.SetPixel(x, y, pixel); } } Mesh = null; }
public override void ProcessPixels(RectangleI region) { Api api = new Api( image: new Image(SourceImage), param: new ScriptParams( PrimaryParam, SecondaryParam, (Pixel)ColorParam ) ); Parallel.For(region.TopLeft.Y, region.BottomRight.Y, (y, outer) => { if (EncounteredError) { outer.Break(); return; } Parallel.For(region.TopLeft.X, region.BottomRight.X, (x, inner) => { if (EncounteredError) { inner.Break(); return; } try { SKColor src = SourceImage.GetPixel(x, y); Pixel colorIn = new Pixel(src.Blue, src.Green, src.Red, src.Alpha); Pixel colorOut = FilterFunc(api, colorIn, x, y); SKColor dst = new SKColor(colorOut.Blue, colorOut.Green, colorOut.Red, colorOut.Alpha); DestImage.SetPixel(x, y, dst); } catch (Exception e) { if (!EncounteredError) { EncounteredError = true; MessageBox.Show($"Your code encountered an exception at runtime.\n{e.Message}", "Runtime Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }); }); }