Nitor Posted November 22, 2015 Share Posted November 22, 2015 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. Quote Link to comment Share on other sites More sharing options...
BoltBait Posted November 22, 2015 Share Posted November 22, 2015 Please tell us what you are trying to accomplish with your plugin so we will know how to fix your algorithm. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Computer Dominos Game Link to comment Share on other sites More sharing options...
ReMake Posted November 22, 2015 Share Posted November 22, 2015 Pay attention to your formula: R = (R - (255 * alpha)) / (1 - alpha); It modifies the R component is too small. In the case where the Amount1 = 100 you get a black image. Quote Link to comment Share on other sites More sharing options...
Nitor Posted November 22, 2015 Author Share Posted November 22, 2015 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. Quote Link to comment Share on other sites More sharing options...
MJW Posted November 22, 2015 Share Posted November 22, 2015 Change the line to: double alpha = Amount1 / 100.0; Otherwise, the Amount1 / 100 is done as integer arithmetic. 1 Quote Link to comment Share on other sites More sharing options...
Nitor Posted November 22, 2015 Author Share Posted November 22, 2015 Thank you very much!!! Quote Link to comment Share on other sites More sharing options...
MJW Posted November 22, 2015 Share Posted November 22, 2015 You're most welcome. I'm glad I happened to spot that. Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted November 22, 2015 Share Posted November 22, 2015 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); Quote (June 9th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab 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.