Paint.NET

Welcome to the Paint.NET forum!
It is currently Sun Nov 22, 2009 10:54 am

All times are UTC


Forum rules


Questions or problems with plugin installation? Click here.



Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Basic Antialias version 1.1 - bug fixed (January 14 2008)
PostPosted: Tue Jan 08, 2008 2:10 pm 
Offline

Joined: Thu Oct 25, 2007 9:35 am
Posts: 80
Download the updated Basic Antialias: BasicAntialias11.zip

-EDIT-

The 1.1 release fixes the reported bug. Or, at least, I hope so. You find this new Basic Antialias in the Effects->Object submenu.
I cannot say if Basic Antialias is better than Antialias. What I can say is that my design goals in writing it were 1) avoid side effects like shrink, grow, blur or outline, and 2) reduce aliasing in a basic way without having to spend time in fine tuning of the settings. Basic Antialias satisfies this goals, and also my personal needs. I hope you will find useful, too.
You find the code below. Now I can understand almost everything of it. My code is far from being perfect, it is redundant and not always does the right thing (it is almost impossible to note this, however). If you want to improve it but you can't understand it, please contact me and I'll try to explain.
I plan to release version 2.0 with support for trasparent objects in the future, but now I want to try developing other plugins.
Thanks,
Pyjo.
________________________


What? After Feather and Antialias, another antialias plugin?
Well... sorry... this is my first plugin, I wanted to start with something simple and not too experimental.
Ok, but why another Antialias plugin? Here is the answer: I noticed that some PdN users, including me, are not totally satisfied with existing antialias tools. I often used motion blur, which is not intended for this purpose, for removing aliasing effectively. So I took CodeLab and wrote this new plugin. Since I'm not a developer (and I don't know C#) it required me a lot of time, but eventually, pushing and kicking, my bare C code worked as expected (I hope that soon or later I'll understand how, too).

I created this plugin for personal use, but maybe that someone else will find it useful. Basic Antialias is basic in that it doesn't ask the user for any setting. It affects the border of "solid" shapes surrounded by trasparent pixels. It is useful when you copy and paste a selection in a new layer or when you fill a selection with something like clouds or gradient, as in this example:

Image

(f you see no difference between the four moons, please put your nose close to the screen.)
The original picture is aliased. Feather and Antialias (with default settings) introduce a blur. Basic Antialias reduces aliasing without altering the sharpness of the border.
Here is another example:

Image


The rose was selected with the magic wand from a photo, copied two times in a new layer and then Basic Antialias was applied to the second one.

To use this plugin dowload the .zip, put the extracted .dll file in the Effects folder and (re)start PdN. You'll find the tool in Effects>Contour submenu (is this the right menu for an antialias? Please give me a feedback).
If the plugin seems not to work, verify that the shape to be processed doesn't contain any partially trasparent pixel. Basic Antialias works only when it finds a totally trasparent pixel (alpha=0) near a not-trasparent-at-all pixel (alpha=255). If some antialias tool was previously used on the picture (note that paintbrush and other drawing tools have the antialias feature on by default), basic antialias won't do anything on it. Maybe this limitation will be removed in 2.0 version.

Bye,
Pyjo.

Code:
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]; 
                int i,j,p;
