Sign in to follow this  
jsonchiu

Bevel Plugin [v1.4, August 22]

Recommended Posts

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:
8192a850.png ->8192a850jt9.png

A few buttons on Ash's siggie:
55122628dz4.png

This link appears to be broken (09 Feb 2013 - EER) >>  dll: http://jason.jjtchiu.com/downloads/Bevel_v1.4.0.0.dll 

 

Download the DLL from the attachment at the bottom of this post.

source:

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. + (diff * (float)CurrentPixel.);
    
    //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"

Bevel_v1.4.0.0.zip

Edited by Ego Eram Reputo
Attached zipped dll.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

Looking good, thanks for this!

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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Lovely plugin. A request: Could you allow for a negative range as well?

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

Could you add a "Invert" button or checkbox, like in the I&BB Gradient plugin?

Btw, thanks for the great responses!

Deserved.

Share this post


Link to post
Share on other sites

Well, in reply to jsonchiu's request to post something that can be done with it (Great plugin BTW - I had posted a tutorial on how to do this manually earlier) here is a cool looking frame I came up with using just the bevel effect here.

Request - any way that you can get it to support odd shapes? Right now it only creates square box bevels. So if you select a round shape, it doesnt work quite right on it.

Anyway, here's the pic

bevelframe.jpg

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