toe_head2001 Posted January 12, 2016 Share Posted January 12, 2016 (edited) Gaussian Blur (Clamped) Effects -> Blurs -> Gaussian Blur (Clamped) Description This effect is exactly the same as the regular Gaussian Blur effect, except this effect gets clamped to the active selection. This stops colors (and transparency) from bleeding through from outside of the selection. If you don't have anything selected, there is no need to run this effect (although, it wouldn't hurt anything if you did run it). Comparison Gaussian Blur (Clamped) - Radius of 25: -> Gaussian Blur - Radius of 25: -> Change Log v2.0 (Jan 22, 2016) Changed: Now works on non-rectangular selections. (Thanks MJW) v1.0 (Jan 11, 2016) Initial release Download ClampedGaussianBlur.zip Donate Source Code https://github.com/toehead2001/pdn-clamped-gaussian-blur Icon based on icons from Fugue Icons. Edited January 16, 2022 by toe_head2001 1 7 Quote (September 25th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
MJW Posted January 12, 2016 Share Posted January 12, 2016 A useful feature. More than once I've wished the non-selected area could be excluded from the blur. Oddly enough I was thinking about adding the same feature to a (non-Gaussian blur) plugin I'm working on. Quote Link to comment Share on other sites More sharing options...
Eli Posted January 12, 2016 Share Posted January 12, 2016 Thanks toe_head2001, A step saver effect. Before I had to duplicate the blurred selection four or more times in order to bring back full opacity to the edges. Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted January 12, 2016 Author Share Posted January 12, 2016 (edited) A useful feature. More than once I've wished the non-selected area could be excluded from the blur. Oddly enough I was thinking about adding the same feature to a (non-Gaussian blur) plugin I'm working on. Oddly enough, this plugin is a side effect (no pun indented) of work I did for my Blur Fill plugin. Edit: I see most (all?) the blur effects don't clamp to the selection. I never bothered to notice that before. Then again, I can't remember the last time I used a blur effect other than Gaussian Blur. A step saver effect. Before I had to duplicate the blurred selection four or more times in order to bring back full opacity to the edges. Before, I would copy the selection to a new image, since the canvas edge works as a clamp. Then I'd run Gaussian Blur. Edited January 12, 2016 by toe_head2001 Quote (September 25th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
Cc4FuzzyHuggles Posted January 12, 2016 Share Posted January 12, 2016 (edited) Thank you! This will be great for making shiny effects easier. Shiny, like what I did in this picture http://m.artician.com/pu/4DBTZC3EM25CZMTXBFPP536M4CJTFVZS.original.png That pic is old, but making new pics like it will hopefully be better now. Edited January 12, 2016 by Cc4FuzzyHuggles Quote *~ Cc4FuzzyHuggles Gallery ~* Link to comment Share on other sites More sharing options...
toe_head2001 Posted January 12, 2016 Author Share Posted January 12, 2016 (edited) Why do I always forget to test non-rectangular selections? Can a non-rectangle even be clamped? I'll see if I can a solution. Edited January 12, 2016 by toe_head2001 Quote (September 25th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
Rick Brewster Posted January 12, 2016 Share Posted January 12, 2016 Maybe not, but you could clamp to the bounding rectangle and clip to the entire selection. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
toe_head2001 Posted January 12, 2016 Author Share Posted January 12, 2016 (edited) Maybe not, but you could clamp to the bounding rectangle and clip to the entire selection. That's what I'm doing already, unless I misunderstand you. It creates a Rectangle based on the selection, and clamps the pixels outside the selection to the edges of the Rectangle edges. It then calls Gaussian Blur on the selection, and renders it to the dst surface. Edited January 12, 2016 by toe_head2001 Quote (September 25th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
BoltBait Posted January 12, 2016 Share Posted January 12, 2016 (edited) On 1/12/2016 at 1:46 PM, toe_head2001 said: Why do I always forget to test non-rectangular selections? Can a non-rectangle even be clamped? I'll see if I can a solution. toe_head2001, This code should solve your problem: Spoiler using System; using System.Drawing; using System.Reflection; using System.Windows.Forms; using System.Runtime.InteropServices; using PaintDotNet; using PaintDotNet.Effects; using PaintDotNet.AppModel; using PaintDotNet.IndirectUI; using PaintDotNet.Collections; using PaintDotNet.PropertySystem; using IntSliderControl = System.Int32; [assembly: AssemblyTitle("GaussianBlurClamped Plugin for Paint.NET")] [assembly: AssemblyDescription("Blur only selected pixels")] [assembly: AssemblyConfiguration("blur|clamped|gaussian")] [assembly: AssemblyCompany("toe_head2001")] [assembly: AssemblyProduct("GaussianBlurClamped")] [assembly: AssemblyCopyright("Copyright ©2016 toe_head2001")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: AssemblyVersion("2.0.*")] namespace GaussianBlurClampedEffect { public class PluginSupportInfo : IPluginSupportInfo { public string Author { get { return ((AssemblyCopyrightAttribute)base.GetType().Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)[0]).Copyright; } } public string Copyright { get { return ((AssemblyDescriptionAttribute)base.GetType().Assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false)[0]).Description; } } public string DisplayName { get { return ((AssemblyProductAttribute)base.GetType().Assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false)[0]).Product; } } public Version Version { get { return base.GetType().Assembly.GetName().Version; } } public Uri WebsiteUri { get { return new Uri("http://www.getpaint.net/redirect/plugins.html"); } } } [PluginSupportInfo(typeof(PluginSupportInfo), DisplayName = "Gaussian Blur Clamped")] public class GaussianBlurClampedEffectPlugin : PropertyBasedEffect { public static string StaticName { get { return "Gaussian Blur Clamped"; } } public static Image StaticIcon { get { return new Bitmap(typeof(GaussianBlurClampedEffectPlugin), "Clamped.png"); } } public static string SubmenuName { get { return SubmenuNames.Blurs; } } public GaussianBlurClampedEffectPlugin() : base(StaticName, StaticIcon, SubmenuName, EffectFlags.Configurable) { } public enum PropertyNames { Amount1 } protected override PropertyCollection OnCreatePropertyCollection() { List<Property> props = new List<Property>(); props.Add(new Int32Property(PropertyNames.Amount1, 2,0,200)); return new PropertyCollection(props); } protected override ControlInfo OnCreateConfigUI(PropertyCollection props) { ControlInfo configUI = CreateDefaultConfigUI(props); configUI.SetPropertyControlValue(PropertyNames.Amount1, ControlInfoPropertyNames.DisplayName, "Radius"); return configUI; } protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs) { Amount1 = newToken.GetProperty<Int32Property>(PropertyNames.Amount1).Value; if (scratch == null) { scratch = new Surface(dstArgs.Size); scratch.Clear(ColorBgra.TransparentBlack); PdnRegion selectionRegion = EnvironmentParameters.GetSelection(srcArgs.Bounds); foreach (Rectangle r in selectionRegion.GetRegionScansInt()) { scratch.CopySurface(src,r.Location,r); } } base.OnSetRenderInfo(newToken, dstArgs, srcArgs); } protected override unsafe void OnRender(Rectangle[] rois, int startIndex, int length) { if (length == 0) return; for (int i = startIndex; i < startIndex + length; ++i) { Render(DstArgs.Surface,SrcArgs.Surface,rois[i]); } } #region User Entered Code #region UICode IntSliderControl Amount1=2; // [0,200] Radius #endregion Surface scratch = null; void Render(Surface dst, Surface src, Rectangle rect) { 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(scratch)); blurEffect.Render(new Rectangle[1] {rect},0,1); } #endregion } } Sorry if it doesn't work. I just wrote it off the top of my head and haven't tested it. Magic is in OnSetRenderInfo. Edited November 15, 2020 by toe_head2001 Fixed broken Hidden box 3 Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
toe_head2001 Posted January 13, 2016 Author Share Posted January 13, 2016 (edited) This code should solve your problem... Yes, it may, in part. When I said non-rectangular, I was specifically thinking of elliptical selections. The clamping would need to be radial. Like so: ---> Which of course can be done in code, but I have yet to try anything yet and measure the performance. Edited January 13, 2016 by toe_head2001 Quote (September 25th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
MJW Posted January 13, 2016 Share Posted January 13, 2016 toe_head2001, I'm not sure how you produced the second image in your most-recent comment, but it it wasn't through a program, and you intend to write such a program, I may be able to help. Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted January 13, 2016 Author Share Posted January 13, 2016 toe_head2001, I'm not sure how you produced the second image in your most-recent comment, but it it wasn't through a program, and you intend to write such a program, I may be able to help. Nothing fancy; Many layers and zooming. Help is always welcome and appreciated. Quote (September 25th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
MJW Posted January 13, 2016 Share Posted January 13, 2016 (edited) I said it was odd that I was thinking of adding the feature of looking at the only the selected region in a plugin I'm working on. What's odder is that the plugin does pretty much what you're interested in doing. It takes an "object" (a region surrounded by transparency) and extends it by setting each transparent pixel to the color of the nearest non-transparent pixel. It uses a separate surface, but the algorithm is O(n), where n in the number of pixels in the window. I describe the algorithm in my "Fast algorithm for finding the minimum distances to a set" comment. (The idea of clamping the edge in this way would work for blurring convex selections, but wouldn't work for some non-convex selections, since the color from one edge could bleed over into another if the blur radius exceeded half the distance between the edges.) Here is the flower image processed with the algorithm. Edited January 13, 2016 by MJW 1 Quote Link to comment Share on other sites More sharing options...
BoltBait Posted January 13, 2016 Share Posted January 13, 2016 The code I wrote for you won't extrude a picture. It only blurs the selected pixels of an irregular selection without the influence of the non-selected pixels. After looking at the code, the only problem will be calculating a proper alpha value for the blurred pixels. Perhaps it would use the source alpha or the most opaque alpha between the result pixel and the source pixel. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
MJW Posted January 13, 2016 Share Posted January 13, 2016 BoltBait, thanks for the selection-copying code in your previous comments. That might be very useful for me. Quote Link to comment Share on other sites More sharing options...
Red ochre Posted January 13, 2016 Share Posted January 13, 2016 A plugin that would 'trail' objects towards a vanishing point would be very useful! I normally duplicate the object, make the background object smaller, use zoom blur, then change the opacity.The plugin named Trail 3d doesn't do that and Pyro's trail is great but doesn't converge for perspective. I guess that's slightly off topic, sorry Toe_Head. Quote Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings Link to comment Share on other sites More sharing options...
toe_head2001 Posted January 13, 2016 Author Share Posted January 13, 2016 I said it was odd that I was thinking of adding the feature of looking at the only the selected region in a plugin I'm working on. What's odder is that the plugin does pretty much what you're interested in doing. It takes an "object" (a region surrounded by transparency) and extends it by setting each transparent pixel to the color of the nearest non-transparent pixel. It uses a separate surface, but the algorithm is O(n), where n in the number of pixels in the window. I describe the algorithm in my "Fast algorithm for finding the minimum distances to a set" comment. (The idea of clamping the edge in this way would work for blurring convex selections, but wouldn't work for some non-convex selections, since the color from one edge could bleed over into another if the blur radius exceeded half the distance between the edges.) Thank you. I'll take a close look at this during the weekend when I have plenty of time. Concave selections are pretty rare (or maybe it's just me that never makes them), so I don't think that's a big deal. ... It only blurs the selected pixels of an irregular selection without the influence of the non-selected pixels... Just because the non-selected pixels are transparent, doesn't mean they aren't influencing the selected ones. That's why transparency is bleeding into the blur when your code is run. This is why the clamping is so important. The code you posted in regards to the PdnRegion will be helpful though. Much appreciated. I'd seen PdnRegion in other people's code before, but I never bothered to see what it did or what it was used for. Quote (September 25th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
toe_head2001 Posted January 22, 2016 Author Share Posted January 22, 2016 Version 2.0 posted. It now uses @MJW's DistanceTransform algorithm for the clamping; which means it will work on non-rectangular selections now. 2 Quote (September 25th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
Manc Posted November 16, 2020 Share Posted November 16, 2020 Great plugin Mate. Quote Link to comment Share on other sites More sharing options...
ardneh Posted May 8, 2021 Share Posted May 8, 2021 (edited) . Edited May 9, 2021 by ardneh Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.