Paint.NET

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

All times are UTC


Forum rules


Questions or problems with plugin installation? Click here.



Post new topic Reply to topic  [ 72 posts ]  Go to page 1, 2, 3, 4, 5  Next
Author Message
 Post subject: Bevel Plugin [v1.4, August 22]
PostPosted: Tue Aug 21, 2007 8:03 pm 
Offline
User avatar

Joined: Sun Feb 04, 2007 2:49 am
Posts: 135
Meh the bevel effect available in most image editing programs (except pdn)

This effect will be under the menu Effects->Renders

Primary color = highlight
Secondary color = shadow

Example:

Ash's tiger:
Image ->Image

A few buttons on Ash's siggie:
Image

dll: http://jason.jjtchiu.com/downloads/Bevel_v1.4.0.0.dll

source:
Code:
int Amount1=7;   //[0,200]Depth
int Amount2=20;   //[0,100]Strength

void Render(Surface dst, Surface src, Rectangle rect)
{
    PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);

    // Delete any of these lines you don't need
    Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();

    long CenterX = (long)(((selection.Right - selection.Left) / 2)+selection.Left);
    long CenterY = (long)(((selection.Bottom - selection.Top) / 2)+selection.Top);
    int left = (int)selection.Left;
    int top = (int)selection.Top;
    int right = (int)selection.Right;
    int bottom = (int)selection.Bottom;
    ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
    ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;
    int BrushWidth = (int)EnvironmentParameters.BrushWidth;

    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];
                //top
                if ((x-left) >= (y-top) && (y-top) <= Amount1 && x+(y-top) < right)
                {
                    CurrentPixel = transformPixel(y-top, CurrentPixel, PrimaryColor);
                }
                //left
                else if ((y-top) >= (x-left) && (x-left) <= Amount1 && (x-left)+y < bottom)
                {
                    CurrentPixel = transformPixel(x-left, CurrentPixel, PrimaryColor);
                }
                //bottom
                else if ((x-left) >= (bottom-y) && (bottom-y) <= Amount1 && x+(bottom-y) <= right)
                {
                    CurrentPixel = transformPixel(bottom-y, CurrentPixel, SecondaryColor);
                }
                //right
                else if ((y-top) >= (right-x) && (right-x) <= Amount1 && (right-x)+y < bottom)
                {
                    CurrentPixel = transformPixel(right-x, CurrentPixel, SecondaryColor);
                }
                dst[x,y] = CurrentPixel;
            }
        }
    }
}
ColorBgra transformPixel(float px_from_edge, ColorBgra CurrentPixel, ColorBgra NewColor)
{
    //set amount of background interference 0~1 (ie how much it blends to the background)
    float diff = (float)(0.05 + px_from_edge/Amount1);
    float strength = (float)((float)(100 - Amount2) / 100 + (float)0.35);
    diff = diff * strength;
    if (diff > 1)
    {
        diff = 1;
    }
    else if (diff < 0)
    {
        diff = 0;
    }
   
    //some vars just for convenience, more readable
    float div = diff + 1;
    float invrt_diff = 1 - diff;
   
    //we set the RGB to primary color if it is completely transparent (black is the default)
    //That should solve
    if (CurrentPixel.A == 0)
    {
        CurrentPixel.R = NewColor.R;
        CurrentPixel.G = NewColor.G;
        CurrentPixel.B = NewColor.B;
    }
   
    //and we are ready to color the pixels
    //ex: if 70% background interference
    //we have 70% of original color's R plus 30% of the new color's R
    CurrentPixel.R = (byte)((invrt_diff * (float)NewColor.R) + (diff * (float)CurrentPixel.R));
    CurrentPixel.G = (byte)((invrt_diff * (float)NewColor.G) + (diff * (float)CurrentPixel.G));
    CurrentPixel.B = (byte)((invrt_diff * (float)NewColor.B) + (diff * (float)CurrentPixel.B));
   
    //transparency values need special manipulation to prevent bad-looking renders
    float temp = CurrentPixel.A + NewColor.A;
    if (temp > 255)
    {
        temp = 255;
    }
    temp = ((int)CurrentPixel.A + temp) / 2;
    if (CurrentPixel.A < 255)
    {
        temp = temp * (1 + (float)invrt_diff);
    }
    if (temp > 255)
    {
        temp = 255;
    }
    CurrentPixel.A = (byte)temp;
   
    //and we are done
    return CurrentPixel;
}


Enjoy!

Update1: fixed selection bug. The plugin should now be able to apply filter to selected areas.
Update2: fixed transparency bug. It should now render correctly.
Update3: moved to Effects->Renders
Update4: fully fixed transparency "color"

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


