Jump to content

Make Palette Plugin v1.0 (February 15, 2021)


Recommended Posts

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

  • Upvote 1

the usual

 

0054-0133.gif

Link to post
Share on other sites

@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

 

jK4IjP.png

 

Image 2 and link to corresponding palette:

UntitledPalette2.txt

 

jK4mtM.png

  • Like 1

Click on the Painting Easel to view my paint.net Gallery creations!

j5jLlM.png

 

Link to post
Share on other sites

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

 

  • Like 1
Link to post
Share on other sites

@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

the usual

 

0054-0133.gif

Link to post
Share on other sites

@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.

  • Like 1

Click on the Painting Easel to view my paint.net Gallery creations!

j5jLlM.png

 

Link to post
Share on other sites

@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.

Click on the Painting Easel to view my paint.net Gallery creations!

j5jLlM.png

 

Link to post
Share on other sites
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.

 

 

 

 

Link to post
Share on other sites

@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);
}

 

  • Like 2
  • Upvote 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...