ReMake Posted October 14, 2021 Share Posted October 14, 2021 (edited) This is an update of the original and slightly forgotten Alpha Transform plugin by @DW-dev. See changelog below. This effect can be useful for creating an alpha mask of an image. Compatible with paint.net 4.3.2+ only Download from my PluginPack You can find it under Adjustments -> Alpha Transform This effect allows you to operate with the alpha value of a pixel based on an estimate of the maximum value of the R, G or B components (RGB color model) or its perceived brightness (YCbCr or YUV color model). The pixel brightness range is determined by two thresholds. Pixels with brightness less the lower limit get alpha set to 0 (fully transparent). Pixels with brightness more the upper limit get alpha set to 255 (fully opaque). Pixels with brightness in the range between the lower and upper limits get alpha set to a value between 0 and 255 depending on their brightness. Before: After: Color Model - a way to estimate the brightness of a pixel:RGB - by the maximum value of R, G, or B.YCbCr, YUV - by perceived pixel brightness.Set Alpha = 0 ... and Set Alpha = 255 ... is define the thresholds for changing the Alpha value.Invert Alpha values - switch between alpha and color.Replace RGB with Color - color selection:Source - without color replacementPrimary / Secondary / Grayscale / Custom - colors that replace the source color. CodeLab Source Spoiler // Name:Alpha Transform // Submenu: // Author:David Wilson & ReMake // Title:Alpha Transform // Version:1.3 // Desc:Alpha Transform Plugin for Paint.NET // Keywords:paint.net|effect|alpha|transform // URL:https://www.getpaint.net/redirect/plugins.html #region UICode ListBoxControl<model> Model = model.RGB; // Color Model|RGB|YCbCr|YUV IntSliderControl aLess = 0; // [0,100] Set Alpha = 0, if pixel brightness <= IntSliderControl aMore = 100; // [0,100] Set Alpha = 255, if pixel brightness > CheckboxControl Invert = false; // Invert Alpha values ListBoxControl<mode> Mode = 0; // Replace RGB with color|Source|Primary|Secondary|Grayscale|Custom ColorWheelControl Custom = ColorBgra.FromBgr(20, 50, 140); // [!] {!Mode} #endregion enum model { RGB, YCbCr, YUV } enum mode { Source, Primary, Secondary, Grayscale, Custom } void Render(Surface dst, Surface src, Rectangle rect) { Rectangle selection = EnvironmentParameters.SelectionBounds; ColorBgra PrimaryColor = EnvironmentParameters.PrimaryColor; ColorBgra SecondaryColor = EnvironmentParameters.SecondaryColor; 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]; int BR = 0; switch (Model) { case model.RGB: BR = (byte)((double)Math.Max(CurrentPixel.R, Math.Max(CurrentPixel.G, CurrentPixel.B)) / 2.55); break; case model.YCbCr: BR = (byte)(((4731 * CurrentPixel.B + 46869 * CurrentPixel.G + 13936 * CurrentPixel.R) >> 16) / 2.55); break; case model.YUV: BR = (byte)(CurrentPixel.GetIntensityByte() / 2.55); break; } BR = (BR <= aLess) ? CurrentPixel.A = 0 : ((BR > aMore) ? CurrentPixel.A = 255 : CurrentPixel.A = (byte)((BR - aLess) * 255 / (aMore - aLess))); if (Invert) { CurrentPixel.A = (byte)(255 - CurrentPixel.A); } switch (Mode) { case mode.Source: break; case mode.Primary: CurrentPixel.R = PrimaryColor.R; CurrentPixel.G = PrimaryColor.G; CurrentPixel.B = PrimaryColor.B; break; case mode.Secondary: CurrentPixel.R = SecondaryColor.R; CurrentPixel.G = SecondaryColor.G; CurrentPixel.B = SecondaryColor.B; break; case mode.Grayscale: CurrentPixel.R = CurrentPixel.A; CurrentPixel.G = CurrentPixel.A; CurrentPixel.B = CurrentPixel.A; break; case mode.Custom: CurrentPixel.R = Custom.R; CurrentPixel.G = Custom.G; CurrentPixel.B = Custom.B; break; } dst[x,y] = CurrentPixel; } } } Thanks to everyone who helped me create the interface of this effect. Changelog v1.3 (January 22, 2022) Added the Grayscale item to the color selection drop-down list. The icon has been changed (fixed). v1.2 (October 14, 2021) Added a drop-down list of color models. Changed behavior of Set Alpha... sliders(MinMax dependency). Added a color selection drop-down list. Changed the behavior of the Grayscale Alpha checkbox. v1.1 by @DW-dev (September 15, 2009) Initial release Edited January 22, 2022 by ReMake Updated 2 1 Quote Link to comment Share on other sites More sharing options...
lynxster4 Posted October 15, 2021 Share Posted October 15, 2021 Thank you for the update @ReMake. Yes, I'd forgotten about this plugin. 😊 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...
ReMake Posted October 16, 2021 Author Share Posted October 16, 2021 In two days, 100 views and 25 downloads - I'm impressed. Probably this plugin can be useful. I would like to know the opinion of other members about this plugin. Is there a need to include it in my Plugin Pack? 1 Quote Link to comment Share on other sites More sharing options...
lynxster4 Posted October 17, 2021 Share Posted October 17, 2021 I definitely would like to see it included in your pack @ReMake. There is so much control over what you can achieve! ☺️ 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...
user.by Posted October 20, 2021 Share Posted October 20, 2021 thank for works and update 1 Quote Link to comment Share on other sites More sharing options...
ReMake Posted January 22, 2022 Author Share Posted January 22, 2022 The effect has been updated to version 1.3. The Grayscale Alpha checkbox has been removed in the new version, its function has been moved to the Replace RGB with Color drop-down list. This made it possible to simplify the user interface. The effect icon has been changed (fixed) according to the plan (in the previous version it was accidentally rotated 180° vertically). 3 2 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.