Jump to content

Plugin don't work. Help! Source code included.


Nitor
 Share

Recommended Posts

Hello everyone. I'm trying to develop my first plugin. It compiles successfuly, but don’t work. Source code:

#region UICode
IntSliderControl Amount1 = 50; // [0,100] Alpha
#endregion

private byte Clamp2Byte(int iValue)
{
    if (iValue < 0) return 0;
    if (iValue > 255) return 255;
    return (byte)iValue;
}

void Render(Surface dst, Surface src, Rectangle rect)
{
    ColorBgra CurrentPixel;
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        for (int x = rect.Left; x < rect.Right; x++)
        {
            CurrentPixel = src[x, y];

            double R = (int)CurrentPixel.R;
            double G = (int)CurrentPixel.G;
            double B = (int)CurrentPixel.B;

            double alpha = Amount1 / 100;

            R = (R - (255 * alpha)) / (1 - alpha);
            G = (G - (255 * alpha)) / (1 - alpha);
            B = (B - (255 * alpha)) / (1 - alpha);

            CurrentPixel = ColorBgra.FromBgra(Clamp2Byte((int), Clamp2Byte((int)G), Clamp2Byte((int)R), CurrentPixel.A);
            dst[x, y] = CurrentPixel;
        }
    }
}

Help me pls.

Link to comment
Share on other sites

Ok. Blend white (with alpha) layer with colored layer and you will get new layer with new color. I want to get original colored layer with this formula: backgroundColour = (finalColour - (255 * foregroundAlpha)) / (1 - foregroundAlpha) (formula was tested by me). It get's ForegroundAlpha from Amount1 variable. After getting original colored layer it replaces finalColour to backgroundColour.

Link to comment
Share on other sites

On 11/22/2015 at 8:19 AM, Nitor said:

private byte Clamp2Byte(int iValue)
{
    if (iValue < 0) return 0;
    if (iValue > 255) return 255;
    return (byte)iValue;
}
...

CurrentPixel = ColorBgra.FromBgra(Clamp2Byte((int)B), Clamp2Byte((int)G), Clamp2Byte((int)R), CurrentPixel.A);

 

You don't need to write your own 'clamp to byte' function. There is already one inside paint.net. You can shave off those extra 5 lines of code.

Int32Util.ClampToByte()

Here's how it would look in your code:

CurrentPixel = ColorBgra.FromBgra(Int32Util.ClampToByte(B), Int32Util.ClampToByte(G), Int32Util.ClampToByte(R), CurrentPixel.A);
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.

 Share

×
×
  • Create New...