Jump to content

Recommended Posts

New version available!

 

This plugin can be used to simulate certain colorblindness types such as: protanopia, protanomaly, deuteranopia, deuteranomaly, tritanopia, tritanomaly, achromatopsia and achromatomaly.

 

DownloadColorblindness4.zip

Can be found in Effects > Color > Colorblindness

 

Preview:

preview.thumb.jpg.27b867b07a6fee0923b86c6f23ffba86.jpg

Code:

// Name: Colorblindness
// Submenu: Color
// Author: Pascal
// Title: Colorblindness
// Version: 4.0.0
// Desc:
// Keywords:
// URL:
// Help:
#region UICode
ListBoxControl<Btype> btype = 0; //Color blindness type|Protanopia
#endregion

enum Btype{
    Protanopia,
    Protanomaly,
    Deuteranopia,
    Deuteranomaly,
    Tritanopia,
    Tritanomaly,
    Achromatopsia,
    Achromatomaly,
    Default
}

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++){

            ColorBgra CurrentPixel = src[x,y];
            
            byte r = CurrentPixel.R, g = CurrentPixel.G, b = CurrentPixel.B;
            byte R, G, B;

            switch(btype){
                case Btype.Protanopia:
                R = (byte)(0.567 * r + 0.433 * g);
                G = (byte)(0.558 * r + 0.432 * g);
                B = (byte)(0.242 * g + 0.758 * b);
                break;
                case Btype.Deuteranopia:
                R = (byte)(0.625 * r + 0.375 * g);
                G = (byte)(0.7 * r + 0.3 * g);
                B = (byte)(0.3* g + 0.7 * b);
                break;
                case Btype.Tritanopia:
                R = (byte)(0.950 * r + 0.05 * g);
                G = (byte)(0.433 * g + 0.567 * b);
                B = (byte)(0.475* g + 0.525 * b);
                break;
                case Btype.Protanomaly:
                R = (byte)(0.817 * r + 0.183 * g);
                G = (byte)(0.333 * r + 0.667 * g);
                B = (byte)(0.125 * g + 0.875 * b);
                break;
                case Btype.Deuteranomaly:
                R = (byte)(0.8 * r + 0.2 * g);
                G = (byte)(0.258 * r + 0.742 * g);
                B = (byte)(0.142 * g + 0.858 * b);
                break;
                case Btype.Tritanomaly:
                R = (byte)(0.967 * r + 0.033 * g);
                G = (byte)(0.733 * g + 0.267 * b);
                B = (byte)(0.183 * g + 0.817 * b);
                break;
                case Btype.Achromatopsia:
                R = (byte)(0.299 * r + 0.587 * g + 0.114 * b);
                G = (byte)(0.299 * r + 0.587 * g + 0.114 * b);
                B = (byte)(0.299 * r + 0.587 * g + 0.114 * b);
                break;
                case Btype.Achromatomaly:
                R = (byte)(0.618 * r + 0.32 * g + 0.062 * b);
                G = (byte)(0.163 * r + 0.775 * g + 0.062 * b);
                B = (byte)(0.163 * r + 0.32 * g + 0.516 * b);
                break;
                default:
                R = r;
                G = g;
                B = b;
                break;
            }

            dst[x,y] = ColorBgra.FromBgra(limit(B), limit(G), limit(R), CurrentPixel.A);
        }
    }
}

private byte limit(byte p){
    if(p > 255){p = 255;}
    if(p < 0){p = 0;}
    return p;
}

 

Edited by pascal
  • Like 2
  • Upvote 4
Link to post
Share on other sites

Hi Pascal & welcome to the forum :)

 

Good job on this plugin. There is this older plugin - but it doesn't do the tritanopia effect....https://forums.getpaint.net/topic/19780-colourblind-simulation/

 

If you want help cleaning up your code post it over here: https://forums.getpaint.net/forum/17-plugin-developers-central/

 

Link to post
Share on other sites
  • 4 weeks later...
  • 2 weeks later...
On 6/7/2020 at 9:44 PM, pascal said:

New version available!

Thank you @pascal for the new version. This post will let everyone know there's been a change, so that they download the new version.

 

You should really make a new post when you update the plugin, otherwise users will have no way of knowing. I was only alerted to this because of your posts on the General Discussion forum.  

 

Also, it's better not to use the plugin version number in the name of the DLL file itself. If the file name of the newer version is not identical to the previous version, it will not replace the older one in the Effects folder. This will result with two (or more) copies of your plugin in the Effects folder and whatever problems that may cause. 

 

Naming the containing zip file with the version number is OK, even helpful. I like it and wish plugin authors would adopt it as a standard.

 

Edited by Djisves
version number

Xkds4Lh.png

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