Popular Post Pratyush Posted February 3, 2018 Popular Post Share Posted February 3, 2018 (edited) Hi All, This plugin is an improvement on Jotaf's Grim Color Reaper. I use this plugin a lot but wanted some improvements, suddenly I realized that the since I can code a little and I can use the skill (?) . As, Jotaf has mentioned in his post that it is opensource, so I made one mine on Codelab version 3.3. The enhancement it has that It lets you now to choose color through UI instead of going through selecting primary color. It also has an option for keeping color i.e. while Grim Color Reaper 'kills' a specific color, Kill Color Keeper has an option to preserve specific color while killing every other one. User Interface: UI is similar to Grim reaper. It has options for tolerance and cut off value. But as a significant improvement, that it has Color Wheel inside UI so you can pick up color as desired. Default is still Primary Color. There are two option for Keep color and Kill color. There are two sliders which are dedicated to these two functions. I could have made it work with same slider, but default value for kill Color always turned out to make whole image transparent for Keep Color Option. Also, there was a need of different slider description . So, I made two dedicated sliders for them with their own default value and own description. In version 1.1, there are two sliders: Function Kill Color has only one slider for it while Keep Color has two sliders dedicated to it. 1. Original Image: 2. Kill color white i.e. background. 3. Keep Color Blue i.e. for dresses here. (Please ignore mistakes in UI name & values, this screen print was taken before final DLL was built.) Versions 1.1 In Keep Color Option if the original image pixel were transparent like this Then Keep Color Options would turn transparent pixels in white color (i.e there were given some opacity while running effect). 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. Versions 1.2 Updated UI to select Color. Source Code: Kill Color Keeper.cs Spoiler // Name:Kill Color Keeper // Submenu: Color // Author: Pratyush // Title: Kill Color Keeper v1.2 // Version: 1.2.0 // Desc: Removes or Preserves a color while maintaining the alpha information // Keywords: Color|Transparency|Alpha|Retention|Background // URL: // Help: #region UICode DoubleSliderControl Amount1 = 1; // [0,20] Color Tolerance: ColorWheelControl Amount2 = ColorBgra.FromBgr(0,0,0); // [PrimaryColor] {!Amount3} Select Color CheckboxControl Amount3 = false; // [0,1] Select Colors for Specific Values ListBoxControl Amount4 = 0; // {Amount3} What color?|Primary Color|Secondary Color|White|Gray|Black RadioButtonControl Amount5 = 0; // [1] Functions|Kill Color|Keep Color IntSliderControl Amount6 = 0; // [0,255] Consider transparent any alpha smaller than: IntSliderControl Amount7 = 255; // [0,255] {!Amount5} 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; ColorBgra color; if(!Amount3) color = Amount2; else //selecting things from dropdown switch(Amount4) { case 0: // Primary color color = (ColorBgra)EnvironmentParameters.PrimaryColor; break; case 1: // Secondary color color = (ColorBgra)EnvironmentParameters.SecondaryColor; break; case 2: // White color = ColorBgra.White; break; case 3: // Gray color = ColorBgra.Gray; break; default: // Black color = ColorBgra.Black; break; } //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); if (Amount5 != 1) { if (alpha <= Amount6) //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; 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)); } } else { if (Amount6 >= pixel.A); //Ignore transparent pixels else if (alpha >= Amount7) //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; alpha = alpha / 255; //normalize alpha to range 0..1 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; } } } I personally call it 'Color keeper' but didn't wanted to leave word 'Kill', I choose one between these two candidates: "Keep Color Killer" and "Kill Color Keeper". I hope you all will find it useful. Download here: Download Edited March 8, 2018 by Pratyush 5 5 Quote Link to comment Share on other sites More sharing options...
Pratyush Posted February 3, 2018 Author Share Posted February 3, 2018 (edited) @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. . Edited February 3, 2018 by Pratyush Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted February 3, 2018 Share Posted February 3, 2018 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. 1 Quote My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
Pratyush Posted February 3, 2018 Author Share Posted February 3, 2018 (edited) 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. Edited February 3, 2018 by Pratyush Quote Link to comment Share on other sites More sharing options...
Pratyush Posted February 3, 2018 Author Share Posted February 3, 2018 At last Post done and dusted. Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted February 3, 2018 Share Posted February 3, 2018 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)? Quote My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
Pratyush Posted February 3, 2018 Author Share Posted February 3, 2018 (edited) 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 February 10, 2018 by Pratyush Quote Link to comment Share on other sites More sharing options...
Pratyush Posted February 3, 2018 Author Share Posted February 3, 2018 (edited) 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 February 3, 2018 by Pratyush Quote Link to comment Share on other sites More sharing options...
ReMake Posted February 3, 2018 Share Posted February 3, 2018 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; } } } 1 Quote Link to comment Share on other sites More sharing options...
Pixey Posted February 4, 2018 Share Posted February 4, 2018 (edited) Great - you are on a roll @Pratyush I will definitely be using this - many thanks Oooooh - it's not downloading for me as of this minute Got it now - many thanks Edited February 5, 2018 by Pixey 1 Quote 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 More sharing options...
lynxster4 Posted February 5, 2018 Share Posted February 5, 2018 Thank you @Pratyush! 1 Quote My Art Gallery | My Shape Packs | ShapeMaker Mini Tut | Air Bubble Stained Glass Chrome Text with Reflections | Porcelain Text w/ Variegated Coloring | Realistic Knit PatternOpalescent Stained Glass | Frosted Snowman Cookie | Leather Texture | Plastic Text | Silk Embroidery Visit my Personal Website "Never, ever lose your sense of humor - you'll live longer" Link to comment Share on other sites More sharing options...
Pratyush Posted February 6, 2018 Author Share Posted February 6, 2018 (edited) On 2/5/2018 at 12:58 AM, Pixey said: Got it now - many thanks 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 February 6, 2018 by Pratyush 1 Quote Link to comment Share on other sites More sharing options...
Seerose Posted February 6, 2018 Share Posted February 6, 2018 @Pratyush! Thank you so much for new plugin and sharing. 1 Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi Link to comment Share on other sites More sharing options...
Pratyush Posted February 11, 2018 Author Share Posted February 11, 2018 Versions 1.1 value In Keep Color Option if the original image pixel were transparent like this Then Keep Color Options would turn transparent pixels in white color (i.e there were given some opacity while running effect). 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. 1 Quote Link to comment Share on other sites More sharing options...
Pratyush Posted March 8, 2018 Author Share Posted March 8, 2018 Versions 1.2 Updated UI to select Color. 3 2 Quote Link to comment Share on other sites More sharing options...
Seerose Posted March 8, 2018 Share Posted March 8, 2018 @Pratyush! Thanks for new version. 1 Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi Link to comment Share on other sites More sharing options...
lynxster4 Posted March 9, 2018 Share Posted March 9, 2018 Thank you for the updated version @Pratyush 2 Quote My Art Gallery | My Shape Packs | ShapeMaker Mini Tut | Air Bubble Stained Glass Chrome Text with Reflections | Porcelain Text w/ Variegated Coloring | Realistic Knit PatternOpalescent Stained Glass | Frosted Snowman Cookie | Leather Texture | Plastic Text | Silk Embroidery Visit my Personal Website "Never, ever lose your sense of humor - you'll live longer" Link to comment Share on other sites More sharing options...
Dominik Agejev Posted July 24, 2018 Share Posted July 24, 2018 (edited) The plugin is located in effects > color. Edited July 24, 2018 by Dominik Agejev Figured it out. Quote Link to comment Share on other sites More sharing options...
Casual Posted October 18, 2020 Share Posted October 18, 2020 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? Quote Link to comment Share on other sites More sharing options...
BoltBait Posted October 18, 2020 Share Posted October 18, 2020 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 1 Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
Doodles Posted December 19, 2021 Share Posted December 19, 2021 Hi, can someone help me with instruction on how to install this on Paint.net on Windows 11? Quote Link to comment Share on other sites More sharing options...
Ego Eram Reputo Posted December 20, 2021 Share Posted December 20, 2021 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 Quote ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker Link to comment Share on other sites More sharing options...
VolkerD Posted January 8, 2022 Share Posted January 8, 2022 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. Quote Link to comment Share on other sites More sharing options...
ML225 Posted November 14, 2022 Share Posted November 14, 2022 It would be wonderful if you could select a number of colours within a range, perhaps even using a dropper tool? Quote Link to comment Share on other sites More sharing options...
Panchdara Posted November 15, 2022 Share Posted November 15, 2022 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.