public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length) { if (needReRender == false || length == 0) { return; } needReRender = false; PdnRegion selection = EnvironmentParameters.GetSelectionAsPdnRegion(); using (Surface tmp = new Surface(srcArgs.Size)) { tmp.CopySurface(srcArgs.Surface); Effect effect = null; EffectConfigToken token = null; int count = this.effects.Count; for (int i = 0; i < count; i++) { effect = this.effects[i]; token = this.dialogs[i]?.EffectToken; effect.SetRenderInfo(token, dstArgs, new RenderArgs(tmp)); effect.Render(token, dstArgs, new RenderArgs(tmp), selection); tmp.CopySurface(dstArgs.Surface); } dstArgs.Surface.CopySurface(tmp); } }
private void ConfigDialog_Load(object sender, EventArgs e) { this.BackColor = SystemColors.Control; this.Text = GridWarp.StaticDialogName; this.DesktopLocation = Owner.PointToScreen(new Point(0, 30)); this.Size = new Size(Owner.ClientSize.Width, Owner.ClientSize.Height - 30); this.WindowState = Owner.WindowState; surface = new Surface(EnvironmentParameters.SourceSurface.Size); mesh = new DisplacementMesh(surface.Size); canvas.Surface = surface; canvas.Selection = EnvironmentParameters.GetSelectionAsPdnRegion(); mesh.Render(surface, EnvironmentParameters.SourceSurface, EnvironmentParameters.SourceSurface.Bounds); }
/// <summary> /// Renders the effect over rectangular regions automatically /// determined and handled by Paint.NET for multithreading support. /// </summary> /// <param name="parameters"> /// Saved settings used to restore the GUI to the same settings it was /// saved with last time the effect was applied. /// </param> /// <param name="dstArgs">The destination canvas.</param> /// <param name="srcArgs">The source canvas.</param> /// <param name="rois"> /// A list of rectangular regions to split this effect into so it can /// be optimized by worker threads. Determined and managed by /// Paint.NET. /// </param> /// <param name="startIndex"> /// The rectangle to begin rendering with. Used in Paint.NET's effect /// multithreading process. /// </param> /// <param name="length"> /// The number of rectangles to render at once. Used in Paint.NET's /// effect multithreading process. /// </param> public override void Render( EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length) { //Renders the effect if the dialog is closed and accepted. if (!RenderSettings.EffectApplied && RenderSettings.DoApplyEffect && !IsCancelRequested) { //The effect should only render once. RenderSettings.EffectApplied = true; dstArgs.Surface.CopySurface( RenderSettings.SurfaceToRender, EnvironmentParameters.GetSelectionAsPdnRegion()); } }
protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs) { scale = newToken.GetProperty <Int32Property>(PropertyNames.Scale).Value; roughness = newToken.GetProperty <DoubleProperty>(PropertyNames.Roughness).Value; minOpacity = newToken.GetProperty <Int32Property>(PropertyNames.MinimumOpacity).Value; reseed = (byte)newToken.GetProperty <Int32Property>(PropertyNames.Reseed).Value; customColor = newToken.GetProperty <BooleanProperty>(PropertyNames.UseCustomColor).Value; color = ColorBgra.FromOpaqueInt32(newToken.GetProperty <Int32Property>(PropertyNames.Color).Value); if (emptySurface == null) { emptySurface = new Surface(srcArgs.Size); } if (cloudSurface == null) { cloudSurface = new Surface(srcArgs.Size); } // Call the Render Clouds function cloudsProps = cloudsEffect.CreatePropertyCollection(); PropertyBasedEffectConfigToken CloudsParameters = new PropertyBasedEffectConfigToken(cloudsProps); CloudsParameters.SetPropertyValue(CloudsEffect.PropertyNames.Scale, scale); CloudsParameters.SetPropertyValue(CloudsEffect.PropertyNames.Power, roughness); CloudsParameters.SetPropertyValue(CloudsEffect.PropertyNames.Seed, reseed); using (EffectEnvironmentParameters environParameters = new EffectEnvironmentParameters(ColorBgra.Black, Color.FromArgb(minOpacity, Color.Black), 0, EnvironmentParameters.GetSelectionAsPdnRegion(), emptySurface)) cloudsEffect.EnvironmentParameters = environParameters; cloudsEffect.SetRenderInfo(CloudsParameters, new RenderArgs(cloudSurface), new RenderArgs(emptySurface)); base.OnSetRenderInfo(newToken, dstArgs, srcArgs); }
public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length) { ConfigToken token = (ConfigToken)parameters; PdnRegion selection = EnvironmentParameters.GetSelectionAsPdnRegion(); if (changed) { changed = false; if (dialog != null) { dialog.SetProgressBarMaximum(token.effects.Count, tilesPerCpu * renderingThreadCount); dialog.EnableOKButton(false); } using (Surface scratch = new Surface(srcArgs.Size)) { scratch.CopySurface(srcArgs.Surface); for (int i = 0; i < token.effects.Count; ++i) { ScriptStep step = token.effects[i]; Type type = step.EffectType; if (type == null) { if (dialog != null) { dialog.IncrementProgressBarValue(i, 1); } } else { Effect effect = (Effect)(type.GetConstructor(Type.EmptyTypes).Invoke(new object[0])); effect.Services = Services; effect.EnvironmentParameters = new EffectEnvironmentParameters( step.PrimaryColor, step.SecondaryColor, EnvironmentParameters.BrushWidth, selection, EnvironmentParameters.SourceSurface); BackgroundEffectRenderer ber = new BackgroundEffectRenderer(effect, step.Token, dstArgs, new RenderArgs(scratch), selection, null, tilesPerCpu * renderingThreadCount, renderingThreadCount); ber.RenderedTile += (sender, e) => RenderedTile((BackgroundEffectRenderer)sender, i, e.TileCount); ber.Start(); ber.Join(); scratch.CopySurface(dstArgs.Surface); } if (IsCancelRequested) { return; } } if (dialog != null) { dialog.ClearProgressBars(); dialog.EnableOKButton(true); } } } }