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); }
private void UpdateProperties(PropertyBasedEffectConfigToken newToken, WhiteBalanceMethod whiteBalanceMethod) { var whiteBalanceFunction = GetWhiteBalanceFunction(whiteBalanceMethod); if (whiteBalanceFunction == null) { return; } var(redGain, greenGain, blueGain) = whiteBalanceFunction(SrcArgs.Surface); (redGain, greenGain, blueGain) = Normalize(redGain, greenGain, blueGain); newToken.SetPropertyValue(PropertyNames.RedGain, redGain); newToken.SetPropertyValue(PropertyNames.GreenGain, greenGain); newToken.SetPropertyValue(PropertyNames.BlueGain, blueGain); // XXX : How to update controls with new values ? // This cannot be done with PropertyBasedEffect effects (The so called IndirectUI). // The solution is to inherit from Effect, and develop the Winform UI manually. (See ScribbleEffect source code) }
protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs) { margin = newToken.GetProperty <Int32Property>(PropertyNames.Margin).Value; spread = newToken.GetProperty <Int32Property>(PropertyNames.Spread).Value; blur = newToken.GetProperty <Int32Property>(PropertyNames.Blur).Value; color = ColorBgra.FromUInt32(unchecked ((uint)newToken.GetProperty <Int32Property>(PropertyNames.Color).Value)); offsetX = newToken.GetProperty <Int32Property>(PropertyNames.OffsetX).Value; offsetY = newToken.GetProperty <Int32Property>(PropertyNames.OffsetY).Value; if (shadowSurface == null) { shadowSurface = new Surface(srcArgs.Surface.Size); } else { shadowSurface.Clear(Color.Transparent); } // Setup for calling the Gaussian Blur effect PropertyCollection blurProps = blurEffect.CreatePropertyCollection(); PropertyBasedEffectConfigToken BlurParameters = new PropertyBasedEffectConfigToken(blurProps); BlurParameters.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, blur); blurEffect.SetRenderInfo(BlurParameters, dstArgs, new RenderArgs(shadowSurface)); Rectangle selection = EnvironmentParameters.GetSelection(srcArgs.Surface.Bounds).GetBoundsInt(); PointF topStart = new PointF(selection.Left, selection.Top + (margin + spread + offsetY) / 2f); PointF topEnd = new PointF(selection.Right, selection.Top + (margin + spread + offsetY) / 2f); PointF rightStart = new PointF(selection.Right - (margin + spread - offsetX) / 2f, selection.Top); PointF rightEnd = new PointF(selection.Right - (margin + spread - offsetX) / 2f, selection.Bottom); PointF bottomStart = new PointF(selection.Left, selection.Bottom - (margin + spread - offsetY) / 2f); PointF bottomEnd = new PointF(selection.Right, selection.Bottom - (margin + spread - offsetY) / 2f); PointF leftStart = new PointF(selection.Left + (margin + spread + offsetX) / 2f, selection.Top); PointF leftEnd = new PointF(selection.Left + (margin + spread + offsetX) / 2f, selection.Bottom); using (Graphics shadow = new RenderArgs(shadowSurface).Graphics) using (Pen shadowPen = new Pen(color)) { shadowPen.Width = margin + spread + offsetX; shadow.DrawLine(shadowPen, leftStart, leftEnd); shadowPen.Width = margin + spread - offsetX; shadow.DrawLine(shadowPen, rightStart, rightEnd); shadowPen.Width = margin + spread + offsetY; shadow.DrawLine(shadowPen, topStart, topEnd); shadowPen.Width = margin + spread - offsetY; shadow.DrawLine(shadowPen, bottomStart, bottomEnd); } base.OnSetRenderInfo(newToken, dstArgs, srcArgs); }
protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs) { this.pencilTipSize = newToken.GetProperty<Int32Property>(PropertyNames.PencilTipSize).Value; this.colorRange = newToken.GetProperty<Int32Property>(PropertyNames.ColorRange).Value; PropertyBasedEffectConfigToken blurToken = new PropertyBasedEffectConfigToken(this.blurProps); blurToken.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, this.pencilTipSize); this.blurEffect.SetRenderInfo(blurToken, dstArgs, srcArgs); PropertyBasedEffectConfigToken bacToken = new PropertyBasedEffectConfigToken(this.bacProps); bacToken.SetPropertyValue(BrightnessAndContrastAdjustment.PropertyNames.Brightness, this.colorRange); bacToken.SetPropertyValue(BrightnessAndContrastAdjustment.PropertyNames.Contrast, -this.colorRange); this.bacAdjustment.SetRenderInfo(bacToken, dstArgs, dstArgs); this.desaturateEffect.SetRenderInfo(null, dstArgs, dstArgs); this.invertEffect.SetRenderInfo(null, dstArgs, dstArgs); base.OnSetRenderInfo(newToken, dstArgs, srcArgs); }
void Render(Surface dst, Surface src, Rectangle rect) { // Setup for calling the Gaussian Blur effect GaussianBlurEffect blurEffect = new GaussianBlurEffect(); PropertyCollection blurProps = blurEffect.CreatePropertyCollection(); PropertyBasedEffectConfigToken BlurParameters = new PropertyBasedEffectConfigToken(blurProps); BlurParameters.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, Amount1); blurEffect.SetRenderInfo(BlurParameters, new RenderArgs(bluredSurface), new RenderArgs(alignedSurface)); // Call the Gaussian Blur function blurEffect.Render(new Rectangle[1] { rect }, 0, 1); // Setup for calling the Brightness and Contrast Adjustment function BrightnessAndContrastAdjustment bacAdjustment = new BrightnessAndContrastAdjustment(); PropertyCollection bacProps = bacAdjustment.CreatePropertyCollection(); PropertyBasedEffectConfigToken bacParameters = new PropertyBasedEffectConfigToken(bacProps); bacParameters.SetPropertyValue(BrightnessAndContrastAdjustment.PropertyNames.Brightness, Amount2); bacParameters.SetPropertyValue(BrightnessAndContrastAdjustment.PropertyNames.Contrast, 0); bacAdjustment.SetRenderInfo(bacParameters, new RenderArgs(lightSurface), new RenderArgs(bluredSurface)); // Call the Brightness and Contrast Adjustment function bacAdjustment.Render(new Rectangle[1] { rect }, 0, 1); for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) return; for (int x = rect.Left; x < rect.Right; x++) { if (Amount4) { dst[x, y] = normalOp.Apply(lightSurface[x, y], src[x, y]); } else { dst[x, y] = lightSurface[x, y]; } } } }
protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs) { this.softness = newToken.GetProperty<Int32Property>(PropertyNames.Softness).Value; this.lighting = newToken.GetProperty<Int32Property>(PropertyNames.Lighting).Value; this.warmth = newToken.GetProperty<Int32Property>(PropertyNames.Warmth).Value; PropertyBasedEffectConfigToken blurToken = new PropertyBasedEffectConfigToken(this.blurProps); blurToken.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, this.softness * 3); this.blurEffect.SetRenderInfo(blurToken, dstArgs, srcArgs); PropertyBasedEffectConfigToken bacToken = new PropertyBasedEffectConfigToken(this.bacProps); bacToken.SetPropertyValue(BrightnessAndContrastAdjustment.PropertyNames.Brightness, this.lighting); bacToken.SetPropertyValue(BrightnessAndContrastAdjustment.PropertyNames.Contrast, -this.lighting / 2); this.bacAdjustment.SetRenderInfo(bacToken, dstArgs, dstArgs); base.OnSetRenderInfo(newToken, dstArgs, srcArgs); }
protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs) { this.inkOutline = newToken.GetProperty<Int32Property>(PropertyNames.InkOutline).Value; this.coloring = newToken.GetProperty<Int32Property>(PropertyNames.Coloring).Value; PropertyBasedEffectConfigToken glowToken = new PropertyBasedEffectConfigToken(this.glowProps); glowToken.SetPropertyValue(GlowEffect.PropertyNames.Radius, 6); glowToken.SetPropertyValue(GlowEffect.PropertyNames.Brightness, -(this.coloring - 50) * 2); glowToken.SetPropertyValue(GlowEffect.PropertyNames.Contrast, -(this.coloring - 50) * 2); this.glowEffect.SetRenderInfo(glowToken, dstArgs, srcArgs); base.OnSetRenderInfo(newToken, dstArgs, srcArgs); }
void Render(Surface dst, Surface src, Rectangle rect) { // Setup for calling the Gaussian Blur effect GaussianBlurEffect blurEffect = new GaussianBlurEffect(); PropertyCollection blurProps = blurEffect.CreatePropertyCollection(); PropertyBasedEffectConfigToken BlurParameters = new PropertyBasedEffectConfigToken(blurProps); BlurParameters.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, Amount1); blurEffect.SetRenderInfo(BlurParameters, new RenderArgs(dst), new RenderArgs(clampedSurface)); // Call the Gaussian Blur function blurEffect.Render(new Rectangle[1] { rect }, 0, 1); }
protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken token, RenderArgs dstArgs, RenderArgs srcArgs) { int blurRadius = token.GetProperty <Int32Property>(PropertyNames.BlurRadius).Value; int brightness = token.GetProperty <Int32Property>(PropertyNames.Brightness).Value; Pair <double, double> position = token.GetProperty <DoubleVectorProperty>(PropertyNames.Position).Value; this.keepOriginal = token.GetProperty <BooleanProperty>(PropertyNames.KeepOriginal).Value; Rectangle selection = this.EnvironmentParameters.SelectionBounds; if (this.trimmedBounds.IsEmpty) { this.trimmedBounds = GetTrimmedBounds(srcArgs.Surface, selection); } float ratio = (float)selection.Width / selection.Height; Size ratioSize = new Size(this.trimmedBounds.Width, this.trimmedBounds.Height); if (ratioSize.Width < ratioSize.Height * ratio) { ratioSize.Height = (int)Math.Round(this.trimmedBounds.Width / ratio); } else if (ratioSize.Width > ratioSize.Height * ratio) { ratioSize.Width = (int)Math.Round(this.trimmedBounds.Height * ratio); } PointF offsetForCenter = new PointF(Math.Abs(ratioSize.Width - this.trimmedBounds.Width) / 2f, Math.Abs(ratioSize.Height - this.trimmedBounds.Height) / 2f); Rectangle srcRect = new Rectangle { X = (int)Math.Round(this.trimmedBounds.X + offsetForCenter.X + (position.First * offsetForCenter.X)), Y = (int)Math.Round(this.trimmedBounds.Y + offsetForCenter.Y + (position.Second * offsetForCenter.Y)), Width = ratioSize.Width, Height = ratioSize.Height }; if (this.enlargedSurface == null) { this.enlargedSurface = new Surface(selection.Size); } using (Surface ratioSurface = new Surface(ratioSize)) { ratioSurface.CopySurface(srcArgs.Surface, Point.Empty, srcRect); this.enlargedSurface.FitSurface(ResamplingAlgorithm.Bicubic, ratioSurface); } if (selection.Size != srcArgs.Surface.Size) { if (this.clampedSurface == null) { this.clampedSurface = new Surface(srcArgs.Surface.Size); } for (int y = Math.Max(0, selection.Top - 200); y < Math.Min(this.clampedSurface.Height, selection.Bottom + 200); y++) { if (this.IsCancelRequested) { return; } for (int x = Math.Max(0, selection.Left - 200); x < Math.Min(this.clampedSurface.Width, selection.Right + 200); x++) { this.clampedSurface[x, y] = this.enlargedSurface.GetBilinearSampleClamped(x - selection.Left, y - selection.Top); } } } else { this.clampedSurface = this.enlargedSurface; } if (this.effectsSurface == null) { this.effectsSurface = new Surface(srcArgs.Surface.Size); } // Setup for calling the Gaussian Blur effect PropertyCollection blurProps = this.blurEffect.CreatePropertyCollection(); PropertyBasedEffectConfigToken BlurParameters = new PropertyBasedEffectConfigToken(blurProps); BlurParameters.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, blurRadius); this.blurEffect.SetRenderInfo(BlurParameters, new RenderArgs(this.effectsSurface), new RenderArgs(this.clampedSurface)); // Setup for calling the Brightness and Contrast Adjustment function PropertyCollection bacProps = this.bacAdjustment.CreatePropertyCollection(); PropertyBasedEffectConfigToken bacParameters = new PropertyBasedEffectConfigToken(bacProps); bacParameters.SetPropertyValue(BrightnessAndContrastAdjustment.PropertyNames.Brightness, brightness); bacParameters.SetPropertyValue(BrightnessAndContrastAdjustment.PropertyNames.Contrast, 0); this.bacAdjustment.SetRenderInfo(bacParameters, new RenderArgs(this.effectsSurface), new RenderArgs(this.effectsSurface)); base.OnSetRenderInfo(token, dstArgs, srcArgs); }
void Render(Surface dst, Surface src, Rectangle rect) { if (Amount3 != 0) { // Setup for calling the Gaussian Blur effect GaussianBlurEffect blurEffect = new GaussianBlurEffect(); PropertyCollection blurProps = blurEffect.CreatePropertyCollection(); PropertyBasedEffectConfigToken BlurParameters = new PropertyBasedEffectConfigToken(blurProps); BlurParameters.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, Amount3); blurEffect.SetRenderInfo(BlurParameters, new RenderArgs(dst), new RenderArgs(shadowSurface)); // Call the Gaussian Blur function blurEffect.Render(new Rectangle[1] { rect }, 0, 1); } else { dst.CopySurface(shadowSurface, rect.Location, rect); } Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); ColorBgra sourcePixel, shadowPixel; for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) return; for (int x = rect.Left; x < rect.Right; x++) { sourcePixel = src[x, y]; shadowPixel = dst[x, y]; if (x < selection.Left + Amount1 + Amount6 || x > selection.Right - Amount1 - 1 + Amount6|| y < selection.Top + Amount1 + Amount7|| y > selection.Bottom - Amount1 - 1 + Amount7) { // Erase the margins shadowPixel.A = 0; } else { shadowPixel.A = Int32Util.ClampToByte(shadowPixel.A * Amount5 / 255); } dst[x, y] = normalOp.Apply(sourcePixel, shadowPixel); } } }
private void btnLoad_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "PDN Preset Files (.pst)|*.pst"; if (openFileDialog.ShowDialog() == DialogResult.OK) { FileStream stream = File.Open(openFileDialog.FileName, FileMode.Open); BinaryFormatter reader = new BinaryFormatter(); this.lbEffect.Items.Clear(); this.types = new List <int>(); this.effects = new List <Effect>(); this.dialogs = new List <EffectConfigDialog>(); this.collections = new List <PropertyCollection>(); int type = 0; Effect effect = null; EffectConfigDialog dialog = null; PropertyCollection collection = null; PropertyBasedEffectConfigToken token = null; int effectCount = (int)reader.Deserialize(stream); for (int i = 0; i < effectCount; i++) { type = (int)reader.Deserialize(stream); effect = (Effect)available[type].GetConstructor(Type.EmptyTypes).Invoke(new object[0]); if ((effect.Options.Flags & EffectFlags.Configurable) != 0) { dialog = effect.CreateConfigDialog(); dialog.Effect = effect; if (dialog.EffectToken is PropertyBasedEffectConfigToken) { collection = ((PropertyBasedEffectConfigToken)dialog.EffectToken).Properties; token = new PropertyBasedEffectConfigToken(collection); IEnumerator <Property> enumerator = collection.GetEnumerator(); while (enumerator.MoveNext()) { token.SetPropertyValue(enumerator.Current.Name, reader.Deserialize(stream)); } dialog.EffectToken = token; collection = ((PropertyBasedEffectConfigToken)dialog.EffectToken).Properties; } else { Type tokenType = dialog.EffectToken.GetType(); PropertyInfo[] info = tokenType.GetProperties(); for (int j = 0; j < info.Length; j++) { if (info[j].GetValue(dialog.EffectToken).GetType().IsSerializable == true) { object property = reader.Deserialize(stream); info[j].SetValue(dialog.EffectToken, property); } } } } this.lbEffect.Items.Add(this.cbEffect.Items[type]); this.types.Add(type); this.effects.Add(effect); this.dialogs.Add(dialog); this.collections.Add(collection); } FinishTokenUpdate(); stream.Close(); } }