FanofSMBX Posted June 14, 2019 Share Posted June 14, 2019 Hello, I have a plugin request, the attached image should explain it. I don't need color+transparencies to count as individual colors, just the color data. This will be helpful for my special method of resizing images which has better results than nearest neighbor but which it's very tedious to count the pixels in each region so I'm requesting just a ctrl+f that can recolor each region for me. Thank you. Quote Link to comment Share on other sites More sharing options...
FanofSMBX Posted June 15, 2019 Author Share Posted June 15, 2019 Can mod please change the title to reversed "Turn Selection to the Most Used Color in it (Plugin Request)" since it is hard to see from the forum homepage. Thank you Quote Link to comment Share on other sites More sharing options...
BoltBait Posted June 15, 2019 Share Posted June 15, 2019 You can change it by editing your initial post. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Computer Dominos Game Link to comment Share on other sites More sharing options...
MJW Posted June 15, 2019 Share Posted June 15, 2019 Is there some limitations on how it would be used. A selection could contain a million colors or more. If you don't mind me asking, what is the purpose of this proposed plugin? Why do to need a plugin to do this? Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted June 15, 2019 Share Posted June 15, 2019 Indeed the performance could be quite lousy if the selection is large. Try this code with CodeLab: Spoiler ColorBgra mode = ColorBgra.Zero; bool collision = false; void PreRender(Surface dst, Surface src) { Dictionary<ColorBgra, int> foundColors = new Dictionary<ColorBgra, int>(); Rectangle[] selRects = EnvironmentParameters.GetSelection(src.Bounds).GetRegionScansInt(); ColorBgra currentPixel; foreach (Rectangle rect in selRects) { 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].NewAlpha(byte.MaxValue); if (foundColors.ContainsKey(currentPixel)) { foundColors[currentPixel]++; } else { foundColors.Add(currentPixel, 1); } } } } KeyValuePair<ColorBgra, int> kvpMode = new KeyValuePair<ColorBgra, int>(ColorBgra.Zero, 0); foreach (var item in foundColors) { if (item.Value > kvpMode.Value) { kvpMode = item; } } mode = kvpMode.Key; collision = foundColors.Values.Where(value => value == kvpMode.Value).Count() > 1; if (collision) { PaintDotNet.Threading.PdnSynchronizationContext.Instance.Send(new SendOrPostCallback(delegate(object state) { // This line runs on the UI thread and not on the Render thread MessageBox.Show("Color Collision"); }), null); } } void Render(Surface dst, Surface src, Rectangle rect) { for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) return; for (int x = rect.Left; x < rect.Right; x++) { dst[x,y] = collision ? src[x,y] : mode; } } } https://forums.getpaint.net/topic/111233-codelab-for-average-users-a-laymans-guide/ Quote (September 25th, 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.