//VERTICAL
                double x1,x2;
      for (p=1;p>=-1;p-=2)
                {
//Addition
                   if((x>selection.Left) && (x<selection.Right-1) && CurrentPixel.A==0&&src[x-p,y].A==255)
                   {
                    for(i=y;src[x,i].A==0 && src[x-p,i].A==255 && i<selection.Bottom-1;i++);
                    for(j=y;src[x,j].A==0 && src[x-p,j].A==255 && j>selection.Top;j--);
                   
                    if(src[x,j].A==255&&y<=(i+j)/2) //bottom
                     {
                      x1=((double)y+(0.5))/(j-i+1)+(0.5)*(i+j)/(-j+i-1);
                      x2=((double)y-(0.5))/(j-i+1)+(0.5)*(i+j)/(-j+i-1);
                      CurrentPixel=src[x-p,y];
                      CurrentPixel.A=(byte)((x1+x2)*127);
                     }
           
                    if(src[x,i].A==255&&y>(i+j)/2) //top
                     {
                      x1=((double)y+(0.5))/(j-i+1)+(0.5)*(i+j)/(-j+i-1);
                      x2=((double)y-(0.5))/(j-i+1)+(0.5)*(i+j)/(-j+i-1); 
                      CurrentPixel=src[x-p,y]; CurrentPixel.A=(byte)(255-(x1+x2)*127);
                     }
                   }
                   
//Subtraction
                   if((x>selection.Left) && (x<selection.Right-1) && src[x,y].A==255&&src[x-p,y].A==0)
                    {
                     for(i=y;src[x,i].A==255 && src[x-p,i].A==0 && i<selection.Bottom-1;i++);
                     for(j=y; src[x,j].A==255 && src[x-p,j].A==0 && j>selection.Top;j--);
             
                     if(src[x,i].A==0&&y>(i+j)/2) //bottom
                      {
                       x1=((double)y+(0.5))/(j-i+1)+(0.5)*(i+j)/(-j+i-1);
                       x2=((double)y-(0.5))/(j-i+1)+(0.5)*(i+j)/(-j+i-1);       
                       CurrentPixel.A+=(byte)((x1+x2)*127);
                      }
                       
                     if(src[x,j].A==0 &&y<(i+j)/2)  //top
                      {
                       x1=((double)y+(0.5))/(j-i+1)+(0.5)*(i+j)/(-j+i-1);
                       x2=((double)y-(0.5))/(j-i+1)+(0.5)*(i+j)/(-j+i-1);
                       CurrentPixel.A-=(byte)((x1+x2)*127); 
                      }
                    }
       
                 }
               
           
//HORIZONTAL
             
                double y1,y2;
                for (p=1;p>=-1;p-=2)
                 {
//Subtraction
                  if((y>selection.Top) && (y<selection.Bottom-1) && CurrentPixel.A==255&&src[x,y-p].A==0)
                   {
                    for(i=x;src[i,y].A==255 && src[i,y-p].A<255 && i<selection.Right-1;i++);
                    for(j=x;src[j,y].A==255 && src[j,y-p].A<255 && j>selection.Left;j--);
                       
                    if(src[j,y].A==0&&x<=(i+j)/2) //going up
                    {
                     y1=((double)x+(0.5))/(i-j-1)+(0.5)*(i+j)/(j-i+1);
                     y2=((double)x-(0.5))/(i-j-1)+(0.5)*(i+j)/(j-i+1);
                     if(x==((i+j)/2)) CurrentPixel.A=(byte)(255-((y1/2)*127));
                      else CurrentPixel.A+=(byte)((y1+y2)*127);
                    }
                   if(src[i,y].A==0 &&x>=(i+j)/2)  //going down
                    {
                     y1=((double)x+(0.5))/(j-i+1)+(0.5)*(i+j)/(i-j-1);
                     y2=((double)x-(0.5))/(j-i+1)+(0.5)*(i+j)/(i-j-1);
                     if(x==((i+j)/2)) CurrentPixel.A=(byte)(255-((y2/2)*127));
                       else CurrentPixel.A+=(byte)((y1+y2)*127);
                    }
                  }
           
//Addition
                  if((y>selection.Top) && (y<selection.Bottom-1) && CurrentPixel.A==0&&src[x,y-p].A==255)
                   {   
                    for(i=x;src[i,y].A==0 && src[i,y-p].A==255&& i<selection.Right-1;i++);
                    for(j=x;src[j,y].A==0 && src[j,y-p].A==255&& j>selection.Left;j--);
                   
                    if(src[i,y].A==255&&x>=(i+j)/2) //going up
                    {
                    CurrentPixel=src[x,y-p];
                     y1=((double)x+(0.5))/(i-j-1)+(0.5)*(i+j)/(j-i+1);
                     y2=((double)x-(0.5))/(i-j-1)+(0.5)*(i+j)/(j-i+1);
                     if(x==((i+j)/2)) CurrentPixel.A=(byte)((y1/2)*127);
                       else CurrentPixel.A=(byte)((y1+y2)*127);
                    }
                   if(src[j,y].A==255&&x<=(i+j)/2) //going down
                    {
                     CurrentPixel=src[x,y-p];
                     y1=((double)x+(0.5))/(j-i+1)+(0.5)*(i+j)/(i-j-1);
                     y2=((double)x-(0.5))/(j-i+1)+(0.5)*(i+j)/(i-j-1);
                     if(x==((i+j)/2)) CurrentPixel.A=(byte)((y2/2)*127);else
                      CurrentPixel.A=(byte)((y1+y2)*127);
                    }
                  }
                 }     
                dst[x,y] = CurrentPixel;
            }
        }
    }
}


