Jump to content
How to Install Plugins ×

Kill Color Keeper v 1.2


Pratyush

Recommended Posts

@BoltBait I think this is first published plugin which is made with codelab v3.3 using feature for disabling UI. Thanks and Congratulations for all that work. :mrblue: :beer:.

Edited by Pratyush

Rl7un0O.png

Link to comment
Share on other sites

RGBA (and BGRA) values don't have decimal points. Therefore, the two alpha sliders should be IntSliderControl, not DoubleSliderControl.

 

15 minutes ago, Pratyush said:

Since, Jotaf has mentioned in his post that it is opensource, so I made mine on Codelab version 3.3.

You should also posted your modified source code. Maybe someone will to make enhancements in the future; just as you did.

  • Like 1

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

I am doing that. I have not still completed the post, edited over five times already.

EDIT: Thanks for the insight on BGRA, I am changing slider values.:biggrin:

Edited by Pratyush

Rl7un0O.png

Link to comment
Share on other sites

47 minutes ago, Pratyush said:

//simple way of figuring out the alpha: the more distant the colors,

//the larger the alpha.

alpha = Amount1 * Math.Sqrt(rdif*rdif + gdif*gdif + bdif*bdif);

 

Can you explain this to me?  How does that equal alpha (the level of opacity)?  Maybe you mean delta (the difference of change)?

 

 

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

On 2/3/2018 at 1:31 PM, toe_head2001 said:

Can you explain this to me?  How does that equal alpha (the level of opacity)?  Maybe you mean delta (the difference of change)?

 

Maybe Jotaf can explain that, I was also wondering what that meant. That comment line is from original code so I let that be there. 

Edited by Pratyush

Rl7un0O.png

Link to comment
Share on other sites

 

6 hours ago, toe_head2001 said:

How does that equal alpha (the level of opacity)?  Maybe you mean delta (the difference of change)?

 

@toe_head2001  I think that this is about plugin function. This plugin does doesn't affect RGB channels but only alpha of pixels. The alpha values are changed according to delta of a color. Since final alpha values are depended on that, he may have named like that way. I am also not sure about exact reason.

 

EDIT: I think the idea of plugin is make transparency proportional to euclidean distance between color. So, final alpha is proportional to (some constant)*(Delta of color). Once final alpha is defined the way, we know that final = foreground*alpha + backgroud*(1 - alpha) where is alpha is between 0 and 1.  after solving back for alpha we obtain: foreground = (final - background*(1-alpha)) / alpha. 

Edited by Pratyush

Rl7un0O.png

Link to comment
Share on other sites

Your code has the repeating lines. May I offer you simplify the code by removing extra lines?

Spoiler

// Name:Kill Color Keeper
// Submenu: Color
// Author: Pratyush
// Title: KillColorKeeper
// Version: 1.0.0
// Desc: Removes or Preserves a color while maintaining the alpha information
// Keywords: Color|Transparency|Alpha|Retention
// URL:
// Help:
#region UICode
DoubleSliderControl Amount1 = 1; // [0,20] Color tolerance:
ColorWheelControl Amount2 = ColorBgra.FromBgr(0,0,0); //[PrimaryColor] Select Color
RadioButtonControl Amount3 = 1; // [1] Functions|Keep Color|Kill Color
IntSliderControl Amount4 = 0; // [0,255] {!Amount3} Consider transparent any alpha smaller than:
IntSliderControl Amount5 = 255; // [0,255] {Amount3} Consider transparent any alpha greater than:
#endregion

//Kill Color Keeper by Pratyush
//Based on Original Grim Color Reaper by Jotaf

