IceCave Posted December 17, 2019 Share Posted December 17, 2019 (edited) I am trying to wrap my head around it, but I can't find a function that blends these colors (122, 141, 153) and (0, 0, 0) into this one (0, 27, 51) Edited December 17, 2019 by IceCave Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted December 17, 2019 Share Posted December 17, 2019 Here's the function for Overlay blend, with your example values: ColorBgra lhs = ColorBgra.FromBgr(153, 141, 122); ColorBgra rhs = ColorBgra.FromBgr(0, 0, 0); byte r = lhs.R < 128 ? Int32Util.ClampToByte(2 * rhs.R * lhs.R / byte.MaxValue) : Int32Util.ClampToByte(byte.MaxValue - 2 * (byte.MaxValue - rhs.R) * (byte.MaxValue - lhs.R) / byte.MaxValue); byte g = lhs.G < 128 ? Int32Util.ClampToByte(2 * rhs.G * lhs.G / byte.MaxValue) : Int32Util.ClampToByte(byte.MaxValue - 2 * (byte.MaxValue - rhs.G) * (byte.MaxValue - lhs.G) / byte.MaxValue); byte b = lhs.B < 128 ? Int32Util.ClampToByte(2 * rhs.B * lhs.B / byte.MaxValue) : Int32Util.ClampToByte(byte.MaxValue - 2 * (byte.MaxValue - rhs.B) * (byte.MaxValue - lhs.B) / byte.MaxValue); ColorBgra overlayColor = ColorBgra.FromBgr(b, g, r); More here: https://github.com/toehead2001/pdn-blendmodes-plus/blob/master/BlendModesPlus/EffectPlugin.cs#L589 1 Quote My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
IceCave Posted December 17, 2019 Author Share Posted December 17, 2019 So it takes the destination color in order to decide between Screen and Overlay and not the source color. Interesting. Thank you very much. Very helpful. Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted December 17, 2019 Share Posted December 17, 2019 2 minutes ago, IceCave said: So it takes the destination color in order to decide between Screen and Overlay and not the source color. Well, you decide which color is the source and which is the destination. The Screen blend mode uses a totally different algorithm, and is not involved in the code I posted. Quote My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
IceCave Posted December 17, 2019 Author Share Posted December 17, 2019 (edited) Well, yeah, true... anyone finding this topic over Google: rhs is the pixel color of the top layer (the one set to overlay) lhs is the blend color of the bottom layers 17 minutes ago, toe_head2001 said: The Screen blend mode uses a totally different algorithm, and is not involved in the code I posted. I was referring to the documentation, I haven't actually checked https://www.getpaint.net/doc/latest/BlendModes.html#16 Edited December 17, 2019 by IceCave Quote Link to comment Share on other sites More sharing options...
Reptillian Posted December 17, 2019 Share Posted December 17, 2019 (edited) For the float version of the overlay blending mode formula - a-base b-blend f(a,b)= a<.5 ? 2ab : 1-2(1-a)(1-b) ; This implies that the ranges has to be normalized to 0-1 ranges before calculation. Edited December 17, 2019 by Reptillian Quote G'MIC Filter Developer 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.