Jump to content
How to Install Plugins ×

Bevel Plugin [v1.4, August 22]


jsonchiu

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.

siggiecj5.png

Some links: | Personal Website | Alien Attack |

Try out my plugins: | Antialias | Diagonal Lines |

Link to comment
Share on other sites

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!

 

Take responsibility for your own intelligence. 😉 -Rick Brewster

Link to comment
Share on other sites

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.

Link to comment
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

time-smaller.png
Link to comment
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!

 

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.

Link to comment
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.

Link to comment
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.

No. Way. I've just seen Bob. And... *poof!*—just like that—he disappears into the mist again. ~Helio

Link to comment
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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...