Sign in to follow this  
Followers 0
Rei

Radial Fade

30 posts in this topic

OK, well this is my first plugin. Hope it's useful for more than just me.

This plugin will allow you to make your image gradually transparent going from the center to the edges (or vice-versa). The transparency gain over distance to the center is modulable, as well as the circle size.

 

If you have any feedback or suggestions, please share your opinion :)

 

This is what the UI looks like :

d041de4e3c.jpg

Before:

graphics-paintdotnet.png

After :

9e0819aea1.png

 

The main difference between this and the gradient tool is the 'Fade Rate' slider, i.e. the modulability of the transparency gain over distance.

Made with the CodeLab plugin for Paint.NET.

 

Installation guide :

Download the dll here:

RadialFade.zip

To install, either disregard the .bat and put the .dll in C:\Program Files\paint.net\Effects

or put both files on your desktop and double-click the .bat.

The second method is preferred if you are updating the plug-in.

It will be installed under Effects\Render.

PdN 3.5.11 users :

Maximilian has come to your rescue!

Download link in his post on page 2, make sure to upvote!

Changelog :

Hidden Content:

1.1 :

+ Added panning (thanks to MikeRobe for the idea!)

- Changed Fade Rate slider from integer values to real values

1.2 :

+ Fade-in (rather than out) checkbox

- Commented source code for readability

1.3 :

+ Made circle size adjustable

Source Code :

Hidden Content:

 

// Submenu: Render
// Name: Radial Fade
// Title: Rei's Radial Fade
// Author: Rei

#region UICode
double Amount1 = 3; // [0,10] Fade Rate
double Amount2 = 0; // [-100,100] X Pan %
double Amount3 = 0; // [-100,100] Y Pan %
double Amount4 = 100; // [0,1000] Circle Size %
bool Amount5 = false; // [0,1] Invert Alpha
#endregion
double distanceTo(int xPos, int yPos, int xTarget, int yTarget){
    //Pythagorean theorem
    return Math.Sqrt((double)((xTarget-xPos)*(xTarget-xPos)+(yTarget-yPos)*(yTarget-yPos)));
}

double getRadius(Rectangle bounds){
    //the Diameter is by default the biggest dimension (x or y) of the selection.
    //thus the Radius is half of that.
    return (Math.Max((bounds.Right-bounds.Left),(bounds.Bottom-bounds.Top))/2);
}
    

void Render(Surface dst, Surface src, Rectangle rect)
{
    Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    int centerX = ((selection.Right - selection.Left) / 2)+selection.Left;
    int centerY = ((selection.Bottom - selection.Top) / 2)+selection.Top;
    //centerX and centerY represent the coordinates of the center of the fade circle,
    //which is by default the center of the selection
    centerX += (int) ((Amount2 *(selection.Left-centerX))/100.0);
    centerY += (int) ((Amount3 *(selection.Bottom-centerY))/100.0);
    
    double radius=getRadius(selection)*(Amount4/100.0);

    ColorBgra CurrentPixel;
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
        {
            //here, we find out how far we are from the center of the fade circle to calculate alpha
            double distanceToCenter = distanceTo(x,y,centerX,centerY);
            CurrentPixel = src[x,y];
            
            if(!Amount5){
                if(distanceToCenter > radius)
                    CurrentPixel.A = (byte) 0;
                else
                    //distanceToCenter / radius gives us a raw representation of where the pixel is in the circle => how transparent it should be
                    //this value is taken to the 'Amount1'th power so our alpha distribution is customizable and non-linear
                    //we multiply this by 255 to scale from a [0.0,1.0] value to a byte
                    //255.0-<expression> will invert this value (without this it fades in)
                    CurrentPixel.A = (byte)  Math.Min((CurrentPixel.A),((255.0)-(Math.Pow((distanceToCenter / radius),Amount1) * 255.0)));
            }
            else
                CurrentPixel.A = (byte)  Math.Min((CurrentPixel.A),((Math.Pow((distanceToCenter / radius),Amount1) * 255.0)));
            
            dst[x,y] = CurrentPixel;
        }
    }
}

You are free to edit, use and publish this source in any way, whether you make or don't make profit off of it ; as long as I am mentioned as the original author and a link to this thread is provided.

EDIT : New license : Do what you want.

Edited by Rei
8

Share this post


Link to post
Share on other sites

Well done..... but can't this be done with the transparent option of the Gradient tool (in Radial mode)?

0

Share this post


Link to post
Share on other sites

It can indeed. I didn't  even see that option, and feel like an idiot for having gone through all that.
Meh, at least I got some experience out of it.

That being said, it seems to me the transparency gain over distance to center can't be tampered with, so I guess this still can be useful... -ish.

0

Share this post


Link to post
Share on other sites

You made a nice job of your first plugin. A good learning experience!

