geist_ 1 Posted February 16 Share Posted February 16 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. Make Palette.zip 1 Quote the usual Link to post Share on other sites
Ladybug 264 Posted February 17 Share Posted February 17 @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 on the Painting Easel to view my paint.net Gallery creations! Link to post Share on other sites
ANONYMISS 17 Posted February 17 Share Posted February 17 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 post Share on other sites
toe_head2001 1,831 Posted February 17 Share Posted February 17 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 My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to post Share on other sites
geist_ 1 Posted February 17 Author Share Posted February 17 @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 post Share on other sites
Ladybug 264 Posted February 17 Share Posted February 17 @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 on the Painting Easel to view my paint.net Gallery creations! Link to post Share on other sites
ANONYMISS 17 Posted February 18 Share Posted February 18 Just a tad discomforted that this plugin is working ,i.e doesn't crash for @Ladybug. Why so? Quote Link to post Share on other sites
Ladybug 264 Posted February 18 Share Posted February 18 @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 on the Painting Easel to view my paint.net Gallery creations! Link to post Share on other sites
ANONYMISS 17 Posted February 18 Share Posted February 18 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 post Share on other sites
Ladybug 264 Posted February 18 Share Posted February 18 @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 on the Painting Easel to view my paint.net Gallery creations! Link to post Share on other sites
toe_head2001 1,831 Posted February 18 Share Posted February 18 @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 My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to post Share on other sites
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.