geist_ Posted February 16, 2021 Share Posted February 16, 2021 (edited) VERSION: Only checked for paint.net version 4.2.15. Adjustments > Make Palette(.dll) As the name suggests, from the current selection the plugin/adjustment will make an "UntitledPalette.txt" file in your \Documents\paint.net User Files\Palettes with each color taken only once. It also displays how many unique colors are in the palette. MakePalette.zip Edited March 11, 2021 by geist_ 3/11/2021 updated to toe_head's code. 1 Quote the usual Link to comment Share on other sites More sharing options...
Ladybug Posted February 17, 2021 Share Posted February 17, 2021 @geist_ thanks for sharing your plugin 🙂. I tried it on two different images and it created a separate palette for both but it only created the palette with the color most used in the image. I do have 2 requests if they are not too much trouble. Could the plugin save the palette to Documents\paint.net App Files\Palettes instead? That is where the other palettes appear. And lastly, is there a way to allow the user to give the palette a name before it saves? I have included the 2 images I tried the plugin on and provided a link to the corresponding palette that was created. Thanks again for your time to make the plugin. Image 1 and link to corresponding palette: UntitledPalette1.txt Image 2 and link to corresponding palette: UntitledPalette2.txt 1 Quote Click HERE to see my Pictorium of images I have worked on. You were once wild here. Don't let them tame you. ~ Isadora Duncan Link to comment Share on other sites More sharing options...
ANONYMISS Posted February 17, 2021 Share Posted February 17, 2021 Crashed. Twice. File: C:\Program Files\Paint.NET\Effects\Make Palette.dll Name: MakePaletteEffect.MakePaletteEffectPlugin Version: 1.0.7716.40392 Author: Copyright ©2021 Copyright: Make Palette selected pixels Website: https://www.getpaint.net/redirect/plugins.html Full error message: PaintDotNet.WorkerThreadException: Worker thread threw an exception ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\users\Ray\Documents\paint.net User Files\Palettes\UntitledPalette1.txt'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) at MakePaletteEffect.MakePaletteEffectPlugin.MakePaletteFile(String _fileName, List`1 _colors, Int32 _colorsAmount) at MakePaletteEffect.MakePaletteEffectPlugin.Render(Surface dst, Surface src, Rectangle rect) at MakePaletteEffect.MakePaletteEffectPlugin.OnRender(Rectangle[] rois, Int32 startIndex, Int32 length) at PaintDotNet.Effects.Effect`1.Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, Int32 startIndex, Int32 length) in D:\src\pdn\src\Effects\Effect`1.cs:line 99 at PaintDotNet.Effects.BackgroundEffectRenderer.RenderWithClipMask(Effect effect, EffectConfigToken token, RenderArgs dstArgs, RenderArgs srcArgs, RectInt32[] rois, Result`1 lazyClipMaskRenderer) in D:\src\pdn\src\PaintDotNet\Effects\BackgroundEffectRenderer.cs:line 192 at PaintDotNet.Effects.BackgroundEffectRenderer.RendererContext.RenderTile(EffectConfigToken token, Int32 tileIndex) in D:\src\pdn\src\PaintDotNet\Effects\BackgroundEffectRenderer.cs:line 172 at PaintDotNet.Effects.BackgroundEffectRenderer.RendererContext.RenderNextTile(EffectConfigToken token) in D:\src\pdn\src\PaintDotNet\Effects\BackgroundEffectRenderer.cs:line 164 at PaintDotNet.Effects.BackgroundEffectRenderer.ThreadFunction() in D:\src\pdn\src\PaintDotNet\Effects\BackgroundEffectRenderer.cs:line 282 --- End of inner exception stack trace --- at PaintDotNet.Effects.BackgroundEffectRenderer.DrainExceptions() in D:\src\pdn\src\PaintDotNet\Effects\BackgroundEffectRenderer.cs:line 451 at PaintDotNet.Menus.EffectMenuBase.DoEffect(Effect effect, EffectConfigToken token, Result`1 lazySelectionScans, Result`1 lazyRegionToRenderScans, Result`1 lazyClipMaskRenderer, Surface originalSurface, Exception& exception) in D:\src\pdn\src\PaintDotNet\Menus\EffectMenuBase.cs:line 0 1 Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted February 17, 2021 Share Posted February 17, 2021 Moved to the 'Plugin Developer's Central' area. @geist_, your code has some serious issues. If you post the source, we can help you fix it. 1 1 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...
geist_ Posted February 17, 2021 Author Share Posted February 17, 2021 @toe_head2001 @ANONYMISS I think the reason it crashed is because it's supposed to store the file in C:\Users\name\Documents\paint.net User Files\Palettes\ which i thought was made by default. Also @Ladybug thanks for checking it out, it means a lot! The main reason i made this was for characters/item sprites, not really for landscapes, and yes, i will change it so the user can choose a name for the file before it saves it. Here's the source code: MakePalette.zip Quote the usual Link to comment Share on other sites More sharing options...
Ladybug Posted February 17, 2021 Share Posted February 17, 2021 @geist_ I tried it again on one of my images and it did create more than one color but the colors looked washed out. Then I tried it on a sprite image and it worked beautifully. The image location still needs a bit of editing since it only saves it to Documents\paint.net App Files\. Just add the Palettes folder name. It did not give me the option to give it a name but perhaps you are still working on that. Thanks for sharing your coding abilities with some of us who have none, lol. Others on here are very well versed and can help you tweak the plugin if it needs to be. 1 Quote Click HERE to see my Pictorium of images I have worked on. You were once wild here. Don't let them tame you. ~ Isadora Duncan Link to comment Share on other sites More sharing options...
ANONYMISS Posted February 18, 2021 Share Posted February 18, 2021 Just a tad discomforted that this plugin is working ,i.e doesn't crash for @Ladybug. Why so? Quote Link to comment Share on other sites More sharing options...
Ladybug Posted February 18, 2021 Share Posted February 18, 2021 @ANONYMISS, not sure why. It is odd. I have the classic release of PDN. I put the plugins I download in Documents/Paint.net App Files/Effects and after the palette is rendered I move it to Documents/Paint.net App Files/Palettes. I hope that may be of help in comparing your setup and why it may be crashing. Quote Click HERE to see my Pictorium of images I have worked on. You were once wild here. Don't let them tame you. ~ Isadora Duncan Link to comment Share on other sites More sharing options...
ANONYMISS Posted February 18, 2021 Share Posted February 18, 2021 10 minutes ago, Ladybug said: @ANONYMISS, not sure why. It is odd. I have the classic release of PDN. I put the plugins I download in Documents/Paint.net App Files/Effects and after the palette is rendered I move it to Documents/Paint.net App Files/Palettes. I hope that may be of help in comparing your setup and why it may be crashing. Thank you @Ladybug. I use the classic release (in Windows 8.1 - cue booing from offstage) and placed the.dll in the Effects folder. If it gets to be up-and-running I'd find it helpful. P.s. But the present duplicitous behaviour is odd. Quote Link to comment Share on other sites More sharing options...
Ladybug Posted February 18, 2021 Share Posted February 18, 2021 @ANONYMISS, the only difference then is the version of Windows. I have Windows 10 (I will boo for that one but had to upgrade since it was a new computer). Quote Click HERE to see my Pictorium of images I have worked on. You were once wild here. Don't let them tame you. ~ Isadora Duncan Link to comment Share on other sites More sharing options...
toe_head2001 Posted February 18, 2021 Share Posted February 18, 2021 @geist_, looks like you were trying to reinvent the wheel a bit. Here's a simplified version. Let me know if you have any questions about it. // Name: // Submenu: // Author: // Title: // Version: // Desc: // Keywords: // URL: // Help: // Force Single Render Call private static string ToHexString(ColorBgra c) { return $"{c.A:X2}{c.R:X2}{c.G:X2}{c.B:X2}"; } // creates file with colors void MakePaletteFile(List<string> _colors) { int fileCount = 0; string fileName = "UntitledPalette"; string paletteDir = Path.Combine(this.Services.GetService<IUserFilesService>().UserFilesPath, "Palettes"); string path = Path.Combine(paletteDir, fileName + ".txt"); while (File.Exists(path)) { fileCount++; path = Path.Combine(paletteDir, $"{fileName}{fileCount}.txt"); } _colors = _colors.Distinct().ToList(); _colors[0] = $"; {_colors.Count - 1} unique color(s)"; File.WriteAllLines(path, _colors); } void Render(Surface dst, Surface src, Rectangle rect) { List<string> colorCodes = new List<string>(){""}; 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]; string colorAsHex = ToHexString(currentPixel); colorCodes.Add(colorAsHex); } } MakePaletteFile(colorCodes); } 2 1 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...
Ego Eram Reputo Posted February 28, 2021 Share Posted February 28, 2021 @geist_ is this still in developement or have you adopted Toe_head's suggestions? 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...
AndrewDavid Posted December 8, 2021 Share Posted December 8, 2021 On 2/17/2021 at 8:03 PM, toe_head2001 said: Let me know if you have any questions about it. When I bring the code into Codelab, it generates a error message and creates 25 different Palette files. All I wanted was to add it to a submenu (which is the easy part). While we are talking about it, we never did get a dialogue box to name the palette file. Put it on my XMAS wish list. Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted December 8, 2021 Share Posted December 8, 2021 3 minutes ago, AndrewDavid said: When I bring the code into Codelab, it generates a error message and creates 25 different Palette files. And now you know why there's 4 items in the menu for CodeLab. Make sure to use the appropriate one. 1 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...
jenkins72 Posted October 31, 2022 Share Posted October 31, 2022 Hi, this is exactly what I was looking for so I made a couple tweaks. Now it sorts colors by most common found in the image and limits them to the palette limit which is 96. It shouldn't give I/O errors d crash but in case you're using non-english pdn this will make another, not localized, folder named "Palettes". // Name: // Submenu: // Author: // Title: // Version: // Desc: // Keywords: // URL: // Help: // Force Single Render Call // creates file with colors void MakePaletteFile(List<string> colors) { int fileCount = 0; string fileName = "UntitledPalette"; string paletteDir = Path.Combine(this.Services.GetService<IUserFilesService>().UserFilesPath, "Palettes"); if (!Directory.Exists(paletteDir)) Directory.CreateDirectory(paletteDir); string path = Path.Combine(paletteDir, fileName + ".txt"); while (File.Exists(path)) { fileCount++; path = Path.Combine(paletteDir, $"{fileName}{fileCount}.txt"); } colors.Insert(0, $"; {colors.Count} unique color(s)"); File.WriteAllLines(path, colors); } void Render(Surface dst, Surface src, Rectangle rect) { List<ColorBgra> colors = new List<ColorBgra>(); 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]; colors.Add(currentPixel); } } List<string> colorCodes = colors .GroupBy(color => color) .Select(g => new {Value = g.Key, Count = g.Count()}) .OrderByDescending(color => color.Count) .Select(color => color.Value) .Take(96) .ToList() .ConvertAll<string>(c => c.ToHexString()); MakePaletteFile(colorCodes); } 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.