I'm sure some users will find it useful due to the slight differences between the two.

Are you going to compile the dll and upload it (zipped)? If you are, there are a few nice features you can include in the source before compiling. See http://www.boltbait.com/pdn/codelab/help/buildingdll.asp (under heading DEFAULTS).

0

Share this post


Link to post
Share on other sites

Thanks :) Strangely, I thought I added the zip with the dll and a .bat that installs it ; but it's obviously not there. Something must've gone wrong, I'll try it again.
 

If you are, there are a few nice features you can include in the source before compiling. See http://www.boltbait.com/pdn/codelab/help/buildingdll.asp (under heading DEFAULTS).

Thanks, I'll do that next time, but I already have the zip on my desktop, so I won't go through the whole recompiling process.

 

EDIT : OK, I  added the dll to my first post. Thanks for pointing that out, Ego.

Edited by Rei
0

Share this post


Link to post
Share on other sites

Puzzled. How to install another file ? In effects folder or somewhere else ?

0

Share this post


Link to post
Share on other sites

Sometimes I find the transparent gradient tool a bit tricky to use (lol), so I'm sure this plugin will come in handy!

 

Perhaps an option to pan the effect would also be useful! :)

1

Share this post


Link to post
Share on other sites

Puzzled. How to install another file ? In effects folder or somewhere else ?

I'm not sure what you mean. If you're wondering which submenu you can find the effect after installation; it should be Effects\Render.

 

 

Sometimes I find the transparent gradient tool a bit tricky to use (lol), so I'm sure this plugin will come in handy!

 

Perhaps an option to pan the effect would also be useful! :)

 

Great to know it's useful!

I'll try working on a panning system ; but in the meantime you can select the area you want to fade ; since this works by selection : it will fade from the center to the edge of the selection. You might be able to make do with that until I implement the panning. Thanks for the idea! :)

EDIT : Implemented panning :)

Edited by Rei
0

Share this post


Link to post
Share on other sites

Where does the Windows Batch File go please ? 

You put both files on your desktop and double-click the .bat. Or you put the dll file in Program Files\paint.net\Effects and the bat in the recycle bin.

0

Share this post


Link to post
Share on other sites

You put both files on your desktop and double-click the .bat. Or you put the dll file in Program Files\paint.net\Effects and the bat in the recycle bin.

Thanks for the prompt reply Rei :)

0

Share this post


Link to post
Share on other sites

Thanks for the prompt reply Rei :)

No problem~ if you have any suggestions or feedback, please do leave a comment :)

0

Share this post


Link to post
Share on other sites

You put both files on your desktop and double-click the .bat. Or you put the dll file in Program Files\paint.net\Effects and the bat in the recycle bin.

Hey, you're actually giving the answer I need. Thanks !

Cheerio !

0

Share this post


Link to post
Share on other sites

Hey, you're actually giving the answer I need. Thanks !

Cheerio !

Oh, great!

0

Share this post


Link to post
Share on other sites

Yeah got it added and it took 1 min instead hours and hours from a much earlier time.

 

Thank you!

0

Share this post


Link to post
Share on other sites

I see you've posted the source code, but I'm not seeing any sort of license. Please let us know what freedoms, if any, are available to us in relation the code.

0

Share this post


Link to post
Share on other sites

My guess is you're free to modify, obfuscate, and build on the posted code.  Even though no license or conditions have been mentioned, the author is still entitled to be credited with the original idea and code.  A solid attribution and perhaps a link to this thread would be a good idea.

0

Share this post


Link to post
Share on other sites

Love this plugin, i can finally do this:

ATGn8za.jpg

Going to put a request in to have this baked into the gradient tool

Edited by SAND33P
0

Share this post


Link to post
Share on other sites

I see you've posted the source code, but I'm not seeing any sort of license. Please let us know what freedoms, if any, are available to us in relation the code.

Done, thanks.

Edited by Rei
0

Share this post


Link to post
Share on other sites

This doesn't show up under Effects. I have re-downloaded and replaced the .dll file, but nothing works.

 

akzsdy.jpg

0

Share this post


Link to post
Share on other sites

Ah, thanks for the replies.

 

My computer is a bit of a mess at the moment. I'm in Bali on my laptop, which came with Windows 7 plus free upgrade to 8 and 8.1. Earlier in the year I installed Windows 10 with the Insider Program, but after too many gliches returned to Win 7. Unfortunately I now only have Win 7, I can no longer use free Win 8. Now, for some reason, my laptop refuses to install Win 7 SP1, which Paint.net 4.0 needs.

 

So thanks for the 3.5 version, I'll install when I get home.

0

Share this post


Link to post
Share on other sites

Welcome and best of lucks with that mess! hi.gif

0

Share this post


Link to post
Share on other sites

@Rei...I use this plugin all the time. Thank you so much for making it!    :)

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0