void Render(Surface dst, Surface src, Rectangle rect)
{
    ColorBgra color = Amount2;


    //color as double
    double R = color.R, G = color.G, B = color.B;

    ColorBgra pixel;
    double rdif, gdif, bdif;
    double alpha;

    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        for (int x = rect.Left; x < rect.Right; x++)
        {
            pixel = src[x,y];

            //difference between this pixel's color and the color to erase
            rdif = pixel.R - R;
            gdif = pixel.G - G;
            bdif = pixel.B - B;

            //simple way of figuring out the alpha: the more distant the colors,
            //the larger the alpha.
            alpha = Amount1 * Math.Sqrt(rdif*rdif + gdif*gdif + bdif*bdif);

            switch (Amount3)
            {
                case 0:
                if (alpha <= Amount4)  //alpha cut-off (fully transparent)
                    pixel.A = 0;
                else if (alpha < pixel.A)    //only apply change if it causes a pixel to become more
                                             //transparent (to blend nicely with existing alphas)
                    pixel.A = (byte) alpha;
                    break;
                case 1:
                if (alpha >= Amount5)  //alpha cut-off (fully opaque)
                    pixel.A = 0;
                else if (alpha > pixel.A)    //only apply change if it causes a pixel to become more
                                             //transparent (to blend nicely with existing alphas)
                    pixel.A = (byte) alpha;
                    break;
            }
            
            alpha = alpha / 255;  //normalize alpha to range 0..1

            //we assume that each pixel is the result of linear interpolation between an
            //unknown foreground color, and the user selected background color, which
            //means it obeys the equation: (for each of Red, Green and Blue)
            //  final = foreground*alpha + background*(1-alpha)
            //we already figured out the alpha, so we just need to invert the equation
            //to obtain the original foreground color:
            //  foreground = (final - background*(1-alpha)) / alpha
            pixel.R = Int32Util.ClampToByte((int) (((double) pixel.R - R*(1-alpha)) / alpha));
            pixel.G = Int32Util.ClampToByte((int) (((double) pixel.G - G*(1-alpha)) / alpha));
            pixel.B = Int32Util.ClampToByte((int) (((double) pixel.B - B*(1-alpha)) / alpha));
            dst[x,y] = pixel;
        }
    }
}

 

 

  • Like 1
Link to comment
Share on other sites

Great - you are on a roll @Pratyush :star: I will definitely be using this - many thanks :D

 

Oooooh - it's not downloading for me as of this minute :|  Got it now - many thanks :star:

Edited by Pixey
  • Like 1

30b8T8B.gif

How I made Jennifer & Halle in Paint.net

My Gallery | My Deviant Art

"Rescuing one animal may not change the world, but for that animal their world is changed forever!" anon.

 
Link to comment
Share on other sites

On 2/5/2018 at 12:58 AM, Pixey said:

Got it now - many thanks :star:

It's great that you have got that, I was going to recommend you compile the effect on Codelab itself as the code was present on desktop.

Thanks @Pixey, and thank you very much @lynxster4 for complements.

Edited by Pratyush
  • Like 1

Rl7un0O.png

Link to comment
Share on other sites

Versions 1.1 

value In Keep Color Option if the original image pixel were transparent like this :arrow-down:

EKnbrDy.png

 

Then Keep Color Options would turn transparent pixels in white color (i.e there were given some opacity while running effect).

YVnWbCJ.png

So new version checks that if Alpha is less than given threshold values. I used first sliders to ignore less opaque pixels. UI is changed, now both sliders will active for Keep Color and only first slider is active for Kill Color.  

  • Upvote 1

Rl7un0O.png

Link to comment
Share on other sites

Link to comment
Share on other sites

  • 4 months later...
  • 2 years later...

so I'm a beginner in paint.net and i have no idea on how mostly things work so if i download the file it is automatically activate or i need to move it to other files? 

Link to comment
Share on other sites

7 minutes ago, Casual said:

so I'm a beginner in paint.net and i have no idea on how mostly things work so if i download the file it is automatically activate or i need to move it to other files? 

 

https://boltbait.com/pdn/InstallingEffects.php

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

If the link in the post above yours didn't help, you're probably using the Store version. See this page in the documentation about how to create the necessary folders

 

https://www.getpaint.net/doc/latest/InstallPlugins.html

Link to comment
Share on other sites

  • 3 weeks later...

Thanks for this great tool. I had to make a color transparent in my wife's logo. On her iMac the pre-installed tool "paints" asked for an upgrade as the logo is bigger than 800px in width. Thanks to paint.net and your great tool it was an effort of 5 minutes (including donwload of everything) on my windows 10 computer.

 

I copied your DLL into the effects sub-folder of paint.net and after a restart of paint.net the actual change was done in a minute.

Link to comment
Share on other sites

  • 10 months later...

Thank you Pratyush.

 

Out of curiosity, 2 questions:

1) What's up on line 100? Empty statement.

2) When I open the plug-in is does show version 1.2, but when I hover over it is shows File version 1.0.8354.20695 - that I just don't understand. Where is this "File version" determined? Just curious.

 

Best

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...