Last edited by jsonchiu on Tue Aug 28, 2007 5:56 am, edited 16 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 21, 2007 8:04 pm 
Offline
Site Admin, 2008 "Monet" Award Winner, and 2008 King of Paint.NET
User avatar

Joined: Fri Dec 22, 2006 8:29 am
Posts: 5708
Location: http://tinyurl.com/6kqz9v
Post some screen shots to show what the plugin can do.

_________________
Image
All creations Ash + Paint.NET [ Googlepage | deviantArt | Club PDN | PDN Fan ]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 21, 2007 8:16 pm 
Offline
User avatar

Joined: Sun Feb 04, 2007 2:49 am
Posts: 135
Ash wrote:
Post some screen shots to show what the plugin can do.

Fine. I thought everybody knows what it is... it's very common in image manipulation programs. :roll:

EDIT: screenshots added

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 21, 2007 8:51 pm 
Offline
User avatar

Joined: Tue Jul 25, 2006 10:12 pm
Posts: 3118
Location: Rochester, NY
This plugin doesn't work on a selection or on any objects that are in an otherwise transparent canvas. Other than that it looks great!

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 21, 2007 8:58 pm 
Offline
User avatar

Joined: Fri Apr 06, 2007 10:22 pm
Posts: 346
very nice but like BB00 said, doesn't work on selection. Perhaps you can put this under render submenu as well.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 21, 2007 10:22 pm 
Offline
User avatar

Joined: Tue May 29, 2007 4:33 pm
Posts: 478
Location: Coruscant
Jsonchiu, I really appreciate that you publish the source code side by side with your plugins. This is a great help for people learning to code. Thank you very much. And congrats for your new plugin.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 21, 2007 11:49 pm 
Offline
User avatar

Joined: Sat Feb 10, 2007 3:09 am
Posts: 2522
Location: Bolivar, MO
Thanks man! :)

_________________
Image
"Sadness is easier because it's surrender...I CHOOSE TO FIGHT"
My Gallery


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 22, 2007 12:03 am 
Offline
User avatar

Joined: Thu May 31, 2007 7:03 pm
Posts: 95
Location: Vancouver-ish, Canada
Oh, that's lovely. If you could just get it to work on an object in a transparent canvas (instead of the whole canvas), it would be perfect. :D


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 22, 2007 12:31 am 
Offline
Forum Moderator and 2008 "Radiance Award" Winner
User avatar

Joined: Sat Mar 03, 2007 7:17 pm
Posts: 3943
Location: Sheffield, England.
Cool, this is most definitely going to be handy, thanks!

Menu icon? :D

I have a few suggestions if you wish, but I'm very happy with anything. :D

_________________


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 22, 2007 2:42 am 
Offline
User avatar

Joined: Sun Feb 04, 2007 2:49 am
Posts: 135
Fixed selection bug. It should now be able to apply effect to selected areas.

I'm trying to solve the transparency bug... It should be done pretty soon.

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 22, 2007 3:06 am 
Offline
Forum Admin and 2008 "Proton Award" Winner
User avatar

Joined: Tue Feb 06, 2007 9:45 pm
Posts: 9483
Location: Indianapolis, IN (39°46′5.88″N 86°9′29.52″W)
You should zip it. Some people can't direct download .DLLs because of proxy blockers or Browser Settings.

Nevertheless, I like this a lot. Good work!

_________________


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 22, 2007 4:27 am 
Offline
User avatar

Joined: Fri Apr 06, 2007 10:22 pm
Posts: 346
Looking good, thanks for this!

jsonchiu wrote:
Fixed selection bug. It should now be able to apply effect to selected areas.

I'm trying to solve the transparency bug... It should be done pretty soon.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 22, 2007 5:06 am 
Offline
User avatar

Joined: Sun Feb 04, 2007 2:49 am
Posts: 135
Update: fixed transparency bug. Also, improved the render a little bit (it should be smoother now), and added a menu icon.

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 22, 2007 5:17 am 
Offline

Joined: Wed Jun 28, 2006 3:36 am
Posts: 183
Lovely plugin. A request: Could you allow for a negative range as well? That would really be super for some purposes!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 22, 2007 5:24 am 
Offline
User avatar

Joined: Sun Feb 04, 2007 2:49 am
Posts: 135
davidtayhs wrote:
Lovely plugin. A request: Could you allow for a negative range as well? That would really be super for some purposes!

You can just reverse the primary color and the secondary color.

Btw, thanks for the great responses!

_________________
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  [ 72 posts ]  Go to page 1, 2, 3, 4, 5  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 33 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