Last edited by pyjo on Mon Jan 14, 2008 3:56 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Basic Antialias
PostPosted: Tue Jan 08, 2008 2:54 pm 
Offline
User avatar

Joined: Tue Jul 25, 2006 10:12 pm
Posts: 3118
Location: Rochester, NY
Nice plugin!

pyjo wrote:
You'll find the tool in Effects>Contour submenu (is this the right menu for an antialias? Please give me a feedback).

I think the "Effects > Object" menu might be a better choice.

Also, you might want to release the source. We have a lot of great programmers here who might be able to assist you in adding to the greatness of this effect.

_________________
Image
Take responsibility for your own intelligence. ;) -Rick Brewster


Top
 Profile  
 
 Post subject: Re: Basic Antialias
PostPosted: Tue Jan 08, 2008 2:59 pm 
Offline
User avatar

Joined: Thu Aug 24, 2006 2:13 pm
Posts: 603
Location: Denmark
IMO, wee can newer have enough plugins to choose from. So thanks for posting. I am going to try it later.

_________________
Image
My DA: http://leif-j.deviantart.com/
--------------
Some people seek justice so persistent, that they will do great injustice themselves.


Top
 Profile  
 
 Post subject: Re: Basic Antialias
PostPosted: Tue Jan 08, 2008 5:14 pm 
Offline
User avatar

Joined: Tue Jul 25, 2006 10:12 pm
Posts: 3118
Location: Rochester, NY
Error:
Code:
File: C:\Program Files\Paint.NET\Effects\BasicAntialias10.dll
      Effect Name: PaintDotNet.Effects.UserScript
      Full error message: PaintDotNet.WorkerThreadException: Worker thread threw an exception ---> System.ArgumentOutOfRangeException: Coordinates out of range, max={Width=399, Height=299}
Parameter name: (x,y)
Actual value was {X=400,Y=264}.
   at PaintDotNet.Surface.get_Item(Int32 x, Int32 y)
   at PaintDotNet.Effects.UserScript.Render(Surface dst, Surface src, Rectangle rect)
   at PaintDotNet.Effects.UserScript.Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, Int32 startIndex, Int32 length)
   at PaintDotNet.Effects.BackgroundEffectRenderer.RendererContext.RenderImpl()
   --- End of inner exception stack trace ---
   at PaintDotNet.Effects.BackgroundEffectRenderer.Join()
   at PaintDotNet.Menus.EffectMenuBase.DoEffect(Effect effect, EffectConfigToken token, PdnRegion selectedRegion, PdnRegion regionToRender, Surface originalSurface, Exception& exception)


The error was achieved with this image.
Image

This image locks the plugin...
Image

_________________
Image
Take responsibility for your own intelligence. ;) -Rick Brewster


Top
 Profile  
 
 Post subject: Re: Basic Antialias
PostPosted: Tue Jan 08, 2008 6:14 pm 
Offline
Forum Moderator and 2008 "Radiance Award" Winner
User avatar

Joined: Sat Mar 03, 2007 7:17 pm
Posts: 3943
Location: Sheffield, England.
From first inspection, the plugin may be (dare I say after all my preaching) better than Anti-Alias. Madness it is.

And yes, I concur with barkbark00, Effects > Object would be the better location. It pairs quite nicely with pyrochild's Outline Object. Also confirming his bug, too.

Very good overall.

_________________


Top
 Profile  
 
 Post subject: Re: Basic Antialias
PostPosted: Tue Jan 08, 2008 10:11 pm 
Offline
2008 "GE Award for Plugin Brilliance" Winner
User avatar

Joined: Tue Apr 17, 2007 10:51 pm
Posts: 7288
Location: Colorado
Considering the fact that you even admit you don't understand your own code, it seems to give better results than Feather or AA plugins.

Good job!
Now... opensource it so we can help you fix those bugs :D

_________________
I'm Bike-Stick-Man and I approve this message I am right, so shut up.


Top
 Profile  
 
 Post subject: Re: Basic Antialias
PostPosted: Wed Jan 09, 2008 3:07 am 
Offline
User avatar

Joined: Tue May 29, 2007 4:33 pm
Posts: 478
Location: Coruscant
I get the same error like barkbark00.

Image

You should publish the code like pyrochild said, he is the plugin award winner for some good reasons.

And I believe the correct place for this is "Object", too.


Top
 Profile  
 
 Post subject: Re: Basic Antialias
PostPosted: Wed Jan 09, 2008 9:19 am 
Offline

