jsonchiu Posted August 23, 2007 Posted August 23, 2007 (edited) Ok, so as you know, Boltbait's feather plugin uses Gaussian Blur to soften the edges. I have always found it doesn't quite work the way I wanted. So, I wrote another plugin for smoothing edges, but still keep it clear, not blurred. With this plugin, the result will be clear and smooth, just like any other anti-aliased shapes. Amount: pretty self explanatory. Slide it around to see different effects. Strength: opaqueness of the "feathering" Default 980 for anti-aliasing. Turn it down for feathering. Soft outline/None: Default is on. If turned on, it would darken the edge a little bit to make it clearer. If the image has light colors, turn it off, or else there would be an ugly dark outline. Example: let's feather a cat... (cut from Bob's siggie). Before: the edge is too hard, and jagged After: the edge is smoothed out (anti-aliased)! This plugin can also blur the edges with a medium-high amount and low strength Download Source: Spoiler int Amount1=5; //[5,50] Amount int Amount2=980; //[0,1000] Strength int Amount3=0; //[0,1] Soft Outline None void Render(Surface dst, Surface src, Rectangle rect) { PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); ColorBgra CurrentPixel; for(int y = rect.Top; y < rect.Bottom; y++) { for (int x = rect.Left; x < rect.Right; x++) { if (selectionRegion.IsVisible(x, y)) { CurrentPixel = src[x,y]; if (isAtEdge(x,y, src, selection) == true) { CurrentPixel = getAveragePixel(x,y, src, selection); } dst[x,y] = CurrentPixel; } } } } bool isAtEdge(int x, int y, Surface src, Rectangle selection) { ColorBgra[] c = new ColorBgra[5]; if (x <= selection.Left) { x = selection.Left + 1; } if (y <= selection.Top) { y = selection.Top + 1; } if (x >= selection.Right-1) { x = selection.Right - 2; } if (y >= selection.Bottom-1) { y = selection.Bottom - 2; } c[0] = src[x, y-1]; c[1] = src[x-1, y]; c[2] = src[x+1, y]; c[3] = src[x, y+1]; c[4] = src[x, y]; for (int i = 0; i < c.Length; i++) { ColorBgra temp = (ColorBgra)c[i]; if (temp.A == 0) { return true; break; } } return false; } ColorBgra getAveragePixel(int x, int y, Surface src, Rectangle selection) { int gridSpan = (int)(Amount1/2) - 1; int gridWidth = gridSpan * 2 + 1; int gridArea = gridWidth * gridWidth - 1; int counter = 0; ColorBgra[] c = new ColorBgra[gridArea]; for (int i = -gridSpan; i <= gridSpan; i++) { for (int j = -gridSpan; j <= gridSpan; j++) { if (!(i == 0 && j == 0)) { int newx = x+i; int newy = y+j; if (newx <= selection.Left+(gridSpan-1)) { newx = selection.Left + gridSpan; } if (newy <= selection.Top+(gridSpan-1)) { newy = selection.Top + gridSpan; } if (newx >= selection.Right-(gridSpan+1)) { newx = selection.Right - (gridSpan + 2); } if (newy >= selection.Bottom-(gridSpan+1)) { newy = selection.Bottom - (gridSpan + 2); } c[counter] = src[newx,newy]; counter++; } } } ColorBgra returnCol = src[x,y]; float newR = 0; float newG = 0; float newB = 0; float newA = 0; float highestA = 0; float counter2 = (float)0; for (int m = 0; m < gridArea; m++) { ColorBgra temp = (ColorBgra) c[m]; if (temp.A > 0) { newR += (float)temp.R; newG += (float)temp.G; newB += (float)temp.B; newA += (float)temp.A; if ((float)temp.A > (float)highestA) { highestA = (float) temp.A; } counter2 = counter2 + 1; } } if (Amount3 == 0 && highestA == 255) { counter2 += 1; } newR = newR / counter2; newG = newG / counter2; newB = newB / counter2; if (counter2 > 1) { newA = (float)((counter2-2)/((1000-Amount2)/5)) * highestA; if (newA > highestA) { newA = highestA; } } else { newA = 0; } returnCol.R = (byte)newR; returnCol.G = (byte)newG; returnCol.B = (byte)newB; returnCol.A = (byte)newA; return returnCol; } Enjoy! Update1: added "strength" slide bar and expand "Amount" to 30 Update2: FULLY fixed transparency bug! Update3: added "soft outline" slider to adjust edge enhancement Update4: fixed "no anti-alias on low alpha" bug. The plugin should now antialias equally for any alpha value. Also, added a menu icon! Edited October 7, 2018 by toe_head2001 Formatting & restore images Quote Some links: | Personal Website | Alien Attack | Try out my plugins: | Antialias | Diagonal Lines |
david.atwell Posted August 23, 2007 Posted August 23, 2007 Okay, as a non-coder who can't read it, what does this do? Quote The Doctor: There was a goblin, or a trickster, or a warrior... A nameless, terrible thing, soaked in the blood of a billion galaxies. The most feared being in all the cosmos. And nothing could stop it, or hold it, or reason with it. One day it would just drop out of the sky and tear down your world.Amy: But how did it end up in there?The Doctor: You know fairy tales. A good wizard tricked it.River Song: I hate good wizards in fairy tales; they always turn out to be him.
jsonchiu Posted August 23, 2007 Author Posted August 23, 2007 Okay, as a non-coder who can't read it, what does this do? Smooth out the edges. Quote Some links: | Personal Website | Alien Attack | Try out my plugins: | Antialias | Diagonal Lines |
david.atwell Posted August 23, 2007 Posted August 23, 2007 Well, yes, that much I understood :-) I mean, how? Progressive transparency? Quote The Doctor: There was a goblin, or a trickster, or a warrior... A nameless, terrible thing, soaked in the blood of a billion galaxies. The most feared being in all the cosmos. And nothing could stop it, or hold it, or reason with it. One day it would just drop out of the sky and tear down your world.Amy: But how did it end up in there?The Doctor: You know fairy tales. A good wizard tricked it.River Song: I hate good wizards in fairy tales; they always turn out to be him.
Ash Posted August 23, 2007 Posted August 23, 2007 I think the title can do without the "much better than the feather plugin" IMO, each plugins can be useful in different case. Quote All creations Ash + Paint.NET [ Googlepage | deviantArt | Club PDN | PDN Fan ]
jsonchiu Posted August 23, 2007 Author Posted August 23, 2007 @david.atwell Yes, progressive transparency. Here's how the code works: 1. take a pixel, and determine whether it's a solid or transparent one. 2. if it's a transparent one, change the color to the nearest solid pixel, and the alpha value to the average of the surrounding pixels (with a little bit of tweaking to make it not so blurred). @Ash I intended it to be the Photoshop-quality feather, but then I couldn't make it to feather at different amount of pixels. Quote Some links: | Personal Website | Alien Attack | Try out my plugins: | Antialias | Diagonal Lines |
Ash Posted August 23, 2007 Posted August 23, 2007 I just tried the plugin. It's making a dark line around my object...... 1. take a pixel, and determine whether it's a solid or transparent one. 2. if it's a transparent one, change the color to the nearest solid pixel, and the alpha value to the average of the surrounding pixels (with a little bit of tweaking to make it not so blurred). That kinda sounds like what feather is doing in "Grow" mode, I'm no coder tho, Tell me if I am wrong.. Quote All creations Ash + Paint.NET [ Googlepage | deviantArt | Club PDN | PDN Fan ]
jsonchiu Posted August 23, 2007 Author Posted August 23, 2007 @Ash Hmm... dark line? It doesn't work with semi-transparent objects IMO. In order for it to work as intended, you need all the pixels on the edge to be opaque. Also, it will place a very tiny line (barely visible) around it if it has a very light color. ------- The feather plugin in the "grow" mode still use Gaussian Blur, and therefore produce blurred results on the edges, instead of clearcut anti-alias. You can see the difference in these pictures (left: feather 1px, grow, right: anti-alias, amount: 5) Quote Some links: | Personal Website | Alien Attack | Try out my plugins: | Antialias | Diagonal Lines |
DecemberWinds Posted August 23, 2007 Posted August 23, 2007 Sometimes when I use magic wand to select only an image from even a pure white background I get little white pixels on the edge, and feather doesn't usually get it to go away. Will this help more? Quote | [deviantART] | [Photobucket] |
snospmiS Posted August 23, 2007 Posted August 23, 2007 works quite nice...thx!! Quote .::[ Kiosk Orbs ]::.
jsonchiu Posted August 23, 2007 Author Posted August 23, 2007 @DecemberWinds It won't get rid of white pixels; only add to it. My suggestion: select with a higher tolerance, and use the plugin. Quote Some links: | Personal Website | Alien Attack | Try out my plugins: | Antialias | Diagonal Lines |
Ash Posted August 23, 2007 Posted August 23, 2007 @AshHmm... dark line? It doesn't work with semi-transparent objects IMO. In order for it to work as intended, you need all the pixels on the edge to be opaque. Also, it will place a very tiny line (barely visible) around it if it has a very light color. ------- The feather plugin in the "grow" mode still use Gaussian Blur, and therefore produce blurred results on the edges, instead of clearcut anti-alias. You can see the difference in these pictures (left: feather 1px, grow, right: anti-alias, amount: 5) I see it. Can the amout of your AA plugin go above 5? Thanks Quote All creations Ash + Paint.NET [ Googlepage | deviantArt | Club PDN | PDN Fan ]
jsonchiu Posted August 23, 2007 Author Posted August 23, 2007 It doesn't smooth anything at all if it goes pass 5 somehow :? However, you can expect something like smoothing 100 pixels soon Quote Some links: | Personal Website | Alien Attack | Try out my plugins: | Antialias | Diagonal Lines |
davidtayhs Posted August 23, 2007 Posted August 23, 2007 Would be great if it works for me! Downloaded the plugin, put in in effects folder, copied the same cat from jsonchiu's posting, ran the plugin. Nothing happened! Setting was at the default value of 5. Quote
pyrochild Posted August 23, 2007 Posted August 23, 2007 The area around the object must be transparent, davidtayhs. Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it!
david.atwell Posted August 23, 2007 Posted August 23, 2007 The cat is on a white border in his post. It needs to be on a transparent background. Quote The Doctor: There was a goblin, or a trickster, or a warrior... A nameless, terrible thing, soaked in the blood of a billion galaxies. The most feared being in all the cosmos. And nothing could stop it, or hold it, or reason with it. One day it would just drop out of the sky and tear down your world.Amy: But how did it end up in there?The Doctor: You know fairy tales. A good wizard tricked it.River Song: I hate good wizards in fairy tales; they always turn out to be him.
jsonchiu Posted August 23, 2007 Author Posted August 23, 2007 Here's a cat with transparent background: It should work. Quote Some links: | Personal Website | Alien Attack | Try out my plugins: | Antialias | Diagonal Lines |
davidtayhs Posted August 23, 2007 Posted August 23, 2007 Thanks Pyrochild. I actually selected the white background with the selection tool at the default setting, and then deleted it. Then I ran the plugin and nothing worked. Discovered the problem: I set the selection tool at 0 tolerance, and then repeated the whole procedure with successful feathering effect. Thanks for the response. Quote
Bob Posted August 23, 2007 Posted August 23, 2007 My browser crashed... ^Click^ Antialias/Feather comparaison. All kudos to Cute Overload for the cat. Oh yeah! I HAZ ANTIALIAS. Quote No. Way. I've just seen Bob. And... *poof!*—just like that—he disappears into the mist again. ~Helio
BoltBait Posted August 23, 2007 Posted August 23, 2007 ^Click^ Antialias/Feather comparaison. Heh. I'll stick with Feather. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game
Bob Posted August 23, 2007 Posted August 23, 2007 Feather is more blurry. Quote No. Way. I've just seen Bob. And... *poof!*—just like that—he disappears into the mist again. ~Helio
barkbark00 Posted August 23, 2007 Posted August 23, 2007 This plugin also seems to have a more consistent progression of transparency. Quote Take responsibility for your own intelligence. 😉 -Rick Brewster
jsonchiu Posted August 23, 2007 Author Posted August 23, 2007 Updated: added the "strength" slidebar, and expand the "Amount" slidebar to 30 You should now be able to do the "true" feathering (low strength) as well as anti-aliasing (high strength). Left: amount 13 strength 669, Right: amount 5 strength 985 The "strength" should be kept above 900 if you want clearcut, solid anti-alias. The higher it is, the clearer the anti-alias, and 990 will produce pixelated results. The "amount" is expanded to 30. Anything above 30 is freaking slow because calculating the average of 1000 surrounding pixels (about 32x32) for every pixel on the screen isn't a very efficient operation. Quote Some links: | Personal Website | Alien Attack | Try out my plugins: | Antialias | Diagonal Lines |
Paint Boy Posted August 23, 2007 Posted August 23, 2007 This is a very nice plugin! This will definitely stop all those blocky pictures I get. Thank you so much! I recommend this for anyone that uses the Crop the selection a lot. Or just for anyone. Have you made any other plugins? EDIT: Updated: added the "strength" slidebar, and expand the "Amount" slidebar to 30You should now be able to do the "true" feathering (low strength) as well as anti-aliasing (high strength). Left: amount 13 strength 669, Right: amount 5 strength 985 The "strength" should be kept above 900 if you want clearcut, solid anti-alias. The higher it is, the clearer the anti-alias, and 990 will produce pixelated results. The "amount" is expanded to 30. Anything above 30 is freaking slow because calculating the average of 1000 surrounding pixels (about 32x32) for every pixel on the screen isn't a very efficient operation. That is very cool. That will come in handy too. Quote
jsonchiu Posted August 23, 2007 Author Posted August 23, 2007 BIG UPDATE! 1. FULLY fixed transparency bug. If you turn the outline off, then semitransparent stuff should be smoothed like any other objects! 2. Add "soft outline" option for edge enhancement. Turn it off if your image has very light colors. Enjoy! Quote Some links: | Personal Website | Alien Attack | Try out my plugins: | Antialias | Diagonal Lines |
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.