Jump to content

How to fix this plugin?


Reptillian

Recommended Posts

The problem now? Everything turns black. This is basically a simple filter attempt to de-saturate filter based on options found in Krita.

// Name: Krita Inspired Desaturation
// Submenu: Color
// Author: Reptillian
// Title: Desaturation
// Version: 1.0
// Desc: Paint.NET Desaturate filter that is based off Krita Desaturate Filter
// Keywords: Lightness|Average|Min|Max|Grayscale|Desaturate
// URL: https://forums.getpaint.net/
// Help:
#region UICode
RadioButtonControl Amount1 = 0; // [1] Desaturation Method|Lightness|Luminosity (ITU-R BT.709)|Luminosity (ITU-R BT.601)|Average|Min|Max
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
    // Delete any of these lines you don't need
    Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    int CenterX = ((selection.Right - selection.Left) / 2) + selection.Left;
    int CenterY = ((selection.Bottom - selection.Top) / 2) + selection.Top;
    ColorBgra PrimaryColor = EnvironmentParameters.PrimaryColor;
    ColorBgra SecondaryColor = EnvironmentParameters.SecondaryColor;
    int BrushWidth = (int)EnvironmentParameters.BrushWidth;

    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];
            byte D = 0;
            int R = (int)PrimaryColor.R;
            int G = (int)PrimaryColor.G;
            int B = (int)PrimaryColor.B;
            switch(Amount1)
            {
                case 0: D = (byte)((Math.Max(R,Math.Max(G,B))+Math.Min(R,Math.Min(G,B)))/2);
                    break;
                case 1: D = (byte)(.2126*R+.7152*G+.0722*B);
                    break;
                case 2: D = (byte)(.2989*R+.5870*G+.1140*B);
                    break;
                case 3: D = (byte)((R+G+B)/3);
                    break;
                case 4: D = (byte)(Math.Max(R,Math.Max(G,B)));
                    break;
                case 5: D = (byte)(Math.Min(R,Math.Min(G,B)));
                    break;
            }
            CurrentPixel = ColorBgra.FromBgra(D,D,D,CurrentPixel.A);
            dst[x,y] = CurrentPixel;
        }
    }
}

 

G'MIC Filter Developer

 

I am away from this forum for undetermined amount of time: If you really need anything related to my PDN plugin or my G'MIC filter within G'MIC plugin, then you can contact me via Paint.NET discord, and mention me.

Link to comment
Share on other sites

Maybe you can look at mine and get some ideas...

 

https://forums.getpaint.net/topic/113452-black-and-white-plugin-v11-updated-nov-10-2018/

 

 

I could add a few new options to mine, if all you're after is the functionality.  I'd be happy to do it.

 

Which calculations should I add?

 

Link to comment
Share on other sites

Looks like Luminosity Rec.701, Min, Max are the only missing options in your plugin.

G'MIC Filter Developer

 

I am away from this forum for undetermined amount of time: If you really need anything related to my PDN plugin or my G'MIC filter within G'MIC plugin, then you can contact me via Paint.NET discord, and mention me.

Link to comment
Share on other sites

2 hours ago, Reptillian said:

The problem now? Everything turns black.

 

Your code is not using the source pixels; it's just using the Primary Color for every single pixel.

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

20 minutes ago, toe_head2001 said:

 

Your code is not using the source pixels; it's just using the Primary Color for every single pixel.

I found out how to fix it. It works, but I think I'll probably just leave the finished source code for any one that prefers the radio button interface without the brightness/contrast. And it's easier to add settings here than to use BoltBait's code.

// Name: Krita Inspired Desaturation
// Submenu: Color
// Author: Reptillian
// Title: Desaturation
// Version: 1.0
// Desc: Paint.NET Desaturate filter that is based off Krita Desaturate Filter
// Keywords: Lightness|Average|Min|Max|Grayscale|Desaturate
// URL: https://forums.getpaint.net/
// Help:
#region UICode
RadioButtonControl Amount1 = 0; // [1] Desaturation Method|Lightness|Luminosity (ITU-R BT.709)|Luminosity (ITU-R BT.601)|Average|Maximum|Minimum
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
    // Delete any of these lines you don't need
    Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    int CenterX = ((selection.Right - selection.Left) / 2) + selection.Left;
    int CenterY = ((selection.Bottom - selection.Top) / 2) + selection.Top;

    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];
            byte D = 0;
            int R = (int)CurrentPixel.R;
            int G = (int)CurrentPixel.G;
            int B = (int)CurrentPixel.B;
            switch(Amount1)
            {
                case 0: D = (byte)((Math.Max(R,Math.Max(G,B))+Math.Min(R,Math.Min(G,B)))/2);
                    break;
                case 1: D = (byte)(.2126*R+.7152*G+.0722*B);
                    break;
                case 2: D = (byte)(.2989*R+.5870*G+.1140*B);
                    break;
                case 3: D = (byte)((R+G+B)/3);
                    break;
                case 4: D = (byte)(Math.Max(R,Math.Max(G,B)));
                    break;
                case 5: D = (byte)(Math.Min(R,Math.Min(G,B)));
                    break;
            }
            CurrentPixel = ColorBgra.FromBgra(D,D,D,CurrentPixel.A);
            dst[x,y] = CurrentPixel;
        }
    }
}

 

Edited by Reptillian

G'MIC Filter Developer

 

I am away from this forum for undetermined amount of time: If you really need anything related to my PDN plugin or my G'MIC filter within G'MIC plugin, then you can contact me via Paint.NET discord, and mention me.

Link to comment
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...