Joined: Thu Oct 25, 2007 9:35 am
Posts: 80
Thanks for comments and bug report.
I'd like to publish the code, but at its current state it is so ugly that an experienced PdN plugin developer could find it obscene, and I don't want to violate again forum rule #12.
Now I'll try to fix the bug by myself, to add features and clean the code, so that I'll release the version 2.0 dll with the source. Then the developer community will possibly improve it.

About the bug: I think the error occurs only whan you antialias the entire picture and the solid shape touches the border of the canvas. The workaround is to apply Basic Antialias to a selection that doesn't touch borders.

Bye,
Pyjo.


Top
 Profile  
 
 Post subject: Re: Basic Antialias
PostPosted: Wed Jan 09, 2008 7:21 pm 
Offline
User avatar

Joined: Tue May 29, 2007 4:33 pm
Posts: 478
Location: Coruscant
If this is a help, the picture I worked on was 1280x800. This seems to be related to "out of range 1279x799" in the way you said.


Last edited by Fisherman's Friend on Sat Jan 12, 2008 2:16 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Basic Antialias
PostPosted: Fri Jan 11, 2008 12:19 am 
Offline
User avatar

Joined: Tue Oct 30, 2007 12:27 am
Posts: 255
Location: Sarasota, Florida
FYI
I got the same error as them.

_________________


Top
 Profile  
 
 Post subject: Re: Basic Antialias
PostPosted: Fri Jan 11, 2008 8:40 pm 
Offline
User avatar

Joined: Sun Feb 04, 2007 2:49 am
Posts: 135
Yeah, open-source it, and we (maybe) can help you solve the bug!
I met the same "coord out of range" bug too while developing my AA plugin. (fixed)
It's because when looping through pixels "around" the corners, some of them will get nasty values like "-1, -1" or "1281, 801."
Good plugin though!

Note: my AA plugin works only in "grow" mode, which means that the shape grow in size.
The more it grows the more smooth it is. 7 is the optimal (if growing doesn't matter).

_________________
Image
Some links: | Personal Website | Alien Attack |
Try out my plugins: | Antialias | Diagonal Lines |


Top
 Profile  
 
 Post subject: Re: Basic Antialias
PostPosted: Sat Jan 12, 2008 2:17 am 
Offline
User avatar

Joined: Tue May 29, 2007 4:33 pm
Posts: 478
Location: Coruscant
This sounds as if we already found the problem. :)


Top
 Profile  
 
 Post subject: Re: Basic Antialias version 1.1 - bug fixed (January 14 2008)
PostPosted: Tue Jan 15, 2008 10:41 am 
Offline
User avatar

Joined: Tue May 29, 2007 4:33 pm
Posts: 478
Location: Coruscant
pyjo wrote:
-EDIT-
The 1.1 release fixes the reported bug. Or, at least, I hope so. You find this new Basic Antialias in the Effects->Object submenu.


Yeah, now it works. :)

I think this is an excellent plugin, and it gives me better results than e.g. Feather (OK, that depends on the images you work on). However, it's worth a download. :wink:


Top
 Profile  
 
 Post subject: Re: Basic Antialias version 1.1 - bug fixed (January 14 2008)
PostPosted: Tue Jan 15, 2008 9:51 pm 
Offline

Joined: Fri Sep 14, 2007 11:09 pm
Posts: 1953
Now I'm all ticked off for rendering Eddie the Head before this plugin came out :roll:
Nice plugin, at first I thought the part of the moon that is absolutely diagonal (on the inside, about at the middle of the curve) looked a bit weird (~bit-weird, I can't help but think that :o), but that's the only flaw.

_________________
http://synthastic.deviantart.com
http://myspace.com/distodisco

Lockerz invites are available, PM me ;)


Last edited by Blooper on Wed Jan 16, 2008 1:20 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Basic Antialias version 1.1 - bug fixed (January 14 2008)
PostPosted: Wed Jan 16, 2008 2:01 am 
Offline
User avatar

Joined: Sun Feb 04, 2007 2:49 am
Posts: 135
One thing: on near 45 degree edges, it doesn't antialias at all.

Otherwise, great plugin!

_________________
Image
Some links: | Personal Website | Alien Attack |
Try out my plugins: | Antialias | Diagonal Lines |


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: georgian and 22 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Hosted by Forumer & phpBB

Get your Forumer™ today!

Adding a forum to your website is a great way to get return visitors.

» Get your own Free Forum!

Terms of Use

Privacy Policy

Report Abuse

Copyright © 2003-2009 Forumer. All Rights Reserved. | Copyright © paint.NET